42 #ifndef THYRA_DEFAULT_STATE_ELIMINATION_MODEL_EVALUATOR_HPP
43 #define THYRA_DEFAULT_STATE_ELIMINATION_MODEL_EVALUATOR_HPP
45 #include "Thyra_ModelEvaluatorDelegatorBase.hpp"
46 #include "Thyra_DefaultNominalBoundsOverrideModelEvaluator.hpp"
47 #include "Thyra_NonlinearSolverBase.hpp"
48 #include "Teuchos_Time.hpp"
61 template<
class Scalar>
155 template<
class Scalar>
159 template<
class Scalar>
165 initialize(thyraModel,stateSolver);
168 template<
class Scalar>
176 stateSolver_ = stateSolver;
177 x_guess_solu_ = Teuchos::null;
184 stateSolver_->setModel(wrappedThyraModel_);
187 template<
class Scalar>
193 if(thyraModel) *thyraModel = this->getUnderlyingModel();
194 if(stateSolver) *stateSolver = stateSolver_;
196 stateSolver_ = Teuchos::null;
197 wrappedThyraModel_ = Teuchos::null;
198 x_guess_solu_ = Teuchos::null;
204 template<
class Scalar>
208 thyraModel = this->getUnderlyingModel();
209 std::ostringstream oss;
210 oss <<
"Thyra::DefaultStateEliminationModelEvaluator{";
211 oss <<
"thyraModel=";
213 oss <<
"\'"<<thyraModel->description()<<
"\'";
216 oss <<
",stateSolver=";
217 if(stateSolver_.get())
218 oss <<
"\'"<<stateSolver_->description()<<
"\'";
227 template<
class Scalar>
231 return Teuchos::null;
234 template<
class Scalar>
238 return Teuchos::null;
241 template<
class Scalar>
247 thyraModel = this->getUnderlyingModel();
248 MEB::InArgsSetup<Scalar> nominalValues(thyraModel->getNominalValues());
249 nominalValues.setModelEvalDescription(this->description());
250 nominalValues.setUnsupportsAndRelated(MEB::IN_ARG_x);
251 return nominalValues;
254 template<
class Scalar>
260 thyraModel = this->getUnderlyingModel();
261 MEB::InArgsSetup<Scalar> lowerBounds(thyraModel->getLowerBounds());
262 lowerBounds.setModelEvalDescription(this->description());
263 lowerBounds.setUnsupportsAndRelated(MEB::IN_ARG_x);
267 template<
class Scalar>
273 thyraModel = this->getUnderlyingModel();
274 MEB::InArgsSetup<Scalar> upperBounds(thyraModel->getUpperBounds());
275 upperBounds.setModelEvalDescription(this->description());
276 upperBounds.setUnsupportsAndRelated(MEB::IN_ARG_x);
280 template<
class Scalar>
284 return Teuchos::null;
287 template<
class Scalar>
291 return Teuchos::null;
295 template<
class Scalar>
301 thyraModel = this->getUnderlyingModel();
302 const MEB::InArgs<Scalar> wrappedInArgs = thyraModel->createInArgs();
303 MEB::InArgsSetup<Scalar> inArgs;
304 inArgs.setModelEvalDescription(this->description());
305 inArgs.set_Np(wrappedInArgs.Np());
306 inArgs.setSupports(wrappedInArgs);
307 inArgs.setUnsupportsAndRelated(MEB::IN_ARG_x);
315 template<
class Scalar>
321 thyraModel = this->getUnderlyingModel();
322 const MEB::OutArgs<Scalar> wrappedOutArgs = thyraModel->createOutArgs();
323 const int Np = wrappedOutArgs.Np(), Ng = wrappedOutArgs.Ng();
324 MEB::OutArgsSetup<Scalar> outArgs;
325 outArgs.setModelEvalDescription(this->description());
326 outArgs.set_Np_Ng(Np,Ng);
327 outArgs.setSupports(wrappedOutArgs);
328 outArgs.setUnsupportsAndRelated(MEB::IN_ARG_x);
329 outArgs.setUnsupportsAndRelated(MEB::OUT_ARG_f);
333 template<
class Scalar>
334 void DefaultStateEliminationModelEvaluator<Scalar>::evalModelImpl(
335 const ModelEvaluatorBase::InArgs<Scalar> &inArgs,
336 const ModelEvaluatorBase::OutArgs<Scalar> &outArgs
339 typedef ModelEvaluatorBase MEB;
341 using Teuchos::rcp_const_cast;
342 using Teuchos::rcp_dynamic_cast;
347 totalTimer.start(
true);
353 *out <<
"\nEntering Thyra::DefaultStateEliminationModelEvaluator<Scalar>::evalModel(...) ...\n";
356 thyraModel = this->getUnderlyingModel();
358 const int Np = outArgs.Np(), Ng = outArgs.Ng();
362 const ModelEvaluatorBase::InArgs<Scalar>
363 nominalValues = thyraModel->getNominalValues();
364 if(nominalValues.get_x().get()) {
365 x_guess_solu_ = nominalValues.get_x()->clone_v();
368 x_guess_solu_ = createMember(thyraModel->get_x_space());
369 assign(x_guess_solu_.ptr(), as<Scalar>(0.0));
374 MEB::InArgs<Scalar> wrappedNominalValues = thyraModel->getNominalValues();
375 wrappedNominalValues.setArgs(inArgs,
true);
376 wrappedNominalValues.set_x(x_guess_solu_);
382 VOTSNSB statSolver_outputTempState(
389 <<
"\ninArgs =\n" << Teuchos::describe(inArgs,verbLevel)
393 *out <<
"\nSolving f(x,...) for x ...\n";
395 wrappedThyraModel_->setNominalValues(
396 rcp(
new MEB::InArgs<Scalar>(wrappedNominalValues))
399 SolveStatus<Scalar> solveStatus = stateSolver_->solve(&*x_guess_solu_,NULL);
404 *out <<
"\nComputing the output functions at the solved state solution ...\n";
406 MEB::InArgs<Scalar> wrappedInArgs = thyraModel->createInArgs();
407 MEB::OutArgs<Scalar> wrappedOutArgs = thyraModel->createOutArgs();
408 wrappedInArgs.setArgs(inArgs,
true);
409 wrappedInArgs.set_x(x_guess_solu_);
410 wrappedOutArgs.setArgs(outArgs,
true);
412 for(
int l = 0; l < Np; ++l ) {
413 for(
int j = 0; j < Ng; ++j ) {
415 outArgs.supports(MEB::OUT_ARG_DgDp,j,l).none()==
false
416 && outArgs.get_DgDp(j,l).isEmpty()==false
427 thyraModel->evalModel(wrappedInArgs,wrappedOutArgs);
432 for(
int l = 0; l < Np; ++l ) {
434 wrappedOutArgs.supports(MEB::OUT_ARG_DfDp,l).none()==
false
435 && wrappedOutArgs.get_DfDp(l).isEmpty()==false
442 for(
int j = 0; j < Ng; ++j ) {
444 outArgs.supports(MEB::OUT_ARG_DgDp,j,l).none()==
false
445 && outArgs.get_DgDp(j,l).isEmpty()==false
462 *out <<
"\nFailed to converge, returning NaNs ...\n";
469 <<
"\noutArgs on output =\n" << Teuchos::describe(outArgs,verbLevel);
474 <<
"\nTotal evaluation time = "<<totalTimer.totalElapsedTime()<<
" sec\n"
475 <<
"\nLeaving Thyra::DefaultStateEliminationModelEvaluator<Scalar>::evalModel(...) ...\n";
483 #endif // THYRA_DEFAULT_STATE_ELIMINATION_MODEL_EVALUATOR_HPP
Pure abstract base interface for evaluating a stateless "model" that can be mapped into a number of d...
bool is_null(const boost::shared_ptr< T > &p)
basic_OSTab< char > OSTab
ModelEvaluatorBase::InArgs< Scalar > getLowerBounds() const
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...
ModelEvaluatorBase::InArgs< Scalar > getNominalValues() const
void initialize(const RCP< ModelEvaluator< Scalar > > &model)
Initialize given a non-const model evaluator.
Base class for all nonlinear equation solvers.
This class wraps any ModelEvaluator object along with a NonlinearSolverBase object and eliminates the...
Teuchos::RCP< const VectorSpaceBase< Scalar > > get_x_space() const
Teuchos::RCP< LinearOpWithSolveBase< Scalar > > create_W() const
Teuchos::RCP< LinearOpBase< Scalar > > create_W_op() const
Teuchos::RCP< const VectorSpaceBase< Scalar > > get_f_space() const
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
DefaultStateEliminationModelEvaluator()
This class wraps any ModelEvaluator object and allows the client to overide the state contained in th...
void initialize(const Teuchos::RCP< ModelEvaluator< Scalar > > &thyraModel, const Teuchos::RCP< NonlinearSolverBase< Scalar > > &stateSolver)
Base subclass for ModelEvaluator that defines some basic types.
ModelEvaluatorBase::InArgs< Scalar > getUpperBounds() const
TypeTo as(const TypeFrom &t)
The requested solution criteria has likely been achieved.
std::string description() const
#define TEUCHOS_TEST_FOR_EXCEPT(throw_exception_test)
ModelEvaluatorBase::InArgs< Scalar > createInArgs() const
Concrete aggregate class for all input arguments computable by a ModelEvaluator subclass object...