42 #ifndef THYRA_DEFAULT_MODEL_EVALUATOR_WITH_SOLVE_FACTORY_HPP
43 #define THYRA_DEFAULT_MODEL_EVALUATOR_WITH_SOLVE_FACTORY_HPP
46 #include "Thyra_ModelEvaluatorDelegatorBase.hpp"
47 #include "Thyra_LinearOpWithSolveFactoryHelpers.hpp"
48 #include "Teuchos_Time.hpp"
62 template<
class Scalar>
147 template<
class Scalar>
152 template<
class Scalar>
158 initialize(thyraModel,W_factory);
162 template<
class Scalar>
169 W_factory_ = W_factory;
173 template<
class Scalar>
179 if(thyraModel) *thyraModel = this->getUnderlyingModel();
180 if(W_factory) *W_factory = W_factory_;
182 W_factory_ = Teuchos::null;
189 template<
class Scalar>
193 thyraModel = this->getUnderlyingModel();
194 std::ostringstream oss;
195 oss <<
"Thyra::DefaultModelEvaluatorWithSolveFactory{";
196 oss <<
"thyraModel=";
198 oss <<
"\'"<<thyraModel->description()<<
"\'";
201 oss <<
",W_factory=";
203 oss <<
"\'"<<W_factory_->description()<<
"\'";
214 template<
class Scalar>
219 W_factory_.get()==NULL, std::logic_error
220 ,
"Thyra::DefaultModelEvaluatorWithSolveFactory<Scalar>::create_W(): "
221 "Error, the client did not set a LinearOpWithSolveFactoryBase object for W!"
223 W_factory_->setOStream(this->getOStream());
224 W_factory_->setVerbLevel(this->getVerbLevel());
225 return W_factory_->createOp();
232 template<
class Scalar>
243 template<
class Scalar>
249 thyraModel = this->getUnderlyingModel();
250 const MEB::OutArgs<Scalar> wrappedOutArgs = thyraModel->createOutArgs();
251 MEB::OutArgsSetup<Scalar> outArgs;
252 outArgs.setModelEvalDescription(this->description());
253 outArgs.set_Np_Ng(wrappedOutArgs.Np(),wrappedOutArgs.Ng());
254 outArgs.setSupports(wrappedOutArgs);
255 outArgs.setSupports(MEB::OUT_ARG_W,
256 wrappedOutArgs.supports(MEB::OUT_ARG_W_op)&&W_factory_.get()!=NULL);
261 template<
class Scalar>
262 void DefaultModelEvaluatorWithSolveFactory<Scalar>::evalModelImpl(
263 const ModelEvaluatorBase::InArgs<Scalar> &inArgs,
264 const ModelEvaluatorBase::OutArgs<Scalar> &outArgs
267 typedef ModelEvaluatorBase MEB;
269 using Teuchos::rcp_const_cast;
270 using Teuchos::rcp_dynamic_cast;
273 THYRA_MODEL_EVALUATOR_DECORATOR_EVAL_MODEL_BEGIN(
274 "Thyra::DefaultModelEvaluatorWithSolveFactory",inArgs,outArgs
281 VOTSLOWSF W_factory_outputTempState(W_factory_,out,verbLevel);
285 MEB::InArgs<Scalar> wrappedInArgs = thyraModel->createInArgs();
287 wrappedInArgs.setArgs(inArgs,
true);
291 MEB::OutArgs<Scalar> wrappedOutArgs = thyraModel->createOutArgs();
293 wrappedOutArgs.setArgs(outArgs,
true);
295 RCP<LinearOpWithSolveBase<Scalar> > W;
296 RCP<const LinearOpBase<Scalar> > fwdW;
297 if( outArgs.supports(MEB::OUT_ARG_W) && (W = outArgs.get_W()).
get() ) {
298 Thyra::uninitializeOp<Scalar>(*W_factory_, W.ptr(), outArg(fwdW));
302 const bool both_W_and_W_op_requested =
nonnull(outArgs.get_W_op());
306 RCP<LinearOpBase<Scalar> > nonconst_fwdW;
308 nonconst_fwdW = rcp_const_cast<LinearOpBase<Scalar> >(fwdW);
311 nonconst_fwdW = thyraModel->create_W_op();
312 fwdW = nonconst_fwdW;
315 wrappedOutArgs.set_W_op(nonconst_fwdW);
321 *out <<
"\nEvaluating the output functions on model \'"
322 << thyraModel->description() <<
"\' ...\n";
325 thyraModel->evalModel(wrappedInArgs,wrappedOutArgs);
329 OSTab(out).o() <<
"\nTime to evaluate underlying model = "
330 << timer.totalElapsedTime()<<
" sec\n";
335 *out <<
"\nPost processing the output objects ...\n";
339 Thyra::initializeOp<Scalar>(*W_factory_, fwdW, W.ptr());
340 W->setVerbLevel(this->getVerbLevel());
341 W->setOStream(this->getOStream());
346 OSTab(out).o() <<
"\nTime to process output objects = "
347 << timer.totalElapsedTime()<<
" sec\n";
349 THYRA_MODEL_EVALUATOR_DECORATOR_EVAL_MODEL_END();
357 #endif // THYRA_DEFAULT_MODEL_EVALUATOR_WITH_SOLVE_FACTORY_HPP
Pure abstract base interface for evaluating a stateless "model" that can be mapped into a number of d...
RCP< LinearOpWithSolveBase< Scalar > > create_W() const
basic_OSTab< char > OSTab
Concrete aggregate class for all output arguments computable by a ModelEvaluator subclass object...
void uninitialize()
Uninitialize.
This is a base class that delegetes almost all function to a wrapped model evaluator object...
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
void initialize(const RCP< ModelEvaluator< Scalar > > &model)
Initialize given a non-const model evaluator.
std::string description() const
RCP< const LinearOpWithSolveFactoryBase< Scalar > > get_W_factory() const
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Factory interface for creating LinearOpWithSolveBase objects from compatible LinearOpBase objects...
TEUCHOSCORE_LIB_DLL_EXPORT bool includesVerbLevel(const EVerbosityLevel verbLevel, const EVerbosityLevel requestedVerbLevel, const bool isDefaultLevel=false)
Base subclass for ModelEvaluator that defines some basic types.
bool nonnull(const boost::shared_ptr< T > &p)
void initialize(const RCP< ModelEvaluator< Scalar > > &thyraModel, const RCP< LinearOpWithSolveFactoryBase< Scalar > > &W_factory)
This class wraps any ModelEvaluator object and uses a compatible LinearOpWithSolveFactory object to c...
DefaultModelEvaluatorWithSolveFactory()
#define TEUCHOS_TEST_FOR_EXCEPT(throw_exception_test)
Concrete aggregate class for all input arguments computable by a ModelEvaluator subclass object...