OGS
getOrCreateMeshProperty.h
Go to the documentation of this file.
1
// SPDX-FileCopyrightText: Copyright (c) OpenGeoSys Community (opengeosys.org)
2
// SPDX-License-Identifier: BSD-3-Clause
3
4
#pragma once
5
#include <string>
6
7
#include "
MeshLib/Mesh.h
"
8
#include "
MeshLib/PropertyVector.h
"
9
10
namespace
MeshLib
11
{
16
template
<
typename
T>
17
PropertyVector<T>
*
getOrCreateMeshProperty
(
Mesh
& mesh,
18
std::string
const
& property_name,
19
MeshItemType
const
item_type,
20
int
const
number_of_components)
21
{
22
if
(property_name.empty())
23
{
24
OGS_FATAL
(
25
"Trying to get or to create a mesh property with empty name."
);
26
}
27
28
auto
numberOfMeshItems = [&mesh, &item_type]() -> std::size_t
29
{
30
switch
(item_type)
31
{
32
case
MeshItemType::Cell
:
33
return
mesh.
getNumberOfElements
();
34
case
MeshItemType::Node
:
35
return
mesh.
getNumberOfNodes
();
36
case
MeshItemType::IntegrationPoint
:
37
return
0;
// For the integration point data the size is
38
// variable
39
default
:
40
OGS_FATAL
(
41
"getOrCreateMeshProperty cannot handle other "
42
"types than Node, Cell, or IntegrationPoint."
);
43
}
44
return
0;
45
};
46
47
if
(mesh.
getProperties
().
existsPropertyVector
<T>(property_name))
48
{
49
auto
result =
50
mesh.
getProperties
().template getPropertyVector<T>(property_name);
51
assert(result);
52
if
(item_type !=
MeshItemType::IntegrationPoint
)
53
{
54
// Test the size if number of mesh items is known, which is not the
55
// case for the integration point data.
56
assert(result->size() ==
57
numberOfMeshItems() * number_of_components);
58
}
59
return
result;
60
}
61
62
auto
result = mesh.
getProperties
().template createNewPropertyVector<T>(
63
property_name, item_type, numberOfMeshItems(), number_of_components);
64
assert(result);
65
return
result;
66
}
67
}
// namespace MeshLib
OGS_FATAL
#define OGS_FATAL(...)
Definition
Error.h:19
Mesh.h
PropertyVector.h
MeshLib::Mesh
Definition
Mesh.h:34
MeshLib::Mesh::getProperties
Properties & getProperties()
Definition
Mesh.h:125
MeshLib::Mesh::getNumberOfNodes
std::size_t getNumberOfNodes() const
Get the number of nodes.
Definition
Mesh.h:91
MeshLib::Mesh::getNumberOfElements
std::size_t getNumberOfElements() const
Get the number of elements.
Definition
Mesh.h:88
MeshLib::Properties::existsPropertyVector
bool existsPropertyVector(std::string_view name) const
Definition
Properties-impl.h:85
MeshLib::PropertyVector
Definition
PropertyVector.h:52
MeshLib
Definition
ProjectData.h:30
MeshLib::getOrCreateMeshProperty
PropertyVector< T > * getOrCreateMeshProperty(Mesh &mesh, std::string const &property_name, MeshItemType const item_type, int const number_of_components)
Definition
getOrCreateMeshProperty.h:17
MeshLib::MeshItemType
MeshItemType
Definition
MeshEnums.h:12
MeshLib::MeshItemType::Cell
@ Cell
Definition
MeshEnums.h:16
MeshLib::MeshItemType::IntegrationPoint
@ IntegrationPoint
Definition
MeshEnums.h:17
MeshLib::MeshItemType::Node
@ Node
Definition
MeshEnums.h:13
MeshLib
Utils
getOrCreateMeshProperty.h
Generated by
1.14.0