25 #include "libmesh/libmesh_common.h"
26 #include "libmesh/string_to_enum.h"
27 #include "libmesh/enum_to_string.h"
28 #include "libmesh/enum_convergence_flags.h"
29 #include "libmesh/enum_elem_quality.h"
30 #include "libmesh/enum_elem_type.h"
31 #include "libmesh/enum_eigen_solver_type.h"
32 #include "libmesh/enum_fe_family.h"
33 #include "libmesh/enum_inf_map_type.h"
34 #include "libmesh/enum_io_package.h"
35 #include "libmesh/enum_norm_type.h"
36 #include "libmesh/enum_order.h"
37 #include "libmesh/enum_parallel_type.h"
38 #include "libmesh/enum_point_locator_type.h"
39 #include "libmesh/enum_preconditioner_type.h"
40 #include "libmesh/enum_quadrature_type.h"
41 #include "libmesh/enum_solver_package.h"
42 #include "libmesh/enum_solver_type.h"
43 #include "libmesh/enum_subset_solve_mode.h"
44 #include "libmesh/enum_xdr_mode.h"
45 #include "libmesh/elem.h"
56 template <
typename MapIter,
class MapType>
58 void build_reverse_map (MapIter it, MapIter
end, MapType & reverse)
62 for (; it !=
end; ++it)
69 typename MapType::iterator preimage = reverse.find(it->second);
70 if (preimage == reverse.end())
71 reverse.insert (std::make_pair(it->second, it->first));
72 else if (preimage->second < it->first)
73 preimage->second = it->first;
77 #define INSTANTIATE_ENUM_MAPS(ENUM_NAME,VAR_NAME) \
78 std::map<std::string, ENUM_NAME> VAR_NAME##_to_enum; \
80 std::map<ENUM_NAME, std::string> enum_to_##VAR_NAME; \
82 void init_##VAR_NAME##_to_enum (); \
85 void init_enum_to_##VAR_NAME () \
88 if (enum_to_##VAR_NAME .empty()) \
91 init_##VAR_NAME##_to_enum(); \
93 build_reverse_map (VAR_NAME##_to_enum.begin(), \
94 VAR_NAME##_to_enum.end(), \
95 enum_to_##VAR_NAME); \
99 INSTANTIATE_ENUM_MAPS(
ElemType, elem_type)
104 void init_elem_type_to_enum ()
106 if (elem_type_to_enum.empty())
108 elem_type_to_enum[
"EDGE" ]=
EDGE2;
109 elem_type_to_enum[
"EDGE2" ]=
EDGE2;
110 elem_type_to_enum[
"EDGE3" ]=
EDGE3;
111 elem_type_to_enum[
"EDGE4" ]=
EDGE4;
113 elem_type_to_enum[
"TRI" ]=
TRI3;
114 elem_type_to_enum[
"TRI3" ]=
TRI3;
115 elem_type_to_enum[
"TRISHELL3" ]=
TRISHELL3;
117 elem_type_to_enum[
"TRI6" ]=
TRI6;
119 elem_type_to_enum[
"QUAD" ]=
QUAD4;
120 elem_type_to_enum[
"QUAD4" ]=
QUAD4;
122 elem_type_to_enum[
"QUAD8" ]=
QUAD8;
124 elem_type_to_enum[
"QUAD9" ]=
QUAD9;
126 elem_type_to_enum[
"TET" ]=
TET4;
127 elem_type_to_enum[
"TET4" ]=
TET4;
128 elem_type_to_enum[
"TET10" ]=
TET10;
130 elem_type_to_enum[
"HEX" ]=
HEX8;
131 elem_type_to_enum[
"HEX8" ]=
HEX8;
132 elem_type_to_enum[
"HEX20" ]=
HEX20;
133 elem_type_to_enum[
"HEX27" ]=
HEX27;
135 elem_type_to_enum[
"PRISM" ]=
PRISM6;
136 elem_type_to_enum[
"PRISM6" ]=
PRISM6;
137 elem_type_to_enum[
"PRISM15" ]=
PRISM15;
138 elem_type_to_enum[
"PRISM18" ]=
PRISM18;
140 elem_type_to_enum[
"PYRAMID" ]=
PYRAMID5;
141 elem_type_to_enum[
"PYRAMID5" ]=
PYRAMID5;
142 elem_type_to_enum[
"PYRAMID13" ]=
PYRAMID13;
143 elem_type_to_enum[
"PYRAMID14" ]=
PYRAMID14;
145 elem_type_to_enum[
"INFEDGE" ]=
INFEDGE2;
146 elem_type_to_enum[
"INFEDGE2" ]=
INFEDGE2;
148 elem_type_to_enum[
"INFQUAD" ]=
INFQUAD4;
149 elem_type_to_enum[
"INFQUAD4" ]=
INFQUAD4;
150 elem_type_to_enum[
"INFQUAD6" ]=
INFQUAD6;
152 elem_type_to_enum[
"INFHEX" ]=
INFHEX8;
153 elem_type_to_enum[
"INFHEX8" ]=
INFHEX8;
154 elem_type_to_enum[
"INFHEX16" ]=
INFHEX16;
155 elem_type_to_enum[
"INFHEX18" ]=
INFHEX18;
157 elem_type_to_enum[
"INFPRISM" ]=
INFPRISM6;
158 elem_type_to_enum[
"INFPRISM6" ]=
INFPRISM6;
161 elem_type_to_enum[
"NODE" ]=
NODEELEM;
162 elem_type_to_enum[
"NODEELEM" ]=
NODEELEM;
169 INSTANTIATE_ENUM_MAPS(
Order, order)
172 void init_order_to_enum ()
174 if (order_to_enum.empty())
176 order_to_enum[
"CONSTANT" ]=
CONSTANT;
177 order_to_enum[
"FIRST" ]=
FIRST;
178 order_to_enum[
"SECOND" ]=
SECOND;
179 order_to_enum[
"THIRD" ]=
THIRD;
180 order_to_enum[
"FOURTH" ]=
FOURTH;
181 order_to_enum[
"FIFTH" ]=
FIFTH;
182 order_to_enum[
"SIXTH" ]=
SIXTH;
183 order_to_enum[
"SEVENTH" ]=
SEVENTH;
184 order_to_enum[
"EIGHTH" ]=
EIGHTH;
185 order_to_enum[
"NINTH" ]=
NINTH;
186 order_to_enum[
"TENTH" ]=
TENTH;
188 order_to_enum[
"ELEVENTH" ]=
ELEVENTH;
189 order_to_enum[
"TWELFTH" ]=
TWELFTH;
219 order_to_enum[
"FORTIETH" ]=
FORTIETH;
229 INSTANTIATE_ENUM_MAPS(
FEFamily, fefamily)
232 void init_fefamily_to_enum ()
234 if (fefamily_to_enum.empty())
236 fefamily_to_enum[
"LAGRANGE" ]=
LAGRANGE;
241 fefamily_to_enum[
"MONOMIAL" ]=
MONOMIAL;
243 fefamily_to_enum[
"SCALAR" ]=
SCALAR;
244 fefamily_to_enum[
"XYZ" ]=
XYZ;
245 fefamily_to_enum[
"BERNSTEIN" ]=
BERNSTEIN;
247 fefamily_to_enum[
"SZABAB" ]=
SZABAB;
251 fefamily_to_enum[
"LEGENDRE" ]=
LEGENDRE;
252 fefamily_to_enum[
"CLOUGH" ]=
CLOUGH;
253 fefamily_to_enum[
"HERMITE" ]=
HERMITE;
262 INSTANTIATE_ENUM_MAPS(
InfMapType, inf_map_type)
265 void init_inf_map_type_to_enum ()
267 if (inf_map_type_to_enum.empty())
269 inf_map_type_to_enum[
"CARTESIAN" ]=
CARTESIAN;
270 inf_map_type_to_enum[
"SPHERICAL" ]=
SPHERICAL;
279 void init_quadrature_type_to_enum ()
281 if (quadrature_type_to_enum.empty())
283 quadrature_type_to_enum[
"QGAUSS" ]=
QGAUSS;
284 quadrature_type_to_enum[
"QJACOBI_1_0"]=
QJACOBI_1_0;
285 quadrature_type_to_enum[
"QJACOBI_2_0"]=
QJACOBI_2_0;
286 quadrature_type_to_enum[
"QSIMPSON" ]=
QSIMPSON;
287 quadrature_type_to_enum[
"QTRAP" ]=
QTRAP;
288 quadrature_type_to_enum[
"QGRID" ]=
QGRID;
289 quadrature_type_to_enum[
"QCLOUGH" ]=
QCLOUGH;
291 quadrature_type_to_enum[
"QNODAL"]=
QNODAL;
299 void init_preconditioner_type_to_enum ()
301 if (preconditioner_type_to_enum.empty())
306 preconditioner_type_to_enum[
"SOR_PRECOND" ]=
SOR_PRECOND;
307 preconditioner_type_to_enum[
"SSOR_PRECOND" ]=
SSOR_PRECOND;
309 preconditioner_type_to_enum[
"ASM_PRECOND" ]=
ASM_PRECOND;
311 preconditioner_type_to_enum[
"ICC_PRECOND" ]=
ICC_PRECOND;
312 preconditioner_type_to_enum[
"ILU_PRECOND" ]=
ILU_PRECOND;
313 preconditioner_type_to_enum[
"LU_PRECOND" ]=
LU_PRECOND;
314 preconditioner_type_to_enum[
"USER_PRECOND" ]=
USER_PRECOND;
316 preconditioner_type_to_enum[
"AMG_PRECOND" ]=
AMG_PRECOND;
330 preconditioner_type_to_enum[
"LU" ]=
LU_PRECOND;
339 #ifdef LIBMESH_ENABLE_AMR
344 void init_refinementstate_type_to_enum ()
346 if (refinementstate_type_to_enum.empty())
358 #endif // LIBMESH_ENABLE_AMR
364 void init_eigensolvertype_to_enum ()
366 if (eigensolvertype_to_enum.empty())
368 eigensolvertype_to_enum[
"POWER" ]=
POWER;
369 eigensolvertype_to_enum[
"LAPACK" ]=
LAPACK;
370 eigensolvertype_to_enum[
"SUBSPACE" ]=
SUBSPACE;
371 eigensolvertype_to_enum[
"ARNOLDI" ]=
ARNOLDI;
372 eigensolvertype_to_enum[
"LANCZOS" ]=
LANCZOS;
373 eigensolvertype_to_enum[
"KRYLOVSCHUR" ]=
KRYLOVSCHUR;
382 void init_solvertype_to_enum ()
384 if (solvertype_to_enum.empty())
386 solvertype_to_enum[
"CG" ]=
CG;
387 solvertype_to_enum[
"CGN" ]=
CGN;
388 solvertype_to_enum[
"CGS" ]=
CGS;
389 solvertype_to_enum[
"CR" ]=
CR;
390 solvertype_to_enum[
"QMR" ]=
QMR;
391 solvertype_to_enum[
"TCQMR" ]=
TCQMR;
392 solvertype_to_enum[
"TFQMR" ]=
TFQMR;
393 solvertype_to_enum[
"BICG" ]=
BICG;
394 solvertype_to_enum[
"MINRES" ]=
MINRES;
395 solvertype_to_enum[
"GMRES" ]=
GMRES;
396 solvertype_to_enum[
"LSQR" ]=
LSQR;
397 solvertype_to_enum[
"JACOBI" ]=
JACOBI;
400 solvertype_to_enum[
"SSOR" ]=
SSOR;
402 solvertype_to_enum[
"CHEBYSHEV" ]=
CHEBYSHEV;
411 void init_elemquality_to_enum ()
413 if (elemquality_to_enum.empty())
416 elemquality_to_enum[
"SKEW" ]=
SKEW;
417 elemquality_to_enum[
"SHEAR" ]=
SHEAR;
418 elemquality_to_enum[
"SHAPE" ]=
SHAPE;
419 elemquality_to_enum[
"MAX_ANGLE" ]=
MAX_ANGLE;
420 elemquality_to_enum[
"MIN_ANGLE" ]=
MIN_ANGLE;
421 elemquality_to_enum[
"CONDITION" ]=
CONDITION;
422 elemquality_to_enum[
"DISTORTION" ]=
DISTORTION;
423 elemquality_to_enum[
"TAPER" ]=
TAPER;
424 elemquality_to_enum[
"WARP" ]=
WARP;
425 elemquality_to_enum[
"STRETCH" ]=
STRETCH;
426 elemquality_to_enum[
"DIAGONAL" ]=
DIAGONAL;
429 elemquality_to_enum[
"SIZE" ]=
SIZE;
430 elemquality_to_enum[
"JACOBIAN" ]=
JACOBIAN;
435 INSTANTIATE_ENUM_MAPS(
IOPackage, iopackage)
438 void init_iopackage_to_enum ()
440 if (iopackage_to_enum.empty())
442 iopackage_to_enum[
"TECPLOT" ]=
TECPLOT;
443 iopackage_to_enum[
"GMV" ]=
GMV;
444 iopackage_to_enum[
"GMSH" ]=
GMSH;
445 iopackage_to_enum[
"VTK" ]=
VTK;
446 iopackage_to_enum[
"DIVA" ]=
DIVA;
447 iopackage_to_enum[
"TETGEN" ]=
TETGEN;
448 iopackage_to_enum[
"UCD" ]=
UCD;
449 iopackage_to_enum[
"LIBMESH" ]=
LIBMESH;
457 void init_norm_type_to_enum ()
459 if (norm_type_to_enum.empty())
461 norm_type_to_enum[
"L2" ]=
L2;
462 norm_type_to_enum[
"H1" ]=
H1;
463 norm_type_to_enum[
"H2" ]=
H2;
464 norm_type_to_enum[
"HCURL" ]=
HCURL;
465 norm_type_to_enum[
"HDIV" ]=
HDIV;
467 norm_type_to_enum[
"L1" ]=
L1;
468 norm_type_to_enum[
"L_INF" ]=
L_INF;
494 void init_parallel_type_to_enum ()
496 if (parallel_type_to_enum.empty())
498 parallel_type_to_enum[
"AUTOMATIC" ]=
AUTOMATIC;
499 parallel_type_to_enum[
"SERIAL" ]=
SERIAL;
500 parallel_type_to_enum[
"PARALLEL" ]=
PARALLEL;
501 parallel_type_to_enum[
"GHOSTED" ]=
GHOSTED;
510 void init_point_locator_type_to_enum ()
512 if (point_locator_type_to_enum.empty())
514 point_locator_type_to_enum[
"TREE" ]=
TREE;
523 void init_solverpackage_type_to_enum ()
525 if (solverpackage_type_to_enum.empty())
541 void init_subset_solve_mode_to_enum ()
543 if (subset_solve_mode_to_enum.empty())
545 subset_solve_mode_to_enum[
"SUBSET_ZERO" ]=
SUBSET_ZERO;
552 INSTANTIATE_ENUM_MAPS(
XdrMODE, xdr_mode)
555 void init_xdr_mode_to_enum ()
557 if (xdr_mode_to_enum.empty())
559 xdr_mode_to_enum[
"UNKNOWN" ]=
UNKNOWN;
560 xdr_mode_to_enum[
"ENCODE" ]=
ENCODE;
561 xdr_mode_to_enum[
"DECODE" ]=
DECODE;
562 xdr_mode_to_enum[
"WRITE" ]=
WRITE;
563 xdr_mode_to_enum[
"READ" ]=
READ;
571 void init_linear_convergence_reason_to_enum ()
573 if (linear_convergence_reason_to_enum.empty())
577 linear_convergence_reason_to_enum[
"CONVERGED_RTOL"] =
CONVERGED_RTOL;
578 linear_convergence_reason_to_enum[
"CONVERGED_ATOL"] =
CONVERGED_ATOL;
579 linear_convergence_reason_to_enum[
"CONVERGED_ITS"] =
CONVERGED_ITS;
584 linear_convergence_reason_to_enum[
"DIVERGED_NULL"] =
DIVERGED_NULL;
585 linear_convergence_reason_to_enum[
"DIVERGED_ITS"] =
DIVERGED_ITS;
586 linear_convergence_reason_to_enum[
"DIVERGED_DTOL"] =
DIVERGED_DTOL;
591 linear_convergence_reason_to_enum[
"DIVERGED_NAN"] =
DIVERGED_NAN;
595 linear_convergence_reason_to_enum[
"UNKNOWN_FLAG"] =
UNKNOWN_FLAG;
600 #undef INSTANTIATE_ENUM_MAPS
611 #define INSTANTIATE_STRING_TO_ENUM(ENUM_NAME,VAR_NAME) \
613 ENUM_NAME string_to_enum<ENUM_NAME> (const std::string & s) \
615 init_##VAR_NAME##_to_enum(); \
617 std::string upper(s); \
618 std::transform(upper.begin(), upper.end(), upper.begin(), ::toupper); \
620 if (!VAR_NAME##_to_enum.count(upper)) \
622 libmesh_error_msg("No " #ENUM_NAME " named " + s + " found."); \
625 return VAR_NAME##_to_enum[upper]; \
629 std::string enum_to_string<ENUM_NAME> (const ENUM_NAME e) \
631 init_enum_to_##VAR_NAME (); \
633 if (!enum_to_##VAR_NAME .count(e)) \
634 libmesh_error_msg("No " #ENUM_NAME " with enumeration " << e << " found."); \
636 return enum_to_##VAR_NAME [e]; \
640 INSTANTIATE_STRING_TO_ENUM(
ElemType,elem_type)
641 INSTANTIATE_STRING_TO_ENUM(
Order,order)
642 INSTANTIATE_STRING_TO_ENUM(
FEFamily,fefamily)
643 INSTANTIATE_STRING_TO_ENUM(
InfMapType,inf_map_type)
647 #ifdef LIBMESH_ENABLE_AMR
649 #endif // LIBMESH_ENABLE_AMR
651 INSTANTIATE_STRING_TO_ENUM(
SolverType,solvertype)
653 INSTANTIATE_STRING_TO_ENUM(
ElemQuality,elemquality)
654 INSTANTIATE_STRING_TO_ENUM(
IOPackage,iopackage)
660 INSTANTIATE_STRING_TO_ENUM(
XdrMODE,xdr_mode)
663 #undef INSTANTIATE_STRING_TO_ENUM