42 #ifndef THYRA_LINEAR_NONLINEAR_SOLVER_BASE_HPP 43 #define THYRA_LINEAR_NONLINEAR_SOLVER_BASE_HPP 46 #include "Thyra_NonlinearSolverBase.hpp" 47 #include "Thyra_ModelEvaluatorHelpers.hpp" 48 #include "Teuchos_VerboseObjectParameterListHelpers.hpp" 49 #include "Teuchos_StandardParameterEntryValidators.hpp" 50 #include "Teuchos_as.hpp" 64 template <
class Scalar>
92 RCP<const ModelEvaluator<Scalar> >
getModel()
const;
100 RCP<LinearOpWithSolveBase<Scalar> >
get_nonconst_W(
const bool forceUpToDate);
102 RCP<const LinearOpWithSolveBase<Scalar> >
get_W()
const;
108 RCP<Teuchos::ParameterList> paramList_;
109 RCP<const ModelEvaluator<Scalar> > model_;
110 RCP<LinearOpWithSolveBase<Scalar> > J_;
119 template <
class Scalar>
133 template<
class Scalar>
135 RCP<Teuchos::ParameterList>
const& paramList
139 TEUCHOS_TEST_FOR_EXCEPT(is_null(paramList));
140 paramList->validateParametersAndSetDefaults(*getValidParameters(),0);
141 paramList_ = paramList;
143 Teuchos::readVerboseObjectSublist(&*paramList_,
this);
145 paramList_->validateParameters(*getValidParameters(),0);
146 #endif // TEUCHOS_DEBUG 150 template<
class Scalar>
151 RCP<Teuchos::ParameterList>
158 template<
class Scalar>
159 RCP<Teuchos::ParameterList>
162 RCP<Teuchos::ParameterList> _paramList = paramList_;
163 paramList_ = Teuchos::null;
168 template<
class Scalar>
169 RCP<const Teuchos::ParameterList>
176 template<
class Scalar>
177 RCP<const Teuchos::ParameterList>
180 using Teuchos::setDoubleParameter;
using Teuchos::setIntParameter;
181 static RCP<const Teuchos::ParameterList> validPL;
182 if (is_null(validPL)) {
183 RCP<Teuchos::ParameterList>
184 pl = Teuchos::parameterList();
186 Teuchos::setupVerboseObjectSublist(&*pl);
196 template <
class Scalar>
201 TEUCHOS_TEST_FOR_EXCEPT(model.get()==NULL);
207 template <
class Scalar>
208 RCP<const ModelEvaluator<Scalar> >
215 template <
class Scalar>
224 using Teuchos::incrVerbLevel;
225 using Teuchos::describe;
228 using Teuchos::OSTab;
229 using Teuchos::getFancyOStream;
230 typedef Teuchos::ScalarTraits<Scalar> ST;
232 typedef Teuchos::VerboseObjectTempState<MEB> VOTSME;
234 typedef Teuchos::VerboseObjectTempState<LOWSB> VOTSLOWSB;
237 TEUCHOS_TEST_FOR_EXCEPT(0==x);
239 "TimeStepNonlinearSolver<Scalar>::solve(...)",
240 *x->
space(),*model_->get_x_space() );
241 TEUCHOS_TEST_FOR_EXCEPT(
242 0!=solveCriteria &&
"ToDo: Support passed in solve criteria!" );
245 const RCP<Teuchos::FancyOStream> out = this->getOStream();
246 const Teuchos::EVerbosityLevel verbLevel = this->getVerbLevel();
247 const bool showTrace = (as<int>(verbLevel) >= as<int>(Teuchos::VERB_LOW));
248 const bool dumpAll = (as<int>(verbLevel) == as<int>(Teuchos::VERB_EXTREME));
250 VOTSME stateModel_outputTempState(model_,out,incrVerbLevel(verbLevel,-1));
251 if(out.get() && showTrace)
253 <<
"\nEntering LinearNonlinearSolver::solve(...) ...\n" 254 <<
"\nmodel = " << describe(*model_,verbLevel);
256 if(out.get() && dumpAll) {
257 *out <<
"\nInitial guess:\n";
258 *out <<
"\nx = " << *x;
262 if(!J_.get()) J_ = model_->create_W();
263 RCP<VectorBase<Scalar> >
264 f = createMember(model_->get_f_space());
265 if(out.get() && showTrace)
266 *out <<
"\nEvaluating the model f and W ...\n";
267 eval_f_W( *model_, *x, &*f, &*J_ );
270 RCP<VectorBase<Scalar> >
271 dx = createMember(model_->get_x_space());
272 if(out.get() && showTrace)
273 *out <<
"\nSolving the system J*dx = -f ...\n";
274 VOTSLOWSB J_outputTempState(J_,out,incrVerbLevel(verbLevel,-1));
275 assign( dx.ptr(), ST::zero() );
277 linearSolveStatus = J_->solve(
NOTRANS, *f, dx.ptr() );
278 if(out.get() && showTrace)
279 *out <<
"\nLinear solve status:\n" << linearSolveStatus;
280 Vt_S( dx.ptr(), Scalar(-ST::one()) );
281 if(out.get() && dumpAll)
282 *out <<
"\ndx = " << Teuchos::describe(*dx,verbLevel);
284 Thyra::assign( ptr(delta), *dx );
285 if(out.get() && dumpAll)
286 *out <<
"\ndelta = " << Teuchos::describe(*delta,verbLevel);
291 if(out.get() && dumpAll)
292 *out <<
"\nUpdated solution x = " << Teuchos::describe(*x,verbLevel);
294 if(out.get() && showTrace)
295 *out <<
"\nLeaving LinearNonlinearSolver::solve(...) ...\n";
303 template <
class Scalar>
304 RCP<LinearOpWithSolveBase<Scalar> >
308 TEUCHOS_TEST_FOR_EXCEPT(forceUpToDate);
314 template <
class Scalar>
315 RCP<const LinearOpWithSolveBase<Scalar> >
325 #endif // THYRA_LINEAR_NONLINEAR_SOLVER_BASE_HPP virtual RCP< const VectorSpaceBase< Scalar > > space() const =0
Return a smart pointer to the vector space that this vector belongs to.
Pure abstract base interface for evaluating a stateless "model" that can be mapped into a number of d...
#define THYRA_ASSERT_VEC_SPACES(FUNC_NAME, VS1, VS2)
This is a very useful macro that should be used to validate that two vector spaces are compatible...
Base class for all linear operators that can support a high-level solve operation.
RCP< const Teuchos::ParameterList > getValidParameters() const
RCP< const ModelEvaluator< Scalar > > getModel() const
RCP< const Teuchos::ParameterList > getParameterList() const
Use the non-transposed operator.
RCP< Teuchos::ParameterList > unsetParameterList()
Base class for all nonlinear equation solvers.
void setParameterList(RCP< Teuchos::ParameterList > const ¶mList)
Concrete nonlinear solver for linear equations.
void setModel(const RCP< const ModelEvaluator< Scalar > > &model)
Abstract interface for finite-dimensional dense vectors.
Simple struct for the return status from a solve.
RCP< LinearOpWithSolveBase< Scalar > > get_nonconst_W(const bool forceUpToDate)
Base subclass for ModelEvaluator that defines some basic types.
RCP< const LinearOpWithSolveBase< Scalar > > get_W() const
SolveStatus< Scalar > solve(VectorBase< Scalar > *x, const SolveCriteria< Scalar > *solveCriteria, VectorBase< Scalar > *delta)
RCP< Teuchos::ParameterList > getNonconstParameterList()
Simple struct that defines the requested solution criteria for a solve.
RCP< LinearNonlinearSolver< Scalar > > linearNonlinearSolver()