10#ifndef THYRA_DEFAULT_MODEL_EVALUATOR_WITH_SOLVE_FACTORY_HPP
11#define THYRA_DEFAULT_MODEL_EVALUATOR_WITH_SOLVE_FACTORY_HPP
14#include "Thyra_ModelEvaluatorDelegatorBase.hpp"
15#include "Thyra_LinearOpWithSolveFactoryHelpers.hpp"
16#include "Teuchos_Time.hpp"
115template<
class Scalar>
120template<
class Scalar>
126 initialize(thyraModel,W_factory);
130template<
class Scalar>
137 W_factory_ = W_factory;
141template<
class Scalar>
147 if(thyraModel) *thyraModel = this->getUnderlyingModel();
148 if(W_factory) *W_factory = W_factory_;
157template<
class Scalar>
161 thyraModel = this->getUnderlyingModel();
162 std::ostringstream oss;
163 oss <<
"Thyra::DefaultModelEvaluatorWithSolveFactory{";
164 oss <<
"thyraModel=";
166 oss <<
"\'"<<thyraModel->description()<<
"\'";
169 oss <<
",W_factory=";
171 oss <<
"\'"<<W_factory_->description()<<
"\'";
182template<
class Scalar>
187 W_factory_.get()==NULL, std::logic_error
188 ,
"Thyra::DefaultModelEvaluatorWithSolveFactory<Scalar>::create_W(): "
189 "Error, the client did not set a LinearOpWithSolveFactoryBase object for W!"
191 W_factory_->setOStream(this->getOStream());
192 W_factory_->setVerbLevel(this->getVerbLevel());
193 return W_factory_->createOp();
200template<
class Scalar>
211template<
class Scalar>
217 thyraModel = this->getUnderlyingModel();
218 const MEB::OutArgs<Scalar> wrappedOutArgs = thyraModel->createOutArgs();
219 MEB::OutArgsSetup<Scalar> outArgs;
220 outArgs.setModelEvalDescription(this->description());
221 outArgs.set_Np_Ng(wrappedOutArgs.Np(),wrappedOutArgs.Ng());
222 outArgs.setSupports(wrappedOutArgs);
223 outArgs.setSupports(MEB::OUT_ARG_W,
224 wrappedOutArgs.supports(MEB::OUT_ARG_W_op)&&W_factory_.get()!=NULL);
229template<
class Scalar>
230void DefaultModelEvaluatorWithSolveFactory<Scalar>::evalModelImpl(
231 const ModelEvaluatorBase::InArgs<Scalar> &inArgs,
232 const ModelEvaluatorBase::OutArgs<Scalar> &outArgs
235 typedef ModelEvaluatorBase MEB;
237 using Teuchos::rcp_const_cast;
238 using Teuchos::rcp_dynamic_cast;
241 THYRA_MODEL_EVALUATOR_DECORATOR_EVAL_MODEL_BEGIN(
242 "Thyra::DefaultModelEvaluatorWithSolveFactory",inArgs,outArgs
249 VOTSLOWSF W_factory_outputTempState(W_factory_,out,verbLevel);
253 MEB::InArgs<Scalar> wrappedInArgs = thyraModel->createInArgs();
255 wrappedInArgs.setArgs(inArgs,
true);
259 MEB::OutArgs<Scalar> wrappedOutArgs = thyraModel->createOutArgs();
261 wrappedOutArgs.setArgs(outArgs,
true);
263 RCP<LinearOpWithSolveBase<Scalar> > W;
264 RCP<const LinearOpBase<Scalar> > fwdW;
265 if( outArgs.supports(MEB::OUT_ARG_W) && (W = outArgs.get_W()).get() ) {
266 Thyra::uninitializeOp<Scalar>(*W_factory_, W.ptr(), outArg(fwdW));
270 const bool both_W_and_W_op_requested = nonnull(outArgs.get_W_op());
274 RCP<LinearOpBase<Scalar> > nonconst_fwdW;
276 nonconst_fwdW = rcp_const_cast<LinearOpBase<Scalar> >(fwdW);
279 nonconst_fwdW = thyraModel->create_W_op();
280 fwdW = nonconst_fwdW;
283 wrappedOutArgs.set_W_op(nonconst_fwdW);
289 *out <<
"\nEvaluating the output functions on model \'"
290 << thyraModel->description() <<
"\' ...\n";
293 thyraModel->evalModel(wrappedInArgs,wrappedOutArgs);
297 OSTab(out).o() <<
"\nTime to evaluate underlying model = "
298 << timer.totalElapsedTime()<<
" sec\n";
303 *out <<
"\nPost processing the output objects ...\n";
307 Thyra::initializeOp<Scalar>(*W_factory_, fwdW, W.ptr());
308 W->setVerbLevel(this->getVerbLevel());
309 W->setOStream(this->getOStream());
314 OSTab(out).o() <<
"\nTime to process output objects = "
315 << timer.totalElapsedTime()<<
" sec\n";
317 THYRA_MODEL_EVALUATOR_DECORATOR_EVAL_MODEL_END();
This class wraps any ModelEvaluator object and uses a compatible LinearOpWithSolveFactory object to c...
void initialize(const RCP< ModelEvaluator< Scalar > > &thyraModel, const RCP< LinearOpWithSolveFactoryBase< Scalar > > &W_factory)
RCP< const LinearOpWithSolveFactoryBase< Scalar > > get_W_factory() const
RCP< LinearOpWithSolveBase< Scalar > > create_W() const
DefaultModelEvaluatorWithSolveFactory()
std::string description() const
Factory interface for creating LinearOpWithSolveBase objects from compatible LinearOpBase objects.
Concrete aggregate class for all input arguments computable by a ModelEvaluator subclass object.
Concrete aggregate class for all output arguments computable by a ModelEvaluator subclass object.
Base subclass for ModelEvaluator that defines some basic types.
This is a base class that delegetes almost all function to a wrapped model evaluator object.
void uninitialize()
Uninitialize.
void initialize(const RCP< ModelEvaluator< Scalar > > &model)
Initialize given a non-const model evaluator.
Pure abstract base interface for evaluating a stateless "model" that can be mapped into a number of d...
#define TEUCHOS_TEST_FOR_EXCEPT(throw_exception_test)
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
T_To & dyn_cast(T_From &from)
basic_OSTab< char > OSTab
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
TEUCHOSCORE_LIB_DLL_EXPORT bool includesVerbLevel(const EVerbosityLevel verbLevel, const EVerbosityLevel requestedVerbLevel, const bool isDefaultLevel=false)