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