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>
106 RCP<LinearOpWithSolveBase<Scalar> >
create_W()
const;
114 RCP<const LinearOpWithSolveFactoryBase<Scalar> >
get_W_factory()
const;
135 RCP<LinearOpWithSolveFactoryBase<Scalar> > W_factory_;
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>
192 const RCP<const ModelEvaluator<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>
215 RCP<LinearOpWithSolveBase<Scalar> >
218 TEUCHOS_TEST_FOR_EXCEPTION(
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>
233 RCP<const LinearOpWithSolveFactoryBase<Scalar> >
243 template<
class Scalar>
248 const RCP<const ModelEvaluator<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;
271 using Teuchos::OSTab;
273 THYRA_MODEL_EVALUATOR_DECORATOR_EVAL_MODEL_BEGIN(
274 "Thyra::DefaultModelEvaluatorWithSolveFactory",inArgs,outArgs
277 Teuchos::Time timer(
"");
279 typedef Teuchos::VerboseObjectTempState<LinearOpWithSolveFactoryBase<Scalar> >
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());
303 TEUCHOS_TEST_FOR_EXCEPT(both_W_and_W_op_requested);
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);
320 if(out.get() && includesVerbLevel(verbLevel,Teuchos::VERB_LOW))
321 *out <<
"\nEvaluating the output functions on model \'" 322 << thyraModel->description() <<
"\' ...\n";
325 thyraModel->evalModel(wrappedInArgs,wrappedOutArgs);
328 if(out.get() && includesVerbLevel(verbLevel,Teuchos::VERB_LOW))
329 OSTab(out).o() <<
"\nTime to evaluate underlying model = " 330 << timer.totalElapsedTime()<<
" sec\n";
334 if(out.get() && includesVerbLevel(verbLevel,Teuchos::VERB_LOW))
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());
345 if(out.get() && includesVerbLevel(verbLevel,Teuchos::VERB_LOW))
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...
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...
void initialize(const RCP< ModelEvaluator< Scalar > > &model)
Initialize given a non-const model evaluator.
RCP< const LinearOpWithSolveFactoryBase< Scalar > > get_W_factory() const
Factory interface for creating LinearOpWithSolveBase objects from compatible LinearOpBase objects...
Base subclass for ModelEvaluator that defines some basic types.
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...
RCP< LinearOpWithSolveBase< Scalar > > create_W() const
std::string description() const
DefaultModelEvaluatorWithSolveFactory()
Concrete aggregate class for all output arguments computable by a ModelEvaluator subclass object...