Bembel
compareElements.hpp
1 // This file is part of Bembel, the higher order C++ boundary element library.
2 //
3 // Copyright (C) 2022 see <http://www.bembel.eu>
4 //
5 // It was written as part of a cooperation of J. Doelz, H. Harbrecht, S. Kurz,
6 // M. Multerer, S. Schoeps, and F. Wolf at Technische Universitaet Darmstadt,
7 // Universitaet Basel, and Universita della Svizzera italiana, Lugano. This
8 // source code is subject to the GNU General Public License version 3 and
9 // provided WITHOUT ANY WARRANTY, see <http://www.bembel.eu> for further
10 // information.
11 
12 #ifndef BEMBEL_SRC_DUFFYTRICK_COMPAREELEMENTS_HPP_
13 #define BEMBEL_SRC_DUFFYTRICK_COMPAREELEMENTS_HPP_
14 
15 namespace Bembel {
16 namespace DuffyTrick {
23 Eigen::Vector3i compareElements(const ElementTreeNode &e1,
24  const ElementTreeNode &e2, double *dist) {
25  Eigen::Vector3i retval;
26  retval.setZero();
27  // check if the two elements are identical and directly return;
28  if (std::addressof(e1) == std::addressof(e2)) {
29  retval << 4, 4, 2;
30  *dist = 0;
31  return retval;
32  } else {
33  // if they are not identical, check if they have a positive distance
34  // check for common vertices
35  *dist = (e1.midpoint_ - e2.midpoint_).norm() - e1.radius_ - e2.radius_;
36  *dist = *dist >= 0 ? *dist : 0;
37  // check if elements are distinct and return now
38  if (*dist > .5 / (1 << e1.level_)) {
39  retval << 4, 4, 0;
40  return retval;
41  // otherwise check for common edge/vertex. Note that there is a
42  // short circuit: either two elements share a single edge or
43  // single point. everything else will break the code
44  } else {
45  for (auto rot1 = 0; rot1 < 4; ++rot1)
46  for (auto rot2 = 0; rot2 < 4; ++rot2)
47  // check for common vertices_
48  if (e1.vertices_[rot1] == e2.vertices_[rot2]) {
49  // if there is a common vertices_, check for common edge
50  if (e1.vertices_[3] == e2.vertices_[(rot2 + 1) % 4]) {
51  retval << 3, rot2, 3;
52  return retval;
53  } else if (e1.vertices_[(rot1 + 1) % 4] ==
54  e2.vertices_[(rot2 + 3) % 4]) {
55  retval << rot1, (rot2 + 3) % 4, 3;
56  return retval;
57  } else {
58  retval << rot1, rot2, 4;
59  return retval;
60  }
61  }
62  retval << 4, 4, 0;
63  return retval;
64  }
65  }
66  // if you ended up here, something went terribly wrong
67  retval << 4, 4, -1;
68  return retval;
69 }
70 } // namespace DuffyTrick
71 } // namespace Bembel
72 
73 #endif // BEMBEL_SRC_DUFFYTRICK_COMPAREELEMENTS_HPP_
The ElementTreeNode corresponds to an element in the element tree.
int level_
element id with respect to the level
std::vector< int > vertices_
neighbouring elements indices
Eigen::Vector3d midpoint_
indices of the vertices
Eigen::Vector3i compareElements(const ElementTreeNode &e1, const ElementTreeNode &e2, double *dist)
Compares two elements for similarities and determines, how the elements have to be rotated to move th...
Routines for the evalutation of pointwise errors.
Definition: AnsatzSpace.hpp:14