https://mooseframework.inl.gov
Loading...
Searching...
No Matches
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
22using namespace libMesh;
23
24namespace Moose
25{
26std::map<std::string, CoordinateSystemType> coordinate_system_type_to_enum;
27std::map<std::string, SolveType> solve_type_to_enum;
28std::map<std::string, EigenSolveType> eigen_solve_type_to_enum;
29std::map<std::string, EigenProblemType> eigen_problem_type_to_enum;
30std::map<std::string, WhichEigenPairs> which_eigen_pairs_to_enum;
31std::map<std::string, LineSearchType> line_search_type_to_enum;
32std::map<std::string, TimeIntegratorType> time_integrator_to_enum;
33std::map<std::string, MffdType> mffd_type_to_enum;
34std::map<std::string, RelationshipManagerType> rm_type_to_enum;
35
36void
46
47void
49{
50 if (solve_type_to_enum.empty())
51 {
54 solve_type_to_enum["NEWTON"] = ST_NEWTON;
56 solve_type_to_enum["LINEAR"] = ST_LINEAR;
57 }
58}
59
60void
76
77void
91
92void
110
111void
128
129void
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;
141 }
142}
143
144void
146{
147 if (mffd_type_to_enum.empty())
148 {
151 }
152}
153
154void
165
166template <>
168stringToEnum<QuadratureType>(const std::string & s)
169{
170 return Utility::string_to_enum<QuadratureType>("Q" + s);
171}
172
173template <>
175stringToEnum<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
186template <>
188stringToEnum<CoordinateSystemType>(const std::string & s)
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
201template <>
203stringToEnum<SolveType>(const std::string & s)
204{
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
216template <>
218stringToEnum<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
231template <>
233stringToEnum<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
246template <>
248stringToEnum<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
261template <>
263stringToEnum<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
276template <>
278stringToEnum<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
291template <>
293stringToEnum<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
306template <>
308stringToEnum<RelationshipManagerType>(const std::string & s)
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
325std::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.
331 return "DEFAULT";
333 return "GEOMETRIC";
335 return "ALGEBRAIC";
337 return "GEOMETRIC and ALGEBRAIC";
339 return "ALGEBRAIC and COUPLING";
342 return "GEOMETRIC and ALGEBRAIC and COUPLING";
344 return "COUPLING";
345
346 mooseError("Unknown RelationshipManagerType");
347}
348
349// Definition in MooseTypes.h
350std::string
352{
353 switch (t)
354 {
356 return "IMPLICIT_EULER";
358 return "EXPLICIT_EULER";
360 return "CRANK_NICOLSON";
362 return "BDF2";
364 return "EXPLICIT_MIDPOINT";
366 return "LSTABLE_DIRK2";
368 return "EXPLICIT_TVDRK2";
369 default:
370 mooseError("Unknown TimeIntegratorType");
371 }
372}
373
374std::string
379
380// Turn the warnings back on
381#include "libmesh/restore_warnings.h"
382
383std::string
385{
386 switch (t)
387 {
388 case ST_NEWTON:
389 return "NEWTON";
390 case ST_JFNK:
391 return "JFNK";
392 case ST_PJFNK:
393 return "Preconditioned JFNK";
394 case ST_FD:
395 return "FD";
396 case ST_LINEAR:
397 return "Linear";
398 }
399 return "";
400}
401
402std::string
404{
405 switch (t)
406 {
407 case EST_POWER:
408 return "Power";
409 case EST_ARNOLDI:
410 return "ARNOLDI";
411 case EST_KRYLOVSCHUR:
412 return "KRYLOVSCHUR";
414 return "Jacobi Davidson";
416 return "Nonlinear Power";
417 case EST_PJFNKMO:
418 return "PJFNK with Matrix Only";
419 case EST_NEWTON:
420 return "Newton";
421 case EST_JFNK:
422 return "JFNK";
423 case EST_PJFNK:
424 return "Preconditioned JFNK";
425 }
426 return "";
427}
428
429std::string
431{
432 switch (t)
433 {
435 return "STANDARD";
436 case VAR_FIELD_VECTOR:
437 return "VECTOR";
438 case VAR_FIELD_ARRAY:
439 return "ARRAY";
440 case VAR_FIELD_SCALAR:
441 return "SCALAR";
442 case VAR_FIELD_ANY:
443 return "ANY";
444 }
445 return "";
446}
447
448std::string
450{
451 switch (t)
452 {
454 return "time";
456 return "nonlinear";
458 return "multiapp_fixed_point";
460 return "multisystem_fixed_point";
461 default:
462 mooseError("Unhandled SolutionIterationType");
463 }
464}
465
466std::string
468{
469 switch (t)
470 {
472 return "ELEMENT";
474 return "NEIGHBOR";
476 return "LOWER";
477 default:
478 mooseError("unrecognized type");
479 }
480}
481
482std::string
487
488std::string
489stringify(const std::string & s)
490{
491 return s;
492}
493
494std::string
496{
497 // this or std::numeric_limits<T>::max_digits10
498 const unsigned int max_digits10 =
499 std::floor(std::numeric_limits<Real>::digits * std::log10(2) + 2);
500
501 std::ostringstream os;
502 os << std::setprecision(max_digits10) << t;
503 return os.str();
504}
505
506Point
507toPoint(const std::vector<Real> & pos)
508{
509 mooseAssert(pos.size() == LIBMESH_DIM, "Wrong array size while converting into a point");
510 return Point(pos[0], pos[1], pos[2]);
511}
512}
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application.
Definition MooseError.h:311
MOOSE now contains C++17 code, so give a reasonable error message stating what the user can do to add...
std::map< std::string, LineSearchType > line_search_type_to_enum
Definition Conversion.C:31
void initMffdType()
Definition Conversion.C:145
SolveType stringToEnum< SolveType >(const std::string &s)
Definition Conversion.C:203
void initEigenProlemType()
Definition Conversion.C:78
LineSearchType stringToEnum< LineSearchType >(const std::string &s)
Definition Conversion.C:263
void initCoordinateSystemType()
Definition Conversion.C:37
MffdType stringToEnum< MffdType >(const std::string &s)
Definition Conversion.C:293
SolveType
Type of the solve.
Definition MooseTypes.h:897
@ ST_FD
Use finite differences to compute Jacobian.
Definition MooseTypes.h:901
@ ST_LINEAR
Solving a linear problem.
Definition MooseTypes.h:902
@ ST_NEWTON
Full Newton Solve.
Definition MooseTypes.h:900
@ ST_JFNK
Jacobian-Free Newton Krylov.
Definition MooseTypes.h:899
@ ST_PJFNK
Preconditioned Jacobian-Free Newton Krylov.
Definition MooseTypes.h:898
@ VAR_FIELD_SCALAR
Definition MooseTypes.h:778
@ VAR_FIELD_STANDARD
Definition MooseTypes.h:777
@ VAR_FIELD_ARRAY
Definition MooseTypes.h:780
@ VAR_FIELD_ANY
Definition MooseTypes.h:781
@ VAR_FIELD_VECTOR
Definition MooseTypes.h:779
QuadratureType stringToEnum< QuadratureType >(const std::string &s)
Definition Conversion.C:168
EigenProblemType stringToEnum< EigenProblemType >(const std::string &s)
Definition Conversion.C:233
std::map< std::string, CoordinateSystemType > coordinate_system_type_to_enum
Definition Conversion.C:26
TimeIntegratorType
Time integrators.
Definition MooseTypes.h:957
@ TI_EXPLICIT_EULER
Definition MooseTypes.h:959
@ TI_EXPLICIT_TVD_RK_2
Definition MooseTypes.h:964
@ TI_EXPLICIT_MIDPOINT
Definition MooseTypes.h:962
@ TI_IMPLICIT_EULER
Definition MooseTypes.h:958
@ TI_CRANK_NICOLSON
Definition MooseTypes.h:960
@ TI_BDF2
Definition MooseTypes.h:961
@ TI_LSTABLE_DIRK2
Definition MooseTypes.h:963
void initLineSearchType()
Definition Conversion.C:112
RelationshipManagerType stringToEnum< RelationshipManagerType >(const std::string &s)
Definition Conversion.C:308
LineSearchType
Type of the line search.
Definition MooseTypes.h:980
@ LS_DEFAULT
Definition MooseTypes.h:982
@ LS_NONE
Definition MooseTypes.h:983
@ LS_PROJECT
Definition MooseTypes.h:987
@ LS_CONTACT
Definition MooseTypes.h:986
@ LS_SHELL
Definition MooseTypes.h:985
@ LS_BASIC
Definition MooseTypes.h:984
TimeIntegratorType stringToEnum< TimeIntegratorType >(const std::string &s)
Definition Conversion.C:278
std::map< std::string, TimeIntegratorType > time_integrator_to_enum
Definition Conversion.C:32
CoordinateSystemType stringToEnum< CoordinateSystemType >(const std::string &s)
Definition Conversion.C:188
void initEigenSolveType()
Definition Conversion.C:61
std::map< std::string, SolveType > solve_type_to_enum
Definition Conversion.C:27
void initSolveType()
Definition Conversion.C:48
std::map< std::string, RelationshipManagerType > rm_type_to_enum
Definition Conversion.C:34
void initWhichEigenPairs()
Definition Conversion.C:93
std::string stringify(const T &t)
conversion to string
Definition Conversion.h:64
RelationshipManagerType
Main types of Relationship Managers.
CoordinateSystemType
Definition MooseTypes.h:864
@ COORD_RZ
Definition MooseTypes.h:866
@ COORD_RSPHERICAL
Definition MooseTypes.h:867
@ COORD_XYZ
Definition MooseTypes.h:865
Point toPoint(const std::vector< Real > &pos)
Definition Conversion.C:507
SolutionIterationType
Definition MooseTypes.h:270
std::map< std::string, EigenProblemType > eigen_problem_type_to_enum
Definition Conversion.C:29
WhichEigenPairs
Which eigen pairs.
Definition MooseTypes.h:939
@ WEP_TARGET_MAGNITUDE
target magnitude
Definition MooseTypes.h:946
@ WEP_LARGEST_IMAGINARY
largest imaginary
Definition MooseTypes.h:944
@ WEP_TARGET_IMAGINARY
target imaginary
Definition MooseTypes.h:948
@ WEP_SMALLEST_REAL
smallest real
Definition MooseTypes.h:943
@ WEP_SLEPC_DEFAULT
use whatever we have in SLEPC
Definition MooseTypes.h:950
@ WEP_LARGEST_MAGNITUDE
largest magnitude
Definition MooseTypes.h:940
@ WEP_SMALLEST_MAGNITUDE
smallest magnitude
Definition MooseTypes.h:941
@ WEP_ALL_EIGENVALUES
all eigenvalues
Definition MooseTypes.h:949
@ WEP_SMALLEST_IMAGINARY
smallest imaginary
Definition MooseTypes.h:945
@ WEP_TARGET_REAL
target real
Definition MooseTypes.h:947
@ WEP_LARGEST_REAL
largest real
Definition MooseTypes.h:942
void initTimeIntegratorsType()
Definition Conversion.C:130
std::map< std::string, MffdType > mffd_type_to_enum
Definition Conversion.C:33
std::string stringifyExact(Real)
Stringify Reals with enough precision to guarantee lossless Real -> string -> Real roundtrips.
Definition Conversion.C:495
EigenSolveType
Type of the eigen solve.
Definition MooseTypes.h:909
@ EST_PJFNKMO
The same as PJFNK except that matrix-vector multiplication is employed to replace residual evaluation...
Definition MooseTypes.h:917
@ EST_JACOBI_DAVIDSON
Jacobi-Davidson.
Definition MooseTypes.h:913
@ EST_KRYLOVSCHUR
Krylov-Schur.
Definition MooseTypes.h:912
@ EST_JFNK
Jacobian-free Newton Krylov.
Definition MooseTypes.h:918
@ EST_NEWTON
Newton-based eigensolver with an assembled Jacobian matrix (fully coupled by default)
Definition MooseTypes.h:915
@ EST_POWER
Power / Inverse / RQI.
Definition MooseTypes.h:910
@ EST_NONLINEAR_POWER
Nonlinear inverse power.
Definition MooseTypes.h:914
@ EST_ARNOLDI
Arnoldi.
Definition MooseTypes.h:911
@ EST_PJFNK
Preconditioned Jacobian-free Newton Krylov.
Definition MooseTypes.h:916
Order stringToEnum< Order >(const std::string &s)
Definition Conversion.C:175
std::map< std::string, WhichEigenPairs > which_eigen_pairs_to_enum
Definition Conversion.C:30
void initRMType()
Definition Conversion.C:155
EigenProblemType
Type of the eigen problem.
Definition MooseTypes.h:925
@ EPT_GEN_INDEFINITE
Generalized Hermitian indefinite.
Definition MooseTypes.h:929
@ EPT_NON_HERMITIAN
Non-Hermitian.
Definition MooseTypes.h:927
@ EPT_GEN_HERMITIAN
Generalized Hermitian.
Definition MooseTypes.h:928
@ EPT_HERMITIAN
Hermitian.
Definition MooseTypes.h:926
@ EPT_GEN_NON_HERMITIAN
Generalized Non-Hermitian.
Definition MooseTypes.h:930
@ EPT_POS_GEN_NON_HERMITIAN
Generalized Non-Hermitian with positive (semi-)definite B.
Definition MooseTypes.h:931
@ EPT_SLEPC_DEFAULT
use whatever SLPEC has by default
Definition MooseTypes.h:932
std::map< std::string, EigenSolveType > eigen_solve_type_to_enum
Definition Conversion.C:28
WhichEigenPairs stringToEnum< WhichEigenPairs >(const std::string &s)
Definition Conversion.C:248
EigenSolveType stringToEnum< EigenSolveType >(const std::string &s)
Definition Conversion.C:218
MffdType
Type of the matrix-free finite-differencing parameter.
Definition MooseTypes.h:997
@ MFFD_WP
Definition MooseTypes.h:999
std::string enum_to_string(const T e)
The following methods are specializations for using the libMesh::Parallel::packed_range_* routines fo...
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real