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"
115template<
class Scalar>
120template<
class Scalar>
130template<
class Scalar>
137 W_factory_ = W_factory;
141template<
class Scalar>
148 if(W_factory) *W_factory = W_factory_;
150 W_factory_ = Teuchos::null;
157template<
class Scalar>
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!"
193 return W_factory_->createOp();
200template<
class Scalar>
211template<
class Scalar>
213DefaultModelEvaluatorWithSolveFactory<Scalar>::createOutArgsImpl()
const
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() ) {
270 const bool both_W_and_W_op_requested = nonnull(outArgs.get_W_op());
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();
virtual RCP< FancyOStream > getOStream() const
virtual EVerbosityLevel getVerbLevel() const
basic_FancyOStream< CharT, Traits > & o() const
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.
void uninitializeOp(const LinearOpWithSolveFactoryBase< Scalar > &lowsFactory, const Ptr< LinearOpWithSolveBase< Scalar > > &Op, const Ptr< RCP< const LinearOpBase< Scalar > > > &fwdOp=Teuchos::null, const Ptr< RCP< const PreconditionerBase< Scalar > > > &prec=Teuchos::null, const Ptr< RCP< const LinearOpBase< Scalar > > > &approxFwdOp=Teuchos::null, const Ptr< ESupportSolveUse > &supportSolveUse=Teuchos::null)
Uninitialized a pre-created LOWSB object, returning input objects used to initialize it.
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.
ModelEvaluatorDelegatorBase()
Constructs to uninitialized.
virtual RCP< const ModelEvaluator< Scalar > > getUnderlyingModel() const
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)
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)