Loading [MathJax]/extensions/MathZoom.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::vector<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, number_of_components);
61 if (!property)
62 {
63 OGS_FATAL("Error while creating PropertyVector '{:s}'.", name);
64 }
65 property->reserve(values.size());
66 std::copy(values.cbegin(), values.cend(), std::back_inserter(*property));
67}
68} // 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::vector< T > const &values)