Go to the documentation of this file. 1 #ifndef DUNE_ALUGRID_COMMON_TWISTS_HH
2 #define DUNE_ALUGRID_COMMON_TWISTS_HH
6 #include <dune/common/fvector.hh>
8 #include <dune/geometry/affinegeometry.hh>
9 #include <dune/geometry/referenceelements.hh>
10 #include <dune/geometry/type.hh>
18 template<
int corners,
int dim >
21 template<
int corners,
int dim >
29 template<
class Twist >
31 :
public std::iterator< std::input_iterator_tag, Twist, int >
53 template<
int corners >
60 template<
class ctype >
63 CoordVector (
const Twist &twist )
65 refElement_( ReferenceElements< ctype, 2 >::general( twist.type() ) )
68 const FieldVector< ctype, 2 > &operator[] (
int i )
const {
return refElement().position( twist_( i ), 2 ); }
70 const ReferenceElement< ctype, 2 > &refElement ()
const {
return refElement_; }
74 const ReferenceElement< ctype, 2 > &refElement_;
79 static const int dimension = 2;
89 explicit ALUTwist ( GeometryType ) : aluTwist_( 0 ) {}
91 explicit ALUTwist (
int aluTwist ) : aluTwist_( aluTwist ) {}
94 : aluTwist_( positive ? origin : (origin + corners - 1) % corners - corners )
108 ALUTwist &operator= (
const ALUTwist &other ) { aluTwist_ = other.aluTwist_;
return *
this; }
120 return ALUTwist( apply( other.apply( 0 ) ), !(positive() ^ other.positive()) );
143 bool operator== (
const ALUTwist &other )
const {
return (aluTwist_ == other.aluTwist_); }
146 bool operator!= (
const ALUTwist &other )
const {
return (aluTwist_ != other.aluTwist_); }
159 return GeometryType(
typename GenericGeometry::SimplexTopology< dimension >::type() );
161 return GeometryType(
typename GenericGeometry::CubeTopology< dimension >::type() );
171 int operator() (
int i )
const {
return aluVertex2duneVertex( apply( duneVertex2aluVertex( i ) ) ); }
173 int operator() (
int i,
int codim )
const {
return alu2dune( apply( dune2alu( i, codim ), codim ), codim ); }
183 template<
class ctype >
184 operator AffineGeometry< ctype, dimension, dimension > ()
const
186 const CoordVector< ctype > coordVector( *
this );
187 return AffineGeometry< ctype, dimension, dimension >( coordVector.refElement(), coordVector );
191 bool positive ()
const {
return (aluTwist_ >= 0); }
197 operator int ()
const {
return aluTwist_; }
200 int apply (
int i )
const {
return ((positive() ? i : 2*corners + 1 - i) + aluTwist_) % corners; }
201 int apply (
int i,
int codim )
const {
return (codim == 0 ? i : (codim == 1 ? applyEdge( i ) :
apply( i ))); }
204 int applyEdge (
int i )
const {
return ((positive() ? i : 2*corners - i) + aluTwist_) % corners; }
207 static int aluEdge2duneEdge (
int i ) {
return ((corners == 3) ? (3 - i) % 3 : (6 - swap23( i )) % 4); }
208 static int duneEdge2aluEdge (
int i ) {
return ((corners == 3) ? (3 - i) % 3 : swap23( (6 - i) % 4 )); }
210 static int aluVertex2duneVertex (
int i ) {
return ((corners == 3) ? i : swap23( i )); }
211 static int duneVertex2aluVertex (
int i ) {
return ((corners == 3) ? i : swap23( i )); }
213 static int alu2dune (
int i,
int codim ) {
return (codim == 0 ? i : (codim == 1 ? aluEdge2duneEdge( i ) : aluVertex2duneVertex( i ))); }
214 static int dune2alu (
int i,
int codim ) {
return (codim == 0 ? i : (codim == 1 ? duneEdge2aluEdge( i ) : aluVertex2duneVertex( i ))); }
216 static int swap23 (
int i ) {
return i ^ (i >> 1); }
233 template<
class ctype >
236 CoordVector (
const Twist &twist ) : twist_( twist ) {}
238 FieldVector< ctype, 1 > operator[] (
int i )
const {
return FieldVector< ctype, 1 >( ctype( twist_( i ) ) ); }
246 static const int dimension = 1;
256 explicit ALUTwist ( GeometryType ) : aluTwist_( 0 ) {}
258 explicit ALUTwist (
int aluTwist ) : aluTwist_( aluTwist ) {}
260 explicit ALUTwist (
bool positive ) : aluTwist_( positive ) {}
273 ALUTwist &operator= (
const ALUTwist &other ) { aluTwist_ = other.aluTwist_;
return *
this; }
305 bool operator== (
const ALUTwist &other )
const {
return (aluTwist_ == other.aluTwist_); }
308 bool operator!= (
const ALUTwist &other )
const {
return (aluTwist_ != other.aluTwist_); }
318 GeometryType
type ()
const {
return GeometryType( GenericGeometry::CubeTopology< dimension >::type() ); }
327 int operator() (
int i )
const {
return (i ^ aluTwist_); }
329 int operator() (
int i,
int codim )
const {
return (codim == 0 ? i : (*
this)( i )); }
339 template<
class ctype >
340 operator AffineGeometry< ctype, dimension, dimension > ()
const
342 const CoordVector< ctype > coordVector( *
this );
343 return AffineGeometry< ctype, dimension, dimension >( type(), coordVector );
347 bool positive ()
const {
return (aluTwist_ == 0); }
351 operator int ()
const {
return aluTwist_; }
363 template<
int corners >
368 static const int dimension = 2;
378 return GeometryType(
typename GenericGeometry::SimplexTopology< dimension >::type() );
380 return GeometryType(
typename GenericGeometry::CubeTopology< dimension >::type() );
384 std::size_t
size ()
const {
return 2*corners; }
387 std::size_t
index (
const Twist &twist )
const {
return static_cast< int >( twist ) + corners; }
400 template<
class Permutation >
404 const int origin = duneVertex2aluVertex( permutation( aluVertex2duneVertex( 0 ) ) );
405 const int next = duneVertex2aluVertex( permutation( aluVertex2duneVertex( 1 ) ) );
406 const Twist twist( origin, (origin + 1) % corners == next );
409 for(
int i = 0; i < corners; ++i )
411 if( twist( i ) != permutation( i ) )
420 static int aluVertex2duneVertex (
int i ) {
return ((corners == 3) ? i : swap23( i )); }
421 static int duneVertex2aluVertex (
int i ) {
return ((corners == 3) ? i : swap23( i )); }
423 static int swap23 (
int i ) {
return i ^ (i >> 1); }
436 static const int dimension = 1;
443 GeometryType
type ()
const {
return GeometryType( GenericGeometry::CubeTopology< dimension >::type() ); }
446 std::size_t
size ()
const {
return 2; }
449 std::size_t
index (
const Twist &twist )
const {
return static_cast< int >( twist ); }
462 template<
class Permutation >
473 template<
unsigned int topologyId,
int dim >
545 GeometryType
type ()
const {
return GeometryType( topologyId, dim ); }
566 template<
class ctype >
567 operator AffineGeometry< ctype, dimension, dimension > ()
const
569 return ReferenceElements< ctype, dimension >::general(
type() ).template geometry< 0 >( 0 );
577 operator int ()
const {
return 0; }
585 template<
unsigned int topologyId,
int dim >
600 GeometryType
type ()
const {
return twist().
type(); }
603 static std::size_t
size () {
return 1; }
619 template<
class Permutation >
623 const int corners = ReferenceElements< double, dimension >::general(
type() ).size(
dimension );
624 for(
int i = 0; i < corners; ++i )
626 if( i != permutation( i ) )
635 const Twist &twist ()
const {
return *
this; }
640 #endif // #ifndef DUNE_ALUGRID_COMMON_TWISTS_HH
TrivialTwist & operator/=(const TrivialTwist &) const
composition with inverse
Definition: twists.hh:519
TrivialTwist inverse() const
obtain inverse
Definition: twists.hh:522
Definition: twists.hh:586
bool operator!=(const TrivialTwist &) const
check for inequality
Definition: twists.hh:535
bool operator!=(const ALUTwistIterator &other) const
Definition: twists.hh:39
TrivialTwist()
default constructor; results in identity twist
Definition: twists.hh:485
Definition: twists.hh:227
ALUTwist< 2, 1 > Twist
Definition: twists.hh:438
ALUTwistIterator & operator++()
Definition: twists.hh:41
Iterator find(const Permutation &permutation) const
Definition: twists.hh:463
Iterator find(const Permutation &permutation) const
Definition: twists.hh:401
const Twist * operator->() const
Definition: twists.hh:36
static std::size_t index(const Twist &)
obtain index of a given twist
Definition: twists.hh:606
std::size_t size() const
obtain number of twists in the group
Definition: twists.hh:446
bool positive() const
equivalent to
Definition: twists.hh:573
ALUTwist(const ALUTwist &other)
copy constructor
Definition: twists.hh:270
bool positive() const
equivalent to
Definition: twists.hh:347
ALUTwistIterator< Twist > Iterator
Definition: twists.hh:440
Iterator end() const
obtain end iterator
Definition: twists.hh:617
TrivialTwists()
Definition: twists.hh:596
TrivialTwist(GeometryType)
Definition: twists.hh:487
const Twist & operator*() const
Definition: twists.hh:35
ALUTwist()
default constructor; results in identity twist
Definition: twists.hh:254
ALUTwist(bool positive)
Definition: twists.hh:260
int operator()(int i) const
map i-th corner
Definition: twists.hh:554
TrivialTwist(const TrivialTwist &)
copy constructor
Definition: twists.hh:497
TrivialTwist< topologyId, dim > Twist
Definition: twists.hh:592
GeometryType type() const
Topological Corner Mapping.
Definition: twists.hh:156
ALUTwist(int aluTwist)
Definition: twists.hh:258
Iterator begin() const
obtain begin iterator
Definition: twists.hh:457
ALUTwist()
default constructor; results in identity twist
Definition: twists.hh:87
ALUTwist< corners, 2 > Twist
Definition: twists.hh:370
Iterator end() const
obtain end iterator
Definition: twists.hh:398
GeometryType type() const
obtain type of reference element
Definition: twists.hh:375
ALUTwist(const ALUTwist &other)
copy constructor
Definition: twists.hh:105
GeometryType type() const
Topological Corner Mapping.
Definition: twists.hh:318
GeometryType type() const
obtain type of reference element
Definition: twists.hh:443
TrivialTwist operator*(const TrivialTwist &) const
composition
Definition: twists.hh:510
Definition: twists.hh:474
ALUTwist(GeometryType)
Definition: twists.hh:89
int apply(int i, int codim) const
Definition: twists.hh:201
static std::size_t size()
obtain number of twists in the group
Definition: twists.hh:603
ALUTwistIterator< Twist > Iterator
Definition: twists.hh:372
Iterator end() const
obtain end iterator
Definition: twists.hh:460
Iterator begin() const
obtain begin iterator
Definition: twists.hh:395
bool operator==(const TrivialTwist &) const
Comparison.
Definition: twists.hh:532
ALUTwist(int origin, bool positive)
Definition: twists.hh:93
TrivialTwist & operator=(const TrivialTwist &)
assignment operator
Definition: twists.hh:500
int apply(int i) const
Definition: twists.hh:200
std::size_t index(const Twist &twist) const
obtain index of a given twist
Definition: twists.hh:449
std::size_t index(const Twist &twist) const
obtain index of a given twist
Definition: twists.hh:387
const typedef Twist * Iterator
Definition: twists.hh:594
TrivialTwists(GeometryType type)
Definition: twists.hh:597
ALUTwist(int aluTwist)
Definition: twists.hh:91
Iterator find(const Permutation &permutation) const
Definition: twists.hh:620
GeometryType type() const
Topological Corner Mapping.
Definition: twists.hh:545
ALUTwist inverse() const
obtain inverse
Definition: twists.hh:295
static const int dimension
dimension
Definition: twists.hh:590
TrivialTwist & operator*=(const TrivialTwist &) const
composition
Definition: twists.hh:516
GeometryType type() const
obtain type of reference element
Definition: twists.hh:600
bool operator==(const ALUTwistIterator &other) const
Definition: twists.hh:38
TrivialTwist operator/(const TrivialTwist &) const
composition with inverse
Definition: twists.hh:513
ALUTwist(GeometryType)
Definition: twists.hh:256
ALUTwistIterator(Twist twist)
Definition: twists.hh:33
ALUTwist inverse() const
obtain inverse
Definition: twists.hh:133
Definition: alu3dinclude.hh:79
static const int dimension
dimension
Definition: twists.hh:477
std::size_t size() const
obtain number of twists in the group
Definition: twists.hh:384
Iterator begin() const
obtain begin iterator
Definition: twists.hh:614
bool positive() const
equivalent to
Definition: twists.hh:191