1#ifndef DUNE_SPGRID_GRIDLEVEL_HH
2#define DUNE_SPGRID_GRIDLEVEL_HH
8#include <dune/grid/spgrid/direction.hh>
9#include <dune/grid/spgrid/geometricgridlevel.hh>
11#include <dune/grid/spgrid/refinement.hh>
13#include <dune/grid/spgrid/mesh.hh>
14#include <dune/grid/spgrid/partitionpool.hh>
15#include <dune/grid/spgrid/linkage.hh>
16#include <dune/grid/spgrid/decomposition.hh>
24 template<
int mydim,
int cdim,
class Gr
id >
25 class SPLocalGeometry;
32 template<
class Gr
id >
34 :
public SPGeometricGridLevel< typename std::remove_const< Grid >::type::ctype, std::remove_const< Grid >::type::dimension >
36 typedef SPGridLevel< Grid > This;
37 typedef SPGeometricGridLevel< typename std::remove_const< Grid >::type::ctype, std::remove_const< Grid >::type::dimension > Base;
40 typedef SPGridLevel< Grid > GridLevel;
42 typedef typename Base::ReferenceCube ReferenceCube;
43 typedef typename Base::ctype ctype;
45 static const int dimension = Base::dimension;
46 static const unsigned int numDirections = Base::numDirections;
47 static const int numFaces = ReferenceCube::numFaces;
49 typedef typename std::remove_const< Grid >::type::Traits Traits;
51 typedef typename Traits::Domain Domain;
52 typedef typename Traits::Refinement Refinement;
53 typedef typename Traits::RefinementPolicy RefinementPolicy;
55 typedef typename ReferenceCube::GlobalVector GlobalVector;
56 typedef typename ReferenceCube::MultiIndex MultiIndex;
58 typedef SPDecomposition< dimension > Decomposition;
59 typedef SPPartitionPool< dimension > PartitionPool;
60 typedef SPLinkage< dimension > Linkage;
62 typedef typename Decomposition::Mesh Mesh;
64 typedef typename PartitionPool::PartitionList PartitionList;
66 typedef typename Linkage::Interface CommInterface;
68 typedef typename Traits::template Codim< 0 >::LocalGeometry LocalGeometry;
71 typedef SPLocalGeometry< dimension, dimension, const Grid > LocalGeometryImpl;
74 SPGridLevel (
const Grid &grid,
const Decomposition &decomposition );
75 SPGridLevel (
const GridLevel &father,
const RefinementPolicy &policy );
76 SPGridLevel (
const This &other );
80 using Base::referenceCube;
82 const Grid &grid ()
const {
return *grid_; }
83 int level ()
const {
return level_; }
84 const Domain &domain ()
const {
return domain_; }
85 const Refinement &refinement ()
const {
return refinement_; }
87 const Mesh &globalMesh ()
const;
88 const Mesh &localMesh ()
const;
90 template< PartitionIteratorType pitype >
91 const PartitionList &partition ()
const;
93 const PartitionList &boundaryPartition (
int face )
const;
97 partitionType (
const MultiIndex &
id,
const unsigned int partitionNumber )
const;
99 const CommInterface &commInterface (
const InterfaceType iftype )
const;
101 MultiIndex macroId (
const MultiIndex &
id )
const;
103 size_t boundaryIndex (
const MultiIndex &
id,
104 const unsigned int partitionNumber,
105 const int face )
const;
107 LocalGeometry geometryInFather (
const MultiIndex &
id )
const;
112 void buildLocalGeometry ();
113 void buildBoundaryPartitions ();
115 static MultiIndex coarseMacroFactor ();
116 static GlobalVector meshWidth (
const Domain &domain,
const Mesh &mesh );
117 static MultiIndex refineWidth (
const MultiIndex &width,
const Refinement &refinement );
119 MultiIndex overlap ()
const;
124 const Refinement refinement_;
125 MultiIndex macroFactor_;
127 std::vector< Mesh > decomposition_;
129 PartitionPool partitionPool_;
132 LocalGeometryImpl **geometryInFather_;
134 PartitionList boundaryPartition_[ numFaces+1 ];
142 template<
class Gr
id >
143 inline SPGridLevel< Grid >
144 ::SPGridLevel (
const Grid &grid,
const Decomposition &decomposition )
145 : Base( grid.refCubes_, meshWidth( grid.domain(), decomposition.mesh() ) ),
149 macroFactor_( coarseMacroFactor() ),
150 domain_( grid.domain() ),
151 decomposition_( decomposition.subMeshes() ),
152 localMesh_( decomposition_[ grid.comm().rank() ] ),
153 partitionPool_( localMesh_, decomposition.mesh(), overlap(), domain_.topology() ),
154 linkage_( grid.comm().rank(), partitionPool_, decomposition_ )
156 buildLocalGeometry();
157 buildBoundaryPartitions();
161 template<
class Gr
id >
162 inline SPGridLevel< Grid >::SPGridLevel (
const GridLevel &father,
const RefinementPolicy &policy )
163 : Base( father.grid().refCubes_, meshWidth( father.domain(), father.globalMesh().refine( Refinement( father.refinement(), policy ) ) ) ),
164 grid_( father.grid_ ),
165 level_( father.level() + 1 ),
166 refinement_( father.refinement(), policy ),
167 macroFactor_( refineWidth( father.macroFactor_, refinement_ ) ),
168 domain_( father.domain() ),
169 decomposition_(
transform( father.decomposition_, [ this ]( const Mesh &mesh ) {
return mesh.refine( refinement_ ); } ) ),
170 localMesh_( father.localMesh().refine( refinement_ ) ),
171 partitionPool_( localMesh_, father.globalMesh().refine( refinement_ ), overlap(), domain_.topology() ),
172 linkage_( father.grid().comm().rank(), partitionPool_, decomposition_ )
174 buildLocalGeometry();
175 buildBoundaryPartitions();
179 template<
class Gr
id >
180 inline SPGridLevel< Grid >::SPGridLevel (
const This &other )
182 grid_( other.grid_ ),
183 refinement_( other.refinement_ ),
184 macroFactor_( other.macroFactor_ ),
185 domain_( other.domain_ ),
186 decomposition_( other.decomposition_ ),
187 localMesh_( other.localMesh_ ),
188 partitionPool_( other.partitionPool_ ),
189 linkage_( other.linkage_ )
191 buildLocalGeometry();
192 buildBoundaryPartitions();
196 template<
class Gr
id >
197 inline SPGridLevel< Grid >::~SPGridLevel ()
199 if( geometryInFather_ )
201 unsigned int numChildren = refinement().numChildren();
202 for(
unsigned int index = 0; index < numChildren; ++index )
203 delete geometryInFather_[ index ];
204 delete geometryInFather_;
208 template<
class Gr
id >
209 inline const typename SPGridLevel< Grid >::Mesh &
210 SPGridLevel< Grid >::globalMesh ()
const
212 return partitionPool_.globalMesh();
216 template<
class Gr
id >
217 inline const typename SPGridLevel< Grid >::Mesh &
218 SPGridLevel< Grid >::localMesh ()
const
224 template<
class Gr
id >
225 template< PartitionIteratorType pitype >
226 inline const typename SPGridLevel< Grid >::PartitionList &
227 SPGridLevel< Grid >::partition ()
const
229 return partitionPool_.template get< pitype >();
233 template<
class Gr
id >
234 inline const typename SPGridLevel< Grid >::PartitionList &
235 SPGridLevel< Grid >::boundaryPartition (
int face )
const
237 assert( (face >= 0) && (face <= numFaces) );
238 return boundaryPartition_[ face ];
242 template<
class Gr
id >
243 template<
int codim >
245 ::partitionType (
const MultiIndex &
id,
const unsigned int partitionNumber )
const
247 return partitionPool_.template partitionType< codim >(
id, partitionNumber );
251 template<
class Gr
id >
252 inline const typename SPGridLevel< Grid >::CommInterface &
253 SPGridLevel< Grid >::commInterface (
const InterfaceType iftype )
const
255 return linkage_.interface( iftype );
259 template<
class Gr
id >
260 inline typename SPGridLevel< Grid >::MultiIndex
261 SPGridLevel< Grid >::macroId (
const MultiIndex &
id )
const
264 for(
int i = 0; i < dimension; ++i )
265 macroId[ i ] = (((
id[ i ] >> 1) / macroFactor_[ i ]) << 1) | (
id[ i ] & 1);
270 template<
class Gr
id >
271 inline size_t SPGridLevel< Grid >
272 ::boundaryIndex (
const MultiIndex &
id,
273 const unsigned int partitionNumber,
274 const int face )
const
279 for(
int i = 0; i < dimension; ++i )
280 macroId[ i ] =
id[ i ] / macroFactor_[ i ];
281 return grid().boundaryIndex( macroId, partitionNumber, face );
285 template<
class Gr
id >
286 inline typename SPGridLevel< Grid >::LocalGeometry
287 SPGridLevel< Grid >::geometryInFather (
const MultiIndex &
id )
const
289 assert( (level() > 0) && (geometryInFather_ != 0) );
290 return LocalGeometry( *(geometryInFather_[ refinement().childIndex(
id ) ]) );
294 template<
class Gr
id >
295 inline int SPGridLevel< Grid >::size ()
const
297 return globalMesh().volume();
301 template<
class Gr
id >
302 inline void SPGridLevel< Grid >::buildLocalGeometry ()
304 geometryInFather_ = 0;
307 const unsigned int numChildren = refinement().numChildren();
308 geometryInFather_ =
new LocalGeometryImpl *[ numChildren ];
309 const GlobalVector hInFather = refinement().template hInFather< ctype >();
310 SPDirectionIterator< dimension, 0 > dirIt;
311 const typename Base::template Codim< 0 >::GeometryCache cacheInFather( hInFather, *dirIt );
312 for(
unsigned int index = 0; index < numChildren; ++index )
314 const GlobalVector origin = refinement().template originInFather< ctype >( index );
315 geometryInFather_[ index ] =
new LocalGeometryImpl( cacheInFather, origin );
321 template<
class Gr
id >
322 inline void SPGridLevel< Grid >::buildBoundaryPartitions ()
324 const Mesh &globalMesh = This::globalMesh();
326 for(
int face = 0; face < numFaces; ++face )
328 const int i = face >> 1;
331 const PartitionList &plist = partition< All_Partition >();
332 const typename PartitionList::Iterator end = plist.end();
333 for(
typename PartitionList::Iterator it = plist.begin(); it != end; ++it )
336 typedef typename PartitionList::Partition Partition;
337 const Partition &partition = *it;
340 MultiIndex bound[ 2 ];
341 bound[ 0 ] = partition.begin();
342 bound[ 1 ] = partition.end();
345 int bnd = (face & 1)*bound[ 1 ][ i ] + (1 - (face & 1))*bound[ 0 ][ i ];
346 bound[ 0 ][ i ] = bnd;
347 bound[ 1 ][ i ] = bnd;
350 if( bnd == 2*globalMesh.bound( face & 1 )[ i ] )
351 boundaryPartition_[ face ] += Partition( bound[ 0 ], bound[ 1 ], partition.number() );
357 template<
class Gr
id >
358 inline typename SPGridLevel< Grid >::MultiIndex
359 SPGridLevel< Grid >::coarseMacroFactor ()
361 MultiIndex macroFactor;
362 for(
int i = 0; i < dimension; ++i )
363 macroFactor[ i ] = 1;
368 template<
class Gr
id >
369 inline typename SPGridLevel< Grid >::GlobalVector
370 SPGridLevel< Grid >::meshWidth (
const Domain &domain,
const Mesh &mesh )
372 GlobalVector h = domain.cube().width();
373 const MultiIndex meshWidth = mesh.width();
374 for(
int i = 0; i < dimension; ++i )
375 h[ i ] /= ctype( meshWidth[ i ] );
380 template<
class Gr
id >
381 inline typename SPGridLevel< Grid >::MultiIndex
382 SPGridLevel< Grid >::refineWidth (
const MultiIndex &
id,
const Refinement &refinement )
385 for(
int i = 0; i < dimension; ++i )
386 result[ i ] =
id[ i ] * refinement.factor( i );
391 template<
class Gr
id >
392 inline typename SPGridLevel< Grid >::MultiIndex
393 SPGridLevel< Grid >::overlap ()
const
396 for(
int i = 0; i < dimension; ++i )
397 overlap[ i ] = macroFactor_[ i ] * grid().overlap()[ i ];
description of computational domain
miscellaneous helper functions
Dune namespace.
Definition: alignedallocator.hh:13
std::vector< decltype(std::declval< Op >()(std::declval< T >())) > transform(const std::vector< T > &in, Op op)
copy a vector, performing an operation on each element
Definition: misc.hh:24