Loading [MathJax]/extensions/tex2jax.js
OGS
addPropertyToMesh.h
Go to the documentation of this file.
1
12#pragma once
13
14#include <vector>
15
16#include "BaseLib/Error.h"
17#include "MeshLib/Mesh.h"
18#include "MeshLib/Properties.h"
19
20namespace MeshLib
21{
32template <typename T>
33void addPropertyToMesh(Mesh& mesh, std::string_view name,
34 MeshItemType item_type, std::size_t number_of_components,
35 std::span<T const> values)
36{
37 if (item_type == MeshItemType::Node)
38 {
39 if (mesh.getNumberOfNodes() != values.size() / number_of_components)
40 {
42 "Error number of nodes ({:d}) does not match the number of "
43 "tuples ({:d}).",
44 mesh.getNumberOfNodes(), values.size() / number_of_components);
45 }
46 }
47 if (item_type == MeshItemType::Cell)
48 {
49 if (mesh.getNumberOfElements() != values.size() / number_of_components)
50 {
52 "Error number of elements ({:d}) does not match the number of "
53 "tuples ({:d}).",
55 values.size() / number_of_components);
56 }
57 }
58
59 auto* const property = mesh.getProperties().createNewPropertyVector<T>(
60 name, item_type, values.size() / number_of_components,
61 number_of_components);
62 if (!property)
63 {
64 OGS_FATAL("Error while creating PropertyVector '{:s}'.", name);
65 }
66 assert(property->size() == values.size());
67 property->assign(values);
68}
69} // namespace MeshLib
#define OGS_FATAL(...)
Definition Error.h:26
Definition of the class Properties that implements a container of properties.
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
PropertyVector< T > * createNewPropertyVector(std::string_view name, MeshItemType mesh_item_type, std::size_t n_components=1)
Definition Properties.h:17
void addPropertyToMesh(Mesh &mesh, std::string_view name, MeshItemType item_type, std::size_t number_of_components, std::span< T const > values)