[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("output_solution_start_time", "0.0",
42  dealii::Patterns::Double(0,dealii::Patterns::Double::max_double_value),
43  "Time at which to start outputting the solution in .vtk files");
44 
45  prm.declare_entry("ode_solver_type", "implicit",
46  dealii::Patterns::Selection(
47  " runge_kutta | "
48  " low_storage_runge_kutta | "
49  " implicit | "
50  " rrk_explicit | "
51  " pod_galerkin | "
52  " pod_petrov_galerkin | "
53  " hyper_reduced_petrov_galerkin | "
54  " pod_galerkin_runge_kutta "),
55  "Type of ODE solver to use."
56  "Choices are "
57  " <runge_kutta | "
58  " low_storage_runge_kutta | "
59  " implicit | "
60  " rrk_explicit | "
61  " pod_galerkin | "
62  " pod_petrov_galerkin | "
63  " hyper_reduced_petrov_galerkin | "
64  " pod_galerkin_runge_kutta>.");
65 
66  prm.declare_entry("nonlinear_max_iterations", "500000",
67  dealii::Patterns::Integer(0,dealii::Patterns::Integer::max_int_value),
68  "Maximum nonlinear solver iterations");
69  prm.declare_entry("nonlinear_steady_residual_tolerance", "1e-13",
70  //dealii::Patterns::Double(1e-16,dealii::Patterns::Double::max_double_value),
71  dealii::Patterns::Double(1e-300,dealii::Patterns::Double::max_double_value),
72  "Nonlinear solver residual tolerance");
73  prm.declare_entry("initial_time_step", "100.0",
74  dealii::Patterns::Double(1e-16,dealii::Patterns::Double::max_double_value),
75  "Time step used in ODE solver.");
76  prm.declare_entry("time_step_factor_residual", "0.0",
77  dealii::Patterns::Double(0,dealii::Patterns::Double::max_double_value),
78  "Multiplies initial time-step by time_step_factor_residual*(-log10(residual_norm_decrease)).");
79  prm.declare_entry("time_step_factor_residual_exp", "1.0",
80  dealii::Patterns::Double(0,dealii::Patterns::Double::max_double_value),
81  "Scales initial time step by pow(time_step_factor_residual*(-log10(residual_norm_decrease)),time_step_factor_residual_exp).");
82 
83  prm.declare_entry("print_iteration_modulo", "1",
84  dealii::Patterns::Integer(0,dealii::Patterns::Integer::max_int_value),
85  "Print every print_iteration_modulo iterations of "
86  "the nonlinear solver");
87  prm.declare_entry("output_final_steady_state_solution_to_file", "false",
88  dealii::Patterns::Bool(),
89  "Output final steady state solution to file if set to true");
90  prm.declare_entry("steady_state_final_solution_filename", "solution_snapshot",
91  dealii::Patterns::Anything(),
92  "Filename to use when outputting solution to a file.");
93  prm.declare_entry("output_ode_solver_steady_state_convergence_table","false",
94  dealii::Patterns::Bool(),
95  "Set as false by default. If true, writes the linear solver convergence data "
96  "for steady state to a file named 'ode_solver_steady_state_convergence_data_table.txt'.");
97 
98  prm.declare_entry("initial_time", "0.0",
99  dealii::Patterns::Double(0, dealii::Patterns::Double::max_double_value),
100  "Initial time at which we initialize the ODE solver with.");
101 
102  prm.declare_entry("initial_iteration", "0",
103  dealii::Patterns::Integer(0, dealii::Patterns::Integer::max_int_value),
104  "Initial iteration at which we initialize the ODE solver with.");
105 
106  prm.declare_entry("initial_desired_time_for_output_solution_every_dt_time_intervals", "0.0",
107  dealii::Patterns::Double(0, dealii::Patterns::Double::max_double_value),
108  "Initial desired time for outputting the solution every dt time intervals "
109  "at which we initialize the ODE solver with.");
110 
111  prm.declare_entry("runge_kutta_method", "ssprk3_ex",
112  dealii::Patterns::Selection(
113  " rk4_ex | "
114  " ssprk3_ex | "
115  " heun2_ex | "
116  " euler_ex | "
117  " euler_im | "
118  " dirk_2_im | "
119  " dirk_3_im | "
120  " RK3_2_5F_3SStarPlus | "
121  " RK4_3_5_3SStar | "
122  " RK4_3_9F_3SStarPlus |"
123  " RK5_4_10F_3SStarPlus "),
124  "Runge-kutta method to use. Methods with _ex are explicit, and with _im are implicit. [3S*] and [3S*+] methods are low-storage RK methods"
125  "Choices are "
126  " <rk4_ex | "
127  " ssprk3_ex | "
128  " heun2_ex | "
129  " euler_ex | "
130  " euler_im | "
131  " dirk_2_im | "
132  " dirk_3_im | "
133  " RK4_3_5_3SStar | "
134  " RK3_2_5F_3SStarPlus | "
135  " RK5_4_10F_3SStarPlus |"
136  " RK4_3_9F_3SStarPlus >.");
137  prm.enter_subsection("rrk root solver");
138  {
139  prm.declare_entry("rrk_root_solver_output", "quiet",
140  dealii::Patterns::Selection("quiet|verbose"),
141  "State whether output from rrk root solver should be printed. "
142  "Choices are <quiet|verbose>.");
143 
144  prm.declare_entry("relaxation_runge_kutta_root_tolerance", "5e-10",
145  dealii::Patterns::Double(),
146  "Tolerance for root-finding problem in entropy RRK ode solver."
147  "Defult 5E-10 is suitable in most cases.");
148  prm.declare_entry("use_relaxation_runge_kutta","false",
149  dealii::Patterns::Bool(),
150  "Toggle using relaxation runge-kutta. "
151  "Must use a RK ode solver."
152  );
153 
154  }
155  prm.leave_subsection();
156 
157  prm.enter_subsection("low-storage rk solver");
158  {
159  prm.declare_entry("atol", "0.001",
160  dealii::Patterns::Double(),
161  "Absolute Tolerance for automatic step size controller");
162 
163  prm.declare_entry("rtol", "0.001",
164  dealii::Patterns::Double(),
165  "Relative Tolerance for automatic step size controller");
166 
167  prm.declare_entry("beta1", "0.70",
168  dealii::Patterns::Double(),
169  "Beta Controller 1 for automatic step size controller");
170 
171  prm.declare_entry("beta2", "-0.23",
172  dealii::Patterns::Double(),
173  "Beta controller 2 for automatic step size controller");
174 
175  prm.declare_entry("beta3", "0.0",
176  dealii::Patterns::Double(),
177  "Beta controller 3 for automatic step size controller");
178  }
179  prm.leave_subsection();
180  }
181  prm.leave_subsection();
182 }
183 
184 void ODESolverParam::parse_parameters (dealii::ParameterHandler &prm)
185 {
186  prm.enter_subsection("ODE solver");
187  {
188  const std::string output_string = prm.get("ode_output");
189  if (output_string == "quiet") ode_output = OutputEnum::quiet;
190  else if (output_string == "verbose") ode_output = OutputEnum::verbose;
191 
192  output_solution_every_x_steps = prm.get_integer("output_solution_every_x_steps");
193  output_solution_every_dt_time_intervals = prm.get_double("output_solution_every_dt_time_intervals");
194  output_solution_at_fixed_times = prm.get_bool("output_solution_at_fixed_times");
195  output_solution_fixed_times_string = prm.get("output_solution_fixed_times_string");
197  output_solution_at_exact_fixed_times = prm.get_bool("output_solution_at_exact_fixed_times");
198  output_solution_start_time = prm.get_double("output_solution_start_time");
199 
200  // Assign ode_solver_type and the allocate AD matrix dRdW flag
201  const std::string solver_string = prm.get("ode_solver_type");
202  if (solver_string == "runge_kutta") { ode_solver_type = ODESolverEnum::runge_kutta_solver;
203  allocate_matrix_dRdW = false; }
204  else if (solver_string == "low_storage_runge_kutta") { ode_solver_type = ODESolverEnum::low_storage_runge_kutta_solver;
205  allocate_matrix_dRdW = false; }
206  else if (solver_string == "implicit") { ode_solver_type = ODESolverEnum::implicit_solver;
207  allocate_matrix_dRdW = true; }
208  else if (solver_string == "rrk_explicit") { ode_solver_type = ODESolverEnum::rrk_explicit_solver;
209  allocate_matrix_dRdW = false; }
210  else if (solver_string == "pod_galerkin") { ode_solver_type = ODESolverEnum::pod_galerkin_solver;
211  allocate_matrix_dRdW = true; }
212  else if (solver_string == "pod_petrov_galerkin") { ode_solver_type = ODESolverEnum::pod_petrov_galerkin_solver;
213  allocate_matrix_dRdW = true; }
214  else if (solver_string == "hyper_reduced_petrov_galerkin") { ode_solver_type = ODESolverEnum::hyper_reduced_petrov_galerkin_solver;
215  allocate_matrix_dRdW = true; }
216  else if (solver_string == "pod_galerkin_runge_kutta") { ode_solver_type = ODESolverEnum::pod_galerkin_runge_kutta_solver;
217  allocate_matrix_dRdW = true; }
218 
219  nonlinear_steady_residual_tolerance = prm.get_double("nonlinear_steady_residual_tolerance");
220  nonlinear_max_iterations = prm.get_integer("nonlinear_max_iterations");
221  initial_time_step = prm.get_double("initial_time_step");
222  time_step_factor_residual = prm.get_double("time_step_factor_residual");
223  time_step_factor_residual_exp = prm.get_double("time_step_factor_residual_exp");
224 
225  print_iteration_modulo = prm.get_integer("print_iteration_modulo");
226  output_final_steady_state_solution_to_file = prm.get_bool("output_final_steady_state_solution_to_file");
227  steady_state_final_solution_filename = prm.get("steady_state_final_solution_filename");
228  output_ode_solver_steady_state_convergence_table = prm.get_bool("output_ode_solver_steady_state_convergence_table");
229 
230  initial_time = prm.get_double("initial_time");
231  initial_iteration = prm.get_integer("initial_iteration");
232  initial_desired_time_for_output_solution_every_dt_time_intervals = prm.get_double("initial_desired_time_for_output_solution_every_dt_time_intervals");
233 
234  const std::string rk_method_string = prm.get("runge_kutta_method");
235  if (rk_method_string == "rk4_ex"){
236  runge_kutta_method = RKMethodEnum::rk4_ex;
237  n_rk_stages = 4;
238  rk_order = 4;
239  }
240  else if (rk_method_string == "ssprk3_ex"){
241  runge_kutta_method = RKMethodEnum::ssprk3_ex;
242  n_rk_stages = 3;
243  rk_order = 3;
244  }
245  else if (rk_method_string == "heun2_ex"){
246  runge_kutta_method = RKMethodEnum::heun2_ex;
247  n_rk_stages = 2;
248  rk_order = 2;
249  }
250  else if (rk_method_string == "euler_ex"){
251  runge_kutta_method = RKMethodEnum::euler_ex;
252  n_rk_stages = 1;
253  rk_order = 1;
254  }
255  else if (rk_method_string == "euler_im"){
256  runge_kutta_method = RKMethodEnum::euler_im;
257  n_rk_stages = 1;
258  rk_order = 1;
259  }
260  else if (rk_method_string == "dirk_2_im"){
261  runge_kutta_method = RKMethodEnum::dirk_2_im;
262  n_rk_stages = 2;
263  rk_order = 2;
264  }
265  else if (rk_method_string == "dirk_3_im"){
266  runge_kutta_method = RKMethodEnum::dirk_3_im;
267  n_rk_stages = 3;
268  rk_order = 3;
269  }
270  else if (rk_method_string == "RK3_2_5F_3SStarPlus"){
271  runge_kutta_method = RKMethodEnum::RK3_2_5F_3SStarPlus;
272  n_rk_stages = 5;
273  num_delta = 5;
274  rk_order = 3;
275  is_3Sstarplus = true;
276  }
277  else if (rk_method_string == "RK4_3_5_3SStar"){
278  runge_kutta_method = RKMethodEnum::RK4_3_5_3SStar;
279  n_rk_stages = 5;
280  num_delta = 7;
281  rk_order = 4;
282  is_3Sstarplus = false;
283  }
284  else if (rk_method_string == "RK4_3_9F_3SStarPlus"){
285  runge_kutta_method = RKMethodEnum::RK4_3_9F_3SStarPlus;
286  n_rk_stages = 9;
287  num_delta = 9;
288  rk_order = 4;
289  is_3Sstarplus = true;
290  }
291  else if (rk_method_string == "RK5_4_10F_3SStarPlus"){
292  runge_kutta_method = RKMethodEnum::RK5_4_10F_3SStarPlus;
293  n_rk_stages = 10;
294  num_delta = 10;
295  rk_order = 5;
296  is_3Sstarplus = true;
297  }
298 
299  prm.enter_subsection("rrk root solver");
300  {
301  const std::string output_string_rrk = prm.get("rrk_root_solver_output");
302  if (output_string_rrk == "verbose") rrk_root_solver_output = verbose;
303  else if (output_string_rrk == "quiet") rrk_root_solver_output = quiet;
304 
305  relaxation_runge_kutta_root_tolerance = prm.get_double("relaxation_runge_kutta_root_tolerance");
306  use_relaxation_runge_kutta = prm.get_bool("use_relaxation_runge_kutta");
308  // For backwards compatibility
310  const int mpi_rank = dealii::Utilities::MPI::this_mpi_process(MPI_COMM_WORLD);
311  dealii::ConditionalOStream pcout(std::cout, mpi_rank==0);
312  pcout << "Warning: rrk_explicit_solver parameter is depreciated. " << std::endl
313  << "Backwards compatibility was verified upon implementation." <<std::endl;
314 
315  }
316  }
317  prm.leave_subsection();
318 
319  prm.enter_subsection("low-storage rk solver");
320  {
321  atol = prm.get_double("atol");
322  rtol = prm.get_double("rtol");
323  beta1 = prm.get_double("beta1");
324  beta2 = prm.get_double("beta2");
325  beta3 = prm.get_double("beta3");
326  }
327  prm.leave_subsection();
328 
329  }
330  prm.leave_subsection();
331 }
332 
333 } // Parameters namespace
334 } // PHiLiP namespace
bool is_3Sstarplus
True or false depending on what low-storage RK method is used.
OutputEnum ode_output
verbose or quiet.
double output_solution_start_time
Time at which to start outputting the solution.
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.