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 //
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_FINITE_DIFFERENCE_MODEL_EVALUATOR_DEF_HPP
43 #define THYRA_DEFAULT_FINITE_DIFFERENCE_MODEL_EVALUATOR_DEF_HPP
44 
45 #include "Thyra_DefaultFiniteDifferenceModelEvaluator_decl.hpp"
46 #include "Thyra_ScaledLinearOpBase.hpp"
47 #include "Thyra_VectorStdOps.hpp"
48 
49 
50 namespace Thyra {
51 
52 
53 // Constructors/initializers/accessors/utilities
54 
55 
56 template<class Scalar>
58 {}
59 
60 
61 // Public functions overridden from Teuchos::Describable
62 
63 
64 template<class Scalar>
66 {
68  thyraModel = this->getUnderlyingModel();
69  std::ostringstream oss;
70  oss << "Thyra::ScaledModelEvaluator{";
71  oss << "thyraModel=";
72  if(thyraModel.get())
73  oss << "\'"<<thyraModel->description()<<"\'";
74  else
75  oss << "NULL";
76  oss << "}";
77  return oss.str();
78 }
79 
80 
81 template<class Scalar>
83 set_f_scaling(const RCP<const Thyra::VectorBase<Scalar> >& f_scaling)
84 {
85  f_scaling_ = f_scaling;
86 }
87 
88 
89 // Private functions overridden from ModelEvaulatorDefaultBase
90 
91 
92 template<class Scalar>
96  ) const
97 {
98  using Teuchos::rcp;
99  using Teuchos::rcp_const_cast;
100  using Teuchos::rcp_dynamic_cast;
101  using Teuchos::OSTab;
102 
103  THYRA_MODEL_EVALUATOR_DECORATOR_EVAL_MODEL_BEGIN(
104  "Thyra::ScaledModelEvaluator",inArgs,outArgs
105  );
106 
107  thyraModel->evalModel(inArgs, outArgs);
108 
109  if (nonnull(f_scaling_)) {
110 
111  const RCP<VectorBase<Scalar> > f = outArgs.get_f();
112  if (nonnull(f)) {
113  ele_wise_scale(*f_scaling_, f.ptr());
114  }
115 
116  const RCP<LinearOpBase<Scalar> > W_op = outArgs.get_W_op();
117  if (nonnull(W_op)) {
118  const RCP<ScaledLinearOpBase<Scalar> > W_scaled =
119  rcp_dynamic_cast<ScaledLinearOpBase<Scalar> >(W_op, true);
120  W_scaled->scaleLeft(*f_scaling_);
121  }
122 
123  }
124 
125  THYRA_MODEL_EVALUATOR_DECORATOR_EVAL_MODEL_END();
126 
127 }
128 
129 
130 } // namespace Thyra
131 
132 
133 #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...