edge_edge3.C
Go to the documentation of this file.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2018 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_edge3.h"
23 #include "libmesh/enum_order.h"
24 
25 namespace libMesh
26 {
27 
28 // Edge3 class static member initializations
29 const int Edge3::num_nodes;
30 const int Edge3::num_children;
31 
32 #ifdef LIBMESH_ENABLE_AMR
33 
34 const float Edge3::_embedding_matrix[2][3][3] =
35  {
36  // embedding matrix for child 0
37  {
38  // 0 1 2
39  {1.0, 0.0, 0.0}, // left
40  {0.0, 0.0, 1.0}, // right
41  {0.375,-0.125,0.75} // middle
42  },
43 
44  // embedding matrix for child 1
45  {
46  // 0 1 2
47  {0.0, 0.0, 1.0}, // left
48  {0.0, 1.0, 0.0}, // right
49  {-0.125,0.375,0.75} // middle
50  }
51  };
52 
53 #endif
54 
55 bool Edge3::is_vertex(const unsigned int i) const
56 {
57  if (i < 2)
58  return true;
59  return false;
60 }
61 
62 bool Edge3::is_edge(const unsigned int i) const
63 {
64  if (i < 2)
65  return false;
66  return true;
67 }
68 
69 bool Edge3::is_face(const unsigned int ) const
70 {
71  return false;
72 }
73 
74 bool Edge3::is_node_on_side(const unsigned int n,
75  const unsigned int s) const
76 {
77  libmesh_assert_less (s, 2);
78  libmesh_assert_less (n, Edge3::num_nodes);
79  return (s == n);
80 }
81 
82 bool Edge3::is_node_on_edge(const unsigned int,
83  const unsigned int libmesh_dbg_var(e)) const
84 {
85  libmesh_assert_equal_to (e, 0);
86  return true;
87 }
88 
89 
90 
92 {
93  return (this->point(2).relative_fuzzy_equals
94  ((this->point(0) + this->point(1))/2));
95 }
96 
97 
98 
100 {
101  return SECOND;
102 }
103 
104 
105 
106 void Edge3::connectivity(const unsigned int sc,
107  const IOPackage iop,
108  std::vector<dof_id_type> & conn) const
109 {
110  libmesh_assert_less_equal (sc, 1);
111  libmesh_assert_less (sc, this->n_sub_elem());
112  libmesh_assert_not_equal_to (iop, INVALID_IO_PACKAGE);
113 
114  // Create storage
115  conn.resize(2);
116 
117  switch (iop)
118  {
119  case TECPLOT:
120  {
121  switch (sc)
122  {
123  case 0:
124  conn[0] = this->node_id(0)+1;
125  conn[1] = this->node_id(2)+1;
126  return;
127 
128  case 1:
129  conn[0] = this->node_id(2)+1;
130  conn[1] = this->node_id(1)+1;
131  return;
132 
133  default:
134  libmesh_error_msg("Invalid sc = " << sc);
135  }
136  }
137 
138 
139  case VTK:
140  {
141  conn.resize(3);
142  conn[0] = this->node_id(0);
143  conn[1] = this->node_id(1);
144  conn[2] = this->node_id(2);
145  return;
146 
147  /*
148  switch (sc)
149  {
150  case 0:
151  conn[0] = this->node_id(0);
152  conn[1] = this->node_id(2);
153 
154  return;
155 
156  case 1:
157  conn[0] = this->node_id(2);
158  conn[1] = this->node_id(1);
159 
160  return;
161 
162  default:
163  libmesh_error_msg("Invalid sc = " << sc);
164  }
165  */
166  }
167 
168  default:
169  libmesh_error_msg("Unsupported IO package " << iop);
170  }
171 }
172 
173 
174 
175 std::pair<unsigned short int, unsigned short int>
176 Edge3::second_order_child_vertex (const unsigned int) const
177 {
178  return std::pair<unsigned short int, unsigned short int>(0,0);
179 }
180 
181 
182 
184 {
185  // Finding the (exact) length of a general quadratic element
186  // is a surprisingly complicated formula.
187  Point A = this->point(0) + this->point(1) - 2*this->point(2);
188  Point B = (this->point(1) - this->point(0))/2;
189 
190  const Real a = A.norm_sq();
191  const Real c = B.norm_sq();
192 
193  // Degenerate straight line case
194  if (a < TOLERANCE*TOLERANCE)
195  return 2. * std::sqrt(c);
196 
197  const Real b = 2.*(A*B);
198  const Real ba=b/a;
199  const Real ca=c/a;
200 
201  libmesh_assert (1.-ba+ca>0.);
202 
203  const Real s1 = std::sqrt(1. - ba + ca);
204  const Real s2 = std::sqrt(1. + ba + ca);
205 
206  Real log_term = (1. - 0.5*ba + s1) / (-1. - 0.5*ba + s2);
207  libmesh_assert(!libmesh_isnan(log_term) && log_term > 0.);
208 
209  return 0.5*std::sqrt(a)*((1.-0.5*ba)*s1 +
210  (1.+0.5*ba)*s2 +
211  (ca - 0.25*ba*ba)*std::log(log_term)
212  );
213 }
214 
215 
216 
218 {
219  // This might be a curved line through 2-space or 3-space, in which
220  // case the full bounding box can be larger than the bounding box of
221  // just the nodes.
222  Point pmin, pmax;
223 
224  for (unsigned d=0; d<LIBMESH_DIM; ++d)
225  {
226  Real center = this->point(2)(d);
227  Real hd = std::max(std::abs(center - this->point(0)(d)),
228  std::abs(center - this->point(1)(d)));
229 
230  pmin(d) = center - hd;
231  pmax(d) = center + hd;
232  }
233 
234  return BoundingBox(pmin, pmax);
235 }
236 
237 
238 
240 {
241  return this->compute_key(this->node_id(2));
242 }
243 
244 
245 } // namespace libMesh
double abs(double a)
virtual std::pair< unsigned short int, unsigned short int > second_order_child_vertex(const unsigned int n) const override
Definition: edge_edge3.C:176
virtual bool is_face(const unsigned int i) const override
Definition: edge_edge3.C:69
virtual bool is_node_on_edge(const unsigned int n, const unsigned int e) const override
Definition: edge_edge3.C:82
virtual BoundingBox loose_bounding_box() const override
Definition: edge_edge3.C:217
virtual bool is_node_on_side(const unsigned int n, const unsigned int s) const override
Definition: edge_edge3.C:74
virtual Real volume() const override
Definition: edge_edge3.C:183
static const Real TOLERANCE
static const float _embedding_matrix[num_children][num_nodes][num_nodes]
Definition: edge_edge3.h:215
long double max(long double a, double b)
static const int num_children
Definition: edge_edge3.h:190
virtual Order default_order() const override
Definition: edge_edge3.C:99
virtual unsigned int n_sub_elem() const override
Definition: edge_edge3.h:80
virtual void connectivity(const unsigned int sc, const IOPackage iop, std::vector< dof_id_type > &conn) const override
Definition: edge_edge3.C:106
virtual bool is_edge(const unsigned int i) const override
Definition: edge_edge3.C:62
Real norm_sq() const
Definition: type_vector.h:943
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
bool libmesh_isnan(float a)
static PetscErrorCode Mat * A
static const int num_nodes
Definition: edge_edge3.h:189
static dof_id_type compute_key(dof_id_type n0)
Definition: elem.h:2754
A geometric point in (x,y,z) space.
Definition: point.h:38
dof_id_type node_id(const unsigned int i) const
Definition: elem.h:1914
virtual dof_id_type key() const override
Definition: edge_edge3.C:239
const Point & point(const unsigned int i) const
Definition: elem.h:1892
virtual bool has_affine_map() const override
Definition: edge_edge3.C:91
virtual bool is_vertex(const unsigned int i) const override
Definition: edge_edge3.C:55
uint8_t dof_id_type
Definition: id_types.h:64