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 //
4 // Thyra: Interfaces and Support for Abstract Numerical Algorithms
5 // Copyright (2004) Sandia Corporation
6 //
7 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
8 // license for use of this work by or on behalf of the U.S. Government.
9 //
10 // Redistribution and use in source and binary forms, with or without
11 // modification, are permitted provided that the following conditions are
12 // met:
13 //
14 // 1. Redistributions of source code must retain the above copyright
15 // notice, this list of conditions and the following disclaimer.
16 //
17 // 2. Redistributions in binary form must reproduce the above copyright
18 // notice, this list of conditions and the following disclaimer in the
19 // documentation and/or other materials provided with the distribution.
20 //
21 // 3. Neither the name of the Corporation nor the names of the
22 // contributors may be used to endorse or promote products derived from
23 // this software without specific prior written permission.
24 //
25 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
26 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
29 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 //
37 // Questions? Contact Roscoe A. Bartlett (bartlettra@ornl.gov)
38 //
39 // ***********************************************************************
40 // @HEADER
41 
42 #ifndef THYRA_DEFAULT_NOMINAL_BOUNDS_OVERRIDE_MODEL_EVALUATOR_HPP
43 #define THYRA_DEFAULT_NOMINAL_BOUNDS_OVERRIDE_MODEL_EVALUATOR_HPP
44 
45 
46 #include "Thyra_ModelEvaluatorDelegatorBase.hpp"
47 #include "Thyra_LinearOpWithSolveFactoryBase.hpp"
48 #include "Teuchos_Time.hpp"
49 
50 
51 namespace Thyra {
52 
53 
100 template<class Scalar>
102  : virtual public ModelEvaluatorDelegatorBase<Scalar>
103 {
104 public:
105 
108 
111 
114 
117  const RCP<ModelEvaluator<Scalar> > &thyraModel,
118  const RCP<const ModelEvaluatorBase::InArgs<Scalar> > &nominalValues,
119  const RCP<const ModelEvaluatorBase::InArgs<Scalar> > &lowerBounds = Teuchos::null,
120  const RCP<const ModelEvaluatorBase::InArgs<Scalar> > &upperBounds = Teuchos::null
121  );
122 
147  void initialize(
148  const RCP<ModelEvaluator<Scalar> > &thyraModel,
149  const RCP<const ModelEvaluatorBase::InArgs<Scalar> > &nominalValues,
150  const RCP<const ModelEvaluatorBase::InArgs<Scalar> > &lowerBounds = Teuchos::null,
151  const RCP<const ModelEvaluatorBase::InArgs<Scalar> > &upperBounds = Teuchos::null
152  );
153 
155  void setNominalValues(
156  const RCP<const ModelEvaluatorBase::InArgs<Scalar> > &nominalValues
157  );
158 
160  void setLowerBounds(
161  const RCP<const ModelEvaluatorBase::InArgs<Scalar> > &lowerBounds
162  );
163 
165  void setUpperBounds(
166  const RCP<const ModelEvaluatorBase::InArgs<Scalar> > &upperBounds
167  );
168 
169  // ToDo: Add functions to reset lower and upper bounds when needed!
170 
172 
175 
177  std::string description() const;
178 
180 
183 
190 
192 
193 private:
194 
197 
199  void evalModelImpl(
202  ) const;
203 
205 
206 private:
207 
211 
212 };
213 
214 
215 // /////////////////////////////////
216 // Implementations
217 
218 
219 // Constructors/initializers/accessors/utilities
220 
221 
222 template<class Scalar>
224 {}
225 
226 
227 template<class Scalar>
229  const RCP<ModelEvaluator<Scalar> > &thyraModel,
230  const RCP<const ModelEvaluatorBase::InArgs<Scalar> > &nominalValues,
231  const RCP<const ModelEvaluatorBase::InArgs<Scalar> > &lowerBounds,
232  const RCP<const ModelEvaluatorBase::InArgs<Scalar> > &upperBounds
233  )
234 {
235  initialize(thyraModel,nominalValues,lowerBounds,upperBounds);
236 }
237 
238 
239 template<class Scalar>
241  const RCP<ModelEvaluator<Scalar> > &thyraModel,
242  const RCP<const ModelEvaluatorBase::InArgs<Scalar> > &nominalValues,
243  const RCP<const ModelEvaluatorBase::InArgs<Scalar> > &lowerBounds,
244  const RCP<const ModelEvaluatorBase::InArgs<Scalar> > &upperBounds
245  )
246 {
248  nominalValues_ = nominalValues;
249  lowerBounds_ = lowerBounds;
250  upperBounds_ = upperBounds;
251 }
252 
253 
254 template<class Scalar>
256  const RCP<const ModelEvaluatorBase::InArgs<Scalar> > &nominalValues
257  )
258 {
259  nominalValues_ = nominalValues;
260 }
261 
262 
263 template<class Scalar>
265  const RCP<const ModelEvaluatorBase::InArgs<Scalar> > &lowerBounds
266  )
267 {
268  lowerBounds_ = lowerBounds;
269 }
270 
271 
272 template<class Scalar>
274  const RCP<const ModelEvaluatorBase::InArgs<Scalar> > &upperBounds
275  )
276 {
277  upperBounds_ = upperBounds;
278 }
279 
280 
281 // Public functions overridden from Teuchos::Describable
282 
283 
284 template<class Scalar>
286 {
288  thyraModel = this->getUnderlyingModel();
289  std::ostringstream oss;
290  oss << "Thyra::DefaultNominalBoundsOverrideModelEvaluator{";
291  oss << "thyraModel=";
292  if(thyraModel.get())
293  oss << "\'"<<thyraModel->description()<<"\'";
294  else
295  oss << "NULL";
296  oss << "}";
297  return oss.str();
298 }
299 
300 
301 // Overridden from ModelEvaulator.
302 
303 
304 template<class Scalar>
307 {
308  if(nominalValues_.get())
309  return *nominalValues_;
310  return this->getUnderlyingModel()->getNominalValues();
311 }
312 
313 
314 template<class Scalar>
317 {
318  if(lowerBounds_.get())
319  return *lowerBounds_;
320  return this->getUnderlyingModel()->getLowerBounds();
321 }
322 
323 
324 template<class Scalar>
327 {
328  if(upperBounds_.get())
329  return *upperBounds_;
330  return this->getUnderlyingModel()->getUpperBounds();
331 }
332 
333 
334 // Private functions overridden from ModelEvaulatorDefaultBase
335 
336 
337 template<class Scalar>
341  ) const
342 {
343 
344  using Teuchos::rcp;
345  using Teuchos::rcp_const_cast;
346  using Teuchos::rcp_dynamic_cast;
347  using Teuchos::OSTab;
348  typedef ModelEvaluatorBase MEB;
349 
350  THYRA_MODEL_EVALUATOR_DECORATOR_EVAL_MODEL_BEGIN(
351  "Thyra::DefaultNominalBoundsOverrideModelEvaluator",inArgs,outArgs
352  );
353 
354  // First set the inArgs to what was overridden
355  MEB::InArgs<Scalar>
356  wrappedInArgs = ( !is_null(nominalValues_) ? *nominalValues_ : this->createInArgs() );
357 
358  if(out.get() && static_cast<int>(verbLevel) >= static_cast<int>(Teuchos::VERB_EXTREME))
359  *out
360  << "\nwrappedInArgs after assigning to nominalValues =\n" << Teuchos::describe(wrappedInArgs,verbLevel);
361 
362  // Reset those not at their nominal values
363  wrappedInArgs.setArgs(inArgs);
364 
365  // This is a special exception: see evalModel() in Thyra::ME
366  // documentation. If inArgs() supports x_dot (or x_dot_dot) but the
367  // evaluate call passes in a null value, then we need to make sure
368  // the null value gets passed on instead of the nominal value.
369  if (wrappedInArgs.supports(Thyra::ModelEvaluatorBase::IN_ARG_x_dot)) {
370  if (is_null(inArgs.get_x_dot())) {
371  wrappedInArgs.set_x_dot(Teuchos::null);
372  }
373  }
374  if (wrappedInArgs.supports(Thyra::ModelEvaluatorBase::IN_ARG_x_dot_dot)) {
375  if (is_null(inArgs.get_x_dot_dot())) {
376  wrappedInArgs.set_x_dot_dot(Teuchos::null);
377  }
378  }
379 
380  if(out.get() && static_cast<int>(verbLevel) >= static_cast<int>(Teuchos::VERB_EXTREME))
381  *out
382  << "\nwrappedInArgs after setting input values =\n" << Teuchos::describe(wrappedInArgs,verbLevel);
383 
384  thyraModel->evalModel(wrappedInArgs,outArgs);
385 
386  THYRA_MODEL_EVALUATOR_DECORATOR_EVAL_MODEL_END();
387 
388 }
389 
390 
391 } // namespace Thyra
392 
393 
394 #endif // THYRA_DEFAULT_NOMINAL_BOUNDS_OVERRIDE_MODEL_EVALUATOR_HPP
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...