https://mooseframework.inl.gov
Conversion.C
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://mooseframework.inl.gov
3 //*
4 //* All rights reserved, see COPYRIGHT for full restrictions
5 //* https://github.com/idaholab/moose/blob/master/COPYRIGHT
6 //*
7 //* Licensed under LGPL 2.1, please see LICENSE for details
8 //* https://www.gnu.org/licenses/lgpl-2.1.html
9 
10 // MOOSE includes
11 #include "Conversion.h"
12 #include "MooseError.h"
13 #include "ExecFlagEnum.h"
14 #include "MooseUtils.h"
15 
16 #include "libmesh/string_to_enum.h"
17 #include "libmesh/point.h"
18 
19 // system includes
20 #include <iomanip>
21 
22 using namespace libMesh;
23 
24 namespace Moose
25 {
26 std::map<std::string, CoordinateSystemType> coordinate_system_type_to_enum;
27 std::map<std::string, SolveType> solve_type_to_enum;
28 std::map<std::string, EigenSolveType> eigen_solve_type_to_enum;
29 std::map<std::string, EigenProblemType> eigen_problem_type_to_enum;
30 std::map<std::string, WhichEigenPairs> which_eigen_pairs_to_enum;
31 std::map<std::string, LineSearchType> line_search_type_to_enum;
32 std::map<std::string, TimeIntegratorType> time_integrator_to_enum;
33 std::map<std::string, MffdType> mffd_type_to_enum;
34 std::map<std::string, RelationshipManagerType> rm_type_to_enum;
35 
36 void
38 {
40  {
44  }
45 }
46 
47 void
49 {
50  if (solve_type_to_enum.empty())
51  {
52  solve_type_to_enum["PJFNK"] = ST_PJFNK;
53  solve_type_to_enum["JFNK"] = ST_JFNK;
54  solve_type_to_enum["NEWTON"] = ST_NEWTON;
55  solve_type_to_enum["FD"] = ST_FD;
56  solve_type_to_enum["LINEAR"] = ST_LINEAR;
57  }
58 }
59 
60 void
62 {
63  if (eigen_solve_type_to_enum.empty())
64  {
68  eigen_solve_type_to_enum["JACOBI_DAVIDSON"] = EST_JACOBI_DAVIDSON;
69  eigen_solve_type_to_enum["NONLINEAR_POWER"] = EST_NONLINEAR_POWER;
74  }
75 }
76 
77 void
79 {
80  if (eigen_problem_type_to_enum.empty())
81  {
87  eigen_problem_type_to_enum["POS_GEN_NON_HERMITIAN"] = EPT_POS_GEN_NON_HERMITIAN;
89  }
90 }
91 
92 void
94 {
95  if (which_eigen_pairs_to_enum.empty())
96  {
97  which_eigen_pairs_to_enum["LARGEST_MAGNITUDE"] = WEP_LARGEST_MAGNITUDE;
98  which_eigen_pairs_to_enum["SMALLEST_MAGNITUDE"] = WEP_SMALLEST_MAGNITUDE;
100  which_eigen_pairs_to_enum["SMALLEST_REAL"] = WEP_SMALLEST_REAL;
101  which_eigen_pairs_to_enum["LARGEST_IMAGINARY"] = WEP_LARGEST_IMAGINARY;
102  which_eigen_pairs_to_enum["SMALLEST_IMAGINARY"] = WEP_SMALLEST_IMAGINARY;
103  which_eigen_pairs_to_enum["TARGET_MAGNITUDE"] = WEP_TARGET_MAGNITUDE;
105  which_eigen_pairs_to_enum["TARGET_IMAGINARY"] = WEP_TARGET_IMAGINARY;
106  which_eigen_pairs_to_enum["ALL_EIGENVALUES"] = WEP_ALL_EIGENVALUES;
107  which_eigen_pairs_to_enum["SLEPC_DEFAULT"] = WEP_SLEPC_DEFAULT;
108  }
109 }
110 
111 void
113 {
114  if (line_search_type_to_enum.empty())
115  {
119 
126  }
127 }
128 
129 void
131 {
132  if (time_integrator_to_enum.empty())
133  {
134  time_integrator_to_enum["IMPLICIT_EULER"] = TI_IMPLICIT_EULER;
135  time_integrator_to_enum["EXPLICIT_EULER"] = TI_EXPLICIT_EULER;
136  time_integrator_to_enum["CRANK_NICOLSON"] = TI_CRANK_NICOLSON;
138  time_integrator_to_enum["EXPLICIT_MIDPOINT"] = TI_EXPLICIT_MIDPOINT;
139  time_integrator_to_enum["LSTABLE_DIRK2"] = TI_LSTABLE_DIRK2;
140  time_integrator_to_enum["EXPLICIT_TVDRK2"] = TI_EXPLICIT_TVD_RK_2;
141  }
142 }
143 
144 void
146 {
147  if (mffd_type_to_enum.empty())
148  {
149  mffd_type_to_enum["DS"] = MFFD_DS;
150  mffd_type_to_enum["WP"] = MFFD_WP;
151  }
152 }
153 
154 void
156 {
157  if (rm_type_to_enum.empty())
158  {
159  rm_type_to_enum["DEFAULT"] = RelationshipManagerType::DEFAULT;
160  rm_type_to_enum["GEOMETRIC"] = RelationshipManagerType::GEOMETRIC;
161  rm_type_to_enum["ALGEBRAIC"] = RelationshipManagerType::ALGEBRAIC;
162  rm_type_to_enum["COUPLING"] = RelationshipManagerType::COUPLING;
163  }
164 }
165 
166 template <>
168 stringToEnum<QuadratureType>(const std::string & s)
169 {
170  return Utility::string_to_enum<QuadratureType>("Q" + s);
171 }
172 
173 template <>
174 Order
175 stringToEnum<Order>(const std::string & s)
176 {
177  std::string upper(s);
178  std::transform(upper.begin(), upper.end(), upper.begin(), ::toupper);
179 
180  if (upper.compare("AUTO") == 0)
181  return INVALID_ORDER;
182  else
183  return Utility::string_to_enum<Order>(upper);
184 }
185 
186 template <>
189 {
191 
192  std::string upper(s);
193  std::transform(upper.begin(), upper.end(), upper.begin(), ::toupper);
194 
195  if (!coordinate_system_type_to_enum.count(upper))
196  mooseError("Unknown coordinate system type: ", upper);
197 
198  return coordinate_system_type_to_enum[upper];
199 }
200 
201 template <>
202 SolveType
203 stringToEnum<SolveType>(const std::string & s)
204 {
205  initSolveType();
206 
207  std::string upper(s);
208  std::transform(upper.begin(), upper.end(), upper.begin(), ::toupper);
209 
210  if (!solve_type_to_enum.count(upper))
211  mooseError("Unknown solve type: ", upper);
212 
213  return solve_type_to_enum[upper];
214 }
215 
216 template <>
218 stringToEnum<EigenSolveType>(const std::string & s)
219 {
221 
222  std::string upper(s);
223  std::transform(upper.begin(), upper.end(), upper.begin(), ::toupper);
224 
225  if (!eigen_solve_type_to_enum.count(upper))
226  mooseError("Unknown eigen solve type: ", upper);
227 
228  return eigen_solve_type_to_enum[upper];
229 }
230 
231 template <>
233 stringToEnum<EigenProblemType>(const std::string & s)
234 {
236 
237  std::string upper(s);
238  std::transform(upper.begin(), upper.end(), upper.begin(), ::toupper);
239 
240  if (!eigen_problem_type_to_enum.count(upper))
241  mooseError("Unknown eigen problem type: ", upper);
242 
243  return eigen_problem_type_to_enum[upper];
244 }
245 
246 template <>
248 stringToEnum<WhichEigenPairs>(const std::string & s)
249 {
251 
252  std::string upper(s);
253  std::transform(upper.begin(), upper.end(), upper.begin(), ::toupper);
254 
255  if (!which_eigen_pairs_to_enum.count(upper))
256  mooseError("Unknown type of WhichEigenPairs: ", upper);
257 
258  return which_eigen_pairs_to_enum[upper];
259 }
260 
261 template <>
263 stringToEnum<LineSearchType>(const std::string & s)
264 {
266 
267  std::string upper(s);
268  std::transform(upper.begin(), upper.end(), upper.begin(), ::toupper);
269 
270  if (!line_search_type_to_enum.count(upper))
271  mooseError("Unknown line search type: ", upper);
272 
273  return line_search_type_to_enum[upper];
274 }
275 
276 template <>
278 stringToEnum<TimeIntegratorType>(const std::string & s)
279 {
281 
282  std::string upper(s);
283  std::transform(upper.begin(), upper.end(), upper.begin(), ::toupper);
284 
285  if (!time_integrator_to_enum.count(upper))
286  mooseError("Unknown time integrator: ", upper);
287 
288  return time_integrator_to_enum[upper];
289 }
290 
291 template <>
292 MffdType
293 stringToEnum<MffdType>(const std::string & s)
294 {
295  initMffdType();
296 
297  std::string upper(s);
298  std::transform(upper.begin(), upper.end(), upper.begin(), ::toupper);
299 
300  if (!mffd_type_to_enum.count(upper))
301  mooseError("Unknown mffd type: ", upper);
302 
303  return mffd_type_to_enum[upper];
304 }
305 
306 template <>
309 {
310  initRMType();
311 
312  std::string upper(s);
313  std::transform(upper.begin(), upper.end(), upper.begin(), ::toupper);
314 
315  if (!rm_type_to_enum.count(upper))
316  mooseError("Unknown RelationshipManager type: ", upper);
317 
318  return rm_type_to_enum[upper];
319 }
320 
321 // Ignore warnings about switching on the |'d type
322 #include "libmesh/ignore_warnings.h"
323 
324 // Definition in MooseTypes.h
325 std::string
327 {
328  // Cannot make a switch statement because the boolean logic doesn't work well with the class type
329  // enumeration and because Cody says so.
330  if (t == RelationshipManagerType::DEFAULT)
331  return "DEFAULT";
332  if (t == RelationshipManagerType::GEOMETRIC)
333  return "GEOMETRIC";
334  if (t == RelationshipManagerType::ALGEBRAIC)
335  return "ALGEBRAIC";
336  if (t == (RelationshipManagerType::GEOMETRIC | RelationshipManagerType::ALGEBRAIC))
337  return "GEOMETRIC and ALGEBRAIC";
338  if (t == (RelationshipManagerType::ALGEBRAIC | RelationshipManagerType::COUPLING))
339  return "ALGEBRAIC and COUPLING";
340  if (t == (RelationshipManagerType::GEOMETRIC | RelationshipManagerType::ALGEBRAIC |
341  RelationshipManagerType::COUPLING))
342  return "GEOMETRIC and ALGEBRAIC and COUPLING";
343  if (t == RelationshipManagerType::COUPLING)
344  return "COUPLING";
345 
346  mooseError("Unknown RelationshipManagerType");
347 }
348 
349 std::string
351 {
353 }
354 
355 // Turn the warnings back on
356 #include "libmesh/restore_warnings.h"
357 
358 std::string
360 {
361  switch (t)
362  {
363  case ST_NEWTON:
364  return "NEWTON";
365  case ST_JFNK:
366  return "JFNK";
367  case ST_PJFNK:
368  return "Preconditioned JFNK";
369  case ST_FD:
370  return "FD";
371  case ST_LINEAR:
372  return "Linear";
373  }
374  return "";
375 }
376 
377 std::string
379 {
380  switch (t)
381  {
382  case EST_POWER:
383  return "Power";
384  case EST_ARNOLDI:
385  return "ARNOLDI";
386  case EST_KRYLOVSCHUR:
387  return "KRYLOVSCHUR";
388  case EST_JACOBI_DAVIDSON:
389  return "Jacobi Davidson";
390  case EST_NONLINEAR_POWER:
391  return "Nonlinear Power";
392  case EST_PJFNKMO:
393  return "PJFNK with Matrix Only";
394  case EST_NEWTON:
395  return "Newton";
396  case EST_JFNK:
397  return "JFNK";
398  case EST_PJFNK:
399  return "Preconditioned JFNK";
400  }
401  return "";
402 }
403 
404 std::string
406 {
407  switch (t)
408  {
409  case VAR_FIELD_STANDARD:
410  return "STANDARD";
411  case VAR_FIELD_VECTOR:
412  return "VECTOR";
413  case VAR_FIELD_ARRAY:
414  return "ARRAY";
415  case VAR_FIELD_SCALAR:
416  return "SCALAR";
417  case VAR_FIELD_ANY:
418  return "ANY";
419  }
420  return "";
421 }
422 
423 std::string
425 {
426  switch (t)
427  {
428  case SolutionIterationType::Time:
429  return "time";
430  case SolutionIterationType::Nonlinear:
431  return "nonlinear";
432  default:
433  mooseError("Unhandled SolutionIterationType");
434  }
435 }
436 
437 std::string
439 {
440  switch (t)
441  {
442  case ElementType::Element:
443  return "ELEMENT";
445  return "NEIGHBOR";
446  case ElementType::Lower:
447  return "LOWER";
448  default:
449  mooseError("unrecognized type");
450  }
451 }
452 
453 std::string
455 {
457 }
458 
459 std::string
460 stringify(const std::string & s)
461 {
462  return s;
463 }
464 
465 std::string
467 {
468  // this or std::numeric_limits<T>::max_digits10
469  const unsigned int max_digits10 =
470  std::floor(std::numeric_limits<Real>::digits * std::log10(2) + 2);
471 
472  std::ostringstream os;
473  os << std::setprecision(max_digits10) << t;
474  return os.str();
475 }
476 
477 Point
478 toPoint(const std::vector<Real> & pos)
479 {
480  mooseAssert(pos.size() == LIBMESH_DIM, "Wrong array size while converting into a point");
481  return Point(pos[0], pos[1], pos[2]);
482 }
483 }
VarFieldType
Definition: MooseTypes.h:721
Generalized Non-Hermitian.
Definition: MooseTypes.h:876
std::map< std::string, EigenSolveType > eigen_solve_type_to_enum
Definition: Conversion.C:28
Generalized Hermitian indefinite.
Definition: MooseTypes.h:875
Newton-based eigensolver with an assembled Jacobian matrix (fully coupled by default) ...
Definition: MooseTypes.h:861
Order
Full Newton Solve.
Definition: MooseTypes.h:846
smallest magnitude
Definition: MooseTypes.h:887
std::map< std::string, CoordinateSystemType > coordinate_system_type_to_enum
Definition: Conversion.C:26
EigenSolveType
Type of the eigen solve.
Definition: MooseTypes.h:854
RelationshipManagerType
Main types of Relationship Managers.
Definition: MooseTypes.h:963
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:302
The same as PJFNK except that matrix-vector multiplication is employed to replace residual evaluation...
Definition: MooseTypes.h:863
EigenProblemType stringToEnum< EigenProblemType >(const std::string &s)
Definition: Conversion.C:233
std::map< std::string, EigenProblemType > eigen_problem_type_to_enum
Definition: Conversion.C:29
std::map< std::string, WhichEigenPairs > which_eigen_pairs_to_enum
Definition: Conversion.C:30
CoordinateSystemType stringToEnum< CoordinateSystemType >(const std::string &s)
Definition: Conversion.C:188
void initCoordinateSystemType()
Definition: Conversion.C:37
EigenProblemType
QuadratureType
Solving a linear problem.
Definition: MooseTypes.h:848
use whatever SLPEC has by default
Definition: MooseTypes.h:878
target magnitude
Definition: MooseTypes.h:892
The following methods are specializations for using the libMesh::Parallel::packed_range_* routines fo...
ElementType
Definition: MooseTypes.h:763
std::basic_ostream< charT, traits > * os
Definition: InfixIterator.h:33
TimeIntegratorType stringToEnum< TimeIntegratorType >(const std::string &s)
Definition: Conversion.C:278
Generalized Non-Hermitian with positive (semi-)definite B.
Definition: MooseTypes.h:877
MffdType
Type of the matrix-free finite-differencing parameter.
Definition: MooseTypes.h:942
Order stringToEnum< Order >(const std::string &s)
Definition: Conversion.C:175
Power / Inverse / RQI.
Definition: MooseTypes.h:856
Krylov-Schur.
Definition: MooseTypes.h:858
MffdType stringToEnum< MffdType >(const std::string &s)
Definition: Conversion.C:293
void initLineSearchType()
Definition: Conversion.C:112
std::string stringifyExact(Real)
Stringify Reals with enough precision to guarantee lossless Real -> string -> Real roundtrips...
Definition: Conversion.C:466
Preconditioned Jacobian-free Newton Krylov.
Definition: MooseTypes.h:862
WhichEigenPairs
Which eigen pairs.
Definition: MooseTypes.h:884
LineSearchType
Type of the line search.
Definition: MooseTypes.h:925
void initSolveType()
Definition: Conversion.C:48
std::map< std::string, TimeIntegratorType > time_integrator_to_enum
Definition: Conversion.C:32
Jacobian-Free Newton Krylov.
Definition: MooseTypes.h:845
Point toPoint(const std::vector< Real > &pos)
Convert point represented as std::vector into Point.
Definition: Conversion.C:478
QuadratureType stringToEnum< QuadratureType >(const std::string &s)
Definition: Conversion.C:168
target imaginary
Definition: MooseTypes.h:894
Use finite differences to compute Jacobian.
Definition: MooseTypes.h:847
WhichEigenPairs stringToEnum< WhichEigenPairs >(const std::string &s)
Definition: Conversion.C:248
void initEigenProlemType()
Definition: Conversion.C:78
std::string stringify(const T &t)
conversion to string
Definition: Conversion.h:64
Nonlinear inverse power.
Definition: MooseTypes.h:860
LineSearchType stringToEnum< LineSearchType >(const std::string &s)
Definition: Conversion.C:263
SolveType stringToEnum< SolveType >(const std::string &s)
Definition: Conversion.C:203
void initMffdType()
Definition: Conversion.C:145
std::map< std::string, MffdType > mffd_type_to_enum
Definition: Conversion.C:33
std::string enum_to_string(const T e)
Jacobi-Davidson.
Definition: MooseTypes.h:859
std::map< std::string, LineSearchType > line_search_type_to_enum
Definition: Conversion.C:31
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
CoordinateSystemType
Definition: MooseTypes.h:809
smallest imaginary
Definition: MooseTypes.h:891
void initTimeIntegratorsType()
Definition: Conversion.C:130
std::map< std::string, RelationshipManagerType > rm_type_to_enum
Definition: Conversion.C:34
Jacobian-free Newton Krylov.
Definition: MooseTypes.h:864
largest imaginary
Definition: MooseTypes.h:890
Non-Hermitian.
Definition: MooseTypes.h:873
TimeIntegratorType
Time integrators.
Definition: MooseTypes.h:902
RelationshipManagerType stringToEnum< RelationshipManagerType >(const std::string &s)
Definition: Conversion.C:308
all eigenvalues
Definition: MooseTypes.h:895
Preconditioned Jacobian-Free Newton Krylov.
Definition: MooseTypes.h:844
MOOSE now contains C++17 code, so give a reasonable error message stating what the user can do to add...
use whatever we have in SLEPC
Definition: MooseTypes.h:896
largest magnitude
Definition: MooseTypes.h:886
SolveType
Type of the solve.
Definition: MooseTypes.h:842
void initRMType()
Definition: Conversion.C:155
void initWhichEigenPairs()
Definition: Conversion.C:93
EigenSolveType stringToEnum< EigenSolveType >(const std::string &s)
Definition: Conversion.C:218
Generalized Hermitian.
Definition: MooseTypes.h:874
std::map< std::string, SolveType > solve_type_to_enum
Definition: Conversion.C:27
SolutionIterationType
Definition: MooseTypes.h:241
void initEigenSolveType()
Definition: Conversion.C:61