string_to_enum.C
Go to the documentation of this file.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2018 Benjamin S. Kirk, John W. Peterson, Roy H. Stogner
3 
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License, or (at your option) any later version.
8 
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // Lesser General Public License for more details.
13 
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 
18 
19 
20 // C++ includes
21 #include <algorithm>
22 #include <map>
23 
24 // Local includes
25 #include "libmesh/libmesh_common.h"
26 #include "libmesh/string_to_enum.h"
29 #include "libmesh/enum_elem_type.h"
31 #include "libmesh/enum_fe_family.h"
34 #include "libmesh/enum_norm_type.h"
35 #include "libmesh/enum_order.h"
43 #include "libmesh/enum_xdr_mode.h"
44 #include "libmesh/elem.h"
45 
46 namespace libMesh
47 {
48 
49 // ------------------------------------------------------------
50 // Anonymous namespace to hold local data & methods
51 namespace {
52 
53 
54 // Reverse a map
55 template <typename MapIter, class MapType>
56 inline
57 void build_reverse_map (MapIter it, MapIter end, MapType & reverse)
58 {
59  reverse.clear();
60 
61  for (; it != end; ++it)
62  {
63  // If the forward map is not invertible, we might already have
64  // found a preimage of it->second. Choose the "largest"
65  // preimage according to operator<; for std::string this will
66  // give us the longest, hopefully most specific name
67  // corresponding to an enum.
68  typename MapType::iterator preimage = reverse.find(it->second);
69  if (preimage == reverse.end())
70  reverse.insert (std::make_pair(it->second, it->first));
71  else if (preimage->second < it->first)
72  preimage->second = it->first;
73  }
74 }
75 
76 #define INSTANTIATE_ENUM_MAPS(ENUM_NAME,VAR_NAME) \
77  std::map<std::string, ENUM_NAME> VAR_NAME##_to_enum; \
78  \
79  std::map<ENUM_NAME, std::string> enum_to_##VAR_NAME; \
80  \
81  void init_##VAR_NAME##_to_enum (); \
82  \
83  /* Initialize the enum_to_elem_type on first call */ \
84  void init_enum_to_##VAR_NAME () \
85  { \
86  /* Build reverse map */ \
87  if (enum_to_##VAR_NAME .empty()) \
88  { \
89  /* Initialize elem_type_to_enum on first call */ \
90  init_##VAR_NAME##_to_enum(); \
91  \
92  build_reverse_map (VAR_NAME##_to_enum.begin(), \
93  VAR_NAME##_to_enum.end(), \
94  enum_to_##VAR_NAME); \
95  } \
96  }
97 
98 INSTANTIATE_ENUM_MAPS(ElemType, elem_type)
99 
100 //----------------------------------------------------
101 
102 // Initialize elem_type_to_enum on first call
103 void init_elem_type_to_enum ()
104 {
105  if (elem_type_to_enum.empty())
106  {
107  elem_type_to_enum["EDGE" ]=EDGE2;
108  elem_type_to_enum["EDGE2" ]=EDGE2;
109  elem_type_to_enum["EDGE3" ]=EDGE3;
110  elem_type_to_enum["EDGE4" ]=EDGE4;
111 
112  elem_type_to_enum["TRI" ]=TRI3;
113  elem_type_to_enum["TRI3" ]=TRI3;
114  elem_type_to_enum["TRISHELL3" ]=TRISHELL3;
115  elem_type_to_enum["TRI3SUBDIVISION"]=TRI3SUBDIVISION;
116  elem_type_to_enum["TRI6" ]=TRI6;
117 
118  elem_type_to_enum["QUAD" ]=QUAD4;
119  elem_type_to_enum["QUAD4" ]=QUAD4;
120  elem_type_to_enum["QUADSHELL4" ]=QUADSHELL4;
121  elem_type_to_enum["QUAD8" ]=QUAD8;
122  elem_type_to_enum["QUADSHELL8" ]=QUADSHELL8;
123  elem_type_to_enum["QUAD9" ]=QUAD9;
124 
125  elem_type_to_enum["TET" ]=TET4;
126  elem_type_to_enum["TET4" ]=TET4;
127  elem_type_to_enum["TET10" ]=TET10;
128 
129  elem_type_to_enum["HEX" ]=HEX8;
130  elem_type_to_enum["HEX8" ]=HEX8;
131  elem_type_to_enum["HEX20" ]=HEX20;
132  elem_type_to_enum["HEX27" ]=HEX27;
133 
134  elem_type_to_enum["PRISM" ]=PRISM6;
135  elem_type_to_enum["PRISM6" ]=PRISM6;
136  elem_type_to_enum["PRISM15" ]=PRISM15;
137  elem_type_to_enum["PRISM18" ]=PRISM18;
138 
139  elem_type_to_enum["PYRAMID" ]=PYRAMID5;
140  elem_type_to_enum["PYRAMID5" ]=PYRAMID5;
141  elem_type_to_enum["PYRAMID13" ]=PYRAMID13;
142  elem_type_to_enum["PYRAMID14" ]=PYRAMID14;
143 
144  elem_type_to_enum["INFEDGE" ]=INFEDGE2;
145  elem_type_to_enum["INFEDGE2" ]=INFEDGE2;
146 
147  elem_type_to_enum["INFQUAD" ]=INFQUAD4;
148  elem_type_to_enum["INFQUAD4" ]=INFQUAD4;
149  elem_type_to_enum["INFQUAD6" ]=INFQUAD6;
150 
151  elem_type_to_enum["INFHEX" ]=INFHEX8;
152  elem_type_to_enum["INFHEX8" ]=INFHEX8;
153  elem_type_to_enum["INFHEX16" ]=INFHEX16;
154  elem_type_to_enum["INFHEX18" ]=INFHEX18;
155 
156  elem_type_to_enum["INFPRISM" ]=INFPRISM6;
157  elem_type_to_enum["INFPRISM6" ]=INFPRISM6;
158  elem_type_to_enum["INFPRISM12" ]=INFPRISM12;
159 
160  elem_type_to_enum["NODE" ]=NODEELEM;
161  elem_type_to_enum["NODEELEM" ]=NODEELEM;
162 
163  elem_type_to_enum["INVALID_ELEM" ]=INVALID_ELEM;
164  }
165 }
166 
167 
168 INSTANTIATE_ENUM_MAPS(Order, order)
169 
170 // Initialize order_to_enum on first call
171 void init_order_to_enum ()
172 {
173  if (order_to_enum.empty())
174  {
175  order_to_enum["CONSTANT" ]=CONSTANT;
176  order_to_enum["FIRST" ]=FIRST;
177  order_to_enum["SECOND" ]=SECOND;
178  order_to_enum["THIRD" ]=THIRD;
179  order_to_enum["FOURTH" ]=FOURTH;
180  order_to_enum["FIFTH" ]=FIFTH;
181  order_to_enum["SIXTH" ]=SIXTH;
182  order_to_enum["SEVENTH" ]=SEVENTH;
183  order_to_enum["EIGHTH" ]=EIGHTH;
184  order_to_enum["NINTH" ]=NINTH;
185  order_to_enum["TENTH" ]=TENTH;
186 
187  order_to_enum["ELEVENTH" ]=ELEVENTH;
188  order_to_enum["TWELFTH" ]=TWELFTH;
189  order_to_enum["THIRTEENTH" ]=THIRTEENTH;
190  order_to_enum["FOURTEENTH" ]=FOURTEENTH;
191  order_to_enum["FIFTEENTH" ]=FIFTEENTH;
192  order_to_enum["SIXTEENTH" ]=SIXTEENTH;
193  order_to_enum["SEVENTEENTH" ]=SEVENTEENTH;
194  order_to_enum["EIGHTTEENTH" ]=EIGHTTEENTH;
195  order_to_enum["NINETEENTH" ]=NINETEENTH;
196  order_to_enum["TWENTIETH" ]=TWENTIETH;
197 
198  order_to_enum["TWENTYFIRST" ]=TWENTYFIRST;
199  order_to_enum["TWENTYSECOND" ]=TWENTYSECOND;
200  order_to_enum["TWENTYTHIRD" ]=TWENTYTHIRD;
201  order_to_enum["TWENTYFOURTH" ]=TWENTYFOURTH;
202  order_to_enum["TWENTYFIFTH" ]=TWENTYFIFTH;
203  order_to_enum["TWENTYSIXTH" ]=TWENTYSIXTH;
204  order_to_enum["TWENTYSEVENTH"]=TWENTYSEVENTH;
205  order_to_enum["TWENTYEIGHTH" ]=TWENTYEIGHTH;
206  order_to_enum["TWENTYNINTH" ]=TWENTYNINTH;
207  order_to_enum["THIRTIETH" ]=THIRTIETH;
208 
209  order_to_enum["THIRTYFIRST" ]=THIRTYFIRST;
210  order_to_enum["THIRTYSECOND" ]=THIRTYSECOND;
211  order_to_enum["THIRTYTHIRD" ]=THIRTYTHIRD;
212  order_to_enum["THIRTYFOURTH" ]=THIRTYFOURTH;
213  order_to_enum["THIRTYFIFTH" ]=THIRTYFIFTH;
214  order_to_enum["THIRTYSIXTH" ]=THIRTYSIXTH;
215  order_to_enum["THIRTYSEVENTH"]=THIRTYSEVENTH;
216  order_to_enum["THIRTYEIGHTH" ]=THIRTYEIGHTH;
217  order_to_enum["THIRTYNINTH" ]=THIRTYNINTH;
218  order_to_enum["FORTIETH" ]=FORTIETH;
219 
220  order_to_enum["FORTYFIRST" ]=FORTYFIRST;
221  order_to_enum["FORTYSECOND" ]=FORTYSECOND;
222  order_to_enum["FORTYTHIRD" ]=FORTYTHIRD;
223  }
224 }
225 
226 
227 
228 INSTANTIATE_ENUM_MAPS(FEFamily, fefamily)
229 
230 // Initialize fefamily_to_enum on first call
231 void init_fefamily_to_enum ()
232 {
233  if (fefamily_to_enum.empty())
234  {
235  fefamily_to_enum["LAGRANGE" ]=LAGRANGE;
236  fefamily_to_enum["LAGRANGE_VEC" ]=LAGRANGE_VEC;
237  fefamily_to_enum["L2_LAGRANGE" ]=L2_LAGRANGE;
238  fefamily_to_enum["HIERARCHIC" ]=HIERARCHIC;
239  fefamily_to_enum["L2_HIERARCHIC"]=L2_HIERARCHIC;
240  fefamily_to_enum["MONOMIAL" ]=MONOMIAL;
241  fefamily_to_enum["SCALAR" ]=SCALAR;
242  fefamily_to_enum["XYZ" ]=XYZ;
243  fefamily_to_enum["BERNSTEIN" ]=BERNSTEIN;
244  fefamily_to_enum["SZABAB" ]=SZABAB;
245  fefamily_to_enum["INFINITE_MAP" ]=INFINITE_MAP;
246  fefamily_to_enum["JACOBI_20_00" ]=JACOBI_20_00;
247  fefamily_to_enum["JACOBI_30_00" ]=JACOBI_30_00;
248  fefamily_to_enum["LEGENDRE" ]=LEGENDRE;
249  fefamily_to_enum["CLOUGH" ]=CLOUGH;
250  fefamily_to_enum["HERMITE" ]=HERMITE;
251  fefamily_to_enum["SUBDIVISION" ]=SUBDIVISION;
252  fefamily_to_enum["NEDELEC_ONE" ]=NEDELEC_ONE;
253  }
254 
255 }
256 
257 
258 
259 INSTANTIATE_ENUM_MAPS(InfMapType, inf_map_type)
260 
261 // Initialize inf_map_type_to_enum on first call
262 void init_inf_map_type_to_enum ()
263 {
264  if (inf_map_type_to_enum.empty())
265  {
266  inf_map_type_to_enum["CARTESIAN" ]=CARTESIAN;
267  inf_map_type_to_enum["SPHERICAL" ]=SPHERICAL;
268  inf_map_type_to_enum["ELLIPSOIDAL"]=ELLIPSOIDAL;
269  }
270 }
271 
272 
273 INSTANTIATE_ENUM_MAPS(QuadratureType, quadrature_type)
274 
275 // Initialize quadrature_type_to_enum on first call
276 void init_quadrature_type_to_enum ()
277 {
278  if (quadrature_type_to_enum.empty())
279  {
280  quadrature_type_to_enum["QGAUSS" ]=QGAUSS;
281  quadrature_type_to_enum["QJACOBI_1_0"]=QJACOBI_1_0;
282  quadrature_type_to_enum["QJACOBI_2_0"]=QJACOBI_2_0;
283  quadrature_type_to_enum["QSIMPSON" ]=QSIMPSON;
284  quadrature_type_to_enum["QTRAP" ]=QTRAP;
285  quadrature_type_to_enum["QGRID" ]=QGRID;
286  quadrature_type_to_enum["QCLOUGH" ]=QCLOUGH;
287  quadrature_type_to_enum["QGAUSS_LOBATTO" ]=QGAUSS_LOBATTO;
288  }
289 }
290 
291 
292 INSTANTIATE_ENUM_MAPS(PreconditionerType, preconditioner_type)
293 
294 // Initialize preconditioner_type_to_enum on first call
295 void init_preconditioner_type_to_enum ()
296 {
297  if (preconditioner_type_to_enum.empty())
298  {
299  preconditioner_type_to_enum["IDENTITY_PRECOND" ]=IDENTITY_PRECOND;
300  preconditioner_type_to_enum["JACOBI_PRECOND" ]=JACOBI_PRECOND;
301  preconditioner_type_to_enum["BLOCK_JACOBI_PRECOND" ]=BLOCK_JACOBI_PRECOND;
302  preconditioner_type_to_enum["SOR_PRECOND" ]=SOR_PRECOND;
303  preconditioner_type_to_enum["SSOR_PRECOND" ]=SSOR_PRECOND;
304  preconditioner_type_to_enum["EISENSTAT_PRECOND" ]=EISENSTAT_PRECOND;
305  preconditioner_type_to_enum["ASM_PRECOND" ]=ASM_PRECOND;
306  preconditioner_type_to_enum["CHOLESKY_PRECOND" ]=CHOLESKY_PRECOND;
307  preconditioner_type_to_enum["ICC_PRECOND" ]=ICC_PRECOND;
308  preconditioner_type_to_enum["ILU_PRECOND" ]=ILU_PRECOND;
309  preconditioner_type_to_enum["LU_PRECOND" ]=LU_PRECOND;
310  preconditioner_type_to_enum["USER_PRECOND" ]=USER_PRECOND;
311  preconditioner_type_to_enum["SHELL_PRECOND" ]=SHELL_PRECOND;
312  preconditioner_type_to_enum["AMG_PRECOND" ]=AMG_PRECOND;
313  preconditioner_type_to_enum["INVALID_PRECONDITIONER"]=INVALID_PRECONDITIONER;
314 
315  //shorter
316  preconditioner_type_to_enum["IDENTITY" ]=IDENTITY_PRECOND;
317  preconditioner_type_to_enum["JACOBI" ]=JACOBI_PRECOND;
318  preconditioner_type_to_enum["BLOCK_JACOBI"]=BLOCK_JACOBI_PRECOND;
319  preconditioner_type_to_enum["SOR" ]=SOR_PRECOND;
320  preconditioner_type_to_enum["SSOR" ]=SSOR_PRECOND;
321  preconditioner_type_to_enum["EISENSTAT" ]=EISENSTAT_PRECOND;
322  preconditioner_type_to_enum["ASM" ]=ASM_PRECOND;
323  preconditioner_type_to_enum["CHOLESKY" ]=CHOLESKY_PRECOND;
324  preconditioner_type_to_enum["ICC" ]=ICC_PRECOND;
325  preconditioner_type_to_enum["ILU" ]=ILU_PRECOND;
326  preconditioner_type_to_enum["LU" ]=LU_PRECOND;
327  preconditioner_type_to_enum["USER" ]=USER_PRECOND;
328  preconditioner_type_to_enum["SHELL" ]=SHELL_PRECOND;
329  preconditioner_type_to_enum["AMG" ]=AMG_PRECOND;
330  preconditioner_type_to_enum["INVALID" ]=INVALID_PRECONDITIONER;
331  }
332 }
333 
334 
335 #ifdef LIBMESH_ENABLE_AMR
336 
337 INSTANTIATE_ENUM_MAPS(Elem::RefinementState, refinementstate_type)
338 
339 // Initialize refinementstate_type_to_enum on first call
340 void init_refinementstate_type_to_enum ()
341 {
342  if (refinementstate_type_to_enum.empty())
343  {
344  refinementstate_type_to_enum["COARSEN" ]=Elem::COARSEN;
345  refinementstate_type_to_enum["DO_NOTHING" ]=Elem::DO_NOTHING;
346  refinementstate_type_to_enum["REFINE" ]=Elem::REFINE;
347  refinementstate_type_to_enum["JUST_REFINED" ]=Elem::JUST_REFINED;
348  refinementstate_type_to_enum["JUST_COARSENED" ]=Elem::JUST_COARSENED;
349  refinementstate_type_to_enum["INACTIVE" ]=Elem::INACTIVE;
350  refinementstate_type_to_enum["COARSEN_INACTIVE" ]=Elem::COARSEN_INACTIVE;
351  refinementstate_type_to_enum["INVALID_REFINEMENTSTATE"]=Elem::INVALID_REFINEMENTSTATE;
352  }
353 }
354 #endif // LIBMESH_ENABLE_AMR
355 
356 
357 INSTANTIATE_ENUM_MAPS(EigenSolverType, eigensolvertype)
358 
359 // Initialize eigensolvertype_to_enum on first call
360 void init_eigensolvertype_to_enum ()
361 {
362  if (eigensolvertype_to_enum.empty())
363  {
364  eigensolvertype_to_enum["POWER" ]=POWER;
365  eigensolvertype_to_enum["LAPACK" ]=LAPACK;
366  eigensolvertype_to_enum["SUBSPACE" ]=SUBSPACE;
367  eigensolvertype_to_enum["ARNOLDI" ]=ARNOLDI;
368  eigensolvertype_to_enum["LANCZOS" ]=LANCZOS;
369  eigensolvertype_to_enum["KRYLOVSCHUR" ]=KRYLOVSCHUR;
370  eigensolvertype_to_enum["INVALID_EIGENSOLVER"]=INVALID_EIGENSOLVER;
371  }
372 }
373 
374 
375 INSTANTIATE_ENUM_MAPS(SolverType, solvertype)
376 
377 // Initialize solvertype_to_enum on first call
378 void init_solvertype_to_enum ()
379 {
380  if (solvertype_to_enum.empty())
381  {
382  solvertype_to_enum["CG" ]=CG;
383  solvertype_to_enum["CGN" ]=CGN;
384  solvertype_to_enum["CGS" ]=CGS;
385  solvertype_to_enum["CR" ]=CR;
386  solvertype_to_enum["QMR" ]=QMR;
387  solvertype_to_enum["TCQMR" ]=TCQMR;
388  solvertype_to_enum["TFQMR" ]=TFQMR;
389  solvertype_to_enum["BICG" ]=BICG;
390  solvertype_to_enum["MINRES" ]=MINRES;
391  solvertype_to_enum["GMRES" ]=GMRES;
392  solvertype_to_enum["LSQR" ]=LSQR;
393  solvertype_to_enum["JACOBI" ]=JACOBI;
394  solvertype_to_enum["SOR_FORWARD" ]=SOR_FORWARD;
395  solvertype_to_enum["SOR_BACKWARD" ]=SOR_BACKWARD;
396  solvertype_to_enum["SSOR" ]=SSOR;
397  solvertype_to_enum["RICHARDSON" ]=RICHARDSON;
398  solvertype_to_enum["CHEBYSHEV" ]=CHEBYSHEV;
399  solvertype_to_enum["INVALID_SOLVER"]=INVALID_SOLVER;
400  }
401 }
402 
403 
404 INSTANTIATE_ENUM_MAPS(ElemQuality, elemquality)
405 
406 // Initialize elemquality_to_enum on first call
407 void init_elemquality_to_enum ()
408 {
409  if (elemquality_to_enum.empty())
410  {
411  elemquality_to_enum["ASPECT_RATIO" ]=ASPECT_RATIO;
412  elemquality_to_enum["SKEW" ]=SKEW;
413  elemquality_to_enum["SHEAR" ]=SHEAR;
414  elemquality_to_enum["SHAPE" ]=SHAPE;
415  elemquality_to_enum["MAX_ANGLE" ]=MAX_ANGLE;
416  elemquality_to_enum["MIN_ANGLE" ]=MIN_ANGLE;
417  elemquality_to_enum["CONDITION" ]=CONDITION;
418  elemquality_to_enum["DISTORTION" ]=DISTORTION;
419  elemquality_to_enum["TAPER" ]=TAPER;
420  elemquality_to_enum["WARP" ]=WARP;
421  elemquality_to_enum["STRETCH" ]=STRETCH;
422  elemquality_to_enum["DIAGONAL" ]=DIAGONAL;
423  elemquality_to_enum["ASPECT_RATIO_BETA" ]=ASPECT_RATIO_BETA;
424  elemquality_to_enum["ASPECT_RATIO_GAMMA" ]=ASPECT_RATIO_GAMMA;
425  elemquality_to_enum["SIZE" ]=SIZE;
426  elemquality_to_enum["JACOBIAN" ]=JACOBIAN;
427  }
428 }
429 
430 
431 INSTANTIATE_ENUM_MAPS(IOPackage, iopackage)
432 
433 // Initialize iopackage_to_enum on first call
434 void init_iopackage_to_enum ()
435 {
436  if (iopackage_to_enum.empty())
437  {
438  iopackage_to_enum["TECPLOT" ]=TECPLOT;
439  iopackage_to_enum["GMV" ]=GMV;
440  iopackage_to_enum["GMSH" ]=GMSH;
441  iopackage_to_enum["VTK" ]=VTK;
442  iopackage_to_enum["DIVA" ]=DIVA;
443  iopackage_to_enum["TETGEN" ]=TETGEN;
444  iopackage_to_enum["UCD" ]=UCD;
445  iopackage_to_enum["LIBMESH" ]=LIBMESH;
446  }
447 }
448 
449 
450 INSTANTIATE_ENUM_MAPS(FEMNormType, norm_type)
451 
452 // Initialize norm_type_to_enum on first call
453 void init_norm_type_to_enum ()
454 {
455  if (norm_type_to_enum.empty())
456  {
457  norm_type_to_enum["L2" ]=L2;
458  norm_type_to_enum["H1" ]=H1;
459  norm_type_to_enum["H2" ]=H2;
460  norm_type_to_enum["HCURL" ]=HCURL;
461  norm_type_to_enum["HDIV" ]=HDIV;
462 
463  norm_type_to_enum["L1" ]=L1;
464  norm_type_to_enum["L_INF" ]=L_INF;
465 
466  norm_type_to_enum["H1_SEMINORM" ]=H1_SEMINORM;
467  norm_type_to_enum["H2_SEMINORM" ]=H2_SEMINORM;
468  norm_type_to_enum["HCURL_SEMINORM" ]=HCURL_SEMINORM;
469  norm_type_to_enum["HDIV_SEMINORM" ]=HDIV_SEMINORM;
470 
471  norm_type_to_enum["W1_INF_SEMINORM" ]=W1_INF_SEMINORM;
472  norm_type_to_enum["W2_INF_SEMINORM" ]=W2_INF_SEMINORM;
473 
474  norm_type_to_enum["DISCRETE_L1" ]=DISCRETE_L1;
475  norm_type_to_enum["DISCRETE_L2" ]=DISCRETE_L2;
476  norm_type_to_enum["DISCRETE_L_INF" ]=DISCRETE_L_INF;
477 
478  norm_type_to_enum["H1_X_SEMINORM" ]=H1_X_SEMINORM;
479  norm_type_to_enum["H1_Y_SEMINORM" ]=H1_Y_SEMINORM;
480  norm_type_to_enum["H1_Z_SEMINORM" ]=H1_Z_SEMINORM;
481 
482  norm_type_to_enum["INVALID_NORM" ]=INVALID_NORM;
483  }
484 }
485 
486 
487 INSTANTIATE_ENUM_MAPS(ParallelType, parallel_type)
488 
489 // Initialize parallel_type_to_enum on first call
490 void init_parallel_type_to_enum ()
491 {
492  if (parallel_type_to_enum.empty())
493  {
494  parallel_type_to_enum["AUTOMATIC" ]=AUTOMATIC;
495  parallel_type_to_enum["SERIAL" ]=SERIAL;
496  parallel_type_to_enum["PARALLEL" ]=PARALLEL;
497  parallel_type_to_enum["GHOSTED" ]=GHOSTED;
498  parallel_type_to_enum["INVALID_PARALLELIZATION" ]=INVALID_PARALLELIZATION;
499  }
500 }
501 
502 
503 INSTANTIATE_ENUM_MAPS(PointLocatorType, point_locator_type)
504 
505 // Initialize point_locator_type_to_enum on first call
506 void init_point_locator_type_to_enum ()
507 {
508  if (point_locator_type_to_enum.empty())
509  {
510  point_locator_type_to_enum["TREE" ]=TREE;
511  point_locator_type_to_enum["INVALID_LOCATOR" ]=INVALID_LOCATOR;
512  }
513 }
514 
515 
516 INSTANTIATE_ENUM_MAPS(SolverPackage, solverpackage_type)
517 
518 // Initialize solverpackage_type_to_enum on first call
519 void init_solverpackage_type_to_enum ()
520 {
521  if (solverpackage_type_to_enum.empty())
522  {
523  solverpackage_type_to_enum["PETSC_SOLVERS" ]=PETSC_SOLVERS;
524  solverpackage_type_to_enum["TRILINOS_SOLVERS" ]=TRILINOS_SOLVERS;
525  solverpackage_type_to_enum["LASPACK_SOLVERS" ]=LASPACK_SOLVERS;
526  solverpackage_type_to_enum["SLEPC_SOLVERS" ]=SLEPC_SOLVERS;
527  solverpackage_type_to_enum["EIGEN_SOLVERS" ]=EIGEN_SOLVERS;
528  solverpackage_type_to_enum["NLOPT_SOLVERS" ]=NLOPT_SOLVERS;
529  solverpackage_type_to_enum["INVALID_SOLVER_PACKAGE" ]=INVALID_SOLVER_PACKAGE;
530  }
531 }
532 
533 
534 INSTANTIATE_ENUM_MAPS(SubsetSolveMode, subset_solve_mode)
535 
536 // Initialize subset_solve_mode_to_enum on first call
537 void init_subset_solve_mode_to_enum ()
538 {
539  if (subset_solve_mode_to_enum.empty())
540  {
541  subset_solve_mode_to_enum["SUBSET_ZERO" ]=SUBSET_ZERO;
542  subset_solve_mode_to_enum["SUBSET_COPY_RHS" ]=SUBSET_COPY_RHS;
543  subset_solve_mode_to_enum["SUBSET_DONT_TOUCH" ]=SUBSET_DONT_TOUCH;
544  }
545 }
546 
547 
548 INSTANTIATE_ENUM_MAPS(XdrMODE, xdr_mode)
549 
550 // Initialize xdr_mode_to_enum on first call
551 void init_xdr_mode_to_enum ()
552 {
553  if (xdr_mode_to_enum.empty())
554  {
555  xdr_mode_to_enum["UNKNOWN" ]=UNKNOWN;
556  xdr_mode_to_enum["ENCODE" ]=ENCODE;
557  xdr_mode_to_enum["DECODE" ]=DECODE;
558  xdr_mode_to_enum["WRITE" ]=WRITE;
559  xdr_mode_to_enum["READ" ]=READ;
560  }
561 }
562 
563 
564 INSTANTIATE_ENUM_MAPS(LinearConvergenceReason, linear_convergence_reason)
565 
566 // Initialize xdr_mode_to_enum on first call
567 void init_linear_convergence_reason_to_enum ()
568 {
569  if (linear_convergence_reason_to_enum.empty())
570  {
571  linear_convergence_reason_to_enum["CONVERGED_RTOL_NORMAL"] = CONVERGED_RTOL_NORMAL;
572  linear_convergence_reason_to_enum["CONVERGED_ATOL_NORMAL"] = CONVERGED_ATOL_NORMAL;
573  linear_convergence_reason_to_enum["CONVERGED_RTOL"] = CONVERGED_RTOL;
574  linear_convergence_reason_to_enum["CONVERGED_ATOL"] = CONVERGED_ATOL;
575  linear_convergence_reason_to_enum["CONVERGED_ITS"] = CONVERGED_ITS;
576  linear_convergence_reason_to_enum["CONVERGED_CG_NEG_CURVE"] = CONVERGED_CG_NEG_CURVE;
577  linear_convergence_reason_to_enum["CONVERGED_CG_CONSTRAINED"] = CONVERGED_CG_CONSTRAINED;
578  linear_convergence_reason_to_enum["CONVERGED_STEP_LENGTH"] = CONVERGED_STEP_LENGTH;
579  linear_convergence_reason_to_enum["CONVERGED_HAPPY_BREAKDOWN"] = CONVERGED_HAPPY_BREAKDOWN;
580  linear_convergence_reason_to_enum["DIVERGED_NULL"] = DIVERGED_NULL;
581  linear_convergence_reason_to_enum["DIVERGED_ITS"] = DIVERGED_ITS;
582  linear_convergence_reason_to_enum["DIVERGED_DTOL"] = DIVERGED_DTOL;
583  linear_convergence_reason_to_enum["DIVERGED_BREAKDOWN"] = DIVERGED_BREAKDOWN;
584  linear_convergence_reason_to_enum["DIVERGED_BREAKDOWN_BICG"] = DIVERGED_BREAKDOWN_BICG;
585  linear_convergence_reason_to_enum["DIVERGED_NONSYMMETRIC"] = DIVERGED_NONSYMMETRIC;
586  linear_convergence_reason_to_enum["DIVERGED_INDEFINITE_PC"] = DIVERGED_INDEFINITE_PC;
587  linear_convergence_reason_to_enum["DIVERGED_NAN"] = DIVERGED_NAN;
588  linear_convergence_reason_to_enum["DIVERGED_INDEFINITE_MAT"] = DIVERGED_INDEFINITE_MAT;
589  linear_convergence_reason_to_enum["DIVERGED_PCSETUP_FAILED"] = DIVERGED_PCSETUP_FAILED;
590  linear_convergence_reason_to_enum["CONVERGED_ITERATING"] = CONVERGED_ITERATING;
591  linear_convergence_reason_to_enum["UNKNOWN_FLAG"] = UNKNOWN_FLAG;
592  }
593 }
594 
595 
596 #undef INSTANTIATE_ENUM_MAPS
597 
598 } // end anonymous namespace
599 
600 
601 
602 // ------------------------------------------------------
603 // Utility::string_to_enum<> & Utility::enum_to_string<>
604 // full specializations
605 namespace Utility {
606 
607 #define INSTANTIATE_STRING_TO_ENUM(ENUM_NAME,VAR_NAME) \
608  template <> \
609  ENUM_NAME string_to_enum<ENUM_NAME> (const std::string & s) \
610  { \
611  init_##VAR_NAME##_to_enum(); \
612  \
613  std::string upper(s); \
614  std::transform(upper.begin(), upper.end(), upper.begin(), ::toupper); \
615  \
616  if (!VAR_NAME##_to_enum.count(upper)) \
617  { \
618  libmesh_error_msg("No " #ENUM_NAME " named " + s + " found."); \
619  } \
620  \
621  return VAR_NAME##_to_enum[upper]; \
622  } \
623  \
624  template <> \
625  std::string enum_to_string<ENUM_NAME> (const ENUM_NAME e) \
626  { \
627  init_enum_to_##VAR_NAME (); \
628  \
629  if (!enum_to_##VAR_NAME .count(e)) \
630  libmesh_error_msg("No " #ENUM_NAME " with enumeration " << e << " found."); \
631  \
632  return enum_to_##VAR_NAME [e]; \
633  }
634 
635 
636 INSTANTIATE_STRING_TO_ENUM(ElemType,elem_type)
637 INSTANTIATE_STRING_TO_ENUM(Order,order)
638 INSTANTIATE_STRING_TO_ENUM(FEFamily,fefamily)
639 INSTANTIATE_STRING_TO_ENUM(InfMapType,inf_map_type)
640 INSTANTIATE_STRING_TO_ENUM(QuadratureType,quadrature_type)
641 INSTANTIATE_STRING_TO_ENUM(PreconditionerType,preconditioner_type)
642 
643 #ifdef LIBMESH_ENABLE_AMR
644 INSTANTIATE_STRING_TO_ENUM(Elem::RefinementState,refinementstate_type)
645 #endif // LIBMESH_ENABLE_AMR
646 
647 INSTANTIATE_STRING_TO_ENUM(SolverType,solvertype)
648 INSTANTIATE_STRING_TO_ENUM(EigenSolverType,eigensolvertype)
649 INSTANTIATE_STRING_TO_ENUM(ElemQuality,elemquality)
650 INSTANTIATE_STRING_TO_ENUM(IOPackage,iopackage)
651 INSTANTIATE_STRING_TO_ENUM(FEMNormType, norm_type)
652 INSTANTIATE_STRING_TO_ENUM(ParallelType, parallel_type)
653 INSTANTIATE_STRING_TO_ENUM(PointLocatorType, point_locator_type)
654 INSTANTIATE_STRING_TO_ENUM(SolverPackage,solverpackage_type)
655 INSTANTIATE_STRING_TO_ENUM(SubsetSolveMode,subset_solve_mode)
656 INSTANTIATE_STRING_TO_ENUM(XdrMODE,xdr_mode)
657 INSTANTIATE_STRING_TO_ENUM(LinearConvergenceReason, linear_convergence_reason)
658 
659 #undef INSTANTIATE_STRING_TO_ENUM
660 
661 } // namespace Utility
662 
663 } // namespace libMesh
EIGEN_SOLVERS
Definition: libmesh.C:246
TRILINOS_SOLVERS
Definition: libmesh.C:244
IterBase * end
LASPACK_SOLVERS
Definition: libmesh.C:248
INVALID_SOLVER_PACKAGE
Definition: libmesh.C:250