3#ifndef DUNE_ALBERTA_DOFVECTOR_HH
4#define DUNE_ALBERTA_DOFVECTOR_HH
9#include <dune/grid/albertagrid/misc.hh>
33 struct DofVectorProvider;
36 struct DofVectorProvider< int >
38 typedef ALBERTA DOF_INT_VEC DofVector;
40 static DofVector *get (
const DofSpace *dofSpace,
const std::string &name )
42 return ALBERTA get_dof_int_vec( name.c_str(), dofSpace );
45 static void free ( DofVector *dofVector )
47 ALBERTA free_dof_int_vec( dofVector );
50 static DofVector *read (
const std::string &filename, Mesh *mesh, DofSpace *dofSpace )
52 return ALBERTA read_dof_int_vec_xdr( filename.c_str(), mesh, dofSpace );
55 static bool write (
const DofVector *dofVector,
const std::string &filename )
57 int success = ALBERTA write_dof_int_vec_xdr( dofVector, filename.c_str() );
58 return (success == 0);
63 struct DofVectorProvider< signed char >
65 typedef ALBERTA DOF_SCHAR_VEC DofVector;
67 static DofVector *get (
const DofSpace *dofSpace,
const std::string &name )
69 return ALBERTA get_dof_schar_vec( name.c_str(), dofSpace );
72 static void free ( DofVector *dofVector )
74 ALBERTA free_dof_schar_vec( dofVector );
77 static DofVector *read (
const std::string &filename, Mesh *mesh, DofSpace *dofSpace )
79 return ALBERTA read_dof_schar_vec_xdr( filename.c_str(), mesh, dofSpace );
82 static bool write (
const DofVector *dofVector,
const std::string &filename )
84 int success = ALBERTA write_dof_schar_vec_xdr( dofVector, filename.c_str() );
85 return (success == 0);
90 struct DofVectorProvider< unsigned char >
92 typedef ALBERTA DOF_UCHAR_VEC DofVector;
94 static DofVector *get (
const DofSpace *dofSpace,
const std::string &name )
96 return ALBERTA get_dof_uchar_vec( name.c_str(), dofSpace );
99 static void free ( DofVector *dofVector )
101 ALBERTA free_dof_uchar_vec( dofVector );
104 static DofVector *read (
const std::string &filename, Mesh *mesh, DofSpace *dofSpace )
106 return ALBERTA read_dof_uchar_vec_xdr( filename.c_str(), mesh, dofSpace );
109 static bool write (
const DofVector *dofVector,
const std::string &filename )
111 int success = ALBERTA write_dof_uchar_vec_xdr( dofVector, filename.c_str() );
112 return (success == 0);
117 struct DofVectorProvider< Real >
119 typedef ALBERTA DOF_REAL_VEC DofVector;
121 static DofVector *get (
const DofSpace *dofSpace,
const std::string &name )
123 return ALBERTA get_dof_real_vec( name.c_str(), dofSpace );
126 static void free ( DofVector *dofVector )
128 ALBERTA free_dof_real_vec( dofVector );
131 static DofVector *read (
const std::string &filename, Mesh *mesh, DofSpace *dofSpace )
133 return ALBERTA read_dof_real_vec_xdr( filename.c_str(), mesh, dofSpace );
136 static bool write (
const DofVector *dofVector,
const std::string &filename )
138 int success = ALBERTA write_dof_real_vec_xdr( dofVector, filename.c_str() );
139 return (success == 0);
144 struct DofVectorProvider< GlobalVector >
146 typedef ALBERTA DOF_REAL_D_VEC DofVector;
148 static DofVector *get (
const DofSpace *dofSpace,
const std::string &name )
150 return ALBERTA get_dof_real_d_vec( name.c_str(), dofSpace );
153 static void free ( DofVector *dofVector )
155 ALBERTA free_dof_real_d_vec( dofVector );
158 static DofVector *read (
const std::string &filename, Mesh *mesh, DofSpace *dofSpace )
160 return ALBERTA read_dof_real_d_vec_xdr( filename.c_str(), mesh, dofSpace );
163 static bool write (
const DofVector *dofVector,
const std::string &filename )
165 int success = ALBERTA write_dof_real_d_vec_xdr( dofVector, filename.c_str() );
166 return (success == 0);
175 template<
class Dof >
176 class DofVectorPointer
178 typedef DofVectorPointer< Dof > This;
180 typedef Alberta::DofVectorProvider< Dof > DofVectorProvider;
183 typedef typename DofVectorProvider::DofVector DofVector;
185 static const bool supportsAdaptationData =
true;
188 DofVector *dofVector_;
195 explicit DofVectorPointer (
const DofSpace *dofSpace,
196 const std::string &name =
"" )
197 : dofVector_ ( DofVectorProvider::get( dofSpace, name ) )
200 explicit DofVectorPointer ( DofVector *dofVector )
201 : dofVector_( dofVector )
204 operator bool ()
const
206 return (
bool)dofVector_;
209 operator DofVector * ()
const
214 operator Dof * ()
const
217 GET_DOF_VEC( ptr, dofVector_ );
221 const DofSpace *dofSpace ()
const
223 return dofVector_->fe_space;
226 std::string name ()
const
229 return dofVector_->name;
231 return std::string();
234 void create (
const DofSpace *dofSpace,
const std::string &name =
"" )
237 dofVector_ = DofVectorProvider::get( dofSpace, name );
241 void read (
const std::string &filename,
const MeshPointer< dim > &meshPointer )
244 dofVector_ = DofVectorProvider::read( filename, meshPointer, NULL );
247 bool write (
const std::string &filename )
const
249 return DofVectorProvider::write( dofVector_, filename );
256 DofVectorProvider::free( dofVector_ );
261 template<
class Functor >
262 void forEach ( Functor &functor )
const
264 Dof *array = (Dof *)(*
this);
265 FOR_ALL_DOFS( dofSpace()->admin, functor( array[ dof ] ) );
268 void initialize (
const Dof &value )
270 Dof *array = (Dof *)(*
this);
271 FOR_ALL_DOFS( dofSpace()->admin, array[ dof ] = value );
274 template<
class AdaptationData >
275 AdaptationData *getAdaptationData ()
const
277 assert( dofVector_ );
278 assert( dofVector_->user_data );
279 return static_cast< AdaptationData *
>( dofVector_->user_data );
282 template<
class AdaptationData >
283 void setAdaptationData ( AdaptationData *adaptationData )
285 assert( dofVector_ );
286 dofVector_->user_data = adaptationData;
289 template<
class Interpolation >
290 void setupInterpolation ()
292 assert( dofVector_ );
293 dofVector_->refine_interpol = &refineInterpolate< Interpolation >;
296 template<
class Restriction >
297 void setupRestriction ()
299 assert( dofVector_ );
300 dofVector_->coarse_restrict = &coarsenRestrict< Restriction >;
304 template<
class Interpolation >
305 static void refineInterpolate ( DofVector *dofVector, RC_LIST_EL *list,
int n )
307 const This dofVectorPointer( dofVector );
308 typename Interpolation::Patch patch( list, n );
309 Interpolation::interpolateVector( dofVectorPointer, patch );
312 template<
class Restriction >
313 static void coarsenRestrict ( DofVector *dofVector, RC_LIST_EL *list,
int n )
315 const This dofVectorPointer( dofVector );
316 typename Restriction::Patch patch( list, n );
317 Restriction::restrictVector( dofVectorPointer, patch );
326 inline void abs (
const DofVectorPointer< int > &dofVector )
328 assert( !dofVector ==
false );
329 int *array = (
int *)dofVector;
330 FOR_ALL_DOFS( dofVector.dofSpace()->admin,
331 array[ dof ] = std::abs( array[ dof ] ) );
335 inline int max (
const DofVectorPointer< int > &dofVector )
337 assert( !dofVector ==
false );
338 int *array = (
int *)dofVector;
339 int result = std::numeric_limits< int >::min();
340 FOR_ALL_DOFS( dofVector.dofSpace()->admin,
341 result = std::max( result, array[ dof ] ) );
346 inline int min (
const DofVectorPointer< int > &dofVector )
348 assert( !dofVector ==
false );
349 int *array = (
int *)dofVector;
350 int result = std::numeric_limits< int >::max();
351 FOR_ALL_DOFS( dofVector.dofSpace()->admin,
352 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
Dune namespace.
Definition: alignment.hh:10