OGS
TemplateElement-impl.h
Go to the documentation of this file.
1
10
11#include <algorithm>
12
13namespace MeshLib
14{
15template <class ELEMENT_RULE>
17 std::size_t id)
18 : Element(id)
19{
20 std::copy_n(nodes, n_all_nodes, std::begin(_nodes));
21 delete[] nodes;
22 this->_neighbors = new Element*[ELEMENT_RULE::n_neighbors];
23 std::fill(this->_neighbors, this->_neighbors + ELEMENT_RULE::n_neighbors,
24 nullptr);
25
26 this->space_dimension_ = ELEMENT_RULE::dimension;
27}
28
29template <class ELEMENT_RULE>
31 std::array<Node*, n_all_nodes> const& nodes, std::size_t id)
32 : Element(id), _nodes{nodes}
33{
34 this->_neighbors = new Element*[ELEMENT_RULE::n_neighbors];
35 std::fill(this->_neighbors, this->_neighbors + ELEMENT_RULE::n_neighbors,
36 nullptr);
37
38 this->space_dimension_ = ELEMENT_RULE::dimension;
39}
40
41template <class ELEMENT_RULE>
44 : Element(e.getID()), _nodes{e._nodes}
45{
46 this->_neighbors = new Element*[ELEMENT_RULE::n_neighbors];
47 for (unsigned i = 0; i < ELEMENT_RULE::n_neighbors; i++)
48 {
49 this->_neighbors[i] = e._neighbors[i];
50 }
51
53}
54
55template <class ELEMENT_RULE>
57{
58 return ELEMENT_RULE::computeVolume(_nodes.data());
59}
60
61namespace details
62{
63
64template<unsigned N>
65bool isEdge(unsigned const (&edge_nodes)[N], unsigned idx1, unsigned idx2)
66{
67 if (edge_nodes[0] == idx1 && edge_nodes[1] == idx2)
68 {
69 return true;
70 }
71 if (edge_nodes[1] == idx1 && edge_nodes[0] == idx2)
72 {
73 return true;
74 }
75
76 return false;
77}
78
79inline bool
80isEdge(unsigned const (&/*edge_nodes*/)[1], unsigned /*idx1*/, unsigned /*idx2*/)
81{
82 return false;
83}
84
85} // namespace details
86
87
88template <class ELEMENT_RULE>
89bool TemplateElement<ELEMENT_RULE>::isEdge(unsigned idx1, unsigned idx2) const
90{
91 for (unsigned i(0); i<getNumberOfEdges(); i++)
92 {
93 if (details::isEdge(ELEMENT_RULE::edge_nodes[i], idx1, idx2))
94 {
95 return true;
96 }
97 }
98 return false;
99}
100
101template <class ELEMENT_RULE>
102const Node* TemplateElement<ELEMENT_RULE>::getNode(unsigned const idx) const
103{
104#ifndef NDEBUG
105 if (idx >= getNumberOfNodes())
106 {
107 ERR("Error in MeshLib::TemplateElement::getNode() - Index {:d} in {:s}",
109 return nullptr;
110 }
111#endif
112 return _nodes[idx];
113}
114
115template <class ELEMENT_RULE>
117{
118#ifndef NDEBUG
119 if (idx >= getNumberOfNodes())
120 {
121 ERR("Error in MeshLib::TemplateElement::getNode() - Index {:d} in {:s}",
123 return nullptr;
124 }
125#endif
126 return _nodes[idx];
127}
128
129template <class ELEMENT_RULE>
131{
132#ifndef NDEBUG
133 if (idx < getNumberOfNodes())
134#endif
135 {
136 _nodes[idx] = node;
137 }
138}
139
140} // namespace MeshLib
void ERR(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:48
Element ** _neighbors
Definition Element.h:204
Element(std::size_t id)
Definition Element.cpp:25
constexpr std::span< Node *const > nodes() const
Span of element's nodes, their pointers actually.
Definition Element.h:74
std::size_t getID() const
Returns the ID of the element.
Definition Element.h:91
unsigned space_dimension_
Dimension of the space, where the element exists.
Definition Element.h:192
std::array< Node *, n_all_nodes > _nodes
unsigned getNumberOfNodes() const override
Get the number of all nodes for this element.
bool isEdge(unsigned idx1, unsigned idx2) const override
Returns true if these two indices form an edge and false otherwise.
MeshElemType getGeomType() const override
Get the type of this element.
static const unsigned n_all_nodes
Constant: The number of all nodes for this element.
void setNode(unsigned idx, Node *node) override
TemplateElement(Node *nodes[n_all_nodes], std::size_t id=std::numeric_limits< std::size_t >::max())
double getContent() const override final
Returns the length, area or volume of a 1D, 2D or 3D element.
unsigned getNumberOfEdges() const override
Get the number of edges for this element.
const Node * getNode(unsigned idx) const override
bool isEdge(unsigned const (&edge_nodes)[N], unsigned idx1, unsigned idx2)
std::string MeshElemType2String(const MeshElemType t)
Given a MeshElemType this returns the appropriate string.
Definition MeshEnums.cpp:21