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/Error.h"
24#include "MathLib/Point3d.h"
25#include "MeshEnums.h"
26#include "Properties.h"
27
28namespace ApplicationUtils
29{
30 class NodeWiseMeshPartitioner;
31}
32
33namespace MeshLib
34{
35 class Node;
36 class Element;
37
41class Mesh
42{
43 /* friend functions: */
44 friend void removeMeshNodes(Mesh& mesh,
45 const std::vector<std::size_t>& nodes);
46
48
49public:
55 Mesh(std::string name,
56 std::vector<Node*>
57 nodes,
58 std::vector<Element*>
59 elements,
60 Properties const& properties = Properties());
61
63 Mesh(const Mesh &mesh);
64
65 Mesh(Mesh&& mesh);
66
67 Mesh& operator=(const Mesh& mesh) = delete;
68 Mesh& operator=(Mesh&& mesh) = delete;
69
71 virtual ~Mesh();
72
78 void shallowClean();
79
81 void addElement(Element* elem);
82
84 unsigned getDimension() const { return _mesh_dimension; }
85
87 const Node* getNode(std::size_t idx) const { return _nodes[idx]; }
88
90 const Element* getElement(std::size_t idx) const { return _elements[idx]; }
91
93 std::size_t getNumberOfElements() const { return _elements.size(); }
94
96 std::size_t getNumberOfNodes() const { return _nodes.size(); }
97
99 const std::string getName() const { return _name; }
100
102 std::vector<Node*> const& getNodes() const { return _nodes; }
103
105 std::vector<Element*> const& getElements() const { return _elements; }
106
108 void resetElementIDs();
109
111 void resetNodeIDs();
112
114 void setName(const std::string &name) { this->_name = name; }
115
117 std::size_t getID() const {return _id; }
118
120 std::size_t computeNumberOfBaseNodes() const;
121
123 bool hasNonlinearElement() const;
124
125 std::vector<Element const*> const& getElementsConnectedToNode(
126 std::size_t node_id) const;
127 std::vector<Element const*> const& getElementsConnectedToNode(
128 Node const& node) const;
129
131 Properties const& getProperties() const { return _properties; }
132
134 void setAxiallySymmetric(bool is_axial_symmetric) {
135 _is_axially_symmetric = is_axial_symmetric;
136 }
137
138protected:
141
143 void setDimension();
144
147 void setElementNeighbors();
148
149 std::size_t const _id;
152 std::pair<double, double> _node_distance;
153 std::string _name;
154 std::vector<Node*> _nodes;
155 std::vector<Element*> _elements;
157
158 std::vector<std::vector<Element const*>> _elements_connected_to_nodes;
159
161}; /* class */
162
165std::vector<std::vector<Node*>> calculateNodesConnectedByElements(
166 Mesh const& mesh);
167
169inline bool operator==(Mesh const& a, Mesh const& b)
170{
171 return a.getID() == b.getID();
172}
173
174inline bool operator!=(Mesh const& a, Mesh const& b)
175{
176 return !(a == b);
177}
178
184PropertyVector<int> const* materialIDs(Mesh const& mesh);
185PropertyVector<int>* materialIDs(Mesh& mesh);
186PropertyVector<std::size_t> const* bulkNodeIDs(Mesh const& mesh);
187PropertyVector<std::size_t> const* bulkElementIDs(Mesh const& mesh);
188
191bool isBaseNode(Node const& node,
192 std::vector<Element const*> const& elements_connected_to_node);
193
195std::pair<double, double> minMaxEdgeLength(
196 std::vector<Element*> const& elements);
197
200template <typename T>
201bool idsComparator(T const a, T const b)
202{
203 if constexpr (std::is_pointer_v<T>)
204 {
205 return a->getID() < b->getID();
206 }
207 else
208 {
209 return a.getID() < b.getID();
210 }
211}
212
214namespace views
215{
217inline constexpr ranges::views::view_closure ids =
218 ranges::views::transform([](auto const& a) { return a->getID(); });
219
221inline constexpr ranges::views::view_closure names =
222 ranges::views::transform([](auto const& a) { return a->getName(); });
223
224inline constexpr ranges::views::view_closure coords =
225 ranges::views::transform([](MathLib::Point3d const* n)
226 { return std::span(n->data(), n->data() + 3); });
227} // namespace views
228} // 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:63
bool isAxiallySymmetric() const
Definition: Mesh.h:133
Properties _properties
Definition: Mesh.h:156
std::vector< Node * > const & getNodes() const
Get the nodes-vector for the mesh.
Definition: Mesh.h:102
void calcEdgeLengthRange()
Set the minimum and maximum length over the edges of the mesh.
std::size_t const _id
Definition: Mesh.h:149
Mesh(Mesh &&mesh)
std::vector< std::vector< Element const * > > _elements_connected_to_nodes
Definition: Mesh.h:158
void setName(const std::string &name)
Changes the name of the mesh.
Definition: Mesh.h:114
void addElement(Element *elem)
Add an element to the mesh.
Definition: Mesh.cpp:144
std::vector< Element * > const & getElements() const
Get the element-vector for the mesh.
Definition: Mesh.h:105
unsigned _mesh_dimension
Definition: Mesh.h:150
std::size_t computeNumberOfBaseNodes() const
Get the number of base nodes.
Definition: Mesh.cpp:228
friend void removeMeshNodes(Mesh &mesh, const std::vector< std::size_t > &nodes)
std::string _name
Definition: Mesh.h:153
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:84
std::size_t getID() const
Get id of the mesh.
Definition: Mesh.h:117
void resetNodeIDs()
Resets the IDs of all mesh-nodes to their position in the node vector.
Definition: Mesh.cpp:149
const Node * getNode(std::size_t idx) const
Get the node with the given index.
Definition: Mesh.h:87
Properties & getProperties()
Definition: Mesh.h:130
const Element * getElement(std::size_t idx) const
Get the element with the given index.
Definition: Mesh.h:90
std::vector< Element * > _elements
Definition: Mesh.h:155
void setDimension()
Sets the dimension of the mesh.
Definition: Mesh.cpp:167
const std::string getName() const
Get name of the mesh.
Definition: Mesh.h:99
void resetElementIDs()
Resets the IDs of all mesh-elements to their position in the element vector.
Definition: Mesh.cpp:158
void setElementNeighbors()
Definition: Mesh.cpp:194
virtual ~Mesh()
Destructor.
Definition: Mesh.cpp:129
std::size_t getNumberOfNodes() const
Get the number of nodes.
Definition: Mesh.h:96
std::vector< Element const * > const & getElementsConnectedToNode(std::size_t node_id) const
Definition: Mesh.cpp:246
void setAxiallySymmetric(bool is_axial_symmetric)
Definition: Mesh.h:134
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:152
Mesh & operator=(const Mesh &mesh)=delete
void shallowClean()
Definition: Mesh.cpp:123
Properties const & getProperties() const
Definition: Mesh.h:131
bool hasNonlinearElement() const
Check if the mesh contains any nonlinear element.
Definition: Mesh.cpp:238
std::size_t getNumberOfElements() const
Get the number of elements.
Definition: Mesh.h:93
std::vector< Node * > _nodes
Definition: Mesh.h:154
bool _is_axially_symmetric
Definition: Mesh.h:160
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:217
constexpr ranges::views::view_closure coords
Definition: Mesh.h:224
constexpr ranges::views::view_closure names
For an element of a range view return its name.
Definition: Mesh.h:221
std::vector< std::vector< Node * > > calculateNodesConnectedByElements(Mesh const &mesh)
Definition: Mesh.cpp:298
bool idsComparator(T const a, T const b)
Definition: Mesh.h:201
PropertyVector< int > const * materialIDs(Mesh const &mesh)
Definition: Mesh.cpp:258
PropertyVector< std::size_t > const * bulkElementIDs(Mesh const &mesh)
Definition: Mesh.cpp:290
std::pair< double, double > minMaxEdgeLength(std::vector< Element * > const &elements)
Returns the minimum and maximum edge length for given elements.
Definition: Mesh.cpp:179
bool operator==(Mesh const &a, Mesh const &b)
Meshes are equal if their id's are equal.
Definition: Mesh.h:169
bool operator!=(Mesh const &a, Mesh const &b)
Definition: Mesh.h:174
bool isBaseNode(Node const &node, std::vector< Element const * > const &elements_connected_to_node)
Definition: Mesh.cpp:336
PropertyVector< std::size_t > const * bulkNodeIDs(Mesh const &mesh)
Definition: Mesh.cpp:282