Thyra  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 // Nonmember constuctors
63 
64 
65 template<class Scalar>
67 dummyTestModelEvaluator(
68  const Ordinal x_size,
69  const ArrayView<const Ordinal> &p_sizes,
70  const ArrayView<const Ordinal> &g_sizes,
71  const bool supports_x_dot,
72  const bool supports_x_dot_dot,
73  const bool supports_extended_inargs,
74  const bool supports_extended_outargs,
75  const bool supports_derivatives
76  )
77 {
78  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));
79 }
80 
81 
82 // Initializers/Accessors
83 
84 
85 template<class Scalar>
87  const Ordinal x_size,
88  const ArrayView<const Ordinal> &p_sizes,
89  const ArrayView<const Ordinal> &g_sizes,
90  const bool supports_x_dot,
91  const bool supports_x_dot_dot,
92  const bool supports_extended_inargs,
93  const bool supports_extended_outargs,
94  const bool supports_derivatives
95  )
96 {
97 
98  typedef ModelEvaluatorBase MEB;
100 
101  x_space_ = defaultSpmdVectorSpace<Scalar>(x_size);
102 
103  p_space_.resize(p_sizes.size());
104  for (Ordinal l = 0; l < p_sizes.size(); ++l) {
105  p_space_[l] = defaultSpmdVectorSpace<Scalar>(p_sizes[l]);
106  }
107 
108  f_space_ = x_space_;
109 
110  g_space_.resize(g_sizes.size());
111  for (Ordinal j = 0; j < g_sizes.size(); ++j) {
112  g_space_[j] = defaultSpmdVectorSpace<Scalar>(g_sizes[j]);
113  }
114 
115  W_factory_ = defaultSerialDenseLinearOpWithSolveFactory<Scalar>();
116 
117  MEB::InArgsSetup<Scalar> inArgs;
118  inArgs.setModelEvalDescription(this->description());
119  inArgs.set_Np_Ng(p_space_.size(),g_sizes.size());
120  inArgs.setSupports(MEB::IN_ARG_x);
121  if (supports_x_dot)
122  inArgs.setSupports(MEB::IN_ARG_x_dot);
123  if (supports_x_dot_dot)
124  inArgs.setSupports(MEB::IN_ARG_x_dot_dot);
125  inArgs.setSupports(MEB::IN_ARG_step_size);
126  inArgs.setSupports(MEB::IN_ARG_stage_number);
127  inArgs.template setSupports<Thyra::MockExtendedInArgs<Scalar> >(true);
128  // test the removal of support
129  if (!supports_extended_inargs)
130  inArgs.template setSupports<Thyra::MockExtendedInArgs<Scalar> >(false);
131  prototypeInArgs_ = inArgs;
132 
133  MEB::OutArgsSetup<Scalar> outArgs;
134  outArgs.setModelEvalDescription(this->description());
135  outArgs.set_Np_Ng(p_space_.size(), g_space_.size());
136  outArgs.setSupports(MEB::OUT_ARG_f);
137  outArgs.setSupports(MEB::OUT_ARG_W_op);
138  outArgs.setSupports(MEB::OUT_ARG_W_prec);
139  outArgs.template setSupports<Thyra::MockExtendedOutArgs<Scalar> >(true);
140  // test the removal of support
141  if (!supports_extended_outargs)
142  outArgs.template setSupports<Thyra::MockExtendedOutArgs<Scalar> >(false);
143  if (supports_derivatives)
144  {
145 #ifdef Thyra_BUILD_HESSIAN_SUPPORT
146  outArgs.setHessianSupports(true);
147 #endif
148 
149  MEB::DerivativeSupport derivativeSupport(MEB::DERIV_MV_BY_COL);
150 
151  for (int j=0; j<g_space_.size(); ++j)
152  outArgs.setSupports(MEB::OUT_ARG_DgDx,j,derivativeSupport);
153  }
154  prototypeOutArgs_ = outArgs;
155 
156  nominalValues_ = inArgs;
157  const RCP<VectorBase<Scalar> > x0 = createMember(x_space_);
158  V_S(x0.ptr(), ST::zero());
159  nominalValues_.set_x(x0);
160 
161 }
162 
163 
164 // Public functions overridden from ModelEvaulator
165 
166 
167 template<class Scalar>
170 {
171  return x_space_;
172 }
173 
174 
175 template<class Scalar>
178 {
179  return p_space_[l];
180 }
181 
182 
183 template<class Scalar>
186 {
187  return Teuchos::null;
188 }
189 
190 
191 template<class Scalar>
194 {
195  return f_space_;
196 }
197 
198 
199 template<class Scalar>
202 {
203  return g_space_[j];
204 }
205 
206 
207 template<class Scalar>
210 {
211  return g_names_;
212 }
213 
214 
215 template<class Scalar>
218 {
219  return nominalValues_;
220 }
221 
222 
223 template<class Scalar>
226 {
228 }
229 
230 
231 template<class Scalar>
234 {
236 }
237 
238 
239 template<class Scalar>
242 {
243  return createNonconstSimpleDenseLinearOp<Scalar>(
244  createMembers<Scalar>(f_space_, x_space_->dim())
245  );
246 }
247 
248 
249 template<class Scalar>
252 {
253  return nonconstUnspecifiedPrec<Scalar>(
254  createNonconstSimpleDenseLinearOp<Scalar>(
255  createMembers<Scalar>(f_space_, x_space_->dim())
256  )
257  );
258 }
259 
260 
261 template<class Scalar>
264 {
265  return W_factory_;
266 }
267 
268 
269 template<class Scalar>
272 {
273  return prototypeInArgs_;
274 }
275 
276 
277 template<class Scalar>
279  const ModelEvaluatorBase::InArgs<Scalar> &/* finalPoint */,
280  const bool /* wasSolved */
281  )
282 {
283  // ToDo: Capture the final point and then provide in interface.
284 }
285 
286 template<class Scalar>
287 void
289 change_p_size_incorrectly(const Ordinal new_size)
290 {
291  using MEB = ModelEvaluatorBase;
292  {
293  MEB::InArgsSetup<Scalar> inArgs(prototypeInArgs_);
294  inArgs.set_Np(new_size);
295  prototypeInArgs_ = inArgs;
296  }
297  {
298  MEB::OutArgsSetup<Scalar> outArgs(prototypeOutArgs_);
299  outArgs.set_Np_Ng(new_size,g_space_.size());
300  prototypeOutArgs_ = outArgs;
301  }
302  // forgot to call initializeDefaultBase() or resetDefaultBase()
303 }
304 
305 template<class Scalar>
306 void
307 DummyTestModelEvaluator<Scalar>::
308 change_p_size_correctly(const Ordinal new_size)
309 {
310  this->change_p_size_incorrectly(new_size);
311  this->resetDefaultBase();
312 }
313 
314 // Private functions overridden from ModelEvaulatorDefaultBase
315 
316 
317 template<class Scalar>
318 ModelEvaluatorBase::OutArgs<Scalar>
319 DummyTestModelEvaluator<Scalar>::createOutArgsImpl() const
320 {
321  return prototypeOutArgs_;
322 }
323 
324 
325 template<class Scalar>
326 void DummyTestModelEvaluator<Scalar>::evalModelImpl(
327  const ModelEvaluatorBase::InArgs<Scalar> &/* inArgs */,
328  const ModelEvaluatorBase::OutArgs<Scalar> &/* outArgs */
329  ) const
330 {
331  TEUCHOS_TEST_FOR_EXCEPT(true); // ToDo: Implement to just copy inArgs and outArgs!
332 }
333 
334 
335 } // namespace Thyra
336 
337 
338 //
339 // Explicit instantiation macro
340 //
341 // Must be expanded from within the global namespace!
342 //
343 
344 #define DUMMY_TEST_MODEL_EVALUATOR_INSTANT(SCALAR) \
345  \
346  template class DummyTestModelEvaluator<SCALAR >; \
347  \
348  template Teuchos::RCP<DummyTestModelEvaluator<SCALAR > > \
349  dummyTestModelEvaluator( \
350  const Ordinal x_size, \
351  const ArrayView<const Ordinal> &p_sizes, \
352  const ArrayView<const Ordinal> &g_sizes, \
353  const bool supports_x_dot, \
354  const bool supports_x_dot_dot, \
355  const bool supports_extended_inargs, \
356  const bool supports_extended_outargs, \
357  const bool supports_derivatives \
358  ); \
359 
360 
361 #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...