string_to_enum.C
Go to the documentation of this file.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2014 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"
28 #include "libmesh/enum_elem_type.h"
30 #include "libmesh/enum_fe_family.h"
33 #include "libmesh/enum_norm_type.h"
34 #include "libmesh/enum_order.h"
42 #include "libmesh/enum_xdr_mode.h"
43 #include "libmesh/elem.h"
44 
45 namespace libMesh
46 {
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["TRI6" ]=TRI6;
115 
116  elem_type_to_enum["QUAD" ]=QUAD4;
117  elem_type_to_enum["QUAD4" ]=QUAD4;
118  elem_type_to_enum["QUAD8" ]=QUAD8;
119  elem_type_to_enum["QUAD9" ]=QUAD9;
120 
121  elem_type_to_enum["TET" ]=TET4;
122  elem_type_to_enum["TET4" ]=TET4;
123  elem_type_to_enum["TET10" ]=TET10;
124 
125  elem_type_to_enum["HEX" ]=HEX8;
126  elem_type_to_enum["HEX8" ]=HEX8;
127  elem_type_to_enum["HEX20" ]=HEX20;
128  elem_type_to_enum["HEX27" ]=HEX27;
129 
130  elem_type_to_enum["PRISM" ]=PRISM6;
131  elem_type_to_enum["PRISM6" ]=PRISM6;
132  elem_type_to_enum["PRISM15" ]=PRISM15;
133  elem_type_to_enum["PRISM18" ]=PRISM18;
134 
135  elem_type_to_enum["PYRAMID" ]=PYRAMID5;
136  elem_type_to_enum["PYRAMID5" ]=PYRAMID5;
137  elem_type_to_enum["PYRAMID14" ]=PYRAMID14;
138 
139  elem_type_to_enum["INFEDGE" ]=INFEDGE2;
140  elem_type_to_enum["INFEDGE2" ]=INFEDGE2;
141 
142  elem_type_to_enum["INFQUAD" ]=INFQUAD4;
143  elem_type_to_enum["INFQUAD4" ]=INFQUAD4;
144  elem_type_to_enum["INFQUAD6" ]=INFQUAD6;
145 
146  elem_type_to_enum["INFHEX" ]=INFHEX8;
147  elem_type_to_enum["INFHEX8" ]=INFHEX8;
148  elem_type_to_enum["INFHEX16" ]=INFHEX16;
149  elem_type_to_enum["INFHEX18" ]=INFHEX18;
150 
151  elem_type_to_enum["INFPRISM" ]=INFPRISM6;
152  elem_type_to_enum["INFPRISM6" ]=INFPRISM6;
153  elem_type_to_enum["INFPRISM12"]=INFPRISM12;
154 
155  elem_type_to_enum["NODE" ]=NODEELEM;
156  elem_type_to_enum["NODEELEM" ]=NODEELEM;
157  }
158  }
159 
160 
161 INSTANTIATE_ENUM_MAPS(Order, order)
162 
163  // Initialize order_to_enum on first call
164  void init_order_to_enum ()
165  {
166  if (order_to_enum.empty())
167  {
168  order_to_enum["CONSTANT" ]=CONSTANT;
169  order_to_enum["FIRST" ]=FIRST;
170  order_to_enum["SECOND" ]=SECOND;
171  order_to_enum["THIRD" ]=THIRD;
172  order_to_enum["FOURTH" ]=FOURTH;
173  order_to_enum["FIFTH" ]=FIFTH;
174  order_to_enum["SIXTH" ]=SIXTH;
175  order_to_enum["SEVENTH" ]=SEVENTH;
176  order_to_enum["EIGHTH" ]=EIGHTH;
177  order_to_enum["NINTH" ]=NINTH;
178  order_to_enum["TENTH" ]=TENTH;
179 
180  order_to_enum["ELEVENTH" ]=ELEVENTH;
181  order_to_enum["TWELFTH" ]=TWELFTH;
182  order_to_enum["THIRTEENTH" ]=THIRTEENTH;
183  order_to_enum["FOURTEENTH" ]=FOURTEENTH;
184  order_to_enum["FIFTEENTH" ]=FIFTEENTH;
185  order_to_enum["SIXTEENTH" ]=SIXTEENTH;
186  order_to_enum["SEVENTEENTH" ]=SEVENTEENTH;
187  order_to_enum["EIGHTTEENTH" ]=EIGHTTEENTH;
188  order_to_enum["NINTEENTH" ]=NINTEENTH;
189  order_to_enum["TWENTIETH" ]=TWENTIETH;
190 
191  order_to_enum["TWENTYFIRST" ]=TWENTYFIRST;
192  order_to_enum["TWENTYSECOND" ]=TWENTYSECOND;
193  order_to_enum["TWENTYTHIRD" ]=TWENTYTHIRD;
194  order_to_enum["TWENTYFOURTH" ]=TWENTYFOURTH;
195  order_to_enum["TWENTYFIFTH" ]=TWENTYFIFTH;
196  order_to_enum["TWENTYSIXTH" ]=TWENTYSIXTH;
197  order_to_enum["TWENTYSEVENTH"]=TWENTYSEVENTH;
198  order_to_enum["TWENTYEIGHTH" ]=TWENTYEIGHTH;
199  order_to_enum["TWENTYNINTH" ]=TWENTYNINTH;
200  order_to_enum["THIRTIETH" ]=THIRTIETH;
201 
202  order_to_enum["THIRTYFIRST" ]=THIRTYFIRST;
203  order_to_enum["THIRTYSECOND" ]=THIRTYSECOND;
204  order_to_enum["THIRTYTHIRD" ]=THIRTYTHIRD;
205  order_to_enum["THIRTYFOURTH" ]=THIRTYFOURTH;
206  order_to_enum["THIRTYFIFTH" ]=THIRTYFIFTH;
207  order_to_enum["THIRTYSIXTH" ]=THIRTYSIXTH;
208  order_to_enum["THIRTYSEVENTH"]=THIRTYSEVENTH;
209  order_to_enum["THIRTYEIGHTH" ]=THIRTYEIGHTH;
210  order_to_enum["THIRTYNINTH" ]=THIRTYNINTH;
211  order_to_enum["FORTIETH" ]=FORTIETH;
212 
213  order_to_enum["FORTYFIRST" ]=FORTYFIRST;
214  order_to_enum["FORTYSECOND" ]=FORTYSECOND;
215  order_to_enum["FORTYTHIRD" ]=FORTYTHIRD;
216  }
217  }
218 
219 
220 
221 INSTANTIATE_ENUM_MAPS(FEFamily, fefamily)
222 
223  // Initialize fefamily_to_enum on first call
224  void init_fefamily_to_enum ()
225  {
226  if (fefamily_to_enum.empty())
227  {
228  fefamily_to_enum["LAGRANGE" ]=LAGRANGE;
229  fefamily_to_enum["LAGRANGE_VEC" ]=LAGRANGE_VEC;
230  fefamily_to_enum["L2_LAGRANGE" ]=L2_LAGRANGE;
231  fefamily_to_enum["HIERARCHIC" ]=HIERARCHIC;
232  fefamily_to_enum["L2_HIERARCHIC"]=L2_HIERARCHIC;
233  fefamily_to_enum["MONOMIAL" ]=MONOMIAL;
234  fefamily_to_enum["SCALAR" ]=SCALAR;
235  fefamily_to_enum["XYZ" ]=XYZ;
236  fefamily_to_enum["BERNSTEIN" ]=BERNSTEIN;
237  fefamily_to_enum["SZABAB" ]=SZABAB;
238  fefamily_to_enum["INFINITE_MAP" ]=INFINITE_MAP;
239  fefamily_to_enum["JACOBI_20_00" ]=JACOBI_20_00;
240  fefamily_to_enum["JACOBI_30_00" ]=JACOBI_30_00;
241  fefamily_to_enum["LEGENDRE" ]=LEGENDRE;
242  fefamily_to_enum["CLOUGH" ]=CLOUGH;
243  fefamily_to_enum["HERMITE" ]=HERMITE;
244  fefamily_to_enum["NEDELEC_ONE" ]=NEDELEC_ONE;
245  }
246 
247  }
248 
249 
250 
251 INSTANTIATE_ENUM_MAPS(InfMapType, inf_map_type)
252 
253  // Initialize inf_map_type_to_enum on first call
254  void init_inf_map_type_to_enum ()
255  {
256  if (inf_map_type_to_enum.empty())
257  {
258  inf_map_type_to_enum["CARTESIAN" ]=CARTESIAN;
259  inf_map_type_to_enum["SPHERICAL" ]=SPHERICAL;
260  inf_map_type_to_enum["ELLIPSOIDAL"]=ELLIPSOIDAL;
261  }
262  }
263 
264 
265 INSTANTIATE_ENUM_MAPS(QuadratureType, quadrature_type)
266 
267  // Initialize quadrature_type_to_enum on first call
268  void init_quadrature_type_to_enum ()
269  {
270  if (quadrature_type_to_enum.empty())
271  {
272  quadrature_type_to_enum["QGAUSS" ]=QGAUSS;
273  quadrature_type_to_enum["QJACOBI_1_0"]=QJACOBI_1_0;
274  quadrature_type_to_enum["QJACOBI_2_0"]=QJACOBI_2_0;
275  quadrature_type_to_enum["QSIMPSON" ]=QSIMPSON;
276  quadrature_type_to_enum["QTRAP" ]=QTRAP;
277  quadrature_type_to_enum["QGRID" ]=QGRID;
278  quadrature_type_to_enum["QCLOUGH" ]=QCLOUGH;
279  }
280  }
281 
282 
283 INSTANTIATE_ENUM_MAPS(PreconditionerType, preconditioner_type)
284 
285  // Initialize preconditioner_type_to_enum on first call
286  void init_preconditioner_type_to_enum ()
287  {
288  if (preconditioner_type_to_enum.empty())
289  {
290  preconditioner_type_to_enum["IDENTITY_PRECOND" ]=IDENTITY_PRECOND;
291  preconditioner_type_to_enum["JACOBI_PRECOND" ]=JACOBI_PRECOND;
292  preconditioner_type_to_enum["BLOCK_JACOBI_PRECOND" ]=BLOCK_JACOBI_PRECOND;
293  preconditioner_type_to_enum["SOR_PRECOND" ]=SOR_PRECOND;
294  preconditioner_type_to_enum["SSOR_PRECOND" ]=SSOR_PRECOND;
295  preconditioner_type_to_enum["EISENSTAT_PRECOND" ]=EISENSTAT_PRECOND;
296  preconditioner_type_to_enum["ASM_PRECOND" ]=ASM_PRECOND;
297  preconditioner_type_to_enum["CHOLESKY_PRECOND" ]=CHOLESKY_PRECOND;
298  preconditioner_type_to_enum["ICC_PRECOND" ]=ICC_PRECOND;
299  preconditioner_type_to_enum["ILU_PRECOND" ]=ILU_PRECOND;
300  preconditioner_type_to_enum["LU_PRECOND" ]=LU_PRECOND;
301  preconditioner_type_to_enum["USER_PRECOND" ]=USER_PRECOND;
302  preconditioner_type_to_enum["SHELL_PRECOND" ]=SHELL_PRECOND;
303  preconditioner_type_to_enum["AMG_PRECOND" ]=AMG_PRECOND;
304  preconditioner_type_to_enum["INVALID_PRECONDITIONER"]=INVALID_PRECONDITIONER;
305 
306  //shorter
307  preconditioner_type_to_enum["IDENTITY" ]=IDENTITY_PRECOND;
308  preconditioner_type_to_enum["JACOBI" ]=JACOBI_PRECOND;
309  preconditioner_type_to_enum["BLOCK_JACOBI"]=BLOCK_JACOBI_PRECOND;
310  preconditioner_type_to_enum["SOR" ]=SOR_PRECOND;
311  preconditioner_type_to_enum["SSOR" ]=SSOR_PRECOND;
312  preconditioner_type_to_enum["EISENSTAT" ]=EISENSTAT_PRECOND;
313  preconditioner_type_to_enum["ASM" ]=ASM_PRECOND;
314  preconditioner_type_to_enum["CHOLESKY" ]=CHOLESKY_PRECOND;
315  preconditioner_type_to_enum["ICC" ]=ICC_PRECOND;
316  preconditioner_type_to_enum["ILU" ]=ILU_PRECOND;
317  preconditioner_type_to_enum["LU" ]=LU_PRECOND;
318  preconditioner_type_to_enum["USER" ]=USER_PRECOND;
319  preconditioner_type_to_enum["SHELL" ]=SHELL_PRECOND;
320  preconditioner_type_to_enum["AMG" ]=AMG_PRECOND;
321  preconditioner_type_to_enum["INVALID" ]=INVALID_PRECONDITIONER;
322  }
323  }
324 
325 
326 #ifdef LIBMESH_ENABLE_AMR
327 
328 INSTANTIATE_ENUM_MAPS(Elem::RefinementState, refinementstate_type)
329 
330  // Initialize refinementstate_type_to_enum on first call
331  void init_refinementstate_type_to_enum ()
332  {
333  if (refinementstate_type_to_enum.empty())
334  {
335  refinementstate_type_to_enum["COARSEN" ]=Elem::COARSEN;
336  refinementstate_type_to_enum["DO_NOTHING" ]=Elem::DO_NOTHING;
337  refinementstate_type_to_enum["REFINE" ]=Elem::REFINE;
338  refinementstate_type_to_enum["JUST_REFINED" ]=Elem::JUST_REFINED;
339  refinementstate_type_to_enum["JUST_COARSENED" ]=Elem::JUST_COARSENED;
340  refinementstate_type_to_enum["INACTIVE" ]=Elem::INACTIVE;
341  refinementstate_type_to_enum["COARSEN_INACTIVE" ]=Elem::COARSEN_INACTIVE;
342  refinementstate_type_to_enum["INVALID_REFINEMENTSTATE"]=Elem::INVALID_REFINEMENTSTATE;
343  }
344  }
345 #endif // LIBMESH_ENABLE_AMR
346 
347 
348 INSTANTIATE_ENUM_MAPS(EigenSolverType, eigensolvertype)
349 
350  // Initialize eigensolvertype_to_enum on first call
351  void init_eigensolvertype_to_enum ()
352  {
353  if (eigensolvertype_to_enum.empty())
354  {
355  eigensolvertype_to_enum["POWER" ]=POWER;
356  eigensolvertype_to_enum["LAPACK" ]=LAPACK;
357  eigensolvertype_to_enum["SUBSPACE" ]=SUBSPACE;
358  eigensolvertype_to_enum["ARNOLDI" ]=ARNOLDI;
359  eigensolvertype_to_enum["LANCZOS" ]=LANCZOS;
360  eigensolvertype_to_enum["KRYLOVSCHUR" ]=KRYLOVSCHUR;
361  eigensolvertype_to_enum["INVALID_EIGENSOLVER"]=INVALID_EIGENSOLVER;
362  }
363  }
364 
365 
366 INSTANTIATE_ENUM_MAPS(SolverType, solvertype)
367 
368  // Initialize solvertype_to_enum on first call
369  void init_solvertype_to_enum ()
370  {
371  if (solvertype_to_enum.empty())
372  {
373  solvertype_to_enum["CG" ]=CG;
374  solvertype_to_enum["CGN" ]=CGN;
375  solvertype_to_enum["CGS" ]=CGS;
376  solvertype_to_enum["CR" ]=CR;
377  solvertype_to_enum["QMR" ]=QMR;
378  solvertype_to_enum["TCQMR" ]=TCQMR;
379  solvertype_to_enum["TFQMR" ]=TFQMR;
380  solvertype_to_enum["BICG" ]=BICG;
381  solvertype_to_enum["MINRES" ]=MINRES;
382  solvertype_to_enum["GMRES" ]=GMRES;
383  solvertype_to_enum["LSQR" ]=LSQR;
384  solvertype_to_enum["JACOBI" ]=JACOBI;
385  solvertype_to_enum["SOR_FORWARD" ]=SOR_FORWARD;
386  solvertype_to_enum["SOR_BACKWARD" ]=SOR_BACKWARD;
387  solvertype_to_enum["SSOR" ]=SSOR;
388  solvertype_to_enum["RICHARDSON" ]=RICHARDSON;
389  solvertype_to_enum["CHEBYSHEV" ]=CHEBYSHEV;
390  solvertype_to_enum["INVALID_SOLVER"]=INVALID_SOLVER;
391  }
392  }
393 
394 
395 INSTANTIATE_ENUM_MAPS(ElemQuality, elemquality)
396 
397  // Initialize elemquality_to_enum on first call
398  void init_elemquality_to_enum ()
399  {
400  if (elemquality_to_enum.empty())
401  {
402  elemquality_to_enum["ASPECT_RATIO" ]=ASPECT_RATIO;
403  elemquality_to_enum["SKEW" ]=SKEW;
404  elemquality_to_enum["SHEAR" ]=SHEAR;
405  elemquality_to_enum["SHAPE" ]=SHAPE;
406  elemquality_to_enum["MAX_ANGLE" ]=MAX_ANGLE;
407  elemquality_to_enum["MIN_ANGLE" ]=MIN_ANGLE;
408  elemquality_to_enum["CONDITION" ]=CONDITION;
409  elemquality_to_enum["DISTORTION" ]=DISTORTION;
410  elemquality_to_enum["TAPER" ]=TAPER;
411  elemquality_to_enum["WARP" ]=WARP;
412  elemquality_to_enum["STRETCH" ]=STRETCH;
413  elemquality_to_enum["DIAGONAL" ]=DIAGONAL;
414  elemquality_to_enum["ASPECT_RATIO_BETA" ]=ASPECT_RATIO_BETA;
415  elemquality_to_enum["ASPECT_RATIO_GAMMA" ]=ASPECT_RATIO_GAMMA;
416  elemquality_to_enum["SIZE" ]=SIZE;
417  elemquality_to_enum["JACOBIAN" ]=JACOBIAN;
418  }
419  }
420 
421 
422 INSTANTIATE_ENUM_MAPS(IOPackage, iopackage)
423 
424  // Initialize iopackage_to_enum on first call
425  void init_iopackage_to_enum ()
426  {
427  if (iopackage_to_enum.empty())
428  {
429  iopackage_to_enum["TECPLOT" ]=TECPLOT;
430  iopackage_to_enum["GMV" ]=GMV;
431  iopackage_to_enum["GMSH" ]=GMSH;
432  iopackage_to_enum["VTK" ]=VTK;
433  iopackage_to_enum["DIVA" ]=DIVA;
434  iopackage_to_enum["TETGEN" ]=TETGEN;
435  iopackage_to_enum["UCD" ]=UCD;
436  iopackage_to_enum["LIBMESH" ]=LIBMESH;
437  }
438  }
439 
440 
441 INSTANTIATE_ENUM_MAPS(FEMNormType, norm_type)
442 
443  // Initialize norm_type_to_enum on first call
444  void init_norm_type_to_enum ()
445  {
446  if (norm_type_to_enum.empty())
447  {
448  norm_type_to_enum["L2" ]=L2;
449  norm_type_to_enum["H1" ]=H1;
450  norm_type_to_enum["H2" ]=H2;
451  norm_type_to_enum["HCURL" ]=HCURL;
452  norm_type_to_enum["HDIV" ]=HDIV;
453 
454  norm_type_to_enum["L1" ]=L1;
455  norm_type_to_enum["L_INF" ]=L_INF;
456 
457  norm_type_to_enum["H1_SEMINORM" ]=H1_SEMINORM;
458  norm_type_to_enum["H2_SEMINORM" ]=H2_SEMINORM;
459  norm_type_to_enum["HCURL_SEMINORM" ]=HCURL_SEMINORM;
460  norm_type_to_enum["HDIV_SEMINORM" ]=HDIV_SEMINORM;
461 
462  norm_type_to_enum["W1_INF_SEMINORM" ]=W1_INF_SEMINORM;
463  norm_type_to_enum["W2_INF_SEMINORM" ]=W2_INF_SEMINORM;
464 
465  norm_type_to_enum["DISCRETE_L1" ]=DISCRETE_L1;
466  norm_type_to_enum["DISCRETE_L2" ]=DISCRETE_L2;
467  norm_type_to_enum["DISCRETE_L_INF" ]=DISCRETE_L_INF;
468 
469  norm_type_to_enum["H1_X_SEMINORM" ]=H1_X_SEMINORM;
470  norm_type_to_enum["H1_Y_SEMINORM" ]=H1_Y_SEMINORM;
471  norm_type_to_enum["H1_Z_SEMINORM" ]=H1_Z_SEMINORM;
472 
473  norm_type_to_enum["INVALID_NORM" ]=INVALID_NORM;
474  }
475  }
476 
477 
478 INSTANTIATE_ENUM_MAPS(ParallelType, parallel_type)
479 
480  // Initialize parallel_type_to_enum on first call
481  void init_parallel_type_to_enum ()
482  {
483  if (parallel_type_to_enum.empty())
484  {
485  parallel_type_to_enum["AUTOMATIC" ]=AUTOMATIC;
486  parallel_type_to_enum["SERIAL" ]=SERIAL;
487  parallel_type_to_enum["PARALLEL" ]=PARALLEL;
488  parallel_type_to_enum["GHOSTED" ]=GHOSTED;
489  parallel_type_to_enum["INVALID_PARALLELIZATION" ]=INVALID_PARALLELIZATION;
490  }
491  }
492 
493 
494 INSTANTIATE_ENUM_MAPS(PointLocatorType, point_locator_type)
495 
496  // Initialize point_locator_type_to_enum on first call
497  void init_point_locator_type_to_enum ()
498  {
499  if (point_locator_type_to_enum.empty())
500  {
501  point_locator_type_to_enum["TREE" ]=TREE;
502  point_locator_type_to_enum["LIST" ]=LIST;
503  point_locator_type_to_enum["INVALID_LOCATOR" ]=INVALID_LOCATOR;
504  }
505  }
506 
507 
508 INSTANTIATE_ENUM_MAPS(SolverPackage, solverpackage_type)
509 
510  // Initialize solverpackage_type_to_enum on first call
511  void init_solverpackage_type_to_enum ()
512  {
513  if (solverpackage_type_to_enum.empty())
514  {
515  solverpackage_type_to_enum["PETSC_SOLVERS" ]=PETSC_SOLVERS;
516  solverpackage_type_to_enum["TRILINOS_SOLVERS" ]=TRILINOS_SOLVERS;
517  solverpackage_type_to_enum["LASPACK_SOLVERS" ]=LASPACK_SOLVERS;
518  solverpackage_type_to_enum["SLEPC_SOLVERS" ]=SLEPC_SOLVERS;
519  solverpackage_type_to_enum["EIGEN_SOLVERS" ]=EIGEN_SOLVERS;
520  solverpackage_type_to_enum["INVALID_SOLVER_PACKAGE" ]=INVALID_SOLVER_PACKAGE;
521  }
522  }
523 
524 
525 INSTANTIATE_ENUM_MAPS(SubsetSolveMode, subset_solve_mode)
526 
527  // Initialize subset_solve_mode_to_enum on first call
528  void init_subset_solve_mode_to_enum ()
529  {
530  if (subset_solve_mode_to_enum.empty())
531  {
532  subset_solve_mode_to_enum["SUBSET_ZERO" ]=SUBSET_ZERO;
533  subset_solve_mode_to_enum["SUBSET_COPY_RHS" ]=SUBSET_COPY_RHS;
534  subset_solve_mode_to_enum["SUBSET_DONT_TOUCH" ]=SUBSET_DONT_TOUCH;
535  }
536  }
537 
538 
539 INSTANTIATE_ENUM_MAPS(XdrMODE, xdr_mode)
540 
541  // Initialize xdr_mode_to_enum on first call
542  void init_xdr_mode_to_enum ()
543  {
544  if (xdr_mode_to_enum.empty())
545  {
546  xdr_mode_to_enum["UNKNOWN" ]=UNKNOWN;
547  xdr_mode_to_enum["ENCODE" ]=ENCODE;
548  xdr_mode_to_enum["DECODE" ]=DECODE;
549  xdr_mode_to_enum["WRITE" ]=WRITE;
550  xdr_mode_to_enum["READ" ]=READ;
551  }
552  }
553 
554 
555 
556 
557 
558 #undef INSTANTIATE_ENUM_MAPS
559 
560 } // end anonymous namespace
561 
562 
563 
564 // ------------------------------------------------------
565 // Utility::string_to_enum<> & Utility::enum_to_string<>
566 // full specializations
567 namespace Utility {
568 
569 #define INSTANTIATE_STRING_TO_ENUM(ENUM_NAME,VAR_NAME) \
570  template <> \
571  ENUM_NAME string_to_enum<ENUM_NAME> (const std::string& s) \
572  { \
573  init_##VAR_NAME##_to_enum(); \
574  \
575  std::string upper(s); \
576  std::transform(upper.begin(), upper.end(), upper.begin(), ::toupper); \
577  \
578  if (!VAR_NAME##_to_enum.count(upper)) \
579  { \
580  libmesh_error_msg("No " #ENUM_NAME " named " + s + " found."); \
581  } \
582  \
583  return VAR_NAME##_to_enum[upper]; \
584  } \
585  \
586  template <> \
587  std::string enum_to_string<ENUM_NAME> (const ENUM_NAME e) \
588  { \
589  init_enum_to_##VAR_NAME (); \
590  \
591  if (!enum_to_##VAR_NAME .count(e)) \
592  libmesh_error(); \
593  \
594  return enum_to_##VAR_NAME [e]; \
595  }
596 
597 
598 INSTANTIATE_STRING_TO_ENUM(ElemType,elem_type)
599 INSTANTIATE_STRING_TO_ENUM(Order,order)
600 INSTANTIATE_STRING_TO_ENUM(FEFamily,fefamily)
601 INSTANTIATE_STRING_TO_ENUM(InfMapType,inf_map_type)
602 INSTANTIATE_STRING_TO_ENUM(QuadratureType,quadrature_type)
603 INSTANTIATE_STRING_TO_ENUM(PreconditionerType,preconditioner_type)
604 
605 #ifdef LIBMESH_ENABLE_AMR
606 INSTANTIATE_STRING_TO_ENUM(Elem::RefinementState,refinementstate_type)
607 #endif // LIBMESH_ENABLE_AMR
608 
609 INSTANTIATE_STRING_TO_ENUM(SolverType,solvertype)
610 INSTANTIATE_STRING_TO_ENUM(EigenSolverType,eigensolvertype)
611 INSTANTIATE_STRING_TO_ENUM(ElemQuality,elemquality)
612 INSTANTIATE_STRING_TO_ENUM(IOPackage,iopackage)
613 INSTANTIATE_STRING_TO_ENUM(FEMNormType, norm_type)
614 INSTANTIATE_STRING_TO_ENUM(ParallelType, parallel_type)
615 INSTANTIATE_STRING_TO_ENUM(PointLocatorType, point_locator_type)
616 INSTANTIATE_STRING_TO_ENUM(SolverPackage,solverpackage_type)
617 INSTANTIATE_STRING_TO_ENUM(SubsetSolveMode,subset_solve_mode)
618 INSTANTIATE_STRING_TO_ENUM(XdrMODE,xdr_mode)
619 
620 #undef INSTANTIATE_STRING_TO_ENUM
621 
622 } // namespace Utility
623 
624 } // namespace libMesh

Site Created By: libMesh Developers
Last modified: February 07 2014 16:57:07 UTC

Hosted By:
SourceForge.net Logo