Tempus  Version of the Day
Time Integration
Tempus_StepperImplicit_impl.hpp
Go to the documentation of this file.
1 // @HEADER
2 // ****************************************************************************
3 // Tempus: Copyright (2017) Sandia Corporation
4 //
5 // Distributed under BSD 3-clause license (See accompanying file Copyright.txt)
6 // ****************************************************************************
7 // @HEADER
8 
9 #ifndef Tempus_StepperImplicit_impl_hpp
10 #define Tempus_StepperImplicit_impl_hpp
11 
12 // Tempus
13 //#include "Tempus_Stepper.hpp"
14 //#include "Tempus_TimeDerivative.hpp"
15 
16 // Thrya
17 //#include "Thyra_VectorBase.hpp"
18 //#include "Thyra_VectorStdOps.hpp"
19 #include "NOX_Thyra.H"
20 
21 
22 namespace Tempus {
23 
24 
25 template<class Scalar>
27  const Teuchos::RCP<const Thyra::ModelEvaluator<Scalar> >& appModel)
28 {
29  this->validImplicitODE_DAE(appModel);
30  wrapperModel_ =
31  Teuchos::rcp(new WrapperModelEvaluatorBasic<Scalar>(appModel));
32 }
33 
34 
35 template<class Scalar>
37  const Teuchos::RCP<Thyra::ModelEvaluator<Scalar> >& appModel)
38 {
39  this->setModel(appModel);
40 }
41 
42 
43 /** \brief Set the solver to a pre-defined solver in the ParameterList.
44  *
45  * The solver is set to solverName sublist in the Stepper's ParameterList.
46  * The solverName sublist should already be defined in the Stepper's
47  * ParameterList. Otherwise it will fail.
48  */
49 template<class Scalar>
50 void StepperImplicit<Scalar>::setSolver(std::string solverName)
51 {
52  Teuchos::RCP<Teuchos::ParameterList> solverPL =
53  Teuchos::sublist(stepperPL_, solverName, true);
54  this->setSolver(solverPL);
55 }
56 
57 
58 /** \brief Set the solver to the supplied Parameter sublist.
59  *
60  * This adds a new solver Parameter sublist to the Stepper's ParameterList.
61  * If the solver sublist is null, the solver is set to the solver name
62  * in the Stepper's ParameterList.
63  */
64 template<class Scalar>
66  Teuchos::RCP<Teuchos::ParameterList> solverPL)
67 {
68  using Teuchos::RCP;
69  using Teuchos::ParameterList;
70 
71  std::string solverName = stepperPL_->get<std::string>("Solver Name");
72  if (is_null(solverPL)) {
73  if ( stepperPL_->isSublist(solverName) )
74  solverPL = Teuchos::sublist(stepperPL_, solverName, true);
75  else
76  solverPL = this->defaultSolverParameters();
77  } else {
78  if (solverName == solverPL->name()) {
79  RCP<Teuchos::FancyOStream> out = this->getOStream();
80  Teuchos::OSTab ostab(out,1,"StepperImplicit::setSolver()");
81  *out << "Warning - Replacing the solver ParameterList.\n"
82  << " Stepper Type = "<< stepperPL_->get<std::string>("Stepper Type")
83  << "\n Solver PL = " << solverName << std::endl;
84  stepperPL_->remove(solverName);
85  }
86  }
87 
88  solverName = solverPL->name();
89  stepperPL_->set("Solver Name", solverName);
90  stepperPL_->set(solverName, *solverPL); // Add sublist
91  RCP<ParameterList> noxPL = Teuchos::sublist(solverPL, "NOX", true);
92 
93  solver_ = rcp(new Thyra::NOXNonlinearSolver());
94  solver_->setParameterList(noxPL);
95 
96  TEUCHOS_TEST_FOR_EXCEPTION(wrapperModel_ == Teuchos::null, std::logic_error,
97  "Error - StepperImplicit<Scalar>::setSolver() wrapperModel_ is unset!\n"
98  << " Should call setModel(...) first.\n");
99  solver_->setModel(wrapperModel_);
100 }
101 
102 
103 /** \brief Set the solver.
104  *
105  * This sets the solver to supplied solver and adds solver's ParameterList
106  * to the Stepper ParameterList.
107  */
108 template<class Scalar>
110  Teuchos::RCP<Thyra::NonlinearSolverBase<Scalar> > solver)
111 {
112  Teuchos::RCP<Teuchos::ParameterList> solverPL =
113  solver->getNonconstParameterList();
114  this->setSolver(solverPL);
115 }
116 
117 
118 template<class Scalar>
119 const Thyra::SolveStatus<Scalar>
121  const Teuchos::RCP<Thyra::VectorBase<Scalar> > & x)
122 {
123  if (getZeroInitialGuess())
124  Thyra::assign(x.ptr(), Teuchos::ScalarTraits<Scalar>::zero());
125 
126  const Thyra::SolveStatus<Scalar> sStatus = (*solver_).solve(&*x);
127 
128  return sStatus;
129 }
130 
131 
132 } // namespace Tempus
133 #endif // Tempus_StepperImplicit_impl_hpp
Tempus::WrapperModelEvaluatorBasic
A ModelEvaluator for residual evaluations given a state. This ModelEvaluator takes a state,...
Definition: Tempus_WrapperModelEvaluatorBasic_decl.hpp:28
Tempus
Definition: Tempus_AdjointAuxSensitivityModelEvaluator_decl.hpp:20
Tempus::StepperImplicit::solveImplicitODE
const Thyra::SolveStatus< Scalar > solveImplicitODE(const Teuchos::RCP< Thyra::VectorBase< Scalar > > &x)
Solve problem using x in-place.
Definition: Tempus_StepperImplicit_impl.hpp:120
Tempus::StepperImplicit::setNonConstModel
virtual void setNonConstModel(const Teuchos::RCP< Thyra::ModelEvaluator< Scalar > > &appModel)
Definition: Tempus_StepperImplicit_impl.hpp:36
Tempus::StepperImplicit::setModel
virtual void setModel(const Teuchos::RCP< const Thyra::ModelEvaluator< Scalar > > &appModel)
Definition: Tempus_StepperImplicit_impl.hpp:26
Tempus::StepperImplicit::setSolver
virtual void setSolver(std::string solverName)
Set solver via ParameterList solver name.
Definition: Tempus_StepperImplicit_impl.hpp:50