dune-grid 2.8.0
Loading...
Searching...
No Matches
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
12namespace Dune
13{
14
15 namespace Alberta
16 {
17
18 // CoordCache
19 // ----------
20
21 template< int dim >
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 >
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 >
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
provides a wrapper for ALBERTA's mesh structure
Include standard header files.
Definition: agrid.hh:58
ALBERTA EL Element
Definition: misc.hh:52
ALBERTA FE_SPACE DofSpace
Definition: misc.hh:63
static const int dimWorld
Definition: misc.hh:44
ALBERTA REAL_D GlobalVector
Definition: misc.hh:48
Definition: coordcache.hh:23
static const int dimension
Definition: coordcache.hh:31
GlobalVector & operator()(const Element *element, int vertex) const
Definition: coordcache.hh:37
Alberta::MeshPointer< dimension > MeshPointer
Definition: coordcache.hh:34
void release()
Definition: coordcache.hh:62
Alberta::ElementInfo< dimension > ElementInfo
Definition: coordcache.hh:33
HierarchyDofNumbering< dimension > DofNumbering
Definition: coordcache.hh:35
void create(const DofNumbering &dofNumbering)
Definition: coordcache.hh:49
Definition: coordcache.hh:79
LocalCaching(const CoordVectorPointer &coords)
Definition: coordcache.hh:84
Definition: coordcache.hh:109
Alberta::Patch< dimension > Patch
Definition: coordcache.hh:112
static void interpolateVector(const CoordVectorPointer &dofVector, const Patch &patch)
Definition: coordcache.hh:115
void hierarchicTraverse(Functor &functor, typename FillFlags::Flags fillFlags=FillFlags::standard) const
Definition: meshpointer.hh:368
static const int numSubEntities
Definition: dofadmin.hh:38
const MeshPointer & mesh() const
Definition: dofadmin.hh:156
const DofSpace * dofSpace(int codim) const
Definition: dofadmin.hh:143
void create(const DofSpace *dofSpace, const std::string &name="")
Definition: dofvector.hh:234
void release()
Definition: dofvector.hh:252
const DofSpace * dofSpace() const
Definition: dofvector.hh:221
const GlobalVector & coordinate(int vertex) const
Definition: elementinfo.hh:683
Element * el() const
Definition: elementinfo.hh:735
Definition: misc.hh:229
Definition: refinement.hh:38