Serac  0.1
Serac is an implicit thermal strucural mechanics simulation code.
solver_config.hpp
Go to the documentation of this file.
1 // Copyright (c) Lawrence Livermore National Security, LLC and
2 // other Serac Project Developers. See the top-level LICENSE file for
3 // details.
4 //
5 // SPDX-License-Identifier: (BSD-3-Clause)
6 
13 #pragma once
14 
15 #include <variant>
16 
17 #include "mfem.hpp"
18 #include "axom/fmt.hpp"
19 
20 namespace serac {
21 
25 enum class TimestepMethod
26 {
27  QuasiStatic,
29  // options for first order ODEs
31  SDIRK33,
32  ForwardEuler,
33  RK2,
34  RK3SSP,
35  RK4,
38  SDIRK23,
39  SDIRK34,
41  // options for second order ODEs
42  //
43  // note: we don't have a way to communicate
44  // parameters to the TimestepMethod,
45  // right now, so Newmark implies
46  // (beta = 0.25, gamma = 0.5)
47  Newmark,
48  HHTAlpha,
49  WBZAlpha,
53  FoxGoodwin
54 };
55 
61 {
69 
78 
89 };
90 
95 
98 };
99 
100 // _linear_solvers_start
102 enum class LinearSolver
103 {
104  CG,
105  GMRES,
106  SuperLU,
107  Strumpack,
108  PetscCG,
109  PetscGMRES
110 };
111 // _linear_solvers_end
112 
114 inline std::string linearName(const LinearSolver& s)
115 {
116  switch (s) {
117  case LinearSolver::CG:
118  return "CG";
119  case LinearSolver::GMRES:
120  return "GMRES";
122  return "SuperLU";
124  return "Strumpack";
126  return "PetscCG";
128  return "PetscGMRES";
129  }
130  // This cannot happen, but GCC doesn't know that
131  return "UNKNOWN";
132 }
133 
135 inline std::ostream& operator<<(std::ostream& os, LinearSolver s) { return os << linearName(s); }
136 
138 inline std::map<std::string, LinearSolver> linearSolverMap = {
139  {"CG", LinearSolver::CG}, {"GMRES", LinearSolver::GMRES},
140  {"SuperLU", LinearSolver::SuperLU}, {"Strumpack", LinearSolver::Strumpack},
141  {"PetscCG", LinearSolver::PetscCG}, {"PetscGMRES", LinearSolver::PetscGMRES},
142 };
143 
144 // Add a custom list of strings? conduit node?
145 // Arbitrary string (e.g. json) to define parameters?
146 
147 // _nonlinear_solvers_start
149 enum class NonlinearSolver
150 {
151  Newton,
152  LBFGS,
154  TrustRegion,
155  KINFullStep,
157  KINPicard,
158  PetscNewton,
162 };
163 // _nonlinear_solvers_end
164 
166 inline std::string nonlinearName(const NonlinearSolver& s)
167 {
168  switch (s) {
170  return "Newton";
172  return "LBFGS";
174  return "NewtonLineSearch";
176  return "TrustRegion";
178  return "KINFullStep";
180  return "KINBacktrackingLineSearch";
182  return "KINPicard";
184  return "PetscNewton";
186  return "PetscNewtonBacktracking";
188  return "PetscNewtonCriticalPoint";
190  return "PetscTrustRegion";
191  }
192  // This cannot happen, but GCC doesn't know that
193  return "UNKNOWN";
194 }
195 
197 inline std::ostream& operator<<(std::ostream& os, NonlinearSolver s) { return os << nonlinearName(s); }
198 
200 inline std::map<std::string, NonlinearSolver> nonlinearSolverMap = {
201  {"Newton", NonlinearSolver::Newton},
202  {"LBFGS", NonlinearSolver::LBFGS},
203  {"NewtonLineSearch", NonlinearSolver::NewtonLineSearch},
204  {"TrustRegion", NonlinearSolver::TrustRegion},
205  {"KINFullStep", NonlinearSolver::KINFullStep},
206  {"KINBacktrackingLineSearch", NonlinearSolver::KINBacktrackingLineSearch},
207  {"KINPicard", NonlinearSolver::KINPicard},
208  {"PetscNewton", NonlinearSolver::PetscNewton},
209  {"PetscNewtonBacktracking", NonlinearSolver::PetscNewtonBacktracking},
210  {"PetscNewtonCriticalPoint", NonlinearSolver::PetscNewtonCriticalPoint},
211  {"PetscTrustRegion", NonlinearSolver::PetscTrustRegion},
212 };
213 
217 enum class AMGXSolver
218 {
219  AMG,
220  PCGF,
221  CG,
222  PCG,
223  PBICGSTAB,
224  BICGSTAB,
225  FGMRES,
226  JACOBI_L1,
227  GS,
228  POLYNOMIAL,
230  BLOCK_JACOBI,
231  MULTICOLOR_GS,
233 };
234 
238 struct AMGXOptions {
250  bool verbose = false;
251 };
252 
256 enum class PetscPCType
257 {
258  JACOBI,
259  JACOBI_L1,
260  JACOBI_ROWSUM,
261  JACOBI_ROWMAX,
262  PBJACOBI,
263  BJACOBI,
264  LU,
265  ILU,
266  CHOLESKY,
267  SVD,
268  ASM,
270  GASM,
272  GAMG,
273  HMG,
274  NONE,
275 };
276 
278 inline std::string petscPCName(const PetscPCType& s)
279 {
280  switch (s) {
281  case PetscPCType::JACOBI:
282  return "JACOBI";
284  return "JACOBI_L1";
286  return "JACOBI_ROWSUM";
288  return "JACOBI_ROWMAX";
290  return "PBJACOBI";
292  return "BJACOBI";
293  case PetscPCType::LU:
294  return "LU";
295  case PetscPCType::ILU:
296  return "ILU";
298  return "CHOLESKY";
299  case PetscPCType::SVD:
300  return "SVD";
301  case PetscPCType::ASM:
302  return "ASM";
303  case PetscPCType::GASM:
304  return "GASM";
305  case PetscPCType::GAMG:
306  return "GAMG";
307  case PetscPCType::HMG:
308  return "HMG";
309  case PetscPCType::NONE:
310  return "NONE";
311  }
312  // This cannot happen, but GCC doesn't know that
313  return "UNKNOWN";
314 }
315 
317 inline std::ostream& operator<<(std::ostream& os, PetscPCType s) { return os << petscPCName(s); }
318 
319 // _preconditioners_start
321 enum class Preconditioner
322 {
323  HypreJacobi,
324  HypreL1Jacobi,
326  HypreAMG,
327  HypreILU,
328  AMGX,
329  Petsc,
330  None
331 };
332 // _preconditioners_end
333 
335 inline std::string preconditionerName(Preconditioner p)
336 {
337  switch (p) {
339  return "HypreJacobi";
341  return "HypreL1Jacobi";
343  return "HypreGaussSeidel";
345  return "HypreAMG";
347  return "HypreILU";
349  return "AMGX";
351  return "Petsc";
353  return "None";
354  }
355  // This cannot happen, but GCC doesn't know that
356  return "UNKNOWN";
357 }
358 
360 inline std::ostream& operator<<(std::ostream& os, Preconditioner p) { return os << preconditionerName(p); }
361 
363 inline std::map<std::string, Preconditioner> preconditionerMap = {
364  {"HypreJacobi", Preconditioner::HypreJacobi},
365  {"HypreL1Jacobi", Preconditioner::HypreL1Jacobi},
366  {"HypreGaussSeidel", Preconditioner::HypreGaussSeidel},
367  {"HypreAMG", Preconditioner::HypreAMG},
368  {"HypreILU", Preconditioner::HypreILU},
369  {"AMGX", Preconditioner::AMGX},
370  {"Petsc", Preconditioner::Petsc},
371  {"None", Preconditioner::None},
372 };
373 
374 // _linear_options_start
379 
382 
385 
388 
390  double relative_tol = 1.0e-8;
391 
393  double absolute_tol = 1.0e-12;
394 
396  int max_iterations = 300;
397 
399  int print_level = 0;
400 
403 };
404 // _linear_options_end
405 
408 {
409  NEVER,
410  WHEN_INDEFINITE,
411  WHEN_INDEFINITE_OR_BOUNDARY,
412  ALWAYS
413 };
414 
415 // _nonlinear_options_start
420 
422  double relative_tol = 1.0e-8;
423 
425  double absolute_tol = 1.0e-12;
426 
428  int min_iterations = 0;
429 
431  int max_iterations = 20;
432 
435 
437  int print_level = 0;
438 
440  double trust_region_scaling = 0.1;
441 
443  SubSpaceOptions subspace_option = SubSpaceOptions::NEVER;
444 
446  int num_leftmost = 1;
447 
449  bool force_monolithic = false;
450 };
451 // _nonlinear_options_end
452 
453 } // namespace serac
454 
455 // fmt support for serac::NonlinearSolver
456 namespace axom::fmt {
457 template <>
458 struct formatter<serac::NonlinearSolver> : ostream_formatter {
459 };
460 
461 // fmt support for serac::LinearSolver
462 template <>
463 struct formatter<serac::LinearSolver> : ostream_formatter {
464 };
465 
466 // fmt support for serac::Preconditioner
467 template <>
468 struct formatter<serac::Preconditioner> : ostream_formatter {
469 };
470 
471 // fmt support for serac::PetscPCType
472 template <>
473 struct formatter<serac::PetscPCType> : ostream_formatter {
474 };
475 } // namespace axom::fmt
Accelerator functionality.
Definition: serac.cpp:36
LinearSolver
Linear solution method indicator.
DirichletEnforcementMethod
this enum describes which way to enforce the time-varying constraint u(t) == U(t)
NonlinearSolver
Nonlinear solver method indicator.
AMGXSolver
Solver types supported by AMGX.
std::string linearName(const LinearSolver &s)
Convert linear solver enums to their string names.
std::map< std::string, LinearSolver > linearSolverMap
string->value matching for optionally entering options as string in command line
std::map< std::string, Preconditioner > preconditionerMap
string->value matching for optionally entering options as string in command line
std::string petscPCName(const PetscPCType &s)
Convert Petsc preconditioner enums to their string names.
Preconditioner
The type of preconditioner to be used.
PetscPCType
Preconditioner types supported by PETSc.
std::map< std::string, NonlinearSolver > nonlinearSolverMap
string->value matching for optionally entering options as string in command line
std::string preconditionerName(Preconditioner p)
Convert preconditioner enums to their string names.
std::string nonlinearName(const NonlinearSolver &s)
Convert nonlinear linear solver enums to their string names.
SubSpaceOptions
Enumerated options for when to use trust-region subspace solver.
TimestepMethod
Timestep method of a solver.
std::ostream & operator<<(std::ostream &out, DoF dof)
stream output for DoF
Stores the information required to configure a NVIDIA AMGX preconditioner.
AMGXSolver smoother
The smoother algorithm.
AMGXSolver solver
The solver algorithm.
bool verbose
Whether to display statistics from AMGX.
Parameters for an iterative linear solution scheme.
AMGXOptions amgx_options
AMGX Options, used for Preconditioner::AMGX.
Preconditioner preconditioner
PreconditionerOptions selection.
LinearSolver linear_solver
Linear solver selection.
double relative_tol
Relative tolerance.
int preconditioner_print_level
Debugging print level for the preconditioner.
PetscPCType petsc_preconditioner
PETSc preconditioner type.
int max_iterations
Maximum number of iterations.
int print_level
Debugging print level for the linear solver.
double absolute_tol
Absolute tolerance.
Nonlinear solution scheme parameters.
double trust_region_scaling
Scaling for the initial trust region size.
int print_level
Debug print level.
bool force_monolithic
Should the gradient be converted to a monolithic matrix.
SubSpaceOptions subspace_option
Option for how when the subspace solver should be utilized within trust-region solver.
double relative_tol
Relative tolerance.
NonlinearSolver nonlin_solver
Nonlinear solver selection.
int min_iterations
Minimum number of iterations.
double absolute_tol
Absolute tolerance.
int num_leftmost
Number of extra leftmost eigenvector to be stored between solves.
int max_line_search_iterations
Maximum line search cutbacks.
int max_iterations
Maximum number of iterations.
A timestep and boundary condition enforcement method for a dynamic solver.
TimestepMethod timestepper
The timestepping method to be applied.
DirichletEnforcementMethod enforcement_method
The essential boundary enforcement method to use.