OGS
Mesh.h
Go to the documentation of this file.
1
15#pragma once
16
17#include <cstdlib>
18#include <memory>
19#include <range/v3/view/transform.hpp>
20#include <string>
21#include <vector>
22
23#include "BaseLib/Algorithm.h"
24#include "BaseLib/Error.h"
25#include "MathLib/Point3d.h"
26#include "MeshEnums.h"
27#include "Properties.h"
28
29namespace ApplicationUtils
30{
31 class NodeWiseMeshPartitioner;
32}
33
34namespace MeshLib
35{
36 class Node;
37 class Element;
38
42class Mesh
43{
44 /* friend functions: */
45 friend void removeMeshNodes(Mesh& mesh,
46 const std::vector<std::size_t>& nodes);
47
49
50public:
58 Mesh(std::string name,
59 std::vector<Node*>
60 nodes,
61 std::vector<Element*>
62 elements,
63 bool const compute_element_neighbors = false,
64 Properties const& properties = Properties());
65
67 Mesh(const Mesh &mesh);
68
69 Mesh(Mesh&& mesh);
70
71 Mesh& operator=(const Mesh& mesh) = delete;
72 Mesh& operator=(Mesh&& mesh) = delete;
73
75 virtual ~Mesh();
76
82 void shallowClean();
83
85 void addElement(Element* elem);
86
88 unsigned getDimension() const { return _mesh_dimension; }
89
91 const Node* getNode(std::size_t idx) const { return _nodes[idx]; }
92
94 const Element* getElement(std::size_t idx) const { return _elements[idx]; }
95
97 std::size_t getNumberOfElements() const { return _elements.size(); }
98
100 std::size_t getNumberOfNodes() const { return _nodes.size(); }
101
103 const std::string getName() const { return _name; }
104
106 std::vector<Node*> const& getNodes() const { return _nodes; }
107
109 std::vector<Element*> const& getElements() const { return _elements; }
110
112 void resetElementIDs();
113
115 void resetNodeIDs();
116
118 void setName(const std::string &name) { this->_name = name; }
119
121 std::size_t getID() const {return _id; }
122
124 std::size_t computeNumberOfBaseNodes() const;
125
127 bool hasNonlinearElement() const;
128
129 std::vector<Element const*> const& getElementsConnectedToNode(
130 std::size_t node_id) const;
131 std::vector<Element const*> const& getElementsConnectedToNode(
132 Node const& node) const;
133
135 Properties const& getProperties() const { return _properties; }
136
138 void setAxiallySymmetric(bool is_axial_symmetric) {
139 _is_axially_symmetric = is_axial_symmetric;
140 }
141
142protected:
145
147 void setDimension();
148
151 void setElementNeighbors();
152
153 std::size_t const _id;
156 std::pair<double, double> _node_distance;
157 std::string _name;
158 std::vector<Node*> _nodes;
159 std::vector<Element*> _elements;
161
162 std::vector<std::vector<Element const*>> _elements_connected_to_nodes;
163
166}; /* class */
167
170std::vector<std::vector<Node*>> calculateNodesConnectedByElements(
171 Mesh const& mesh);
172
174inline bool operator==(Mesh const& a, Mesh const& b)
175{
176 return a.getID() == b.getID();
177}
178
179inline bool operator!=(Mesh const& a, Mesh const& b)
180{
181 return !(a == b);
182}
183
189PropertyVector<int> const* materialIDs(Mesh const& mesh);
190PropertyVector<int>* materialIDs(Mesh& mesh);
191PropertyVector<std::size_t> const* bulkNodeIDs(Mesh const& mesh);
192PropertyVector<std::size_t> const* bulkElementIDs(Mesh const& mesh);
193
196bool isBaseNode(Node const& node,
197 std::vector<Element const*> const& elements_connected_to_node);
198
200std::pair<double, double> minMaxEdgeLength(
201 std::vector<Element*> const& elements);
202
205template <typename T>
206bool idsComparator(T const a, T const b)
207{
208 if constexpr (std::is_pointer_v<T>)
209 {
210 return a->getID() < b->getID();
211 }
212 else
213 {
214 return a.getID() < b.getID();
215 }
216}
217
218Mesh& findMeshByName(std::vector<std::unique_ptr<Mesh>> const& meshes,
219 std::string_view const name);
220
222namespace views
223{
225inline constexpr ranges::views::view_closure ids =
226 ranges::views::transform([](auto const& a) { return a->getID(); });
227
229inline constexpr ranges::views::view_closure names =
230 ranges::views::transform([](auto const& a) { return a->getName(); });
231
232inline constexpr ranges::views::view_closure coords =
233 ranges::views::transform([](MathLib::Point3d const* n)
234 { return std::span(n->data(), n->data() + 3); });
235} // namespace views
236} // namespace MeshLib
Definition of mesh-related Enumerations.
Definition of the class Properties that implements a container of properties.
Definition of the Point3d class.
const double * data() const
Definition Point3d.h:60
bool isAxiallySymmetric() const
Definition Mesh.h:137
Properties _properties
Definition Mesh.h:160
std::vector< Node * > const & getNodes() const
Get the nodes-vector for the mesh.
Definition Mesh.h:106
void calcEdgeLengthRange()
Set the minimum and maximum length over the edges of the mesh.
std::size_t const _id
Definition Mesh.h:153
bool const _compute_element_neighbors
Definition Mesh.h:165
Mesh(Mesh &&mesh)
std::vector< std::vector< Element const * > > _elements_connected_to_nodes
Definition Mesh.h:162
void setName(const std::string &name)
Changes the name of the mesh.
Definition Mesh.h:118
void addElement(Element *elem)
Add an element to the mesh.
Definition Mesh.cpp:154
std::vector< Element * > const & getElements() const
Get the element-vector for the mesh.
Definition Mesh.h:109
unsigned _mesh_dimension
Definition Mesh.h:154
std::size_t computeNumberOfBaseNodes() const
Get the number of base nodes.
Definition Mesh.cpp:238
friend void removeMeshNodes(Mesh &mesh, const std::vector< std::size_t > &nodes)
std::string _name
Definition Mesh.h:157
Mesh & operator=(Mesh &&mesh)=delete
unsigned getDimension() const
Returns the dimension of the mesh (determined by the maximum dimension over all elements).
Definition Mesh.h:88
std::size_t getID() const
Get id of the mesh.
Definition Mesh.h:121
void resetNodeIDs()
Resets the IDs of all mesh-nodes to their position in the node vector.
Definition Mesh.cpp:159
const Node * getNode(std::size_t idx) const
Get the node with the given index.
Definition Mesh.h:91
Properties & getProperties()
Definition Mesh.h:134
const Element * getElement(std::size_t idx) const
Get the element with the given index.
Definition Mesh.h:94
std::vector< Element * > _elements
Definition Mesh.h:159
void setDimension()
Sets the dimension of the mesh.
Definition Mesh.cpp:177
const std::string getName() const
Get name of the mesh.
Definition Mesh.h:103
void resetElementIDs()
Resets the IDs of all mesh-elements to their position in the element vector.
Definition Mesh.cpp:168
void setElementNeighbors()
Definition Mesh.cpp:204
virtual ~Mesh()
Destructor.
Definition Mesh.cpp:139
Mesh(std::string name, std::vector< Node * > nodes, std::vector< Element * > elements, bool const compute_element_neighbors=false, Properties const &properties=Properties())
Definition Mesh.cpp:62
std::size_t getNumberOfNodes() const
Get the number of nodes.
Definition Mesh.h:100
std::vector< Element const * > const & getElementsConnectedToNode(std::size_t node_id) const
Definition Mesh.cpp:256
void setAxiallySymmetric(bool is_axial_symmetric)
Definition Mesh.h:138
std::pair< double, double > _node_distance
The minimal and maximal distance of nodes within an element over all elements in the mesh.
Definition Mesh.h:156
Mesh & operator=(const Mesh &mesh)=delete
void shallowClean()
Definition Mesh.cpp:133
Properties const & getProperties() const
Definition Mesh.h:135
bool hasNonlinearElement() const
Check if the mesh contains any nonlinear element.
Definition Mesh.cpp:248
std::size_t getNumberOfElements() const
Get the number of elements.
Definition Mesh.h:97
std::vector< Node * > _nodes
Definition Mesh.h:158
bool _is_axially_symmetric
Definition Mesh.h:164
Property manager on mesh items. Class Properties manages scalar, vector or matrix properties....
Definition Properties.h:36
constexpr ranges::views::view_closure ids
For an element of a range view return its id.
Definition Mesh.h:225
constexpr ranges::views::view_closure coords
Definition Mesh.h:232
constexpr ranges::views::view_closure names
For an element of a range view return its name.
Definition Mesh.h:229
std::vector< std::vector< Node * > > calculateNodesConnectedByElements(Mesh const &mesh)
Definition Mesh.cpp:308
Mesh & findMeshByName(std::vector< std::unique_ptr< Mesh > > const &meshes, std::string_view const name)
Definition Mesh.cpp:364
bool idsComparator(T const a, T const b)
Definition Mesh.h:206
PropertyVector< int > const * materialIDs(Mesh const &mesh)
Definition Mesh.cpp:268
PropertyVector< std::size_t > const * bulkElementIDs(Mesh const &mesh)
Definition Mesh.cpp:300
std::pair< double, double > minMaxEdgeLength(std::vector< Element * > const &elements)
Returns the minimum and maximum edge length for given elements.
Definition Mesh.cpp:189
bool operator==(Mesh const &a, Mesh const &b)
Meshes are equal if their id's are equal.
Definition Mesh.h:174
bool operator!=(Mesh const &a, Mesh const &b)
Definition Mesh.h:179
bool isBaseNode(Node const &node, std::vector< Element const * > const &elements_connected_to_node)
Definition Mesh.cpp:346
PropertyVector< std::size_t > const * bulkNodeIDs(Mesh const &mesh)
Definition Mesh.cpp:292