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
16
namespace
MeshLib
17
{
22
template
<
typename
T>
23
PropertyVector<T>
*
getOrCreateMeshProperty
(
Mesh
& mesh,
24
std::string
const
& property_name,
25
MeshItemType
const
item_type,
26
int
const
number_of_components)
27
{
28
if
(property_name.empty())
29
{
30
OGS_FATAL
(
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
{
38
case
MeshItemType::Cell
:
39
return
mesh.
getNumberOfElements
();
40
case
MeshItemType::Node
:
41
return
mesh.
getNumberOfNodes
();
42
case
MeshItemType::IntegrationPoint
:
43
return
0;
// For the integration point data the size is
44
// variable
45
default
:
46
OGS_FATAL
(
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
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
MeshLib::PropertyVector
Definition
CreateConstitutiveSetting.h:18
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:23
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.11.0