libMesh
edge.C
Go to the documentation of this file.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2025 Benjamin S. Kirk, John W. Peterson, Roy H. Stogner
3 
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License, or (at your option) any later version.
8 
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // Lesser General Public License for more details.
13 
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 
18 
19 
20 // Local includes
21 #include "libmesh/edge.h"
22 #include "libmesh/node_elem.h"
23 
24 namespace libMesh
25 {
26 
27 
28 // ------------------------------------------------------------
29 // Edge class static member initializations
30 const int Edge::num_sides;
31 const int Edge::num_edges;
32 const int Edge::num_children;
33 const int Edge::nodes_per_side;
34 const int Edge::nodes_per_edge;
35 
36 // ------------------------------------------------------------
37 // Edge class member functions
38 unsigned int Edge::local_side_node(unsigned int side,
39  unsigned int /*side_node*/) const
40 {
41  libmesh_assert_less (side, this->n_sides());
42  return side;
43 }
44 
45 
46 
47 unsigned int Edge::local_edge_node(unsigned int /*edge*/,
48  unsigned int /*edge_node*/) const
49 {
50  libmesh_error_msg("Calling Edge::local_edge_node() does not make sense.");
51  return 0;
52 }
53 
54 
55 
56 std::unique_ptr<Elem> Edge::side_ptr (const unsigned int i)
57 {
58  libmesh_assert_less (i, 2);
59  std::unique_ptr<Elem> nodeelem = std::make_unique<NodeElem>();
60  nodeelem->set_node(0, this->node_ptr(i));
61 
62  nodeelem->set_interior_parent(this);
63  nodeelem->inherit_data_from(*this);
64 
65  return nodeelem;
66 }
67 
68 
69 void Edge::side_ptr (std::unique_ptr<Elem> & side,
70  const unsigned int i)
71 {
72  libmesh_assert_less (i, this->n_sides());
73 
74  if (!side.get() || side->type() != NODEELEM)
75  side = this->build_side_ptr(i);
76  else
77  {
78  side->inherit_data_from(*this);
79  side->set_node(0, this->node_ptr(i));
80  }
81 }
82 
83 
84 
85 
86 std::unique_ptr<Elem> Edge::build_side_ptr (const unsigned int i)
87 {
88  libmesh_assert_less (i, 2);
89  std::unique_ptr<Elem> nodeelem = std::make_unique<NodeElem>();
90  nodeelem->set_node(0, this->node_ptr(i));
91 
92  nodeelem->set_interior_parent(this);
93  nodeelem->inherit_data_from(*this);
94 
95  return nodeelem;
96 }
97 
98 
99 void Edge::build_side_ptr (std::unique_ptr<Elem> & side,
100  const unsigned int i)
101 {
102  libmesh_assert_less (i, this->n_sides());
103 
104  if (!side.get() || side->type() != NODEELEM)
105  side = this->build_side_ptr(i);
106  else
107  {
108  side->set_interior_parent(this);
109  side->inherit_data_from(*this);
110  side->set_node(0, this->node_ptr(i));
111  }
112 }
113 
114 
115 
116 
117 bool Edge::is_child_on_side(const unsigned int c,
118  const unsigned int s) const
119 {
120  libmesh_assert_less (c, this->n_children());
121  libmesh_assert_less (s, this->n_sides());
122 
123  return (c == s);
124 }
125 
126 
127 
128 unsigned int Edge::opposite_side(const unsigned int side_in) const
129 {
130  libmesh_assert_less (side_in, 2);
131  return 1 - side_in;
132 }
133 
134 
135 
136 unsigned int Edge::opposite_node(const unsigned int node_in,
137  const unsigned int libmesh_dbg_var(side_in)) const
138 {
139  libmesh_assert_less (node_in, 2);
140  libmesh_assert_less (side_in, this->n_sides());
141  libmesh_assert(this->is_node_on_side(node_in, side_in));
142 
143  return 1 - node_in;
144 }
145 
146 std::vector<unsigned>
147 Edge::nodes_on_side(const unsigned int s) const
148 {
149  libmesh_assert_less(s, 2);
150  return {s};
151 }
152 
153 std::vector<unsigned>
154 Edge::nodes_on_edge(const unsigned int e) const
155 {
156  return nodes_on_side(e);
157 }
158 
159 unsigned int Edge::center_node_on_side(const unsigned short side) const
160 {
161  libmesh_assert_less (side, this->n_sides());
162  return side;
163 }
164 
165 ElemType Edge::side_type (const unsigned int libmesh_dbg_var(s)) const
166 {
167  libmesh_assert_less (s, 2);
168  return NODEELEM;
169 }
170 
171 
172 bool
174 {
175  // Don't trigger on 1D elements embedded in 2D/3D
176  return (
177 #if LIBMESH_DIM > 2
178  !this->point(0)(2) && !this->point(1)(2) &&
179 #endif
180 #if LIBMESH_DIM > 1
181  !this->point(0)(1) && !this->point(1)(1) &&
182 #endif
183  this->point(0)(0) > this->point(1)(0));
184 }
185 
186 
187 
189  const Real eps) const
190 {
191  return ((p(0) >= -1-eps) && (p(0) <= 1+eps));
192 }
193 
194 } // namespace libMesh
ElemType
Defines an enum for geometric element types.
virtual unsigned int local_edge_node(unsigned int edge, unsigned int edge_node) const override final
Throws an error.
Definition: edge.C:47
virtual std::vector< unsigned int > nodes_on_side(const unsigned int s) const override
Definition: edge.C:147
virtual unsigned int local_side_node(unsigned int side, unsigned int) const override final
Definition: edge.C:38
static const int nodes_per_edge
Definition: edge.h:68
virtual bool is_flipped() const override final
Definition: edge.C:173
virtual bool is_node_on_side(const unsigned int n, const unsigned int s) const =0
The libMesh namespace provides an interface to certain functionality in the library.
static const int num_sides
Geometric constants for all Edges.
Definition: edge.h:64
static const int num_children
Definition: edge.h:66
virtual std::unique_ptr< Elem > build_side_ptr(const unsigned int i) override final
Definition: edge.C:86
virtual unsigned int opposite_side(const unsigned int s) const override final
Definition: edge.C:128
libmesh_assert(ctx)
virtual std::unique_ptr< Elem > side_ptr(const unsigned int i) override final
Definition: edge.C:56
virtual unsigned int n_children() const override final
Definition: edge.h:103
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
const Node * node_ptr(const unsigned int i) const
Definition: elem.h:2507
unsigned int center_node_on_side(const unsigned short side) const override final
Definition: edge.C:159
static const int num_edges
Definition: edge.h:65
virtual bool on_reference_element(const Point &p, const Real eps=TOLERANCE) const override final
Definition: edge.C:188
ElemType side_type(const unsigned int s) const override final
Definition: edge.C:165
virtual unsigned int opposite_node(const unsigned int n, const unsigned int s) const override final
Definition: edge.C:136
A Point defines a location in LIBMESH_DIM dimensional Real space.
Definition: point.h:39
const Point & point(const unsigned int i) const
Definition: elem.h:2453
virtual std::vector< unsigned int > nodes_on_edge(const unsigned int e) const override
Definition: edge.C:154
virtual bool is_child_on_side(const unsigned int c, const unsigned int s) const override final
Definition: edge.C:117
virtual unsigned int n_sides() const override final
Definition: edge.h:83
static const int nodes_per_side
Definition: edge.h:67