OGS
Properties-impl.h
Go to the documentation of this file.
1 
13 template <typename T>
14 PropertyVector<T>* Properties::createNewPropertyVector(
15  std::string const& name,
16  MeshItemType mesh_item_type,
17  std::size_t n_components)
18 {
19  std::map<std::string, PropertyVectorBase*>::const_iterator it(
20  _properties.find(name)
21  );
22  if (it != _properties.end()) {
23  ERR("A property of the name '{:s}' is already assigned to the mesh.",
24  name);
25  return nullptr;
26  }
27  auto entry_info(
28  _properties.insert(
29  std::make_pair(
30  name, new PropertyVector<T>(name, mesh_item_type, n_components)
31  )
32  )
33  );
34  return static_cast<PropertyVector<T>*>((entry_info.first)->second);
35 }
36 
37 template <typename T>
38 PropertyVector<T>* Properties::createNewPropertyVector(
39  std::string const& name,
40  std::size_t n_prop_groups,
41  std::vector<std::size_t> const& item2group_mapping,
42  MeshItemType mesh_item_type,
43  std::size_t n_components)
44 {
45  // check if there is already a PropertyVector with the same name
46  std::map<std::string, PropertyVectorBase*>::const_iterator it(
47  _properties.find(name)
48  );
49  if (it != _properties.end()) {
50  ERR("A property of the name '{:s}' already assigned to the mesh.",
51  name);
52  return nullptr;
53  }
54 
55  // check entries of item2group_mapping for consistence
56  for (std::size_t k(0); k<item2group_mapping.size(); k++) {
57  std::size_t const group_id (item2group_mapping[k]);
58  if (group_id >= n_prop_groups) {
59  ERR("The mapping to property {:d} for item {:d} is not in the "
60  "correct range [0,{:d}).",
61  group_id, k, n_prop_groups);
62  return nullptr;
63  }
64  }
65 
66  auto entry_info(
67  _properties.insert(
68  std::pair<std::string, PropertyVectorBase*>(
69  name,
70  new PropertyVector<T>(n_prop_groups,
71  item2group_mapping, name, mesh_item_type, n_components)
72  )
73  )
74  );
75  return static_cast<PropertyVector<T>*>((entry_info.first)->second);
76 }
77 
78 template <typename T>
79 bool Properties::existsPropertyVector(std::string const& name) const
80 {
81  auto it(_properties.find(name));
82  // Check that a PropertyVector with the appropriate name exists.
83  if (it == _properties.end())
84  {
85  return false;
86  }
87  // Check that the PropertyVector has the correct data type.
88  return dynamic_cast<PropertyVector<T> const*>(it->second) != nullptr;
89 }
90 
91 template <typename T>
92 bool Properties::existsPropertyVector(std::string const& name,
93  MeshItemType const mesh_item_type,
94  int const number_of_components) const
95 {
96  auto const it = _properties.find(name);
97  if (it == _properties.end())
98  {
99  return false;
100  }
101 
102  auto property = dynamic_cast<PropertyVector<T>*>(it->second);
103  if (property == nullptr)
104  {
105  return false;
106  }
107  if (property->getMeshItemType() != mesh_item_type)
108  {
109  return false;
110  }
111  if (property->getNumberOfGlobalComponents() != number_of_components)
112  {
113  return false;
114  }
115  return true;
116 }
117 
118 template <typename T>
119 PropertyVector<T> const* Properties::getPropertyVector(
120  std::string const& name) const
121 {
122  auto it(_properties.find(name));
123  if (it == _properties.end())
124  {
125  OGS_FATAL("The PropertyVector '{:s}' is not available in the mesh.",
126  name);
127  }
128  if (!dynamic_cast<PropertyVector<T> const*>(it->second))
129  {
130  OGS_FATAL(
131  "The PropertyVector '{:s}' has a different type than the requested "
132  "PropertyVector.",
133  name);
134  }
135  return dynamic_cast<PropertyVector<T> const*>(it->second);
136 }
137 
138 template <typename T>
139 PropertyVector<T>* Properties::getPropertyVector(std::string const& name)
140 {
141  auto it(_properties.find(name));
142  if (it == _properties.end())
143  {
144  OGS_FATAL(
145  "A PropertyVector with the specified name '{:s}' is not available.",
146  name);
147  }
148  if (!dynamic_cast<PropertyVector<T>*>(it->second))
149  {
150  OGS_FATAL(
151  "The PropertyVector '{:s}' has a different type than the requested "
152  "PropertyVector.",
153  name);
154  }
155  return dynamic_cast<PropertyVector<T>*>(it->second);
156 }
157 
158 template <typename T>
159 PropertyVector<T> const* Properties::getPropertyVector(
160  std::string const& name, MeshItemType const item_type,
161  int const n_components) const
162 {
163  auto const it = _properties.find(name);
164  if (it == _properties.end())
165  {
166  OGS_FATAL(
167  "A PropertyVector with name '{:s}' does not exist in the mesh.",
168  name);
169  }
170 
171  auto property = dynamic_cast<PropertyVector<T>*>(it->second);
172  if (property == nullptr)
173  {
174  OGS_FATAL(
175  "Could not cast the data type of the PropertyVector '{:s}' to "
176  "requested data type.",
177  name);
178  }
179  if (property->getMeshItemType() != item_type)
180  {
181  OGS_FATAL(
182  "The PropertyVector '{:s}' has type '{:s}'. A '{:s}' field is "
183  "requested.",
184  name, toString(property->getMeshItemType()), toString(item_type));
185  }
186  if (property->getNumberOfGlobalComponents() != n_components)
187  {
188  OGS_FATAL(
189  "PropertyVector '{:s}' has {:d} components, {:d} components are "
190  "needed.",
191  name, property->getNumberOfGlobalComponents(), n_components);
192  }
193  return property;
194 }
195 
196 template <typename T>
197 PropertyVector<T>* Properties::getPropertyVector(std::string const& name,
198  MeshItemType const item_type,
199  int const n_components)
200 {
201  auto const it = _properties.find(name);
202  if (it == _properties.end())
203  {
204  OGS_FATAL(
205  "A PropertyVector with name '{:s}' does not exist in the mesh.",
206  name);
207  }
208 
209  auto property = dynamic_cast<PropertyVector<T>*>(it->second);
210  if (property == nullptr)
211  {
212  OGS_FATAL(
213  "Could not cast the data type of the PropertyVector '{:s}' to "
214  "requested data type.",
215  name);
216  }
217  if (property->getMeshItemType() != item_type)
218  {
219  OGS_FATAL(
220  "The PropertyVector '{:s}' has type '{:s}'. A '{:s}' field is "
221  "requested.",
222  name, toString(property->getMeshItemType()), toString(item_type));
223  }
224  if (property->getNumberOfGlobalComponents() != n_components)
225  {
226  OGS_FATAL(
227  "PropertyVector '{:s}' has {:d} components, {:d} components are "
228  "needed.",
229  name, property->getNumberOfGlobalComponents(), n_components);
230  }
231  return property;
232 }
#define OGS_FATAL(...)
Definition: Error.h:26
void ERR(char const *fmt, Args const &... args)
Definition: Logging.h:42
const char * toString(mgis::behaviour::Behaviour::Kinematic kin)
Converts MGIS kinematic to a string representation.
Definition: MFront.cpp:103
MeshItemType
Definition: Location.h:21