BEM++  2.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Groups Pages
element_pair_topology.hpp
1 // Copyright (C) 2011-2012 by the Bem++ Authors
2 //
3 // Permission is hereby granted, free of charge, to any person obtaining a copy
4 // of this software and associated documentation files (the "Software"), to deal
5 // in the Software without restriction, including without limitation the rights
6 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7 // copies of the Software, and to permit persons to whom the Software is
8 // furnished to do so, subject to the following conditions:
9 //
10 // The above copyright notice and this permission notice shall be included in
11 // all copies or substantial portions of the Software.
12 //
13 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19 // THE SOFTWARE.
20 
21 #ifndef fiber_element_pair_topology_hpp
22 #define fiber_element_pair_topology_hpp
23 
24 #include "../common/common.hpp"
25 
26 #include "../common/armadillo_fwd.hpp"
27 #include <cassert>
28 #include <iostream>
29 #include <boost/tuple/tuple_comparison.hpp>
30 
31 namespace Fiber
32 {
33 
36 {
39  type(Disjoint),
43  {}
44 
46  enum Type { Disjoint, SharedVertex, SharedEdge, Coincident };
50  unsigned char testVertexCount;
52  unsigned char trialVertexCount;
56  signed char testSharedVertex0;
60  signed char testSharedVertex1;
64  signed char trialSharedVertex0;
68  signed char trialSharedVertex1;
69 
70  bool operator<(const ElementPairTopology& other) const {
71  using boost::tuples::make_tuple;
72  return make_tuple(type, testVertexCount, trialVertexCount,
75  make_tuple(other.type, other.testVertexCount, other.trialVertexCount,
78  }
79 
80  bool operator==(const ElementPairTopology& other) const {
81  return type == other.type &&
88  }
89 
90  bool operator!=(const ElementPairTopology& other) const {
91  return !operator==(other);
92  }
93 
94  friend std::ostream&
95  operator<< (std::ostream& dest, const ElementPairTopology& obj)
96  {
97  dest << obj.type << " "
98  << (int)obj.testVertexCount << " "
99  << (int)obj.trialVertexCount << " "
100  << (int)obj.testSharedVertex0 << " "
101  << (int)obj.testSharedVertex1 << " "
102  << (int)obj.trialSharedVertex0 << " "
103  << (int)obj.trialSharedVertex1;
104  return dest;
105  }
106 };
107 
108 inline ElementPairTopology determineElementPairTopologyIn3D(
109  const arma::Col<int>& testElementCornerIndices,
110  const arma::Col<int>& trialElementCornerIndices)
111 {
112  ElementPairTopology topology;
113 
114  // Determine number of element corners
115 #ifndef NDEBUG
116  const int MIN_VERTEX_COUNT = 3;
117 #endif
118  const int MAX_VERTEX_COUNT = 4;
119  topology.testVertexCount = testElementCornerIndices.n_rows;
120  assert(MIN_VERTEX_COUNT <= topology.testVertexCount &&
121  topology.testVertexCount <= MAX_VERTEX_COUNT);
122  topology.trialVertexCount = trialElementCornerIndices.n_rows;
123  assert(MIN_VERTEX_COUNT <= topology.trialVertexCount &&
124  topology.trialVertexCount <= MAX_VERTEX_COUNT);
125 
126  // How many vertices coincide?
127  int testSharedVertices[MAX_VERTEX_COUNT];
128  int trialSharedVertices[MAX_VERTEX_COUNT];
129  int hits = 0;
130 
131  for (int trialV = 0; trialV < topology.trialVertexCount; ++trialV)
132  for (int testV = 0; testV < topology.testVertexCount; ++testV)
133  if (testElementCornerIndices(testV) ==
134  trialElementCornerIndices(trialV))
135  {
136  testSharedVertices[hits] = testV;
137  trialSharedVertices[hits] = trialV;
138  ++hits;
139  break;
140  }
141 
142  if (hits == 0)
143  {
144  topology.type = ElementPairTopology::Disjoint;
145  }
146  else if (hits == 1)
147  {
148  topology.type = ElementPairTopology::SharedVertex;
149  topology.testSharedVertex0 = testSharedVertices[0];
150  topology.trialSharedVertex0 = trialSharedVertices[0];
151  }
152  else if (hits == 2) // && elementDim == 2)
153  {
154  topology.type = ElementPairTopology::SharedEdge;
155  topology.testSharedVertex0 = testSharedVertices[0];
156  topology.testSharedVertex1 = testSharedVertices[1];
157  topology.trialSharedVertex0 = trialSharedVertices[0];
158  topology.trialSharedVertex1 = trialSharedVertices[1];
159  }
160  // coincident
161  else if (hits == topology.testVertexCount &&
162  hits == topology.trialVertexCount)
163  {
164  // Note: we don't handle the case where elements are different, but
165  // their vertices coincide
166  for (int i = 0; i < hits; ++i)
167  assert(testSharedVertices[i] == trialSharedVertices[i]);
168  topology.type = ElementPairTopology::Coincident;
169  }
170  else
171  throw std::runtime_error(
172  "Standard3DIntegrationManager::"
173  "selectTestKernelTrialQuadratureRules() :"
174  "Invalid element configuration");
175 
176  return topology;
177 }
178 
179 } // namespace Fiber
180 
181 #endif
unsigned char testVertexCount
Number of vertices of the test element.
Definition: element_pair_topology.hpp:50
Configuration of a pair of elements.
Definition: element_pair_topology.hpp:35
unsigned char trialVertexCount
Number of vertices of the trial element.
Definition: element_pair_topology.hpp:52
Type
Location of one element with respect to the other.
Definition: element_pair_topology.hpp:46
ElementPairTopology()
Constructor.
Definition: element_pair_topology.hpp:38
signed char testSharedVertex1
Index of the second vertex of the test element that is shared with the trial element, or -1 if at most one vertex is shared.
Definition: element_pair_topology.hpp:60
Type type
Location of one element with respect to the other.
Definition: element_pair_topology.hpp:48
signed char trialSharedVertex1
Index of the second vertex of the trial element that is shared with the test element, or -1 if at most one vertex is shared.
Definition: element_pair_topology.hpp:68
signed char testSharedVertex0
Index of the first vertex of the test element that is shared with the trial element, or -1 if no vertices are shared.
Definition: element_pair_topology.hpp:56
signed char trialSharedVertex0
Index of the first vertex of the trial element that is shared with the test element, or -1 if no vertices are shared.
Definition: element_pair_topology.hpp:64