Thyra  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Thyra_DefaultNominalBoundsOverrideModelEvaluator.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 THYRA_DEFAULT_NOMINAL_BOUNDS_OVERRIDE_MODEL_EVALUATOR_HPP
11 #define THYRA_DEFAULT_NOMINAL_BOUNDS_OVERRIDE_MODEL_EVALUATOR_HPP
12 
13 
14 #include "Thyra_ModelEvaluatorDelegatorBase.hpp"
15 #include "Thyra_LinearOpWithSolveFactoryBase.hpp"
16 #include "Teuchos_Time.hpp"
17 
18 
19 namespace Thyra {
20 
21 
68 template<class Scalar>
70  : virtual public ModelEvaluatorDelegatorBase<Scalar>
71 {
72 public:
73 
76 
79 
82 
85  const RCP<ModelEvaluator<Scalar> > &thyraModel,
86  const RCP<const ModelEvaluatorBase::InArgs<Scalar> > &nominalValues,
87  const RCP<const ModelEvaluatorBase::InArgs<Scalar> > &lowerBounds = Teuchos::null,
88  const RCP<const ModelEvaluatorBase::InArgs<Scalar> > &upperBounds = Teuchos::null
89  );
90 
115  void initialize(
116  const RCP<ModelEvaluator<Scalar> > &thyraModel,
117  const RCP<const ModelEvaluatorBase::InArgs<Scalar> > &nominalValues,
118  const RCP<const ModelEvaluatorBase::InArgs<Scalar> > &lowerBounds = Teuchos::null,
119  const RCP<const ModelEvaluatorBase::InArgs<Scalar> > &upperBounds = Teuchos::null
120  );
121 
123  void setNominalValues(
124  const RCP<const ModelEvaluatorBase::InArgs<Scalar> > &nominalValues
125  );
126 
128  void setLowerBounds(
129  const RCP<const ModelEvaluatorBase::InArgs<Scalar> > &lowerBounds
130  );
131 
133  void setUpperBounds(
134  const RCP<const ModelEvaluatorBase::InArgs<Scalar> > &upperBounds
135  );
136 
137  // ToDo: Add functions to reset lower and upper bounds when needed!
138 
140 
143 
145  std::string description() const;
146 
148 
151 
158 
160 
161 private:
162 
165 
167  void evalModelImpl(
170  ) const;
171 
173 
174 private:
175 
179 
180 };
181 
182 
183 // /////////////////////////////////
184 // Implementations
185 
186 
187 // Constructors/initializers/accessors/utilities
188 
189 
190 template<class Scalar>
192 {}
193 
194 
195 template<class Scalar>
197  const RCP<ModelEvaluator<Scalar> > &thyraModel,
198  const RCP<const ModelEvaluatorBase::InArgs<Scalar> > &nominalValues,
199  const RCP<const ModelEvaluatorBase::InArgs<Scalar> > &lowerBounds,
200  const RCP<const ModelEvaluatorBase::InArgs<Scalar> > &upperBounds
201  )
202 {
203  initialize(thyraModel,nominalValues,lowerBounds,upperBounds);
204 }
205 
206 
207 template<class Scalar>
209  const RCP<ModelEvaluator<Scalar> > &thyraModel,
210  const RCP<const ModelEvaluatorBase::InArgs<Scalar> > &nominalValues,
211  const RCP<const ModelEvaluatorBase::InArgs<Scalar> > &lowerBounds,
212  const RCP<const ModelEvaluatorBase::InArgs<Scalar> > &upperBounds
213  )
214 {
216  nominalValues_ = nominalValues;
217  lowerBounds_ = lowerBounds;
218  upperBounds_ = upperBounds;
219 }
220 
221 
222 template<class Scalar>
224  const RCP<const ModelEvaluatorBase::InArgs<Scalar> > &nominalValues
225  )
226 {
227  nominalValues_ = nominalValues;
228 }
229 
230 
231 template<class Scalar>
233  const RCP<const ModelEvaluatorBase::InArgs<Scalar> > &lowerBounds
234  )
235 {
236  lowerBounds_ = lowerBounds;
237 }
238 
239 
240 template<class Scalar>
242  const RCP<const ModelEvaluatorBase::InArgs<Scalar> > &upperBounds
243  )
244 {
245  upperBounds_ = upperBounds;
246 }
247 
248 
249 // Public functions overridden from Teuchos::Describable
250 
251 
252 template<class Scalar>
254 {
256  thyraModel = this->getUnderlyingModel();
257  std::ostringstream oss;
258  oss << "Thyra::DefaultNominalBoundsOverrideModelEvaluator{";
259  oss << "thyraModel=";
260  if(thyraModel.get())
261  oss << "\'"<<thyraModel->description()<<"\'";
262  else
263  oss << "NULL";
264  oss << "}";
265  return oss.str();
266 }
267 
268 
269 // Overridden from ModelEvaulator.
270 
271 
272 template<class Scalar>
275 {
276  if(nominalValues_.get())
277  return *nominalValues_;
278  return this->getUnderlyingModel()->getNominalValues();
279 }
280 
281 
282 template<class Scalar>
285 {
286  if(lowerBounds_.get())
287  return *lowerBounds_;
288  return this->getUnderlyingModel()->getLowerBounds();
289 }
290 
291 
292 template<class Scalar>
295 {
296  if(upperBounds_.get())
297  return *upperBounds_;
298  return this->getUnderlyingModel()->getUpperBounds();
299 }
300 
301 
302 // Private functions overridden from ModelEvaulatorDefaultBase
303 
304 
305 template<class Scalar>
309  ) const
310 {
311 
312  using Teuchos::rcp;
313  using Teuchos::rcp_const_cast;
314  using Teuchos::rcp_dynamic_cast;
315  using Teuchos::OSTab;
316  typedef ModelEvaluatorBase MEB;
317 
318  THYRA_MODEL_EVALUATOR_DECORATOR_EVAL_MODEL_BEGIN(
319  "Thyra::DefaultNominalBoundsOverrideModelEvaluator",inArgs,outArgs
320  );
321 
322  // First set the inArgs to what was overridden
323  MEB::InArgs<Scalar>
324  wrappedInArgs = ( !is_null(nominalValues_) ? *nominalValues_ : this->createInArgs() );
325 
326  if(out.get() && static_cast<int>(verbLevel) >= static_cast<int>(Teuchos::VERB_EXTREME))
327  *out
328  << "\nwrappedInArgs after assigning to nominalValues =\n" << Teuchos::describe(wrappedInArgs,verbLevel);
329 
330  // Reset those not at their nominal values
331  wrappedInArgs.setArgs(inArgs);
332 
333  // This is a special exception: see evalModel() in Thyra::ME
334  // documentation. If inArgs() supports x_dot (or x_dot_dot) but the
335  // evaluate call passes in a null value, then we need to make sure
336  // the null value gets passed on instead of the nominal value.
337  if (wrappedInArgs.supports(Thyra::ModelEvaluatorBase::IN_ARG_x_dot)) {
338  if (is_null(inArgs.get_x_dot())) {
339  wrappedInArgs.set_x_dot(Teuchos::null);
340  }
341  }
342  if (wrappedInArgs.supports(Thyra::ModelEvaluatorBase::IN_ARG_x_dot_dot)) {
343  if (is_null(inArgs.get_x_dot_dot())) {
344  wrappedInArgs.set_x_dot_dot(Teuchos::null);
345  }
346  }
347 
348  if(out.get() && static_cast<int>(verbLevel) >= static_cast<int>(Teuchos::VERB_EXTREME))
349  *out
350  << "\nwrappedInArgs after setting input values =\n" << Teuchos::describe(wrappedInArgs,verbLevel);
351 
352  thyraModel->evalModel(wrappedInArgs,outArgs);
353 
354  THYRA_MODEL_EVALUATOR_DECORATOR_EVAL_MODEL_END();
355 
356 }
357 
358 
359 } // namespace Thyra
360 
361 
362 #endif // THYRA_DEFAULT_NOMINAL_BOUNDS_OVERRIDE_MODEL_EVALUATOR_HPP
void initialize(int *argc, char ***argv)
Pure abstract base interface for evaluating a stateless &quot;model&quot; that can be mapped into a number of d...
bool is_null(const boost::shared_ptr< T > &p)
basic_OSTab< char > OSTab
Concrete aggregate class for all output arguments computable by a ModelEvaluator subclass object...
RCP< const VectorBase< Scalar > > get_x_dot() const
Precondition: supports(IN_ARG_x_dot)==true.
This is a base class that delegetes almost all function to a wrapped model evaluator object...
void initialize(const RCP< ModelEvaluator< Scalar > > &model)
Initialize given a non-const model evaluator.
T * get() const
void setNominalValues(const RCP< const ModelEvaluatorBase::InArgs< Scalar > > &nominalValues)
Set only nominal values.
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
This class wraps any ModelEvaluator object and allows the client to overide the state contained in th...
void initialize(const RCP< ModelEvaluator< Scalar > > &thyraModel, const RCP< const ModelEvaluatorBase::InArgs< Scalar > > &nominalValues, const RCP< const ModelEvaluatorBase::InArgs< Scalar > > &lowerBounds=Teuchos::null, const RCP< const ModelEvaluatorBase::InArgs< Scalar > > &upperBounds=Teuchos::null)
Initalize.
Base subclass for ModelEvaluator that defines some basic types.
RCP< const VectorBase< Scalar > > get_x_dot_dot() const
Precondition: supports(IN_ARG_x_dot_dot)==true.
void setLowerBounds(const RCP< const ModelEvaluatorBase::InArgs< Scalar > > &lowerBounds)
Set only lower bounds.
void setUpperBounds(const RCP< const ModelEvaluatorBase::InArgs< Scalar > > &upperBounds)
Set only upper bounds.
Concrete aggregate class for all input arguments computable by a ModelEvaluator subclass object...