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  )
76 {
77  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));
78 }
79 
80 
81 // Initializers/Accessors
82 
83 
84 template<class Scalar>
86  const Ordinal x_size,
87  const ArrayView<const Ordinal> &p_sizes,
88  const ArrayView<const Ordinal> &g_sizes,
89  const bool supports_x_dot,
90  const bool supports_x_dot_dot,
91  const bool supports_extended_inargs,
92  const bool supports_extended_outargs
93  )
94 {
95 
96  typedef ModelEvaluatorBase MEB;
98 
99  x_space_ = defaultSpmdVectorSpace<Scalar>(x_size);
100 
101  p_space_.resize(p_sizes.size());
102  for (Ordinal l = 0; l < p_sizes.size(); ++l) {
103  p_space_[l] = defaultSpmdVectorSpace<Scalar>(p_sizes[l]);
104  }
105 
106  f_space_ = x_space_;
107 
108  g_space_.resize(g_sizes.size());
109  for (Ordinal j = 0; j < g_sizes.size(); ++j) {
110  g_space_[j] = defaultSpmdVectorSpace<Scalar>(g_sizes[j]);
111  }
112 
113  W_factory_ = defaultSerialDenseLinearOpWithSolveFactory<Scalar>();
114 
115  MEB::InArgsSetup<Scalar> inArgs;
116  inArgs.setModelEvalDescription(this->description());
117  inArgs.set_Np(p_space_.size());
118  inArgs.setSupports(MEB::IN_ARG_x);
119  if (supports_x_dot)
120  inArgs.setSupports(MEB::IN_ARG_x_dot);
121  if (supports_x_dot_dot)
122  inArgs.setSupports(MEB::IN_ARG_x_dot_dot);
123  inArgs.setSupports(MEB::IN_ARG_step_size);
124  inArgs.setSupports(MEB::IN_ARG_stage_number);
125  inArgs.template setSupports<Thyra::MockExtendedInArgs<Scalar> >(true);
126  // test the removal of support
127  if (!supports_extended_inargs)
128  inArgs.template setSupports<Thyra::MockExtendedInArgs<Scalar> >(false);
129  prototypeInArgs_ = inArgs;
130 
131  MEB::OutArgsSetup<Scalar> outArgs;
132  outArgs.setModelEvalDescription(this->description());
133  outArgs.set_Np_Ng(p_space_.size(), g_space_.size());
134  outArgs.setSupports(MEB::OUT_ARG_f);
135  outArgs.setSupports(MEB::OUT_ARG_W_op);
136  outArgs.setSupports(MEB::OUT_ARG_W_prec);
137  outArgs.template setSupports<Thyra::MockExtendedOutArgs<Scalar> >(true);
138  // test the removal of support
139  if (!supports_extended_outargs)
140  outArgs.template setSupports<Thyra::MockExtendedOutArgs<Scalar> >(false);
141  prototypeOutArgs_ = outArgs;
142 
143  nominalValues_ = inArgs;
144  const RCP<VectorBase<Scalar> > x0 = createMember(x_space_);
145  V_S(x0.ptr(), ST::zero());
146  nominalValues_.set_x(x0);
147 
148 }
149 
150 
151 // Public functions overridden from ModelEvaulator
152 
153 
154 template<class Scalar>
157 {
158  return x_space_;
159 }
160 
161 
162 template<class Scalar>
165 {
166  return p_space_[l];
167 }
168 
169 
170 template<class Scalar>
173 {
174  return Teuchos::null;
175 }
176 
177 
178 template<class Scalar>
181 {
182  return f_space_;
183 }
184 
185 
186 template<class Scalar>
189 {
190  return g_space_[j];
191 }
192 
193 
194 template<class Scalar>
197 {
198  return g_names_;
199 }
200 
201 
202 template<class Scalar>
205 {
206  return nominalValues_;
207 }
208 
209 
210 template<class Scalar>
213 {
215 }
216 
217 
218 template<class Scalar>
221 {
223 }
224 
225 
226 template<class Scalar>
229 {
230  return createNonconstSimpleDenseLinearOp<Scalar>(
231  createMembers<Scalar>(f_space_, x_space_->dim())
232  );
233 }
234 
235 
236 template<class Scalar>
239 {
240  return nonconstUnspecifiedPrec<Scalar>(
241  createNonconstSimpleDenseLinearOp<Scalar>(
242  createMembers<Scalar>(f_space_, x_space_->dim())
243  )
244  );
245 }
246 
247 
248 template<class Scalar>
251 {
252  return W_factory_;
253 }
254 
255 
256 template<class Scalar>
259 {
260  return prototypeInArgs_;
261 }
262 
263 
264 template<class Scalar>
266  const ModelEvaluatorBase::InArgs<Scalar> &/* finalPoint */,
267  const bool /* wasSolved */
268  )
269 {
270  // ToDo: Capture the final point and then provide in interface.
271 }
272 
273 template<class Scalar>
274 void
276 change_p_size_incorrectly(const Ordinal new_size)
277 {
278  using MEB = ModelEvaluatorBase;
279  {
280  MEB::InArgsSetup<Scalar> inArgs(prototypeInArgs_);
281  inArgs.set_Np(new_size);
282  prototypeInArgs_ = inArgs;
283  }
284  {
285  MEB::OutArgsSetup<Scalar> outArgs(prototypeOutArgs_);
286  outArgs.set_Np_Ng(new_size,g_space_.size());
287  prototypeOutArgs_ = outArgs;
288  }
289  // forgot to call initializeDefaultBase() or resetDefaultBase()
290 }
291 
292 template<class Scalar>
293 void
294 DummyTestModelEvaluator<Scalar>::
295 change_p_size_correctly(const Ordinal new_size)
296 {
297  this->change_p_size_incorrectly(new_size);
298  this->resetDefaultBase();
299 }
300 
301 // Private functions overridden from ModelEvaulatorDefaultBase
302 
303 
304 template<class Scalar>
305 ModelEvaluatorBase::OutArgs<Scalar>
306 DummyTestModelEvaluator<Scalar>::createOutArgsImpl() const
307 {
308  return prototypeOutArgs_;
309 }
310 
311 
312 template<class Scalar>
313 void DummyTestModelEvaluator<Scalar>::evalModelImpl(
314  const ModelEvaluatorBase::InArgs<Scalar> &/* inArgs */,
315  const ModelEvaluatorBase::OutArgs<Scalar> &/* outArgs */
316  ) const
317 {
318  TEUCHOS_TEST_FOR_EXCEPT(true); // ToDo: Implement to just copy inArgs and outArgs!
319 }
320 
321 
322 } // namespace Thyra
323 
324 
325 //
326 // Explicit instantiation macro
327 //
328 // Must be expanded from within the global namespace!
329 //
330 
331 #define DUMMY_TEST_MODEL_EVALUATOR_INSTANT(SCALAR) \
332  \
333  template class DummyTestModelEvaluator<SCALAR >; \
334  \
335  template Teuchos::RCP<DummyTestModelEvaluator<SCALAR > > \
336  dummyTestModelEvaluator( \
337  const Ordinal x_size, \
338  const ArrayView<const Ordinal> &p_sizes, \
339  const ArrayView<const Ordinal> &g_sizes, \
340  const bool supports_x_dot, \
341  const bool supports_x_dot_dot, \
342  const bool supports_extended_inargs, \
343  const bool supports_extended_outargs \
344  ); \
345 
346 
347 #endif // DUMMY_TEST_MODEL_EVALUATOR_DEF_HPP
ModelEvaluatorBase::InArgs< Scalar > getNominalValues() const
void reportFinalPoint(const ModelEvaluatorBase::InArgs< Scalar > &finalPoint, const bool wasSolved)
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)
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)
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...