DUNE PDELab (git)

projection.hh
1// SPDX-FileCopyrightText: Copyright © 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_NODEPROJECTION_HH
6#define DUNE_ALBERTA_NODEPROJECTION_HH
7
8#include <memory>
9
10#include <dune/grid/common/boundaryprojection.hh>
11
12#include <dune/grid/albertagrid/misc.hh>
14
15#if HAVE_ALBERTA
16
17namespace Dune
18{
19
20 namespace Alberta
21 {
22
23 // Internal Forward Declarations
24 // -----------------------------
25
26 template< class Proj, class Impl >
27 class ProjectionFactory;
28
29
30
31 // DuneBoundaryProjection
32 // ----------------------
33
34 template< int dim >
35 class DuneBoundaryProjection
36 {
37 typedef DuneBoundaryProjection< dim > This;
38
39 public:
40 static const int dimension = dim;
41
42 typedef Alberta::ElementInfo< dimension > ElementInfo;
43 typedef FieldVector< Real, dimWorld > GlobalCoordinate;
44
46 typedef std::shared_ptr< const Projection > ProjectionPtr;
47
48 explicit DuneBoundaryProjection ( const ProjectionPtr &projection )
49 : projection_( projection )
50 {}
51
52 // note: GlobalVector is an array type; global is the return value
53 void operator() ( const ElementInfo & /* elementInfo */, const LocalVector /* local */,
54 GlobalVector global ) const
55 {
56 GlobalCoordinate x;
57 for( int i = 0; i < dimWorld; ++i )
58 x[ i ] = global[ i ];
59 GlobalCoordinate y = projection() ( x );
60 for( int i = 0; i < dimWorld; ++i )
61 global[ i ] = y[ i ];
62 }
63
64 const Projection &projection () const
65 {
66 return *projection_;
67 }
68
69 private:
70 ProjectionPtr projection_;
71 };
72
73
74
75 // ProjectionFactoryInterface
76 // --------------------------
77
78 template< class Proj, class Impl >
79 class ProjectionFactoryInterface
80 {
81 typedef ProjectionFactoryInterface< Proj, Impl > This;
82
83 friend class ProjectionFactory< Proj, Impl >;
84
85 public:
86 typedef Proj Projection;
87
88 static const int dimension = Projection::dimension;
89
90 typedef Alberta::ElementInfo< dimension > ElementInfo;
91
92 private:
93 ProjectionFactoryInterface ()
94 {}
95
96 ProjectionFactoryInterface ( const This &other );
97 This &operator= ( const This &other );
98
99 public:
100 bool hasProjection ( const ElementInfo &elementInfo, const int face ) const
101 {
102 return asImpl().hasProjection( elementInfo, face );
103 }
104
105 bool hasProjection ( const ElementInfo &elementInfo ) const
106 {
107 return asImpl().hasProjection( elementInfo );
108 }
109
110 Projection projection ( const ElementInfo &elementInfo, const int face ) const
111 {
112 return asImpl().projection( elementInfo, face );
113 };
114
115 Projection projection ( const ElementInfo &elementInfo ) const
116 {
117 return asImpl().projection( elementInfo );
118 };
119
120 protected:
121 const Impl &asImpl () const
122 {
123 return static_cast< const Impl & >( *this );
124 }
125 };
126
127
128
129 // ProjectionFactory
130 // -----------------
131
132 template< class Proj, class Impl >
133 class ProjectionFactory
134 : public ProjectionFactoryInterface< Proj, Impl >
135 {
136 typedef ProjectionFactory< Proj, Impl > This;
137 typedef ProjectionFactoryInterface< Proj, Impl > Base;
138
139 public:
140 typedef typename Base::Projection Projection;
141 typedef typename Base::ElementInfo ElementInfo;
142
143 protected:
144 ProjectionFactory ()
145 {}
146
147 private:
148 bool hasProjection ( const ElementInfo &elementInfo, const int face ) const;
149 bool hasProjection ( const ElementInfo &elementInfo ) const;
150
151 Projection projection ( const ElementInfo &elementInfo, const int face ) const;
152 Projection projection ( const ElementInfo &elementInfo ) const;
153 };
154
155
156
157 // DuneGlobalBoundaryProjectionFactory
158 // -----------------------------------
159
160 template< int dim >
161 class DuneGlobalBoundaryProjectionFactory
162 : public ProjectionFactory< DuneBoundaryProjection< dim >, DuneGlobalBoundaryProjectionFactory< dim > >
163 {
164 typedef DuneGlobalBoundaryProjectionFactory< dim > This;
165 typedef ProjectionFactory< DuneBoundaryProjection< dim >, This > Base;
166
167 public:
168 typedef typename Base::Projection Projection;
169 typedef typename Base::ElementInfo ElementInfo;
170
171 typedef typename Projection::ProjectionPtr DuneProjectionPtr;
172
173 DuneGlobalBoundaryProjectionFactory ( const DuneProjectionPtr &projection )
174 : projection_( projection )
175 {}
176
177 bool hasProjection ( const ElementInfo &elementInfo, const int face ) const
178 {
179 return true;
180 }
181
182 bool hasProjection ( const ElementInfo &elementInfo ) const
183 {
184 return true;
185 }
186
187 Projection projection ( const ElementInfo &elementInfo, const int face ) const
188 {
189 return projection_;
190 };
191
192 Projection projection ( const ElementInfo &elementInfo ) const
193 {
194 return projection_;
195 };
196
197 private:
198 const Projection projection_;
199 };
200
201
202
203 // BasicNodeProjection
204 // -------------------
205
206 struct BasicNodeProjection
207 : public ALBERTA NODE_PROJECTION
208 {
209 explicit BasicNodeProjection ( unsigned int boundaryIndex )
210 : boundaryIndex_( boundaryIndex )
211 {
212 func = 0;
213 }
214
215 virtual ~BasicNodeProjection ()
216 {}
217
218 unsigned int boundaryIndex () const
219 {
220 return boundaryIndex_;
221 }
222
223 private:
224 unsigned int boundaryIndex_;
225 };
226
227
228
229 // NodeProjection
230 // --------------
231
232 template< int dim, class Projection >
233 class NodeProjection
234 : public BasicNodeProjection
235 {
236 typedef NodeProjection< dim, Projection > This;
237 typedef BasicNodeProjection Base;
238
239 public:
240 static const int dimension = dim;
241
242 typedef Alberta::ElementInfo< dimension > ElementInfo;
243
244 private:
245 Projection projection_;
246
247 public:
248 NodeProjection ( unsigned int boundaryIndex, const Projection &projection )
249 : Base( boundaryIndex ),
250 projection_( projection )
251 {
252 func = apply;
253 }
254
255 private:
256 // note: global is the return type (it is an array type and hence no
257 // reference is needed)
258 static void apply ( GlobalVector global, const EL_INFO *info, const LocalVector local )
259 {
260 const ElementInfo elementInfo = ElementInfo::createFake( *info );
261
262 assert( (info->fill_flag & FillFlags< dimension >::projection) != 0 );
263 const This *nodeProjection = static_cast< const This * >( info->active_projection );
264
265 assert( nodeProjection != NULL );
266 nodeProjection->projection_( elementInfo, local, global );
267 }
268 };
269
270 }
271
272}
273
274#endif // #if HAVE_ALBERTA
275
276#endif // #ifndef DUNE_ALBERTA_NODEPROJECTION_HH
provides a wrapper for ALBERTA's el_info structure
Dune namespace.
Definition: alignedallocator.hh:13
Interface class for vertex projection at the boundary.
Definition: boundaryprojection.hh:33
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Nov 13, 23:29, 2024)