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>
19 template<
int corners,
int dim >
22 template<
int corners,
int dim >
30 template<
class Twist >
32 :
public std::iterator< std::input_iterator_tag, Twist, int >
54 template<
int corners >
61 template<
class ctype >
65 typedef ReferenceElements< ctype, 2 > ReferenceElementContainerType;
68 typedef std::decay_t< decltype( ReferenceElementContainerType::general( std::declval< const Dune::GeometryType & >() ) ) > ReferenceElementType;
70 CoordVector (
const Twist &twist )
72 refElement_( ReferenceElements< ctype, 2 >::general( twist.type() ) )
75 const FieldVector< ctype, 2 > operator[] (
int i )
const {
return refElement().position( twist_( i ), 2 ); }
77 const ReferenceElementType& refElement ()
const {
return refElement_; }
81 const ReferenceElementType& refElement_;
86 static const int dimension = 2;
96 explicit ALUTwist ( GeometryType ) : aluTwist_( 0 ) {}
98 explicit ALUTwist (
int aluTwist ) : aluTwist_( aluTwist ) {}
101 : aluTwist_( positive ? origin : (origin + corners - 1) % corners - corners )
115 ALUTwist &operator= (
const ALUTwist &other ) { aluTwist_ = other.aluTwist_;
return *
this; }
127 return ALUTwist( apply( other.apply( 0 ) ), !(positive() ^ other.positive()) );
150 bool operator== (
const ALUTwist &other )
const {
return (aluTwist_ == other.aluTwist_); }
153 bool operator!= (
const ALUTwist &other )
const {
return (aluTwist_ != other.aluTwist_); }
166 return GeometryType(
typename Impl::SimplexTopology< dimension >::type() );
168 return GeometryType(
typename Impl::CubeTopology< dimension >::type() );
178 int operator() (
int i )
const {
return aluVertex2duneVertex( apply( duneVertex2aluVertex( i ) ) ); }
180 int operator() (
int i,
int codim )
const {
return alu2dune( apply( dune2alu( i, codim ), codim ), codim ); }
190 template<
class ctype >
191 operator AffineGeometry< ctype, dimension, dimension > ()
const
193 const CoordVector< ctype > coordVector( *
this );
194 return AffineGeometry< ctype, dimension, dimension >( coordVector.refElement(), coordVector );
198 bool positive ()
const {
return (aluTwist_ >= 0); }
204 operator int ()
const {
return aluTwist_; }
207 int apply (
int i )
const {
return ((positive() ? i : 2*corners + 1 - i) + aluTwist_) % corners; }
208 int apply (
int i,
int codim )
const {
return (codim == 0 ? i : (codim == 1 ? applyEdge( i ) :
apply( i ))); }
211 int applyEdge (
int i )
const {
return ((positive() ? i : 2*corners - i) + aluTwist_) % corners; }
214 static int aluEdge2duneEdge (
int i ) {
return ((corners == 3) ? (3 - i) % 3 : (6 - swap23( i )) % 4); }
215 static int duneEdge2aluEdge (
int i ) {
return ((corners == 3) ? (3 - i) % 3 : swap23( (6 - i) % 4 )); }
217 static int aluVertex2duneVertex (
int i ) {
return ((corners == 3) ? i : swap23( i )); }
218 static int duneVertex2aluVertex (
int i ) {
return ((corners == 3) ? i : swap23( i )); }
220 static int alu2dune (
int i,
int codim ) {
return (codim == 0 ? i : (codim == 1 ? aluEdge2duneEdge( i ) : aluVertex2duneVertex( i ))); }
221 static int dune2alu (
int i,
int codim ) {
return (codim == 0 ? i : (codim == 1 ? duneEdge2aluEdge( i ) : aluVertex2duneVertex( i ))); }
223 static int swap23 (
int i ) {
return i ^ (i >> 1); }
240 template<
class ctype >
243 CoordVector (
const Twist &twist ) : twist_( twist ) {}
245 FieldVector< ctype, 1 > operator[] (
int i )
const {
return FieldVector< ctype, 1 >( ctype( twist_( i ) ) ); }
253 static const int dimension = 1;
263 explicit ALUTwist ( GeometryType ) : aluTwist_( 0 ) {}
265 explicit ALUTwist (
int aluTwist ) : aluTwist_( aluTwist ) {}
267 explicit ALUTwist (
bool positive ) : aluTwist_( positive ) {}
280 ALUTwist &operator= (
const ALUTwist &other ) { aluTwist_ = other.aluTwist_;
return *
this; }
312 bool operator== (
const ALUTwist &other )
const {
return (aluTwist_ == other.aluTwist_); }
315 bool operator!= (
const ALUTwist &other )
const {
return (aluTwist_ != other.aluTwist_); }
325 GeometryType
type ()
const {
return GeometryType( Impl::CubeTopology< dimension >::type() ); }
334 int operator() (
int i )
const {
return (i ^ aluTwist_); }
336 int operator() (
int i,
int codim )
const {
return (codim == 0 ? i : (*
this)( i )); }
346 template<
class ctype >
347 operator AffineGeometry< ctype, dimension, dimension > ()
const
349 const CoordVector< ctype > coordVector( *
this );
350 return AffineGeometry< ctype, dimension, dimension >( type(), coordVector );
354 bool positive ()
const {
return (aluTwist_ == 0); }
358 operator int ()
const {
return aluTwist_; }
370 template<
int corners >
375 static const int dimension = 2;
385 return GeometryType(
typename Impl::SimplexTopology< dimension >::type() );
387 return GeometryType(
typename Impl::CubeTopology< dimension >::type() );
391 std::size_t
size ()
const {
return 2*corners; }
394 std::size_t
index (
const Twist &twist )
const {
return static_cast< int >( twist ) + corners; }
407 template<
class Permutation >
411 const int origin = duneVertex2aluVertex( permutation( aluVertex2duneVertex( 0 ) ) );
412 const int next = duneVertex2aluVertex( permutation( aluVertex2duneVertex( 1 ) ) );
413 const Twist twist( origin, (origin + 1) % corners == next );
416 for(
int i = 0; i < corners; ++i )
418 if( twist( i ) != permutation( i ) )
427 static int aluVertex2duneVertex (
int i ) {
return ((corners == 3) ? i : swap23( i )); }
428 static int duneVertex2aluVertex (
int i ) {
return ((corners == 3) ? i : swap23( i )); }
430 static int swap23 (
int i ) {
return i ^ (i >> 1); }
443 static const int dimension = 1;
450 GeometryType
type ()
const {
return GeometryType( Impl::CubeTopology< dimension >::type() ); }
453 std::size_t
size ()
const {
return 2; }
456 std::size_t
index (
const Twist &twist )
const {
return static_cast< int >( twist ); }
469 template<
class Permutation >
480 template<
unsigned int topologyId,
int dim >
552 GeometryType
type ()
const {
return GeometryType( topologyId, dim ); }
573 template<
class ctype >
574 operator AffineGeometry< ctype, dimension, dimension > ()
const
576 return ReferenceElements< ctype, dimension >::general(
type() ).template geometry< 0 >( 0 );
584 operator int ()
const {
return 0; }
592 template<
unsigned int topologyId,
int dim >
607 GeometryType
type ()
const {
return twist().
type(); }
610 static std::size_t
size () {
return 1; }
626 template<
class Permutation >
630 const int corners = ReferenceElements< double, dimension >::general(
type() ).size(
dimension );
631 for(
int i = 0; i < corners; ++i )
633 if( i != permutation( i ) )
642 const Twist &twist ()
const {
return *
this; }
Capabilities for ALUGrid.
Definition: alu3dinclude.hh:80
ALUTwistIterator & operator++()
Definition: twists.hh:42
bool operator==(const ALUTwistIterator &other) const
Definition: twists.hh:39
const Twist * operator->() const
Definition: twists.hh:37
const Twist & operator*() const
Definition: twists.hh:36
bool operator!=(const ALUTwistIterator &other) const
Definition: twists.hh:40
ALUTwistIterator(Twist twist)
Definition: twists.hh:34
ALUTwist(int origin, bool positive)
Definition: twists.hh:100
ALUTwist()
default constructor; results in identity twist
Definition: twists.hh:94
ALUTwist(const ALUTwist &other)
copy constructor
Definition: twists.hh:112
int apply(int i) const
Definition: twists.hh:207
ALUTwist(GeometryType)
Definition: twists.hh:96
bool positive() const
equivalent to
Definition: twists.hh:198
GeometryType type() const
Topological Corner Mapping.
Definition: twists.hh:163
ALUTwist inverse() const
obtain inverse
Definition: twists.hh:140
int apply(int i, int codim) const
Definition: twists.hh:208
ALUTwist(int aluTwist)
Definition: twists.hh:98
Definition: twists.hh:235
ALUTwist()
default constructor; results in identity twist
Definition: twists.hh:261
ALUTwist(GeometryType)
Definition: twists.hh:263
ALUTwist(bool positive)
Definition: twists.hh:267
ALUTwist(const ALUTwist &other)
copy constructor
Definition: twists.hh:277
ALUTwist(int aluTwist)
Definition: twists.hh:265
bool positive() const
equivalent to
Definition: twists.hh:354
GeometryType type() const
Topological Corner Mapping.
Definition: twists.hh:325
ALUTwist inverse() const
obtain inverse
Definition: twists.hh:302
std::size_t index(const Twist &twist) const
obtain index of a given twist
Definition: twists.hh:394
Iterator find(const Permutation &permutation) const
Definition: twists.hh:408
Iterator begin() const
obtain begin iterator
Definition: twists.hh:402
ALUTwistIterator< Twist > Iterator
Definition: twists.hh:379
Iterator end() const
obtain end iterator
Definition: twists.hh:405
ALUTwist< corners, 2 > Twist
Definition: twists.hh:377
GeometryType type() const
obtain type of reference element
Definition: twists.hh:382
std::size_t size() const
obtain number of twists in the group
Definition: twists.hh:391
Iterator find(const Permutation &permutation) const
Definition: twists.hh:470
std::size_t index(const Twist &twist) const
obtain index of a given twist
Definition: twists.hh:456
Iterator end() const
obtain end iterator
Definition: twists.hh:467
GeometryType type() const
obtain type of reference element
Definition: twists.hh:450
Iterator begin() const
obtain begin iterator
Definition: twists.hh:464
ALUTwistIterator< Twist > Iterator
Definition: twists.hh:447
std::size_t size() const
obtain number of twists in the group
Definition: twists.hh:453
ALUTwist< 2, 1 > Twist
Definition: twists.hh:445
Definition: twists.hh:482
TrivialTwist & operator=(const TrivialTwist &)
assignment operator
Definition: twists.hh:507
int operator()(int i) const
map i-th corner
Definition: twists.hh:561
TrivialTwist operator*(const TrivialTwist &) const
composition
Definition: twists.hh:517
TrivialTwist(GeometryType)
Definition: twists.hh:494
TrivialTwist inverse() const
obtain inverse
Definition: twists.hh:529
TrivialTwist & operator/=(const TrivialTwist &) const
composition with inverse
Definition: twists.hh:526
static const int dimension
dimension
Definition: twists.hh:484
TrivialTwist & operator*=(const TrivialTwist &) const
composition
Definition: twists.hh:523
bool operator==(const TrivialTwist &) const
Comparison.
Definition: twists.hh:539
bool positive() const
equivalent to
Definition: twists.hh:580
TrivialTwist()
default constructor; results in identity twist
Definition: twists.hh:492
TrivialTwist(const TrivialTwist &)
copy constructor
Definition: twists.hh:504
GeometryType type() const
Topological Corner Mapping.
Definition: twists.hh:552
TrivialTwist operator/(const TrivialTwist &) const
composition with inverse
Definition: twists.hh:520
bool operator!=(const TrivialTwist &) const
check for inequality
Definition: twists.hh:542
Definition: twists.hh:595
Iterator find(const Permutation &permutation) const
Definition: twists.hh:627
static std::size_t index(const Twist &)
obtain index of a given twist
Definition: twists.hh:613
TrivialTwist< topologyId, dim > Twist
Definition: twists.hh:599
static std::size_t size()
obtain number of twists in the group
Definition: twists.hh:610
TrivialTwists(GeometryType type)
Definition: twists.hh:604
Iterator end() const
obtain end iterator
Definition: twists.hh:624
TrivialTwists()
Definition: twists.hh:603
GeometryType type() const
obtain type of reference element
Definition: twists.hh:607
const Twist * Iterator
Definition: twists.hh:601
Iterator begin() const
obtain begin iterator
Definition: twists.hh:621
static const int dimension
dimension
Definition: twists.hh:597