Dune Core Modules (2.4.2)

coordcache.hh
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
7#include <dune/grid/albertagrid/dofadmin.hh>
8#include <dune/grid/albertagrid/dofvector.hh>
9
10#if HAVE_ALBERTA
11
12namespace Dune
13{
14
15 namespace Alberta
16 {
17
18 // CoordCache
19 // ----------
20
21 template< int dim >
22 class CoordCache
23 {
24 typedef DofVectorPointer< GlobalVector > CoordVectorPointer;
25 typedef Alberta::DofAccess< dim, dim > DofAccess;
26
27 class LocalCaching;
28 struct Interpolation;
29
30 public:
31 static const int dimension = dim;
32
33 typedef Alberta::ElementInfo< dimension > ElementInfo;
34 typedef Alberta::MeshPointer< dimension > MeshPointer;
35 typedef HierarchyDofNumbering< dimension > DofNumbering;
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_ );
56 mesh.hierarchicTraverse( localCaching, FillFlags< dimension >::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
112 typedef Alberta::Patch< dimension > Patch;
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
Dune namespace.
Definition: alignment.hh:10
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Dec 21, 23:30, 2024)