www.mooseframework.org
Conversion.h
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://www.mooseframework.org
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 #pragma once
11 
12 // MOOSE includes
13 #include "MooseTypes.h"
14 
15 // libMesh
16 #include "libmesh/enum_order.h"
17 #include "libmesh/enum_quadrature_type.h"
18 
19 // Forward declarations
20 class MultiMooseEnum;
21 namespace libMesh
22 {
23 class Point;
24 }
25 
26 namespace Moose
27 {
28 // Scalar conversions
29 template <typename T>
30 T stringToEnum(const std::string & s);
31 
32 template <>
33 QuadratureType stringToEnum<QuadratureType>(const std::string & s);
34 
35 template <>
36 Order stringToEnum<Order>(const std::string & s);
37 
38 template <>
40 
41 template <>
42 SolveType stringToEnum<SolveType>(const std::string & s);
43 
44 template <>
45 LineSearchType stringToEnum<LineSearchType>(const std::string & s);
46 
47 template <>
49 
50 template <>
52 
53 // Vector conversions
54 template <typename T>
55 std::vector<T> vectorStringsToEnum(const MultiMooseEnum & v);
56 
58 template <typename T>
59 std::string
60 stringify(const T & t)
61 {
62  std::ostringstream os;
63  os << t;
64  return os.str();
65 }
66 
68 std::string stringify(const SolveType & t);
69 
71 std::string stringify(const std::string & s);
72 
74 template <typename T, typename U>
75 std::string
76 stringify(const std::pair<T, U> & p)
77 {
78  return stringify(p.first) + ':' + stringify(p.second);
79 }
80 
94 template <template <typename...> class T, typename... U>
95 std::string
96 stringify(const T<U...> & c,
97  const std::string & delim = ",",
98  const std::string & elem_encl = "",
99  bool enclose_list_in_curly_braces = false)
100 {
101  std::string str;
102  if (enclose_list_in_curly_braces)
103  str += "{";
104  const auto begin = c.begin();
105  const auto end = c.end();
106  for (auto i = begin; i != end; ++i)
107  str += (i != begin ? delim : "") + elem_encl + stringify(*i) + elem_encl;
108  if (enclose_list_in_curly_braces)
109  str += "}";
110  return str;
111 }
112 
117 std::string stringifyExact(Real);
118 }
119 
125 Point toPoint(const std::vector<Real> & pos);
126 
RelationshipManagerType
Main types of Relationship Managers.
Definition: MooseTypes.h:716
T stringToEnum(const std::string &s)
CoordinateSystemType stringToEnum< CoordinateSystemType >(const std::string &s)
Definition: Conversion.C:216
The following methods are specializations for using the libMesh::Parallel::packed_range_* routines fo...
TimeIntegratorType stringToEnum< TimeIntegratorType >(const std::string &s)
Definition: Conversion.C:306
Order stringToEnum< Order >(const std::string &s)
Definition: Conversion.C:203
std::string stringifyExact(Real)
Stringify Reals with enough precision to guarantee lossless Real -> string -> Real roundtrips...
Definition: Conversion.C:401
LineSearchType
Type of the line search.
Definition: MooseTypes.h:671
Point toPoint(const std::vector< Real > &pos)
Convert point represented as std::vector into Point.
Definition: Conversion.C:413
QuadratureType stringToEnum< QuadratureType >(const std::string &s)
Definition: Conversion.C:188
std::string stringify(const T &t)
conversion to string
Definition: Conversion.h:60
LineSearchType stringToEnum< LineSearchType >(const std::string &s)
Definition: Conversion.C:291
SolveType stringToEnum< SolveType >(const std::string &s)
Definition: Conversion.C:231
CoordinateSystemType
Definition: MooseTypes.h:556
std::vector< T > vectorStringsToEnum(const MultiMooseEnum &v)
TimeIntegratorType
Time integrators.
Definition: MooseTypes.h:648
RelationshipManagerType stringToEnum< RelationshipManagerType >(const std::string &s)
Definition: Conversion.C:336
Definition: Moose.h:112
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type It sho...
SolveType
Type of the solve.
Definition: MooseTypes.h:589