Dune Core Modules (2.9.0)

coordcache.hh
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
9#include <dune/grid/albertagrid/dofadmin.hh>
10#include <dune/grid/albertagrid/dofvector.hh>
11
12#if HAVE_ALBERTA
13
14namespace Dune
15{
16
17 namespace Alberta
18 {
19
20 // CoordCache
21 // ----------
22
23 template< int dim >
24 class CoordCache
25 {
26 typedef DofVectorPointer< GlobalVector > CoordVectorPointer;
27 typedef Alberta::DofAccess< dim, dim > DofAccess;
28
29 class LocalCaching;
30 struct Interpolation;
31
32 public:
33 static const int dimension = dim;
34
35 typedef Alberta::ElementInfo< dimension > ElementInfo;
36 typedef Alberta::MeshPointer< dimension > MeshPointer;
37 typedef HierarchyDofNumbering< dimension > DofNumbering;
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_ );
58 mesh.hierarchicTraverse( localCaching, FillFlags< dimension >::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 >
80 class CoordCache< dim >::LocalCaching
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 >
110 struct CoordCache< dim >::Interpolation
111 {
112 static const int dimension = dim;
113
114 typedef Alberta::Patch< dimension > Patch;
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
constexpr GeometryType vertex
GeometryType representing a vertex.
Definition: type.hh:506
provides a wrapper for ALBERTA's mesh structure
Dune namespace.
Definition: alignedallocator.hh:13
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Jul 15, 22:36, 2024)