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;
41 typedef Alberta::ElementInfo< dim > ElementInfo;
42 typedef typename ElementInfo::MacroElement MacroElement;
43 typedef typename ElementInfo::FillFlags FillFlags;
45 class BoundaryProvider;
47 template<
int dimWorld >
57 explicit MeshPointer ( Mesh *mesh )
61 operator Mesh * ()
const
66 operator bool ()
const
71 MacroIterator begin ()
const
73 return MacroIterator( *
this,
false );
76 MacroIterator end ()
const
78 return MacroIterator( *
this,
true );
81 int numMacroElements ()
const;
82 int size (
int codim )
const;
87 unsigned int create (
const MacroData< dim > ¯oData );
93 template<
class Proj,
class Impl >
94 unsigned int create (
const MacroData< dim > ¯oData,
95 const ProjectionFactoryInterface< Proj, Impl > &projectionFactory );
101 unsigned int create (
const std::string &filename,
bool binary =
false );
112 unsigned int read (
const std::string &filename, Real &time );
114 bool write (
const std::string &filename, Real time )
const;
118 template<
class Functor >
119 void hierarchicTraverse ( Functor &functor,
120 typename FillFlags::Flags fillFlags = FillFlags::standard )
const;
122 template<
class Functor >
123 void leafTraverse ( Functor &functor,
124 typename FillFlags::Flags fillFlags = FillFlags::standard )
const;
126 bool coarsen (
typename FillFlags::Flags fillFlags = FillFlags::nothing );
128 bool refine (
typename FillFlags::Flags fillFlags = FillFlags::nothing );
131 static ALBERTA NODE_PROJECTION *
132 initNodeProjection ( Mesh *mesh, ALBERTA MACRO_EL *macroElement,
int n );
133 template<
class ProjectionProv
ider >
134 static ALBERTA NODE_PROJECTION *
135 initNodeProjection ( Mesh *mesh, ALBERTA MACRO_EL *macroElement,
int n );
146 template<
int dimWorld >
147 struct MeshPointer< dim >::Library
149 typedef Alberta::MeshPointer< dim > MeshPointer;
151 static unsigned int boundaryCount;
152 static const void *projectionFactory;
155 create ( MeshPointer &ptr,
const MacroData< dim > ¯oData,
156 ALBERTA NODE_PROJECTION *(*initNodeProjection)( Mesh *, ALBERTA MACRO_EL *,
int ) );
157 static void release ( MeshPointer &ptr );
166 class MeshPointer< dim >::MacroIterator
168 typedef MacroIterator This;
170 friend class MeshPointer< dim >;
173 typedef Alberta::MeshPointer< dim > MeshPointer;
174 typedef Alberta::ElementInfo< dim > ElementInfo;
177 explicit MacroIterator (
const MeshPointer &mesh,
bool end =
false )
179 index_( end ? mesh.numMacroElements() : 0 )
185 return (index_ >= mesh().numMacroElements());
188 bool equals (
const MacroIterator &other )
const
190 return (index_ == other.index_);
199 const MacroElement ¯oElement ()
const
202 return static_cast< const MacroElement &
>( mesh().mesh_->macro_els[ index_ ] );
205 const MeshPointer &mesh ()
const
216 ElementInfo operator* ()
const
218 return elementInfo();
221 bool operator== (
const MacroIterator &other )
const
223 return equals( other );
226 bool operator!= (
const MacroIterator &other )
const
228 return !equals( other );
232 elementInfo (
typename FillFlags::Flags fillFlags = FillFlags::standard )
const
235 return ElementInfo();
237 return ElementInfo( mesh(), macroElement(), fillFlags );
251 inline int MeshPointer< dim >::numMacroElements ()
const
253 return (mesh_ ? mesh_->n_macro_el : 0);
258 inline int MeshPointer< 1 >::size(
int codim )
const
260 assert( (codim >= 0) && (codim <= 1) );
261 return (codim == 0 ? mesh_->n_elements : mesh_->n_vertices);
265 inline int MeshPointer< 2 >::size(
int codim )
const
267 assert( (codim >= 0) && (codim <= 2) );
269 return mesh_->n_elements;
270 else if( codim == 2 )
271 return mesh_->n_vertices;
273 return mesh_->n_edges;
277 inline int MeshPointer< 3 >::size(
int codim )
const
279 assert( (codim >= 0) && (codim <= 3) );
281 return mesh_->n_elements;
282 else if( codim == 3 )
283 return mesh_->n_vertices;
284 else if( codim == 1 )
285 return mesh_->n_faces;
287 return mesh_->n_edges;
292 inline unsigned int MeshPointer< dim >
293 ::create (
const MacroData< dim > ¯oData )
297 Library< dimWorld >::boundaryCount = 0;
298 Library< dimWorld >::create( *
this, macroData, &initNodeProjection );
299 return Library< dimWorld >::boundaryCount;
304 template<
class Proj,
class Impl >
305 inline unsigned int MeshPointer< dim >
306 ::create (
const MacroData< dim > ¯oData,
307 const ProjectionFactoryInterface< Proj, Impl > &projectionFactory )
309 typedef ProjectionFactoryInterface< Proj, Impl > ProjectionFactory;
313 Library< dimWorld >::boundaryCount = 0;
314 Library< dimWorld >::projectionFactory = &projectionFactory;
315 Library< dimWorld >::create( *
this, macroData, &initNodeProjection< ProjectionFactory > );
316 Library< dimWorld >::projectionFactory = 0;
317 return Library< dimWorld >::boundaryCount;
324 inline unsigned int MeshPointer< dim >
325 ::create (
const std::string &filename,
bool binary )
327 MacroData< dim > macroData;
328 macroData.read( filename, binary );
329 const unsigned int boundaryCount = create( macroData );
331 return boundaryCount;
336 inline unsigned int MeshPointer< dim >::read (
const std::string &filename, Real &time )
340 Library< dimWorld >::boundaryCount = 0;
341#if DUNE_ALBERTA_VERSION >= 0x300
342 mesh_ = ALBERTA read_mesh_xdr( filename.c_str(), &time, NULL, NULL );
344 mesh_ = ALBERTA read_mesh_xdr( filename.c_str(), &time, 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 );
395#if DUNE_ALBERTA_VERSION >= 0x300
397 inline bool MeshPointer< dim >::coarsen (
typename FillFlags::Flags fillFlags )
399 const bool coarsened = (ALBERTA coarsen( mesh_, fillFlags ) == meshCoarsened);
401 ALBERTA dof_compress( mesh_ );
406#if DUNE_ALBERTA_VERSION <= 0x200
408 inline bool MeshPointer< dim >::coarsen (
typename FillFlags::Flags fillFlags )
410 assert( fillFlags == FillFlags::nothing );
411 const bool coarsened = (ALBERTA coarsen( mesh_ ) == meshCoarsened);
413 ALBERTA dof_compress( mesh_ );
419#if DUNE_ALBERTA_VERSION >= 0x300
421 inline bool MeshPointer< dim >::refine (
typename FillFlags::Flags fillFlags )
423 return (ALBERTA refine( mesh_, fillFlags ) == meshRefined);
427#if DUNE_ALBERTA_VERSION <= 0x200
429 inline bool MeshPointer< dim >::refine (
typename FillFlags::Flags fillFlags )
431 assert( fillFlags == FillFlags::nothing );
432 return (ALBERTA refine( mesh_ ) == meshRefined);
438 inline ALBERTA NODE_PROJECTION *
439 MeshPointer< dim >::initNodeProjection ( Mesh *mesh, ALBERTA MACRO_EL *macroEl,
int n )
441 const MacroElement ¯oElement =
static_cast< const MacroElement &
>( *macroEl );
442 if( (n > 0) && macroElement.isBoundary( n-1 ) )
443 return new BasicNodeProjection( Library< dimWorld >::boundaryCount++ );
450 template<
class ProjectionFactory >
451 inline ALBERTA NODE_PROJECTION *
452 MeshPointer< dim >::initNodeProjection ( Mesh *mesh, ALBERTA MACRO_EL *macroEl,
int n )
454 typedef typename ProjectionFactory::Projection Projection;
456 const MacroElement ¯oElement =
static_cast< const MacroElement &
>( *macroEl );
458 MeshPointer< dim > meshPointer( mesh );
459 ElementInfo elementInfo( meshPointer, macroElement, FillFlags::standard );
460 const ProjectionFactory &projectionFactory = *
static_cast< const ProjectionFactory *
>( Library< dimWorld >::projectionFactory );
461 if( (n > 0) && macroElement.isBoundary( n-1 ) )
463 const unsigned int boundaryIndex = Library< dimWorld >::boundaryCount++;
464 if( projectionFactory.hasProjection( elementInfo, n-1 ) )
466 Projection projection = projectionFactory.projection( elementInfo, n-1 );
467 return new NodeProjection< dim, Projection >( boundaryIndex, projection );
470 return new BasicNodeProjection( boundaryIndex );
472 else if( (dim < dimWorld) && (n == 0) )
474 const unsigned int boundaryIndex = std::numeric_limits< unsigned int >::max();
475 if( projectionFactory.hasProjection( elementInfo ) )
477 Projection projection = projectionFactory.projection( elementInfo );
478 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:231
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:253
provides a wrapper for ALBERTA's macro_data structure
Dune namespace.
Definition: alignment.hh:14