OGS
MeshLib/Properties.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
6#include <cstdlib>
7#include <map>
8#include <string>
9
10#include "BaseLib/Error.h"
11#include "PropertyVector.h"
12
13namespace MeshLib
14{
15
25{
26public:
40 template <typename T>
41 PropertyVector<T>* createNewPropertyVector(std::string_view name,
42 MeshItemType mesh_item_type,
43 std::size_t n_components = 1);
44
45 template <typename T>
46 PropertyVector<T>* createNewPropertyVector(std::string_view name,
47 MeshItemType mesh_item_type,
48 std::size_t n_property_values,
49 std::size_t n_components);
50
54 template <typename T>
55 bool existsPropertyVector(std::string_view name) const;
56
59 template <typename T>
60 bool existsPropertyVector(std::string_view name,
61 MeshItemType const mesh_item_type,
62 int const number_of_components) const;
63
66 template <typename T>
67 PropertyVector<T> const* getPropertyVector(std::string_view name) const;
68
71 template <typename T>
72 PropertyVector<T>* getPropertyVector(std::string_view name);
73
77 template <typename T>
78 PropertyVector<T> const* getPropertyVector(std::string_view name,
79 MeshItemType const item_type,
80 int const n_components) const;
81
85 template <typename T>
86 PropertyVector<T>* getPropertyVector(std::string_view name,
87 MeshItemType const item_type,
88 int const n_components);
89
90 void removePropertyVector(std::string_view name);
91
95 bool hasPropertyVector(std::string_view name) const;
96
101 template <typename T>
102 bool hasPropertyVector(std::string_view name,
103 MeshItemType const item_type) const;
104
105 std::vector<std::string> getPropertyVectorNames() const;
106 std::vector<std::string> getPropertyVectorNames(
107 MeshLib::MeshItemType t) const;
108
114 std::vector<std::size_t> const& exclude_elem_ids,
115 std::vector<std::size_t> const& exclude_node_ids) const;
116
121 std::vector<MeshItemType> const& exclude_mesh_item_types) const;
122
123 Properties() = default;
124
125 Properties(Properties const& properties);
126 Properties(Properties&& properties) = default;
127 Properties& operator=(Properties const& properties);
128 Properties& operator=(Properties&& properties) = default;
129
130 ~Properties();
131
132 std::map<std::string, PropertyVectorBase*>::const_iterator begin() const;
133 std::map<std::string, PropertyVectorBase*>::const_iterator end() const;
134 std::map<std::string, PropertyVectorBase*>::iterator begin();
135 std::map<std::string, PropertyVectorBase*>::iterator end();
136 std::map<std::string, PropertyVectorBase*>::size_type size() const;
137 // Counts properties of given mesh item type.
138 std::map<std::string, PropertyVectorBase*>::size_type size(
139 MeshItemType const mesh_item_type) const;
140
141private:
144 std::map<std::string, PropertyVectorBase*> _properties;
145}; // end class
146
152template <typename Function>
153void applyToPropertyVectors(Properties const& properties, Function f);
154
159constexpr std::string_view getBulkIDString(MeshItemType mesh_item_type)
160{
161 switch (mesh_item_type)
162 {
164 return "bulk_node_ids";
165 break;
167 return "bulk_element_ids";
168 break;
170 return "bulk_edge_ids";
171 break;
173 return "bulk_face_ids";
174 break;
176 OGS_FATAL("MeshItemType::IntegrationPoint is not handled.");
177 return "";
178 break;
179 default:
180 OGS_FATAL(
181 "Unknown mesh item type '{}'. At the moment mapping names only "
182 "for mesh item types 'Node', 'Cell', 'Edge', and 'Face' are "
183 "specified.",
184 static_cast<int>(mesh_item_type));
185 return "";
186 }
187}
188
189constexpr std::string_view globalIDString(
190 MeshLib::MeshItemType const mesh_item_type)
191{
192 switch (mesh_item_type)
193 {
195 {
196 return "global_node_ids";
197 }
199 {
200 return "global_element_ids";
201 }
203 OGS_FATAL("MeshItemType::Edge is not handled in globalIDString.");
205 OGS_FATAL("MeshItemType::Face is not handled in globalIDString.");
207 OGS_FATAL(
208 "MeshItemType::IntegrationPoint is not handled in "
209 "globalIDString.");
210 default:
211 return "";
212 }
213}
214
215} // end namespace MeshLib
216
217#include "Properties-impl.h"
#define OGS_FATAL(...)
Definition Error.h:10
Property manager on mesh items. Class Properties manages scalar, vector or matrix properties....
Properties & operator=(Properties &&properties)=default
std::vector< std::string > getPropertyVectorNames() const
std::map< std::string, PropertyVectorBase * > _properties
bool hasPropertyVector(std::string_view name) const
bool existsPropertyVector(std::string_view name) const
std::map< std::string, PropertyVectorBase * >::size_type size() const
Properties excludeCopyProperties(std::vector< std::size_t > const &exclude_elem_ids, std::vector< std::size_t > const &exclude_node_ids) const
std::map< std::string, PropertyVectorBase * >::const_iterator begin() const
PropertyVector< T > * createNewPropertyVector(std::string_view name, MeshItemType mesh_item_type, std::size_t n_components=1)
PropertyVector< T > const * getPropertyVector(std::string_view name) const
std::map< std::string, PropertyVectorBase * >::const_iterator end() const
Properties(Properties &&properties)=default
void removePropertyVector(std::string_view name)
Definition Properties.cpp:8
Properties & operator=(Properties const &properties)
PropertyVector< T > const * getPropertyVector(std::string_view name, MeshItemType const item_type, int const n_components) const
constexpr std::string_view getBulkIDString(MeshItemType mesh_item_type)
void applyToPropertyVectors(Properties const &properties, Function f)
constexpr std::string_view globalIDString(MeshLib::MeshItemType const mesh_item_type)