Line data Source code
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
37 65164 : initCoordinateSystemType()
38 : {
39 65164 : if (coordinate_system_type_to_enum.empty())
40 : {
41 107186 : coordinate_system_type_to_enum["XYZ"] = COORD_XYZ;
42 107186 : coordinate_system_type_to_enum["RZ"] = COORD_RZ;
43 107186 : coordinate_system_type_to_enum["RSPHERICAL"] = COORD_RSPHERICAL;
44 : }
45 65164 : }
46 :
47 : void
48 35486 : initSolveType()
49 : {
50 35486 : if (solve_type_to_enum.empty())
51 : {
52 59274 : solve_type_to_enum["PJFNK"] = ST_PJFNK;
53 59274 : solve_type_to_enum["JFNK"] = ST_JFNK;
54 59274 : solve_type_to_enum["NEWTON"] = ST_NEWTON;
55 59274 : solve_type_to_enum["FD"] = ST_FD;
56 59274 : solve_type_to_enum["LINEAR"] = ST_LINEAR;
57 : }
58 35486 : }
59 :
60 : void
61 565 : initEigenSolveType()
62 : {
63 565 : if (eigen_solve_type_to_enum.empty())
64 : {
65 1130 : eigen_solve_type_to_enum["POWER"] = EST_POWER;
66 1130 : eigen_solve_type_to_enum["ARNOLDI"] = EST_ARNOLDI;
67 1130 : eigen_solve_type_to_enum["KRYLOVSCHUR"] = EST_KRYLOVSCHUR;
68 1130 : eigen_solve_type_to_enum["JACOBI_DAVIDSON"] = EST_JACOBI_DAVIDSON;
69 1130 : eigen_solve_type_to_enum["NONLINEAR_POWER"] = EST_NONLINEAR_POWER;
70 1130 : eigen_solve_type_to_enum["NEWTON"] = EST_NEWTON;
71 1130 : eigen_solve_type_to_enum["PJFNK"] = EST_PJFNK;
72 1130 : eigen_solve_type_to_enum["PJFNKMO"] = EST_PJFNKMO;
73 1130 : eigen_solve_type_to_enum["JFNK"] = EST_JFNK;
74 : }
75 565 : }
76 :
77 : void
78 565 : initEigenProlemType()
79 : {
80 565 : if (eigen_problem_type_to_enum.empty())
81 : {
82 1130 : eigen_problem_type_to_enum["HERMITIAN"] = EPT_HERMITIAN;
83 1130 : eigen_problem_type_to_enum["NON_HERMITIAN"] = EPT_NON_HERMITIAN;
84 1130 : eigen_problem_type_to_enum["GEN_HERMITIAN"] = EPT_GEN_HERMITIAN;
85 1130 : eigen_problem_type_to_enum["GEN_NON_HERMITIAN"] = EPT_GEN_NON_HERMITIAN;
86 1130 : eigen_problem_type_to_enum["GEN_INDEFINITE"] = EPT_GEN_INDEFINITE;
87 1130 : eigen_problem_type_to_enum["POS_GEN_NON_HERMITIAN"] = EPT_POS_GEN_NON_HERMITIAN;
88 1130 : eigen_problem_type_to_enum["SLEPC_DEFAULT"] = EPT_SLEPC_DEFAULT;
89 : }
90 565 : }
91 :
92 : void
93 69 : initWhichEigenPairs()
94 : {
95 69 : if (which_eigen_pairs_to_enum.empty())
96 : {
97 138 : which_eigen_pairs_to_enum["LARGEST_MAGNITUDE"] = WEP_LARGEST_MAGNITUDE;
98 138 : which_eigen_pairs_to_enum["SMALLEST_MAGNITUDE"] = WEP_SMALLEST_MAGNITUDE;
99 138 : which_eigen_pairs_to_enum["LARGEST_REAL"] = WEP_LARGEST_REAL;
100 138 : which_eigen_pairs_to_enum["SMALLEST_REAL"] = WEP_SMALLEST_REAL;
101 138 : which_eigen_pairs_to_enum["LARGEST_IMAGINARY"] = WEP_LARGEST_IMAGINARY;
102 138 : which_eigen_pairs_to_enum["SMALLEST_IMAGINARY"] = WEP_SMALLEST_IMAGINARY;
103 138 : which_eigen_pairs_to_enum["TARGET_MAGNITUDE"] = WEP_TARGET_MAGNITUDE;
104 138 : which_eigen_pairs_to_enum["TARGET_REAL"] = WEP_TARGET_REAL;
105 138 : which_eigen_pairs_to_enum["TARGET_IMAGINARY"] = WEP_TARGET_IMAGINARY;
106 138 : which_eigen_pairs_to_enum["ALL_EIGENVALUES"] = WEP_ALL_EIGENVALUES;
107 138 : which_eigen_pairs_to_enum["SLEPC_DEFAULT"] = WEP_SLEPC_DEFAULT;
108 : }
109 69 : }
110 :
111 : void
112 59792 : initLineSearchType()
113 : {
114 59792 : if (line_search_type_to_enum.empty())
115 : {
116 95942 : line_search_type_to_enum["DEFAULT"] = LS_DEFAULT;
117 95942 : line_search_type_to_enum["NONE"] = LS_NONE;
118 95942 : line_search_type_to_enum["BASIC"] = LS_BASIC;
119 :
120 95942 : line_search_type_to_enum["SHELL"] = LS_SHELL;
121 95942 : line_search_type_to_enum["L2"] = LS_L2;
122 95942 : line_search_type_to_enum["BT"] = LS_BT;
123 95942 : line_search_type_to_enum["CP"] = LS_CP;
124 95942 : line_search_type_to_enum["CONTACT"] = LS_CONTACT;
125 95942 : line_search_type_to_enum["PROJECT"] = LS_PROJECT;
126 : }
127 59792 : }
128 :
129 : void
130 60 : initTimeIntegratorsType()
131 : {
132 60 : if (time_integrator_to_enum.empty())
133 : {
134 44 : time_integrator_to_enum["IMPLICIT_EULER"] = TI_IMPLICIT_EULER;
135 44 : time_integrator_to_enum["EXPLICIT_EULER"] = TI_EXPLICIT_EULER;
136 44 : time_integrator_to_enum["CRANK_NICOLSON"] = TI_CRANK_NICOLSON;
137 44 : time_integrator_to_enum["BDF2"] = TI_BDF2;
138 44 : time_integrator_to_enum["EXPLICIT_MIDPOINT"] = TI_EXPLICIT_MIDPOINT;
139 44 : time_integrator_to_enum["LSTABLE_DIRK2"] = TI_LSTABLE_DIRK2;
140 44 : time_integrator_to_enum["EXPLICIT_TVDRK2"] = TI_EXPLICIT_TVD_RK_2;
141 : }
142 60 : }
143 :
144 : void
145 73419 : initMffdType()
146 : {
147 73419 : if (mffd_type_to_enum.empty())
148 : {
149 95942 : mffd_type_to_enum["DS"] = MFFD_DS;
150 95942 : mffd_type_to_enum["WP"] = MFFD_WP;
151 : }
152 73419 : }
153 :
154 : void
155 0 : initRMType()
156 : {
157 0 : if (rm_type_to_enum.empty())
158 : {
159 0 : rm_type_to_enum["DEFAULT"] = RelationshipManagerType::DEFAULT;
160 0 : rm_type_to_enum["GEOMETRIC"] = RelationshipManagerType::GEOMETRIC;
161 0 : rm_type_to_enum["ALGEBRAIC"] = RelationshipManagerType::ALGEBRAIC;
162 0 : rm_type_to_enum["COUPLING"] = RelationshipManagerType::COUPLING;
163 : }
164 0 : }
165 :
166 : template <>
167 : QuadratureType
168 66814 : stringToEnum<QuadratureType>(const std::string & s)
169 : {
170 66814 : return Utility::string_to_enum<QuadratureType>("Q" + s);
171 : }
172 :
173 : template <>
174 : Order
175 200495 : stringToEnum<Order>(const std::string & s)
176 : {
177 200495 : std::string upper(s);
178 200495 : std::transform(upper.begin(), upper.end(), upper.begin(), ::toupper);
179 :
180 200495 : if (upper.compare("AUTO") == 0)
181 199821 : return INVALID_ORDER;
182 : else
183 674 : return Utility::string_to_enum<Order>(upper);
184 200495 : }
185 :
186 : template <>
187 : CoordinateSystemType
188 65164 : stringToEnum<CoordinateSystemType>(const std::string & s)
189 : {
190 65164 : initCoordinateSystemType();
191 :
192 65164 : std::string upper(s);
193 65164 : std::transform(upper.begin(), upper.end(), upper.begin(), ::toupper);
194 :
195 65164 : if (!coordinate_system_type_to_enum.count(upper))
196 0 : mooseError("Unknown coordinate system type: ", upper);
197 :
198 130328 : return coordinate_system_type_to_enum[upper];
199 65164 : }
200 :
201 : template <>
202 : SolveType
203 35486 : stringToEnum<SolveType>(const std::string & s)
204 : {
205 35486 : initSolveType();
206 :
207 35486 : std::string upper(s);
208 35486 : std::transform(upper.begin(), upper.end(), upper.begin(), ::toupper);
209 :
210 35486 : if (!solve_type_to_enum.count(upper))
211 0 : mooseError("Unknown solve type: ", upper);
212 :
213 70972 : return solve_type_to_enum[upper];
214 35486 : }
215 :
216 : template <>
217 : EigenSolveType
218 565 : stringToEnum<EigenSolveType>(const std::string & s)
219 : {
220 565 : initEigenSolveType();
221 :
222 565 : std::string upper(s);
223 565 : std::transform(upper.begin(), upper.end(), upper.begin(), ::toupper);
224 :
225 565 : if (!eigen_solve_type_to_enum.count(upper))
226 0 : mooseError("Unknown eigen solve type: ", upper);
227 :
228 1130 : return eigen_solve_type_to_enum[upper];
229 565 : }
230 :
231 : template <>
232 : EigenProblemType
233 565 : stringToEnum<EigenProblemType>(const std::string & s)
234 : {
235 565 : initEigenProlemType();
236 :
237 565 : std::string upper(s);
238 565 : std::transform(upper.begin(), upper.end(), upper.begin(), ::toupper);
239 :
240 565 : if (!eigen_problem_type_to_enum.count(upper))
241 0 : mooseError("Unknown eigen problem type: ", upper);
242 :
243 1130 : return eigen_problem_type_to_enum[upper];
244 565 : }
245 :
246 : template <>
247 : WhichEigenPairs
248 69 : stringToEnum<WhichEigenPairs>(const std::string & s)
249 : {
250 69 : initWhichEigenPairs();
251 :
252 69 : std::string upper(s);
253 69 : std::transform(upper.begin(), upper.end(), upper.begin(), ::toupper);
254 :
255 69 : if (!which_eigen_pairs_to_enum.count(upper))
256 0 : mooseError("Unknown type of WhichEigenPairs: ", upper);
257 :
258 138 : return which_eigen_pairs_to_enum[upper];
259 69 : }
260 :
261 : template <>
262 : LineSearchType
263 59792 : stringToEnum<LineSearchType>(const std::string & s)
264 : {
265 59792 : initLineSearchType();
266 :
267 59792 : std::string upper(s);
268 59792 : std::transform(upper.begin(), upper.end(), upper.begin(), ::toupper);
269 :
270 59792 : if (!line_search_type_to_enum.count(upper))
271 0 : mooseError("Unknown line search type: ", upper);
272 :
273 119584 : return line_search_type_to_enum[upper];
274 59792 : }
275 :
276 : template <>
277 : TimeIntegratorType
278 60 : stringToEnum<TimeIntegratorType>(const std::string & s)
279 : {
280 60 : initTimeIntegratorsType();
281 :
282 60 : std::string upper(s);
283 60 : std::transform(upper.begin(), upper.end(), upper.begin(), ::toupper);
284 :
285 60 : if (!time_integrator_to_enum.count(upper))
286 0 : mooseError("Unknown time integrator: ", upper);
287 :
288 120 : return time_integrator_to_enum[upper];
289 60 : }
290 :
291 : template <>
292 : MffdType
293 73419 : stringToEnum<MffdType>(const std::string & s)
294 : {
295 73419 : initMffdType();
296 :
297 73419 : std::string upper(s);
298 73419 : std::transform(upper.begin(), upper.end(), upper.begin(), ::toupper);
299 :
300 73419 : if (!mffd_type_to_enum.count(upper))
301 0 : mooseError("Unknown mffd type: ", upper);
302 :
303 146838 : return mffd_type_to_enum[upper];
304 73419 : }
305 :
306 : template <>
307 : RelationshipManagerType
308 0 : stringToEnum<RelationshipManagerType>(const std::string & s)
309 : {
310 0 : initRMType();
311 :
312 0 : std::string upper(s);
313 0 : std::transform(upper.begin(), upper.end(), upper.begin(), ::toupper);
314 :
315 0 : if (!rm_type_to_enum.count(upper))
316 0 : mooseError("Unknown RelationshipManager type: ", upper);
317 :
318 0 : return rm_type_to_enum[upper];
319 0 : }
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
326 582175 : stringify(const RelationshipManagerType & t)
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 582175 : if (t == RelationshipManagerType::DEFAULT)
331 0 : return "DEFAULT";
332 582175 : if (t == RelationshipManagerType::GEOMETRIC)
333 241772 : return "GEOMETRIC";
334 461289 : if (t == RelationshipManagerType::ALGEBRAIC)
335 6942 : return "ALGEBRAIC";
336 457818 : if (t == (RelationshipManagerType::GEOMETRIC | RelationshipManagerType::ALGEBRAIC))
337 316346 : return "GEOMETRIC and ALGEBRAIC";
338 299645 : if (t == (RelationshipManagerType::ALGEBRAIC | RelationshipManagerType::COUPLING))
339 0 : return "ALGEBRAIC and COUPLING";
340 299645 : if (t == (RelationshipManagerType::GEOMETRIC | RelationshipManagerType::ALGEBRAIC |
341 : RelationshipManagerType::COUPLING))
342 106022 : return "GEOMETRIC and ALGEBRAIC and COUPLING";
343 246634 : if (t == RelationshipManagerType::COUPLING)
344 493268 : return "COUPLING";
345 :
346 0 : mooseError("Unknown RelationshipManagerType");
347 : }
348 :
349 : // Definition in MooseTypes.h
350 : std::string
351 16 : stringify(const TimeIntegratorType & t)
352 : {
353 16 : switch (t)
354 : {
355 2 : case TimeIntegratorType::TI_IMPLICIT_EULER:
356 4 : return "IMPLICIT_EULER";
357 2 : case TimeIntegratorType::TI_EXPLICIT_EULER:
358 4 : return "EXPLICIT_EULER";
359 2 : case TimeIntegratorType::TI_CRANK_NICOLSON:
360 4 : return "CRANK_NICOLSON";
361 4 : case TimeIntegratorType::TI_BDF2:
362 8 : return "BDF2";
363 2 : case TimeIntegratorType::TI_EXPLICIT_MIDPOINT:
364 4 : return "EXPLICIT_MIDPOINT";
365 2 : case TimeIntegratorType::TI_LSTABLE_DIRK2:
366 4 : return "LSTABLE_DIRK2";
367 2 : case TimeIntegratorType::TI_EXPLICIT_TVD_RK_2:
368 4 : return "EXPLICIT_TVDRK2";
369 0 : default:
370 0 : mooseError("Unknown TimeIntegratorType");
371 : }
372 : }
373 :
374 : std::string
375 12 : stringify(libMesh::FEFamily f)
376 : {
377 12 : return libMesh::Utility::enum_to_string(f);
378 : }
379 :
380 : // Turn the warnings back on
381 : #include "libmesh/restore_warnings.h"
382 :
383 : std::string
384 53706 : stringify(const SolveType & t)
385 : {
386 53706 : switch (t)
387 : {
388 11178 : case ST_NEWTON:
389 22356 : return "NEWTON";
390 77 : case ST_JFNK:
391 154 : return "JFNK";
392 40320 : case ST_PJFNK:
393 80640 : return "Preconditioned JFNK";
394 2 : case ST_FD:
395 4 : return "FD";
396 2129 : case ST_LINEAR:
397 4258 : return "Linear";
398 : }
399 0 : return "";
400 : }
401 :
402 : std::string
403 550 : stringify(const EigenSolveType & t)
404 : {
405 550 : switch (t)
406 : {
407 0 : case EST_POWER:
408 0 : return "Power";
409 0 : case EST_ARNOLDI:
410 0 : return "ARNOLDI";
411 36 : case EST_KRYLOVSCHUR:
412 72 : return "KRYLOVSCHUR";
413 24 : case EST_JACOBI_DAVIDSON:
414 48 : return "Jacobi Davidson";
415 12 : case EST_NONLINEAR_POWER:
416 24 : return "Nonlinear Power";
417 90 : case EST_PJFNKMO:
418 180 : return "PJFNK with Matrix Only";
419 33 : case EST_NEWTON:
420 66 : return "Newton";
421 36 : case EST_JFNK:
422 72 : return "JFNK";
423 319 : case EST_PJFNK:
424 638 : return "Preconditioned JFNK";
425 : }
426 0 : return "";
427 : }
428 :
429 : std::string
430 12 : stringify(const VarFieldType & t)
431 : {
432 12 : switch (t)
433 : {
434 6 : case VAR_FIELD_STANDARD:
435 12 : return "STANDARD";
436 6 : case VAR_FIELD_VECTOR:
437 12 : return "VECTOR";
438 0 : case VAR_FIELD_ARRAY:
439 0 : return "ARRAY";
440 0 : case VAR_FIELD_SCALAR:
441 0 : return "SCALAR";
442 0 : case VAR_FIELD_ANY:
443 0 : return "ANY";
444 : }
445 0 : return "";
446 : }
447 :
448 : std::string
449 0 : stringify(SolutionIterationType t)
450 : {
451 0 : switch (t)
452 : {
453 0 : case SolutionIterationType::Time:
454 0 : return "time";
455 0 : case SolutionIterationType::Nonlinear:
456 0 : return "nonlinear";
457 0 : case SolutionIterationType::FixedPoint:
458 0 : return "fixed_point";
459 0 : default:
460 0 : mooseError("Unhandled SolutionIterationType");
461 : }
462 : }
463 :
464 : std::string
465 0 : stringify(ElementType t)
466 : {
467 0 : switch (t)
468 : {
469 0 : case ElementType::Element:
470 0 : return "ELEMENT";
471 0 : case ElementType::Neighbor:
472 0 : return "NEIGHBOR";
473 0 : case ElementType::Lower:
474 0 : return "LOWER";
475 0 : default:
476 0 : mooseError("unrecognized type");
477 : }
478 : }
479 :
480 : std::string
481 533 : stringify(libMesh::ElemType t)
482 : {
483 533 : return libMesh::Utility::enum_to_string(t);
484 : }
485 :
486 : std::string
487 1434776 : stringify(const std::string & s)
488 : {
489 1434776 : return s;
490 : }
491 :
492 : std::string
493 14 : stringifyExact(Real t)
494 : {
495 : // this or std::numeric_limits<T>::max_digits10
496 14 : const unsigned int max_digits10 =
497 : std::floor(std::numeric_limits<Real>::digits * std::log10(2) + 2);
498 :
499 14 : std::ostringstream os;
500 14 : os << std::setprecision(max_digits10) << t;
501 28 : return os.str();
502 14 : }
503 :
504 : Point
505 0 : toPoint(const std::vector<Real> & pos)
506 : {
507 : mooseAssert(pos.size() == LIBMESH_DIM, "Wrong array size while converting into a point");
508 0 : return Point(pos[0], pos[1], pos[2]);
509 : }
510 : }
|