Smith  0.1
Smith is an implicit thermal structural mechanics simulation code.
solver_config.hpp
Go to the documentation of this file.
1 // Copyright (c) Lawrence Livermore National Security, LLC and
2 // other Smith 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"
19 
20 namespace smith {
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 
260  int relax_type = 88; // l1-hybrid symmetric Gauss-Seidel smoother
265  3; // geometric dimension of problem, used to set more robust options for systems such as elasticity
266 };
267 
271 enum class PetscPCType
272 {
273  JACOBI,
274  JACOBI_L1,
275  JACOBI_ROWSUM,
276  JACOBI_ROWMAX,
277  PBJACOBI,
278  BJACOBI,
279  LU,
280  ILU,
281  CHOLESKY,
282  SVD,
283  ASM,
285  GASM,
287  GAMG,
288  HMG,
289  NONE,
290 };
291 
293 inline std::string petscPCName(const PetscPCType& s)
294 {
295  switch (s) {
296  case PetscPCType::JACOBI:
297  return "JACOBI";
299  return "JACOBI_L1";
301  return "JACOBI_ROWSUM";
303  return "JACOBI_ROWMAX";
305  return "PBJACOBI";
307  return "BJACOBI";
308  case PetscPCType::LU:
309  return "LU";
310  case PetscPCType::ILU:
311  return "ILU";
313  return "CHOLESKY";
314  case PetscPCType::SVD:
315  return "SVD";
316  case PetscPCType::ASM:
317  return "ASM";
318  case PetscPCType::GASM:
319  return "GASM";
320  case PetscPCType::GAMG:
321  return "GAMG";
322  case PetscPCType::HMG:
323  return "HMG";
324  case PetscPCType::NONE:
325  return "NONE";
326  }
327  // This cannot happen, but GCC doesn't know that
328  return "UNKNOWN";
329 }
330 
332 inline std::ostream& operator<<(std::ostream& os, PetscPCType s) { return os << petscPCName(s); }
333 
334 // _preconditioners_start
336 enum class Preconditioner
337 {
338  HypreJacobi,
339  HypreL1Jacobi,
341  HypreAMG,
342  HypreILU,
343  AMGX,
344  Petsc,
345  AMGFContact,
346  None
347 };
348 // _preconditioners_end
349 
351 inline std::string preconditionerName(Preconditioner p)
352 {
353  switch (p) {
355  return "HypreJacobi";
357  return "HypreL1Jacobi";
359  return "HypreGaussSeidel";
361  return "HypreAMG";
363  return "HypreILU";
365  return "AMGX";
367  return "Petsc";
369  return "AMGFContact";
371  return "None";
372  }
373  // This cannot happen, but GCC doesn't know that
374  return "UNKNOWN";
375 }
376 
378 inline std::ostream& operator<<(std::ostream& os, Preconditioner p) { return os << preconditionerName(p); }
379 
381 inline std::map<std::string, Preconditioner> preconditionerMap = {
382  {"HypreJacobi", Preconditioner::HypreJacobi},
383  {"HypreL1Jacobi", Preconditioner::HypreL1Jacobi},
384  {"HypreGaussSeidel", Preconditioner::HypreGaussSeidel},
385  {"HypreAMG", Preconditioner::HypreAMG},
386  {"HypreILU", Preconditioner::HypreILU},
387  {"AMGX", Preconditioner::AMGX},
388  {"Petsc", Preconditioner::Petsc},
389  {"AMGFContact", Preconditioner::AMGFContact},
390  {"None", Preconditioner::None},
391 };
392 
393 // _linear_options_start
398 
401 
404 
407 
410 
412  double relative_tol = 1.0e-8;
413 
415  double absolute_tol = 1.0e-12;
416 
418  int max_iterations = 300;
419 
421  int print_level = 0;
422 
425 };
426 // _linear_options_end
427 
430 {
431  NEVER,
432  WHEN_INDEFINITE,
433  WHEN_INDEFINITE_OR_BOUNDARY,
434  ALWAYS
435 };
436 
437 // _nonlinear_options_start
442 
444  double relative_tol = 1.0e-8;
445 
447  double absolute_tol = 1.0e-12;
448 
450  int min_iterations = 0;
451 
453  int max_iterations = 20;
454 
457 
459  int print_level = 0;
460 
462  double trust_region_scaling = 0.1;
463 
465  SubSpaceOptions subspace_option = SubSpaceOptions::NEVER;
466 
468  int num_leftmost = 1;
469 
471  bool force_monolithic = false;
472 };
473 // _nonlinear_options_end
474 
475 } // namespace smith
476 
477 // std::format support for Smith solver enums
478 namespace std {
479 template <>
482 
483 template <>
486 
487 template <>
490 
491 template <>
494 } // namespace std
Shared helpers for C++ standard formatting support in Smith.
Accelerator functionality.
Definition: smith.cpp:36
std::map< std::string, Preconditioner > preconditionerMap
string->value matching for optionally entering options as string in command line
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.
std::map< std::string, LinearSolver > linearSolverMap
string->value matching for optionally entering options as string in command line
std::string linearName(const LinearSolver &s)
Convert linear solver enums to their string names.
LinearSolver
Linear solution method indicator.
Preconditioner
The type of preconditioner to be used.
std::map< std::string, NonlinearSolver > nonlinearSolverMap
string->value matching for optionally entering options as string in command line
std::ostream & operator<<(std::ostream &out, DoF dof)
stream output for DoF
std::string petscPCName(const PetscPCType &s)
Convert Petsc preconditioner enums to their string names.
TimestepMethod
Timestep method of a solver.
PetscPCType
Preconditioner types supported by PETSc.
AMGXSolver
Solver types supported by AMGX.
NonlinearSolver
Nonlinear solver method indicator.
std::string preconditionerName(Preconditioner p)
Convert preconditioner enums to their string names.
DirichletEnforcementMethod
this enum describes which way to enforce the time-varying constraint u(t) == U(t)
Stores the configuration information for an AMGFContact preconditioner.
int relax_type
The amg relaxation type.
int dim_systems_options
amg DimSystemsOptions
Stores the information required to configure a NVIDIA AMGX preconditioner.
AMGXSolver solver
The solver algorithm.
bool verbose
Whether to display statistics from AMGX.
AMGXSolver smoother
The smoother algorithm.
Parameters for an iterative linear solution scheme.
int preconditioner_print_level
Debugging print level for the preconditioner.
int max_iterations
Maximum number of iterations.
double relative_tol
Relative tolerance.
int print_level
Debugging print level for the linear solver.
AMGFContactOptions amgfcontact_options
AMGFContact Options, used for Preconditioner::AMGFContact.
Preconditioner preconditioner
PreconditionerOptions selection.
PetscPCType petsc_preconditioner
PETSc preconditioner type.
double absolute_tol
Absolute tolerance.
AMGXOptions amgx_options
AMGX Options, used for Preconditioner::AMGX.
LinearSolver linear_solver
Linear solver selection.
Nonlinear solution scheme parameters.
int min_iterations
Minimum number of iterations.
int max_iterations
Maximum number of iterations.
double trust_region_scaling
Scaling for the initial trust region size.
int max_line_search_iterations
Maximum line search cutbacks.
double relative_tol
Relative tolerance.
int print_level
Debug print level.
int num_leftmost
Number of extra leftmost eigenvector to be stored between solves.
double absolute_tol
Absolute tolerance.
NonlinearSolver nonlin_solver
Nonlinear solver selection.
SubSpaceOptions subspace_option
Option for how when the subspace solver should be utilized within trust-region solver.
bool force_monolithic
Should the gradient be converted to a monolithic matrix.
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.
Formatter that renders values through operator<<.
Definition: format.hpp:32