Loading [MathJax]/extensions/tex2jax.js
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/iota.hpp>
20#include <range/v3/view/transform.hpp>
21#include <string>
22#include <vector>
23
24#include "BaseLib/Algorithm.h"
25#include "BaseLib/Error.h"
26#include "Location.h"
27#include "MathLib/Point3d.h"
28#include "MeshEnums.h"
29#include "Properties.h"
30
31namespace ApplicationUtils
32{
33 class NodeWiseMeshPartitioner;
34}
35
36namespace MeshLib
37{
38 class Node;
39 class Element;
40
44class Mesh
45{
46 /* friend functions: */
47 friend void removeMeshNodes(Mesh& mesh,
48 const std::vector<std::size_t>& nodes);
49
51
52public:
60 Mesh(std::string name,
61 std::vector<Node*>
62 nodes,
63 std::vector<Element*>
64 elements,
65 bool const compute_element_neighbors = false,
66 Properties const& properties = Properties());
67
69 Mesh(const Mesh &mesh);
70
71 Mesh(Mesh&& mesh);
72
73 Mesh& operator=(const Mesh& mesh) = delete;
74 Mesh& operator=(Mesh&& mesh) = delete;
75
77 virtual ~Mesh();
78
84 void shallowClean();
85
87 void addElement(Element* elem);
88
90 unsigned getDimension() const { return _mesh_dimension; }
91
93 const Node* getNode(std::size_t idx) const { return _nodes[idx]; }
94
96 const Element* getElement(std::size_t idx) const { return _elements[idx]; }
97
99 std::size_t getNumberOfElements() const { return _elements.size(); }
100
102 std::size_t getNumberOfNodes() const { return _nodes.size(); }
103
105 const std::string getName() const { return _name; }
106
108 std::vector<Node*> const& getNodes() const { return _nodes; }
109
111 std::vector<Element*> const& getElements() const { return _elements; }
112
114 void resetElementIDs();
115
117 void resetNodeIDs();
118
120 void setName(const std::string &name) { this->_name = name; }
121
123 std::size_t getID() const {return _id; }
124
126 std::size_t computeNumberOfBaseNodes() const;
127
129 bool hasNonlinearElement() const;
130
131 std::vector<Element const*> const& getElementsConnectedToNode(
132 std::size_t node_id) const;
133 std::vector<Element const*> const& getElementsConnectedToNode(
134 Node const& node) const;
135
137 Properties const& getProperties() const { return _properties; }
138
140 void setAxiallySymmetric(bool is_axial_symmetric) {
141 _is_axially_symmetric = is_axial_symmetric;
142 }
143
144protected:
147
149 void setDimension();
150
153 void setElementNeighbors();
154
155 std::size_t const _id;
158 std::pair<double, double> _node_distance;
159 std::string _name;
160 std::vector<Node*> _nodes;
161 std::vector<Element*> _elements;
163
164 std::vector<std::vector<Element const*>> _elements_connected_to_nodes;
165
168}; /* class */
169
172std::vector<std::vector<Node*>> calculateNodesConnectedByElements(
173 Mesh const& mesh);
174
176inline bool operator==(Mesh const& a, Mesh const& b)
177{
178 return a.getID() == b.getID();
179}
180
181inline bool operator!=(Mesh const& a, Mesh const& b)
182{
183 return !(a == b);
184}
185
191PropertyVector<int> const* materialIDs(Mesh const& mesh);
192PropertyVector<int>* materialIDs(Mesh& mesh);
193PropertyVector<std::size_t> const* bulkNodeIDs(Mesh const& mesh);
194PropertyVector<std::size_t> const* bulkElementIDs(Mesh const& mesh);
195
198bool isBaseNode(Node const& node,
199 std::vector<Element const*> const& elements_connected_to_node);
200
202std::pair<double, double> minMaxEdgeLength(
203 std::vector<Element*> const& elements);
204
207template <typename T>
208bool idsComparator(T const a, T const b)
209{
210 if constexpr (std::is_pointer_v<T>)
211 {
212 return a->getID() < b->getID();
213 }
214 else
215 {
216 return a.getID() < b.getID();
217 }
218}
219
220Mesh& findMeshByName(std::vector<std::unique_ptr<Mesh>> const& meshes,
221 std::string_view const name);
222
224namespace views
225{
227inline constexpr ranges::views::view_closure ids =
228 ranges::views::transform([](auto const& a) { return a->getID(); });
229
231inline constexpr ranges::views::view_closure names =
232 ranges::views::transform([](auto const& a) { return a->getName(); });
233
234inline constexpr ranges::views::view_closure coords =
235 ranges::views::transform([](MathLib::Point3d const* n)
236 { return std::span(n->data(), n->data() + 3); });
237
238inline auto meshLocations(Mesh const& mesh, MeshItemType const item_type)
239{
240 return ranges::views::iota(std::size_t{0}, mesh.getNumberOfNodes()) |
241 ranges::views::transform(
242 [mesh_id = mesh.getID(), item_type](std::size_t const n)
243 { return Location{mesh_id, item_type, n}; });
244}
245} // namespace views
246} // 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:139
Properties _properties
Definition Mesh.h:162
std::vector< Node * > const & getNodes() const
Get the nodes-vector for the mesh.
Definition Mesh.h:108
void calcEdgeLengthRange()
Set the minimum and maximum length over the edges of the mesh.
std::size_t const _id
Definition Mesh.h:155
bool const _compute_element_neighbors
Definition Mesh.h:167
Mesh(Mesh &&mesh)
std::vector< std::vector< Element const * > > _elements_connected_to_nodes
Definition Mesh.h:164
void setName(const std::string &name)
Changes the name of the mesh.
Definition Mesh.h:120
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:111
unsigned _mesh_dimension
Definition Mesh.h:156
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:159
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:90
std::size_t getID() const
Get id of the mesh.
Definition Mesh.h:123
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:93
Properties & getProperties()
Definition Mesh.h:136
const Element * getElement(std::size_t idx) const
Get the element with the given index.
Definition Mesh.h:96
std::vector< Element * > _elements
Definition Mesh.h:161
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:105
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:102
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:140
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:158
Mesh & operator=(const Mesh &mesh)=delete
void shallowClean()
Definition Mesh.cpp:133
Properties const & getProperties() const
Definition Mesh.h:137
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:99
std::vector< Node * > _nodes
Definition Mesh.h:160
bool _is_axially_symmetric
Definition Mesh.h:166
Property manager on mesh items. Class Properties manages scalar, vector or matrix properties....
Definition Properties.h:33
constexpr ranges::views::view_closure ids
For an element of a range view return its id.
Definition Mesh.h:227
auto meshLocations(Mesh const &mesh, MeshItemType const item_type)
Definition Mesh.h:238
constexpr ranges::views::view_closure coords
Definition Mesh.h:234
constexpr ranges::views::view_closure names
For an element of a range view return its name.
Definition Mesh.h:231
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:208
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:176
bool operator!=(Mesh const &a, Mesh const &b)
Definition Mesh.h:181
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