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#include "libmesh/fe_type.h"
19
20// system includes
21#include <iomanip>
22
23namespace Moose
24{
25std::map<std::string, CoordinateSystemType> coordinate_system_type_to_enum;
26std::map<std::string, SolveType> solve_type_to_enum;
27std::map<std::string, EigenSolveType> eigen_solve_type_to_enum;
28std::map<std::string, EigenProblemType> eigen_problem_type_to_enum;
29std::map<std::string, WhichEigenPairs> which_eigen_pairs_to_enum;
30std::map<std::string, LineSearchType> line_search_type_to_enum;
31std::map<std::string, TimeIntegratorType> time_integrator_to_enum;
32std::map<std::string, MffdType> mffd_type_to_enum;
33std::map<std::string, RelationshipManagerType> rm_type_to_enum;
34
35void
45
46void
48{
49 if (solve_type_to_enum.empty())
50 {
53 solve_type_to_enum["NEWTON"] = ST_NEWTON;
55 solve_type_to_enum["LINEAR"] = ST_LINEAR;
56 }
57}
58
59void
75
76void
90
91void
109
110void
127
128void
130{
131 if (time_integrator_to_enum.empty())
132 {
133 time_integrator_to_enum["IMPLICIT_EULER"] = TI_IMPLICIT_EULER;
134 time_integrator_to_enum["EXPLICIT_EULER"] = TI_EXPLICIT_EULER;
135 time_integrator_to_enum["CRANK_NICOLSON"] = TI_CRANK_NICOLSON;
137 time_integrator_to_enum["EXPLICIT_MIDPOINT"] = TI_EXPLICIT_MIDPOINT;
138 time_integrator_to_enum["LSTABLE_DIRK2"] = TI_LSTABLE_DIRK2;
140 }
141}
142
143void
145{
146 if (mffd_type_to_enum.empty())
147 {
150 }
151}
152
153void
164
165template <>
166QuadratureType
167stringToEnum<QuadratureType>(const std::string & s)
168{
169 return Utility::string_to_enum<QuadratureType>("Q" + s);
170}
171
172template <>
173Order
174stringToEnum<Order>(const std::string & s)
175{
176 std::string upper(s);
177 std::transform(upper.begin(), upper.end(), upper.begin(), ::toupper);
178
179 if (upper.compare("AUTO") == 0)
180 return INVALID_ORDER;
181 else
182 return Utility::string_to_enum<Order>(upper);
183}
184
185template <>
187stringToEnum<CoordinateSystemType>(const std::string & s)
188{
190
191 std::string upper(s);
192 std::transform(upper.begin(), upper.end(), upper.begin(), ::toupper);
193
194 if (!coordinate_system_type_to_enum.count(upper))
195 mooseError("Unknown coordinate system type: ", upper);
196
197 return coordinate_system_type_to_enum[upper];
198}
199
200template <>
202stringToEnum<SolveType>(const std::string & s)
203{
205
206 std::string upper(s);
207 std::transform(upper.begin(), upper.end(), upper.begin(), ::toupper);
208
209 if (!solve_type_to_enum.count(upper))
210 mooseError("Unknown solve type: ", upper);
211
212 return solve_type_to_enum[upper];
213}
214
215template <>
217stringToEnum<EigenSolveType>(const std::string & s)
218{
220
221 std::string upper(s);
222 std::transform(upper.begin(), upper.end(), upper.begin(), ::toupper);
223
224 if (!eigen_solve_type_to_enum.count(upper))
225 mooseError("Unknown eigen solve type: ", upper);
226
227 return eigen_solve_type_to_enum[upper];
228}
229
230template <>
232stringToEnum<EigenProblemType>(const std::string & s)
233{
235
236 std::string upper(s);
237 std::transform(upper.begin(), upper.end(), upper.begin(), ::toupper);
238
239 if (!eigen_problem_type_to_enum.count(upper))
240 mooseError("Unknown eigen problem type: ", upper);
241
242 return eigen_problem_type_to_enum[upper];
243}
244
245template <>
247stringToEnum<WhichEigenPairs>(const std::string & s)
248{
250
251 std::string upper(s);
252 std::transform(upper.begin(), upper.end(), upper.begin(), ::toupper);
253
254 if (!which_eigen_pairs_to_enum.count(upper))
255 mooseError("Unknown type of WhichEigenPairs: ", upper);
256
257 return which_eigen_pairs_to_enum[upper];
258}
259
260template <>
262stringToEnum<LineSearchType>(const std::string & s)
263{
265
266 std::string upper(s);
267 std::transform(upper.begin(), upper.end(), upper.begin(), ::toupper);
268
269 if (!line_search_type_to_enum.count(upper))
270 mooseError("Unknown line search type: ", upper);
271
272 return line_search_type_to_enum[upper];
273}
274
275template <>
277stringToEnum<TimeIntegratorType>(const std::string & s)
278{
280
281 std::string upper(s);
282 std::transform(upper.begin(), upper.end(), upper.begin(), ::toupper);
283
284 if (!time_integrator_to_enum.count(upper))
285 mooseError("Unknown time integrator: ", upper);
286
287 return time_integrator_to_enum[upper];
288}
289
290template <>
292stringToEnum<MffdType>(const std::string & s)
293{
294 initMffdType();
295
296 std::string upper(s);
297 std::transform(upper.begin(), upper.end(), upper.begin(), ::toupper);
298
299 if (!mffd_type_to_enum.count(upper))
300 mooseError("Unknown mffd type: ", upper);
301
302 return mffd_type_to_enum[upper];
303}
304
305template <>
307stringToEnum<RelationshipManagerType>(const std::string & s)
308{
309 initRMType();
310
311 std::string upper(s);
312 std::transform(upper.begin(), upper.end(), upper.begin(), ::toupper);
313
314 if (!rm_type_to_enum.count(upper))
315 mooseError("Unknown RelationshipManager type: ", upper);
316
317 return rm_type_to_enum[upper];
318}
319
320// Ignore warnings about switching on the |'d type
321#include "libmesh/ignore_warnings.h"
322
323// Definition in MooseTypes.h
324std::string
326{
327 // Cannot make a switch statement because the boolean logic doesn't work well with the class type
328 // enumeration and because Cody says so.
330 return "DEFAULT";
332 return "GEOMETRIC";
334 return "ALGEBRAIC";
336 return "GEOMETRIC and ALGEBRAIC";
338 return "ALGEBRAIC and COUPLING";
341 return "GEOMETRIC and ALGEBRAIC and COUPLING";
343 return "COUPLING";
344
345 mooseError("Unknown RelationshipManagerType");
346}
347
348// Definition in MooseTypes.h
349std::string
351{
352 switch (t)
353 {
355 return "IMPLICIT_EULER";
357 return "EXPLICIT_EULER";
359 return "CRANK_NICOLSON";
361 return "BDF2";
363 return "EXPLICIT_MIDPOINT";
365 return "LSTABLE_DIRK2";
367 return "EXPLICIT_TVDRK2";
368 default:
369 mooseError("Unknown TimeIntegratorType");
370 }
371}
372
373std::string
378
379// Turn the warnings back on
380#include "libmesh/restore_warnings.h"
381
382std::string
384{
385 auto msg = stringify(t.family) + " of order " + stringify(t.order);
386 // A scalar variable has no spatial basis, so p-refinement carries no meaning for it
387 if (t.family != libMesh::SCALAR)
388 msg += t.p_refinement ? " with p-refinement" : " without p-refinement";
389 return msg;
390}
391
392std::string
394{
395 switch (t)
396 {
397 case ST_NEWTON:
398 return "NEWTON";
399 case ST_JFNK:
400 return "JFNK";
401 case ST_PJFNK:
402 return "Preconditioned JFNK";
403 case ST_FD:
404 return "FD";
405 case ST_LINEAR:
406 return "Linear";
407 }
408 return "";
409}
410
411std::string
413{
414 switch (t)
415 {
416 case EST_POWER:
417 return "Power";
418 case EST_ARNOLDI:
419 return "ARNOLDI";
420 case EST_KRYLOVSCHUR:
421 return "KRYLOVSCHUR";
423 return "Jacobi Davidson";
425 return "Nonlinear Power";
426 case EST_PJFNKMO:
427 return "PJFNK with Matrix Only";
428 case EST_NEWTON:
429 return "Newton";
430 case EST_JFNK:
431 return "JFNK";
432 case EST_PJFNK:
433 return "Preconditioned JFNK";
434 }
435 return "";
436}
437
438std::string
440{
441 switch (t)
442 {
444 return "STANDARD";
445 case VAR_FIELD_VECTOR:
446 return "VECTOR";
447 case VAR_FIELD_ARRAY:
448 return "ARRAY";
449 case VAR_FIELD_SCALAR:
450 return "SCALAR";
451 case VAR_FIELD_ANY:
452 return "ANY";
453 }
454 return "";
455}
456
457std::string
459{
460 switch (t)
461 {
463 return "time";
465 return "nonlinear";
467 return "multiapp_fixed_point";
469 return "multisystem_fixed_point";
470 default:
471 mooseError("Unhandled SolutionIterationType");
472 }
473}
474
475std::string
477{
478 switch (t)
479 {
481 return "ELEMENT";
483 return "NEIGHBOR";
485 return "LOWER";
486 default:
487 mooseError("unrecognized type");
488 }
489}
490
491std::string
496
497std::string
498stringify(const std::string & s)
499{
500 return s;
501}
502
503std::string
505{
506 // this or std::numeric_limits<T>::max_digits10
507 const unsigned int max_digits10 =
508 std::floor(std::numeric_limits<Real>::digits * std::log10(2) + 2);
509
510 std::ostringstream os;
511 os << std::setprecision(max_digits10) << t;
512 return os.str();
513}
514
515Point
516toPoint(const std::vector<Real> & pos)
517{
518 mooseAssert(pos.size() == LIBMESH_DIM, "Wrong array size while converting into a point");
519 return Point(pos[0], pos[1], pos[2]);
520}
521}
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application.
Definition MooseError.h:311
OrderWrapper order
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:30
void initMffdType()
Definition Conversion.C:144
SolveType stringToEnum< SolveType >(const std::string &s)
Definition Conversion.C:202
void initEigenProlemType()
Definition Conversion.C:77
LineSearchType stringToEnum< LineSearchType >(const std::string &s)
Definition Conversion.C:262
void initCoordinateSystemType()
Definition Conversion.C:36
MffdType stringToEnum< MffdType >(const std::string &s)
Definition Conversion.C:292
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:167
EigenProblemType stringToEnum< EigenProblemType >(const std::string &s)
Definition Conversion.C:232
std::map< std::string, CoordinateSystemType > coordinate_system_type_to_enum
Definition Conversion.C:25
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:111
RelationshipManagerType stringToEnum< RelationshipManagerType >(const std::string &s)
Definition Conversion.C:307
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:277
std::map< std::string, TimeIntegratorType > time_integrator_to_enum
Definition Conversion.C:31
CoordinateSystemType stringToEnum< CoordinateSystemType >(const std::string &s)
Definition Conversion.C:187
void initEigenSolveType()
Definition Conversion.C:60
std::map< std::string, SolveType > solve_type_to_enum
Definition Conversion.C:26
void initSolveType()
Definition Conversion.C:47
std::map< std::string, RelationshipManagerType > rm_type_to_enum
Definition Conversion.C:33
void initWhichEigenPairs()
Definition Conversion.C:92
std::string stringify(const T &t)
conversion to string
Definition Conversion.h:65
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:516
SolutionIterationType
Definition MooseTypes.h:270
std::map< std::string, EigenProblemType > eigen_problem_type_to_enum
Definition Conversion.C:28
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:129
std::map< std::string, MffdType > mffd_type_to_enum
Definition Conversion.C:32
std::string stringifyExact(Real)
Stringify Reals with enough precision to guarantee lossless Real -> string -> Real roundtrips.
Definition Conversion.C:504
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:174
std::map< std::string, WhichEigenPairs > which_eigen_pairs_to_enum
Definition Conversion.C:29
void initRMType()
Definition Conversion.C:154
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:27
WhichEigenPairs stringToEnum< WhichEigenPairs >(const std::string &s)
Definition Conversion.C:247
EigenSolveType stringToEnum< EigenSolveType >(const std::string &s)
Definition Conversion.C:217
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)