DUNE-ACFEM (2.5.1)

boundaryindicator.hh
1#ifndef __DUNE_ACFEM_BOUNDARY_CONSTRAINTS_HH__
2#define __DUNE_ACFEM_BOUNDARY_CONSTRAINTS_HH__
3
4#include <dune/fem/misc/bartonnackmaninterface.hh>
5
6#include "../expressions/expressionoperations.hh"
7
8namespace Dune {
9
10 namespace ACFem {
11
37 template<class Implementation>
39 : public Dune::Fem::BartonNackmanInterface<BoundaryIndicatorInterface<Implementation>,
40 Implementation>
41 {
42 typedef Implementation ImplementationType;
44 typedef Dune::Fem::BartonNackmanInterface<ThisType, ImplementationType> BaseType;
45 using BaseType::asImp;
46 protected:
49 BoundaryIndicatorInterface& operator=(const BoundaryIndicatorInterface& other) { return *this; }
50 public:
60 template<class Intersection>
61 bool applies(const Intersection &intersection) const
62 {
63 return asImp().applies(intersection);
64 }
65 };
66
73 template<class Implementation>
75 : public BoundaryIndicatorInterface<Implementation>
76 {
78 protected:
80 DefaultBoundaryIndicator(const ThisType& other) {}
81 ThisType& operator=(const ThisType& other) { return *this; }
82 public:
84 template<class Intersection>
85 bool applies(const Intersection &intersection) const
86 {
87 return false;
88 }
89 };
90
92 template<class Implementation, template<class> class ExpressionTag = ExpressionTemplate>
94 : public DefaultBoundaryIndicator<Implementation>,
95 public ExpressionTag<Implementation>
96 {
98 protected:
101 ThisType& operator=(const ThisType& other) { return *this; }
102 public:
103 };
104
106
115 template<class Intersection>
116 bool isDomainBoundary(const Intersection& intersection)
117 {
118 return !intersection.neighbor() && intersection.boundary();
119 }
120
124 template<class Intersection>
125 bool isPeriodicBoundary(const Intersection& intersection)
126 {
127 return intersection.neighbor() && intersection.boundary();
128 }
129
133 template<class Intersection>
134 bool isProcessorBoundary(const Intersection& intersection)
135 {
136 if (intersection.neighbor()) {
137 return intersection.outside().partitionType() == GhostEntity;
138 } else {
139 return !intersection.boundary();
140 }
141 }
142
147 template<class Intersection>
148 bool isInterior(const Intersection& intersection)
149 {
150 return intersection.neighbor();
151 }
152
153 template<bool answer = true>
154 struct ConstantBoundaryIndicator;
155
156 template<>
157 struct ConstantBoundaryIndicator<true>
158 : public BoundaryIndicatorExpression<ConstantBoundaryIndicator<true>, NonZeroExpression>
159 {
160 private:
161 enum { answer = true };
162 public:
163
165 template<class Intersection>
166 bool applies(const Intersection &intersection) const
167 {
168 return answer;
169 }
170 };
171
172 template<>
173 struct ConstantBoundaryIndicator<false>
174 : public BoundaryIndicatorExpression<ConstantBoundaryIndicator<false>, ZeroExpression>
175 {};
176
177 typedef ConstantBoundaryIndicator<false> EmptyBoundaryIndicatorType;
178 typedef ConstantBoundaryIndicator<true> EntireBoundaryIndicatorType;
179
182 : public BoundaryIndicatorExpression<BoundaryIdIndicator>
183 {
186 : id_(id)
187 {};
188
190 template<class Intersection>
191 bool applies(const Intersection &intersection) const
192 {
193 return intersection.boundaryId() == id_;
194 }
195 protected:
196 const int id_;
197 };
198
200 template<class Indicator>
202 : public BoundaryIndicatorExpression<ComplementBoundaryIndicator<Indicator> >
203 {
204 typedef Indicator ContainedIndicatorType;
206 : indicator_(indicator)
207 {}
208
210 template<class Intersection>
211 bool applies(const Intersection &intersection) const
212 {
213 return !indicator_().applies(intersection);
214 }
215
216 const ContainedIndicatorType& containedExpression() const
217 {
218 return indicator_();
219 }
220 protected:
221 ExpressionStorage<ContainedIndicatorType> indicator_;
222 };
223
225 template<class Indicator>
227 : public BoundaryIndicatorExpression<BoundaryIndicatorWrapper<Indicator> >
228 {
229 typedef Indicator ContainedIndicatorType;
231 : indicator_(indicator)
232 {}
233
235 template<class Intersection>
236 bool applies(const Intersection &intersection) const
237 {
238 return indicator_().applies(intersection);
239 }
240 protected:
241 // The wrapper makes a real copy in any case
243 };
244
246 template<class One, class Two>
248 : public BoundaryIndicatorExpression<UnionBoundaryIndicator<One, Two> >
249 {
250 typedef One IndicatorOneType;
251 typedef Two IndicatorTwoType;
254 : one_(one), two_(two)
255 {}
256
258 template<class Intersection>
259 bool applies(const Intersection &intersection) const
260 {
261 return one_().applies(intersection) || two_().applies(intersection);
262 }
263
264 protected:
267 };
268
270 template<class One, class Two>
272 : public BoundaryIndicatorExpression<IntersectionBoundaryIndicator<One, Two> >
273 {
274 typedef One IndicatorOneType;
275 typedef Two IndicatorTwoType;
278 : one_(one), two_(two)
279 {}
280
282 template<class Intersection>
283 bool applies(const Intersection &intersection) const
284 {
285 return one_().applies(intersection) && two_().applies(intersection);
286 }
287
288 protected:
291 };
292
294
296
312 template<class Indicator>
313 BoundaryIndicatorWrapper<Indicator>
315 {
316 typedef BoundaryIndicatorWrapper<Indicator> ExpressionType;
317
318 return ExpressionType(arg);
319 }
320
322 template<class Indicator>
323 auto
325 -> decltype(*asImp(arg))
326 {
327 return *asImp(arg);
328 }
329
331 template<class Indicator>
332 Indicator
334 {
335 return arg.expression();
336 }
337
339 template<class Indicator>
340 ComplementBoundaryIndicator<Indicator>
342 {
343 typedef ComplementBoundaryIndicator<Indicator> ExpressionType;
344
345 return ExpressionType(arg);
346 }
347
349 template<class Indicator>
350 auto
352 -> decltype(!asImp(arg))
353 {
354 return !asImp(arg);
355 }
356
358 template<class Indicator>
359 auto
361 -> decltype(*arg.containedExpression())
362 {
363 return *arg.containedExpression();
364 }
365
367 template<class One, class Two>
368 UnionBoundaryIndicator<One, Two>
371 {
372 typedef UnionBoundaryIndicator<One, Two> ExpressionType;
373
374 return ExpressionType(one, two);
375 }
376
378 template<class One, class Two>
379 auto
382 -> decltype(asImp(one) || asImp(two))
383 {
384 return asImp(one) || asImp(two);
385 }
386
388 template<class One, class Two>
389 IntersectionBoundaryIndicator<One, Two>
392 {
393 typedef IntersectionBoundaryIndicator<One, Two> ExpressionType;
394
395 return ExpressionType(one, two);
396 }
397
399 template<class One, class Two>
400 auto
403 -> decltype(asImp(one) && asImp(two))
404 {
405 return asImp(one) && asImp(two);
406 }
407
409 template<class One, class Two>
410 auto
413 -> decltype(asImp(one) && (!asImp(two)))
414 {
415 return asImp(one) && (!asImp(two)); // aka one * (-two)
416 }
417
426 static inline
427 EntireBoundaryIndicatorType
428 operator!(const EmptyBoundaryIndicatorType& arg)
429 {
430 return EntireBoundaryIndicatorType();
431 }
432
434 static inline
435 EmptyBoundaryIndicatorType
436 operator!(const EntireBoundaryIndicatorType& arg)
437 {
438 return EmptyBoundaryIndicatorType();
439 }
440
442 template<class Other>
443 static inline
444 auto operator||(const EmptyBoundaryIndicatorType& one,
446 -> decltype(*asImp(two))
447 {
448 return *asImp(two);
449 }
450
452 template<class Other>
453 static inline
455 const EmptyBoundaryIndicatorType& two)
456 -> decltype(*asImp(one))
457 {
458 return *asImp(one);
459 }
460
462 static inline
463 EmptyBoundaryIndicatorType
464 operator||(const EmptyBoundaryIndicatorType& one,
465 const EmptyBoundaryIndicatorType& two)
466 {
467 return EmptyBoundaryIndicatorType();
468 }
469
471 template<class Other>
472 static inline
473 EntireBoundaryIndicatorType
474 operator||(const EntireBoundaryIndicatorType& one,
476 {
477 return EntireBoundaryIndicatorType();
478 }
479
481 template<class Other>
482 static inline
483 EntireBoundaryIndicatorType
485 const EntireBoundaryIndicatorType& two)
486 {
487 return EntireBoundaryIndicatorType();
488 }
489
491 static inline
492 EntireBoundaryIndicatorType
493 operator||(const EntireBoundaryIndicatorType& one,
494 const EntireBoundaryIndicatorType& two)
495 {
496 return EntireBoundaryIndicatorType();
497 }
498
499#if 0
500 // Nope, this would only hold if one == two which is a runtime
501 //condition. Boundary indicators need not be stateless.
502 //Some || Some = Some
503 template<class Some>
504 static inline
505 auto operator||(const BoundaryIndicatorInterface<Some>& one,
506 const BoundaryIndicatorInterface<Some>& two)
507 -> decltype(*asImp(one))
508 {
509 return *asImp(one);
510 }
511#endif
512
514 static inline
515 EntireBoundaryIndicatorType
516 operator||(const EntireBoundaryIndicatorType& one,
517 const EmptyBoundaryIndicatorType& two)
518 {
519 return EntireBoundaryIndicatorType();
520 }
521
523 static inline
524 EntireBoundaryIndicatorType
525 operator||(const EmptyBoundaryIndicatorType& one,
526 const EntireBoundaryIndicatorType& two)
527 {
528 return EntireBoundaryIndicatorType();
529 }
530
532 template<class Other>
533 static inline
534 EmptyBoundaryIndicatorType
535 operator&&(const EmptyBoundaryIndicatorType& fixed,
537 {
538 return EmptyBoundaryIndicatorType();
539 }
540
542 template<class Other>
544 const EmptyBoundaryIndicatorType& fixed)
545 -> decltype(*fixed)
546 {
547 return *fixed;
548 }
549
551 template<class Other>
552 static inline
553 auto operator&&(const EntireBoundaryIndicatorType& fixed,
555 -> decltype(*asImp(other))
556 {
557 return *asImp(other);
558 }
559
561 template<class Other>
562 static inline
564 const EntireBoundaryIndicatorType& fixed)
565 -> decltype(*asImp(other))
566 {
567 return *asImp(other);
568 }
569
570#if 0
571 // Only holds if one == two, actually
572
573 // Other && Other = Other
574 template<class Other>
575 auto
576 operator&&(const BoundaryIndicatorInterface<Other>& one,
577 const EntireBoundaryIndicatorType& two)
578 -> decltype(*one)
579 {
580 return *one;
581 }
582#endif
583
585 static inline
586 EmptyBoundaryIndicatorType
587 operator&&(const EmptyBoundaryIndicatorType& one,
588 const EmptyBoundaryIndicatorType& two)
589 {
590 return EmptyBoundaryIndicatorType();
591 }
592
594 static inline
595 EntireBoundaryIndicatorType
596 operator&&(const EntireBoundaryIndicatorType& one,
597 const EntireBoundaryIndicatorType& two)
598 {
599 return EntireBoundaryIndicatorType();
600 }
601
603 static inline
604 EmptyBoundaryIndicatorType
605 operator&&(const EmptyBoundaryIndicatorType& one,
606 const EntireBoundaryIndicatorType& two)
607 {
608 return EmptyBoundaryIndicatorType();
609 }
610
612 static inline
613 EmptyBoundaryIndicatorType
614 operator&&(const EntireBoundaryIndicatorType& one,
615 const EmptyBoundaryIndicatorType& two)
616 {
617 return EmptyBoundaryIndicatorType();
618 }
619
620#if 0
621 // This also does only hold if notSome would refer to !some (the
622 // instance, not the data-type)
623
624 // Some && !Some = Empty
625 template<class Other>
626 EmptyBoundaryIndicatorType
627 operator&&(const BoundaryIndicatorInterface<Other>& some,
628 const ComplementBoundaryIndicator<Other>& notSome)
629 {
630 typedef EmptyBoundaryIndicatorType ExpressionType;
631
632 return ExpressionType();
633 }
634
636 template<class Other>
637 auto
638 operator&&(const ComplementBoundaryIndicator<Other>& notSome,
639 const BoundaryIndicatorInterface<Other>& some)
640 -> decltype(asImp(some) && notSome)
641 {
642 return asImp(some) && notSome;
643 }
644#endif
645
647
649
651
652 } // ACFem::
653
654} // Dune::
655
656#endif // __DUNE_ACFEM_BOUNDARY_CONSTRAINTS_HH__
A simple interface class for a boundary-indicator.
Definition: boundaryindicator.hh:41
bool applies(const Intersection &intersection) const
Classify a boundary facet.
Definition: boundaryindicator.hh:61
bool isInterior(const Intersection &intersection)
Return true if there is a neighbor.
Definition: boundaryindicator.hh:148
bool isProcessorBoundary(const Intersection &intersection)
Retrun true if at the border to another computing note.
Definition: boundaryindicator.hh:134
bool isDomainBoundary(const Intersection &intersection)
Return true if at the global domain boundary.
Definition: boundaryindicator.hh:116
bool isPeriodicBoundary(const Intersection &intersection)
Return true if at a periodic boundary.
Definition: boundaryindicator.hh:125
const Implementation & asImp(const Fem::BartonNackmanInterface< Interface, Implementation > &arg)
Up-cast to the implementation for any Fem::BartonNackmanInterface.
Definition: expressionoperations.hh:71
IntersectionBoundaryIndicator< One, Two > operator&&(const BoundaryIndicatorInterface< One > &one, const BoundaryIndicatorInterface< Two > &two)
Intersection of two indicators.
Definition: boundaryindicator.hh:390
UnionBoundaryIndicator< One, Two > operator||(const BoundaryIndicatorInterface< One > &one, const BoundaryIndicatorInterface< Two > &two)
Union of two indicators.
Definition: boundaryindicator.hh:369
ComplementBoundaryIndicator< Indicator > operator!(const BoundaryIndicatorInterface< Indicator > &arg)
Boolean negation, take the complement.
Definition: boundaryindicator.hh:341
BinaryParameterExpression< MultiplyOperation, Left, Right > operator*(const ParameterInterface< Left > &left, const ParameterInterface< Right > &right)
Scalar product between parameters.
Definition: parameterexpression.hh:321
Apply to boundary segments which carry the respective id.
Definition: boundaryindicator.hh:183
BoundaryIdIndicator(int id)
Construct the indicator with the given id.
Definition: boundaryindicator.hh:185
bool applies(const Intersection &intersection) const
Classify a boundary facet.
Definition: boundaryindicator.hh:191
Expression tag-class for boundary indicators.
Definition: boundaryindicator.hh:96
Wrap another boundary indicator.
Definition: boundaryindicator.hh:228
bool applies(const Intersection &intersection) const
Classify a boundary facet.
Definition: boundaryindicator.hh:236
Turn any boundary-indicator into its complement.
Definition: boundaryindicator.hh:203
bool applies(const Intersection &intersection) const
Classify a boundary facet.
Definition: boundaryindicator.hh:211
Default boundary indicator: like EntireBoundaryIndicator<false>
Definition: boundaryindicator.hh:76
bool applies(const Intersection &intersection) const
Classify a boundary facet.
Definition: boundaryindicator.hh:85
const ExpressionType & expression() const
Return a const reference to the underlying expression.
Definition: expressionoperations.hh:42
Intersection of two indicators, apply iff both apply.
Definition: boundaryindicator.hh:273
bool applies(const Intersection &intersection) const
Classify a boundary facet.
Definition: boundaryindicator.hh:283
Union of two indicators, apply to the union of both boundary parts.
Definition: boundaryindicator.hh:249
bool applies(const Intersection &intersection) const
Classify a boundary facet.
Definition: boundaryindicator.hh:259
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Aug 13, 22:30, 2024)