Thyra  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Thyra_DefaultFinalPointCaptureModelEvaluator.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_FINAL_POINT_CAPTURE_MODEL_EVALUATOR_HPP
43 #define THYRA_DEFAULT_FINAL_POINT_CAPTURE_MODEL_EVALUATOR_HPP
44 
45 #include "Thyra_ModelEvaluatorDelegatorBase.hpp"
46 #include "Thyra_LinearOpWithSolveFactoryBase.hpp"
47 #include "Teuchos_Time.hpp"
48 
49 
50 //#define THYRA_DEFAULT_FINAL_POINT_CAPTURE_MODEL_EVALUATOR_DUMP_ALL
51 
52 
53 namespace Thyra {
54 
55 
63 template<class Scalar>
65  : virtual public ModelEvaluatorDelegatorBase<Scalar>
66 {
67 public:
68 
71 
74 
77 
80  const Teuchos::RCP<ModelEvaluator<Scalar> > &thyraModel
81  );
82 
85 
87  bool finalPointWasSolved() const;
88 
90 
93 
95  std::string description() const;
96 
98 
101 
103  void reportFinalPoint(
104  const ModelEvaluatorBase::InArgs<Scalar> &finalPoint,
105  const bool wasSolved
106  );
107 
109 
110 private:
111 
114 
116  void evalModelImpl(
119  ) const;
120 
122 
123 private:
124 
126  bool finalPointWasSolved_;
127 
128 };
129 
130 
131 // /////////////////////////////////
132 // Implementations
133 
134 
135 // Constructors/initializers/accessors/utilities
136 
137 
138 template<class Scalar>
140  :finalPointWasSolved_(false)
141 {}
142 
143 
144 template<class Scalar>
146  const Teuchos::RCP<ModelEvaluator<Scalar> > &thyraModel
147  )
148 {
150  finalPoint_ = thyraModel->createInArgs();
151  finalPoint_.setArgs(thyraModel->getNominalValues());
152  finalPointWasSolved_ = false;
153 }
154 
155 
156 template<class Scalar>
159 {
160 #ifdef THYRA_DEFAULT_FINAL_POINT_CAPTURE_MODEL_EVALUATOR_DUMP_ALL
162  << "\nDefaultFinalPointCaptureModelEvaluator<Scalar>::getFinalPoint():"
163  << " finalPoint =\n" << Teuchos::describe(finalPoint_,Teuchos::VERB_EXTREME);
164 #endif
165  return finalPoint_;
166 }
167 
168 
169 template<class Scalar>
171 {
172  return finalPointWasSolved_;
173 }
174 
175 
176 // Public functions overridden from Teuchos::Describable
177 
178 
179 template<class Scalar>
181 {
183  thyraModel = this->getUnderlyingModel();
184  std::ostringstream oss;
185  oss << "Thyra::DefaultFinalPointCaptureModelEvaluator{";
186  oss << "thyraModel=";
187  if(thyraModel.get())
188  oss << "\'"<<thyraModel->description()<<"\'";
189  else
190  oss << "NULL";
191  oss << "}";
192  return oss.str();
193 }
194 
195 
196 // Overridden from ModelEvaulator.
197 
198 
199 template<class Scalar>
201  const ModelEvaluatorBase::InArgs<Scalar> &finalPoint,
202  const bool wasSolved
203  )
204 {
205  finalPoint_.setArgs(finalPoint);
206  finalPointWasSolved_ = wasSolved;
207  if(!this->isUnderlyingModelConst())
208  this->getNonconstUnderlyingModel()->reportFinalPoint(finalPoint,wasSolved);
209 #ifdef THYRA_DEFAULT_FINAL_POINT_CAPTURE_MODEL_EVALUATOR_DUMP_ALL
211  << "\nDefaultFinalPointCaptureModelEvaluator<Scalar>::reportFinalPoint(...):"
212  << " finalPoint =\n" << Teuchos::describe(finalPoint_,Teuchos::VERB_EXTREME);
213 #endif
214 }
215 
216 
217 // Private functions overridden from ModelEvaulatorDefaultBase
218 
219 
220 template<class Scalar>
224  ) const
225 {
226 
227  THYRA_MODEL_EVALUATOR_DECORATOR_EVAL_MODEL_BEGIN(
228  "Thyra::DefaultFinalPointCaptureModelEvaluator",inArgs,outArgs
229  );
230 
231  thyraModel->evalModel(inArgs,outArgs);
232 
233  THYRA_MODEL_EVALUATOR_DECORATOR_EVAL_MODEL_END();
234 
235 }
236 
237 
238 } // namespace Thyra
239 
240 
241 #endif // THYRA_DEFAULT_FINAL_POINT_CAPTURE_MODEL_EVALUATOR_HPP
void reportFinalPoint(const ModelEvaluatorBase::InArgs< Scalar > &finalPoint, const bool wasSolved)
Pure abstract base interface for evaluating a stateless &quot;model&quot; that can be mapped into a number of d...
Concrete aggregate class for all output arguments computable by a ModelEvaluator subclass object...
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
const ModelEvaluatorBase::InArgs< Scalar > & getFinalPoint() const
static RCP< FancyOStream > getDefaultOStream()
This class wraps any ModelEvaluator object and allows the client to capture the final point that is r...
Concrete aggregate class for all input arguments computable by a ModelEvaluator subclass object...