OGS
TemplateElement-impl.h
Go to the documentation of this file.
1 
11 #include <algorithm>
12 
13 namespace MeshLib
14 {
15 template <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*[getNumberOfNeighbors()];
23  std::fill(this->_neighbors, this->_neighbors + getNumberOfNeighbors(),
24  nullptr);
25 
26  this->space_dimension_ = ELEMENT_RULE::dimension;
27 }
28 
29 template <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*[getNumberOfNeighbors()];
35  std::fill(this->_neighbors, this->_neighbors + getNumberOfNeighbors(), nullptr);
36 
37  this->space_dimension_ = ELEMENT_RULE::dimension;
38 }
39 
40 template <class ELEMENT_RULE>
43  : Element(e.getID()), _nodes{e._nodes}
44 {
45  this->_neighbors = new Element*[getNumberOfNeighbors()];
46  for (unsigned i = 0; i < getNumberOfNeighbors(); i++)
47  {
48  this->_neighbors[i] = e._neighbors[i];
49  }
50 
52 }
53 
54 template <class ELEMENT_RULE>
56 {
57  return ELEMENT_RULE::computeVolume(_nodes.data());
58 }
59 
60 namespace details
61 {
62 
63 template<unsigned N>
64 bool isEdge(unsigned const (&edge_nodes)[N], unsigned idx1, unsigned idx2)
65 {
66  if (edge_nodes[0] == idx1 && edge_nodes[1] == idx2)
67  {
68  return true;
69  }
70  if (edge_nodes[1] == idx1 && edge_nodes[0] == idx2)
71  {
72  return true;
73  }
74 
75  return false;
76 }
77 
78 inline bool
79 isEdge(unsigned const (&/*edge_nodes*/)[1], unsigned /*idx1*/, unsigned /*idx2*/)
80 {
81  return false;
82 }
83 
84 } // namespace details
85 
86 
87 template <class ELEMENT_RULE>
88 bool TemplateElement<ELEMENT_RULE>::isEdge(unsigned idx1, unsigned idx2) const
89 {
90  for (unsigned i(0); i<getNumberOfEdges(); i++)
91  {
92  if (details::isEdge(ELEMENT_RULE::edge_nodes[i], idx1, idx2))
93  {
94  return true;
95  }
96  }
97  return false;
98 }
99 
100 template <class ELEMENT_RULE>
101 const Node* TemplateElement<ELEMENT_RULE>::getNode(unsigned const idx) const
102 {
103 #ifndef NDEBUG
104  if (idx >= getNumberOfNodes())
105  {
106  ERR("Error in MeshLib::TemplateElement::getNode() - Index {:d} in {:s}",
107  idx, MeshElemType2String(getGeomType()));
108  return nullptr;
109  }
110 #endif
111  return _nodes[idx];
112 }
113 
114 template <class ELEMENT_RULE>
116 {
117 #ifndef NDEBUG
118  if (idx >= getNumberOfNodes())
119  {
120  ERR("Error in MeshLib::TemplateElement::getNode() - Index {:d} in {:s}",
121  idx, MeshElemType2String(getGeomType()));
122  return nullptr;
123  }
124 #endif
125  return _nodes[idx];
126 }
127 
128 template <class ELEMENT_RULE>
130 {
131 #ifndef NDEBUG
132  if (idx < getNumberOfNodes())
133 #endif
134  {
135  _nodes[idx] = node;
136  }
137 }
138 
139 } // namespace MeshLib
void ERR(char const *fmt, Args const &... args)
Definition: Logging.h:42
Element ** _neighbors
Definition: Element.h:197
unsigned space_dimension_
Dimension of the space, where the element exists.
Definition: Element.h:185
std::array< Node *, n_all_nodes > _nodes
bool isEdge(unsigned idx1, unsigned idx2) const override
Returns true if these two indices form an edge and false otherwise.
unsigned getNumberOfNeighbors() const override
Get the number of neighbors for 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.
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