Tempus  Version of the Day
Time Integration
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Tempus_Stepper_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_Stepper_impl_hpp
10 #define Tempus_Stepper_impl_hpp
11 
12 
13 namespace Tempus {
14 
15 
17  Teuchos::RCP<Teuchos::ParameterList> pl, std::string stepperType)
18 {
19  pl->setName("Default Stepper - " + stepperType);
20  pl->set<std::string>("Stepper Type", stepperType);
21 
22  pl->set<bool>("Use FSAL", false,
23  "The First-Step-As-Last (FSAL) principle is the situation where the\n"
24  "last function evaluation, f(x^{n-1},t^{n-1}) [a.k.a. xDot^{n-1}],\n"
25  "can be used for the first function evaluation, f(x^n,t^n)\n"
26  "[a.k.a. xDot^n]. For RK methods, this applies to the stages.\n"
27  "\n"
28  "Often the FSAL priniciple can be used to save an evaluation.\n"
29  "However there are cases when it cannot be used, e.g., operator\n"
30  "splitting where other steppers/operators have modified the solution,\n"
31  "x^*, and thus require the function evaluation, f(x^*, t^{n-1}).\n"
32  "\n"
33  "It should be noted that when the FSAL priniciple can be used\n"
34  "(can set useFSAL=true), setting useFSAL=false will give the\n"
35  "same solution but at additional expense. However, the reverse\n"
36  "is not true. When the FSAL priniciple can not be used\n"
37  "(need to set useFSAL=false), setting useFSAL=true will produce\n"
38  "incorrect solutions.\n"
39  "\n"
40  "Default in general for explicit and implicit steppers is false,\n"
41  "but individual steppers can override this default.");
42 
43  pl->set<std::string>("Initial Condition Consistency", "None",
44  "This indicates which type of consistency should be applied to\n"
45  "the initial conditions (ICs):\n"
46  "\n"
47  " 'None' - Do nothing to the ICs provided in the SolutionHistory.\n"
48  " 'Zero' - Set the derivative of the SolutionState to zero in the\n"
49  " SolutionHistory provided, e.g., xDot^0 = 0, or \n"
50  " xDotDot^0 = 0.\n"
51  " 'App' - Use the application's ICs, e.g., getNominalValues().\n"
52  " 'Consistent' - Make the initial conditions for x and xDot\n"
53  " consistent with the governing equations, e.g.,\n"
54  " xDot = f(x,t), and f(x, xDot, t) = 0. For implicit\n"
55  " ODEs, this requires a solve of f(x, xDot, t) = 0 for\n"
56  " xDot, and another Jacobian and residual may be\n"
57  " needed, e.g., boundary conditions on xDot may need\n"
58  " to replace boundary conditions on x.\n"
59  "\n"
60  "In general for explicit steppers, the default is 'Consistent',\n"
61  "because it is fairly cheap with just one residual evaluation.\n"
62  "In general for implicit steppers, the default is 'None', because\n"
63  "the application often knows its IC and can set it the initial\n"
64  "SolutionState. Also, as noted above, 'Consistent' may require\n"
65  "another Jacobian from the application. Individual steppers may\n"
66  "override these defaults.");
67 
68  pl->set<bool>("Initial Condition Consistency Check", true,
69  "Check if the initial condition, x and xDot, is consistent with the\n"
70  "governing equations, xDot = f(x,t), or f(x, xDot, t) = 0.\n"
71  "\n"
72  "In general for explicit and implicit steppers, the default is true,\n"
73  "because it is fairly cheap with just one residual evaluation.\n"
74  "Individual steppers may override this default.");
75 }
76 
77 
78 Teuchos::RCP<Teuchos::ParameterList> defaultSolverParameters()
79 {
80  using Teuchos::RCP;
81  using Teuchos::ParameterList;
82 
83  // NOX Solver ParameterList
84  RCP<ParameterList> noxPL = Teuchos::parameterList();
85 
86  // Direction ParameterList
87  RCP<ParameterList> directionPL = Teuchos::parameterList();
88  directionPL->set<std::string>("Method", "Newton");
89  RCP<ParameterList> newtonPL = Teuchos::parameterList();
90  newtonPL->set<std::string>("Forcing Term Method", "Constant");
91  newtonPL->set<bool> ("Rescue Bad Newton Solve", 1);
92  directionPL->set("Newton", *newtonPL);
93  noxPL->set("Direction", *directionPL);
94 
95  // Line Search ParameterList
96  RCP<ParameterList> lineSearchPL = Teuchos::parameterList();
97  lineSearchPL->set<std::string>("Method", "Full Step");
98  RCP<ParameterList> fullStepPL = Teuchos::parameterList();
99  fullStepPL->set<double>("Full Step", 1);
100  lineSearchPL->set("Full Step", *fullStepPL);
101  noxPL->set("Line Search", *lineSearchPL);
102 
103  noxPL->set<std::string>("Nonlinear Solver", "Line Search Based");
104 
105  // Printing ParameterList
106  RCP<ParameterList> printingPL = Teuchos::parameterList();
107  printingPL->set<int>("Output Precision", 3);
108  printingPL->set<int>("Output Processor", 0);
109  RCP<ParameterList> outputPL = Teuchos::parameterList();
110  outputPL->set<bool>("Error", 1);
111  outputPL->set<bool>("Warning", 1);
112  outputPL->set<bool>("Outer Iteration", 0);
113  outputPL->set<bool>("Parameters", 0);
114  outputPL->set<bool>("Details", 0);
115  outputPL->set<bool>("Linear Solver Details", 1);
116  outputPL->set<bool>("Stepper Iteration", 1);
117  outputPL->set<bool>("Stepper Details", 1);
118  outputPL->set<bool>("Stepper Parameters", 1);
119  printingPL->set("Output Information", *outputPL);
120  noxPL->set("Printing", *printingPL);
121 
122  // Solver Options ParameterList
123  RCP<ParameterList> solverOptionsPL = Teuchos::parameterList();
124  solverOptionsPL->set<std::string>("Status Test Check Type", "Minimal");
125  noxPL->set("Solver Options", *solverOptionsPL);
126 
127  // Status Tests ParameterList
128  RCP<ParameterList> statusTestsPL = Teuchos::parameterList();
129  statusTestsPL->set<std::string>("Test Type", "Combo");
130  statusTestsPL->set<std::string>("Combo Type", "OR");
131  statusTestsPL->set<int>("Number of Tests", 2);
132  RCP<ParameterList> test0PL = Teuchos::parameterList();
133  test0PL->set<std::string>("Test Type", "NormF");
134  test0PL->set<double>("Tolerance", 1e-08);
135  statusTestsPL->set("Test 0", *test0PL);
136  RCP<ParameterList> test1PL = Teuchos::parameterList();
137  test1PL->set<std::string>("Test Type", "MaxIters");
138  test1PL->set<int>("Maximum Iterations", 10);
139  statusTestsPL->set("Test 1", *test1PL);
140  noxPL->set("Status Tests", *statusTestsPL);
141 
142  // Solver ParameterList
143  RCP<ParameterList> solverPL = Teuchos::parameterList();
144  solverPL->set("NOX", *noxPL);
145 
146  return solverPL;
147 }
148 
149 
150 template<class Scalar>
152 {
153  Teuchos::RCP<Teuchos::FancyOStream> out = this->getOStream();
154 
155  bool isValidSetup = this->isValidSetup(*out);
156 
157  if (isValidSetup)
158  this->isInitialized_ = true; // Only place it is set to true.
159  else
160  this->describe(*out, Teuchos::VERB_MEDIUM);
161 }
162 
163 
164 template<class Scalar>
166 {
167  if ( !this->isInitialized() ) {
168  this->describe( *(this->getOStream()), Teuchos::VERB_MEDIUM);
169  TEUCHOS_TEST_FOR_EXCEPTION( !this->isInitialized(), std::logic_error,
170  "Error - " << this->description() << " is not initialized!");
171  }
172 }
173 
174 
175 
176 template<class Scalar>
177 Teuchos::RCP<Thyra::VectorBase<Scalar> >
179 {
180  if (state->getX() != Teuchos::null) stepperX_ = state->getX();
181  // Else use temporary storage stepperX_ which should have been set in
182  // setInitialConditions().
183 
184  TEUCHOS_TEST_FOR_EXCEPTION( stepperX_ == Teuchos::null, std::logic_error,
185  "Error - stepperX_ has not been set in setInitialConditions() or\n"
186  " can not be set from the state!\n");
187 
188  return stepperX_;
189 }
190 
191 template<class Scalar>
192 Teuchos::RCP<Thyra::VectorBase<Scalar> >
194 {
195  if (state->getXDot() != Teuchos::null) stepperXDot_ = state->getXDot();
196  // Else use temporary storage stepperXDot_ which should have been set in
197  // setInitialConditions().
198 
199  TEUCHOS_TEST_FOR_EXCEPTION( stepperXDot_ == Teuchos::null, std::logic_error,
200  "Error - stepperXDot_ has not set in setInitialConditions() or\n"
201  " can not be set from the state!\n");
202 
203  return stepperXDot_;
204 }
205 
206 template<class Scalar>
207 Teuchos::RCP<Thyra::VectorBase<Scalar> >
209 {
210  if (state->getXDotDot() != Teuchos::null) stepperXDotDot_=state->getXDotDot();
211  // Else use temporary storage stepperXDotDot_ which should have been set in
212  // setInitialConditions().
213 
214  TEUCHOS_TEST_FOR_EXCEPTION( stepperXDotDot_==Teuchos::null, std::logic_error,
215  "Error - stepperXDotDot_ has not set in setInitialConditions() or\n"
216  " can not be set from the state!\n");
217 
218  return stepperXDotDot_;
219 }
220 
221 
222 template<class Scalar>
223 void Stepper<Scalar>::describe(Teuchos::FancyOStream & out,
224  const Teuchos::EVerbosityLevel verbLevel) const
225 {
226  out << "--- Stepper ---\n"
227  << " isInitialized_ = " << Teuchos::toString(isInitialized_) << std::endl
228  << " stepperType_ = " << stepperType_ << std::endl
229  << " useFSAL_ = " << Teuchos::toString(useFSAL_) << std::endl
230  << " ICConsistency_ = " << ICConsistency_ << std::endl
231  << " ICConsistencyCheck_ = " << Teuchos::toString(ICConsistencyCheck_) << std::endl
232  << " stepperX_ = " << stepperX_ << std::endl
233  << " stepperXDot_ = " << stepperXDot_ << std::endl
234  << " stepperXDotDot_ = " << stepperXDotDot_ << std::endl;
235 }
236 
237 
238 template<class Scalar>
240  Teuchos::FancyOStream & out) const
241 {
242  bool isValidSetup = true;
243 
244  if ( !(ICConsistency_ == "None" || ICConsistency_ == "Zero" ||
245  ICConsistency_ == "App" || ICConsistency_ == "Consistent") ) {
246  isValidSetup = false;
247  out << "The IC consistency does not have a valid value!\n"
248  << "('None', 'Zero', 'App' or 'Consistent')\n"
249  << " ICConsistency = " << ICConsistency_ << "\n";
250  }
251 
252  return isValidSetup;
253 }
254 
255 
256 } // namespace Tempus
257 #endif // Tempus_Stepper_impl_hpp
virtual bool isValidSetup(Teuchos::FancyOStream &out) const
const std::string toString(const Status status)
Convert Status to string.
virtual Teuchos::RCP< Thyra::VectorBase< Scalar > > getStepperX(Teuchos::RCP< SolutionState< Scalar > > state)
Get x from SolutionState or Stepper storage.
Teuchos::RCP< Teuchos::ParameterList > defaultSolverParameters()
Returns the default solver ParameterList for implicit Steppers.
virtual void initialize()
Initialize after construction and changing input parameters.
virtual Teuchos::RCP< Thyra::VectorBase< Scalar > > getStepperXDotDot(Teuchos::RCP< SolutionState< Scalar > > state)
Get xDotDot from SolutionState or Stepper storage.
virtual void checkInitialized()
Check initialization, and error out on failure.
virtual void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel) const
void getValidParametersBasic(Teuchos::RCP< Teuchos::ParameterList > pl, std::string stepperType)
Provide basic parameters to Steppers.
virtual Teuchos::RCP< Thyra::VectorBase< Scalar > > getStepperXDot(Teuchos::RCP< SolutionState< Scalar > > state)
Get xDot from SolutionState or Stepper storage.
Solution state for integrators and steppers. SolutionState contains the metadata for solutions and th...