Thyra  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Thyra_DummyTestModelEvaluator_def.hpp
1 // @HEADER
2 // *****************************************************************************
3 // Thyra: Interfaces and Support for Abstract Numerical Algorithms
4 //
5 // Copyright 2004 NTESS and the Thyra contributors.
6 // SPDX-License-Identifier: BSD-3-Clause
7 // *****************************************************************************
8 // @HEADER
9 
10 #ifndef DUMMY_TEST_MODEL_EVALUATOR_DEF_HPP
11 #define DUMMY_TEST_MODEL_EVALUATOR_DEF_HPP
12 
13 
14 #include "Thyra_DummyTestModelEvaluator_decl.hpp"
15 #include "Thyra_SimpleDenseLinearOp.hpp"
16 #include "Thyra_DefaultSpmdVectorSpace.hpp"
17 #include "Thyra_DefaultSerialDenseLinearOpWithSolveFactory.hpp"
18 #include "Thyra_DefaultPreconditioner.hpp"
19 #include "Thyra_DetachedMultiVectorView.hpp"
20 #include "Thyra_DetachedVectorView.hpp"
21 #include "Thyra_MultiVectorStdOps.hpp"
22 #include "Thyra_VectorStdOps.hpp"
23 
24 
25 namespace Thyra {
26 
27 // Nonmember constuctors
28 
29 
30 template<class Scalar>
32 dummyTestModelEvaluator(
33  const Ordinal x_size,
34  const ArrayView<const Ordinal> &p_sizes,
35  const ArrayView<const Ordinal> &g_sizes,
36  const bool supports_x_dot,
37  const bool supports_x_dot_dot,
38  const bool supports_extended_inargs,
39  const bool supports_extended_outargs,
40  const bool supports_derivatives
41  )
42 {
43  return Teuchos::rcp(new DummyTestModelEvaluator<Scalar>(x_size, p_sizes, g_sizes, supports_x_dot, supports_x_dot_dot,supports_extended_inargs,supports_extended_outargs,supports_derivatives));
44 }
45 
46 
47 // Initializers/Accessors
48 
49 
50 template<class Scalar>
52  const Ordinal x_size,
53  const ArrayView<const Ordinal> &p_sizes,
54  const ArrayView<const Ordinal> &g_sizes,
55  const bool supports_x_dot,
56  const bool supports_x_dot_dot,
57  const bool supports_extended_inargs,
58  const bool supports_extended_outargs,
59  const bool supports_derivatives
60  )
61 {
62 
63  typedef ModelEvaluatorBase MEB;
65 
66  x_space_ = defaultSpmdVectorSpace<Scalar>(x_size);
67 
68  p_space_.resize(p_sizes.size());
69  for (Ordinal l = 0; l < p_sizes.size(); ++l) {
70  p_space_[l] = defaultSpmdVectorSpace<Scalar>(p_sizes[l]);
71  }
72 
73  f_space_ = x_space_;
74 
75  g_space_.resize(g_sizes.size());
76  for (Ordinal j = 0; j < g_sizes.size(); ++j) {
77  g_space_[j] = defaultSpmdVectorSpace<Scalar>(g_sizes[j]);
78  }
79 
80  W_factory_ = defaultSerialDenseLinearOpWithSolveFactory<Scalar>();
81 
82  MEB::InArgsSetup<Scalar> inArgs;
83  inArgs.setModelEvalDescription(this->description());
84  inArgs.set_Np_Ng(p_space_.size(),g_sizes.size());
85  inArgs.setSupports(MEB::IN_ARG_x);
86  if (supports_x_dot)
87  inArgs.setSupports(MEB::IN_ARG_x_dot);
88  if (supports_x_dot_dot)
89  inArgs.setSupports(MEB::IN_ARG_x_dot_dot);
90  inArgs.setSupports(MEB::IN_ARG_step_size);
91  inArgs.setSupports(MEB::IN_ARG_stage_number);
92  inArgs.template setSupports<Thyra::MockExtendedInArgs<Scalar> >(true);
93  // test the removal of support
94  if (!supports_extended_inargs)
95  inArgs.template setSupports<Thyra::MockExtendedInArgs<Scalar> >(false);
96  prototypeInArgs_ = inArgs;
97 
98  MEB::OutArgsSetup<Scalar> outArgs;
99  outArgs.setModelEvalDescription(this->description());
100  outArgs.set_Np_Ng(p_space_.size(), g_space_.size());
101  outArgs.setSupports(MEB::OUT_ARG_f);
102  outArgs.setSupports(MEB::OUT_ARG_W_op);
103  outArgs.setSupports(MEB::OUT_ARG_W_prec);
104  outArgs.template setSupports<Thyra::MockExtendedOutArgs<Scalar> >(true);
105  // test the removal of support
106  if (!supports_extended_outargs)
107  outArgs.template setSupports<Thyra::MockExtendedOutArgs<Scalar> >(false);
108  if (supports_derivatives)
109  {
110 #ifdef Thyra_BUILD_HESSIAN_SUPPORT
111  outArgs.setHessianSupports(true);
112 #endif
113 
114  MEB::DerivativeSupport derivativeSupport(MEB::DERIV_MV_BY_COL);
115 
116  for (int j=0; j<g_space_.size(); ++j)
117  outArgs.setSupports(MEB::OUT_ARG_DgDx,j,derivativeSupport);
118  }
119  prototypeOutArgs_ = outArgs;
120 
121  nominalValues_ = inArgs;
122  const RCP<VectorBase<Scalar> > x0 = createMember(x_space_);
123  V_S(x0.ptr(), ST::zero());
124  nominalValues_.set_x(x0);
125 
126 }
127 
128 
129 // Public functions overridden from ModelEvaulator
130 
131 
132 template<class Scalar>
135 {
136  return x_space_;
137 }
138 
139 
140 template<class Scalar>
143 {
144  return p_space_[l];
145 }
146 
147 
148 template<class Scalar>
151 {
152  return Teuchos::null;
153 }
154 
155 
156 template<class Scalar>
159 {
160  return f_space_;
161 }
162 
163 
164 template<class Scalar>
167 {
168  return g_space_[j];
169 }
170 
171 
172 template<class Scalar>
175 {
176  return g_names_;
177 }
178 
179 
180 template<class Scalar>
183 {
184  return nominalValues_;
185 }
186 
187 
188 template<class Scalar>
191 {
193 }
194 
195 
196 template<class Scalar>
199 {
201 }
202 
203 
204 template<class Scalar>
207 {
208  return createNonconstSimpleDenseLinearOp<Scalar>(
209  createMembers<Scalar>(f_space_, x_space_->dim())
210  );
211 }
212 
213 
214 template<class Scalar>
217 {
218  return nonconstUnspecifiedPrec<Scalar>(
219  createNonconstSimpleDenseLinearOp<Scalar>(
220  createMembers<Scalar>(f_space_, x_space_->dim())
221  )
222  );
223 }
224 
225 
226 template<class Scalar>
229 {
230  return W_factory_;
231 }
232 
233 
234 template<class Scalar>
237 {
238  return prototypeInArgs_;
239 }
240 
241 
242 template<class Scalar>
244  const ModelEvaluatorBase::InArgs<Scalar> &/* finalPoint */,
245  const bool /* wasSolved */
246  )
247 {
248  // ToDo: Capture the final point and then provide in interface.
249 }
250 
251 template<class Scalar>
252 void
254 change_p_size_incorrectly(const Ordinal new_size)
255 {
256  using MEB = ModelEvaluatorBase;
257  {
258  MEB::InArgsSetup<Scalar> inArgs(prototypeInArgs_);
259  inArgs.set_Np(new_size);
260  prototypeInArgs_ = inArgs;
261  }
262  {
263  MEB::OutArgsSetup<Scalar> outArgs(prototypeOutArgs_);
264  outArgs.set_Np_Ng(new_size,g_space_.size());
265  prototypeOutArgs_ = outArgs;
266  }
267  // forgot to call initializeDefaultBase() or resetDefaultBase()
268 }
269 
270 template<class Scalar>
271 void
272 DummyTestModelEvaluator<Scalar>::
273 change_p_size_correctly(const Ordinal new_size)
274 {
275  this->change_p_size_incorrectly(new_size);
276  this->resetDefaultBase();
277 }
278 
279 // Private functions overridden from ModelEvaulatorDefaultBase
280 
281 
282 template<class Scalar>
283 ModelEvaluatorBase::OutArgs<Scalar>
284 DummyTestModelEvaluator<Scalar>::createOutArgsImpl() const
285 {
286  return prototypeOutArgs_;
287 }
288 
289 
290 template<class Scalar>
291 void DummyTestModelEvaluator<Scalar>::evalModelImpl(
292  const ModelEvaluatorBase::InArgs<Scalar> &/* inArgs */,
293  const ModelEvaluatorBase::OutArgs<Scalar> &/* outArgs */
294  ) const
295 {
296  TEUCHOS_TEST_FOR_EXCEPT(true); // ToDo: Implement to just copy inArgs and outArgs!
297 }
298 
299 
300 } // namespace Thyra
301 
302 
303 //
304 // Explicit instantiation macro
305 //
306 // Must be expanded from within the global namespace!
307 //
308 
309 #define DUMMY_TEST_MODEL_EVALUATOR_INSTANT(SCALAR) \
310  \
311  template class DummyTestModelEvaluator<SCALAR >; \
312  \
313  template Teuchos::RCP<DummyTestModelEvaluator<SCALAR > > \
314  dummyTestModelEvaluator( \
315  const Ordinal x_size, \
316  const ArrayView<const Ordinal> &p_sizes, \
317  const ArrayView<const Ordinal> &g_sizes, \
318  const bool supports_x_dot, \
319  const bool supports_x_dot_dot, \
320  const bool supports_extended_inargs, \
321  const bool supports_extended_outargs, \
322  const bool supports_derivatives \
323  ); \
324 
325 
326 #endif // DUMMY_TEST_MODEL_EVALUATOR_DEF_HPP
ModelEvaluatorBase::InArgs< Scalar > getNominalValues() const
void reportFinalPoint(const ModelEvaluatorBase::InArgs< Scalar > &finalPoint, const bool wasSolved)
RCP< const VectorSpaceBase< Scalar > > get_p_space(int l) const
RCP< const Teuchos::Array< std::string > > get_p_names(int l) const
ModelEvaluatorBase::InArgs< Scalar > createInArgs() const
size_type size() const
RCP< LinearOpBase< Scalar > > create_W_op() const
ModelEvaluatorBase::InArgs< Scalar > getUpperBounds() const
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Teuchos::Ordinal Ordinal
Type for the dimension of a vector space. `*.
RCP< const VectorSpaceBase< Scalar > > get_x_space() const
Ptr< T > ptr() const
Base subclass for ModelEvaluator that defines some basic types.
Teuchos::ArrayView< const std::string > get_g_names(int j) const
RCP< const VectorSpaceBase< Scalar > > get_f_space() const
ModelEvaluatorBase::InArgs< Scalar > getLowerBounds() const
RCP< const VectorSpaceBase< Scalar > > get_g_space(int j) const
#define TEUCHOS_TEST_FOR_EXCEPT(throw_exception_test)
DummyTestModelEvaluator(const Ordinal x_size, const ArrayView< const Ordinal > &p_sizes, const ArrayView< const Ordinal > &g_sizes, const bool supports_x_dot=false, const bool supports_x_dot_dot=false, const bool supports_extended_inargs=true, const bool supports_extended_outargs=true, const bool supports_derivatives=false)
RCP< const LinearOpWithSolveFactoryBase< Scalar > > get_W_factory() const
RCP< PreconditionerBase< Scalar > > create_W_prec() const
Concrete aggregate class for all input arguments computable by a ModelEvaluator subclass object...