5#ifndef DUNE_ALBERTA_DOFVECTOR_HH
6#define DUNE_ALBERTA_DOFVECTOR_HH
11#include <dune/grid/albertagrid/misc.hh>
35 struct DofVectorProvider;
38 struct DofVectorProvider< int >
40 typedef ALBERTA DOF_INT_VEC DofVector;
42 static DofVector *get (
const DofSpace *dofSpace,
const std::string &name )
44 return ALBERTA get_dof_int_vec( name.c_str(), dofSpace );
47 static void free ( DofVector *dofVector )
49 ALBERTA free_dof_int_vec( dofVector );
52 static DofVector *read (
const std::string &filename, Mesh *mesh, DofSpace *dofSpace )
54 return ALBERTA read_dof_int_vec_xdr( filename.c_str(), mesh, dofSpace );
57 static bool write (
const DofVector *dofVector,
const std::string &filename )
59 int success = ALBERTA write_dof_int_vec_xdr( dofVector, filename.c_str() );
60 return (success == 0);
65 struct DofVectorProvider< signed char >
67 typedef ALBERTA DOF_SCHAR_VEC DofVector;
69 static DofVector *get (
const DofSpace *dofSpace,
const std::string &name )
71 return ALBERTA get_dof_schar_vec( name.c_str(), dofSpace );
74 static void free ( DofVector *dofVector )
76 ALBERTA free_dof_schar_vec( dofVector );
79 static DofVector *read (
const std::string &filename, Mesh *mesh, DofSpace *dofSpace )
81 return ALBERTA read_dof_schar_vec_xdr( filename.c_str(), mesh, dofSpace );
84 static bool write (
const DofVector *dofVector,
const std::string &filename )
86 int success = ALBERTA write_dof_schar_vec_xdr( dofVector, filename.c_str() );
87 return (success == 0);
92 struct DofVectorProvider< unsigned char >
94 typedef ALBERTA DOF_UCHAR_VEC DofVector;
96 static DofVector *get (
const DofSpace *dofSpace,
const std::string &name )
98 return ALBERTA get_dof_uchar_vec( name.c_str(), dofSpace );
101 static void free ( DofVector *dofVector )
103 ALBERTA free_dof_uchar_vec( dofVector );
106 static DofVector *read (
const std::string &filename, Mesh *mesh, DofSpace *dofSpace )
108 return ALBERTA read_dof_uchar_vec_xdr( filename.c_str(), mesh, dofSpace );
111 static bool write (
const DofVector *dofVector,
const std::string &filename )
113 int success = ALBERTA write_dof_uchar_vec_xdr( dofVector, filename.c_str() );
114 return (success == 0);
119 struct DofVectorProvider< Real >
121 typedef ALBERTA DOF_REAL_VEC DofVector;
123 static DofVector *get (
const DofSpace *dofSpace,
const std::string &name )
125 return ALBERTA get_dof_real_vec( name.c_str(), dofSpace );
128 static void free ( DofVector *dofVector )
130 ALBERTA free_dof_real_vec( dofVector );
133 static DofVector *read (
const std::string &filename, Mesh *mesh, DofSpace *dofSpace )
135 return ALBERTA read_dof_real_vec_xdr( filename.c_str(), mesh, dofSpace );
138 static bool write (
const DofVector *dofVector,
const std::string &filename )
140 int success = ALBERTA write_dof_real_vec_xdr( dofVector, filename.c_str() );
141 return (success == 0);
146 struct DofVectorProvider< GlobalVector >
148 typedef ALBERTA DOF_REAL_D_VEC DofVector;
150 static DofVector *get (
const DofSpace *dofSpace,
const std::string &name )
152 return ALBERTA get_dof_real_d_vec( name.c_str(), dofSpace );
155 static void free ( DofVector *dofVector )
157 ALBERTA free_dof_real_d_vec( dofVector );
160 static DofVector *read (
const std::string &filename, Mesh *mesh, DofSpace *dofSpace )
162 return ALBERTA read_dof_real_d_vec_xdr( filename.c_str(), mesh, dofSpace );
165 static bool write (
const DofVector *dofVector,
const std::string &filename )
167 int success = ALBERTA write_dof_real_d_vec_xdr( dofVector, filename.c_str() );
168 return (success == 0);
177 template<
class Dof >
178 class DofVectorPointer
180 typedef DofVectorPointer< Dof > This;
182 typedef Alberta::DofVectorProvider< Dof > DofVectorProvider;
185 typedef typename DofVectorProvider::DofVector DofVector;
187 static const bool supportsAdaptationData =
true;
190 DofVector *dofVector_;
197 explicit DofVectorPointer (
const DofSpace *dofSpace,
198 const std::string &name =
"" )
199 : dofVector_ ( DofVectorProvider::get( dofSpace, name ) )
202 explicit DofVectorPointer ( DofVector *dofVector )
203 : dofVector_( dofVector )
206 explicit operator bool ()
const
208 return (
bool)dofVector_;
211 operator DofVector * ()
const
216 operator Dof * ()
const
219 GET_DOF_VEC( ptr, dofVector_ );
223 const DofSpace *dofSpace ()
const
225 return dofVector_->fe_space;
228 std::string name ()
const
231 return dofVector_->name;
233 return std::string();
236 void create (
const DofSpace *dofSpace,
const std::string &name =
"" )
239 dofVector_ = DofVectorProvider::get( dofSpace, name );
243 void read (
const std::string &filename,
const MeshPointer< dim > &meshPointer )
246 dofVector_ = DofVectorProvider::read( filename, meshPointer, NULL );
249 bool write (
const std::string &filename )
const
251 return DofVectorProvider::write( dofVector_, filename );
258 DofVectorProvider::free( dofVector_ );
263 template<
class Functor >
264 void forEach ( Functor &functor )
const
266 Dof *array = (Dof *)(*
this);
267 FOR_ALL_DOFS( dofSpace()->admin, functor( array[ dof ] ) );
270 void initialize (
const Dof &value )
272 Dof *array = (Dof *)(*
this);
273 FOR_ALL_DOFS( dofSpace()->admin, array[ dof ] = value );
276 template<
class AdaptationData >
277 AdaptationData *getAdaptationData ()
const
279 assert( dofVector_ );
280 assert( dofVector_->user_data );
281 return static_cast< AdaptationData *
>( dofVector_->user_data );
284 template<
class AdaptationData >
285 void setAdaptationData ( AdaptationData *adaptationData )
287 assert( dofVector_ );
288 dofVector_->user_data = adaptationData;
291 template<
class Interpolation >
292 void setupInterpolation ()
294 assert( dofVector_ );
295 dofVector_->refine_interpol = &refineInterpolate< Interpolation >;
298 template<
class Restriction >
299 void setupRestriction ()
301 assert( dofVector_ );
302 dofVector_->coarse_restrict = &coarsenRestrict< Restriction >;
306 template<
class Interpolation >
307 static void refineInterpolate ( DofVector *dofVector, RC_LIST_EL *list,
int n )
309 const This dofVectorPointer( dofVector );
310 typename Interpolation::Patch patch( list, n );
311 Interpolation::interpolateVector( dofVectorPointer, patch );
314 template<
class Restriction >
315 static void coarsenRestrict ( DofVector *dofVector, RC_LIST_EL *list,
int n )
317 const This dofVectorPointer( dofVector );
318 typename Restriction::Patch patch( list, n );
319 Restriction::restrictVector( dofVectorPointer, patch );
328 inline void abs (
const DofVectorPointer< int > &dofVector )
330 assert( !dofVector ==
false );
331 int *array = (
int *)dofVector;
332 FOR_ALL_DOFS( dofVector.dofSpace()->admin,
333 array[ dof ] = std::abs( array[ dof ] ) );
337 inline int max (
const DofVectorPointer< int > &dofVector )
339 assert( !dofVector ==
false );
340 int *array = (
int *)dofVector;
342 FOR_ALL_DOFS( dofVector.dofSpace()->admin,
343 result =
std::max( result, array[ dof ] ) );
348 inline int min (
const DofVectorPointer< int > &dofVector )
350 assert( !dofVector ==
false );
351 int *array = (
int *)dofVector;
353 FOR_ALL_DOFS( dofVector.dofSpace()->admin,
354 result =
std::min( result, array[ dof ] ) );
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