FEAT 3
Finite Element Analysis Toolbox
Loading...
Searching...
No Matches
congruency_sampler.hpp
1// FEAT3: Finite Element Analysis Toolbox, Version 3
2// Copyright (C) 2010 by Stefan Turek & the FEAT group
3// FEAT3 is released under the GNU General Public License version 3,
4// see the file 'copyright.txt' in the top level directory for details.
5
6#pragma once
7
8// includes, FEAT
9#include <kernel/shape.hpp>
10
11namespace FEAT
12{
13 namespace Geometry
14 {
16 namespace Intern
17 {
25 template<typename Shape_>
26#ifndef DOXYGEN
27 class CongruencySampler;
28#else
29 class CongruencySampler
30 {
31 public:
44 template<
45 typename Source_,
46 typename Target_>
47 static int compare(const Source_& src, const Target_& trg);
48
58 static int orientation(int orientation_code);
59 };
60#endif // DOXYGEN
61
72 template<>
73 class CongruencySampler< Shape::Simplex<1> >
74 {
75 public:
76 template<
77 typename Source_,
78 typename Target_>
79 static int compare(const Source_& src, const Target_& trg)
80 {
81 return compare_with(src, trg, [](const auto& a, const auto& b) { return a == b; });
82 }
83
84 template<
85 typename Source_,
86 typename Target_,
87 typename Comparator_>
88 static int compare_with(const Source_& src, const Target_& trg, const Comparator_& comp)
89 {
90 auto sv0 = src[0];
91 if(comp(sv0, trg[0]))
92 {
93 return 0;
94 }
95 else if(comp(sv0, trg[1]))
96 {
97 return 1;
98 }
99 // invalid
100 return -1;
101 }
102
103 static int orientation(int orientation_code)
104 {
105 if(orientation_code == 0)
106 return 1;
107 if(orientation_code == 1)
108 return -1;
109 return 0;
110 }
111 }; // class CongruencySampler<Simplex<1>>
112
132 template<>
133 class CongruencySampler< Shape::Simplex<2> >
134 {
135 public:
136 template<
137 typename Source_,
138 typename Target_>
139 static int compare(const Source_& src, const Target_& trg)
140 {
141 return compare_with(src, trg, [](const auto& a, const auto& b) { return a == b; });
142 }
143
144 template<
145 typename Source_,
146 typename Target_,
147 typename Comparator_>
148 static int compare_with(const Source_& src, const Target_& trg, const Comparator_& comp)
149 {
150 auto sv0 = src[0];
151 auto sv1 = src[1];
152 if(comp(sv0, trg[0]))
153 {
154 if(comp(sv1, trg[1]))
155 {
156 return 0;
157 }
158 else if(comp(sv1, trg[2]))
159 {
160 return 4;
161 }
162 }
163 else if(comp(sv0, trg[1]))
164 {
165 if(comp(sv1, trg[2]))
166 {
167 return 1;
168 }
169 else if(comp(sv1, trg[0]))
170 {
171 return 5;
172 }
173 }
174 else if(comp(sv0, trg[2]))
175 {
176 if(comp(sv1, trg[0]))
177 {
178 return 2;
179 }
180 else if(comp(sv1, trg[1]))
181 {
182 return 6;
183 }
184 }
185 // invalid
186 return -1;
187 }
188
189 static int orientation(int orientation_code)
190 {
191 if(orientation_code == -1)
192 return 0;
193 if(orientation_code < 3)
194 return 1;
195 else
196 return -1;
197 }
198 }; // class CongruencySampler<Simplex<2>>
199
210 template<>
211 class CongruencySampler< Shape::Hypercube<1> >
212 {
213 public:
214 template<
215 typename Source_,
216 typename Target_>
217 static int compare(const Source_& src, const Target_& trg)
218 {
219 return compare_with(src, trg, [](const auto& a, const auto& b) { return a == b; });
220 }
221
222 template<
223 typename Source_,
224 typename Target_,
225 typename Comparator_>
226 static int compare_with(const Source_& src, const Target_& trg, const Comparator_& comp)
227 {
228 auto sv0 = src[0];
229 if(comp(sv0, trg[0]))
230 {
231 return 0;
232 }
233 else if(comp(sv0, trg[1]))
234 {
235 return 1;
236 }
237 // invalid
238 return -1;
239 }
240
241 static int orientation(int orientation_code)
242 {
243 if(orientation_code == 0)
244 return 1;
245 if(orientation_code == 1)
246 return -1;
247 return 0;
248 }
249 }; // class CongruencySampler<Hypercube<1>>
250
268 template<>
269 class CongruencySampler< Shape::Hypercube<2> >
270 {
271 public:
272 template<
273 typename Source_,
274 typename Target_>
275 static int compare(const Source_& src, const Target_& trg)
276 {
277 return compare_with(src, trg, [](const auto& a, const auto& b) { return a == b; });
278 }
279
280 template<
281 typename Source_,
282 typename Target_,
283 typename Comparator_>
284 static int compare_with(const Source_& src, const Target_& trg, const Comparator_& comp)
285 {
286 auto sv0 = src[0];
287 auto sv1 = src[1];
288 if(comp(sv0, trg[0]))
289 {
290 if(comp(sv1, trg[1]))
291 {
292 return 0;
293 }
294 else if(comp(sv1, trg[2]))
295 {
296 return 4;
297 }
298 }
299 else if(comp(sv0, trg[1]))
300 {
301 if(comp(sv1, trg[3]))
302 {
303 return 1;
304 }
305 else if(comp(sv1, trg[0]))
306 {
307 return 5;
308 }
309 }
310 else if(comp(sv0, trg[2]))
311 {
312 if(comp(sv1, trg[0]))
313 {
314 return 2;
315 }
316 else if(comp(sv1, trg[3]))
317 {
318 return 6;
319 }
320 }
321 else if(comp(sv0, trg[3]))
322 {
323 if(comp(sv1, trg[2]))
324 {
325 return 3;
326 }
327 else if(comp(sv1, trg[1]))
328 {
329 return 7;
330 }
331 }
332 // invalid
333 return -1;
334 }
335
336 static int orientation(int orientation_code)
337 {
338 if(orientation_code == -1)
339 return 0;
340 if(orientation_code < 4)
341 return 1;
342 else
343 return -1;
344 }
345 }; // class CongruencySampler<Hypercube<2>>
346 } // namespace Intern
348 } // namespace Geometry
349} // namespace FEAT
FEAT namespace.
Definition: adjactor.hpp:12