Dune Core Modules (2.9.1)

dofvector.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_DOFVECTOR_HH
6#define DUNE_ALBERTA_DOFVECTOR_HH
7
8#include <cstdlib>
9#include <limits>
10
11#include <dune/grid/albertagrid/misc.hh>
14
15#if HAVE_ALBERTA
16
17namespace Dune
18{
19
20 namespace Alberta
21 {
22
23 // External Forward Declarations
24 // -----------------------------
25
26 template< int dim >
27 class MeshPointer;
28
29
30
31 // DofVectorProvider
32 // -----------------
33
34 template< class Dof >
35 struct DofVectorProvider;
36
37 template<>
38 struct DofVectorProvider< int >
39 {
40 typedef ALBERTA DOF_INT_VEC DofVector;
41
42 static DofVector *get ( const DofSpace *dofSpace, const std::string &name )
43 {
44 return ALBERTA get_dof_int_vec( name.c_str(), dofSpace );
45 }
46
47 static void free ( DofVector *dofVector )
48 {
49 ALBERTA free_dof_int_vec( dofVector );
50 }
51
52 static DofVector *read ( const std::string &filename, Mesh *mesh, DofSpace *dofSpace )
53 {
54 return ALBERTA read_dof_int_vec_xdr( filename.c_str(), mesh, dofSpace );
55 }
56
57 static bool write ( const DofVector *dofVector, const std::string &filename )
58 {
59 int success = ALBERTA write_dof_int_vec_xdr( dofVector, filename.c_str() );
60 return (success == 0);
61 }
62 };
63
64 template<>
65 struct DofVectorProvider< signed char >
66 {
67 typedef ALBERTA DOF_SCHAR_VEC DofVector;
68
69 static DofVector *get ( const DofSpace *dofSpace, const std::string &name )
70 {
71 return ALBERTA get_dof_schar_vec( name.c_str(), dofSpace );
72 }
73
74 static void free ( DofVector *dofVector )
75 {
76 ALBERTA free_dof_schar_vec( dofVector );
77 }
78
79 static DofVector *read ( const std::string &filename, Mesh *mesh, DofSpace *dofSpace )
80 {
81 return ALBERTA read_dof_schar_vec_xdr( filename.c_str(), mesh, dofSpace );
82 }
83
84 static bool write ( const DofVector *dofVector, const std::string &filename )
85 {
86 int success = ALBERTA write_dof_schar_vec_xdr( dofVector, filename.c_str() );
87 return (success == 0);
88 }
89 };
90
91 template<>
92 struct DofVectorProvider< unsigned char >
93 {
94 typedef ALBERTA DOF_UCHAR_VEC DofVector;
95
96 static DofVector *get ( const DofSpace *dofSpace, const std::string &name )
97 {
98 return ALBERTA get_dof_uchar_vec( name.c_str(), dofSpace );
99 }
100
101 static void free ( DofVector *dofVector )
102 {
103 ALBERTA free_dof_uchar_vec( dofVector );
104 }
105
106 static DofVector *read ( const std::string &filename, Mesh *mesh, DofSpace *dofSpace )
107 {
108 return ALBERTA read_dof_uchar_vec_xdr( filename.c_str(), mesh, dofSpace );
109 }
110
111 static bool write ( const DofVector *dofVector, const std::string &filename )
112 {
113 int success = ALBERTA write_dof_uchar_vec_xdr( dofVector, filename.c_str() );
114 return (success == 0);
115 }
116 };
117
118 template<>
119 struct DofVectorProvider< Real >
120 {
121 typedef ALBERTA DOF_REAL_VEC DofVector;
122
123 static DofVector *get ( const DofSpace *dofSpace, const std::string &name )
124 {
125 return ALBERTA get_dof_real_vec( name.c_str(), dofSpace );
126 }
127
128 static void free ( DofVector *dofVector )
129 {
130 ALBERTA free_dof_real_vec( dofVector );
131 }
132
133 static DofVector *read ( const std::string &filename, Mesh *mesh, DofSpace *dofSpace )
134 {
135 return ALBERTA read_dof_real_vec_xdr( filename.c_str(), mesh, dofSpace );
136 }
137
138 static bool write ( const DofVector *dofVector, const std::string &filename )
139 {
140 int success = ALBERTA write_dof_real_vec_xdr( dofVector, filename.c_str() );
141 return (success == 0);
142 }
143 };
144
145 template<>
146 struct DofVectorProvider< GlobalVector >
147 {
148 typedef ALBERTA DOF_REAL_D_VEC DofVector;
149
150 static DofVector *get ( const DofSpace *dofSpace, const std::string &name )
151 {
152 return ALBERTA get_dof_real_d_vec( name.c_str(), dofSpace );
153 }
154
155 static void free ( DofVector *dofVector )
156 {
157 ALBERTA free_dof_real_d_vec( dofVector );
158 }
159
160 static DofVector *read ( const std::string &filename, Mesh *mesh, DofSpace *dofSpace )
161 {
162 return ALBERTA read_dof_real_d_vec_xdr( filename.c_str(), mesh, dofSpace );
163 }
164
165 static bool write ( const DofVector *dofVector, const std::string &filename )
166 {
167 int success = ALBERTA write_dof_real_d_vec_xdr( dofVector, filename.c_str() );
168 return (success == 0);
169 }
170 };
171
172
173
174 // DofVectorPointer
175 // ----------------
176
177 template< class Dof >
178 class DofVectorPointer
179 {
180 typedef DofVectorPointer< Dof > This;
181
182 typedef Alberta::DofVectorProvider< Dof > DofVectorProvider;
183
184 public:
185 typedef typename DofVectorProvider::DofVector DofVector;
186
187 static const bool supportsAdaptationData = true;
188
189 private:
190 DofVector *dofVector_;
191
192 public:
193 DofVectorPointer ()
194 : dofVector_( NULL )
195 {}
196
197 explicit DofVectorPointer ( const DofSpace *dofSpace,
198 const std::string &name = "" )
199 : dofVector_ ( DofVectorProvider::get( dofSpace, name ) )
200 {}
201
202 explicit DofVectorPointer ( DofVector *dofVector )
203 : dofVector_( dofVector )
204 {}
205
206 explicit operator bool () const
207 {
208 return (bool)dofVector_;
209 }
210
211 operator DofVector * () const
212 {
213 return dofVector_;
214 }
215
216 operator Dof * () const
217 {
218 Dof *ptr = NULL;
219 GET_DOF_VEC( ptr, dofVector_ );
220 return ptr;
221 }
222
223 const DofSpace *dofSpace () const
224 {
225 return dofVector_->fe_space;
226 }
227
228 std::string name () const
229 {
230 if( dofVector_ )
231 return dofVector_->name;
232 else
233 return std::string();
234 }
235
236 void create ( const DofSpace *dofSpace, const std::string &name = "" )
237 {
238 release();
239 dofVector_ = DofVectorProvider::get( dofSpace, name );
240 }
241
242 template< int dim >
243 void read ( const std::string &filename, const MeshPointer< dim > &meshPointer )
244 {
245 release();
246 dofVector_ = DofVectorProvider::read( filename, meshPointer, NULL );
247 }
248
249 bool write ( const std::string &filename ) const
250 {
251 return DofVectorProvider::write( dofVector_, filename );
252 }
253
254 void release ()
255 {
256 if( dofVector_ )
257 {
258 DofVectorProvider::free( dofVector_ );
259 dofVector_ = NULL;
260 }
261 }
262
263 template< class Functor >
264 void forEach ( Functor &functor ) const
265 {
266 Dof *array = (Dof *)(*this);
267 FOR_ALL_DOFS( dofSpace()->admin, functor( array[ dof ] ) );
268 }
269
270 void initialize ( const Dof &value )
271 {
272 Dof *array = (Dof *)(*this);
273 FOR_ALL_DOFS( dofSpace()->admin, array[ dof ] = value );
274 }
275
276 template< class AdaptationData >
277 AdaptationData *getAdaptationData () const
278 {
279 assert( dofVector_ );
280 assert( dofVector_->user_data );
281 return static_cast< AdaptationData * >( dofVector_->user_data );
282 }
283
284 template< class AdaptationData >
285 void setAdaptationData ( AdaptationData *adaptationData )
286 {
287 assert( dofVector_ );
288 dofVector_->user_data = adaptationData;
289 }
290
291 template< class Interpolation >
292 void setupInterpolation ()
293 {
294 assert( dofVector_ );
295 dofVector_->refine_interpol = &refineInterpolate< Interpolation >;
296 }
297
298 template< class Restriction >
299 void setupRestriction ()
300 {
301 assert( dofVector_ );
302 dofVector_->coarse_restrict = &coarsenRestrict< Restriction >;
303 }
304
305 private:
306 template< class Interpolation >
307 static void refineInterpolate ( DofVector *dofVector, RC_LIST_EL *list, int n )
308 {
309 const This dofVectorPointer( dofVector );
310 typename Interpolation::Patch patch( list, n );
311 Interpolation::interpolateVector( dofVectorPointer, patch );
312 }
313
314 template< class Restriction >
315 static void coarsenRestrict ( DofVector *dofVector, RC_LIST_EL *list, int n )
316 {
317 const This dofVectorPointer( dofVector );
318 typename Restriction::Patch patch( list, n );
319 Restriction::restrictVector( dofVectorPointer, patch );
320 }
321 };
322
323
324
325 // Auxiliary Functions
326 // --------------------
327
328 inline void abs ( const DofVectorPointer< int > &dofVector )
329 {
330 assert( !dofVector == false );
331 int *array = (int *)dofVector;
332 FOR_ALL_DOFS( dofVector.dofSpace()->admin,
333 array[ dof ] = std::abs( array[ dof ] ) );
334 }
335
336
337 inline int max ( const DofVectorPointer< int > &dofVector )
338 {
339 assert( !dofVector == false );
340 int *array = (int *)dofVector;
341 int result = std::numeric_limits< int >::min();
342 FOR_ALL_DOFS( dofVector.dofSpace()->admin,
343 result = std::max( result, array[ dof ] ) );
344 return result;
345 }
346
347
348 inline int min ( const DofVectorPointer< int > &dofVector )
349 {
350 assert( !dofVector == false );
351 int *array = (int *)dofVector;
352 int result = std::numeric_limits< int >::max();
353 FOR_ALL_DOFS( dofVector.dofSpace()->admin,
354 result = std::min( result, array[ dof ] ) );
355 return result;
356 }
357
358 } // namespace Alberta
359
360} // namespace Dune
361
362#endif // #if HAVE_ALBERTA
363
364#endif // #ifndef DUNE_ALBERTA_DOFVECTOR_HH
provides a wrapper for ALBERTA's refinement patches and the corners for geometryInFather
provides a wrapper for ALBERTA's el_info structure
constexpr void forEach(Range &&range, F &&f)
Range based for loop.
Definition: hybridutilities.hh:268
auto min(ADLTag< 0 >, const V &v1, const V &v2)
implements binary Simd::min()
Definition: defaults.hh:89
auto max(ADLTag< 0 >, const V &v1, const V &v2)
implements binary Simd::max()
Definition: defaults.hh:81
Dune namespace.
Definition: alignedallocator.hh:13
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Nov 21, 23:30, 2024)