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  outArgs.setHessianSupports(true);
146 
147  MEB::DerivativeSupport derivativeSupport(MEB::DERIV_MV_BY_COL);
148 
149  for (int j=0; j<g_space_.size(); ++j)
150  outArgs.setSupports(MEB::OUT_ARG_DgDx,j,derivativeSupport);
151  }
152  prototypeOutArgs_ = outArgs;
153 
154  nominalValues_ = inArgs;
155  const RCP<VectorBase<Scalar> > x0 = createMember(x_space_);
156  V_S(x0.ptr(), ST::zero());
157  nominalValues_.set_x(x0);
158 
159 }
160 
161 
162 // Public functions overridden from ModelEvaulator
163 
164 
165 template<class Scalar>
168 {
169  return x_space_;
170 }
171 
172 
173 template<class Scalar>
176 {
177  return p_space_[l];
178 }
179 
180 
181 template<class Scalar>
184 {
185  return Teuchos::null;
186 }
187 
188 
189 template<class Scalar>
192 {
193  return f_space_;
194 }
195 
196 
197 template<class Scalar>
200 {
201  return g_space_[j];
202 }
203 
204 
205 template<class Scalar>
208 {
209  return g_names_;
210 }
211 
212 
213 template<class Scalar>
216 {
217  return nominalValues_;
218 }
219 
220 
221 template<class Scalar>
224 {
226 }
227 
228 
229 template<class Scalar>
232 {
234 }
235 
236 
237 template<class Scalar>
240 {
241  return createNonconstSimpleDenseLinearOp<Scalar>(
242  createMembers<Scalar>(f_space_, x_space_->dim())
243  );
244 }
245 
246 
247 template<class Scalar>
250 {
251  return nonconstUnspecifiedPrec<Scalar>(
252  createNonconstSimpleDenseLinearOp<Scalar>(
253  createMembers<Scalar>(f_space_, x_space_->dim())
254  )
255  );
256 }
257 
258 
259 template<class Scalar>
262 {
263  return W_factory_;
264 }
265 
266 
267 template<class Scalar>
270 {
271  return prototypeInArgs_;
272 }
273 
274 
275 template<class Scalar>
277  const ModelEvaluatorBase::InArgs<Scalar> &/* finalPoint */,
278  const bool /* wasSolved */
279  )
280 {
281  // ToDo: Capture the final point and then provide in interface.
282 }
283 
284 template<class Scalar>
285 void
287 change_p_size_incorrectly(const Ordinal new_size)
288 {
289  using MEB = ModelEvaluatorBase;
290  {
291  MEB::InArgsSetup<Scalar> inArgs(prototypeInArgs_);
292  inArgs.set_Np(new_size);
293  prototypeInArgs_ = inArgs;
294  }
295  {
296  MEB::OutArgsSetup<Scalar> outArgs(prototypeOutArgs_);
297  outArgs.set_Np_Ng(new_size,g_space_.size());
298  prototypeOutArgs_ = outArgs;
299  }
300  // forgot to call initializeDefaultBase() or resetDefaultBase()
301 }
302 
303 template<class Scalar>
304 void
305 DummyTestModelEvaluator<Scalar>::
306 change_p_size_correctly(const Ordinal new_size)
307 {
308  this->change_p_size_incorrectly(new_size);
309  this->resetDefaultBase();
310 }
311 
312 // Private functions overridden from ModelEvaulatorDefaultBase
313 
314 
315 template<class Scalar>
316 ModelEvaluatorBase::OutArgs<Scalar>
317 DummyTestModelEvaluator<Scalar>::createOutArgsImpl() const
318 {
319  return prototypeOutArgs_;
320 }
321 
322 
323 template<class Scalar>
324 void DummyTestModelEvaluator<Scalar>::evalModelImpl(
325  const ModelEvaluatorBase::InArgs<Scalar> &/* inArgs */,
326  const ModelEvaluatorBase::OutArgs<Scalar> &/* outArgs */
327  ) const
328 {
329  TEUCHOS_TEST_FOR_EXCEPT(true); // ToDo: Implement to just copy inArgs and outArgs!
330 }
331 
332 
333 } // namespace Thyra
334 
335 
336 //
337 // Explicit instantiation macro
338 //
339 // Must be expanded from within the global namespace!
340 //
341 
342 #define DUMMY_TEST_MODEL_EVALUATOR_INSTANT(SCALAR) \
343  \
344  template class DummyTestModelEvaluator<SCALAR >; \
345  \
346  template Teuchos::RCP<DummyTestModelEvaluator<SCALAR > > \
347  dummyTestModelEvaluator( \
348  const Ordinal x_size, \
349  const ArrayView<const Ordinal> &p_sizes, \
350  const ArrayView<const Ordinal> &g_sizes, \
351  const bool supports_x_dot, \
352  const bool supports_x_dot_dot, \
353  const bool supports_extended_inargs, \
354  const bool supports_extended_outargs, \
355  const bool supports_derivatives \
356  ); \
357 
358 
359 #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...