Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PolyhedralGrid: use MPIHelper's default communicator for CollectiveCommunication. #431

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions opm/grid/cpgrid/Entity.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
#include <dune/common/version.hh>
#include <dune/geometry/type.hh>
#include <dune/grid/common/gridenums.hh>
#include <dune/grid/common/entity.hh>

#include "PartitionTypeIndicator.hpp"
#include "EntityRep.hpp"
Expand Down Expand Up @@ -332,6 +333,13 @@ namespace Dune
}
};
} // namespace cpgrid

#if DUNE_VERSION_NEWER(DUNE_GRID, 2, 7)
template <int codim>
auto referenceElement(const Dune::cpgrid::Entity<codim>& entity) -> decltype(referenceElement<double, 3>(entity.type()))
{ return referenceElement<double, 3>(entity.type()); }
#endif

} // namespace Dune

// now we include the Iterators.hh We need to do this here because for hbegin/hend the compiler
Expand Down
74 changes: 34 additions & 40 deletions opm/grid/polyhedralgrid/geometry.hh
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,10 @@ namespace Dune
// host geometry object
EntitySeed seed_;

GeometryType type_;

Storage( ExtraData data, EntitySeed seed )
: data_( data ), seed_( seed )
: data_( data ), seed_( seed ), type_( data->geometryType( seed ) )
{}

Storage( ExtraData data )
Expand All @@ -95,6 +97,9 @@ namespace Dune
ctype volume() const { return data()->volumes( seed_ ); }

const EntitySeed& seed () const { return seed_; }
const GeometryType& type () const { return type_; }

bool hasGeometry () const { return (! type_.isNone()) && isValid(); }
};

template <int mdim, int cordim>
Expand Down Expand Up @@ -130,41 +135,23 @@ namespace Dune
PolyhedralGridBasicGeometry ( ExtraData data, const EntitySeed& seed )
: storage_( data, seed )
{
GeometryType myType = type();
if( ! myType.isNone() && storage_.isValid() )
{
geometryImpl_.reset( new MultiLinearGeometryType(myType, storage_) );
}
//std::cout << myType << " " << storage_.corners() << std::endl;
}

GeometryType type () const { return data()->geometryType( storage_.seed() ); }
GeometryType type () const { return storage_.type(); }
bool affine () const { return (geometryImpl_) ? geometryImpl_->affine() : false; }

int corners () const { return storage_.corners(); }
GlobalCoordinate corner ( const int i ) const { return storage_.corner( i ); }
GlobalCoordinate center () const
{
if( type().isNone() )
{
return storage_.center();
}
else
{
#if DUNE_VERSION_NEWER(DUNE_GRID,2,7)
const auto refElem = Dune::referenceElement< ctype, mydim > ( type() );
#else
const auto& refElem = Dune::ReferenceElements< ctype, mydim >::general( type() );
#endif
return global( refElem.position(0,0) );
}
return storage_.center();
}

