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 65219 : initCoordinateSystemType()
38 : {
39 65219 : if (coordinate_system_type_to_enum.empty())
40 : {
41 53453 : coordinate_system_type_to_enum["XYZ"] = COORD_XYZ;
42 53453 : coordinate_system_type_to_enum["RZ"] = COORD_RZ;
43 53453 : coordinate_system_type_to_enum["RSPHERICAL"] = COORD_RSPHERICAL;
44 : }
45 65219 : }
46 :
47 : void
48 37938 : initSolveType()
49 : {
50 37938 : if (solve_type_to_enum.empty())
51 : {
52 31068 : solve_type_to_enum["PJFNK"] = ST_PJFNK;
53 31068 : solve_type_to_enum["JFNK"] = ST_JFNK;
54 31068 : solve_type_to_enum["NEWTON"] = ST_NEWTON;
55 31068 : solve_type_to_enum["FD"] = ST_FD;
56 31068 : solve_type_to_enum["LINEAR"] = ST_LINEAR;
57 : }
58 37938 : }
59 :
60 : void
61 588 : initEigenSolveType()
62 : {
63 588 : if (eigen_solve_type_to_enum.empty())
64 : {
65 588 : eigen_solve_type_to_enum["POWER"] = EST_POWER;
66 588 : eigen_solve_type_to_enum["ARNOLDI"] = EST_ARNOLDI;
67 588 : eigen_solve_type_to_enum["KRYLOVSCHUR"] = EST_KRYLOVSCHUR;
68 588 : eigen_solve_type_to_enum["JACOBI_DAVIDSON"] = EST_JACOBI_DAVIDSON;
69 588 : eigen_solve_type_to_enum["NONLINEAR_POWER"] = EST_NONLINEAR_POWER;
70 588 : eigen_solve_type_to_enum["NEWTON"] = EST_NEWTON;
71 588 : eigen_solve_type_to_enum["PJFNK"] = EST_PJFNK;
72 588 : eigen_solve_type_to_enum["PJFNKMO"] = EST_PJFNKMO;
73 588 : 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 588 : eigen_problem_type_to_enum["HERMITIAN"] = EPT_HERMITIAN;
83 588 : eigen_problem_type_to_enum["NON_HERMITIAN"] = EPT_NON_HERMITIAN;
84 588 : eigen_problem_type_to_enum["GEN_HERMITIAN"] = EPT_GEN_HERMITIAN;
85 588 : eigen_problem_type_to_enum["GEN_NON_HERMITIAN"] = EPT_GEN_NON_HERMITIAN;
86 588 : eigen_problem_type_to_enum["GEN_INDEFINITE"] = EPT_GEN_INDEFINITE;
87 588 : eigen_problem_type_to_enum["POS_GEN_NON_HERMITIAN"] = EPT_POS_GEN_NON_HERMITIAN;
88 588 : 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 77 : which_eigen_pairs_to_enum["LARGEST_MAGNITUDE"] = WEP_LARGEST_MAGNITUDE;
98 77 : which_eigen_pairs_to_enum["SMALLEST_MAGNITUDE"] = WEP_SMALLEST_MAGNITUDE;
99 77 : which_eigen_pairs_to_enum["LARGEST_REAL"] = WEP_LARGEST_REAL;
100 77 : which_eigen_pairs_to_enum["SMALLEST_REAL"] = WEP_SMALLEST_REAL;
101 77 : which_eigen_pairs_to_enum["LARGEST_IMAGINARY"] = WEP_LARGEST_IMAGINARY;
102 77 : which_eigen_pairs_to_enum["SMALLEST_IMAGINARY"] = WEP_SMALLEST_IMAGINARY;
103 77 : which_eigen_pairs_to_enum["TARGET_MAGNITUDE"] = WEP_TARGET_MAGNITUDE;
104 77 : which_eigen_pairs_to_enum["TARGET_REAL"] = WEP_TARGET_REAL;
105 77 : which_eigen_pairs_to_enum["TARGET_IMAGINARY"] = WEP_TARGET_IMAGINARY;
106 77 : which_eigen_pairs_to_enum["ALL_EIGENVALUES"] = WEP_ALL_EIGENVALUES;
107 77 : which_eigen_pairs_to_enum["SLEPC_DEFAULT"] = WEP_SLEPC_DEFAULT;
108 : }
109 77 : }
110 :
111 : void
112 61008 : initLineSearchType()
113 : {
114 61008 : if (line_search_type_to_enum.empty())
115 : {
116 48344 : line_search_type_to_enum["DEFAULT"] = LS_DEFAULT;
117 48344 : line_search_type_to_enum["NONE"] = LS_NONE;
118 48344 : line_search_type_to_enum["BASIC"] = LS_BASIC;
119 :
120 48344 : line_search_type_to_enum["SHELL"] = LS_SHELL;
121 48344 : line_search_type_to_enum["L2"] = LS_L2;
122 48344 : line_search_type_to_enum["BT"] = LS_BT;
123 48344 : line_search_type_to_enum["CP"] = LS_CP;
124 48344 : line_search_type_to_enum["CONTACT"] = LS_CONTACT;
125 48344 : line_search_type_to_enum["PROJECT"] = LS_PROJECT;
126 : }
127 61008 : }
128 :
129 : void
130 66 : initTimeIntegratorsType()
131 : {
132 66 : if (time_integrator_to_enum.empty())
133 : {
134 24 : time_integrator_to_enum["IMPLICIT_EULER"] = TI_IMPLICIT_EULER;
135 24 : time_integrator_to_enum["EXPLICIT_EULER"] = TI_EXPLICIT_EULER;
136 24 : time_integrator_to_enum["CRANK_NICOLSON"] = TI_CRANK_NICOLSON;
137 24 : time_integrator_to_enum["BDF2"] = TI_BDF2;
138 24 : time_integrator_to_enum["EXPLICIT_MIDPOINT"] = TI_EXPLICIT_MIDPOINT;
139 24 : time_integrator_to_enum["LSTABLE_DIRK2"] = TI_LSTABLE_DIRK2;
140 24 : time_integrator_to_enum["EXPLICIT_TVDRK2"] = TI_EXPLICIT_TVD_RK_2;
141 : }
142 66 : }
143 :
144 : void
145 75659 : initMffdType()
146 : {
147 75659 : if (mffd_type_to_enum.empty())
148 : {
149 48344 : mffd_type_to_enum["DS"] = MFFD_DS;
150 48344 : mffd_type_to_enum["WP"] = MFFD_WP;
151 : }
152 75659 : }
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 66817 : stringToEnum<QuadratureType>(const std::string & s)
169 : {
170 66817 : return Utility::string_to_enum<QuadratureType>("Q" + s);
171 : }
172 :
173 : template <>
174 : Order
175 200535 : stringToEnum<Order>(const std::string & s)
176 : {
177 200535 : std::string upper(s);
178 200535 : std::transform(upper.begin(), upper.end(), upper.begin(), ::toupper);
179 :
180 200535 : if (upper.compare("AUTO") == 0)
181 199922 : return INVALID_ORDER;
182 : else
183 613 : return Utility::string_to_enum<Order>(upper);
184 200535 : }
185 :
186 : template <>
187 : CoordinateSystemType
188 65219 : stringToEnum<CoordinateSystemType>(const std::string & s)
189 : {
190 65219 : initCoordinateSystemType();
191 :
192 65219 : std::string upper(s);
193 65219 : std::transform(upper.begin(), upper.end(), upper.begin(), ::toupper);
194 :
195 65219 : if (!coordinate_system_type_to_enum.count(upper))
196 0 : mooseError("Unknown coordinate system type: ", upper);
197 :
198 130438 : return coordinate_system_type_to_enum[upper];
199 65219 : }
200 :
201 : template <>
202 : SolveType
203 37938 : stringToEnum<SolveType>(const std::string & s)
204 : {
205 37938 : initSolveType();
206 :
207 37938 : std::string upper(s);
208 37938 : std::transform(upper.begin(), upper.end(), upper.begin(), ::toupper);
209 :
210 37938 : if (!solve_type_to_enum.count(upper))
211 0 : mooseError("Unknown solve type: ", upper);
212 :
213 75876 : return solve_type_to_enum[upper];
214 37938 : }
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 61008 : stringToEnum<LineSearchType>(const std::string & s)
264 : {
265 61008 : initLineSearchType();
266 :
267 61008 : std::string upper(s);
268 61008 : std::transform(upper.begin(), upper.end(), upper.begin(), ::toupper);
269 :
270 61008 : if (!line_search_type_to_enum.count(upper))
271 0 : mooseError("Unknown line search type: ", upper);
272 :
273 122016 : return line_search_type_to_enum[upper];
274 61008 : }
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 75659 : stringToEnum<MffdType>(const std::string & s)
294 : {
295 75659 : initMffdType();
296 :
297 75659 : std::string upper(s);
298 75659 : std::transform(upper.begin(), upper.end(), upper.begin(), ::toupper);
299 :
300 75659 : if (!mffd_type_to_enum.count(upper))
301 0 : mooseError("Unknown mffd type: ", upper);
302 :
303 151318 : return mffd_type_to_enum[upper];
304 75659 : }
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 589896 : 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 589896 : if (t == RelationshipManagerType::DEFAULT)
331 0 : return "DEFAULT";
332 589896 : if (t == RelationshipManagerType::GEOMETRIC)
333 122867 : return "GEOMETRIC";
334 467029 : if (t == RelationshipManagerType::ALGEBRAIC)
335 15002 : return "ALGEBRAIC";
336 452027 : if (t == (RelationshipManagerType::GEOMETRIC | RelationshipManagerType::ALGEBRAIC))
337 128560 : return "GEOMETRIC and ALGEBRAIC";
338 323467 : if (t == (RelationshipManagerType::ALGEBRAIC | RelationshipManagerType::COUPLING))
339 0 : return "ALGEBRAIC and COUPLING";
340 323467 : if (t == (RelationshipManagerType::GEOMETRIC | RelationshipManagerType::ALGEBRAIC |
341 : RelationshipManagerType::COUPLING))
342 70205 : return "GEOMETRIC and ALGEBRAIC and COUPLING";
343 253262 : if (t == RelationshipManagerType::COUPLING)
344 253262 : 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 54170 : stringify(const SolveType & t)
360 : {
361 54170 : switch (t)
362 : {
363 11916 : case ST_NEWTON:
364 11916 : return "NEWTON";
365 77 : case ST_JFNK:
366 77 : return "JFNK";
367 39816 : case ST_PJFNK:
368 39816 : return "Preconditioned JFNK";
369 1 : case ST_FD:
370 1 : return "FD";
371 2360 : case ST_LINEAR:
372 2360 : 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 39 : return "KRYLOVSCHUR";
388 26 : case EST_JACOBI_DAVIDSON:
389 26 : return "Jacobi Davidson";
390 13 : case EST_NONLINEAR_POWER:
391 13 : return "Nonlinear Power";
392 98 : case EST_PJFNKMO:
393 98 : return "PJFNK with Matrix Only";
394 36 : case EST_NEWTON:
395 36 : return "Newton";
396 40 : case EST_JFNK:
397 40 : return "JFNK";
398 316 : case EST_PJFNK:
399 316 : 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 8 : return "STANDARD";
411 8 : case VAR_FIELD_VECTOR:
412 8 : 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 : default:
433 0 : mooseError("Unhandled SolutionIterationType");
434 : }
435 : }
436 :
437 : std::string
438 0 : stringify(ElementType t)
439 : {
440 0 : switch (t)
441 : {
442 0 : case ElementType::Element:
443 0 : return "ELEMENT";
444 0 : case ElementType::Neighbor:
445 0 : return "NEIGHBOR";
446 0 : case ElementType::Lower:
447 0 : return "LOWER";
448 0 : default:
449 0 : mooseError("unrecognized type");
450 : }
451 : }
452 :
453 : std::string
454 296 : stringify(libMesh::ElemType t)
455 : {
456 296 : return libMesh::Utility::enum_to_string(t);
457 : }
458 :
459 : std::string
460 2672571 : stringify(const std::string & s)
461 : {
462 2672571 : return s;
463 : }
464 :
465 : std::string
466 7 : stringifyExact(Real t)
467 : {
468 : // this or std::numeric_limits<T>::max_digits10
469 7 : const unsigned int max_digits10 =
470 : std::floor(std::numeric_limits<Real>::digits * std::log10(2) + 2);
471 :
472 7 : std::ostringstream os;
473 7 : os << std::setprecision(max_digits10) << t;
474 14 : return os.str();
475 7 : }
476 :
477 : Point
478 0 : toPoint(const std::vector<Real> & pos)
479 : {
480 : mooseAssert(pos.size() == LIBMESH_DIM, "Wrong array size while converting into a point");
481 0 : return Point(pos[0], pos[1], pos[2]);
482 : }
483 : }
|