OGS
TemplateElement-impl.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#include <algorithm>
5
6namespace MeshLib
7{
8template <class ELEMENT_RULE>
10 std::size_t id)
11 : Element(id)
12{
13 std::copy_n(nodes, n_all_nodes, std::begin(_nodes));
14 delete[] nodes;
15 this->_neighbors = new Element*[ELEMENT_RULE::n_neighbors];
16 std::fill(this->_neighbors, this->_neighbors + ELEMENT_RULE::n_neighbors,
17 nullptr);
18
19 this->space_dimension_ = ELEMENT_RULE::dimension;
20}
21
22template <class ELEMENT_RULE>
24 std::array<Node*, n_all_nodes> const& nodes, std::size_t id)
25 : Element(id), _nodes{nodes}
26{
27 this->_neighbors = new Element*[ELEMENT_RULE::n_neighbors];
28 std::fill(this->_neighbors, this->_neighbors + ELEMENT_RULE::n_neighbors,
29 nullptr);
30
31 this->space_dimension_ = ELEMENT_RULE::dimension;
32}
33
34template <class ELEMENT_RULE>
37 : Element(e.getID()), _nodes{e._nodes}
38{
39 this->_neighbors = new Element*[ELEMENT_RULE::n_neighbors];
40 for (unsigned i = 0; i < ELEMENT_RULE::n_neighbors; i++)
41 {
42 this->_neighbors[i] = e._neighbors[i];
43 }
44
46}
47
48template <class ELEMENT_RULE>
50{
51 return ELEMENT_RULE::computeVolume(_nodes.data());
52}
53
54namespace details
55{
56
57template<unsigned N>
58bool isEdge(unsigned const (&edge_nodes)[N], unsigned idx1, unsigned idx2)
59{
60 if (edge_nodes[0] == idx1 && edge_nodes[1] == idx2)
61 {
62 return true;
63 }
64 if (edge_nodes[1] == idx1 && edge_nodes[0] == idx2)
65 {
66 return true;
67 }
68
69 return false;
70}
71
72inline bool
73isEdge(unsigned const (&/*edge_nodes*/)[1], unsigned /*idx1*/, unsigned /*idx2*/)
74{
75 return false;
76}
77
78} // namespace details
79
80
81template <class ELEMENT_RULE>
82bool TemplateElement<ELEMENT_RULE>::isEdge(unsigned idx1, unsigned idx2) const
83{
84 for (unsigned i(0); i<getNumberOfEdges(); i++)
85 {
86 if (details::isEdge(ELEMENT_RULE::edge_nodes[i], idx1, idx2))
87 {
88 return true;
89 }
90 }
91 return false;
92}
93
94template <class ELEMENT_RULE>
95const Node* TemplateElement<ELEMENT_RULE>::getNode(unsigned const idx) const
96{
97#ifndef NDEBUG
98 if (idx >= getNumberOfNodes())
99 {
100 ERR("Error in MeshLib::TemplateElement::getNode() - Index {:d} in {:s}",
102 return nullptr;
103 }
104#endif
105 return _nodes[idx];
106}
107
108template <class ELEMENT_RULE>
110{
111#ifndef NDEBUG
112 if (idx >= getNumberOfNodes())
113 {
114 ERR("Error in MeshLib::TemplateElement::getNode() - Index {:d} in {:s}",
116 return nullptr;
117 }
118#endif
119 return _nodes[idx];
120}
121
122template <class ELEMENT_RULE>
124{
125#ifndef NDEBUG
126 if (idx < getNumberOfNodes())
127#endif
128 {
129 _nodes[idx] = node;
130 }
131}
132
133} // namespace MeshLib
void ERR(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:40
Element ** _neighbors
Definition Element.h:193
Element(std::size_t id)
Definition Element.cpp:14
constexpr std::span< Node *const > nodes() const
Span of element's nodes, their pointers actually.
Definition Element.h:63
std::size_t getID() const
Returns the ID of the element.
Definition Element.h:80
unsigned space_dimension_
Dimension of the space, where the element exists.
Definition Element.h:181
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:10