OGS
Element.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 <spdlog/fmt/ostr.h>
7
8#include <limits>
9#include <optional>
10#include <span>
11
12#include "MathLib/Point3d.h"
14#include "MeshLib/Mesh.h"
15#include "MeshLib/MeshEnums.h"
16
17namespace MeshLib
18{
19class Node;
20
25{
26 friend class Mesh;
27
28public:
35 std::optional<unsigned> addNeighbor(Element* e);
36
38 virtual double getContent() const = 0;
39
49 virtual const Node* getNode(unsigned idx) const = 0;
50 virtual Node* getNode(unsigned idx) = 0;
51
57 virtual void setNode(unsigned idx, Node* node) = 0;
58
60 virtual Node* const* getNodes() const = 0;
61
63 constexpr std::span<Node* const> nodes() const
64 {
65 return {getNodes(), getNumberOfNodes()};
66 }
67
69 virtual constexpr unsigned getDimension() const = 0;
70
72 virtual const Element* getEdge(unsigned i) const = 0;
73
75 virtual const Element* getFace(unsigned i) const = 0;
76
77 virtual const Element* getBoundary(unsigned i) const = 0;
78
80 std::size_t getID() const { return _id; }
81
82 virtual unsigned getNumberOfBoundaries() const = 0;
83
85 virtual unsigned getNumberOfEdges() const = 0;
86
88 virtual unsigned getNumberOfFaces() const = 0;
89
91 virtual const Element* getNeighbor(unsigned i) const = 0;
92
94 virtual unsigned getNumberOfNeighbors() const = 0;
95
99 virtual unsigned getNumberOfBaseNodes() const = 0;
100
103 virtual unsigned getNumberOfNodes() const = 0;
104
109 virtual MeshElemType getGeomType() const = 0;
110
115 virtual CellType getCellType() const = 0;
116
119 virtual bool isBoundaryElement() const;
120
122 virtual bool isEdge(unsigned i, unsigned j) const = 0;
123
131 virtual bool isPntInElement(
132 MathLib::Point3d const& pnt,
133 double eps = std::numeric_limits<double>::epsilon()) const = 0;
134
138 virtual ElementErrorCode validate() const = 0;
139
141 virtual ~Element();
142
149 virtual Element* clone() const = 0;
150
157 virtual Element* clone(Node** nodes, std::size_t id) const = 0;
158
164 virtual double computeVolume() = 0;
165
167 virtual unsigned identifyFace(Node const* nodes[3]) const = 0;
168
173 virtual bool testElementNodeOrder() const = 0;
174
176 virtual Node* getEdgeNode(unsigned edge_id, unsigned node_id) const = 0;
177
178 friend std::ostream& operator<<(std::ostream& os, Element const& e);
179
181 unsigned space_dimension_ = 3u;
182
183protected:
186 explicit Element(std::size_t id);
187
189 void setID(std::size_t id) { _id = id; }
190
191 std::size_t _id;
192
196 void setNeighbor(Element* neighbor, unsigned const face_id);
197}; /* class */
198
200bool areNeighbors(Element const* const element, Element const* const other);
201
203bool hasZeroVolume(MeshLib::Element const& element);
204
207
209std::pair<double, double> computeSqrNodeDistanceRange(
210 MeshLib::Element const& element, bool const check_allnodes = true);
211
213std::pair<double, double> computeSqrEdgeLengthRange(Element const& element);
214
223bool isPointInElementXY(MathLib::Point3d const& p, Element const& e);
224
226unsigned getNodeIDinElement(Element const& element, const Node* node);
227
239std::size_t getNodeIndex(Element const& element, unsigned idx);
240
241} // namespace MeshLib
242
243namespace fmt
244{
245template <>
246struct formatter<::MeshLib::Element> : ostream_formatter
247{
248};
249} // namespace fmt
Collects error flags for mesh elements.
virtual MeshElemType getGeomType() const =0
void setNeighbor(Element *neighbor, unsigned const face_id)
Definition Element.cpp:21
virtual ~Element()
Destructor.
Definition Element.cpp:16
virtual const Element * getEdge(unsigned i) const =0
Returns the i-th edge of the element.
friend std::ostream & operator<<(std::ostream &os, Element const &e)
Definition Element.cpp:97
virtual CellType getCellType() const =0
virtual bool isPntInElement(MathLib::Point3d const &pnt, double eps=std::numeric_limits< double >::epsilon()) const =0
virtual unsigned getNumberOfNodes() const =0
virtual ElementErrorCode validate() const =0
virtual Node * getNode(unsigned idx)=0
virtual Element * clone() const =0
virtual double getContent() const =0
Returns the length, area or volume of a 1D, 2D or 3D element.
Element ** _neighbors
Definition Element.h:193
virtual double computeVolume()=0
void setID(std::size_t id)
Sets the element ID.
Definition Element.h:189
Element(std::size_t id)
Definition Element.cpp:14
virtual unsigned getNumberOfBoundaries() const =0
virtual unsigned getNumberOfFaces() const =0
Get the number of faces for this element.
virtual const Element * getFace(unsigned i) const =0
Returns the i-th face of the element.
virtual unsigned getNumberOfBaseNodes() const =0
virtual bool isBoundaryElement() const
Definition Element.cpp:90
virtual bool testElementNodeOrder() const =0
virtual const Node * getNode(unsigned idx) const =0
friend class Mesh
Definition Element.h:26
virtual unsigned getNumberOfNeighbors() const =0
Get the number of neighbors for this element.
virtual void setNode(unsigned idx, Node *node)=0
std::size_t _id
Definition Element.h:191
virtual unsigned getNumberOfEdges() const =0
Get the number of edges for this element.
virtual bool isEdge(unsigned i, unsigned j) const =0
Returns true if these two indices form an edge and false otherwise.
virtual constexpr unsigned getDimension() const =0
Get dimension of the mesh element.
virtual Element * clone(Node **nodes, std::size_t id) const =0
std::optional< unsigned > addNeighbor(Element *e)
Tries to add an element e as neighbour to this element. If the elements really are neighbours,...
Definition Element.cpp:31
constexpr std::span< Node *const > nodes() const
Span of element's nodes, their pointers actually.
Definition Element.h:63
virtual Node *const * getNodes() const =0
Get array of element nodes.
std::size_t getID() const
Returns the ID of the element.
Definition Element.h:80
virtual const Element * getNeighbor(unsigned i) const =0
Get the specified neighbor.
unsigned space_dimension_
Dimension of the space, where the element exists.
Definition Element.h:181
virtual Node * getEdgeNode(unsigned edge_id, unsigned node_id) const =0
Return a specific edge node.
virtual const Element * getBoundary(unsigned i) const =0
virtual unsigned identifyFace(Node const *nodes[3]) const =0
Returns the ID of a face given an array of nodes.
std::pair< double, double > computeSqrNodeDistanceRange(MeshLib::Element const &element, bool const check_allnodes)
Compute the minimum and maximum node distances for this element.
Definition Element.cpp:143
CellType
Types of mesh elements supported by OpenGeoSys.
Definition MeshEnums.h:53
bool isPointInElementXY(MathLib::Point3d const &p, Element const &e)
Definition Element.cpp:178
bool hasZeroVolume(MeshLib::Element const &element)
Returns true if the element has zero length/area/volume.
Definition Element.cpp:126
std::pair< double, double > computeSqrEdgeLengthRange(Element const &element)
Compute the minimum and maximum squared edge length for this element.
Definition Element.cpp:163
std::size_t getNodeIndex(Element const &element, unsigned const idx)
Definition Element.cpp:226
unsigned getNodeIDinElement(Element const &element, const MeshLib::Node *node)
Returns the position of the given node in the node array of this element.
Definition Element.cpp:213
MathLib::Point3d getCenterOfGravity(Element const &element)
Calculates the center of gravity for the mesh element.
Definition Element.cpp:131
bool areNeighbors(Element const *const element, Element const *const other)
Returns true if elem is a neighbour of this element and false otherwise.
Definition Element.cpp:113
MeshElemType
Types of mesh elements supported by OpenGeoSys. Values are from VTKCellType enum.
Definition MeshEnums.h:37
Definition AABB.h:277