www.mooseframework.org
Conversion.C
Go to the documentation of this file.
1 /****************************************************************/
2 /* DO NOT MODIFY THIS HEADER */
3 /* MOOSE - Multiphysics Object Oriented Simulation Environment */
4 /* */
5 /* (c) 2010 Battelle Energy Alliance, LLC */
6 /* ALL RIGHTS RESERVED */
7 /* */
8 /* Prepared by Battelle Energy Alliance, LLC */
9 /* Under Contract No. DE-AC07-05ID14517 */
10 /* With the U. S. Department of Energy */
11 /* */
12 /* See COPYRIGHT for full restrictions */
13 /****************************************************************/
14 
15 // MOOSE includes
16 #include "Conversion.h"
17 #include "MooseError.h"
18 #include "MultiMooseEnum.h"
19 
20 #include "libmesh/string_to_enum.h"
21 
22 // system includes
23 #include <iomanip>
24 
25 namespace Moose
26 {
27 std::map<std::string, ExecFlagType> execstore_type_to_enum;
28 std::map<std::string, QuadratureType> quadrature_type_to_enum;
29 std::map<std::string, CoordinateSystemType> coordinate_system_type_to_enum;
30 std::map<std::string, SolveType> solve_type_to_enum;
31 std::map<std::string, EigenSolveType> eigen_solve_type_to_enum;
32 std::map<std::string, EigenProblemType> eigen_problem_type_to_enum;
33 std::map<std::string, WhichEigenPairs> which_eigen_pairs_to_enum;
34 std::map<std::string, LineSearchType> line_search_type_to_enum;
35 std::map<std::string, TimeIntegratorType> time_integrator_to_enum;
36 std::map<std::string, MffdType> mffd_type_to_enum;
37 
38 void
40 {
41  if (execstore_type_to_enum.empty())
42  {
43  execstore_type_to_enum["INITIAL"] = EXEC_INITIAL;
44  execstore_type_to_enum["LINEAR"] = EXEC_LINEAR;
45  execstore_type_to_enum["NONLINEAR"] = EXEC_NONLINEAR;
46  execstore_type_to_enum["TIMESTEP_END"] = EXEC_TIMESTEP_END;
47  execstore_type_to_enum["TIMESTEP_BEGIN"] = EXEC_TIMESTEP_BEGIN;
48  execstore_type_to_enum["FINAL"] = EXEC_FINAL;
49  execstore_type_to_enum["CUSTOM"] = EXEC_CUSTOM;
50  }
51 }
52 
53 void
55 {
56  if (quadrature_type_to_enum.empty())
57  {
58  quadrature_type_to_enum["CLOUGH"] = QCLOUGH;
59  quadrature_type_to_enum["CONICAL"] = QCONICAL;
60  quadrature_type_to_enum["GAUSS"] = QGAUSS;
61  quadrature_type_to_enum["GRID"] = QGRID;
62  quadrature_type_to_enum["MONOMIAL"] = QMONOMIAL;
63  quadrature_type_to_enum["SIMPSON"] = QSIMPSON;
64  quadrature_type_to_enum["TRAP"] = QTRAP;
65  quadrature_type_to_enum["GAUSS_LOBATTO"] = QGAUSS_LOBATTO;
66  }
67 }
68 
69 void
71 {
72  if (coordinate_system_type_to_enum.empty())
73  {
74  coordinate_system_type_to_enum["XYZ"] = COORD_XYZ;
75  coordinate_system_type_to_enum["RZ"] = COORD_RZ;
76  coordinate_system_type_to_enum["RSPHERICAL"] = COORD_RSPHERICAL;
77  }
78 }
79 
80 void
82 {
83  if (solve_type_to_enum.empty())
84  {
85  solve_type_to_enum["PJFNK"] = ST_PJFNK;
86  solve_type_to_enum["JFNK"] = ST_JFNK;
87  solve_type_to_enum["NEWTON"] = ST_NEWTON;
88  solve_type_to_enum["FD"] = ST_FD;
89  solve_type_to_enum["LINEAR"] = ST_LINEAR;
90  }
91 }
92 
93 void
95 {
96  if (eigen_solve_type_to_enum.empty())
97  {
98  eigen_solve_type_to_enum["POWER"] = EST_POWER;
99  eigen_solve_type_to_enum["ARNOLDI"] = EST_ARNOLDI;
100  eigen_solve_type_to_enum["KRYLOVSCHUR"] = EST_KRYLOVSCHUR;
101  eigen_solve_type_to_enum["JACOBI_DAVIDSON"] = EST_JACOBI_DAVIDSON;
102  eigen_solve_type_to_enum["NONLINEAR_POWER"] = EST_NONLINEAR_POWER;
103  eigen_solve_type_to_enum["MF_NONLINEAR_POWER"] = EST_MF_NONLINEAR_POWER;
104  eigen_solve_type_to_enum["MONOLITH_NEWTON"] = EST_MONOLITH_NEWTON;
105  eigen_solve_type_to_enum["MF_MONOLITH_NEWTON"] = EST_MF_MONOLITH_NEWTON;
106  }
107 }
108 
109 void
111 {
112  if (eigen_problem_type_to_enum.empty())
113  {
114  eigen_problem_type_to_enum["HERMITIAN"] = EPT_HERMITIAN;
115  eigen_problem_type_to_enum["NON_HERMITIAN"] = EPT_NON_HERMITIAN;
116  eigen_problem_type_to_enum["GEN_HERMITIAN"] = EPT_GEN_HERMITIAN;
117  eigen_problem_type_to_enum["GEN_NON_HERMITIAN"] = EPT_GEN_NON_HERMITIAN;
118  eigen_problem_type_to_enum["GEN_INDEFINITE"] = EPT_GEN_INDEFINITE;
119  eigen_problem_type_to_enum["POS_GEN_NON_HERMITIAN"] = EPT_POS_GEN_NON_HERMITIAN;
120  eigen_problem_type_to_enum["SLEPC_DEFAULT"] = EPT_SLEPC_DEFAULT;
121  }
122 }
123 
124 void
126 {
127  if (which_eigen_pairs_to_enum.empty())
128  {
129  which_eigen_pairs_to_enum["LARGEST_MAGNITUDE"] = WEP_LARGEST_MAGNITUDE;
130  which_eigen_pairs_to_enum["SMALLEST_MAGNITUDE"] = WEP_SMALLEST_MAGNITUDE;
131  which_eigen_pairs_to_enum["LARGEST_REAL"] = WEP_LARGEST_REAL;
132  which_eigen_pairs_to_enum["SMALLEST_REAL"] = WEP_SMALLEST_REAL;
133  which_eigen_pairs_to_enum["LARGEST_IMAGINARY"] = WEP_LARGEST_IMAGINARY;
134  which_eigen_pairs_to_enum["SMALLEST_IMAGINARY"] = WEP_SMALLEST_IMAGINARY;
135  which_eigen_pairs_to_enum["TARGET_MAGNITUDE"] = WEP_TARGET_MAGNITUDE;
136  which_eigen_pairs_to_enum["TARGET_REAL"] = WEP_TARGET_REAL;
137  which_eigen_pairs_to_enum["TARGET_IMAGINARY"] = WEP_TARGET_IMAGINARY;
138  which_eigen_pairs_to_enum["ALL_EIGENVALUES"] = WEP_ALL_EIGENVALUES;
139  which_eigen_pairs_to_enum["SLEPC_DEFAULT"] = WEP_SLEPC_DEFAULT;
140  }
141 }
142 
143 void
145 {
146  if (line_search_type_to_enum.empty())
147  {
148  line_search_type_to_enum["DEFAULT"] = LS_DEFAULT;
149  line_search_type_to_enum["NONE"] = LS_NONE;
150  line_search_type_to_enum["BASIC"] = LS_BASIC;
151 #ifdef LIBMESH_HAVE_PETSC
152 #if PETSC_VERSION_LESS_THAN(3, 3, 0)
153  line_search_type_to_enum["CUBIC"] = LS_CUBIC;
154  line_search_type_to_enum["QUADRATIC"] = LS_QUADRATIC;
155  line_search_type_to_enum["BASICNONORMS"] = LS_BASICNONORMS;
156 #else
157  line_search_type_to_enum["SHELL"] = LS_SHELL;
158  line_search_type_to_enum["L2"] = LS_L2;
159  line_search_type_to_enum["BT"] = LS_BT;
160  line_search_type_to_enum["CP"] = LS_CP;
161 #endif
162 #endif
163  }
164 }
165 
166 void
168 {
169  if (time_integrator_to_enum.empty())
170  {
171  time_integrator_to_enum["IMPLICIT_EULER"] = TI_IMPLICIT_EULER;
172  time_integrator_to_enum["EXPLICIT_EULER"] = TI_EXPLICIT_EULER;
173  time_integrator_to_enum["CRANK_NICOLSON"] = TI_CRANK_NICOLSON;
174  time_integrator_to_enum["BDF2"] = TI_BDF2;
175  time_integrator_to_enum["EXPLICIT_MIDPOINT"] = TI_EXPLICIT_MIDPOINT;
176  time_integrator_to_enum["LSTABLE_DIRK2"] = TI_LSTABLE_DIRK2;
177  time_integrator_to_enum["EXPLICIT_TVDRK2"] = TI_EXPLICIT_TVD_RK_2;
178  }
179 }
180 
181 void
183 {
184  if (mffd_type_to_enum.empty())
185  {
186  mffd_type_to_enum["DS"] = MFFD_DS;
187  mffd_type_to_enum["WP"] = MFFD_WP;
188  }
189 }
190 
191 template <>
193 stringToEnum(const std::string & s)
194 {
196 
197  std::string upper(s);
198  std::transform(upper.begin(), upper.end(), upper.begin(), ::toupper);
199 
200  if (!execstore_type_to_enum.count(upper))
201  mooseError("Unknown execution flag: ", upper);
202 
203  return execstore_type_to_enum[upper];
204 }
205 
206 template <>
207 QuadratureType
208 stringToEnum<QuadratureType>(const std::string & s)
209 {
211 
212  std::string upper(s);
213  std::transform(upper.begin(), upper.end(), upper.begin(), ::toupper);
214 
215  if (!quadrature_type_to_enum.count(upper))
216  mooseError("Unknown quadrature type: ", upper);
217 
218  return quadrature_type_to_enum[upper];
219 }
220 
221 template <>
222 Order
223 stringToEnum<Order>(const std::string & s)
224 {
225  std::string upper(s);
226  std::transform(upper.begin(), upper.end(), upper.begin(), ::toupper);
227 
228  if (upper.compare("AUTO") == 0)
229  return INVALID_ORDER;
230  else
231  return Utility::string_to_enum<Order>(upper);
232 }
233 
234 template <>
237 {
239 
240  std::string upper(s);
241  std::transform(upper.begin(), upper.end(), upper.begin(), ::toupper);
242 
243  if (!coordinate_system_type_to_enum.count(upper))
244  mooseError("Unknown coordinate system type: ", upper);
245 
246  return coordinate_system_type_to_enum[upper];
247 }
248 
249 template <>
250 SolveType
251 stringToEnum<SolveType>(const std::string & s)
252 {
253  initSolveType();
254 
255  std::string upper(s);
256  std::transform(upper.begin(), upper.end(), upper.begin(), ::toupper);
257 
258  if (!solve_type_to_enum.count(upper))
259  mooseError("Unknown solve type: ", upper);
260 
261  return solve_type_to_enum[upper];
262 }
263 
264 template <>
266 stringToEnum<EigenSolveType>(const std::string & s)
267 {
269 
270  std::string upper(s);
271  std::transform(upper.begin(), upper.end(), upper.begin(), ::toupper);
272 
273  if (!eigen_solve_type_to_enum.count(upper))
274  mooseError("Unknown eigen solve type: ", upper);
275 
276  return eigen_solve_type_to_enum[upper];
277 }
278 
279 template <>
281 stringToEnum<EigenProblemType>(const std::string & s)
282 {
284 
285  std::string upper(s);
286  std::transform(upper.begin(), upper.end(), upper.begin(), ::toupper);
287 
288  if (!eigen_problem_type_to_enum.count(upper))
289  mooseError("Unknown eigen problem type: ", upper);
290 
291  return eigen_problem_type_to_enum[upper];
292 }
293 
294 template <>
296 stringToEnum<WhichEigenPairs>(const std::string & s)
297 {
299 
300  std::string upper(s);
301  std::transform(upper.begin(), upper.end(), upper.begin(), ::toupper);
302 
303  if (!which_eigen_pairs_to_enum.count(upper))
304  mooseError("Unknown type of WhichEigenPairs: ", upper);
305 
306  return which_eigen_pairs_to_enum[upper];
307 }
308 
309 template <>
311 stringToEnum<LineSearchType>(const std::string & s)
312 {
314 
315  std::string upper(s);
316  std::transform(upper.begin(), upper.end(), upper.begin(), ::toupper);
317 
318  if (!line_search_type_to_enum.count(upper))
319  mooseError("Unknown line search type: ", upper);
320 
321  return line_search_type_to_enum[upper];
322 }
323 
324 template <>
326 stringToEnum<TimeIntegratorType>(const std::string & s)
327 {
329 
330  std::string upper(s);
331  std::transform(upper.begin(), upper.end(), upper.begin(), ::toupper);
332 
333  if (!time_integrator_to_enum.count(upper))
334  mooseError("Unknown time integrator: ", upper);
335 
336  return time_integrator_to_enum[upper];
337 }
338 
339 template <>
340 MffdType
341 stringToEnum<MffdType>(const std::string & s)
342 {
343  initMffdType();
344 
345  std::string upper(s);
346  std::transform(upper.begin(), upper.end(), upper.begin(), ::toupper);
347 
348  if (!mffd_type_to_enum.count(upper))
349  mooseError("Unknown mffd type: ", upper);
350 
351  return mffd_type_to_enum[upper];
352 }
353 
354 template <>
355 std::vector<ExecFlagType>
357 {
358  std::vector<ExecFlagType> exec_flags(v.size());
359  for (unsigned int i = 0; i < v.size(); ++i)
360  exec_flags[i] = stringToEnum<ExecFlagType>(v[i]);
361 
362  return exec_flags;
363 }
364 
365 std::string
367 {
368  switch (t)
369  {
370  case ST_NEWTON:
371  return "NEWTON";
372  case ST_JFNK:
373  return "JFNK";
374  case ST_PJFNK:
375  return "Preconditioned JFNK";
376  case ST_FD:
377  return "FD";
378  case ST_LINEAR:
379  return "Linear";
380  }
381  return "";
382 }
383 
384 std::string
386 {
387  switch (t)
388  {
389  case EXEC_INITIAL:
390  return "INITIAL";
391  case EXEC_LINEAR:
392  return "LINEAR";
393  case EXEC_NONLINEAR:
394  return "NONLINEAR";
395  case EXEC_TIMESTEP_END:
396  return "TIMESTEP_END";
397  case EXEC_TIMESTEP_BEGIN:
398  return "TIMESTEP_BEGIN";
399  case EXEC_CUSTOM:
400  return "CUSTOM";
401  case EXEC_FINAL:
402  return "FINAL";
403  case EXEC_FORCED:
404  return "FORCED";
405  case EXEC_FAILED:
406  return "FAILED";
407  case EXEC_SUBDOMAIN:
408  return "SUBDOMAIN";
409  case EXEC_NONE:
410  return "NONE";
411  }
412  return "";
413 }
414 
415 std::string
416 stringify(const std::string & s)
417 {
418  return s;
419 }
420 
421 std::string
423 {
424  // this or std::numeric_limits<T>::max_digits10
425  const unsigned int max_digits10 =
426  std::floor(std::numeric_limits<Real>::digits * std::log10(2) + 2);
427 
428  std::ostringstream os;
429  os << std::setprecision(max_digits10) << t;
430  return os.str();
431 }
432 
433 Point
434 toPoint(const std::vector<Real> & pos)
435 {
436  mooseAssert(pos.size() == LIBMESH_DIM, "Wrong array size while converting into a point");
437  return Point(pos[0], pos[1], pos[2]);
438 }
439 }
Object is evaluated in every residual computation.
Definition: MooseTypes.h:96
Generalized Non-Hermitian.
Definition: MooseTypes.h:278
Newton-based eigen solver.
Definition: MooseTypes.h:265
std::map< std::string, EigenSolveType > eigen_solve_type_to_enum
Definition: Conversion.C:31
std::map< std::string, ExecFlagType > execstore_type_to_enum
Definition: Conversion.C:27
Generalized Hermitian indefinite.
Definition: MooseTypes.h:277
Full Newton Solve.
Definition: MooseTypes.h:249
smallest magnitude
Definition: MooseTypes.h:289
std::map< std::string, CoordinateSystemType > coordinate_system_type_to_enum
Definition: Conversion.C:29
EigenSolveType
Type of the eigen solve.
Definition: MooseTypes.h:257
For use with custom executioners that want to fire objects at a specific time.
Definition: MooseTypes.h:110
Object is evaluated only once at the beginning of the simulation.
Definition: MooseTypes.h:94
Matrix-free Newton-based eigen solver.
Definition: MooseTypes.h:266
void initQuadratureType()
Definition: Conversion.C:54
void mooseError(Args &&...args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:182
EigenProblemType stringToEnum< EigenProblemType >(const std::string &s)
Definition: Conversion.C:281
std::map< std::string, EigenProblemType > eigen_problem_type_to_enum
Definition: Conversion.C:32
T stringToEnum(const std::string &s)
Definition: Conversion.C:193
std::map< std::string, WhichEigenPairs > which_eigen_pairs_to_enum
Definition: Conversion.C:33
CoordinateSystemType stringToEnum< CoordinateSystemType >(const std::string &s)
Definition: Conversion.C:236
void initCoordinateSystemType()
Definition: Conversion.C:70
Solving a linear problem.
Definition: MooseTypes.h:251
Matrix-free nonlinear inverse power.
Definition: MooseTypes.h:264
use whatever SLPEC has by default
Definition: MooseTypes.h:280
target magnitude
Definition: MooseTypes.h:294
TimeIntegratorType stringToEnum< TimeIntegratorType >(const std::string &s)
Definition: Conversion.C:326
Generalized Non-Hermitian with positive (semi-)definite B.
Definition: MooseTypes.h:279
MffdType
Type of the matrix-free finite-differencing parameter.
Definition: MooseTypes.h:349
Order stringToEnum< Order >(const std::string &s)
Definition: Conversion.C:223
Object is evaluated at the end of every time step.
Definition: MooseTypes.h:100
Power / Inverse / RQI.
Definition: MooseTypes.h:259
Krylov-Schur.
Definition: MooseTypes.h:261
MffdType stringToEnum< MffdType >(const std::string &s)
Definition: Conversion.C:341
void initLineSearchType()
Definition: Conversion.C:144
std::string stringifyExact(Real)
Stringify Reals with enough precision to guarantee lossless Real -> string -> Real roundtrips...
Definition: Conversion.C:422
Forces execution to occur (output only)
Definition: MooseTypes.h:106
WhichEigenPairs
Which eigen pairs.
Definition: MooseTypes.h:286
ExecFlagType stringToEnum< ExecFlagType >(const std::string &s)
LineSearchType
Type of the line search.
Definition: MooseTypes.h:326
void initSolveType()
Definition: Conversion.C:81
std::map< std::string, TimeIntegratorType > time_integrator_to_enum
Definition: Conversion.C:35
Jacobian-Free Newton Krylov.
Definition: MooseTypes.h:248
Point toPoint(const std::vector< Real > &pos)
Convert point represented as std::vector into Point.
Definition: Conversion.C:434
QuadratureType stringToEnum< QuadratureType >(const std::string &s)
Definition: Conversion.C:208
target imaginary
Definition: MooseTypes.h:296
Use finite differences to compute Jacobian.
Definition: MooseTypes.h:250
WhichEigenPairs stringToEnum< WhichEigenPairs >(const std::string &s)
Definition: Conversion.C:296
void initEigenProlemType()
Definition: Conversion.C:110
Objects is evaluated on subdomain.
Definition: MooseTypes.h:112
void initExecStoreType()
Definition: Conversion.C:39
std::string stringify(const T &t)
conversion to string
Definition: Conversion.h:66
Nonlinear inverse power.
Definition: MooseTypes.h:263
LineSearchType stringToEnum< LineSearchType >(const std::string &s)
Definition: Conversion.C:311
SolveType stringToEnum< SolveType >(const std::string &s)
Definition: Conversion.C:251
void initMffdType()
Definition: Conversion.C:182
std::map< std::string, MffdType > mffd_type_to_enum
Definition: Conversion.C:36
CoordinateSystemType
Definition: MooseTypes.h:212
Jacobi-Davidson.
Definition: MooseTypes.h:262
std::map< std::string, LineSearchType > line_search_type_to_enum
Definition: Conversion.C:34
Forces execution on failed solve (output only)
Definition: MooseTypes.h:108
smallest imaginary
Definition: MooseTypes.h:293
void initTimeIntegratorsType()
Definition: Conversion.C:167
largest imaginary
Definition: MooseTypes.h:292
Non-Hermitian.
Definition: MooseTypes.h:275
TimeIntegratorType
Time integrators.
Definition: MooseTypes.h:304
Object is evaluated at the end of the simulations (output only)
Definition: MooseTypes.h:104
Object is evaluated at the beginning of every time step.
Definition: MooseTypes.h:102
all eigenvalues
Definition: MooseTypes.h:297
Preconditioned Jacobian-Free Newton Krylov.
Definition: MooseTypes.h:247
ExecFlagType
Execution flags - when is the object executed/evaluated.
Definition: MooseTypes.h:90
Object is evaluated in every jacobian computation.
Definition: MooseTypes.h:98
Definition: Moose.h:84
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type It sho...
use whatever we have in SLEPC
Definition: MooseTypes.h:298
largest magnitude
Definition: MooseTypes.h:288
SolveType
Type of the solve.
Definition: MooseTypes.h:245
void initWhichEigenPairs()
Definition: Conversion.C:125
EigenSolveType stringToEnum< EigenSolveType >(const std::string &s)
Definition: Conversion.C:266
EigenProblemType
Type of the eigen problem.
Definition: MooseTypes.h:272
std::map< std::string, QuadratureType > quadrature_type_to_enum
Definition: Conversion.C:28
std::vector< ExecFlagType > vectorStringsToEnum< ExecFlagType >(const MultiMooseEnum &v)
Definition: Conversion.C:356
Generalized Hermitian.
Definition: MooseTypes.h:276
std::map< std::string, SolveType > solve_type_to_enum
Definition: Conversion.C:30
void initEigenSolveType()
Definition: Conversion.C:94