Thyra  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Thyra_ScaledModelEvaluator_def.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_FINITE_DIFFERENCE_MODEL_EVALUATOR_DEF_HPP
11 #define THYRA_DEFAULT_FINITE_DIFFERENCE_MODEL_EVALUATOR_DEF_HPP
12 
13 #include "Thyra_DefaultFiniteDifferenceModelEvaluator_decl.hpp"
14 #include "Thyra_ScaledLinearOpBase.hpp"
15 #include "Thyra_VectorStdOps.hpp"
16 
17 
18 namespace Thyra {
19 
20 
21 // Constructors/initializers/accessors/utilities
22 
23 
24 template<class Scalar>
26 {}
27 
28 
29 // Public functions overridden from Teuchos::Describable
30 
31 
32 template<class Scalar>
34 {
36  thyraModel = this->getUnderlyingModel();
37  std::ostringstream oss;
38  oss << "Thyra::ScaledModelEvaluator{";
39  oss << "thyraModel=";
40  if(thyraModel.get())
41  oss << "\'"<<thyraModel->description()<<"\'";
42  else
43  oss << "NULL";
44  oss << "}";
45  return oss.str();
46 }
47 
48 
49 template<class Scalar>
51 set_f_scaling(const RCP<const Thyra::VectorBase<Scalar> >& f_scaling)
52 {
53  f_scaling_ = f_scaling;
54 }
55 
56 
57 // Private functions overridden from ModelEvaulatorDefaultBase
58 
59 
60 template<class Scalar>
64  ) const
65 {
66  using Teuchos::rcp;
67  using Teuchos::rcp_const_cast;
68  using Teuchos::rcp_dynamic_cast;
69  using Teuchos::OSTab;
70 
71  THYRA_MODEL_EVALUATOR_DECORATOR_EVAL_MODEL_BEGIN(
72  "Thyra::ScaledModelEvaluator",inArgs,outArgs
73  );
74 
75  thyraModel->evalModel(inArgs, outArgs);
76 
77  if (nonnull(f_scaling_)) {
78 
79  const RCP<VectorBase<Scalar> > f = outArgs.get_f();
80  if (nonnull(f)) {
81  ele_wise_scale(*f_scaling_, f.ptr());
82  }
83 
84  const RCP<LinearOpBase<Scalar> > W_op = outArgs.get_W_op();
85  if (nonnull(W_op)) {
86  const RCP<ScaledLinearOpBase<Scalar> > W_scaled =
87  rcp_dynamic_cast<ScaledLinearOpBase<Scalar> >(W_op, true);
88  W_scaled->scaleLeft(*f_scaling_);
89  }
90 
91  }
92 
93  THYRA_MODEL_EVALUATOR_DECORATOR_EVAL_MODEL_END();
94 
95 }
96 
97 
98 } // namespace Thyra
99 
100 
101 #endif // THYRA_DEFAULT_FINITE_DIFFERENCE_MODEL_EVALUATOR_DEF_HPP
basic_OSTab< char > OSTab
Concrete aggregate class for all output arguments computable by a ModelEvaluator subclass object...
Evaluation< VectorBase< Scalar > > get_f() const
Precondition: supports(OUT_ARG_f)==true.
T * get() const
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Ptr< T > ptr() const
void set_f_scaling(const RCP< const Thyra::VectorBase< Scalar > > &f_scaling)
Abstract interface for finite-dimensional dense vectors.
ScaledModelEvaluator()
Constructs to uninitialized.
This class decorates a ModelEvaluator and returns scaled residual and Jacobian values.
bool nonnull(const boost::shared_ptr< T > &p)
RCP< LinearOpBase< Scalar > > get_W_op() const
Precondition: supports(OUT_ARG_W_op)==true.
Concrete aggregate class for all input arguments computable by a ModelEvaluator subclass object...