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
67 template <typename T>
69 std::string const& name,
70 std::size_t n_prop_groups,
71 std::vector<std::size_t> const& item2group_mapping,
72 MeshItemType mesh_item_type,
73 std::size_t n_components = 1);
74
78 template <typename T>
79 bool existsPropertyVector(std::string_view name) const;
80
83 template <typename T>
84 bool existsPropertyVector(std::string_view name,
85 MeshItemType const mesh_item_type,
86 int const number_of_components) const;
87
90 template <typename T>
91 PropertyVector<T> const* getPropertyVector(std::string_view name) const;
92
95 template <typename T>
96 PropertyVector<T>* getPropertyVector(std::string_view name);
97
101 template <typename T>
102 PropertyVector<T> const* getPropertyVector(std::string_view name,
103 MeshItemType const item_type,
104 int const n_components) const;
105
109 template <typename T>
110 PropertyVector<T>* getPropertyVector(std::string_view name,
111 MeshItemType const item_type,
112 int const n_components);
113
114 void removePropertyVector(std::string_view name);
115
119 bool hasPropertyVector(std::string_view name) const;
120
125 template <typename T>
126 bool hasPropertyVector(std::string_view name,
127 MeshItemType const item_type) const;
128
129 std::vector<std::string> getPropertyVectorNames() const;
130 std::vector<std::string> getPropertyVectorNames(
131 MeshLib::MeshItemType t) const;
132
138 std::vector<std::size_t> const& exclude_elem_ids,
139 std::vector<std::size_t> const& exclude_node_ids) const;
140
145 std::vector<MeshItemType> const& exclude_mesh_item_types) const;
146
147 Properties() = default;
148
149 Properties(Properties const& properties);
150 Properties(Properties&& properties) = default;
151 Properties& operator=(Properties const& properties);
152 Properties& operator=(Properties&& properties) = default;
153
154 ~Properties();
155
156 std::map<std::string, PropertyVectorBase*>::const_iterator begin() const;
157 std::map<std::string, PropertyVectorBase*>::const_iterator end() const;
158 std::map<std::string, PropertyVectorBase*>::iterator begin();
159 std::map<std::string, PropertyVectorBase*>::iterator end();
160 std::map<std::string, PropertyVectorBase*>::size_type size() const;
161 // Counts properties of given mesh item type.
162 std::map<std::string, PropertyVectorBase*>::size_type size(
163 MeshItemType const mesh_item_type) const;
164
165private:
168 std::map<std::string, PropertyVectorBase*> _properties;
169}; // end class
170
176template <typename Function>
177void applyToPropertyVectors(Properties const& properties, Function f);
178
183constexpr std::string_view getBulkIDString(MeshItemType mesh_item_type)
184{
185 switch (mesh_item_type)
186 {
188 return "bulk_node_ids";
189 break;
191 return "bulk_element_ids";
192 break;
194 return "bulk_edge_ids";
195 break;
197 return "bulk_face_ids";
198 break;
200 OGS_FATAL("MeshItemType::IntegrationPoint is not handled.");
201 return "";
202 break;
203 default:
204 OGS_FATAL(
205 "Unknown mesh item type '{}'. At the moment mapping names only "
206 "for mesh item types 'Node', 'Cell', 'Edge', and 'Face' are "
207 "specified.",
208 static_cast<int>(mesh_item_type));
209 return "";
210 }
211}
212
213constexpr std::string_view globalIDString(
214 MeshLib::MeshItemType const mesh_item_type)
215{
216 switch (mesh_item_type)
217 {
219 {
220 return "global_node_ids";
221 }
223 {
224 return "global_element_ids";
225 }
227 OGS_FATAL("MeshItemType::Edge is not handled in globalIDString.");
229 OGS_FATAL("MeshItemType::Face is not handled in globalIDString.");
231 OGS_FATAL(
232 "MeshItemType::IntegrationPoint is not handled in "
233 "globalIDString.");
234 default:
235 return "";
236 }
237}
238
239} // end namespace MeshLib
240
241#include "Properties-impl.h"
#define OGS_FATAL(...)
Definition Error.h:19
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)