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