10 #ifndef THYRA_DEFAULT_STATE_ELIMINATION_MODEL_EVALUATOR_HPP
11 #define THYRA_DEFAULT_STATE_ELIMINATION_MODEL_EVALUATOR_HPP
13 #include "Thyra_ModelEvaluatorDelegatorBase.hpp"
14 #include "Thyra_DefaultNominalBoundsOverrideModelEvaluator.hpp"
15 #include "Thyra_NonlinearSolverBase.hpp"
16 #include "Teuchos_Time.hpp"
29 template<
class Scalar>
123 template<
class Scalar>
127 template<
class Scalar>
136 template<
class Scalar>
144 stateSolver_ = stateSolver;
145 x_guess_solu_ = Teuchos::null;
152 stateSolver_->setModel(wrappedThyraModel_);
155 template<
class Scalar>
161 if(thyraModel) *thyraModel = this->getUnderlyingModel();
162 if(stateSolver) *stateSolver = stateSolver_;
164 stateSolver_ = Teuchos::null;
165 wrappedThyraModel_ = Teuchos::null;
166 x_guess_solu_ = Teuchos::null;
172 template<
class Scalar>
176 thyraModel = this->getUnderlyingModel();
177 std::ostringstream oss;
178 oss <<
"Thyra::DefaultStateEliminationModelEvaluator{";
179 oss <<
"thyraModel=";
181 oss <<
"\'"<<thyraModel->description()<<
"\'";
184 oss <<
",stateSolver=";
185 if(stateSolver_.get())
186 oss <<
"\'"<<stateSolver_->description()<<
"\'";
195 template<
class Scalar>
199 return Teuchos::null;
202 template<
class Scalar>
206 return Teuchos::null;
209 template<
class Scalar>
215 thyraModel = this->getUnderlyingModel();
216 MEB::InArgsSetup<Scalar> nominalValues(thyraModel->getNominalValues());
217 nominalValues.setModelEvalDescription(this->description());
218 nominalValues.setUnsupportsAndRelated(MEB::IN_ARG_x);
219 return nominalValues;
222 template<
class Scalar>
228 thyraModel = this->getUnderlyingModel();
229 MEB::InArgsSetup<Scalar> lowerBounds(thyraModel->getLowerBounds());
230 lowerBounds.setModelEvalDescription(this->description());
231 lowerBounds.setUnsupportsAndRelated(MEB::IN_ARG_x);
235 template<
class Scalar>
241 thyraModel = this->getUnderlyingModel();
242 MEB::InArgsSetup<Scalar> upperBounds(thyraModel->getUpperBounds());
243 upperBounds.setModelEvalDescription(this->description());
244 upperBounds.setUnsupportsAndRelated(MEB::IN_ARG_x);
248 template<
class Scalar>
252 return Teuchos::null;
255 template<
class Scalar>
259 return Teuchos::null;
263 template<
class Scalar>
269 thyraModel = this->getUnderlyingModel();
270 const MEB::InArgs<Scalar> wrappedInArgs = thyraModel->createInArgs();
271 MEB::InArgsSetup<Scalar> inArgs;
272 inArgs.setModelEvalDescription(this->description());
273 inArgs.set_Np(wrappedInArgs.Np());
274 inArgs.setSupports(wrappedInArgs);
275 inArgs.setUnsupportsAndRelated(MEB::IN_ARG_x);
283 template<
class Scalar>
289 thyraModel = this->getUnderlyingModel();
290 const MEB::OutArgs<Scalar> wrappedOutArgs = thyraModel->createOutArgs();
291 const int Np = wrappedOutArgs.Np(), Ng = wrappedOutArgs.Ng();
292 MEB::OutArgsSetup<Scalar> outArgs;
293 outArgs.setModelEvalDescription(this->description());
294 outArgs.set_Np_Ng(Np,Ng);
295 outArgs.setSupports(wrappedOutArgs);
296 outArgs.setUnsupportsAndRelated(MEB::IN_ARG_x);
297 outArgs.setUnsupportsAndRelated(MEB::OUT_ARG_f);
301 template<
class Scalar>
302 void DefaultStateEliminationModelEvaluator<Scalar>::evalModelImpl(
303 const ModelEvaluatorBase::InArgs<Scalar> &inArgs,
304 const ModelEvaluatorBase::OutArgs<Scalar> &outArgs
307 typedef ModelEvaluatorBase MEB;
309 using Teuchos::rcp_const_cast;
310 using Teuchos::rcp_dynamic_cast;
315 totalTimer.start(
true);
321 *out <<
"\nEntering Thyra::DefaultStateEliminationModelEvaluator<Scalar>::evalModel(...) ...\n";
324 thyraModel = this->getUnderlyingModel();
326 const int Np = outArgs.Np(), Ng = outArgs.Ng();
330 const ModelEvaluatorBase::InArgs<Scalar>
331 nominalValues = thyraModel->getNominalValues();
332 if(nominalValues.get_x().get()) {
333 x_guess_solu_ = nominalValues.get_x()->clone_v();
336 x_guess_solu_ = createMember(thyraModel->get_x_space());
337 assign(x_guess_solu_.ptr(), as<Scalar>(0.0));
342 MEB::InArgs<Scalar> wrappedNominalValues = thyraModel->getNominalValues();
343 wrappedNominalValues.setArgs(inArgs,
true);
344 wrappedNominalValues.set_x(x_guess_solu_);
350 VOTSNSB statSolver_outputTempState(
357 <<
"\ninArgs =\n" << Teuchos::describe(inArgs,verbLevel)
361 *out <<
"\nSolving f(x,...) for x ...\n";
363 wrappedThyraModel_->setNominalValues(
364 rcp(
new MEB::InArgs<Scalar>(wrappedNominalValues))
367 SolveStatus<Scalar> solveStatus = stateSolver_->solve(&*x_guess_solu_,NULL);
372 *out <<
"\nComputing the output functions at the solved state solution ...\n";
374 MEB::InArgs<Scalar> wrappedInArgs = thyraModel->createInArgs();
375 MEB::OutArgs<Scalar> wrappedOutArgs = thyraModel->createOutArgs();
376 wrappedInArgs.setArgs(inArgs,
true);
377 wrappedInArgs.set_x(x_guess_solu_);
378 wrappedOutArgs.setArgs(outArgs,
true);
380 for(
int l = 0; l < Np; ++l ) {
381 for(
int j = 0; j < Ng; ++j ) {
383 outArgs.supports(MEB::OUT_ARG_DgDp,j,l).none()==
false
384 && outArgs.get_DgDp(j,l).isEmpty()==false
395 thyraModel->evalModel(wrappedInArgs,wrappedOutArgs);
400 for(
int l = 0; l < Np; ++l ) {
402 wrappedOutArgs.supports(MEB::OUT_ARG_DfDp,l).none()==
false
403 && wrappedOutArgs.get_DfDp(l).isEmpty()==false
410 for(
int j = 0; j < Ng; ++j ) {
412 outArgs.supports(MEB::OUT_ARG_DgDp,j,l).none()==
false
413 && outArgs.get_DgDp(j,l).isEmpty()==false
430 *out <<
"\nFailed to converge, returning NaNs ...\n";
437 <<
"\noutArgs on output =\n" << Teuchos::describe(outArgs,verbLevel);
442 <<
"\nTotal evaluation time = "<<totalTimer.totalElapsedTime()<<
" sec\n"
443 <<
"\nLeaving Thyra::DefaultStateEliminationModelEvaluator<Scalar>::evalModel(...) ...\n";
451 #endif // THYRA_DEFAULT_STATE_ELIMINATION_MODEL_EVALUATOR_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...
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...