[P]arallel [Hi]gh-order [Li]brary for [P]DEs  Latest
Parallel High-Order Library for PDEs through hp-adaptive Discontinuous Galerkin methods
parameters_ode_solver.cpp
1 #include "parameters/parameters_ode_solver.h"
2 #include <deal.II/base/mpi.h>
3 #include <deal.II/base/utilities.h>
4 #include <deal.II/base/conditional_ostream.h>
5 
6 namespace PHiLiP {
7 namespace Parameters {
8 
9 void ODESolverParam::declare_parameters (dealii::ParameterHandler &prm)
10 {
11  prm.enter_subsection("ODE solver");
12  {
13 
14  prm.declare_entry("ode_output", "verbose",
15  dealii::Patterns::Selection("quiet|verbose"),
16  "State whether output from ODE solver should be printed. "
17  "Choices are <quiet|verbose>.");
18 
19  prm.declare_entry("output_solution_every_x_steps", "-1",
20  dealii::Patterns::Integer(-1,dealii::Patterns::Integer::max_int_value),
21  "Outputs the solution every x steps in .vtk file");
22 
23  prm.declare_entry("output_solution_every_dt_time_intervals", "0.0",
24  dealii::Patterns::Double(0,dealii::Patterns::Double::max_double_value),
25  "Outputs the solution at time intervals of dt in .vtk file");
26 
27  prm.declare_entry("output_solution_at_fixed_times", "false",
28  dealii::Patterns::Bool(),
29  "Output solution at fixed times. False by default.");
30 
31  prm.declare_entry("output_solution_fixed_times_string", " ",
32  dealii::Patterns::FileName(dealii::Patterns::FileName::FileType::input),
33  "String of the times at which to output the velocity field. "
34  "Example: '0.0 1.0 2.0 3.0 ' or '0.0 1.0 2.0 3.0'");
35 
36  prm.declare_entry("output_solution_at_exact_fixed_times", "false",
37  dealii::Patterns::Bool(),
38  "Output solution at exact fixed times by decreasing the time step on the fly. False by default. "
39  "NOTE: Should be set to false if doing stability studies so that the time step is never influenced by solution file soutput times.");
40 
41  prm.declare_entry("ode_solver_type", "implicit",
42  dealii::Patterns::Selection(
43  " runge_kutta | "
44  " low_storage_runge_kutta | "
45  " implicit | "
46  " rrk_explicit | "
47  " pod_galerkin | "
48  " pod_petrov_galerkin | "
49  " hyper_reduced_petrov_galerkin | "
50  " pod_galerkin_runge_kutta "),
51  "Type of ODE solver to use."
52  "Choices are "
53  " <runge_kutta | "
54  " low_storage_runge_kutta | "
55  " implicit | "
56  " rrk_explicit | "
57  " pod_galerkin | "
58  " pod_petrov_galerkin | "
59  " hyper_reduced_petrov_galerkin | "
60  " pod_galerkin_runge_kutta>.");
61 
62  prm.declare_entry("nonlinear_max_iterations", "500000",
63  dealii::Patterns::Integer(0,dealii::Patterns::Integer::max_int_value),
64  "Maximum nonlinear solver iterations");
65  prm.declare_entry("nonlinear_steady_residual_tolerance", "1e-13",
66  //dealii::Patterns::Double(1e-16,dealii::Patterns::Double::max_double_value),
67  dealii::Patterns::Double(1e-300,dealii::Patterns::Double::max_double_value),
68  "Nonlinear solver residual tolerance");
69  prm.declare_entry("initial_time_step", "100.0",
70  dealii::Patterns::Double(1e-16,dealii::Patterns::Double::max_double_value),
71  "Time step used in ODE solver.");
72  prm.declare_entry("time_step_factor_residual", "0.0",
73  dealii::Patterns::Double(0,dealii::Patterns::Double::max_double_value),
74  "Multiplies initial time-step by time_step_factor_residual*(-log10(residual_norm_decrease)).");
75  prm.declare_entry("time_step_factor_residual_exp", "1.0",
76  dealii::Patterns::Double(0,dealii::Patterns::Double::max_double_value),
77  "Scales initial time step by pow(time_step_factor_residual*(-log10(residual_norm_decrease)),time_step_factor_residual_exp).");
78 
79  prm.declare_entry("print_iteration_modulo", "1",
80  dealii::Patterns::Integer(0,dealii::Patterns::Integer::max_int_value),
81  "Print every print_iteration_modulo iterations of "
82  "the nonlinear solver");
83  prm.declare_entry("output_final_steady_state_solution_to_file", "false",
84  dealii::Patterns::Bool(),
85  "Output final steady state solution to file if set to true");
86  prm.declare_entry("steady_state_final_solution_filename", "solution_snapshot",
87  dealii::Patterns::Anything(),
88  "Filename to use when outputting solution to a file.");
89  prm.declare_entry("output_ode_solver_steady_state_convergence_table","false",
90  dealii::Patterns::Bool(),
91  "Set as false by default. If true, writes the linear solver convergence data "
92  "for steady state to a file named 'ode_solver_steady_state_convergence_data_table.txt'.");
93 
94  prm.declare_entry("initial_time", "0.0",
95  dealii::Patterns::Double(0, dealii::Patterns::Double::max_double_value),
96  "Initial time at which we initialize the ODE solver with.");
97 
98  prm.declare_entry("initial_iteration", "0",
99  dealii::Patterns::Integer(0, dealii::Patterns::Integer::max_int_value),
100  "Initial iteration at which we initialize the ODE solver with.");
101 
102  prm.declare_entry("initial_desired_time_for_output_solution_every_dt_time_intervals", "0.0",
103  dealii::Patterns::Double(0, dealii::Patterns::Double::max_double_value),
104  "Initial desired time for outputting the solution every dt time intervals "
105  "at which we initialize the ODE solver with.");
106 
107  prm.declare_entry("runge_kutta_method", "ssprk3_ex",
108  dealii::Patterns::Selection(
109  " rk4_ex | "
110  " ssprk3_ex | "
111  " heun2_ex | "
112  " euler_ex | "
113  " euler_im | "
114  " dirk_2_im | "
115  " dirk_3_im | "
116  " RK3_2_5F_3SStarPlus | "
117  " RK4_3_5_3SStar | "
118  " RK4_3_9F_3SStarPlus |"
119  " RK5_4_10F_3SStarPlus "),
120  "Runge-kutta method to use. Methods with _ex are explicit, and with _im are implicit. [3S*] and [3S*+] methods are low-storage RK methods"
121  "Choices are "
122  " <rk4_ex | "
123  " ssprk3_ex | "
124  " heun2_ex | "
125  " euler_ex | "
126  " euler_im | "
127  " dirk_2_im | "
128  " dirk_3_im | "
129  " RK4_3_5_3SStar | "
130  " RK3_2_5F_3SStarPlus | "
131  " RK5_4_10F_3SStarPlus |"
132  " RK4_3_9F_3SStarPlus >.");
133  prm.enter_subsection("rrk root solver");
134  {
135  prm.declare_entry("rrk_root_solver_output", "quiet",
136  dealii::Patterns::Selection("quiet|verbose"),
137  "State whether output from rrk root solver should be printed. "
138  "Choices are <quiet|verbose>.");
139 
140  prm.declare_entry("relaxation_runge_kutta_root_tolerance", "5e-10",
141  dealii::Patterns::Double(),
142  "Tolerance for root-finding problem in entropy RRK ode solver."
143  "Defult 5E-10 is suitable in most cases.");
144  prm.declare_entry("use_relaxation_runge_kutta","false",
145  dealii::Patterns::Bool(),
146  "Toggle using relaxation runge-kutta. "
147  "Must use a RK ode solver."
148  );
149 
150  }
151  prm.leave_subsection();
152 
153  prm.enter_subsection("low-storage rk solver");
154  {
155  prm.declare_entry("atol", "0.001",
156  dealii::Patterns::Double(),
157  "Absolute Tolerance for automatic step size controller");
158 
159  prm.declare_entry("rtol", "0.001",
160  dealii::Patterns::Double(),
161  "Relative Tolerance for automatic step size controller");
162 
163  prm.declare_entry("beta1", "0.70",
164  dealii::Patterns::Double(),
165  "Beta Controller 1 for automatic step size controller");
166 
167  prm.declare_entry("beta2", "-0.23",
168  dealii::Patterns::Double(),
169  "Beta controller 2 for automatic step size controller");
170 
171  prm.declare_entry("beta3", "0.0",
172  dealii::Patterns::Double(),
173  "Beta controller 3 for automatic step size controller");
174  }
175  prm.leave_subsection();
176  }
177  prm.leave_subsection();
178 }
179 
180 void ODESolverParam::parse_parameters (dealii::ParameterHandler &prm)
181 {
182  prm.enter_subsection("ODE solver");
183  {
184  const std::string output_string = prm.get("ode_output");
185  if (output_string == "quiet") ode_output = OutputEnum::quiet;
186  else if (output_string == "verbose") ode_output = OutputEnum::verbose;
187 
188  output_solution_every_x_steps = prm.get_integer("output_solution_every_x_steps");
189  output_solution_every_dt_time_intervals = prm.get_double("output_solution_every_dt_time_intervals");
190  output_solution_at_fixed_times = prm.get_bool("output_solution_at_fixed_times");
191  output_solution_fixed_times_string = prm.get("output_solution_fixed_times_string");
193  output_solution_at_exact_fixed_times = prm.get_bool("output_solution_at_exact_fixed_times");
194 
195  // Assign ode_solver_type and the allocate AD matrix dRdW flag
196  const std::string solver_string = prm.get("ode_solver_type");
197  if (solver_string == "runge_kutta") { ode_solver_type = ODESolverEnum::runge_kutta_solver;
198  allocate_matrix_dRdW = false; }
199  else if (solver_string == "low_storage_runge_kutta") { ode_solver_type = ODESolverEnum::low_storage_runge_kutta_solver;
200  allocate_matrix_dRdW = false; }
201  else if (solver_string == "implicit") { ode_solver_type = ODESolverEnum::implicit_solver;
202  allocate_matrix_dRdW = true; }
203  else if (solver_string == "rrk_explicit") { ode_solver_type = ODESolverEnum::rrk_explicit_solver;
204  allocate_matrix_dRdW = false; }
205  else if (solver_string == "pod_galerkin") { ode_solver_type = ODESolverEnum::pod_galerkin_solver;
206  allocate_matrix_dRdW = true; }
207  else if (solver_string == "pod_petrov_galerkin") { ode_solver_type = ODESolverEnum::pod_petrov_galerkin_solver;
208  allocate_matrix_dRdW = true; }
209  else if (solver_string == "hyper_reduced_petrov_galerkin") { ode_solver_type = ODESolverEnum::hyper_reduced_petrov_galerkin_solver;
210  allocate_matrix_dRdW = true; }
211  else if (solver_string == "pod_galerkin_runge_kutta") { ode_solver_type = ODESolverEnum::pod_galerkin_runge_kutta_solver;
212  allocate_matrix_dRdW = true; }
213 
214  nonlinear_steady_residual_tolerance = prm.get_double("nonlinear_steady_residual_tolerance");
215  nonlinear_max_iterations = prm.get_integer("nonlinear_max_iterations");
216  initial_time_step = prm.get_double("initial_time_step");
217  time_step_factor_residual = prm.get_double("time_step_factor_residual");
218  time_step_factor_residual_exp = prm.get_double("time_step_factor_residual_exp");
219 
220  print_iteration_modulo = prm.get_integer("print_iteration_modulo");
221  output_final_steady_state_solution_to_file = prm.get_bool("output_final_steady_state_solution_to_file");
222  steady_state_final_solution_filename = prm.get("steady_state_final_solution_filename");
223  output_ode_solver_steady_state_convergence_table = prm.get_bool("output_ode_solver_steady_state_convergence_table");
224 
225  initial_time = prm.get_double("initial_time");
226  initial_iteration = prm.get_integer("initial_iteration");
227  initial_desired_time_for_output_solution_every_dt_time_intervals = prm.get_double("initial_desired_time_for_output_solution_every_dt_time_intervals");
228 
229  const std::string rk_method_string = prm.get("runge_kutta_method");
230  if (rk_method_string == "rk4_ex"){
231  runge_kutta_method = RKMethodEnum::rk4_ex;
232  n_rk_stages = 4;
233  rk_order = 4;
234  }
235  else if (rk_method_string == "ssprk3_ex"){
236  runge_kutta_method = RKMethodEnum::ssprk3_ex;
237  n_rk_stages = 3;
238  rk_order = 3;
239  }
240  else if (rk_method_string == "heun2_ex"){
241  runge_kutta_method = RKMethodEnum::heun2_ex;
242  n_rk_stages = 2;
243  rk_order = 2;
244  }
245  else if (rk_method_string == "euler_ex"){
246  runge_kutta_method = RKMethodEnum::euler_ex;
247  n_rk_stages = 1;
248  rk_order = 1;
249  }
250  else if (rk_method_string == "euler_im"){
251  runge_kutta_method = RKMethodEnum::euler_im;
252  n_rk_stages = 1;
253  rk_order = 1;
254  }
255  else if (rk_method_string == "dirk_2_im"){
256  runge_kutta_method = RKMethodEnum::dirk_2_im;
257  n_rk_stages = 2;
258  rk_order = 2;
259  }
260  else if (rk_method_string == "dirk_3_im"){
261  runge_kutta_method = RKMethodEnum::dirk_3_im;
262  n_rk_stages = 3;
263  rk_order = 3;
264  }
265  else if (rk_method_string == "RK3_2_5F_3SStarPlus"){
266  runge_kutta_method = RKMethodEnum::RK3_2_5F_3SStarPlus;
267  n_rk_stages = 5;
268  num_delta = 5;
269  rk_order = 3;
270  is_3Sstarplus = true;
271  }
272  else if (rk_method_string == "RK4_3_5_3SStar"){
273  runge_kutta_method = RKMethodEnum::RK4_3_5_3SStar;
274  n_rk_stages = 5;
275  num_delta = 7;
276  rk_order = 4;
277  is_3Sstarplus = false;
278  }
279  else if (rk_method_string == "RK4_3_9F_3SStarPlus"){
280  runge_kutta_method = RKMethodEnum::RK4_3_9F_3SStarPlus;
281  n_rk_stages = 9;
282  num_delta = 9;
283  rk_order = 4;
284  is_3Sstarplus = true;
285  }
286  else if (rk_method_string == "RK5_4_10F_3SStarPlus"){
287  runge_kutta_method = RKMethodEnum::RK5_4_10F_3SStarPlus;
288  n_rk_stages = 10;
289  num_delta = 10;
290  rk_order = 5;
291  is_3Sstarplus = true;
292  }
293 
294  prm.enter_subsection("rrk root solver");
295  {
296  const std::string output_string_rrk = prm.get("rrk_root_solver_output");
297  if (output_string_rrk == "verbose") rrk_root_solver_output = verbose;
298  else if (output_string_rrk == "quiet") rrk_root_solver_output = quiet;
299 
300  relaxation_runge_kutta_root_tolerance = prm.get_double("relaxation_runge_kutta_root_tolerance");
301  use_relaxation_runge_kutta = prm.get_bool("use_relaxation_runge_kutta");
303  // For backwards compatibility
305  const int mpi_rank = dealii::Utilities::MPI::this_mpi_process(MPI_COMM_WORLD);
306  dealii::ConditionalOStream pcout(std::cout, mpi_rank==0);
307  pcout << "Warning: rrk_explicit_solver parameter is depreciated. " << std::endl
308  << "Backwards compatibility was verified upon implementation." <<std::endl;
309 
310  }
311  }
312  prm.leave_subsection();
313 
314  prm.enter_subsection("low-storage rk solver");
315  {
316  atol = prm.get_double("atol");
317  rtol = prm.get_double("rtol");
318  beta1 = prm.get_double("beta1");
319  beta2 = prm.get_double("beta2");
320  beta3 = prm.get_double("beta3");
321  }
322  prm.leave_subsection();
323 
324  }
325  prm.leave_subsection();
326 }
327 
328 } // Parameters namespace
329 } // PHiLiP namespace
bool is_3Sstarplus
True or false depending on what low-storage RK method is used.
OutputEnum ode_output
verbose or quiet.
double initial_time
Initial time at which we initialize the ODE solver with.
double beta2
Second value for beta controller;.
int output_solution_every_x_steps
Outputs the solution every x steps to .vtk file.
int num_delta
Number of delta values in low-storage RK methods.
bool output_solution_at_fixed_times
Flag for outputting solution at fixed times.
double time_step_factor_residual_exp
Scales initial time step by pow(time_step_factor_residual*(-log10(residual_norm_decrease)),time_step_factor_residual_exp)
Files for the baseline physics.
Definition: ADTypes.hpp:10
OutputEnum rrk_root_solver_output
Do output for root solving routine.
unsigned int print_iteration_modulo
If ode_output==verbose, print every print_iteration_modulo iterations.
unsigned int initial_iteration
Initial iteration at which we initialize the ODE solver with.
double output_solution_every_dt_time_intervals
Outputs the solution every dt time intervals to .vtk file.
bool allocate_matrix_dRdW
Flag to signal that automatic differentiation (AD) matrix dRdW must be allocated. ...
int rk_order
Order of the RK method; assigned based on runge_kutta_method.
std::string output_solution_fixed_times_string
String of fixed solution output times.
double initial_time_step
Time step used in ODE solver.
double nonlinear_steady_residual_tolerance
Tolerance to determine steady-state convergence.
std::string steady_state_final_solution_filename
Filename to write final steady state solution.
unsigned int number_of_fixed_times_to_output_solution
Number of fixed times to output the solution.
bool output_final_steady_state_solution_to_file
Output final steady state solution to file.
RKMethodEnum runge_kutta_method
Runge-kutta method.
double time_step_factor_residual
Multiplies initial time-step by time_step_factor_residual*(-log10(residual_norm_decrease)) ...
void parse_parameters(dealii::ParameterHandler &prm)
Parses input file and sets the variables.
bool output_solution_at_exact_fixed_times
Flag for outputting the solution at exact fixed times by decreasing the time step on the fly...
ODESolverEnum ode_solver_type
ODE solver type.
double relaxation_runge_kutta_root_tolerance
Tolerance for RRK root solver, default value 5E-10.
double beta3
Third value for beta controller;.
int n_rk_stages
Number of stages for an RK method; assigned based on runge_kutta_method.
bool use_relaxation_runge_kutta
Use relaxation runge-kutta.
double beta1
First value for beta controller;.
unsigned int nonlinear_max_iterations
Maximum number of iterations.
static void declare_parameters(dealii::ParameterHandler &prm)
Declares the possible variables and sets the defaults.