OGS
getOrCreateMeshProperty.h
Go to the documentation of this file.
1
10#pragma once
11#include <string>
12
13#include "MeshLib/Mesh.h"
15
16namespace MeshLib
17{
22template <typename T>
24 std::string const& property_name,
25 MeshItemType const item_type,
26 int const number_of_components)
27{
28 if (property_name.empty())
29 {
31 "Trying to get or to create a mesh property with empty name.");
32 }
33
34 auto numberOfMeshItems = [&mesh, &item_type]() -> std::size_t
35 {
36 switch (item_type)
37 {
39 return mesh.getNumberOfElements();
41 return mesh.getNumberOfNodes();
43 return 0; // For the integration point data the size is
44 // variable
45 default:
47 "getOrCreateMeshProperty cannot handle other "
48 "types than Node, Cell, or IntegrationPoint.");
49 }
50 return 0;
51 };
52
53 if (mesh.getProperties().existsPropertyVector<T>(property_name))
54 {
55 auto result =
56 mesh.getProperties().template getPropertyVector<T>(property_name);
57 assert(result);
58 if (item_type != MeshItemType::IntegrationPoint)
59 {
60 // Test the size if number of mesh items is known, which is not the
61 // case for the integration point data.
62 assert(result->size() ==
63 numberOfMeshItems() * number_of_components);
64 }
65 return result;
66 }
67
68 auto result = mesh.getProperties().template createNewPropertyVector<T>(
69 property_name, item_type, numberOfMeshItems(), number_of_components);
70 assert(result);
71 return result;
72}
73} // namespace MeshLib
#define OGS_FATAL(...)
Definition Error.h:26
Definition of the Mesh class.
Properties & getProperties()
Definition Mesh.h:136
std::size_t getNumberOfNodes() const
Get the number of nodes.
Definition Mesh.h:102
std::size_t getNumberOfElements() const
Get the number of elements.
Definition Mesh.h:99
bool existsPropertyVector(std::string_view name) const
PropertyVector< T > * getOrCreateMeshProperty(Mesh &mesh, std::string const &property_name, MeshItemType const item_type, int const number_of_components)