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"
30 template<
class Scalar>
115 template<
class Scalar>
120 template<
class Scalar>
130 template<
class Scalar>
137 W_factory_ = W_factory;
141 template<
class Scalar>
147 if(thyraModel) *thyraModel = this->getUnderlyingModel();
148 if(W_factory) *W_factory = W_factory_;
150 W_factory_ = Teuchos::null;
157 template<
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()<<
"\'";
182 template<
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();
200 template<
class Scalar>
211 template<
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);
229 template<
class Scalar>
230 void 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();
325 #endif // THYRA_DEFAULT_MODEL_EVALUATOR_WITH_SOLVE_FACTORY_HPP
void initialize(int *argc, char ***argv)
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...