3#ifndef DUNE_ALBERTA_MESHPOINTER_HH
4#define DUNE_ALBERTA_MESHPOINTER_HH
14#include <dune/grid/albertagrid/misc.hh>
17#include <dune/grid/albertagrid/projection.hh>
31 class HierarchyDofNumbering;
39 typedef Alberta::ElementInfo< dim > ElementInfo;
40 typedef typename ElementInfo::MacroElement MacroElement;
41 typedef typename ElementInfo::FillFlags FillFlags;
43 class BoundaryProvider;
45 template<
int dimWorld >
55 explicit MeshPointer ( Mesh *mesh )
59 operator Mesh * ()
const
64 operator bool ()
const
69 MacroIterator begin ()
const
71 return MacroIterator( *
this,
false );
74 MacroIterator end ()
const
76 return MacroIterator( *
this,
true );
79 int numMacroElements ()
const;
80 int size (
int codim )
const;
85 unsigned int create (
const MacroData< dim > ¯oData );
91 template<
class Proj,
class Impl >
92 unsigned int create (
const MacroData< dim > ¯oData,
93 const ProjectionFactoryInterface< Proj, Impl > &projectionFactory );
99 unsigned int create (
const std::string &filename,
bool binary =
false );
110 unsigned int read (
const std::string &filename, Real &time );
112 bool write (
const std::string &filename, Real time )
const;
116 template<
class Functor >
117 void hierarchicTraverse ( Functor &functor,
118 typename FillFlags::Flags fillFlags = FillFlags::standard )
const;
120 template<
class Functor >
121 void leafTraverse ( Functor &functor,
122 typename FillFlags::Flags fillFlags = FillFlags::standard )
const;
124 bool coarsen (
typename FillFlags::Flags fillFlags = FillFlags::nothing );
126 bool refine (
typename FillFlags::Flags fillFlags = FillFlags::nothing );
129 static ALBERTA NODE_PROJECTION *
130 initNodeProjection ( Mesh *mesh, ALBERTA MACRO_EL *macroElement,
int n );
131 template<
class ProjectionProv
ider >
132 static ALBERTA NODE_PROJECTION *
133 initNodeProjection ( Mesh *mesh, ALBERTA MACRO_EL *macroElement,
int n );
144 template<
int dimWorld >
145 struct MeshPointer< dim >::Library
147 typedef Alberta::MeshPointer< dim > MeshPointer;
149 static unsigned int boundaryCount;
150 static const void *projectionFactory;
153 create ( MeshPointer &ptr,
const MacroData< dim > ¯oData,
154 ALBERTA NODE_PROJECTION *(*initNodeProjection)( Mesh *, ALBERTA MACRO_EL *,
int ) );
155 static void release ( MeshPointer &ptr );
164 class MeshPointer< dim >::MacroIterator
166 typedef MacroIterator This;
168 friend class MeshPointer< dim >;
171 typedef Alberta::MeshPointer< dim > MeshPointer;
172 typedef Alberta::ElementInfo< dim > ElementInfo;
181 explicit MacroIterator (
const MeshPointer &mesh,
bool end =
false )
183 index_( end ? mesh.numMacroElements() : 0 )
189 return (index_ >= mesh().numMacroElements());
192 bool equals (
const MacroIterator &other )
const
194 return (index_ == other.index_);
203 const MacroElement ¯oElement ()
const
206 return static_cast< const MacroElement &
>( mesh().mesh_->macro_els[ index_ ] );
209 const MeshPointer &mesh ()
const
220 ElementInfo operator* ()
const
222 return elementInfo();
225 bool operator== (
const MacroIterator &other )
const
227 return equals( other );
230 bool operator!= (
const MacroIterator &other )
const
232 return !equals( other );
236 elementInfo (
typename FillFlags::Flags fillFlags = FillFlags::standard )
const
239 return ElementInfo();
241 return ElementInfo( mesh(), macroElement(), fillFlags );
255 inline int MeshPointer< dim >::numMacroElements ()
const
257 return (mesh_ ? mesh_->n_macro_el : 0);
262 inline int MeshPointer< 1 >::size(
int codim )
const
264 assert( (codim >= 0) && (codim <= 1) );
265 return (codim == 0 ? mesh_->n_elements : mesh_->n_vertices);
269 inline int MeshPointer< 2 >::size(
int codim )
const
271 assert( (codim >= 0) && (codim <= 2) );
273 return mesh_->n_elements;
274 else if( codim == 2 )
275 return mesh_->n_vertices;
277 return mesh_->n_edges;
281 inline int MeshPointer< 3 >::size(
int codim )
const
283 assert( (codim >= 0) && (codim <= 3) );
285 return mesh_->n_elements;
286 else if( codim == 3 )
287 return mesh_->n_vertices;
288 else if( codim == 1 )
289 return mesh_->n_faces;
291 return mesh_->n_edges;
296 inline unsigned int MeshPointer< dim >
297 ::create (
const MacroData< dim > ¯oData )
301 Library< dimWorld >::boundaryCount = 0;
302 Library< dimWorld >::create( *
this, macroData, &initNodeProjection );
303 return Library< dimWorld >::boundaryCount;
308 template<
class Proj,
class Impl >
309 inline unsigned int MeshPointer< dim >
310 ::create (
const MacroData< dim > ¯oData,
311 const ProjectionFactoryInterface< Proj, Impl > &projectionFactory )
313 typedef ProjectionFactoryInterface< Proj, Impl > ProjectionFactory;
317 Library< dimWorld >::boundaryCount = 0;
318 Library< dimWorld >::projectionFactory = &projectionFactory;
319 Library< dimWorld >::create( *
this, macroData, &initNodeProjection< ProjectionFactory > );
320 Library< dimWorld >::projectionFactory = 0;
321 return Library< dimWorld >::boundaryCount;
328 inline unsigned int MeshPointer< dim >
329 ::create (
const std::string &filename,
bool binary )
331 MacroData< dim > macroData;
332 macroData.read( filename, binary );
333 const unsigned int boundaryCount = create( macroData );
335 return boundaryCount;
340 inline unsigned int MeshPointer< dim >::read (
const std::string &filename, Real &time )
344 Library< dimWorld >::boundaryCount = 0;
345 mesh_ = ALBERTA read_mesh_xdr( filename.c_str(), &time, NULL, NULL );
346 return Library< dimWorld >::boundaryCount;
351 inline bool MeshPointer< dim >::write (
const std::string &filename, Real time )
const
353 int success = ALBERTA write_mesh_xdr( mesh_, filename.c_str(), time );
354 return (success == 0);
359 inline void MeshPointer< dim >::release ()
361 Library< dimWorld >::release( *
this );
366 template<
class Functor >
367 inline void MeshPointer< dim >
368 ::hierarchicTraverse ( Functor &functor,
369 typename FillFlags::Flags fillFlags )
const
371 const MacroIterator eit = end();
372 for( MacroIterator it = begin(); it != eit; ++it )
374 const ElementInfo info = it.elementInfo( fillFlags );
375 info.hierarchicTraverse( functor );
381 template<
class Functor >
382 inline void MeshPointer< dim >
383 ::leafTraverse ( Functor &functor,
384 typename FillFlags::Flags fillFlags )
const
386 const MacroIterator eit = end();
387 for( MacroIterator it = begin(); it != eit; ++it )
389 const ElementInfo info = it.elementInfo( fillFlags );
390 info.leafTraverse( functor );
396 inline bool MeshPointer< dim >::coarsen (
typename FillFlags::Flags fillFlags )
398 const bool coarsened = (ALBERTA coarsen( mesh_, fillFlags ) == meshCoarsened);
400 ALBERTA dof_compress( mesh_ );
405 inline bool MeshPointer< dim >::refine (
typename FillFlags::Flags fillFlags )
407 return (ALBERTA refine( mesh_, fillFlags ) == meshRefined);
412 inline ALBERTA NODE_PROJECTION *
413 MeshPointer< dim >::initNodeProjection ( Mesh *mesh, ALBERTA MACRO_EL *macroEl,
int n )
415 const MacroElement ¯oElement =
static_cast< const MacroElement &
>( *macroEl );
416 if( (n > 0) && macroElement.isBoundary( n-1 ) )
417 return new BasicNodeProjection( Library< dimWorld >::boundaryCount++ );
424 template<
class ProjectionFactory >
425 inline ALBERTA NODE_PROJECTION *
426 MeshPointer< dim >::initNodeProjection ( Mesh *mesh, ALBERTA MACRO_EL *macroEl,
int n )
428 typedef typename ProjectionFactory::Projection Projection;
430 const MacroElement ¯oElement =
static_cast< const MacroElement &
>( *macroEl );
432 MeshPointer< dim > meshPointer( mesh );
433 ElementInfo elementInfo( meshPointer, macroElement, FillFlags::standard );
434 const ProjectionFactory &projectionFactory = *
static_cast< const ProjectionFactory *
>( Library< dimWorld >::projectionFactory );
435 if( (n > 0) && macroElement.isBoundary( n-1 ) )
437 const unsigned int boundaryIndex = Library< dimWorld >::boundaryCount++;
438 if( projectionFactory.hasProjection( elementInfo, n-1 ) )
440 Projection projection = projectionFactory.projection( elementInfo, n-1 );
441 return new NodeProjection< dim, Projection >( boundaryIndex, projection );
444 return new BasicNodeProjection( boundaryIndex );
446 else if( (dim < dimWorld) && (n == 0) )
448 const unsigned int boundaryIndex = std::numeric_limits< unsigned int >::max();
449 if( projectionFactory.hasProjection( elementInfo ) )
451 Projection projection = projectionFactory.projection( elementInfo );
452 return new NodeProjection< dim, Projection >( boundaryIndex, projection );
provides a wrapper for ALBERTA's el_info structure
EnableIfInterOperable< T1, T2, bool >::type operator==(const ForwardIteratorFacade< T1, V1, R1, D > &lhs, const ForwardIteratorFacade< T2, V2, R2, D > &rhs)
Checks for equality.
Definition: iteratorfacades.hh:230
EnableIfInterOperable< T1, T2, bool >::type operator!=(const ForwardIteratorFacade< T1, V1, R1, D > &lhs, const ForwardIteratorFacade< T2, V2, R2, D > &rhs)
Checks for inequality.
Definition: iteratorfacades.hh:252
provides a wrapper for ALBERTA's macro_data structure
Dune namespace.
Definition: alignment.hh:10