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 #include <vector>
17 
18 #include "mfem.hpp"
20 #include "smith/numerics/block_preconditioner.hpp"
21 
22 namespace smith {
23 
27 enum class TimestepMethod
28 {
29  QuasiStatic,
31  // options for first order ODEs
33  SDIRK33,
34  ForwardEuler,
35  RK2,
36  RK3SSP,
37  RK4,
40  SDIRK23,
41  SDIRK34,
43  // options for second order ODEs
44  //
45  // note: we don't have a way to communicate
46  // parameters to the TimestepMethod,
47  // right now, so Newmark implies
48  // (beta = 0.25, gamma = 0.5)
49  Newmark,
50  HHTAlpha,
51  WBZAlpha,
55  FoxGoodwin
56 };
57 
63 {
71 
80 
91 };
92 
97 
100 };
101 
102 // _linear_solvers_start
104 enum class LinearSolver
105 {
106  CG,
107  GMRES,
108  SuperLU,
109  Strumpack,
110  PetscCG,
111  PetscGMRES
112 };
113 // _linear_solvers_end
114 
116 inline std::string linearName(const LinearSolver& s)
117 {
118  switch (s) {
119  case LinearSolver::CG:
120  return "CG";
121  case LinearSolver::GMRES:
122  return "GMRES";
124  return "SuperLU";
126  return "Strumpack";
128  return "PetscCG";
130  return "PetscGMRES";
131  }
132  // This cannot happen, but GCC doesn't know that
133  return "UNKNOWN";
134 }
135 
137 inline std::ostream& operator<<(std::ostream& os, LinearSolver s) { return os << linearName(s); }
138 
140 inline std::map<std::string, LinearSolver> linearSolverMap = {
141  {"CG", LinearSolver::CG}, {"GMRES", LinearSolver::GMRES},
142  {"SuperLU", LinearSolver::SuperLU}, {"Strumpack", LinearSolver::Strumpack},
143  {"PetscCG", LinearSolver::PetscCG}, {"PetscGMRES", LinearSolver::PetscGMRES},
144 };
145 
146 // Add a custom list of strings? conduit node?
147 // Arbitrary string (e.g. json) to define parameters?
148 
149 // _nonlinear_solvers_start
151 enum class NonlinearSolver
152 {
153  Newton,
154  LBFGS,
156  TrustRegion,
157  KINFullStep,
159  KINPicard,
160  PetscNewton,
164 };
165 // _nonlinear_solvers_end
166 
168 inline std::string nonlinearName(const NonlinearSolver& s)
169 {
170  switch (s) {
172  return "Newton";
174  return "LBFGS";
176  return "NewtonLineSearch";
178  return "TrustRegion";
180  return "KINFullStep";
182  return "KINBacktrackingLineSearch";
184  return "KINPicard";
186  return "PetscNewton";
188  return "PetscNewtonBacktracking";
190  return "PetscNewtonCriticalPoint";
192  return "PetscTrustRegion";
193  }
194  // This cannot happen, but GCC doesn't know that
195  return "UNKNOWN";
196 }
197 
199 inline std::ostream& operator<<(std::ostream& os, NonlinearSolver s) { return os << nonlinearName(s); }
200 
202 inline std::map<std::string, NonlinearSolver> nonlinearSolverMap = {
203  {"Newton", NonlinearSolver::Newton},
204  {"LBFGS", NonlinearSolver::LBFGS},
205  {"NewtonLineSearch", NonlinearSolver::NewtonLineSearch},
206  {"TrustRegion", NonlinearSolver::TrustRegion},
207  {"KINFullStep", NonlinearSolver::KINFullStep},
208  {"KINBacktrackingLineSearch", NonlinearSolver::KINBacktrackingLineSearch},
209  {"KINPicard", NonlinearSolver::KINPicard},
210  {"PetscNewton", NonlinearSolver::PetscNewton},
211  {"PetscNewtonBacktracking", NonlinearSolver::PetscNewtonBacktracking},
212  {"PetscNewtonCriticalPoint", NonlinearSolver::PetscNewtonCriticalPoint},
213  {"PetscTrustRegion", NonlinearSolver::PetscTrustRegion},
214 };
215 
219 enum class AMGXSolver
220 {
221  AMG,
222  PCGF,
223  CG,
224  PCG,
225  PBICGSTAB,
226  BICGSTAB,
227  FGMRES,
228  JACOBI_L1,
229  GS,
230  POLYNOMIAL,
232  BLOCK_JACOBI,
233  MULTICOLOR_GS,
235 };
236 
240 struct AMGXOptions {
252  bool verbose = false;
253 };
254 
262  int relax_type = 88; // l1-hybrid symmetric Gauss-Seidel smoother
267  3; // geometric dimension of problem, used to set more robust options for systems such as elasticity
268 };
269 
273 enum class PetscPCType
274 {
275  JACOBI,
276  JACOBI_L1,
277  JACOBI_ROWSUM,
278  JACOBI_ROWMAX,
279  PBJACOBI,
280  BJACOBI,
281  LU,
282  ILU,
283  CHOLESKY,
284  SVD,
285  ASM,
287  GASM,
289  GAMG,
290  HMG,
291  NONE,
292 };
293 
295 inline std::string petscPCName(const PetscPCType& s)
296 {
297  switch (s) {
298  case PetscPCType::JACOBI:
299  return "JACOBI";
301  return "JACOBI_L1";
303  return "JACOBI_ROWSUM";
305  return "JACOBI_ROWMAX";
307  return "PBJACOBI";
309  return "BJACOBI";
310  case PetscPCType::LU:
311  return "LU";
312  case PetscPCType::ILU:
313  return "ILU";
315  return "CHOLESKY";
316  case PetscPCType::SVD:
317  return "SVD";
318  case PetscPCType::ASM:
319  return "ASM";
320  case PetscPCType::GASM:
321  return "GASM";
322  case PetscPCType::GAMG:
323  return "GAMG";
324  case PetscPCType::HMG:
325  return "HMG";
326  case PetscPCType::NONE:
327  return "NONE";
328  }
329  // This cannot happen, but GCC doesn't know that
330  return "UNKNOWN";
331 }
332 
334 inline std::ostream& operator<<(std::ostream& os, PetscPCType s) { return os << petscPCName(s); }
335 
336 // _preconditioners_start
338 enum class Preconditioner
339 {
340  HypreJacobi,
341  HypreL1Jacobi,
343  HypreAMG,
344  HypreILU,
345  AMGX,
346  Petsc,
347  AMGFContact,
348  BlockDiagonal,
350  BlockSchur,
351  None
352 };
353 // _preconditioners_end
354 
356 inline std::string preconditionerName(Preconditioner p)
357 {
358  switch (p) {
360  return "HypreJacobi";
362  return "HypreL1Jacobi";
364  return "HypreGaussSeidel";
366  return "HypreAMG";
368  return "HypreILU";
370  return "AMGX";
372  return "Petsc";
374  return "AMGFContact";
376  return "BlockDiagonal";
378  return "BlockTriangular";
380  return "BlockSchur";
382  return "None";
383  }
384  // This cannot happen, but GCC doesn't know that
385  return "UNKNOWN";
386 }
387 
389 inline std::ostream& operator<<(std::ostream& os, Preconditioner p) { return os << preconditionerName(p); }
390 
392 inline std::map<std::string, Preconditioner> preconditionerMap = {
393  {"HypreJacobi", Preconditioner::HypreJacobi},
394  {"HypreL1Jacobi", Preconditioner::HypreL1Jacobi},
395  {"HypreGaussSeidel", Preconditioner::HypreGaussSeidel},
396  {"HypreAMG", Preconditioner::HypreAMG},
397  {"HypreILU", Preconditioner::HypreILU},
398  {"AMGX", Preconditioner::AMGX},
399  {"Petsc", Preconditioner::Petsc},
400  {"AMGFContact", Preconditioner::AMGFContact},
401  {"BlockDiagonal", Preconditioner::BlockDiagonal},
402  {"BlockTriangular", Preconditioner::BlockTriangular},
403  {"BlockSchur", Preconditioner::BlockSchur},
404  {"None", Preconditioner::None},
405 };
406 
407 // _linear_options_start
412 
415 
418 
421 
424 
426  double relative_tol = 1.0e-8;
427 
429  double absolute_tol = 1.0e-12;
430 
432  int max_iterations = 300;
433 
435  int print_level = 0;
436 
439 
441  std::vector<LinearSolverOptions> sub_block_linear_solver_options = {};
442 
445 
448 
451 };
452 // _linear_options_end
453 
456 {
457  NEVER,
458  WHEN_INDEFINITE,
459  WHEN_INDEFINITE_OR_BOUNDARY,
460  ALWAYS
461 };
462 
463 // _nonlinear_options_start
468 
470  double relative_tol = 1.0e-8;
471 
473  double absolute_tol = 1.0e-12;
474 
476  int min_iterations = 0;
477 
479  int max_iterations = 20;
480 
483 
485  int print_level = 0;
486 
488  double trust_region_scaling = 0.1;
489 
491  SubSpaceOptions subspace_option = SubSpaceOptions::NEVER;
492 
494  int num_leftmost = 1;
495 };
496 // _nonlinear_options_end
497 
498 } // namespace smith
499 
500 // std::format support for Smith solver enums
501 namespace std {
502 template <>
505 
506 template <>
509 
510 template <>
513 
514 template <>
517 } // 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
SchurApproxType
Selects how the (1,1) Schur operator is approximated.
BlockTriangularType
Selects the block triangular sweep used by BlockTriangularPreconditioner.
BlockSchurType
Selects the block Schur preconditioner variant.
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.
SchurApproxType schur_approx_type
Schur approximation type.
PetscPCType petsc_preconditioner
PETSc preconditioner type.
std::vector< LinearSolverOptions > sub_block_linear_solver_options
Subblock linear solver options for block preconditioners.
BlockSchurType block_schur_type
Block Schur preconditioner factorization type.
double absolute_tol
Absolute tolerance.
AMGXOptions amgx_options
AMGX Options, used for Preconditioner::AMGX.
BlockTriangularType block_triangular_type
Block Triangular Preconditioner factorization type.
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.
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