dune-grid  2.3.1
coordcache.hh
Go to the documentation of this file.
1 // -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 // vi: set et ts=4 sw=2 sts=2:
3 #ifndef DUNE_ALBERTA_COORDCACHE_HH
4 #define DUNE_ALBERTA_COORDCACHE_HH
5 
9 
10 #if HAVE_ALBERTA
11 
12 namespace Dune
13 {
14 
15  namespace Alberta
16  {
17 
18  // CoordCache
19  // ----------
20 
21  template< int dim >
22  class CoordCache
23  {
26 
27  class LocalCaching;
28  struct Interpolation;
29 
30  public:
31  static const int dimension = dim;
32 
36 
37  GlobalVector &operator() ( const Element *element, int vertex ) const
38  {
39  assert( !(!coords_) );
40  GlobalVector *array = (GlobalVector *)coords_;
41  return array[ dofAccess_( element, vertex ) ];
42  }
43 
44  GlobalVector &operator() ( const ElementInfo &elementInfo, int vertex ) const
45  {
46  return (*this)( elementInfo.el(), vertex );
47  }
48 
49  void create ( const DofNumbering &dofNumbering )
50  {
51  MeshPointer mesh = dofNumbering.mesh();
52  const DofSpace *dofSpace = dofNumbering.dofSpace( dimension );
53 
54  coords_.create( dofSpace, "Coordinate Cache" );
55  LocalCaching localCaching( coords_ );
57  coords_.template setupInterpolation< Interpolation >();
58 
59  dofAccess_ = DofAccess( dofSpace );
60  }
61 
62  void release ()
63  {
64  coords_.release();
65  }
66 
67  private:
68  CoordVectorPointer coords_;
69  DofAccess dofAccess_;
70  };
71 
72 
73 
74  // CoordCache::LocalCaching
75  // ------------------------
76 
77  template< int dim >
78  class CoordCache< dim >::LocalCaching
79  {
80  CoordVectorPointer coords_;
81  DofAccess dofAccess_;
82 
83  public:
84  explicit LocalCaching ( const CoordVectorPointer &coords )
85  : coords_( coords ),
86  dofAccess_( coords.dofSpace() )
87  {}
88 
89  void operator() ( const ElementInfo &elementInfo ) const
90  {
91  GlobalVector *array = (GlobalVector *)coords_;
92  for( int i = 0; i < DofAccess::numSubEntities; ++i )
93  {
94  const GlobalVector &x = elementInfo.coordinate( i );
95  GlobalVector &y = array[ dofAccess_( elementInfo.el(), i ) ];
96  for( int i = 0; i < dimWorld; ++i )
97  y[ i ] = x[ i ];
98  }
99  }
100  };
101 
102 
103 
104  // CoordCache::Interpolation
105  // -------------------------
106 
107  template< int dim >
108  struct CoordCache< dim >::Interpolation
109  {
110  static const int dimension = dim;
111 
113 
114  static void
115  interpolateVector ( const CoordVectorPointer &dofVector, const Patch &patch )
116  {
117  DofAccess dofAccess( dofVector.dofSpace() );
118  GlobalVector *array = (GlobalVector *)dofVector;
119 
120  const Element *element = patch[ 0 ];
121 
122  // new vertex is always the last one
123  assert( element->child[ 0 ] != NULL );
124  GlobalVector &newCoord = array[ dofAccess( element->child[ 0 ], dimension ) ];
125 
126  if( element->new_coord != NULL )
127  {
128  for( int j = 0; j < dimWorld; ++j )
129  newCoord[ j ] = element->new_coord[ j ];
130  }
131  else
132  {
133  // new coordinate is the average of of old ones on the same edge
134  // refinement edge is always between vertices 0 and 1
135  const GlobalVector &coord0 = array[ dofAccess( element, 0 ) ];
136  const GlobalVector &coord1 = array[ dofAccess( element, 1 ) ];
137  for( int j = 0; j < dimWorld; ++j )
138  newCoord[ j ] = 0.5 * (coord0[ j ] + coord1[ j ]);
139  }
140  }
141  };
142 
143  }
144 
145 }
146 
147 #endif // #if HAVE_ALBERTA
148 
149 #endif // #ifndef DUNE_ALBERTA_COORDCACHE_HH
HierarchyDofNumbering< dimension > DofNumbering
Definition: coordcache.hh:35
static const int dimWorld
Definition: misc.hh:43
Definition: coordcache.hh:78
Definition: common.hh:179
provides a wrapper for ALBERTA's mesh structure
Alberta::ElementInfo< dimension > ElementInfo
Definition: coordcache.hh:33
ALBERTA FE_SPACE DofSpace
Definition: misc.hh:76
void create(const DofNumbering &dofNumbering)
Definition: coordcache.hh:49
static const int numSubEntities
Definition: dofadmin.hh:34
GlobalVector & operator()(const Element *element, int vertex) const
Definition: coordcache.hh:37
ALBERTA REAL_D GlobalVector
Definition: misc.hh:47
void release()
Definition: dofvector.hh:252
const DofSpace * dofSpace(int codim) const
Definition: dofadmin.hh:139
Alberta::Patch< dimension > Patch
Definition: coordcache.hh:112
void create(const DofSpace *dofSpace, const std::string &name="")
Definition: dofvector.hh:234
LocalCaching(const CoordVectorPointer &coords)
Definition: coordcache.hh:84
void hierarchicTraverse(Functor &functor, typename FillFlags::Flags fillFlags=FillFlags::standard) const
Definition: meshpointer.hh:368
const MeshPointer & mesh() const
Definition: dofadmin.hh:152
Alberta::MeshPointer< dimension > MeshPointer
Definition: coordcache.hh:34
Definition: misc.hh:241
static const int dimension
Definition: coordcache.hh:31
Definition: coordcache.hh:22
const GlobalVector & coordinate(int vertex) const
Definition: elementinfo.hh:745
ALBERTA EL Element
Definition: misc.hh:61
Definition: coordcache.hh:108
static void interpolateVector(const CoordVectorPointer &dofVector, const Patch &patch)
Definition: coordcache.hh:115
const DofSpace * dofSpace() const
Definition: dofvector.hh:221
Definition: albertagrid/refinement.hh:37
Element * el() const
Definition: elementinfo.hh:797
void release()
Definition: coordcache.hh:62