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
22namespace Moose
23{
24std::map<std::string, CoordinateSystemType> coordinate_system_type_to_enum;
25std::map<std::string, SolveType> solve_type_to_enum;
26std::map<std::string, EigenSolveType> eigen_solve_type_to_enum;
27std::map<std::string, EigenProblemType> eigen_problem_type_to_enum;
28std::map<std::string, WhichEigenPairs> which_eigen_pairs_to_enum;
29std::map<std::string, LineSearchType> line_search_type_to_enum;
30std::map<std::string, TimeIntegratorType> time_integrator_to_enum;
31std::map<std::string, MffdType> mffd_type_to_enum;
32std::map<std::string, RelationshipManagerType> rm_type_to_enum;
33
34void
44
45void
47{
48 if (solve_type_to_enum.empty())
49 {
52 solve_type_to_enum["NEWTON"] = ST_NEWTON;
54 solve_type_to_enum["LINEAR"] = ST_LINEAR;
55 }
56}
57
58void
74
75void
89
90void
108
109void
126
127void
129{
130 if (time_integrator_to_enum.empty())
131 {
132 time_integrator_to_enum["IMPLICIT_EULER"] = TI_IMPLICIT_EULER;
133 time_integrator_to_enum["EXPLICIT_EULER"] = TI_EXPLICIT_EULER;
134 time_integrator_to_enum["CRANK_NICOLSON"] = TI_CRANK_NICOLSON;
136 time_integrator_to_enum["EXPLICIT_MIDPOINT"] = TI_EXPLICIT_MIDPOINT;
137 time_integrator_to_enum["LSTABLE_DIRK2"] = TI_LSTABLE_DIRK2;
139 }
140}
141
142void
144{
145 if (mffd_type_to_enum.empty())
146 {
149 }
150}
151
152void
163
164template <>
165QuadratureType
166stringToEnum<QuadratureType>(const std::string & s)
167{
168 return Utility::string_to_enum<QuadratureType>("Q" + s);
169}
170
171template <>
172Order
173stringToEnum<Order>(const std::string & s)
174{
175 std::string upper(s);
176 std::transform(upper.begin(), upper.end(), upper.begin(), ::toupper);
177
178 if (upper.compare("AUTO") == 0)
179 return INVALID_ORDER;
180 else
181 return Utility::string_to_enum<Order>(upper);
182}
183
184template <>
186stringToEnum<CoordinateSystemType>(const std::string & s)
187{
189
190 std::string upper(s);
191 std::transform(upper.begin(), upper.end(), upper.begin(), ::toupper);
192
193 if (!coordinate_system_type_to_enum.count(upper))
194 mooseError("Unknown coordinate system type: ", upper);
195
196 return coordinate_system_type_to_enum[upper];
197}
198
199template <>
201stringToEnum<SolveType>(const std::string & s)
202{
204
205 std::string upper(s);
206 std::transform(upper.begin(), upper.end(), upper.begin(), ::toupper);
207
208 if (!solve_type_to_enum.count(upper))
209 mooseError("Unknown solve type: ", upper);
210
211 return solve_type_to_enum[upper];
212}
213
214template <>
216stringToEnum<EigenSolveType>(const std::string & s)
217{
219
220 std::string upper(s);
221 std::transform(upper.begin(), upper.end(), upper.begin(), ::toupper);
222
223 if (!eigen_solve_type_to_enum.count(upper))
224 mooseError("Unknown eigen solve type: ", upper);
225
226 return eigen_solve_type_to_enum[upper];
227}
228
229template <>
231stringToEnum<EigenProblemType>(const std::string & s)
232{
234
235 std::string upper(s);
236 std::transform(upper.begin(), upper.end(), upper.begin(), ::toupper);
237
238 if (!eigen_problem_type_to_enum.count(upper))
239 mooseError("Unknown eigen problem type: ", upper);
240
241 return eigen_problem_type_to_enum[upper];
242}
243
244template <>
246stringToEnum<WhichEigenPairs>(const std::string & s)
247{
249
250 std::string upper(s);
251 std::transform(upper.begin(), upper.end(), upper.begin(), ::toupper);
252
253 if (!which_eigen_pairs_to_enum.count(upper))
254 mooseError("Unknown type of WhichEigenPairs: ", upper);
255
256 return which_eigen_pairs_to_enum[upper];
257}
258
259template <>
261stringToEnum<LineSearchType>(const std::string & s)
262{
264
265 std::string upper(s);
266 std::transform(upper.begin(), upper.end(), upper.begin(), ::toupper);
267
268 if (!line_search_type_to_enum.count(upper))
269 mooseError("Unknown line search type: ", upper);
270
271 return line_search_type_to_enum[upper];
272}
273
274template <>
276stringToEnum<TimeIntegratorType>(const std::string & s)
277{
279
280 std::string upper(s);
281 std::transform(upper.begin(), upper.end(), upper.begin(), ::toupper);
282
283 if (!time_integrator_to_enum.count(upper))
284 mooseError("Unknown time integrator: ", upper);
285
286 return time_integrator_to_enum[upper];
287}
288
289template <>
291stringToEnum<MffdType>(const std::string & s)
292{
293 initMffdType();
294
295 std::string upper(s);
296 std::transform(upper.begin(), upper.end(), upper.begin(), ::toupper);
297
298 if (!mffd_type_to_enum.count(upper))
299 mooseError("Unknown mffd type: ", upper);
300
301 return mffd_type_to_enum[upper];
302}
303
304template <>
306stringToEnum<RelationshipManagerType>(const std::string & s)
307{
308 initRMType();
309
310 std::string upper(s);
311 std::transform(upper.begin(), upper.end(), upper.begin(), ::toupper);
312
313 if (!rm_type_to_enum.count(upper))
314 mooseError("Unknown RelationshipManager type: ", upper);
315
316 return rm_type_to_enum[upper];
317}
318
319// Ignore warnings about switching on the |'d type
320#include "libmesh/ignore_warnings.h"
321
322// Definition in MooseTypes.h
323std::string
325{
326 // Cannot make a switch statement because the boolean logic doesn't work well with the class type
327 // enumeration and because Cody says so.
329 return "DEFAULT";
331 return "GEOMETRIC";
333 return "ALGEBRAIC";
335 return "GEOMETRIC and ALGEBRAIC";
337 return "ALGEBRAIC and COUPLING";
340 return "GEOMETRIC and ALGEBRAIC and COUPLING";
342 return "COUPLING";
343
344 mooseError("Unknown RelationshipManagerType");
345}
346
347// Definition in MooseTypes.h
348std::string
350{
351 switch (t)
352 {
354 return "IMPLICIT_EULER";
356 return "EXPLICIT_EULER";
358 return "CRANK_NICOLSON";
360 return "BDF2";
362 return "EXPLICIT_MIDPOINT";
364 return "LSTABLE_DIRK2";
366 return "EXPLICIT_TVDRK2";
367 default:
368 mooseError("Unknown TimeIntegratorType");
369 }
370}
371
372std::string
377
378// Turn the warnings back on
379#include "libmesh/restore_warnings.h"
380
381std::string
383{
384 switch (t)
385 {
386 case ST_NEWTON:
387 return "NEWTON";
388 case ST_JFNK:
389 return "JFNK";
390 case ST_PJFNK:
391 return "Preconditioned JFNK";
392 case ST_FD:
393 return "FD";
394 case ST_LINEAR:
395 return "Linear";
396 }
397 return "";
398}
399
400std::string
402{
403 switch (t)
404 {
405 case EST_POWER:
406 return "Power";
407 case EST_ARNOLDI:
408 return "ARNOLDI";
409 case EST_KRYLOVSCHUR:
410 return "KRYLOVSCHUR";
412 return "Jacobi Davidson";
414 return "Nonlinear Power";
415 case EST_PJFNKMO:
416 return "PJFNK with Matrix Only";
417 case EST_NEWTON:
418 return "Newton";
419 case EST_JFNK:
420 return "JFNK";
421 case EST_PJFNK:
422 return "Preconditioned JFNK";
423 }
424 return "";
425}
426
427std::string
429{
430 switch (t)
431 {
433 return "STANDARD";
434 case VAR_FIELD_VECTOR:
435 return "VECTOR";
436 case VAR_FIELD_ARRAY:
437 return "ARRAY";
438 case VAR_FIELD_SCALAR:
439 return "SCALAR";
440 case VAR_FIELD_ANY:
441 return "ANY";
442 }
443 return "";
444}
445
446std::string
448{
449 switch (t)
450 {
452 return "time";
454 return "nonlinear";
456 return "multiapp_fixed_point";
458 return "multisystem_fixed_point";
459 default:
460 mooseError("Unhandled SolutionIterationType");
461 }
462}
463
464std::string
466{
467 switch (t)
468 {
470 return "ELEMENT";
472 return "NEIGHBOR";
474 return "LOWER";
475 default:
476 mooseError("unrecognized type");
477 }
478}
479
480std::string
485
486std::string
487stringify(const std::string & s)
488{
489 return s;
490}
491
492std::string
494{
495 // this or std::numeric_limits<T>::max_digits10
496 const unsigned int max_digits10 =
497 std::floor(std::numeric_limits<Real>::digits * std::log10(2) + 2);
498
499 std::ostringstream os;
500 os << std::setprecision(max_digits10) << t;
501 return os.str();
502}
503
504Point
505toPoint(const std::vector<Real> & pos)
506{
507 mooseAssert(pos.size() == LIBMESH_DIM, "Wrong array size while converting into a point");
508 return Point(pos[0], pos[1], pos[2]);
509}
510}
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:29
void initMffdType()
Definition Conversion.C:143
SolveType stringToEnum< SolveType >(const std::string &s)
Definition Conversion.C:201
void initEigenProlemType()
Definition Conversion.C:76
LineSearchType stringToEnum< LineSearchType >(const std::string &s)
Definition Conversion.C:261
void initCoordinateSystemType()
Definition Conversion.C:35
MffdType stringToEnum< MffdType >(const std::string &s)
Definition Conversion.C:291
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:166
EigenProblemType stringToEnum< EigenProblemType >(const std::string &s)
Definition Conversion.C:231
std::map< std::string, CoordinateSystemType > coordinate_system_type_to_enum
Definition Conversion.C:24
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:110
RelationshipManagerType stringToEnum< RelationshipManagerType >(const std::string &s)
Definition Conversion.C:306
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:276
std::map< std::string, TimeIntegratorType > time_integrator_to_enum
Definition Conversion.C:30
CoordinateSystemType stringToEnum< CoordinateSystemType >(const std::string &s)
Definition Conversion.C:186
void initEigenSolveType()
Definition Conversion.C:59
std::map< std::string, SolveType > solve_type_to_enum
Definition Conversion.C:25
void initSolveType()
Definition Conversion.C:46
std::map< std::string, RelationshipManagerType > rm_type_to_enum
Definition Conversion.C:32
void initWhichEigenPairs()
Definition Conversion.C:91
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:505
SolutionIterationType
Definition MooseTypes.h:270
std::map< std::string, EigenProblemType > eigen_problem_type_to_enum
Definition Conversion.C:27
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:128
std::map< std::string, MffdType > mffd_type_to_enum
Definition Conversion.C:31
std::string stringifyExact(Real)
Stringify Reals with enough precision to guarantee lossless Real -> string -> Real roundtrips.
Definition Conversion.C:493
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:173
std::map< std::string, WhichEigenPairs > which_eigen_pairs_to_enum
Definition Conversion.C:28
void initRMType()
Definition Conversion.C:153
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:26
WhichEigenPairs stringToEnum< WhichEigenPairs >(const std::string &s)
Definition Conversion.C:246
EigenSolveType stringToEnum< EigenSolveType >(const std::string &s)
Definition Conversion.C:216
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)