5#ifndef DUNE_ALBERTA_MESHPOINTER_HH
6#define DUNE_ALBERTA_MESHPOINTER_HH
16#include <dune/grid/albertagrid/misc.hh>
19#include <dune/grid/albertagrid/projection.hh>
33 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 explicit 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 ( [[maybe_unused]] 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 inline unsigned int boundaryCount = 0;
152 static inline const void *projectionFactory =
nullptr;
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;
183 explicit MacroIterator (
const MeshPointer &mesh,
bool end =
false )
185 index_( end ? mesh.numMacroElements() : 0 )
191 return (index_ >= mesh().numMacroElements());
194 bool equals (
const MacroIterator &other )
const
196 return (index_ == other.index_);
205 const MacroElement ¯oElement ()
const
208 return static_cast< const MacroElement &
>( mesh().mesh_->macro_els[ index_ ] );
211 const MeshPointer &mesh ()
const
222 ElementInfo operator* ()
const
224 return elementInfo();
227 bool operator== (
const MacroIterator &other )
const
232 bool operator!= (
const MacroIterator &other )
const
238 elementInfo (
typename FillFlags::Flags fillFlags = FillFlags::standard )
const
241 return ElementInfo();
243 return ElementInfo( mesh(), macroElement(), fillFlags );
257 inline int MeshPointer< dim >::numMacroElements ()
const
259 return (mesh_ ? mesh_->n_macro_el : 0);
264 inline int MeshPointer< 1 >::size(
int codim )
const
266 assert( (codim >= 0) && (codim <= 1) );
267 return (codim == 0 ? mesh_->n_elements : mesh_->n_vertices);
271 inline int MeshPointer< 2 >::size(
int codim )
const
273 assert( (codim >= 0) && (codim <= 2) );
275 return mesh_->n_elements;
276 else if( codim == 2 )
277 return mesh_->n_vertices;
279 return mesh_->n_edges;
283 inline int MeshPointer< 3 >::size(
int codim )
const
285 assert( (codim >= 0) && (codim <= 3) );
287 return mesh_->n_elements;
288 else if( codim == 3 )
289 return mesh_->n_vertices;
290 else if( codim == 1 )
291 return mesh_->n_faces;
293 return mesh_->n_edges;
298 inline unsigned int MeshPointer< dim >
299 ::create (
const MacroData< dim > ¯oData )
303 Library< dimWorld >::boundaryCount = 0;
304 Library< dimWorld >::create( *
this, macroData, &initNodeProjection );
305 return Library< dimWorld >::boundaryCount;
310 template<
class Proj,
class Impl >
311 inline unsigned int MeshPointer< dim >
312 ::create (
const MacroData< dim > ¯oData,
313 const ProjectionFactoryInterface< Proj, Impl > &projectionFactory )
315 typedef ProjectionFactoryInterface< Proj, Impl > ProjectionFactory;
319 Library< dimWorld >::boundaryCount = 0;
320 Library< dimWorld >::projectionFactory = &projectionFactory;
321 Library< dimWorld >::create( *
this, macroData, &initNodeProjection< ProjectionFactory > );
322 Library< dimWorld >::projectionFactory =
nullptr;
323 return Library< dimWorld >::boundaryCount;
330 inline unsigned int MeshPointer< dim >
331 ::create (
const std::string &filename,
bool binary )
333 MacroData< dim > macroData;
334 macroData.read( filename, binary );
335 const unsigned int boundaryCount = create( macroData );
337 return boundaryCount;
342 inline unsigned int MeshPointer< dim >::read (
const std::string &filename, Real &time )
346 Library< dimWorld >::boundaryCount = 0;
347 mesh_ = ALBERTA read_mesh_xdr( filename.c_str(), &time, NULL, NULL );
348 return Library< dimWorld >::boundaryCount;
353 inline bool MeshPointer< dim >::write (
const std::string &filename, Real time )
const
355 int success = ALBERTA write_mesh_xdr( mesh_, filename.c_str(), time );
356 return (success == 0);
361 inline void MeshPointer< dim >::release ()
363 Library< dimWorld >::release( *
this );
368 template<
class Functor >
369 inline void MeshPointer< dim >
370 ::hierarchicTraverse ( Functor &functor,
371 typename FillFlags::Flags fillFlags )
const
373 const MacroIterator eit = end();
374 for( MacroIterator it = begin(); it != eit; ++it )
376 const ElementInfo info = it.elementInfo( fillFlags );
377 info.hierarchicTraverse( functor );
383 template<
class Functor >
384 inline void MeshPointer< dim >
385 ::leafTraverse ( Functor &functor,
386 typename FillFlags::Flags fillFlags )
const
388 const MacroIterator eit = end();
389 for( MacroIterator it = begin(); it != eit; ++it )
391 const ElementInfo info = it.elementInfo( fillFlags );
392 info.leafTraverse( functor );
398 inline bool MeshPointer< dim >::coarsen (
typename FillFlags::Flags fillFlags )
400 const bool coarsened = (ALBERTA coarsen( mesh_, fillFlags ) == meshCoarsened);
402 ALBERTA dof_compress( mesh_ );
407 inline bool MeshPointer< dim >::refine (
typename FillFlags::Flags fillFlags )
409 return (ALBERTA refine( mesh_, fillFlags ) == meshRefined);
414 inline ALBERTA NODE_PROJECTION *
415 MeshPointer< dim >::initNodeProjection ( Mesh *mesh, ALBERTA MACRO_EL *macroEl,
int n )
417 const MacroElement ¯oElement =
static_cast< const MacroElement &
>( *macroEl );
418 if( (n > 0) && macroElement.isBoundary( n-1 ) )
419 return new BasicNodeProjection( Library< dimWorld >::boundaryCount++ );
426 template<
class ProjectionFactory >
427 inline ALBERTA NODE_PROJECTION *
428 MeshPointer< dim >::initNodeProjection ( Mesh *mesh, ALBERTA MACRO_EL *macroEl,
int n )
430 typedef typename ProjectionFactory::Projection Projection;
432 const MacroElement ¯oElement =
static_cast< const MacroElement &
>( *macroEl );
434 MeshPointer< dim > meshPointer( mesh );
435 ElementInfo elementInfo( meshPointer, macroElement, FillFlags::standard );
436 const ProjectionFactory &projectionFactory = *
static_cast< const ProjectionFactory *
>( Library< dimWorld >::projectionFactory );
437 if( (n > 0) && macroElement.isBoundary( n-1 ) )
439 const unsigned int boundaryIndex = Library< dimWorld >::boundaryCount++;
440 if( projectionFactory.hasProjection( elementInfo, n-1 ) )
442 Projection projection = projectionFactory.projection( elementInfo, n-1 );
443 return new NodeProjection< dim, Projection >( boundaryIndex, projection );
446 return new BasicNodeProjection( boundaryIndex );
448 else if( (dim < dimWorld) && (n == 0) )
451 if( projectionFactory.hasProjection( elementInfo ) )
453 Projection projection = projectionFactory.projection( elementInfo );
454 return new NodeProjection< dim, Projection >( boundaryIndex, projection );
provides a wrapper for ALBERTA's el_info structure
constexpr auto equals(T1 &&t1, T2 &&t2)
Equality comparison.
Definition: hybridutilities.hh:587
constexpr auto max
Function object that returns the greater of the given values.
Definition: hybridutilities.hh:484
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:238
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:260
provides a wrapper for ALBERTA's macro_data structure
Dune namespace.
Definition: alignedallocator.hh:13
constexpr std::integral_constant< std::size_t, sizeof...(II)> size(std::integer_sequence< T, II... >)
Return the size of the sequence.
Definition: integersequence.hh:75