Thyra  Version of the Day
Thyra_DummyTestModelEvaluator_def.hpp
1 /*
2 // @HEADER
3 // ***********************************************************************
4 //
5 // Thyra: Interfaces and Support for Abstract Numerical Algorithms
6 // Copyright (2004) Sandia Corporation
7 //
8 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
9 // license for use of this work by or on behalf of the U.S. Government.
10 //
11 // Redistribution and use in source and binary forms, with or without
12 // modification, are permitted provided that the following conditions are
13 // met:
14 //
15 // 1. Redistributions of source code must retain the above copyright
16 // notice, this list of conditions and the following disclaimer.
17 //
18 // 2. Redistributions in binary form must reproduce the above copyright
19 // notice, this list of conditions and the following disclaimer in the
20 // documentation and/or other materials provided with the distribution.
21 //
22 // 3. Neither the name of the Corporation nor the names of the
23 // contributors may be used to endorse or promote products derived from
24 // this software without specific prior written permission.
25 //
26 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
27 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
30 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
31 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
32 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
33 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
34 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
35 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
36 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 //
38 // Questions? Contact Roscoe A. Bartlett (bartlettra@ornl.gov)
39 //
40 // ***********************************************************************
41 // @HEADER
42 */
43 
44 
45 #ifndef DUMMY_TEST_MODEL_EVALUATOR_DEF_HPP
46 #define DUMMY_TEST_MODEL_EVALUATOR_DEF_HPP
47 
48 
49 #include "Thyra_DummyTestModelEvaluator_decl.hpp"
50 #include "Thyra_SimpleDenseLinearOp.hpp"
51 #include "Thyra_DefaultSpmdVectorSpace.hpp"
52 #include "Thyra_DefaultSerialDenseLinearOpWithSolveFactory.hpp"
53 #include "Thyra_DefaultPreconditioner.hpp"
54 #include "Thyra_DetachedMultiVectorView.hpp"
55 #include "Thyra_DetachedVectorView.hpp"
56 #include "Thyra_MultiVectorStdOps.hpp"
57 #include "Thyra_VectorStdOps.hpp"
58 
59 
60 namespace Thyra {
61 
62 
63 // Nonmember constuctors
64 
65 
66 template<class Scalar>
67 Teuchos::RCP<DummyTestModelEvaluator<Scalar> >
68 dummyTestModelEvaluator(
69  const Ordinal x_size,
70  const ArrayView<const Ordinal> &p_sizes,
71  const ArrayView<const Ordinal> &g_sizes
72  )
73 {
74  return Teuchos::rcp(new DummyTestModelEvaluator<Scalar>(x_size, p_sizes, g_sizes));
75 }
76 
77 
78 // Initializers/Accessors
79 
80 
81 template<class Scalar>
83  const Ordinal x_size,
84  const ArrayView<const Ordinal> &p_sizes,
85  const ArrayView<const Ordinal> &g_sizes
86  )
87 {
88 
89  typedef ModelEvaluatorBase MEB;
90  typedef Teuchos::ScalarTraits<Scalar> ST;
91 
92  x_space_ = defaultSpmdVectorSpace<Scalar>(x_size);
93 
94  p_space_.resize(p_sizes.size());
95  for (Ordinal l = 0; l < p_sizes.size(); ++l) {
96  p_space_[l] = defaultSpmdVectorSpace<Scalar>(p_sizes[l]);
97  }
98 
99  f_space_ = x_space_;
100 
101  g_space_.resize(g_sizes.size());
102  for (Ordinal j = 0; j < g_sizes.size(); ++j) {
103  g_space_[j] = defaultSpmdVectorSpace<Scalar>(g_sizes[j]);
104  }
105 
106  W_factory_ = defaultSerialDenseLinearOpWithSolveFactory<Scalar>();
107 
108  MEB::InArgsSetup<Scalar> inArgs;
109  inArgs.setModelEvalDescription(this->description());
110  inArgs.set_Np(p_space_.size());
111  inArgs.setSupports(MEB::IN_ARG_x);
112  inArgs.setSupports(MEB::IN_ARG_step_size);
113  inArgs.setSupports(MEB::IN_ARG_stage_number);
114  prototypeInArgs_ = inArgs;
115 
116  MEB::OutArgsSetup<Scalar> outArgs;
117  outArgs.setModelEvalDescription(this->description());
118  outArgs.set_Np_Ng(p_space_.size(), g_space_.size());
119  outArgs.setSupports(MEB::OUT_ARG_f);
120  outArgs.setSupports(MEB::OUT_ARG_W_op);
121  outArgs.setSupports(MEB::OUT_ARG_W_prec);
122  prototypeOutArgs_ = outArgs;
123 
124  nominalValues_ = inArgs;
125  const RCP<VectorBase<Scalar> > x0 = createMember(x_space_);
126  V_S(x0.ptr(), ST::zero());
127  nominalValues_.set_x(x0);
128 
129 }
130 
131 
132 // Public functions overridden from ModelEvaulator
133 
134 
135 template<class Scalar>
136 Teuchos::RCP<const VectorSpaceBase<Scalar> >
138 {
139  return x_space_;
140 }
141 
142 
143 template<class Scalar>
144 Teuchos::RCP<const VectorSpaceBase<Scalar> >
146 {
147  return p_space_[l];
148 }
149 
150 
151 template<class Scalar>
152 Teuchos::RCP<const Teuchos::Array<std::string> >
154 {
155  return Teuchos::null;
156 }
157 
158 
159 template<class Scalar>
160 Teuchos::RCP<const VectorSpaceBase<Scalar> >
162 {
163  return f_space_;
164 }
165 
166 
167 template<class Scalar>
168 Teuchos::RCP<const VectorSpaceBase<Scalar> >
170 {
171  return g_space_[j];
172 }
173 
174 
175 template<class Scalar>
176 Teuchos::ArrayView<const std::string>
178 {
179  return g_names_;
180 }
181 
182 
183 template<class Scalar>
186 {
187  return nominalValues_;
188 }
189 
190 
191 template<class Scalar>
194 {
196 }
197 
198 
199 template<class Scalar>
202 {
204 }
205 
206 
207 template<class Scalar>
208 Teuchos::RCP<LinearOpBase<Scalar> >
210 {
211  return createNonconstSimpleDenseLinearOp<Scalar>(
212  createMembers<Scalar>(f_space_, x_space_->dim())
213  );
214 }
215 
216 
217 template<class Scalar>
218 Teuchos::RCP<PreconditionerBase<Scalar> >
220 {
221  return nonconstUnspecifiedPrec<Scalar>(
222  createNonconstSimpleDenseLinearOp<Scalar>(
223  createMembers<Scalar>(f_space_, x_space_->dim())
224  )
225  );
226 }
227 
228 
229 template<class Scalar>
230 Teuchos::RCP<const LinearOpWithSolveFactoryBase<Scalar> >
232 {
233  return W_factory_;
234 }
235 
236 
237 template<class Scalar>
240 {
241  return prototypeInArgs_;
242 }
243 
244 
245 template<class Scalar>
247  const ModelEvaluatorBase::InArgs<Scalar> &finalPoint,
248  const bool wasSolved
249  )
250 {
251  // ToDo: Capture the final point and then provide in interface.
252 }
253 
254 
255 // Private functions overridden from ModelEvaulatorDefaultBase
256 
257 
258 template<class Scalar>
261 {
262  return prototypeOutArgs_;
263 }
264 
265 
266 template<class Scalar>
267 void DummyTestModelEvaluator<Scalar>::evalModelImpl(
268  const ModelEvaluatorBase::InArgs<Scalar> &inArgs,
269  const ModelEvaluatorBase::OutArgs<Scalar> &outArgs
270  ) const
271 {
272  TEUCHOS_TEST_FOR_EXCEPT(true); // ToDo: Implement to just copy inArgs and outArgs!
273 }
274 
275 
276 } // namespace Thyra
277 
278 
279 //
280 // Explicit instantiation macro
281 //
282 // Must be expanded from within the global namespace!
283 //
284 
285 #define DUMMY_TEST_MODEL_EVALUATOR_INSTANT(SCALAR) \
286  \
287  template class DummyTestModelEvaluator<SCALAR >; \
288  \
289  template Teuchos::RCP<DummyTestModelEvaluator<SCALAR > > \
290  dummyTestModelEvaluator( \
291  const Ordinal x_size, \
292  const ArrayView<const Ordinal> &p_sizes, \
293  const ArrayView<const Ordinal> &g_sizes \
294  ); \
295 
296 
297 #endif // DUMMY_TEST_MODEL_EVALUATOR_DEF_HPP
ModelEvaluatorBase::InArgs< Scalar > getUpperBounds() const
RCP< const VectorSpaceBase< Scalar > > get_f_space() const
RCP< const Teuchos::Array< std::string > > get_p_names(int l) const
ModelEvaluatorBase::InArgs< Scalar > getNominalValues() const
Concrete aggregate class for all output arguments computable by a ModelEvaluator subclass object...
DummyTestModelEvaluator(const Ordinal x_size, const ArrayView< const Ordinal > &p_sizes, const ArrayView< const Ordinal > &g_sizes)
void reportFinalPoint(const ModelEvaluatorBase::InArgs< Scalar > &finalPoint, const bool wasSolved)
RCP< const LinearOpWithSolveFactoryBase< Scalar > > get_W_factory() const
RCP< LinearOpBase< Scalar > > create_W_op() const
Teuchos::Ordinal Ordinal
Type for the dimension of a vector space. `*.
RCP< PreconditionerBase< Scalar > > create_W_prec() const
RCP< const VectorSpaceBase< Scalar > > get_p_space(int l) const
ModelEvaluatorBase::InArgs< Scalar > createInArgs() const
RCP< const VectorSpaceBase< Scalar > > get_g_space(int j) const
Base subclass for ModelEvaluator that defines some basic types.
ModelEvaluatorBase::InArgs< Scalar > getLowerBounds() const
Teuchos::ArrayView< const std::string > get_g_names(int j) const
RCP< const VectorSpaceBase< Scalar > > get_x_space() const
Concrete aggregate class for all output arguments computable by a ModelEvaluator subclass object...