Commit 6c3f2da0 authored by Praetorius, Simon's avatar Praetorius, Simon
Browse files

added dune grid standard tests

parent c5ca3dd5
......@@ -24,64 +24,64 @@ namespace Dune
using Traits = typename std::remove_const_t<Grid>::Traits;
public:
CommDataHandle ( const Grid &grid, WrappedHandle &handle )
: grid_( grid ),
wrappedHandle_( handle )
CommDataHandle (const Grid& grid, WrappedHandle& handle)
: grid_(grid)
, wrappedHandle_(handle)
{}
bool contains ( int dim, int codim ) const
bool contains (int dim, int codim) const
{
const bool contains = wrappedHandle_.contains( dim, codim );
if( contains )
assertHostEntity( dim, codim );
const bool contains = wrappedHandle_.contains(dim, codim);
if (contains)
assertHostEntity(dim, codim);
return contains;
}
bool fixedSize ( int dim, int codim ) const
bool fixedSize (int dim, int codim) const
{
return wrappedHandle_.fixedSize( dim, codim );
return wrappedHandle_.fixedSize(dim, codim);
}
template< class HostEntity >
size_t size ( const HostEntity &hostEntity ) const
std::size_t size (const HostEntity& hostEntity) const
{
typedef typename Grid::Traits::template Codim< HostEntity::codimension >::Entity Entity;
typedef typename Grid::Traits::template Codim< HostEntity::codimension >::EntityImpl EntityImpl;
Entity entity( EntityImpl( grid_, hostEntity ) );
return wrappedHandle_.size( entity );
using Entity = typename Grid::Traits::template Codim<HostEntity::codimension>::Entity;
using EntityImpl = typename Grid::Traits::template Codim<HostEntity::codimension>::EntityImpl;
Entity entity(EntityImpl(grid_, hostEntity));
return wrappedHandle_.size(entity);
}
template< class MessageBuffer, class HostEntity >
void gather ( MessageBuffer &buffer, const HostEntity &hostEntity ) const
void gather (MessageBuffer& buffer, const HostEntity& hostEntity) const
{
typedef typename Grid::Traits::template Codim< HostEntity::codimension >::Entity Entity;
typedef typename Grid::Traits::template Codim< HostEntity::codimension >::EntityImpl EntityImpl;
Entity entity( EntityImpl( grid_, hostEntity ) );
wrappedHandle_.gather( buffer, entity );
using Entity = typename Grid::Traits::template Codim<HostEntity::codimension>::Entity;
using EntityImpl = typename Grid::Traits::template Codim<HostEntity::codimension>::EntityImpl;
Entity entity(EntityImpl(grid_, hostEntity));
wrappedHandle_.gather(buffer, entity);
}
template< class MessageBuffer, class HostEntity >
void scatter ( MessageBuffer &buffer, const HostEntity &hostEntity, size_t size )
void scatter (MessageBuffer& buffer, const HostEntity& hostEntity, std::size_t size)
{
typedef typename Grid::Traits::template Codim< HostEntity::codimension >::Entity Entity;
typedef typename Grid::Traits::template Codim< HostEntity::codimension >::EntityImpl EntityImpl;
Entity entity( EntityImpl( grid_, hostEntity ) );
wrappedHandle_.scatter( buffer, entity, size );
using Entity = typename Grid::Traits::template Codim< HostEntity::codimension >::Entity;
using EntityImpl = typename Grid::Traits::template Codim< HostEntity::codimension >::EntityImpl;
Entity entity(EntityImpl(grid_, hostEntity));
wrappedHandle_.scatter(buffer, entity, size);
}
private:
static void assertHostEntity ( int dim, int codim )
static void assertHostEntity (int dim, int codim)
{
if( !Capabilities::CodimCache< Grid >::hasHostEntity( codim ) )
DUNE_THROW( NotImplemented, "Host grid has no entities for codimension " << codim << "." );
if (!Capabilities::CodimCache<Grid>::hasHostEntity(codim))
DUNE_THROW(NotImplemented, "Host grid has no entities for codimension " << codim << ".");
}
const Grid &grid_;
WrappedHandle &wrappedHandle_;
private:
const Grid& grid_;
WrappedHandle& wrappedHandle_;
};
} // namespace CGeo
} // namespace Dune
#endif // DUNE_CURVED_SURFACE_GRID_DATAHANDLE_HH
......@@ -135,20 +135,6 @@ namespace Dune
, grid_(&grid)
{}
// construct the entity from a host-entity and a transformed geometry
EntityBase (const GeometryImpl& geo, const HostEntity& hostEntity)
: hostEntity_(hostEntity)
, grid_(&geo.grid())
, geo_(geo)
{}
// construct the entity from a host-entity and a transformed geometry
EntityBase (const GeometryImpl& geo, HostEntity&& hostEntity)
: hostEntity_(std::move(hostEntity))
, grid_(&geo.grid())
, geo_(geo)
{}
// construct the entity from a host-entity
EntityBase (const Grid& grid, const HostEntity& hostEntity)
: hostEntity_(hostEntity)
......@@ -194,14 +180,6 @@ namespace Dune
return hostEntity().partitionType();
}
GeometryImpl makeGeometry () const
{
auto ff = [f=grid().coordFunction(),geo=hostEntity().geometry()](const auto& local) {
return f(geo.global(local));
};
return GeometryImpl(type(), ff);
}
//! obtain the geometry of this entity
/**
* Each DUNE entity encapsulates a geometry object, representing the map
......@@ -216,23 +194,22 @@ namespace Dune
Geometry geometry () const
{
if (!geo_) {
if (grid_->useGeometryCaching())
{
// mapping from local to curved global coordinates
auto ff = [f=grid().coordFunction(),geo=hostEntity().geometry()](const auto& local) {
return f(geo.global(local));
};
if (grid_->useGeometryCaching()) {
auto const& idSet = grid_->hostGrid().localIdSet();
auto& cached_geo = std::get<codim>(grid_->geometryCache_)[id(idSet)];
// if geometry is already in cache
if (cached_geo)
geo_ = *cached_geo;
// otherwise cache a new constructed geometry
else {
geo_ = makeGeometry();
*cached_geo = *geo_;
}
auto id = idSet.id(hostEntity());
auto& cache = std::get<codim>(grid_->geometryCache_);
auto [it,inserted] = cache.try_emplace(id, type(), ff);
geo_ = it->second;
}
else
{
geo_ = makeGeometry();
else {
geo_ = GeometryImpl(type(), ff);
}
}
......@@ -242,7 +219,7 @@ namespace Dune
//! obtain number of sub-entities of the current entity
unsigned int subEntities (unsigned int cc) const
{
return hostEntity().subEntities( cc );
return hostEntity().subEntities(cc);
}
//! return EntitySeed of host grid entity
......@@ -269,71 +246,6 @@ namespace Dune
return hostEntity_;
}
//! initiliaze an entity by a corresponding host-entity
/**
* \param[in] hostEntity reference to the host entity
*/
void initialize (const HostEntity& hostEntity)
{
hostEntity_ = hostEntity;
}
//! obtain the entity's index from a host IndexSet
/**
* \internal This method is provided by the entity, because its
* implementation is different for fake and non-fake entities.
*
* \param[in] indexSet host IndexSet to use
*/
template< class HostIndexSet >
typename HostIndexSet::IndexType
index (const HostIndexSet& indexSet) const
{
return indexSet.template index<codimension>(hostEntity());
}
//! obtain the index of a subentity from a host IndexSet
/**
* \internal This method is provided by the entity, because its
* implementation is different for fake and non-fake entities.
*
* \param[in] indexSet host IndexSet to use
* \param[in] i number of the subentity
* \param[in] cd codimension of the subentity
*/
template< class HostIndexSet >
typename HostIndexSet::IndexType
subIndex (const HostIndexSet& indexSet, int i, unsigned int cd) const
{
return indexSet.subIndex(hostEntity(), i, cd);
}
//! check whether the entity is contained in a host index set
/**
* \internal This method is provided by the entity, because its
* implementation is different for fake and non-fake entities.
*
* \param indexSet host IndexSet to use
*/
template< class HostIndexSet >
bool isContained (const HostIndexSet& indexSet) const
{
return indexSet.contains(hostEntity());
}
//! obtain the entity's id from a host IdSet
/**
* \internal This method is provided by the entity, because its
* implementation is different for fake and non-fake entities.
*
* \param idSet host IdSet to use
*/
template< class HostIdSet >
typename HostIdSet::IdType id (const HostIdSet& idSet) const
{
return idSet.template id<codimension>(hostEntity());
}
/** \} */
private:
......@@ -404,26 +316,26 @@ namespace Dune
LevelIntersectionIterator ilevelbegin () const
{
using LevelIntersectionIteratorImpl = CGeo::IntersectionIterator<Grid, typename HostGrid::LevelIntersectionIterator>;
return LevelIntersectionIteratorImpl(*this, Super::hostEntity().ilevelbegin());
using IteratorImpl = CGeo::IntersectionIterator<Grid, typename HostGrid::LevelIntersectionIterator>;
return IteratorImpl(*this, Super::hostEntity().ilevelbegin());
}
LevelIntersectionIterator ilevelend () const
{
using LevelIntersectionIteratorImpl = CGeo::IntersectionIterator<Grid, typename HostGrid::LevelIntersectionIterator>;
return LevelIntersectionIteratorImpl(*this, Super::hostEntity().ilevelend());
using IteratorImpl = CGeo::IntersectionIterator<Grid, typename HostGrid::LevelIntersectionIterator>;
return IteratorImpl(*this, Super::hostEntity().ilevelend());
}
LeafIntersectionIterator ileafbegin () const
{
using LeafIntersectionIteratorImpl = CGeo::IntersectionIterator<Grid, typename HostGrid::LeafIntersectionIterator>;
return LeafIntersectionIteratorImpl(*this, Super::hostEntity().ileafbegin());
using IteratorImpl = CGeo::IntersectionIterator<Grid, typename HostGrid::LeafIntersectionIterator>;
return IteratorImpl(*this, Super::hostEntity().ileafbegin());
}
LeafIntersectionIterator ileafend () const
{
using LeafIntersectionIteratorImpl = CGeo::IntersectionIterator<Grid, typename HostGrid::LeafIntersectionIterator>;
return LeafIntersectionIteratorImpl(*this, Super::hostEntity().ileafend());
using IteratorImpl = CGeo::IntersectionIterator<Grid, typename HostGrid::LeafIntersectionIterator>;
return IteratorImpl(*this, Super::hostEntity().ileafend());
}
bool hasBoundaryIntersections () const
......@@ -453,14 +365,14 @@ namespace Dune
HierarchicIterator hbegin (int maxLevel) const
{
using HierarchicIteratorImpl = CGeo::HierarchicIterator<Grid>;
return HierarchicIteratorImpl(Super::grid(), Super::hostEntity().hbegin(maxLevel));
using IteratorImpl = CGeo::HierarchicIterator<Grid>;
return IteratorImpl(Super::grid(), Super::hostEntity().hbegin(maxLevel));
}
HierarchicIterator hend (int maxLevel) const
{
using HierarchicIteratorImpl = CGeo::HierarchicIterator<Grid>;
return HierarchicIteratorImpl(Super::grid(), Super::hostEntity().hend(maxLevel));
using IteratorImpl = CGeo::HierarchicIterator<Grid>;
return IteratorImpl(Super::grid(), Super::hostEntity().hend(maxLevel));
}
bool isRegular () const
......@@ -480,7 +392,6 @@ namespace Dune
};
} // namespace CGeo
} // namespace Dune
#endif // DUNE_CURVED_SURFACE_GRID_ENTITY_HH
......@@ -47,20 +47,22 @@ namespace Dune
};
\endcode
*
* \tparam HostGrid DUNE grid to be wrapped (called host grid)
* \tparam HG DUNE grid to be wrapped (called host grid)
* \tparam CoordFunction coordinate function
* \tparam lagrangeOrder Polynomial order of local lagrange basis function in geometry
* parametrization
*
* \nosubgrouping
*/
template< class HostGrid, class CoordFunction, int lagrangeOrder, class Allocator = std::allocator<void> >
template< class HG, class CoordFunction, int lagrangeOrder, class Allocator = std::allocator<void> >
class CurvedSurfaceGrid
: public GridDefaultImplementation<HostGrid::dimension, CoordFunction::dimRange, typename HostGrid::ctype,
CGeo::GridFamily<HostGrid, CoordFunction, lagrangeOrder, Allocator> >
, public CGeo::BackupRestoreFacilities<CurvedSurfaceGrid<HostGrid, CoordFunction, lagrangeOrder, Allocator> >
: public GridDefaultImplementation<HG::dimension, CoordFunction::dimRange, typename HG::ctype,
CGeo::GridFamily<HG, CoordFunction, lagrangeOrder, Allocator> >
, public CGeo::BackupRestoreFacilities<CurvedSurfaceGrid<HG, CoordFunction, lagrangeOrder, Allocator> >
{
using Self = CurvedSurfaceGrid;
using Super = GridDefaultImplementation<HostGrid::dimension, CoordFunction::dimRange, typename HostGrid::ctype,
CGeo::GridFamily<HostGrid, CoordFunction, lagrangeOrder, Allocator> >;
using Super = GridDefaultImplementation<HG::dimension, CoordFunction::dimRange, typename HG::ctype,
CGeo::GridFamily<HG, CoordFunction, lagrangeOrder, Allocator> >;
// friend declarations
friend class CGeo::HierarchicIterator<const Self>;
......@@ -74,7 +76,9 @@ namespace Dune
template< class, class > friend class CGeo::CommDataHandle;
public:
using GridFamily = CGeo::GridFamily<HostGrid, CoordFunction, lagrangeOrder, Allocator>;
using GridFamily = CGeo::GridFamily<HG, CoordFunction, lagrangeOrder, Allocator>;
using HostGrid = HG;
/** \name Traits
* \{ */
......@@ -221,21 +225,16 @@ namespace Dune
: hostGrid_(std::move(hostGrid))
, coordFunction_(wrap_or_move(std::forward<Param>(param)))
, levelIndexSets_(hostGrid_->maxLevel()+1, nullptr, allocator)
, storageAllocator_(allocator)
{}
//! destructor
~CurvedSurfaceGrid ()
{
for(auto &mapEntry : std::get<0>(geometryCache_)) delete mapEntry.second;
for(auto &mapEntry : std::get<1>(geometryCache_)) delete mapEntry.second;
for(auto &mapEntry : std::get<2>(geometryCache_)) delete mapEntry.second;
for( unsigned int i = 0; i < levelIndexSets_.size(); ++i )
for (unsigned int i = 0; i < levelIndexSets_.size(); ++i)
{
if( levelIndexSets_[ i ] )
delete( levelIndexSets_[ i ] );
if (levelIndexSets_[i])
delete (levelIndexSets_[i]);
}
}
......@@ -304,7 +303,7 @@ namespace Dune
/**
* \returns number of boundary segments within the macro grid
*/
size_t numBoundarySegments () const
std::size_t numBoundarySegments () const
{
return hostGrid().numBoundarySegments();
}
......@@ -543,16 +542,6 @@ namespace Dune
return entity.impl().hostEntity();
}
void *allocateStorage (std::size_t size) const
{
return storageAllocator_.allocate( size );
}
void deallocateStorage (void *p, std::size_t size) const
{
storageAllocator_.deallocate( (char *)p, size );
}
private:
std::shared_ptr<HostGrid> hostGrid_;
std::shared_ptr<CoordFunction> coordFunction_;
......@@ -563,7 +552,6 @@ namespace Dune
mutable LeafIndexSet leafIndexSet_;
mutable GlobalIdSet globalIdSet_;
mutable LocalIdSet localIdSet_;
mutable typename Allocator::template rebind<char>::other storageAllocator_;
private:
template <class Indices>
......@@ -575,7 +563,7 @@ namespace Dune
using type = std::tuple<
std::map<
typename HostGrid::Traits::LocalIdSet::IdType,
typename Traits::template Codim<codims>::GeometryImpl*
typename Traits::template Codim<codims>::GeometryImpl
>...
>;
};
......
......@@ -8,7 +8,6 @@
#include <dune/curvedsurfacegrid/capabilities.hh>
#include <dune/curvedsurfacegrid/entity.hh>
#include <dune/curvedsurfacegrid/entityseed.hh>
//#include <dune/curvedsurfacegrid/geometry.hh>
#include <dune/curvedsurfacegrid/gridview.hh>
#include <dune/curvedsurfacegrid/intersection.hh>
#include <dune/curvedsurfacegrid/intersectioniterator.hh>
......@@ -41,15 +40,18 @@ namespace Dune
static const int dimension = HostGrid::dimension;
static const int dimensionworld = CoordFunction::dimRange;
using LeafIntersection = Dune::Intersection<const Grid, CGeo::Intersection<const Grid, typename HostGrid::LeafIntersection> >;
using LevelIntersection = Dune::Intersection<const Grid, CGeo::Intersection<const Grid, typename HostGrid::LevelIntersection> >;
using LeafIntersection
= Dune::Intersection<const Grid, CGeo::Intersection<const Grid, typename HostGrid::LeafIntersection>>;
using LevelIntersection
= Dune::Intersection<const Grid, CGeo::Intersection<const Grid, typename HostGrid::LevelIntersection>>;
using LeafIntersectionIterator
= Dune::IntersectionIterator<const Grid, CGeo::IntersectionIterator<const Grid, typename HostGrid::LeafIntersectionIterator>, CGeo::Intersection<const Grid, typename HostGrid::LeafIntersection> >;
using LevelIntersectionIterator
= Dune::IntersectionIterator<const Grid, CGeo::IntersectionIterator<const Grid, typename HostGrid::LevelIntersectionIterator >, CGeo::Intersection<const Grid, typename HostGrid::LevelIntersection> >;
using HierarchicIterator = Dune::EntityIterator<0, const Grid, CGeo::HierarchicIterator<const Grid> >;
using HierarchicIterator
= Dune::EntityIterator<0, const Grid, CGeo::HierarchicIterator<const Grid>>;
template< int codim >
struct Codim
......@@ -59,7 +61,8 @@ namespace Dune
// geometry types
using GeometryImpl = GeometryImplTemplate<dimension-codim, dimensionworld, const Grid>;
using Geometry = Dune::Geometry<dimension-codim, dimensionworld, const Grid, GeometryImplTemplate>;
using Geometry
= Dune::Geometry<dimension-codim, dimensionworld, const Grid, GeometryImplTemplate>;
using LocalGeometry = typename HostGrid::template Codim<codim>::LocalGeometry;
// entity types
......@@ -71,10 +74,12 @@ namespace Dune
template< PartitionIteratorType pitype >
struct Partition
{
using LeafIteratorImp = CGeo::Iterator<typename HostGrid::LeafGridView, codim, pitype, const Grid>;
using LeafIteratorImp
= CGeo::Iterator<typename HostGrid::LeafGridView, codim, pitype, const Grid>;
using LeafIterator = Dune::EntityIterator<codim, const Grid, LeafIteratorImp>;
using LevelIteratorImp = CGeo::Iterator<typename HostGrid::LevelGridView, codim, pitype, const Grid>;
using LevelIteratorImp
= CGeo::Iterator<typename HostGrid::LevelGridView, codim, pitype, const Grid>;
using LevelIterator = Dune::EntityIterator<codim, const Grid, LevelIteratorImp>;
};
......@@ -93,8 +98,10 @@ namespace Dune
using CollectiveCommunication = typename HostGrid::Traits::CollectiveCommunication;
// grid views
using LeafGridView = Dune::GridView< CGeo::GridViewTraits< typename HostGrid::LeafGridView, CF, order, Allocator > >;
using LevelGridView = Dune::GridView< CGeo::GridViewTraits< typename HostGrid::LevelGridView, CF, order, Allocator > >;
using LeafGridView
= Dune::GridView<CGeo::GridViewTraits<typename HostGrid::LeafGridView, CF, order, Allocator>>;
using LevelGridView
= Dune::GridView<CGeo::GridViewTraits<typename HostGrid::LevelGridView, CF, order, Allocator>>;
};
};
......
......@@ -3,12 +3,12 @@
#ifndef DUNE_CURVED_SURFACE_GRID_GRIDVIEW_HH
#define DUNE_CURVED_SURFACE_GRID_GRIDVIEW_HH
#include <dune/common/typetraits.hh>
#include <dune/common/exceptions.hh>
#include <cassert>
#include <utility>
#include <dune/grid/common/capabilities.hh>
#include <dune/grid/common/gridview.hh>
#include <dune/curvedsurfacegrid/datahandle.hh>
#include <dune/curvedsurfacegrid/declaration.hh>
#include <dune/curvedsurfacegrid/indexsets.hh>
#include <dune/curvedsurfacegrid/intersection.hh>
#include <dune/curvedsurfacegrid/intersectioniterator.hh>
......@@ -97,7 +97,7 @@ namespace Dune
template< int codim >
struct Codim
: public Traits::template Codim<codim>
: public Traits::template Codim<codim>
{};
static const bool conforming = Traits::conforming;
......@@ -191,14 +191,14 @@ namespace Dune
IntersectionIterator ibegin (const typename Codim<0>::Entity& entity) const
{
using IntersectionIteratorImpl = CGeo::IntersectionIterator<const Grid, typename HostGridView::IntersectionIterator>;
return IntersectionIteratorImpl(entity, hostGridView().ibegin(entity.impl().hostEntity()));
using IteratorImpl = CGeo::IntersectionIterator<const Grid, typename HostGridView::IntersectionIterator>;
return IteratorImpl(entity, hostGridView().ibegin(entity.impl().hostEntity()));
}
IntersectionIterator iend (const typename Codim<0>::Entity& entity) const
{
using IntersectionIteratorImpl = CGeo::IntersectionIterator<const Grid, typename HostGridView::IntersectionIterator>;
return IntersectionIteratorImpl(entity, hostGridView().iend(entity.impl().hostEntity()));
using IteratorImpl = CGeo::IntersectionIterator<const Grid, typename HostGridView::IntersectionIterator>;
return IteratorImpl(entity, hostGridView().iend(entity.impl().hostEntity()));
}
const CollectiveCommunication& comm () const
......
......@@ -3,6 +3,8 @@
#ifndef DUNE_CURVED_SURFACE_GRID_IDSET_HH
#define DUNE_CURVED_SURFACE_GRID_IDSET_HH
#include <type_traits>
#include <dune/grid/common/indexidset.hh>
namespace Dune
......@@ -32,10 +34,22 @@ namespace Dune
: hostIdSet_(&hostIdSet)
{}
//! Copy constructor. Copies only the host-idset pointer
IdSet (const IdSet& other)
: hostIdSet_(other.hostIdSet_)
{}
//! Copy-assignment operator. Copies only the host-idset pointer
IdSet& operator= (const IdSet& other)
{
hostIdSet_ = other.hostIdSet_;
return *this;
}
template< int codim >
IdType id (const typename Traits::template Codim<codim>::Entity& entity) const
{
return entity.impl().id(hostIdSet());
return hostIdSet().id(Grid::template getHostEntity<codim>(entity));
}
using Super::id;
......
......@@ -3,15 +3,12 @@
#ifndef DUNE_CURVED_SURFACE_GRID_INDEXSETS_HH
#define DUNE_CURVED_SURFACE_GRID_INDEXSETS_HH
#include <type_traits>
#include <vector>
#include <dune/common/typetraits.hh>
#include <dune/grid/common/gridenums.hh>
#include <dune/grid/common/indexidset.hh>
#include <dune/curvedsurfacegrid/declaration.hh>
namespace Dune
{
namespace CGeo
......@@ -47,7 +44,7 @@ namespace Dune
template< int cc >
IndexType index (const typename Traits::template Codim<cc>::Entity& entity) const
{
return entity.impl().index(hostIndexSet());
return hostIndexSet().index(Grid::template getHostEntity<cc>(entity));
}
using Super::index;
......@@ -55,7 +52,7 @@ namespace Dune
template< int cc >
IndexType subIndex (const typename Traits::template Codim<cc>::Entity& entity, int i, unsigned int codim) const
{
return entity.impl().subIndex(hostIndexSet(), i, codim);
return hostIndexSet().subIndex(Grid::template getHostEntity<cc>(entity), i, codim);
}
using Super::subIndex;
......@@ -73,10 +70,13 @@ namespace Dune
template< class Entity >
bool contains (const Entity& entity) const
{
return entity.impl().isContained(hostIndexSet());