1#ifndef DUNE_ALUGRID_COMMON_TWISTS_HH
2#define DUNE_ALUGRID_COMMON_TWISTS_HH
7#include <dune/geometry/referenceelements.hh>
17 template<
int corners,
int dim >
20 template<
int corners,
int dim >
28 template<
class Twist >
29 struct ALUTwistIterator
31 typedef std::input_iterator_tag iterator_category;
32 typedef Twist value_type;
33 typedef int difference_type;
34 typedef Twist* pointer;
35 typedef Twist& reference;
37 explicit ALUTwistIterator ( Twist twist ) : twist_( twist ) {}
39 const Twist &operator* ()
const {
return twist_; }
40 const Twist *operator-> ()
const {
return &twist_; }
42 bool operator== (
const ALUTwistIterator &other )
const {
return (twist_ == other.twist_); }
43 bool operator!= (
const ALUTwistIterator &other )
const {
return (twist_ != other.twist_); }
45 ALUTwistIterator &operator++ () { ++twist_.aluTwist_;
return *
this; }
46 ALUTwistIterator operator++ (
int ) { ALUTwistIterator other( *
this ); ++(*this);
return other; }
57 template<
int corners >
58 class ALUTwist< corners, 2 >
60 typedef ALUTwist< corners, 2 > Twist;
62 friend struct ALUTwistIterator< Twist >;
64 template<
class ctype >
68 typedef ReferenceElements< ctype, 2 > ReferenceElementContainerType;
71 typedef std::decay_t< decltype( ReferenceElementContainerType::general( std::declval< const Dune::GeometryType & >() ) ) > ReferenceElementType;
73 CoordVector (
const Twist &twist )
75 refElement_( ReferenceElements< ctype, 2 >::general( twist.type() ) )
78 const FieldVector< ctype, 2 > operator[] (
int i )
const {
return refElement().position( twist_( i ), 2 ); }
80 const ReferenceElementType& refElement ()
const {
return refElement_; }
84 const ReferenceElementType& refElement_;
89 static const int dimension = 2;
97 ALUTwist () : aluTwist_( 0 ) {}
99 explicit ALUTwist ( GeometryType ) : aluTwist_( 0 ) {}
101 explicit ALUTwist (
int aluTwist ) : aluTwist_( aluTwist ) {}
103 ALUTwist (
int origin,
bool positive )
104 : aluTwist_( positive ? origin : (origin + corners - 1) % corners - corners )
115 ALUTwist (
const ALUTwist &other ) : aluTwist_( other.aluTwist_ ) {}
118 ALUTwist &operator= (
const ALUTwist &other ) { aluTwist_ = other.aluTwist_;
return *
this; }
128 ALUTwist operator* (
const ALUTwist &other )
const
130 return ALUTwist( apply( other.apply( 0 ) ), !(positive() ^ other.positive()) );
134 ALUTwist operator/ (
const ALUTwist &other )
const {
return (*
this * other.inverse()); }
137 ALUTwist &operator*= (
const ALUTwist &other ) {
return (*
this = (*
this) * other); }
140 ALUTwist &operator/= (
const ALUTwist &other ) {
return (*
this = (*
this) / other); }
143 ALUTwist inverse ()
const {
return ALUTwist( positive() ? (corners - aluTwist_) % corners : aluTwist_ ); }
153 bool operator== (
const ALUTwist &other )
const {
return (aluTwist_ == other.aluTwist_); }
156 bool operator!= (
const ALUTwist &other )
const {
return (aluTwist_ != other.aluTwist_); }
181 int operator() (
int i )
const {
return aluVertex2duneVertex( apply( duneVertex2aluVertex( i ) ) ); }
183 int operator() (
int i,
int codim )
const {
return alu2dune( apply( dune2alu( i, codim ), codim ), codim ); }
193 template<
class ctype >
194 operator AffineGeometry< ctype, dimension, dimension > ()
const
196 const CoordVector< ctype > coordVector( *
this );
197 return AffineGeometry< ctype, dimension, dimension >( coordVector.refElement(), coordVector );
201 bool positive ()
const {
return (aluTwist_ >= 0); }
207 operator int ()
const {
return aluTwist_; }
210 int apply (
int i )
const {
return ((positive() ? i : 2*corners + 1 - i) + aluTwist_) % corners; }
211 int apply (
int i,
int codim )
const {
return (codim == 0 ? i : (codim == 1 ? applyEdge( i ) : apply( i ))); }
214 int applyEdge (
int i )
const {
return ((positive() ? i : 2*corners - i) + aluTwist_) % corners; }
217 static int aluEdge2duneEdge (
int i ) {
return ((corners == 3) ? (3 - i) % 3 : (6 - swap23( i )) % 4); }
218 static int duneEdge2aluEdge (
int i ) {
return ((corners == 3) ? (3 - i) % 3 : swap23( (6 - i) % 4 )); }
220 static int aluVertex2duneVertex (
int i ) {
return ((corners == 3) ? i : swap23( i )); }
221 static int duneVertex2aluVertex (
int i ) {
return ((corners == 3) ? i : swap23( i )); }
223 static int alu2dune (
int i,
int codim ) {
return (codim == 0 ? i : (codim == 1 ? aluEdge2duneEdge( i ) : aluVertex2duneVertex( i ))); }
224 static int dune2alu (
int i,
int codim ) {
return (codim == 0 ? i : (codim == 1 ? duneEdge2aluEdge( i ) : aluVertex2duneVertex( i ))); }
226 static int swap23 (
int i ) {
return i ^ (i >> 1); }
237 class ALUTwist< 2, 1 >
239 typedef ALUTwist< 2, 1 > Twist;
241 friend struct ALUTwistIterator< Twist >;
243 template<
class ctype >
246 CoordVector (
const Twist &twist ) : twist_( twist ) {}
248 FieldVector< ctype, 1 > operator[] (
int i )
const {
return FieldVector< ctype, 1 >( ctype( twist_( i ) ) ); }
256 static const int dimension = 1;
264 ALUTwist () : aluTwist_( 0 ) {}
266 explicit ALUTwist ( GeometryType ) : aluTwist_( 0 ) {}
268 explicit ALUTwist (
int aluTwist ) : aluTwist_( aluTwist ) {}
270 explicit ALUTwist (
bool positive ) : aluTwist_( positive ) {}
280 ALUTwist (
const ALUTwist &other ) : aluTwist_( other.aluTwist_ ) {}
283 ALUTwist &operator= (
const ALUTwist &other ) { aluTwist_ = other.aluTwist_;
return *
this; }
293 ALUTwist operator* (
const ALUTwist &other )
const {
return ALUTwist( aluTwist_ ^ other.aluTwist_ ); }
296 ALUTwist operator/ (
const ALUTwist &other )
const {
return (*
this * other.inverse()); }
299 ALUTwist &operator*= (
const ALUTwist &other ) {
return (*
this = (*
this) * other); }
302 ALUTwist &operator/= (
const ALUTwist &other ) {
return (*
this = (*
this) / other); }
305 ALUTwist inverse ()
const {
return *
this; }
315 bool operator== (
const ALUTwist &other )
const {
return (aluTwist_ == other.aluTwist_); }
318 bool operator!= (
const ALUTwist &other )
const {
return (aluTwist_ != other.aluTwist_); }
337 int operator() (
int i )
const {
return (i ^ aluTwist_); }
339 int operator() (
int i,
int codim )
const {
return (codim == 0 ? i : (*
this)( i )); }
349 template<
class ctype >
350 operator AffineGeometry< ctype, dimension, dimension > ()
const
352 const CoordVector< ctype > coordVector( *
this );
353 return AffineGeometry< ctype, dimension, dimension >( type(), coordVector );
357 bool positive ()
const {
return (aluTwist_ == 0); }
361 operator int ()
const {
return aluTwist_; }
373 template<
int corners >
374 class ALUTwists< corners, 2 >
378 static const int dimension = 2;
380 typedef ALUTwist< corners, 2 > Twist;
382 typedef ALUTwistIterator< Twist > Iterator;
394 std::size_t size ()
const {
return 2*corners; }
397 std::size_t index (
const Twist &twist )
const {
return static_cast< int >( twist ) + corners; }
405 Iterator begin ()
const {
return Iterator( Twist( -corners ) ); }
408 Iterator end ()
const {
return Iterator( Twist( corners ) ); }
410 template<
class Permutation >
411 Iterator find (
const Permutation &permutation )
const
414 const int origin = duneVertex2aluVertex( permutation( aluVertex2duneVertex( 0 ) ) );
415 const int next = duneVertex2aluVertex( permutation( aluVertex2duneVertex( 1 ) ) );
416 const Twist twist( origin, (origin + 1) % corners == next );
419 for(
int i = 0; i < corners; ++i )
421 if( twist( i ) != permutation( i ) )
424 return Iterator( twist );
430 static int aluVertex2duneVertex (
int i ) {
return ((corners == 3) ? i : swap23( i )); }
431 static int duneVertex2aluVertex (
int i ) {
return ((corners == 3) ? i : swap23( i )); }
433 static int swap23 (
int i ) {
return i ^ (i >> 1); }
442 class ALUTwists< 2, 1 >
446 static const int dimension = 1;
448 typedef ALUTwist< 2, 1 > Twist;
450 typedef ALUTwistIterator< Twist > Iterator;
456 std::size_t size ()
const {
return 2; }
459 std::size_t index (
const Twist &twist )
const {
return static_cast< int >( twist ); }
467 Iterator begin ()
const {
return Iterator( Twist( 0 ) ); }
470 Iterator end ()
const {
return Iterator( Twist(
int( size() ) ) ); }
472 template<
class Permutation >
473 Iterator find (
const Permutation &permutation )
const {
return Iterator( Twist( permutation( 0 ) ) ); }
483 template<
unsigned int topologyId,
int dim >
487 static const int dimension = dim;
497 explicit TrivialTwist ( GeometryType ) {}
507 TrivialTwist (
const TrivialTwist & ) {}
510 TrivialTwist &operator= (
const TrivialTwist & ) {
return *
this; }
520 TrivialTwist operator* (
const TrivialTwist & )
const {
return *
this; }
523 TrivialTwist operator/ (
const TrivialTwist & )
const {
return *
this; }
526 TrivialTwist &operator*= (
const TrivialTwist & )
const {
return *
this; }
529 TrivialTwist &operator/= (
const TrivialTwist & )
const {
return *
this; }
532 TrivialTwist inverse ()
const {
return *
this; }
542 bool operator== (
const TrivialTwist & )
const {
return true; }
545 bool operator!= (
const TrivialTwist & )
const {
return false; }
564 int operator() (
int i )
const {
return i; }
566 int operator() (
int i,
int codim )
const {
return i; }
576 template<
class ctype >
577 operator AffineGeometry< ctype, dimension, dimension > ()
const
583 bool positive ()
const {
return true; }
587 operator int ()
const {
return 0; }
595 template<
unsigned int topologyId,
int dim >
597 :
private TrivialTwist< topologyId, dim >
600 static const int dimension = dim;
602 typedef TrivialTwist< topologyId, dim > Twist;
604 typedef const Twist *Iterator;
607 explicit TrivialTwists ( GeometryType type ) {}
613 static std::size_t size () {
return 1; }
616 static std::size_t index (
const Twist & ) {
return 0; }
624 Iterator begin ()
const {
return &twist(); }
627 Iterator end ()
const {
return begin() + size(); }
629 template<
class Permutation >
630 Iterator find (
const Permutation &permutation )
const
634 for(
int i = 0; i < corners; ++i )
636 if( i != permutation( i ) )
645 const Twist &twist ()
const {
return *
this; }
An implementation of the Geometry interface for affine geometries.
Capabilities for ALUGrid.
GeometryType
Type representing VTK's entity geometry types.
Definition: common.hh:132
Implements a vector constructed from a given type representing a field and a compile-time given size.
constexpr GeometryType cube(unsigned int dim)
Returns a GeometryType representing a hypercube of dimension dim.
Definition: type.hh:472
constexpr GeometryType simplex(unsigned int dim)
Returns a GeometryType representing a simplex of dimension dim.
Definition: type.hh:463
EnableIfInterOperable< T1, T2, bool >::type operator==(const ForwardIteratorFacade< T1, V1, R1, D > &lhs, const ForwardIteratorFacade< T2, V2, R2, D > &rhs)
Checks for equality.
Definition: iteratorfacades.hh:237
EnableIfInterOperable< T1, T2, bool >::type operator!=(const ForwardIteratorFacade< T1, V1, R1, D > &lhs, const ForwardIteratorFacade< T2, V2, R2, D > &rhs)
Checks for inequality.
Definition: iteratorfacades.hh:259
Dune namespace.
Definition: alignedallocator.hh:13
static const ReferenceElement & general(const GeometryType &type)
get general reference elements
Definition: referenceelements.hh:198