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; }
Definition alu3dinclude.hh:80
const Twist * operator->() const
Definition twists.hh:36
const Twist & operator*() const
Definition twists.hh:35
bool operator==(const ALUTwistIterator &other) const
Definition twists.hh:38
ALUTwistIterator & operator++()
Definition twists.hh:41
bool operator!=(const ALUTwistIterator &other) const
Definition twists.hh:39
ALUTwistIterator(Twist twist)
Definition twists.hh:33
ALUTwist(int origin, bool positive)
Definition twists.hh:93
ALUTwist()
default constructor; results in identity twist
Definition twists.hh:87
ALUTwist(const ALUTwist &other)
copy constructor
Definition twists.hh:105
int apply(int i) const
Definition twists.hh:200
ALUTwist(GeometryType)
Definition twists.hh:89
bool positive() const
equivalent to
Definition twists.hh:191
GeometryType type() const
Topological Corner Mapping.
Definition twists.hh:156
ALUTwist inverse() const
obtain inverse
Definition twists.hh:133
int apply(int i, int codim) const
Definition twists.hh:201
ALUTwist(int aluTwist)
Definition twists.hh:91
ALUTwist()
default constructor; results in identity twist
Definition twists.hh:254
ALUTwist(GeometryType)
Definition twists.hh:256
ALUTwist(bool positive)
Definition twists.hh:260
ALUTwist(const ALUTwist &other)
copy constructor
Definition twists.hh:270
ALUTwist(int aluTwist)
Definition twists.hh:258
bool positive() const
equivalent to
Definition twists.hh:347
GeometryType type() const
Topological Corner Mapping.
Definition twists.hh:318
ALUTwist inverse() const
obtain inverse
Definition twists.hh:295
std::size_t index(const Twist &twist) const
obtain index of a given twist
Definition twists.hh:387
Iterator find(const Permutation &permutation) const
Definition twists.hh:401
Iterator begin() const
obtain begin iterator
Definition twists.hh:395
ALUTwistIterator< Twist > Iterator
Definition twists.hh:372
Iterator end() const
obtain end iterator
Definition twists.hh:398
ALUTwist< corners, 2 > Twist
Definition twists.hh:370
GeometryType type() const
obtain type of reference element
Definition twists.hh:375
std::size_t size() const
obtain number of twists in the group
Definition twists.hh:384
Iterator find(const Permutation &permutation) const
Definition twists.hh:463
std::size_t index(const Twist &twist) const
obtain index of a given twist
Definition twists.hh:449
Iterator end() const
obtain end iterator
Definition twists.hh:460
GeometryType type() const
obtain type of reference element
Definition twists.hh:443
Iterator begin() const
obtain begin iterator
Definition twists.hh:457
ALUTwistIterator< Twist > Iterator
Definition twists.hh:440
std::size_t size() const
obtain number of twists in the group
Definition twists.hh:446
ALUTwist< 2, 1 > Twist
Definition twists.hh:438
int operator()(int i) const
map i-th corner
Definition twists.hh:554
TrivialTwist operator*(const TrivialTwist &) const
composition
Definition twists.hh:510
TrivialTwist & operator*=(const TrivialTwist &) const
composition
Definition twists.hh:516
TrivialTwist & operator=(const TrivialTwist &)
assignment operator
Definition twists.hh:500
TrivialTwist(GeometryType)
Definition twists.hh:487
TrivialTwist inverse() const
obtain inverse
Definition twists.hh:522
static const int dimension
dimension
Definition twists.hh:477
bool operator==(const TrivialTwist &) const
Comparison.
Definition twists.hh:532
bool positive() const
equivalent to
Definition twists.hh:573
TrivialTwist()
default constructor; results in identity twist
Definition twists.hh:485
TrivialTwist(const TrivialTwist &)
copy constructor
Definition twists.hh:497
GeometryType type() const
Topological Corner Mapping.
Definition twists.hh:545
TrivialTwist operator/(const TrivialTwist &) const
composition with inverse
Definition twists.hh:513
TrivialTwist & operator/=(const TrivialTwist &) const
composition with inverse
Definition twists.hh:519
bool operator!=(const TrivialTwist &) const
check for inequality
Definition twists.hh:535
Iterator find(const Permutation &permutation) const
Definition twists.hh:620
static std::size_t index(const Twist &)
obtain index of a given twist
Definition twists.hh:606
TrivialTwist< topologyId, dim > Twist
Definition twists.hh:592
static std::size_t size()
obtain number of twists in the group
Definition twists.hh:603
TrivialTwists(GeometryType type)
Definition twists.hh:597
Iterator end() const
obtain end iterator
Definition twists.hh:617
TrivialTwists()
Definition twists.hh:596
GeometryType type() const
obtain type of reference element
Definition twists.hh:600
const Twist * Iterator
Definition twists.hh:594
Iterator begin() const
obtain begin iterator
Definition twists.hh:614
static const int dimension
dimension
Definition twists.hh:590