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
*.log
*.o
*.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)
set(DUNE_REENABLE_ADD_TEST TRUE)
cmake_minimum_required(VERSION 2.8.12)
cmake_minimum_required(VERSION 3.13)
# guess dune-common build dir
if(NOT (dune-common_DIR OR dune-common_ROOT OR
......
......@@ -59,7 +59,7 @@ namespace Dune
// ----------------------
#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;
template< class WrappedHandle >
......@@ -111,7 +111,7 @@ namespace Dune
typedef MetaGridDataHandleBase< WrappedHandle > Base;
// 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
typedef typename Traits :: ExtraData ExtraData ;
......@@ -210,7 +210,7 @@ namespace Dune
template< class WrappedDofManager, class GridFamily, class Filter = MetaGridNoFilter >
class MetaGridWrappedDofManager
{
typedef typename std::remove_const< GridFamily >::type::Traits Traits;
typedef typename std::remove_const_t<GridFamily>::Traits Traits;
// type of extra data
typedef typename Traits :: ExtraData ExtraData ;
// type of host element (i.e. codim = 0)
......
......@@ -116,11 +116,6 @@ namespace Dune
return hostEntity().type();
}
unsigned int subEntities( const unsigned int cd ) const
{
return hostEntity().subEntities( cd );
}
/** \brief obtain the level of this entity */
int level () const
{
......@@ -133,6 +128,12 @@ namespace Dune
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 */
Geometry geometry () const
{
......
......@@ -30,14 +30,12 @@ namespace Dune
static const bool v = isCartesian< HostGrid >::v;
};
template< class HostGrid, int codim >
struct hasEntity< ParallelGrid< HostGrid >, codim >
{
static const bool v = hasEntity< HostGrid, codim >::v;
};
template< class HostGrid, int codim >
struct canCommunicate< ParallelGrid< HostGrid >, codim >
{
......
......@@ -4,7 +4,7 @@
#include <vector>
#include <dune/common/applyif.hh>
#include <dune/common/forloop.hh>
#include <dune/common/hybridutilities.hh>
#include <dune/grid/common/gridenums.hh>
......@@ -36,18 +36,16 @@ namespace Dune
typedef ALU3DSPACE ALUMpAccess MpAccess;
template< int codim >
struct CodimAvailable
{
static const bool value = Capabilities::hasEntity< Grid, codim >::v;
};
template< int codim >
struct PackData;
template< int codim >
struct UnpackData;
template<int codim>
static constexpr bool codimAvailable()
{ return Capabilities::hasEntity<Grid, codim>::v; }
public:
static const int dimension = Grid::dimension;
......@@ -85,8 +83,10 @@ namespace Dune
if( (info.partitionType() == sendType) && info.hasConnectivity() )
{
ForLoop< ApplyIf< PackData, CodimAvailable >::template Operation, 0, dimension >
::apply( mpAccess(), rankManager_, dataHandle, buffer, entity, count );
Hybrid::forEach(std::make_index_sequence<dimension+1>{}, [&](auto codim){
if constexpr (codimAvailable<codim>())
PackData<codim>::apply(mpAccess(), rankManager_, dataHandle, buffer, entity, count);
});
}
}
......@@ -100,8 +100,10 @@ namespace Dune
if( (info.partitionType() == recvType) && info.hasConnectivity() )
{
ForLoop< ApplyIf< PackData, CodimAvailable >::template Operation, 0, dimension >
::apply( mpAccess(), rankManager_, dataHandle, buffer, entity, count );
Hybrid::forEach(std::make_index_sequence<dimension+1>{}, [&](auto codim){
if constexpr (codimAvailable<codim>())
PackData<codim>::apply(mpAccess(), rankManager_, dataHandle, buffer, entity, count);
});
}
}
}
......@@ -136,8 +138,10 @@ namespace Dune
if( (info.partitionType() == recvType) && info.hasConnectivity() )
{
ForLoop< ApplyIf< UnpackData, CodimAvailable >::template Operation, 0, dimension >
::apply( mpAccess(), rankManager_, dataHandle, buffer, entity, count, sizes );
Hybrid::forEach(std::make_index_sequence<dimension+1>{}, [&](auto codim){
if constexpr (codimAvailable<codim>())
UnpackData<codim>::apply(mpAccess(), rankManager_, dataHandle, buffer, entity, count, sizes);
});
}
}
......@@ -152,8 +156,10 @@ namespace Dune
// if entity is not send type, don't do anything
if( (info.partitionType() == sendType) && info.hasConnectivity() )
{
ForLoop< ApplyIf< UnpackData, CodimAvailable >::template Operation, 0, dimension >
::apply( mpAccess(), rankManager_, dataHandle, buffer, entity, count, sizes );
Hybrid::forEach(std::make_index_sequence<dimension+1>{}, [&](auto codim){
if constexpr (codimAvailable<codim>())
UnpackData<codim>::apply(mpAccess(), rankManager_, dataHandle, buffer, entity, count, sizes);
});
}
}
}
......@@ -242,9 +248,7 @@ namespace Dune
template< int codim >
struct ParallelGridCommunication< Grid >::UnpackData
{
typedef typename Grid::template Codim< 0 >::Entity Element;
typedef typename Grid::template Codim< codim >::Entity Entity;
using Element = typename Grid::template Codim< 0 >::Entity;
template< class DataHandleIF >
static void apply ( const MpAccess &mpAccess, const RankManager &rankManager,
......@@ -264,15 +268,13 @@ namespace Dune
for( int subEntity = 0; subEntity < numSubEntities; ++subEntity )
{
// get subentity
const Entity &entity = element.template subEntity< codim >( subEntity );
const auto& entity = element.template subEntity< codim >( subEntity );
// 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( typename PartitionInfo::iterator it = info.begin(); it != end; ++it )
for( const int srcRank : info )
{
const int srcRank = (*it);
const int link = mpAccess.link( srcRank );
#ifndef NDEBUG
......
......@@ -16,8 +16,6 @@ namespace Dune
template< class, PartitionIteratorType, class > class ParallelGridIteratorChecked;
// ParallelGridEntity
// ------------------
......@@ -26,22 +24,22 @@ namespace Dune
* \nosubgrouping
*/
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:
typedef typename Base::HostGrid HostGrid;
typedef typename Base::ExtraData ExtraData;
using HostGrid = typename Base::HostGrid;
using ExtraData = typename Base::ExtraData;
public:
using Base :: data ;
using Base :: hostEntity ;
using Base::data;
using Base::hostEntity;
/** \name Host Types
* \{ */
//! type of corresponding host entity
typedef typename Base :: HostEntity HostEntity ;
using HostEntity = typename Base::HostEntity;
/** \} */
......@@ -50,8 +48,13 @@ namespace Dune
* \{ */
/** \brief construct a null entity */
explicit ParallelGridEntity ( ExtraData data )
: Base( data )
explicit ParallelGridEntityBase(ExtraData data)
: Base(data)
{}
/** \brief Default constructed null entity */
ParallelGridEntityBase()
: Base(nullptr)
{}
/** \brief construct an initialized entity
......@@ -61,14 +64,14 @@ namespace Dune
* \note The reference to the host entity must remain valid as long as
* this entity is in use.
*/
ParallelGridEntity ( ExtraData data,
const HostEntity &hostEntity )
: Base( data, hostEntity )
ParallelGridEntityBase(ExtraData data,
const HostEntity& hostEntity )
: Base(data, hostEntity)
{}
/** \brief copy constructor */
ParallelGridEntity ( const ParallelGridEntity &other )
: Base( other )
ParallelGridEntityBase(const ParallelGridEntityBase& other)
: Base(other)
{}
/** \name Methods Shared by Entities of All Codimensions
......@@ -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
#endif // #ifndef DUNE_PARALLELGRID_ENTITY_HH
......@@ -7,6 +7,7 @@
#include <dune/grid/common/sizecache.hh>
#include <dune/grid/idgrid/idset.hh>
#include <dune/grid/idgrid/entityseed.hh>
#include <dune/grid/idgrid/geometry.hh>
#include <dune/grid/idgrid/intersectioniterator.hh>
......@@ -80,7 +81,7 @@ namespace Dune
typedef Dune::Entity< codim, dimension, const Grid, ParallelGridEntity > Entity;
// 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 >
struct Partition
......@@ -313,10 +314,7 @@ namespace Dune
DUNE_THROW( InvalidStateException, "ParallelGrid can only be used with serial host grids." );
for( int i = 0; i <= HostGrid::dimension; ++i )
{
auto types = hostGrid.levelGridView( 0 ).indexSet().types( i );
geomTypes_.push_back( types );
}
geomTypes_.push_back( hostGrid.levelGridView( 0 ).indexSet().types( i ) );
sizeCache_.reset();
}
......@@ -345,10 +343,7 @@ namespace Dune
DUNE_THROW( InvalidStateException, "ParallelGrid can only be used with serial host grids." );
for( int i = 0; i <= HostGrid::dimension; ++i )
{
auto types = hostGrid.levelGridView( 0 ).indexSet().types( i );
geomTypes_.push_back( types );
}
geomTypes_.push_back( hostGrid->levelGridView( 0 ).indexSet().types( i ) );
sizeCache_.reset();
}
......@@ -820,16 +815,17 @@ namespace Dune
return LeafGridView( ViewImp( *this ) );
}
/** \brief obtain EntityPointer from EntitySeed. */
template< class EntitySeed >
typename Traits::template Codim< EntitySeed::codimension >::EntityPointer
entityPointer ( const EntitySeed &seed ) const
/** \brief Create an Entity from an EntitySeed */
template <class EntitySeed>
typename Traits::template Codim<EntitySeed::codimension>::Entity
entity(const EntitySeed& seed) const
{
typedef typename Traits::template Codim< EntitySeed::codimension >::EntityPointerImpl EntityPointerImpl;
return EntityPointerImpl( extraData(), hostGrid().entityPointer( seed ) );
static constexpr int codim = EntitySeed::codimension;
using EntityImpl = typename Traits::template Codim<codim>::EntityImpl;
return EntityImpl( extraData(), hostGrid().entity( seed.impl().hostEntitySeed() ) );
}
/** \} */
/** \name Miscellaneous Methods
......
......@@ -5,8 +5,6 @@
#include <dune/grid/parallelgrid/rankmanager.hh>
#include <dune/grid/idgrid/intersection.hh>
#if HAVE_DUNE_ALUGRID
namespace Dune
{
......@@ -24,6 +22,10 @@ namespace Dune
using Base :: data ;
using Base :: hostIntersection ;
ParallelGridIntersection ()
: Base ()
{}
explicit ParallelGridIntersection ( ExtraData data )
: Base( data )
{}
......@@ -40,6 +42,4 @@ namespace Dune
} // namespace Dune
#endif // #if HAVE_DUNE_ALUGRID
#endif // #ifndef DUNE_PARALLELGRID_INTERSECTION_HH
#ifndef 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>
#if HAVE_DUNE_ALUGRID
......@@ -17,31 +13,31 @@ namespace Dune
template< class Grid, PartitionIteratorType pitype, class HostIterator >
class ParallelGridIteratorChecked
: public IdGridIterator< Grid, HostIterator >
{
typedef IdGridIterator< Grid, HostIterator > Base;
protected:
using Base::hostIterator_;
using RankManager = ParallelGridRankManager<std::remove_const_t<Grid>>;
using Traits = typename std::remove_const_t<Grid>::Traits;
using Base::data;
using ExtraData = typename Traits::ExtraData;
static constexpr int codimension = HostIterator::Entity::codimension;
protected:
typedef typename Base::ExtraData ExtraData;
public:
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_ )
{
const typename HostIterator::Entity &hostEntity = *hostIterator_;
const auto& hostEntity = *hostIterator_;
if( !rankManager().validEntity( hostEntity ) )
if( !rankManager_().validEntity( hostEntity ) )
continue;
// determine interior and ghost
const PartitionInfo &info = rankManager().partitionInfo( hostEntity );
const auto& info = rankManager_().partitionInfo( hostEntity );
switch( pitype )
{
case All_Partition:
......@@ -73,27 +69,47 @@ namespace Dune
public:
// constructor for begin iterator
ParallelGridIteratorChecked ( ExtraData data, const HostIterator &hostIterator, const HostIterator &endIterator )
: Base( data, hostIterator ),
endIterator_( endIterator )
: data_(data)
, hostIterator_(hostIterator)
, endIterator_(endIterator)
{
checkValid();
keepIncrementingIfInvalid_();
}
// constructor for end iterator
ParallelGridIteratorChecked ( ExtraData data, const HostIterator &endIterator )
: Base( data, endIterator ),
endIterator_( endIterator )
: data_(data)
, hostIterator_(endIterator)
, endIterator_(endIterator)
{}
void increment ()
{
++hostIterator_;
checkValid();
keepIncrementingIfInvalid_();
}
protected:
const RankManager &rankManager () const { return data()->rankManager(); }
/** \brief check for equality */
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_;
};
......
......@@ -17,7 +17,7 @@ namespace Dune
{
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;
......
......@@ -23,62 +23,55 @@ namespace ALUGrid
typedef MpAccessGlobal::minmaxsum_t minmaxsum_t;
typedef MpAccessLocal::NonBlockingExchange NonBlockingExchange;
virtual int psize() const { return 1; }
virtual int nlinks() const { return 0; }
int myrank () const { return 0; }
virtual int barrier () const { return psize(); }
virtual bool gmax (bool value) const { return value; }
virtual int gmax (int value) const { return value; }
virtual int gmin ( int value ) const { return value; }
virtual int gsum ( int value ) const { return value; }
virtual long gmax ( long value ) const { return value; }
virtual long gmin ( long value ) const { return value; }
virtual long gsum ( long value ) const { return value; }
virtual double gmax ( double value ) const { return value; }
virtual double gmin ( double value ) const { return value; }
virtual double gsum ( double value ) const { return value; }
virtual void gmax (double* in, int length, double* out) const { std::copy(in, in+length, out ); }
virtual void gmin (double* in, int length, double* out) const { std::copy(in, in+length, out ); }
virtual void gsum (double* in, int length, double* out) const { std::copy(in, in+length, out ); }
virtual void gmax (int*,int,int*) const { }
virtual void gmin (int*,int,int*) const { }
virtual void gsum (int*,int,int*) const { }
virtual minmaxsum_t minmaxsum( double value ) const { return minmaxsum_t( value ); }
virtual std::pair<double,double> gmax (std::pair<double,double> value ) const { return value; }
virtual std::pair<double,double> gmin (std::pair<double,double> value ) const { return value; }
virtual std::pair<double,double> gsum (std::pair<double,double> value ) const { return value; }
virtual void bcast(int*,int, int) const { }
virtual void bcast(char*,int, int) const { }
virtual void bcast(double*,int, int) const { }
virtual int exscan( int value ) const { return 0; }
virtual int scan( int value ) const { return value; }
virtual std::vector< int > gcollect ( int value ) const { return std::vector< int >( psize(), value ); }
virtual std::vector< double > gcollect ( double value ) const { return std::vector< double >( psize(), value ); }
virtual std::vector< std::vector< int > > gcollect ( const std::vector< int > &value ) const
{
return std::vector< std::vector< int > > (psize(), value);
}
virtual std::vector< std::vector< double > > gcollect ( const std::vector< double > &value ) const
{
return std::vector< std::vector< double > > ( psize(), value );
}
virtual std::vector< ObjectStream > gcollect ( const ObjectStream &os ) const
{
return std::vector< ObjectStream >( psize(), os );
}
int psize() const override { return 1; }
int nlinks () const { return 0; }
int myrank () const override { return 0; }
int barrier () const override { return psize(); }
bool gmax (bool value) const override { return value; }
int gmax (int value) const override { return value; }
int gmin ( int value ) const override { return value; }
int gsum ( int value ) const override { return value; }
long gmax ( long value ) const override { return value; }
long gmin ( long value ) const override { return value; }
long gsum ( long value ) const override { return value; }
double gmax ( double value ) const override { return value; }
double gmin ( double value ) const override { return value; }
double gsum ( double value ) const override { return value; }
void gmax (double* in, int length, double* out) const override { std::copy(in, in+length, out ); }
void gmin (double* in, int length, double* out) const override { std::copy(in, in+length, out ); }
void gsum (double* in, int length, double* out) const override { std::copy(in, in+length, out ); }
void gmax (int*, int, int*) const override {}
void gmin (int*, int, int*) const override {}
void gsum (int*, int, int*) const override {}
minmaxsum_t minmaxsum( double value ) const override { return minmaxsum_t( value ); }
std::pair<double, double> gmax (std::pair<double, double> value ) const override { return value; }
std::pair<double, double> gmin (std::pair<double, double> value ) const override { return value; }
std::pair<double, double> gsum (std::pair<double, double> value ) const override { return value; }
void bcast(int*, int, int) const override {}
void bcast(char*, int, int) const override {}
void bcast(double*, int, int) const override {}
int exscan( int value ) const override { return 0; }
int scan( int value ) const override { return 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 ); }
std::vector< std::vector< int > > gcollect ( const std::vector< int > &value ) const override
{ 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 ); }
std::vector< ObjectStream > gcollect ( const ObjectStream &os ) const override
{ return std::vector< ObjectStream >( psize(), os ); }
#if HAVE_MPI
// return handle for non-blocking exchange and already do send operation
virtual NonBlockingExchange* nonBlockingExchange ( const int tag,
const std::vector < ObjectStream > & ) const { return 0; }
NonBlockingExchange* nonBlockingExchange (const int tag, const std::vector<ObjectStream>&) const override
{ return 0; }
// 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
std::vector< int > dest () const { return std::vector< int >(); }
#endif // #else // #if HAVE_MPI
......@@ -88,26 +81,12 @@ namespace ALUGrid
int link (int) const { 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
{
return v;
}
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;
}
// exchange data and return new vector of object streams
std::vector< ObjectStream > exchange (const std::vector<ObjectStream>& v) const override { 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 {};
};
#if HAVE_MPI
......
......@@ -10,6 +10,9 @@
//- dune-common includes
#include <dune/common/parallel/mpihelper.hh>
//- dune-grid includes
#include <dune/grid/common/partitionset.hh>
#if HAVE_DUNE_ALUGRID
//- dune-alugrid includes
#include <dune/alugrid/grid.hh>
......@@ -74,24 +77,18 @@ namespace Dune
void calculateGraph ()
{
typedef typename GridView::template Codim< 0 >::template Partition< pitype >::Iterator Iterator;
const Iterator end = gridView().template end< 0, pitype >();
for( Iterator it = gridView().template begin< 0, pitype >(); it != end; ++it )
ldbUpdateVertex( *it, db_ );
for (const auto& element : elements(gridView(), partitionSet<pitype>()))
ldbUpdateVertex( element, db_ );
}
int weight ( const Element &element ) const
{
typedef typename Element::HierarchicIterator HierarchicIterator;
// set weight to 1 for the element itself
int weight = 1;
// for every child, increase weight by 1
const int maxLevel = gridView().grid().maxLevel();
const HierarchicIterator hend = element.hend( maxLevel );
for( HierarchicIterator hit = element.hbegin( maxLevel ); hit != hend; ++hit )
for ([[maybe_unused]] const auto& child : descendantElements(element, maxLevel))
++weight;
return weight;
......@@ -99,8 +96,6 @@ namespace Dune
void ldbUpdateVertex ( const Element &element, DataBase &db )
{
//typedef typename Element::Geometry::GlobalCoordinate GlobalCoordinate;
const int index = indexSet_.index( element );
const int wght = weight( element );
......@@ -115,23 +110,17 @@ namespace Dune
void updateFaces ( const Element &element, const int elementId, const int weight, DataBase &db )
{
typedef typename GridView::IntersectionIterator IntersectionIterator;
typedef typename GridView::Intersection Intersection;
const IntersectionIterator iend = gridView().iend( element );
for( IntersectionIterator iit = gridView().ibegin( element ); iit != iend; ++iit )
for(const auto& intersection : intersections(gridView(), element))
{
const Intersection &intersection = *iit;
if( !intersection.neighbor() )
continue;
const Element &outside = intersection.outside();
const auto& outside = intersection.outside();
if( outside.partitionType() == InteriorEntity )
{
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
double mean = std::accumulate( v.begin(), v.end(), 0.0 ) / double( np );
bool unbalanced = false;
for( typename std::vector< double >::iterator it = v.begin(); it != v.end(); ++it )
unbalanced |= (*it > mean ? (*it > ldbOver_*mean) : (*it < ldbUnder_*mean));
for( const double load : v )
unbalanced |= (load > mean ? (load > ldbOver_*mean) : (load < ldbUnder_*mean));
#ifndef NDEBUG
// make sure all processes have come to the same conclusion
int local = int( unbalanced );
......
......@@ -6,11 +6,11 @@
#include <map>
#include <string>
#include <vector>
#include <memory>
//- dune-common includes
#include <dune/common/version.hh>
#include <dune/common/parallel/mpihelper.hh>
#include <dune/common/smartptr.hh>
//- dune-geometry includes
#if HAVE_DUNE_ALUGRID
......@@ -31,7 +31,6 @@ namespace Dune
// -------------
class PartitionInfo
: public ReferenceCountable
{
typedef PartitionInfo This;
......@@ -106,7 +105,7 @@ namespace Dune
typedef std::map< IdType, int > RankMapType;
public:
typedef PersistentContainer< HostGrid, SmartPtr< PartitionInfo > > PartitionInfoStorage;
typedef PersistentContainer< HostGrid, std::shared_ptr< PartitionInfo > > PartitionInfoStorage;
typedef ALU3DSPACE ObjectStream ObjectStream;
......@@ -143,7 +142,7 @@ namespace Dune
Partitioner partitioner_;
MacroDecomposition macroDecomposition_;
SmartPtr< PartitionInfo > interiorPartitionInfo_;
std::shared_ptr< PartitionInfo > interiorPartitionInfo_;
PartitionInfoStorageArray partitionInfoStorage_;
template < int codim >
......@@ -318,7 +317,7 @@ namespace Dune
{
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 )
{
const auto& pEntity = helement.template subEntity< codim >( i );
......@@ -336,7 +335,7 @@ namespace Dune
{
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 )
{
const auto& pEntity = helement.template subEntity< codim >( i );
......@@ -389,8 +388,8 @@ namespace Dune
#endif
}
void setPartitionType ( SmartPtr< PartitionInfo > &pInfo, PartitionType ptype );
void setConnectivity ( SmartPtr< PartitionInfo > &pInfo, int otherRank, PartitionType ptype );
void setPartitionType ( std::shared_ptr< PartitionInfo > &pInfo, PartitionType ptype );
void setConnectivity ( std::shared_ptr< PartitionInfo > &pInfo, int otherRank, PartitionType ptype );
void insertAllSubEntities ( const HostElement &hostElement, PartitionType ptype, int rank );
void insertConnectivity ( const HostElement &hostElement, const PartitionType ptype,
......@@ -429,7 +428,11 @@ namespace Dune
interiorPartitionInfo_( new PartitionInfo( InteriorEntity ) )
{
// 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();
}
......@@ -480,24 +483,24 @@ namespace Dune
}
template< class Grid >
inline void ParallelGridRankManager< Grid >
::setPartitionType ( SmartPtr< PartitionInfo > &pInfo, PartitionType ptype )
::setPartitionType ( std::shared_ptr< PartitionInfo > &pInfo, PartitionType ptype )
{
if( pInfo && (pInfo != interiorPartitionInfo_) )
pInfo->setPartitionType( ptype );
else if( ptype == InteriorEntity )
pInfo = interiorPartitionInfo_;
else
pInfo = SmartPtr< PartitionInfo >( new PartitionInfo( ptype ) );
pInfo = std::shared_ptr< PartitionInfo >( new PartitionInfo( ptype ) );
}
template< class 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 );
if( pInfo == interiorPartitionInfo_ )
pInfo = SmartPtr< PartitionInfo >( new PartitionInfo( InteriorEntity ) );
pInfo = std::shared_ptr< PartitionInfo >( new PartitionInfo( InteriorEntity ) );
pInfo->setConnectivity( otherRank, ptype );
}
......@@ -506,7 +509,7 @@ namespace Dune
inline void ParallelGridRankManager< Grid >
::insertAllSubEntities ( const HostElement &hostElement, PartitionType ptype, int rank )
{
auto refElement = Dune::referenceElement<ctype,dimension>( hostElement.type() );
const auto refElement = referenceElement(hostElement);
assert( rank == myRank_ );
......@@ -539,7 +542,7 @@ namespace Dune
if( codimAvailable< 1 >() )
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 )
{
if( codimAvailable( codim ) )
......@@ -731,7 +734,11 @@ namespace Dune
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;
......@@ -739,7 +746,11 @@ namespace Dune
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
......@@ -781,7 +792,11 @@ namespace Dune
sync.ensure( buffer[ link ], size );
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;
......@@ -789,7 +804,11 @@ namespace Dune
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 ] );
......
......@@ -7,23 +7,23 @@ set(METAGRIDS 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-cartesiangrid test-idgrid test-parallelgrid )
set(TESTS test-cartesiangrid test-idgrid )
foreach(_executable ${TESTS})
dune_add_test(NAME ${_executable} SOURCES ${_executable}.cc)
set_property(TARGET ${_executable} APPEND PROPERTY COMPILE_DEFINITIONS
"GRIDDIM=${GRIDDIM}" "WORLDDIM=${WORLDDIM}" "${GRIDTYPE}")
set_property(TARGET ${_executable} APPEND PROPERTY COMPILE_DEFINITIONS "METAGRIDS=${METAGRIDS}")
# dune_target_enable_all_packages( ${_executable} )
endforeach(_executable ${TESTS})
endforeach()
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")
#add_directory_test_target(test_target)
# add_dependencies(${test_target} ${TESTS})
dune_add_test(NAME test-parallelgrid
SOURCES test-parallelgrid.cc
CMAKE_GUARD dune-alugrid_FOUND
COMPILE_DEFINITIONS "GRIDDIM=${GRIDDIM}" "WORLDDIM=${WORLDDIM}" "${GRIDTYPE}" "METAGRIDS=${METAGRIDS}"
CMD_ARGS 2dcube.dgf)
set(DGFS
1dcube.dgf 2dcube.dgf 3dcube.dgf cubedsphere2d.dgf octahedron.dgf
......
......@@ -26,27 +26,16 @@ using namespace Dune;
template <bool leafconform, class 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");
static_assert( Dune::Capabilities::isLeafwiseConforming< Grid > :: v == leafconform,
static_assert( Dune::Capabilities::isLeafwiseConforming<Grid>::v == leafconform,
"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,
"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");
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 =
#if ALU3DGRID_PARALLEL && ALU2DGRID_PARALLEL
true ;
......@@ -55,33 +44,30 @@ void checkCapabilities(const Grid& grid)
#else
false ;
#endif
static const bool canCommunicate = Dune::Capabilities::canCommunicate< Grid, 1 > :: v
== reallyCanCommunicate;
static_assert( canCommunicate,
"canCommunicate is not set correctly");
static const bool canCommunicate
= Dune::Capabilities::canCommunicate<Grid, 1>::v == reallyCanCommunicate;
static_assert( canCommunicate, "canCommunicate is not set correctly");
}
template <class GridType>
void makeNonConfGrid(GridType &grid,int level,int adapt) {
void makeNonConformingGrid(GridType& grid, int level, int adapt)
{
int myrank = grid.comm().rank();
grid.loadBalance();
grid.globalRefine(level);
grid.loadBalance();
for (int i=0;i<adapt;i++)
for (int i=0; i<adapt; i++)
{
if (myrank==0)
{
typedef typename GridType :: template Codim<0> ::
template Partition<Interior_Partition> :: LeafIterator LeafIterator;
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++ )
std::size_t numberOfRefinedElements = 0;
const auto size = grid.leafGridView().size(0);
for(const auto& element : elements(grid.leafGridView()))
{
grid.mark(1, *it );
if (nr>size*0.8) break;
grid.mark(1, element);
if (numberOfRefinedElements > size*0.8)
break;
numberOfRefinedElements++;
}
}
grid.adapt();
......@@ -91,60 +77,60 @@ void makeNonConfGrid(GridType &grid,int level,int adapt) {
}
template <class GridView>
void writeFile( const GridView& gridView )
void writeFile(const GridView& gridView)
{
DGFWriter< GridView > writer( gridView );
writer.write( "dump.dgf" );
}
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
std::cout << " CHECKING: Macro" << std::endl;
//gridcheck(grid);
gridcheck(grid);
std::cout << " CHECKING: Macro-intersections" << std::endl;
//checkIntersectionIterator(grid);
checkIntersectionIterator(grid);
for(int i=0; i<mxl; i++)
{
grid.globalRefine( 1 );//DGFGridInfo<GridType> :: refineStepsForHalf() );
std::cout << " CHECKING: Refined" << std::endl;
//gridcheck(grid);
gridcheck(grid);
std::cout << " CHECKING: intersections" << std::endl;
//checkIntersectionIterator(grid);
checkIntersectionIterator(grid);
}
// check also non-conform grids
//makeNonConfGrid(grid,0,1);
makeNonConformingGrid(grid,0,1);
//std::cout << " CHECKING: non-conform" << std::endl;
//gridcheck(grid);
gridcheck(grid);
// check the method geometryInFather()
//std::cout << " CHECKING: geometry in father" << std::endl;
//checkGeometryInFather(grid);
std::cout << " CHECKING: geometry in father" << std::endl;
checkGeometryInFather(grid);
// check the intersection iterator and the geometries it returns
//std::cout << " CHECKING: intersections" << std::endl;
//checkIntersectionIterator(grid);
std::cout << " CHECKING: intersections" << std::endl;
checkIntersectionIterator(grid);
std::cout << std::endl << std::endl;
}
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;
#if HAVE_MPI
//makeNonConfGrid(grid,gref,mxl);
//makeNonConformingGrid(grid,gref,mxl);
// -1 stands for leaf check
checkCommunication(grid, -1, std::cout);
const int maxLevel = std::min( mxl, grid.maxLevel() );
for(int l=0; l<= maxLevel; ++l)
checkCommunication(grid, l , Dune::dvverb);
checkCommunication(grid, l, Dune::dvverb);
#endif
}
......@@ -153,61 +139,45 @@ int main (int argc , char **argv)
{
// this method calls MPI_Init, if MPI is enabled
MPIHelper & mpihelper = MPIHelper::instance(argc,argv);
int myrank = mpihelper.rank();
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 );
auto& mpiHelper = MPIHelper::instance(argc,argv);
const int myrank = mpiHelper.rank();
const int mysize = mpiHelper.size();
typedef ParallelGrid< HostGridType > ParallelGridType;
ParallelGridType grid( *hostGrid );
grid.loadBalance();
std::cout << "P["<<myrank<<"] size = "<< grid.size( 0 ) << std::endl;
/* use grid-file appropriate for dimensions */
if( argc < 2 )
{
std::cerr << "Usage: " << argv[0] << " <dgf file of hostgrid>" << std::endl;
return 1;
}
{
std::cout << "Check serial grid" << std::endl;
checkSerial(grid,
(mysize == 1) ? 1 : 0,
(mysize == 1) ? display: false);
}
using HostGridType = Dune::GridSelector::GridType;
std::string filename( argv[1] );
GridPtr< HostGridType > hostGrid( filename );
// perform parallel check only when more then one proc
if(mysize > 1)
{
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 );
}
using ParallelGridType = ParallelGrid<HostGridType>;
ParallelGridType grid( *hostGrid );
Dune :: VTKWriter<ParallelGridType :: LeafGridView> vtkWriter(grid.leafGridView());
vtkWriter.write( "paragrid.out" );
grid.loadBalance();
std::cout << "P["<<myrank<<"] size = "<< grid.size( 0 ) << std::endl;
}
catch (Dune::Exception &e)
{
std::cerr << e << std::endl;
return 1;
std::cout << "Check serial grid" << std::endl;
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;
return 2;
if (myrank == 0) std::cout << "Check conform grid" << std::endl;
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;
}