GlobalCoordinate global(const LocalCoordinate& local) const
{
if( geometryImpl_ )
if( storage_.hasGeometry() )
{
return geometryImpl_->global( local );
return geometryImpl().global( local );
}

return center();
Expand All @@ -174,9 +161,9 @@ namespace Dune
/// May be slow.
LocalCoordinate local(const GlobalCoordinate& global) const
{
if( geometryImpl_ )
if( storage_.hasGeometry() )
{
return geometryImpl_->local( global );
return geometryImpl().local( global );
}

// if no geometry type return a vector filled with 1
Expand All @@ -185,28 +172,24 @@ namespace Dune

ctype integrationElement ( const LocalCoordinate &local ) const
{
if( geometryImpl_ )
if( storage_.hasGeometry() )
{
return geometryImpl_->integrationElement( local );
return geometryImpl().integrationElement( local );
}
return volume();
}

ctype volume () const
{
if( geometryImpl_ )
{
return geometryImpl_->volume();
}
return storage_.volume();
}

#if DUNE_VERSION_NEWER(DUNE_GRID,2,4)
JacobianTransposed jacobianTransposed ( const LocalCoordinate & local ) const
{
if( geometryImpl_ )
if( storage_.hasGeometry() )
{
return geometryImpl_->jacobianTransposed( local );
return geometryImpl().jacobianTransposed( local );
}

DUNE_THROW(NotImplemented,"jacobianTransposed not implemented");
Expand All @@ -215,9 +198,9 @@ namespace Dune

JacobianInverseTransposed jacobianInverseTransposed ( const LocalCoordinate & local ) const
{
if( geometryImpl_ )
if( storage_.hasGeometry() )
{
return geometryImpl_->jacobianInverseTransposed( local );
return geometryImpl().jacobianInverseTransposed( local );
}

DUNE_THROW(NotImplemented,"jacobianInverseTransposed not implemented");
Expand All @@ -226,9 +209,9 @@ namespace Dune
#else
const JacobianTransposed& jacobianTransposed ( const LocalCoordinate &local ) const
{
if( geometryImpl_ )
if( storage_.hasGeometry() )
{
return geometryImpl_->jacobianTransposed( local );
return geometryImpl().jacobianTransposed( local );
}

DUNE_THROW(NotImplemented,"jacobianTransposed not implemented");
Expand All @@ -238,9 +221,9 @@ namespace Dune

const JacobianInverseTransposed& jacobianInverseTransposed ( const LocalCoordinate &local ) const
{
if( geometryImpl_ )
if( storage_.hasGeometry() )
{
return geometryImpl_->jacobianInverseTransposed( local );
return geometryImpl().jacobianInverseTransposed( local );
}

DUNE_THROW(NotImplemented,"jacobianInverseTransposed not implemented");
Expand All @@ -252,8 +235,19 @@ namespace Dune
ExtraData data() const { return storage_.data(); }

protected:
const MultiLinearGeometryType& geometryImpl() const
{
assert( storage_.hasGeometry() );
if( ! geometryImpl_ )
{
geometryImpl_.reset( new MultiLinearGeometryType(storage_.type(), storage_) );
}

return *geometryImpl_;
}

CornerStorageType storage_;
std::shared_ptr< MultiLinearGeometryType > geometryImpl_;
mutable std::shared_ptr< MultiLinearGeometryType > geometryImpl_;
};


Expand Down
21 changes: 14 additions & 7 deletions opm/grid/polyhedralgrid/grid.hh
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
//- dune-grid includes
#include <dune/grid/common/grid.hh>
#include <dune/common/parallel/collectivecommunication.hh>
#include <dune/common/parallel/mpicollectivecommunication.hh>
#include <dune/common/parallel/mpihelper.hh>

//- polyhedralgrid includes
#include <opm/grid/polyhedralgrid/capabilities.hh>
Expand Down Expand Up @@ -120,7 +122,7 @@ namespace Dune
typedef PolyhedralGridIdSet< dim, dimworld, ctype > GlobalIdSet;
typedef GlobalIdSet LocalIdSet;

typedef Dune::CollectiveCommunication< Grid > CollectiveCommunication;
typedef Dune::CollectiveCommunication< Dune::MPIHelper::MPICommunicator > CollectiveCommunication;

template< PartitionIteratorType pitype >
struct Partition
Expand Down Expand Up @@ -323,7 +325,7 @@ namespace Dune
const std::vector<double>& poreVolumes = std::vector<double> ())
: gridPtr_( createGrid( deck, poreVolumes ) ),
grid_( *gridPtr_ ),
comm_( *this ),
comm_( Dune::MPIHelper::getCommunicator() ),
leafIndexSet_( *this ),
globalIdSet_( *this ),
localIdSet_( *this ),
Expand All @@ -342,7 +344,7 @@ namespace Dune
const std::vector< double >& dx )
: gridPtr_( createGrid( n, dx ) ),
grid_( *gridPtr_ ),
comm_( *this ),
comm_( Dune::MPIHelper::getCommunicator() ),
leafIndexSet_( *this ),
globalIdSet_( *this ),
localIdSet_( *this ),
Expand All @@ -360,7 +362,7 @@ namespace Dune
explicit PolyhedralGrid ( UnstructuredGridPtr &&gridPtr )
: gridPtr_( std::move( gridPtr ) ),
grid_( *gridPtr_ ),
comm_( *this ),
comm_( Dune::MPIHelper::getCommunicator() ),
leafIndexSet_( *this ),
globalIdSet_( *this ),
localIdSet_( *this ),
Expand All @@ -379,7 +381,7 @@ namespace Dune
explicit PolyhedralGrid ( const UnstructuredGridType& grid )
: gridPtr_(),
grid_( grid ),
comm_( *this ),
comm_( Dune::MPIHelper::getCommunicator() ),
leafIndexSet_( *this ),
globalIdSet_( *this ),
localIdSet_( *this ),
Expand Down Expand Up @@ -675,8 +677,8 @@ namespace Dune
* \param[in] direction communication direction (one of
* ForwardCommunication, BackwardCommunication)
*/
template< class DataHandle, class Data >
void communicate ( CommDataHandleIF< DataHandle, Data >& /* dataHandle */,
template< class DataHandle >
void communicate ( DataHandle& /* dataHandle */,
InterfaceType /* interface */,
CommunicationDirection /* direction */ ) const
{
Expand All @@ -698,6 +700,11 @@ namespace Dune

// data handle interface different between geo and interface

template< class DataHandle >
void scatterData ( DataHandle& /* datahandle */ ) const
{
}

/** \brief rebalance the load each process has to handle
*
* A parallel grid is redistributed such that each process has about
Expand Down