Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • extensions/dune-metagrid
  • tkoch/dune-metagrid
2 results
Show changes
Commits on Source (25)
Showing
with 383 additions and 310 deletions
...@@ -28,4 +28,52 @@ Makefile.in ...@@ -28,4 +28,52 @@ Makefile.in
*.log *.log
*.o *.o
*.swp *.swp
# build system clutter
build-*
Testing
# auto-saved files
*~ *~
# hidden files
.cproject
.project
# left overs from git rebase
*.orig
*.rej
# latex clutter
*.pdf
*.aux
*.blg
*.log
*.bbl
*.dvi
*.idx
*.out
*.tdo
*.toc
*.synctex.gz
# Python clutter
*.pyc
__pycache__
# macOS
.DS_Store
# always consider files containing source code regardless of their name
!*.cc
!*.hh
!*.c
!*.h
!*.sh
!*.py
# ignore files generated during python setup.py sdist
MANIFEST
_skbuild/
dist
*.egg-info
project("dune-metagrid" C CXX) project("dune-metagrid" C CXX)
set(DUNE_REENABLE_ADD_TEST TRUE) cmake_minimum_required(VERSION 3.13)
cmake_minimum_required(VERSION 2.8.12)
# guess dune-common build dir # guess dune-common build dir
if(NOT (dune-common_DIR OR dune-common_ROOT OR if(NOT (dune-common_DIR OR dune-common_ROOT OR
......
...@@ -59,7 +59,7 @@ namespace Dune ...@@ -59,7 +59,7 @@ namespace Dune
// ---------------------- // ----------------------
#if HAVE_DUNE_ALUGRID #if HAVE_DUNE_ALUGRID
template< class WrappedHandle, bool = std::is_base_of< LoadBalanceHandleWithReserveAndCompress, WrappedHandle >::value > template< class WrappedHandle, bool = std::is_base_of_v<LoadBalanceHandleWithReserveAndCompress, WrappedHandle> >
struct MetaGridDataHandleBase; struct MetaGridDataHandleBase;
template< class WrappedHandle > template< class WrappedHandle >
...@@ -111,7 +111,7 @@ namespace Dune ...@@ -111,7 +111,7 @@ namespace Dune
typedef MetaGridDataHandleBase< WrappedHandle > Base; typedef MetaGridDataHandleBase< WrappedHandle > Base;
// type of traits // type of traits
typedef typename std::remove_const< GridFamily >::type::Traits Traits; typedef typename std::remove_const_t<GridFamily>::Traits Traits;
// type of extra data // type of extra data
typedef typename Traits :: ExtraData ExtraData ; typedef typename Traits :: ExtraData ExtraData ;
...@@ -210,7 +210,7 @@ namespace Dune ...@@ -210,7 +210,7 @@ namespace Dune
template< class WrappedDofManager, class GridFamily, class Filter = MetaGridNoFilter > template< class WrappedDofManager, class GridFamily, class Filter = MetaGridNoFilter >
class MetaGridWrappedDofManager class MetaGridWrappedDofManager
{ {
typedef typename std::remove_const< GridFamily >::type::Traits Traits; typedef typename std::remove_const_t<GridFamily>::Traits Traits;
// type of extra data // type of extra data
typedef typename Traits :: ExtraData ExtraData ; typedef typename Traits :: ExtraData ExtraData ;
// type of host element (i.e. codim = 0) // type of host element (i.e. codim = 0)
......
...@@ -116,11 +116,6 @@ namespace Dune ...@@ -116,11 +116,6 @@ namespace Dune
return hostEntity().type(); return hostEntity().type();
} }
unsigned int subEntities( const unsigned int cd ) const
{
return hostEntity().subEntities( cd );
}
/** \brief obtain the level of this entity */ /** \brief obtain the level of this entity */
int level () const int level () const
{ {
...@@ -133,6 +128,12 @@ namespace Dune ...@@ -133,6 +128,12 @@ namespace Dune
return hostEntity().partitionType(); return hostEntity().partitionType();
} }
/** \brief Return number of subentities with codimension c */
unsigned int subEntities( const unsigned int c ) const
{
return hostEntity().subEntities( c );
}
/** obtain the geometry of this entity */ /** obtain the geometry of this entity */
Geometry geometry () const Geometry geometry () const
{ {
......
...@@ -30,14 +30,12 @@ namespace Dune ...@@ -30,14 +30,12 @@ namespace Dune
static const bool v = isCartesian< HostGrid >::v; static const bool v = isCartesian< HostGrid >::v;
}; };
template< class HostGrid, int codim > template< class HostGrid, int codim >
struct hasEntity< ParallelGrid< HostGrid >, codim > struct hasEntity< ParallelGrid< HostGrid >, codim >
{ {
static const bool v = hasEntity< HostGrid, codim >::v; static const bool v = hasEntity< HostGrid, codim >::v;
}; };
template< class HostGrid, int codim > template< class HostGrid, int codim >
struct canCommunicate< ParallelGrid< HostGrid >, codim > struct canCommunicate< ParallelGrid< HostGrid >, codim >
{ {
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
#include <vector> #include <vector>
#include <dune/common/applyif.hh> #include <dune/common/applyif.hh>
#include <dune/common/forloop.hh> #include <dune/common/hybridutilities.hh>
#include <dune/grid/common/gridenums.hh> #include <dune/grid/common/gridenums.hh>
...@@ -36,18 +36,16 @@ namespace Dune ...@@ -36,18 +36,16 @@ namespace Dune
typedef ALU3DSPACE ALUMpAccess MpAccess; typedef ALU3DSPACE ALUMpAccess MpAccess;
template< int codim >
struct CodimAvailable
{
static const bool value = Capabilities::hasEntity< Grid, codim >::v;
};
template< int codim > template< int codim >
struct PackData; struct PackData;
template< int codim > template< int codim >
struct UnpackData; struct UnpackData;
template<int codim>
static constexpr bool codimAvailable()
{ return Capabilities::hasEntity<Grid, codim>::v; }
public: public:
static const int dimension = Grid::dimension; static const int dimension = Grid::dimension;
...@@ -85,8 +83,10 @@ namespace Dune ...@@ -85,8 +83,10 @@ namespace Dune
if( (info.partitionType() == sendType) && info.hasConnectivity() ) if( (info.partitionType() == sendType) && info.hasConnectivity() )
{ {
ForLoop< ApplyIf< PackData, CodimAvailable >::template Operation, 0, dimension > Hybrid::forEach(std::make_index_sequence<dimension+1>{}, [&](auto codim){
::apply( mpAccess(), rankManager_, dataHandle, buffer, entity, count ); if constexpr (codimAvailable<codim>())
PackData<codim>::apply(mpAccess(), rankManager_, dataHandle, buffer, entity, count);
});
} }
} }
...@@ -100,8 +100,10 @@ namespace Dune ...@@ -100,8 +100,10 @@ namespace Dune
if( (info.partitionType() == recvType) && info.hasConnectivity() ) if( (info.partitionType() == recvType) && info.hasConnectivity() )
{ {
ForLoop< ApplyIf< PackData, CodimAvailable >::template Operation, 0, dimension > Hybrid::forEach(std::make_index_sequence<dimension+1>{}, [&](auto codim){
::apply( mpAccess(), rankManager_, dataHandle, buffer, entity, count ); if constexpr (codimAvailable<codim>())
PackData<codim>::apply(mpAccess(), rankManager_, dataHandle, buffer, entity, count);
});
} }
} }
} }
...@@ -136,8 +138,10 @@ namespace Dune ...@@ -136,8 +138,10 @@ namespace Dune
if( (info.partitionType() == recvType) && info.hasConnectivity() ) if( (info.partitionType() == recvType) && info.hasConnectivity() )
{ {
ForLoop< ApplyIf< UnpackData, CodimAvailable >::template Operation, 0, dimension > Hybrid::forEach(std::make_index_sequence<dimension+1>{}, [&](auto codim){
::apply( mpAccess(), rankManager_, dataHandle, buffer, entity, count, sizes ); if constexpr (codimAvailable<codim>())
UnpackData<codim>::apply(mpAccess(), rankManager_, dataHandle, buffer, entity, count, sizes);
});
} }
} }
...@@ -152,8 +156,10 @@ namespace Dune ...@@ -152,8 +156,10 @@ namespace Dune
// if entity is not send type, don't do anything // if entity is not send type, don't do anything
if( (info.partitionType() == sendType) && info.hasConnectivity() ) if( (info.partitionType() == sendType) && info.hasConnectivity() )
{ {
ForLoop< ApplyIf< UnpackData, CodimAvailable >::template Operation, 0, dimension > Hybrid::forEach(std::make_index_sequence<dimension+1>{}, [&](auto codim){
::apply( mpAccess(), rankManager_, dataHandle, buffer, entity, count, sizes ); if constexpr (codimAvailable<codim>())
UnpackData<codim>::apply(mpAccess(), rankManager_, dataHandle, buffer, entity, count, sizes);
});
} }
} }
} }
...@@ -242,9 +248,7 @@ namespace Dune ...@@ -242,9 +248,7 @@ namespace Dune
template< int codim > template< int codim >
struct ParallelGridCommunication< Grid >::UnpackData struct ParallelGridCommunication< Grid >::UnpackData
{ {
typedef typename Grid::template Codim< 0 >::Entity Element; using Element = typename Grid::template Codim< 0 >::Entity;
typedef typename Grid::template Codim< codim >::Entity Entity;
template< class DataHandleIF > template< class DataHandleIF >
static void apply ( const MpAccess &mpAccess, const RankManager &rankManager, static void apply ( const MpAccess &mpAccess, const RankManager &rankManager,
...@@ -264,15 +268,13 @@ namespace Dune ...@@ -264,15 +268,13 @@ namespace Dune
for( int subEntity = 0; subEntity < numSubEntities; ++subEntity ) for( int subEntity = 0; subEntity < numSubEntities; ++subEntity )
{ {
// get subentity // get subentity
const Entity &entity = element.template subEntity< codim >( subEntity ); const auto& entity = element.template subEntity< codim >( subEntity );
// get partition info // get partition info
const PartitionInfo &info = rankManager.partitionInfo( entity.impl().hostEntity() ); const auto& info = rankManager.partitionInfo( entity.impl().hostEntity() );
const typename PartitionInfo::iterator end = info.end(); for( const int srcRank : info )
for( typename PartitionInfo::iterator it = info.begin(); it != end; ++it )
{ {
const int srcRank = (*it);
const int link = mpAccess.link( srcRank ); const int link = mpAccess.link( srcRank );
#ifndef NDEBUG #ifndef NDEBUG
......
...@@ -16,8 +16,6 @@ namespace Dune ...@@ -16,8 +16,6 @@ namespace Dune
template< class, PartitionIteratorType, class > class ParallelGridIteratorChecked; template< class, PartitionIteratorType, class > class ParallelGridIteratorChecked;
// ParallelGridEntity // ParallelGridEntity
// ------------------ // ------------------
...@@ -26,22 +24,22 @@ namespace Dune ...@@ -26,22 +24,22 @@ namespace Dune
* \nosubgrouping * \nosubgrouping
*/ */
template< int codim, int dim, class Grid > template< int codim, int dim, class Grid >
class ParallelGridEntity : public IdGridEntity< codim, dim, Grid > class ParallelGridEntityBase : public IdGridEntity< codim, dim, Grid >
{ {
typedef IdGridEntity< codim, dim, Grid > Base ; using Base = IdGridEntity<codim, dim, Grid>;
protected: protected:
typedef typename Base::HostGrid HostGrid; using HostGrid = typename Base::HostGrid;
typedef typename Base::ExtraData ExtraData; using ExtraData = typename Base::ExtraData;
public: public:
using Base :: data ; using Base::data;
using Base :: hostEntity ; using Base::hostEntity;
/** \name Host Types /** \name Host Types
* \{ */ * \{ */
//! type of corresponding host entity //! type of corresponding host entity
typedef typename Base :: HostEntity HostEntity ; using HostEntity = typename Base::HostEntity;
/** \} */ /** \} */
...@@ -50,8 +48,13 @@ namespace Dune ...@@ -50,8 +48,13 @@ namespace Dune
* \{ */ * \{ */
/** \brief construct a null entity */ /** \brief construct a null entity */
explicit ParallelGridEntity ( ExtraData data ) explicit ParallelGridEntityBase(ExtraData data)
: Base( data ) : Base(data)
{}
/** \brief Default constructed null entity */
ParallelGridEntityBase()
: Base(nullptr)
{} {}
/** \brief construct an initialized entity /** \brief construct an initialized entity
...@@ -61,14 +64,14 @@ namespace Dune ...@@ -61,14 +64,14 @@ namespace Dune
* \note The reference to the host entity must remain valid as long as * \note The reference to the host entity must remain valid as long as
* this entity is in use. * this entity is in use.
*/ */
ParallelGridEntity ( ExtraData data, ParallelGridEntityBase(ExtraData data,
const HostEntity &hostEntity ) const HostEntity& hostEntity )
: Base( data, hostEntity ) : Base(data, hostEntity)
{} {}
/** \brief copy constructor */ /** \brief copy constructor */
ParallelGridEntity ( const ParallelGridEntity &other ) ParallelGridEntityBase(const ParallelGridEntityBase& other)
: Base( other ) : Base(other)
{} {}
/** \name Methods Shared by Entities of All Codimensions /** \name Methods Shared by Entities of All Codimensions
...@@ -83,6 +86,60 @@ namespace Dune ...@@ -83,6 +86,60 @@ namespace Dune
/** \} */ /** \} */
}; };
// ParallelGridEntity
// ------------------
/** \copydoc ParallelGridEntity
*
* \nosubgrouping
*/
template< int codim, int dim, class Grid >
class ParallelGridEntity
: public ParallelGridEntityBase<codim, dim, Grid>
{
using Base = ParallelGridEntityBase<codim, dim, Grid>;
public:
//! inherit constructors
using Base::Base;
};
/** \brief ParallelGridEntity specialization for codim-0 entities
*
* \nosubgrouping
*/
template<int dim, class Grid >
class ParallelGridEntity<0, dim, Grid>
: public ParallelGridEntityBase<0, dim, Grid>
{
using Base = ParallelGridEntityBase<0, dim, Grid>;
public:
//! inherit constructors
using Base::Base;
/** \name Types required by DUNE
* \{ */
//! type of hierarchic iterator
using HierarchicIterator = typename Base::HierarchicIterator;
/** \} */
//! hierarchic iterators are overloaded because of special constructor
HierarchicIterator hbegin (int maxLevel) const
{
using Impl = typename Base::Traits::HierarchicIteratorImpl;
return Impl(this->data(), this->hostEntity().hbegin(maxLevel), this->hostEntity().hend(maxLevel));
}
//! hierarchic iterators are overloaded because of special constructor
HierarchicIterator hend (int maxLevel) const
{
using Impl = typename Base::Traits::HierarchicIteratorImpl;
return Impl(this->data(), this->hostEntity().hend(maxLevel));
}
};
} // namespace Dune } // namespace Dune
#endif // #ifndef DUNE_PARALLELGRID_ENTITY_HH #endif // #ifndef DUNE_PARALLELGRID_ENTITY_HH
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include <dune/grid/common/sizecache.hh> #include <dune/grid/common/sizecache.hh>
#include <dune/grid/idgrid/idset.hh> #include <dune/grid/idgrid/idset.hh>
#include <dune/grid/idgrid/entityseed.hh>
#include <dune/grid/idgrid/geometry.hh> #include <dune/grid/idgrid/geometry.hh>
#include <dune/grid/idgrid/intersectioniterator.hh> #include <dune/grid/idgrid/intersectioniterator.hh>
...@@ -80,7 +81,7 @@ namespace Dune ...@@ -80,7 +81,7 @@ namespace Dune
typedef Dune::Entity< codim, dimension, const Grid, ParallelGridEntity > Entity; typedef Dune::Entity< codim, dimension, const Grid, ParallelGridEntity > Entity;
// minimal information to generate entities // minimal information to generate entities
typedef typename HostGrid::template Codim< codim >::EntitySeed EntitySeed; typedef Dune::EntitySeed< const Grid, IdGridEntitySeed< codim, const Grid > > EntitySeed;
template< PartitionIteratorType pitype > template< PartitionIteratorType pitype >
struct Partition struct Partition
...@@ -313,10 +314,7 @@ namespace Dune ...@@ -313,10 +314,7 @@ namespace Dune
DUNE_THROW( InvalidStateException, "ParallelGrid can only be used with serial host grids." ); DUNE_THROW( InvalidStateException, "ParallelGrid can only be used with serial host grids." );
for( int i = 0; i <= HostGrid::dimension; ++i ) for( int i = 0; i <= HostGrid::dimension; ++i )
{ geomTypes_.push_back( hostGrid.levelGridView( 0 ).indexSet().types( i ) );
auto types = hostGrid.levelGridView( 0 ).indexSet().types( i );
geomTypes_.push_back( types );
}
sizeCache_.reset(); sizeCache_.reset();
} }
...@@ -345,10 +343,7 @@ namespace Dune ...@@ -345,10 +343,7 @@ namespace Dune
DUNE_THROW( InvalidStateException, "ParallelGrid can only be used with serial host grids." ); DUNE_THROW( InvalidStateException, "ParallelGrid can only be used with serial host grids." );
for( int i = 0; i <= HostGrid::dimension; ++i ) for( int i = 0; i <= HostGrid::dimension; ++i )
{ geomTypes_.push_back( hostGrid->levelGridView( 0 ).indexSet().types( i ) );
auto types = hostGrid.levelGridView( 0 ).indexSet().types( i );
geomTypes_.push_back( types );
}
sizeCache_.reset(); sizeCache_.reset();
} }
...@@ -820,16 +815,17 @@ namespace Dune ...@@ -820,16 +815,17 @@ namespace Dune
return LeafGridView( ViewImp( *this ) ); return LeafGridView( ViewImp( *this ) );
} }
/** \brief Create an Entity from an EntitySeed */
/** \brief obtain EntityPointer from EntitySeed. */ template <class EntitySeed>
template< class EntitySeed > typename Traits::template Codim<EntitySeed::codimension>::Entity
typename Traits::template Codim< EntitySeed::codimension >::EntityPointer entity(const EntitySeed& seed) const
entityPointer ( const EntitySeed &seed ) const
{ {
typedef typename Traits::template Codim< EntitySeed::codimension >::EntityPointerImpl EntityPointerImpl; static constexpr int codim = EntitySeed::codimension;
return EntityPointerImpl( extraData(), hostGrid().entityPointer( seed ) ); using EntityImpl = typename Traits::template Codim<codim>::EntityImpl;
return EntityImpl( extraData(), hostGrid().entity( seed.impl().hostEntitySeed() ) );
} }
/** \} */ /** \} */
/** \name Miscellaneous Methods /** \name Miscellaneous Methods
......
...@@ -5,8 +5,6 @@ ...@@ -5,8 +5,6 @@
#include <dune/grid/parallelgrid/rankmanager.hh> #include <dune/grid/parallelgrid/rankmanager.hh>
#include <dune/grid/idgrid/intersection.hh> #include <dune/grid/idgrid/intersection.hh>
#if HAVE_DUNE_ALUGRID
namespace Dune namespace Dune
{ {
...@@ -24,6 +22,10 @@ namespace Dune ...@@ -24,6 +22,10 @@ namespace Dune
using Base :: data ; using Base :: data ;
using Base :: hostIntersection ; using Base :: hostIntersection ;
ParallelGridIntersection ()
: Base ()
{}
explicit ParallelGridIntersection ( ExtraData data ) explicit ParallelGridIntersection ( ExtraData data )
: Base( data ) : Base( data )
{} {}
...@@ -40,6 +42,4 @@ namespace Dune ...@@ -40,6 +42,4 @@ namespace Dune
} // namespace Dune } // namespace Dune
#endif // #if HAVE_DUNE_ALUGRID
#endif // #ifndef DUNE_PARALLELGRID_INTERSECTION_HH #endif // #ifndef DUNE_PARALLELGRID_INTERSECTION_HH
#ifndef DUNE_PARALLELGRID_ITERATOR_HH #ifndef DUNE_PARALLELGRID_ITERATOR_HH
#define DUNE_PARALLELGRID_ITERATOR_HH #define DUNE_PARALLELGRID_ITERATOR_HH
#include <dune/geometry/referenceelements.hh>
#include <dune/grid/idgrid/iterator.hh>
#include <dune/grid/parallelgrid/rankmanager.hh> #include <dune/grid/parallelgrid/rankmanager.hh>
#if HAVE_DUNE_ALUGRID #if HAVE_DUNE_ALUGRID
...@@ -17,31 +13,31 @@ namespace Dune ...@@ -17,31 +13,31 @@ namespace Dune
template< class Grid, PartitionIteratorType pitype, class HostIterator > template< class Grid, PartitionIteratorType pitype, class HostIterator >
class ParallelGridIteratorChecked class ParallelGridIteratorChecked
: public IdGridIterator< Grid, HostIterator >
{ {
typedef IdGridIterator< Grid, HostIterator > Base; using RankManager = ParallelGridRankManager<std::remove_const_t<Grid>>;
using Traits = typename std::remove_const_t<Grid>::Traits;
protected:
using Base::hostIterator_;
using Base::data; using ExtraData = typename Traits::ExtraData;
static constexpr int codimension = HostIterator::Entity::codimension;
protected: public:
typedef typename Base::ExtraData ExtraData; using Entity = typename Traits::template Codim<codimension>::Entity;
static constexpr int dimension = HostIterator::Entity::dimension;
typedef ParallelGridRankManager< typename std::remove_const< Grid >::type > RankManager; private:
using EntityImpl = typename Traits::template Codim<codimension>::EntityImpl;
void checkValid () void keepIncrementingIfInvalid_()
{ {
for( ; hostIterator_ != endIterator_; ++hostIterator_ ) for( ; hostIterator_ != endIterator_; ++hostIterator_ )
{ {
const typename HostIterator::Entity &hostEntity = *hostIterator_; const auto& hostEntity = *hostIterator_;
if( !rankManager().validEntity( hostEntity ) ) if( !rankManager_().validEntity( hostEntity ) )
continue; continue;
// determine interior and ghost // determine interior and ghost
const PartitionInfo &info = rankManager().partitionInfo( hostEntity ); const auto& info = rankManager_().partitionInfo( hostEntity );
switch( pitype ) switch( pitype )
{ {
case All_Partition: case All_Partition:
...@@ -73,27 +69,47 @@ namespace Dune ...@@ -73,27 +69,47 @@ namespace Dune
public: public:
// constructor for begin iterator // constructor for begin iterator
ParallelGridIteratorChecked ( ExtraData data, const HostIterator &hostIterator, const HostIterator &endIterator ) ParallelGridIteratorChecked ( ExtraData data, const HostIterator &hostIterator, const HostIterator &endIterator )
: Base( data, hostIterator ), : data_(data)
endIterator_( endIterator ) , hostIterator_(hostIterator)
, endIterator_(endIterator)
{ {
checkValid(); keepIncrementingIfInvalid_();
} }
// constructor for end iterator // constructor for end iterator
ParallelGridIteratorChecked ( ExtraData data, const HostIterator &endIterator ) ParallelGridIteratorChecked ( ExtraData data, const HostIterator &endIterator )
: Base( data, endIterator ), : data_(data)
endIterator_( endIterator ) , hostIterator_(endIterator)
, endIterator_(endIterator)
{} {}
void increment () void increment ()
{ {
++hostIterator_; ++hostIterator_;
checkValid(); keepIncrementingIfInvalid_();
} }
protected: /** \brief check for equality */
const RankManager &rankManager () const { return data()->rankManager(); } bool equals ( const ParallelGridIteratorChecked& other ) const
{
return (hostIterator_ == other.hostIterator_);
}
/** \brief dereference entity */
Entity dereference () const
{
return Entity( EntityImpl( data_, *hostIterator_ ) );
}
/** \brief obtain level */
int level () const { return hostIterator_->level(); }
private:
const RankManager& rankManager_() const
{ return data_->rankManager(); }
ExtraData data_;
HostIterator hostIterator_;
HostIterator endIterator_; HostIterator endIterator_;
}; };
......
...@@ -17,7 +17,7 @@ namespace Dune ...@@ -17,7 +17,7 @@ namespace Dune
{ {
typedef ParallelGridMacroDecomposition< Grid > This; typedef ParallelGridMacroDecomposition< Grid > This;
typedef typename std::remove_const< Grid >::type::Traits Traits; typedef typename std::remove_const_t<Grid>::Traits Traits;
typedef typename Traits::HostGrid HostGrid; typedef typename Traits::HostGrid HostGrid;
......
...@@ -23,62 +23,55 @@ namespace ALUGrid ...@@ -23,62 +23,55 @@ namespace ALUGrid
typedef MpAccessGlobal::minmaxsum_t minmaxsum_t; typedef MpAccessGlobal::minmaxsum_t minmaxsum_t;
typedef MpAccessLocal::NonBlockingExchange NonBlockingExchange; typedef MpAccessLocal::NonBlockingExchange NonBlockingExchange;
virtual int psize() const { return 1; } int psize() const override { return 1; }
virtual int nlinks() const { return 0; } int nlinks () const { return 0; }
int myrank () const { return 0; } int myrank () const override { return 0; }
virtual int barrier () const { return psize(); } int barrier () const override { return psize(); }
virtual bool gmax (bool value) const { return value; } bool gmax (bool value) const override { return value; }
virtual int gmax (int value) const { return value; } int gmax (int value) const override { return value; }
virtual int gmin ( int value ) const { return value; } int gmin ( int value ) const override { return value; }
virtual int gsum ( int value ) const { return value; } int gsum ( int value ) const override { return value; }
virtual long gmax ( long value ) const { return value; } long gmax ( long value ) const override { return value; }
virtual long gmin ( long value ) const { return value; } long gmin ( long value ) const override { return value; }
virtual long gsum ( long value ) const { return value; } long gsum ( long value ) const override { return value; }
virtual double gmax ( double value ) const { return value; } double gmax ( double value ) const override { return value; }
virtual double gmin ( double value ) const { return value; } double gmin ( double value ) const override { return value; }
virtual double gsum ( double value ) const { return value; } double gsum ( double value ) const override { return value; }
virtual void gmax (double* in, int length, double* out) const { std::copy(in, in+length, out ); } void gmax (double* in, int length, double* out) const override { std::copy(in, in+length, out ); }
virtual void gmin (double* in, int length, double* out) const { std::copy(in, in+length, out ); } void gmin (double* in, int length, double* out) const override { std::copy(in, in+length, out ); }
virtual void gsum (double* in, int length, double* out) const { std::copy(in, in+length, out ); } void gsum (double* in, int length, double* out) const override { std::copy(in, in+length, out ); }
virtual void gmax (int*,int,int*) const { } void gmax (int*, int, int*) const override {}
virtual void gmin (int*,int,int*) const { } void gmin (int*, int, int*) const override {}
virtual void gsum (int*,int,int*) const { } void gsum (int*, int, int*) const override {}
virtual minmaxsum_t minmaxsum( double value ) const { return minmaxsum_t( value ); } minmaxsum_t minmaxsum( double value ) const override { return minmaxsum_t( value ); }
virtual std::pair<double,double> gmax (std::pair<double,double> value ) const { return value; } std::pair<double, double> gmax (std::pair<double, double> value ) const override { return value; }
virtual std::pair<double,double> gmin (std::pair<double,double> value ) const { return value; } std::pair<double, double> gmin (std::pair<double, double> value ) const override { return value; }
virtual std::pair<double,double> gsum (std::pair<double,double> value ) const { return value; } std::pair<double, double> gsum (std::pair<double, double> value ) const override { return value; }
virtual void bcast(int*,int, int) const { } void bcast(int*, int, int) const override {}
virtual void bcast(char*,int, int) const { } void bcast(char*, int, int) const override {}
virtual void bcast(double*,int, int) const { } void bcast(double*, int, int) const override {}
virtual int exscan( int value ) const { return 0; } int exscan( int value ) const override { return 0; }
virtual int scan( int value ) const { return value; } int scan( int value ) const override { return value; }
virtual std::vector< int > gcollect ( int value ) const { return std::vector< int >( psize(), value ); } std::vector< int > gcollect ( int value ) const override { return std::vector< int >( psize(), value ); }
std::vector< double > gcollect ( double value ) const override { return std::vector< double >( psize(), value ); }
virtual std::vector< double > gcollect ( double value ) const { return std::vector< double >( psize(), value ); }
std::vector< std::vector< int > > gcollect ( const std::vector< int > &value ) const override
virtual std::vector< std::vector< int > > gcollect ( const std::vector< int > &value ) const { return std::vector< std::vector< int > > (psize(), value); }
{
return std::vector< std::vector< int > > (psize(), value); std::vector< std::vector< double > > gcollect ( const std::vector< double > &value ) const override
} { return std::vector< std::vector< double > > ( psize(), value ); }
virtual std::vector< std::vector< double > > gcollect ( const std::vector< double > &value ) const std::vector< ObjectStream > gcollect ( const ObjectStream &os ) const override
{ { return std::vector< ObjectStream >( psize(), os ); }
return std::vector< std::vector< double > > ( psize(), value );
}
virtual std::vector< ObjectStream > gcollect ( const ObjectStream &os ) const
{
return std::vector< ObjectStream >( psize(), os );
}
#if HAVE_MPI #if HAVE_MPI
// return handle for non-blocking exchange and already do send operation // return handle for non-blocking exchange and already do send operation
virtual NonBlockingExchange* nonBlockingExchange ( const int tag, NonBlockingExchange* nonBlockingExchange (const int tag, const std::vector<ObjectStream>&) const override
const std::vector < ObjectStream > & ) const { return 0; } { return 0; }
// return handle for non-blocking exchange // return handle for non-blocking exchange
virtual NonBlockingExchange* nonBlockingExchange ( const int tag ) const { return 0; } NonBlockingExchange* nonBlockingExchange (const int tag) const override { return 0; }
#else // #if HAVE_MPI #else // #if HAVE_MPI
std::vector< int > dest () const { return std::vector< int >(); } std::vector< int > dest () const { return std::vector< int >(); }
#endif // #else // #if HAVE_MPI #endif // #else // #if HAVE_MPI
...@@ -88,26 +81,12 @@ namespace ALUGrid ...@@ -88,26 +81,12 @@ namespace ALUGrid
int link (int) const { return 0; } int link (int) const { return 0; }
int insertRequestSymetric (std::set < int, std::less < int > >){ return 0; } int insertRequestSymetric (std::set < int, std::less < int > >){ return 0; }
virtual std::vector< std::vector< int > > exchange ( const std::vector< std::vector< int > > &v ) const // exchange data and return new vector of object streams
{ std::vector< ObjectStream > exchange (const std::vector<ObjectStream>& v) const override { return v; }
return v; void exchange ( const std::vector< ObjectStream > &, NonBlockingExchange::DataHandleIF& ) const override {};
} void exchange ( NonBlockingExchange::DataHandleIF& ) const override {};
void exchangeSymmetric ( NonBlockingExchange::DataHandleIF& dh ) const override {};
virtual std::vector< std::vector< double > > exchange ( const std::vector< std::vector< double > > &v ) const
{
return v;
}
virtual std::vector< std::vector< char > > exchange ( const std::vector< std::vector< char > > &v ) const
{
return v;
}
// exchange data and return new std::vector of object streams
virtual std::vector< ObjectStream > exchange ( const std::vector < ObjectStream > &v ) const
{
return v;
}
}; };
#if HAVE_MPI #if HAVE_MPI
......
...@@ -10,6 +10,9 @@ ...@@ -10,6 +10,9 @@
//- dune-common includes //- dune-common includes
#include <dune/common/parallel/mpihelper.hh> #include <dune/common/parallel/mpihelper.hh>
//- dune-grid includes
#include <dune/grid/common/partitionset.hh>
#if HAVE_DUNE_ALUGRID #if HAVE_DUNE_ALUGRID
//- dune-alugrid includes //- dune-alugrid includes
#include <dune/alugrid/grid.hh> #include <dune/alugrid/grid.hh>
...@@ -74,24 +77,18 @@ namespace Dune ...@@ -74,24 +77,18 @@ namespace Dune
void calculateGraph () void calculateGraph ()
{ {
typedef typename GridView::template Codim< 0 >::template Partition< pitype >::Iterator Iterator; for (const auto& element : elements(gridView(), partitionSet<pitype>()))
ldbUpdateVertex( element, db_ );
const Iterator end = gridView().template end< 0, pitype >();
for( Iterator it = gridView().template begin< 0, pitype >(); it != end; ++it )
ldbUpdateVertex( *it, db_ );
} }
int weight ( const Element &element ) const int weight ( const Element &element ) const
{ {
typedef typename Element::HierarchicIterator HierarchicIterator;
// set weight to 1 for the element itself // set weight to 1 for the element itself
int weight = 1; int weight = 1;
// for every child, increase weight by 1 // for every child, increase weight by 1
const int maxLevel = gridView().grid().maxLevel(); const int maxLevel = gridView().grid().maxLevel();
const HierarchicIterator hend = element.hend( maxLevel ); for ([[maybe_unused]] const auto& child : descendantElements(element, maxLevel))
for( HierarchicIterator hit = element.hbegin( maxLevel ); hit != hend; ++hit )
++weight; ++weight;
return weight; return weight;
...@@ -99,8 +96,6 @@ namespace Dune ...@@ -99,8 +96,6 @@ namespace Dune
void ldbUpdateVertex ( const Element &element, DataBase &db ) void ldbUpdateVertex ( const Element &element, DataBase &db )
{ {
//typedef typename Element::Geometry::GlobalCoordinate GlobalCoordinate;
const int index = indexSet_.index( element ); const int index = indexSet_.index( element );
const int wght = weight( element ); const int wght = weight( element );
...@@ -115,23 +110,17 @@ namespace Dune ...@@ -115,23 +110,17 @@ namespace Dune
void updateFaces ( const Element &element, const int elementId, const int weight, DataBase &db ) void updateFaces ( const Element &element, const int elementId, const int weight, DataBase &db )
{ {
typedef typename GridView::IntersectionIterator IntersectionIterator; for(const auto& intersection : intersections(gridView(), element))
typedef typename GridView::Intersection Intersection;
const IntersectionIterator iend = gridView().iend( element );
for( IntersectionIterator iit = gridView().ibegin( element ); iit != iend; ++iit )
{ {
const Intersection &intersection = *iit;
if( !intersection.neighbor() ) if( !intersection.neighbor() )
continue; continue;
const Element &outside = intersection.outside(); const auto& outside = intersection.outside();
if( outside.partitionType() == InteriorEntity ) if( outside.partitionType() == InteriorEntity )
{ {
const int outsideId = indexSet_.index( outside ); const int outsideId = indexSet_.index( outside );
db.edgeUpdate( typename LoadBalancerType::GraphEdge( elementId, outsideId, weight, 0 , 0 ) ); db.edgeUpdate( typename LoadBalancerType::GraphEdge( elementId, outsideId, weight, 0, 0 ) );
} }
} }
} }
...@@ -179,8 +168,8 @@ namespace Dune ...@@ -179,8 +168,8 @@ namespace Dune
double mean = std::accumulate( v.begin(), v.end(), 0.0 ) / double( np ); double mean = std::accumulate( v.begin(), v.end(), 0.0 ) / double( np );
bool unbalanced = false; bool unbalanced = false;
for( typename std::vector< double >::iterator it = v.begin(); it != v.end(); ++it ) for( const double load : v )
unbalanced |= (*it > mean ? (*it > ldbOver_*mean) : (*it < ldbUnder_*mean)); unbalanced |= (load > mean ? (load > ldbOver_*mean) : (load < ldbUnder_*mean));
#ifndef NDEBUG #ifndef NDEBUG
// make sure all processes have come to the same conclusion // make sure all processes have come to the same conclusion
int local = int( unbalanced ); int local = int( unbalanced );
......
...@@ -6,11 +6,11 @@ ...@@ -6,11 +6,11 @@
#include <map> #include <map>
#include <string> #include <string>
#include <vector> #include <vector>
#include <memory>
//- dune-common includes //- dune-common includes
#include <dune/common/version.hh> #include <dune/common/version.hh>
#include <dune/common/parallel/mpihelper.hh> #include <dune/common/parallel/mpihelper.hh>
#include <dune/common/smartptr.hh>
//- dune-geometry includes //- dune-geometry includes
#if HAVE_DUNE_ALUGRID #if HAVE_DUNE_ALUGRID
...@@ -31,7 +31,6 @@ namespace Dune ...@@ -31,7 +31,6 @@ namespace Dune
// ------------- // -------------
class PartitionInfo class PartitionInfo
: public ReferenceCountable
{ {
typedef PartitionInfo This; typedef PartitionInfo This;
...@@ -106,7 +105,7 @@ namespace Dune ...@@ -106,7 +105,7 @@ namespace Dune
typedef std::map< IdType, int > RankMapType; typedef std::map< IdType, int > RankMapType;
public: public:
typedef PersistentContainer< HostGrid, SmartPtr< PartitionInfo > > PartitionInfoStorage; typedef PersistentContainer< HostGrid, std::shared_ptr< PartitionInfo > > PartitionInfoStorage;
typedef ALU3DSPACE ObjectStream ObjectStream; typedef ALU3DSPACE ObjectStream ObjectStream;
...@@ -143,7 +142,7 @@ namespace Dune ...@@ -143,7 +142,7 @@ namespace Dune
Partitioner partitioner_; Partitioner partitioner_;
MacroDecomposition macroDecomposition_; MacroDecomposition macroDecomposition_;
SmartPtr< PartitionInfo > interiorPartitionInfo_; std::shared_ptr< PartitionInfo > interiorPartitionInfo_;
PartitionInfoStorageArray partitionInfoStorage_; PartitionInfoStorageArray partitionInfoStorage_;
template < int codim > template < int codim >
...@@ -318,7 +317,7 @@ namespace Dune ...@@ -318,7 +317,7 @@ namespace Dune
{ {
if( dataHandle.contains( dimension, codim ) ) if( dataHandle.contains( dimension, codim ) )
{ {
const int numSubEntities = helement.template count< codim >(); const int numSubEntities = helement.subEntities(codim);
for( int i = 0 ; i < numSubEntities ; ++i ) for( int i = 0 ; i < numSubEntities ; ++i )
{ {
const auto& pEntity = helement.template subEntity< codim >( i ); const auto& pEntity = helement.template subEntity< codim >( i );
...@@ -336,7 +335,7 @@ namespace Dune ...@@ -336,7 +335,7 @@ namespace Dune
{ {
if( dataHandle.contains( dimension, codim ) ) if( dataHandle.contains( dimension, codim ) )
{ {
const int numSubEntities = helement.template count< codim >(); const int numSubEntities = helement.subEntities(codim);
for( int i = 0 ; i < numSubEntities ; ++i ) for( int i = 0 ; i < numSubEntities ; ++i )
{ {
const auto& pEntity = helement.template subEntity< codim >( i ); const auto& pEntity = helement.template subEntity< codim >( i );
...@@ -389,8 +388,8 @@ namespace Dune ...@@ -389,8 +388,8 @@ namespace Dune
#endif #endif
} }
void setPartitionType ( SmartPtr< PartitionInfo > &pInfo, PartitionType ptype ); void setPartitionType ( std::shared_ptr< PartitionInfo > &pInfo, PartitionType ptype );
void setConnectivity ( SmartPtr< PartitionInfo > &pInfo, int otherRank, PartitionType ptype ); void setConnectivity ( std::shared_ptr< PartitionInfo > &pInfo, int otherRank, PartitionType ptype );
void insertAllSubEntities ( const HostElement &hostElement, PartitionType ptype, int rank ); void insertAllSubEntities ( const HostElement &hostElement, PartitionType ptype, int rank );
void insertConnectivity ( const HostElement &hostElement, const PartitionType ptype, void insertConnectivity ( const HostElement &hostElement, const PartitionType ptype,
...@@ -429,7 +428,11 @@ namespace Dune ...@@ -429,7 +428,11 @@ namespace Dune
interiorPartitionInfo_( new PartitionInfo( InteriorEntity ) ) interiorPartitionInfo_( new PartitionInfo( InteriorEntity ) )
{ {
// create partition infos // create partition infos
ForLoop< CreatePartitionInfo, 0, dimension >::apply( hostGrid(), partitionInfoStorage_ ); Hybrid::forEach(std::make_index_sequence<dimension+1>{}, [&](auto i){
CreatePartitionInfo<i>::apply(
hostGrid(), partitionInfoStorage_
);
});
update(); update();
} }
...@@ -480,24 +483,24 @@ namespace Dune ...@@ -480,24 +483,24 @@ namespace Dune
} }
template< class Grid > template< class Grid >
inline void ParallelGridRankManager< Grid > inline void ParallelGridRankManager< Grid >
::setPartitionType ( SmartPtr< PartitionInfo > &pInfo, PartitionType ptype ) ::setPartitionType ( std::shared_ptr< PartitionInfo > &pInfo, PartitionType ptype )
{ {
if( pInfo && (pInfo != interiorPartitionInfo_) ) if( pInfo && (pInfo != interiorPartitionInfo_) )
pInfo->setPartitionType( ptype ); pInfo->setPartitionType( ptype );
else if( ptype == InteriorEntity ) else if( ptype == InteriorEntity )
pInfo = interiorPartitionInfo_; pInfo = interiorPartitionInfo_;
else else
pInfo = SmartPtr< PartitionInfo >( new PartitionInfo( ptype ) ); pInfo = std::shared_ptr< PartitionInfo >( new PartitionInfo( ptype ) );
} }
template< class Grid > template< class Grid >
inline void ParallelGridRankManager< Grid > inline void ParallelGridRankManager< Grid >
::setConnectivity ( SmartPtr< PartitionInfo > &pInfo, int otherRank, PartitionType ptype ) ::setConnectivity ( std::shared_ptr< PartitionInfo > &pInfo, int otherRank, PartitionType ptype )
{ {
assert( pInfo ); assert( pInfo );
if( pInfo == interiorPartitionInfo_ ) if( pInfo == interiorPartitionInfo_ )
pInfo = SmartPtr< PartitionInfo >( new PartitionInfo( InteriorEntity ) ); pInfo = std::shared_ptr< PartitionInfo >( new PartitionInfo( InteriorEntity ) );
pInfo->setConnectivity( otherRank, ptype ); pInfo->setConnectivity( otherRank, ptype );
} }
...@@ -506,7 +509,7 @@ namespace Dune ...@@ -506,7 +509,7 @@ namespace Dune
inline void ParallelGridRankManager< Grid > inline void ParallelGridRankManager< Grid >
::insertAllSubEntities ( const HostElement &hostElement, PartitionType ptype, int rank ) ::insertAllSubEntities ( const HostElement &hostElement, PartitionType ptype, int rank )
{ {
auto refElement = Dune::referenceElement<ctype,dimension>( hostElement.type() ); const auto refElement = referenceElement(hostElement);
assert( rank == myRank_ ); assert( rank == myRank_ );
...@@ -539,7 +542,7 @@ namespace Dune ...@@ -539,7 +542,7 @@ namespace Dune
if( codimAvailable< 1 >() ) if( codimAvailable< 1 >() )
setConnectivity( partitionInfoStorage( 1 )( hostElement, face ), otherRank, BorderEntity ); setConnectivity( partitionInfoStorage( 1 )( hostElement, face ), otherRank, BorderEntity );
auto refElement = Dune::referenceElement<ctype,dimension>( hostElement.type() ); const auto refElement = referenceElement(hostElement);
for( int codim = 2; codim <= dimension; ++codim ) for( int codim = 2; codim <= dimension; ++codim )
{ {
if( codimAvailable( codim ) ) if( codimAvailable( codim ) )
...@@ -731,7 +734,11 @@ namespace Dune ...@@ -731,7 +734,11 @@ namespace Dune
MessageBufferObjectStream mboStream( buffer[link]); MessageBufferObjectStream mboStream( buffer[link]);
ForLoop<Gather,0, dimension>::apply(hostElement,mboStream,dataHandle); Hybrid::forEach(std::make_index_sequence<dimension+1>{}, [&](auto i){
Gather<i>::apply(
hostElement, mboStream, dataHandle
);
});
typedef typename HostElement::HierarchicIterator HierarchicIterator; typedef typename HostElement::HierarchicIterator HierarchicIterator;
...@@ -739,7 +746,11 @@ namespace Dune ...@@ -739,7 +746,11 @@ namespace Dune
for( HierarchicIterator hit = hostElement.hbegin(maxLevel); hit!=hend ; ++hit ) for( HierarchicIterator hit = hostElement.hbegin(maxLevel); hit!=hend ; ++hit )
{ {
ForLoop<Gather,0,dimension>::apply(*hit,mboStream,dataHandle); Hybrid::forEach(std::make_index_sequence<dimension+1>{}, [&](auto i){
Gather<i>::apply(
*hit, mboStream, dataHandle
);
});
} }
} }
// write end marker to all streams // write end marker to all streams
...@@ -781,7 +792,11 @@ namespace Dune ...@@ -781,7 +792,11 @@ namespace Dune
sync.ensure( buffer[ link ], size ); sync.ensure( buffer[ link ], size );
MessageBufferObjectStream mboStream( buffer[link]); MessageBufferObjectStream mboStream( buffer[link]);
ForLoop<Scatter,0, dimension>::apply(hostElement,mboStream,dataHandle, size); Hybrid::forEach(std::make_index_sequence<dimension+1>{}, [&](auto i){
Scatter<i>::apply(
hostElement, mboStream, dataHandle, size
);
});
typedef typename HostElement::HierarchicIterator HierarchicIterator; typedef typename HostElement::HierarchicIterator HierarchicIterator;
...@@ -789,7 +804,11 @@ namespace Dune ...@@ -789,7 +804,11 @@ namespace Dune
for( HierarchicIterator hit = hostElement.hbegin(maxLevel); hit!=hend ; ++hit ) for( HierarchicIterator hit = hostElement.hbegin(maxLevel); hit!=hend ; ++hit )
{ {
ForLoop<Scatter,0,dimension>::apply(*hit,mboStream,dataHandle,size); Hybrid::forEach(std::make_index_sequence<dimension+1>{}, [&](auto i){
Scatter<i>::apply(
*hit, mboStream, dataHandle, size
);
});
} }
sync.ensure( buffer[ link ] ); sync.ensure( buffer[ link ] );
......
...@@ -7,23 +7,23 @@ set(METAGRIDS idgrid) ...@@ -7,23 +7,23 @@ set(METAGRIDS idgrid)
# set(METAGRIDS idgrid,idgrid,idgrid) # set(METAGRIDS idgrid,idgrid,idgrid)
# set(TESTS test-cacheitgrid test-cartesiangrid test-filteredgrid test-idgrid test-metagrids test-parallelgrid test-sfc test-prismgrid) # set(TESTS test-cacheitgrid test-cartesiangrid test-filteredgrid test-idgrid test-metagrids test-parallelgrid test-sfc test-prismgrid)
set(TESTS test-cartesiangrid test-idgrid test-parallelgrid ) set(TESTS test-cartesiangrid test-idgrid )
foreach(_executable ${TESTS}) foreach(_executable ${TESTS})
dune_add_test(NAME ${_executable} SOURCES ${_executable}.cc) dune_add_test(NAME ${_executable} SOURCES ${_executable}.cc)
set_property(TARGET ${_executable} APPEND PROPERTY COMPILE_DEFINITIONS set_property(TARGET ${_executable} APPEND PROPERTY COMPILE_DEFINITIONS
"GRIDDIM=${GRIDDIM}" "WORLDDIM=${WORLDDIM}" "${GRIDTYPE}") "GRIDDIM=${GRIDDIM}" "WORLDDIM=${WORLDDIM}" "${GRIDTYPE}")
set_property(TARGET ${_executable} APPEND PROPERTY COMPILE_DEFINITIONS "METAGRIDS=${METAGRIDS}") set_property(TARGET ${_executable} APPEND PROPERTY COMPILE_DEFINITIONS "METAGRIDS=${METAGRIDS}")
endforeach()
# dune_target_enable_all_packages( ${_executable} )
endforeach(_executable ${TESTS})
dune_add_test(NAME test-spheregrid SOURCES test-spheregrid.cc CMAKE_GUARD dune-alugrid_FOUND) dune_add_test(NAME test-spheregrid SOURCES test-spheregrid.cc CMAKE_GUARD dune-alugrid_FOUND)
set_property(TARGET test-spheregrid APPEND PROPERTY COMPILE_DEFINITIONS "GRIDDIM=2" "WORLDDIM=3" "ALUGRID_SIMPLEX") set_property(TARGET test-spheregrid APPEND PROPERTY COMPILE_DEFINITIONS "GRIDDIM=2" "WORLDDIM=3" "ALUGRID_SIMPLEX")
dune_add_test(NAME test-parallelgrid
#add_directory_test_target(test_target) SOURCES test-parallelgrid.cc
# add_dependencies(${test_target} ${TESTS}) CMAKE_GUARD dune-alugrid_FOUND
COMPILE_DEFINITIONS "GRIDDIM=${GRIDDIM}" "WORLDDIM=${WORLDDIM}" "${GRIDTYPE}" "METAGRIDS=${METAGRIDS}"
CMD_ARGS 2dcube.dgf)
set(DGFS set(DGFS
1dcube.dgf 2dcube.dgf 3dcube.dgf cubedsphere2d.dgf octahedron.dgf 1dcube.dgf 2dcube.dgf 3dcube.dgf cubedsphere2d.dgf octahedron.dgf
......
...@@ -26,27 +26,16 @@ using namespace Dune; ...@@ -26,27 +26,16 @@ using namespace Dune;
template <bool leafconform, class Grid> template <bool leafconform, class Grid>
void checkCapabilities(const Grid& grid) void checkCapabilities(const Grid& grid)
{ {
static_assert( Dune::Capabilities::isLevelwiseConforming< Grid > :: v == ! leafconform, static_assert( Dune::Capabilities::isLevelwiseConforming<Grid>::v == !leafconform,
"isLevelwiseConforming is not set correctly"); "isLevelwiseConforming is not set correctly");
static_assert( Dune::Capabilities::isLeafwiseConforming< Grid > :: v == leafconform, static_assert( Dune::Capabilities::isLeafwiseConforming<Grid>::v == leafconform,
"isLevelwiseConforming is not set correctly"); "isLevelwiseConforming is not set correctly");
static const bool hasEntity = Dune::Capabilities::hasEntity<Grid, 1> :: v == true; static const bool hasEntity = Dune::Capabilities::hasEntity<Grid, 1>::v == true;
static_assert( hasEntity, static_assert( hasEntity,
"hasEntity is not set correctly"); "hasEntity is not set correctly");
static_assert( Dune::Capabilities::hasBackupRestoreFacilities< Grid > :: v == true, static_assert( Dune::Capabilities::hasBackupRestoreFacilities<Grid>::v == true,
"hasBackupRestoreFacilities is not set correctly"); "hasBackupRestoreFacilities is not set correctly");
static const bool reallyParallel =
#if ALU3DGRID_PARALLEL && ALU2DGRID_PARALLEL
true ;
#elif ALU3DGRID_PARALLEL
Grid :: dimension == 3;
#else
false ;
#endif
//static_assert( Dune::Capabilities::isParallel< Grid > :: v == reallyParallel,
// "isParallel is not set correctly");
static const bool reallyCanCommunicate = static const bool reallyCanCommunicate =
#if ALU3DGRID_PARALLEL && ALU2DGRID_PARALLEL #if ALU3DGRID_PARALLEL && ALU2DGRID_PARALLEL
true ; true ;
...@@ -55,33 +44,30 @@ void checkCapabilities(const Grid& grid) ...@@ -55,33 +44,30 @@ void checkCapabilities(const Grid& grid)
#else #else
false ; false ;
#endif #endif
static const bool canCommunicate = Dune::Capabilities::canCommunicate< Grid, 1 > :: v static const bool canCommunicate
== reallyCanCommunicate; = Dune::Capabilities::canCommunicate<Grid, 1>::v == reallyCanCommunicate;
static_assert( canCommunicate, static_assert( canCommunicate, "canCommunicate is not set correctly");
"canCommunicate is not set correctly");
} }
template <class GridType> template <class GridType>
void makeNonConfGrid(GridType &grid,int level,int adapt) { void makeNonConformingGrid(GridType& grid, int level, int adapt)
{
int myrank = grid.comm().rank(); int myrank = grid.comm().rank();
grid.loadBalance(); grid.loadBalance();
grid.globalRefine(level); grid.globalRefine(level);
grid.loadBalance(); grid.loadBalance();
for (int i=0;i<adapt;i++) for (int i=0; i<adapt; i++)
{ {
if (myrank==0) if (myrank==0)
{ {
typedef typename GridType :: template Codim<0> :: std::size_t numberOfRefinedElements = 0;
template Partition<Interior_Partition> :: LeafIterator LeafIterator; const auto size = grid.leafGridView().size(0);
for(const auto& element : elements(grid.leafGridView()))
LeafIterator endit = grid.template leafend<0,Interior_Partition> ();
int nr = 0;
int size = grid.size(0);
for(LeafIterator it = grid.template leafbegin<0,Interior_Partition> ();
it != endit ; ++it,nr++ )
{ {
grid.mark(1, *it ); grid.mark(1, element);
if (nr>size*0.8) break; if (numberOfRefinedElements > size*0.8)
break;
numberOfRefinedElements++;
} }
} }
grid.adapt(); grid.adapt();
...@@ -91,60 +77,60 @@ void makeNonConfGrid(GridType &grid,int level,int adapt) { ...@@ -91,60 +77,60 @@ void makeNonConfGrid(GridType &grid,int level,int adapt) {
} }
template <class GridView> template <class GridView>
void writeFile( const GridView& gridView ) void writeFile(const GridView& gridView)
{ {
DGFWriter< GridView > writer( gridView ); DGFWriter< GridView > writer( gridView );
writer.write( "dump.dgf" ); writer.write( "dump.dgf" );
} }
template <class GridType> template <class GridType>
void checkSerial(GridType & grid, int mxl = 2, const bool display = false) void checkSerial(GridType& grid, int mxl = 2)
{ {
// be careful, each global refine create 8 x maxlevel elements // be careful, each global refine create 8 x maxlevel elements
std::cout << " CHECKING: Macro" << std::endl; std::cout << " CHECKING: Macro" << std::endl;
//gridcheck(grid); gridcheck(grid);
std::cout << " CHECKING: Macro-intersections" << std::endl; std::cout << " CHECKING: Macro-intersections" << std::endl;
//checkIntersectionIterator(grid); checkIntersectionIterator(grid);
for(int i=0; i<mxl; i++) for(int i=0; i<mxl; i++)
{ {
grid.globalRefine( 1 );//DGFGridInfo<GridType> :: refineStepsForHalf() ); grid.globalRefine( 1 );//DGFGridInfo<GridType> :: refineStepsForHalf() );
std::cout << " CHECKING: Refined" << std::endl; std::cout << " CHECKING: Refined" << std::endl;
//gridcheck(grid); gridcheck(grid);
std::cout << " CHECKING: intersections" << std::endl; std::cout << " CHECKING: intersections" << std::endl;
//checkIntersectionIterator(grid); checkIntersectionIterator(grid);
} }
// check also non-conform grids // check also non-conform grids
//makeNonConfGrid(grid,0,1); makeNonConformingGrid(grid,0,1);
//std::cout << " CHECKING: non-conform" << std::endl; //std::cout << " CHECKING: non-conform" << std::endl;
//gridcheck(grid); gridcheck(grid);
// check the method geometryInFather() // check the method geometryInFather()
//std::cout << " CHECKING: geometry in father" << std::endl; std::cout << " CHECKING: geometry in father" << std::endl;
//checkGeometryInFather(grid); checkGeometryInFather(grid);
// check the intersection iterator and the geometries it returns // check the intersection iterator and the geometries it returns
//std::cout << " CHECKING: intersections" << std::endl; std::cout << " CHECKING: intersections" << std::endl;
//checkIntersectionIterator(grid); checkIntersectionIterator(grid);
std::cout << std::endl << std::endl; std::cout << std::endl << std::endl;
} }
template <class GridType> template <class GridType>
void checkParallel(GridType & grid, int gref, int mxl = 3, const bool display = false ) void checkParallel(GridType& grid, int gref, int mxl = 3)
{ {
std::cout << "P[ " << grid.comm().rank() << " ] = " << grid.size( 0 ) << std::endl; std::cout << "P[ " << grid.comm().rank() << " ] = " << grid.size( 0 ) << std::endl;
#if HAVE_MPI #if HAVE_MPI
//makeNonConfGrid(grid,gref,mxl); //makeNonConformingGrid(grid,gref,mxl);
// -1 stands for leaf check // -1 stands for leaf check
checkCommunication(grid, -1, std::cout); checkCommunication(grid, -1, std::cout);
const int maxLevel = std::min( mxl, grid.maxLevel() ); const int maxLevel = std::min( mxl, grid.maxLevel() );
for(int l=0; l<= maxLevel; ++l) for(int l=0; l<= maxLevel; ++l)
checkCommunication(grid, l , Dune::dvverb); checkCommunication(grid, l, Dune::dvverb);
#endif #endif
} }
...@@ -153,61 +139,45 @@ int main (int argc , char **argv) ...@@ -153,61 +139,45 @@ int main (int argc , char **argv)
{ {
// this method calls MPI_Init, if MPI is enabled // this method calls MPI_Init, if MPI is enabled
MPIHelper & mpihelper = MPIHelper::instance(argc,argv); auto& mpiHelper = MPIHelper::instance(argc,argv);
int myrank = mpihelper.rank(); const int myrank = mpiHelper.rank();
int mysize = mpihelper.size(); const int mysize = mpiHelper.size();
try {
/* use grid-file appropriate for dimensions */
if( argc < 2 )
{
std::cerr << "Usage: " << argv[0] << " <dgf file of hostgrid>" << std::endl;
return 1;
}
const bool display = (argc > 2);
typedef Dune::GridSelector :: GridType HostGridType ;
std::string filename( argv[1] );
GridPtr< HostGridType > hostGrid( filename );
typedef ParallelGrid< HostGridType > ParallelGridType; /* use grid-file appropriate for dimensions */
ParallelGridType grid( *hostGrid ); if( argc < 2 )
{
grid.loadBalance(); std::cerr << "Usage: " << argv[0] << " <dgf file of hostgrid>" << std::endl;
std::cout << "P["<<myrank<<"] size = "<< grid.size( 0 ) << std::endl; return 1;
}
{ using HostGridType = Dune::GridSelector::GridType;
std::cout << "Check serial grid" << std::endl; std::string filename( argv[1] );
checkSerial(grid, GridPtr< HostGridType > hostGrid( filename );
(mysize == 1) ? 1 : 0,
(mysize == 1) ? display: false);
}
// perform parallel check only when more then one proc using ParallelGridType = ParallelGrid<HostGridType>;
if(mysize > 1) ParallelGridType grid( *hostGrid );
{
if (myrank == 0) std::cout << "Check conform grid" << std::endl;
checkParallel(grid,1,0, display );
if (myrank == 0) std::cout << "Check non-conform grid" << std::endl;
checkParallel(grid,0,2, display );
}
Dune :: VTKWriter<ParallelGridType :: LeafGridView> vtkWriter(grid.leafGridView()); grid.loadBalance();
vtkWriter.write( "paragrid.out" ); std::cout << "P["<<myrank<<"] size = "<< grid.size( 0 ) << std::endl;
}
catch (Dune::Exception &e)
{ {
std::cerr << e << std::endl; std::cout << "Check serial grid" << std::endl;
return 1; checkSerial(grid, (mysize == 1) ? 1 : 0);
} }
catch (...)
// perform parallel check only when more then one proc
if(mysize > 1)
{ {
std::cerr << "Generic exception!" << std::endl; if (myrank == 0) std::cout << "Check conform grid" << std::endl;
return 2; checkParallel(grid, 1, 0);
if (myrank == 0) std::cout << "Check non-conform grid" << std::endl;
checkParallel(grid, 0, 2);
} }
Dune::VTKWriter<ParallelGridType::LeafGridView> vtkWriter(grid.leafGridView());
std::vector<int> ranks(grid.leafGridView().size(0), myrank);
vtkWriter.addCellData( ranks, "rank" );
vtkWriter.write( "parallel_grid" );
return 0; return 0;
} }