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