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