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 ...@@ -24,64 +24,64 @@ namespace Dune
using Traits = typename std::remove_const_t<Grid>::Traits; using Traits = typename std::remove_const_t<Grid>::Traits;
public: public:
CommDataHandle ( const Grid &grid, WrappedHandle &handle ) CommDataHandle (const Grid& grid, WrappedHandle& handle)
: grid_( grid ), : grid_(grid)
wrappedHandle_( handle ) , wrappedHandle_(handle)
{} {}
bool contains ( int dim, int codim ) const bool contains (int dim, int codim) const
{ {
const bool contains = wrappedHandle_.contains( dim, codim ); const bool contains = wrappedHandle_.contains(dim, codim);
if( contains ) if (contains)
assertHostEntity( dim, codim ); assertHostEntity(dim, codim);
return contains; 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 > 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; using Entity = typename Grid::Traits::template Codim<HostEntity::codimension>::Entity;
typedef typename Grid::Traits::template Codim< HostEntity::codimension >::EntityImpl EntityImpl; using EntityImpl = typename Grid::Traits::template Codim<HostEntity::codimension>::EntityImpl;
Entity entity( EntityImpl( grid_, hostEntity ) ); Entity entity(EntityImpl(grid_, hostEntity));
return wrappedHandle_.size( entity ); return wrappedHandle_.size(entity);
} }
template< class MessageBuffer, class HostEntity > 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; using Entity = typename Grid::Traits::template Codim<HostEntity::codimension>::Entity;
typedef typename Grid::Traits::template Codim< HostEntity::codimension >::EntityImpl EntityImpl; using EntityImpl = typename Grid::Traits::template Codim<HostEntity::codimension>::EntityImpl;
Entity entity( EntityImpl( grid_, hostEntity ) ); Entity entity(EntityImpl(grid_, hostEntity));
wrappedHandle_.gather( buffer, entity ); wrappedHandle_.gather(buffer, entity);
} }
template< class MessageBuffer, class HostEntity > 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; using Entity = typename Grid::Traits::template Codim< HostEntity::codimension >::Entity;
typedef typename Grid::Traits::template Codim< HostEntity::codimension >::EntityImpl EntityImpl; using EntityImpl = typename Grid::Traits::template Codim< HostEntity::codimension >::EntityImpl;
Entity entity( EntityImpl( grid_, hostEntity ) ); Entity entity(EntityImpl(grid_, hostEntity));
wrappedHandle_.scatter( buffer, entity, size ); wrappedHandle_.scatter(buffer, entity, size);
} }
private: private:
static void assertHostEntity ( int dim, int codim ) static void assertHostEntity (int dim, int codim)
{ {
if( !Capabilities::CodimCache< Grid >::hasHostEntity( codim ) ) if (!Capabilities::CodimCache<Grid>::hasHostEntity(codim))
DUNE_THROW( NotImplemented, "Host grid has no entities for codimension " << codim << "." ); DUNE_THROW(NotImplemented, "Host grid has no entities for codimension " << codim << ".");
} }
const Grid &grid_; private:
WrappedHandle &wrappedHandle_; const Grid& grid_;
WrappedHandle& wrappedHandle_;
}; };
} // namespace CGeo } // namespace CGeo
} // namespace Dune } // namespace Dune
#endif // DUNE_CURVED_SURFACE_GRID_DATAHANDLE_HH #endif // DUNE_CURVED_SURFACE_GRID_DATAHANDLE_HH
...@@ -135,20 +135,6 @@ namespace Dune ...@@ -135,20 +135,6 @@ namespace Dune
, grid_(&grid) , 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 // construct the entity from a host-entity
EntityBase (const Grid& grid, const HostEntity& hostEntity) EntityBase (const Grid& grid, const HostEntity& hostEntity)
: hostEntity_(hostEntity) : hostEntity_(hostEntity)
...@@ -194,14 +180,6 @@ namespace Dune ...@@ -194,14 +180,6 @@ namespace Dune
return hostEntity().partitionType(); 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 //! obtain the geometry of this entity
/** /**
* Each DUNE entity encapsulates a geometry object, representing the map * Each DUNE entity encapsulates a geometry object, representing the map
...@@ -216,23 +194,22 @@ namespace Dune ...@@ -216,23 +194,22 @@ namespace Dune
Geometry geometry () const Geometry geometry () const
{ {
if (!geo_) { 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 const& idSet = grid_->hostGrid().localIdSet();
auto& cached_geo = std::get<codim>(grid_->geometryCache_)[id(idSet)]; auto id = idSet.id(hostEntity());
// if geometry is already in cache auto& cache = std::get<codim>(grid_->geometryCache_);
if (cached_geo) auto [it,inserted] = cache.try_emplace(id, type(), ff);
geo_ = *cached_geo;
// otherwise cache a new constructed geometry geo_ = it->second;
else {
geo_ = makeGeometry();
*cached_geo = *geo_;
}
} }
else else {
{ geo_ = GeometryImpl(type(), ff);
geo_ = makeGeometry();
} }
} }
...@@ -242,7 +219,7 @@ namespace Dune ...@@ -242,7 +219,7 @@ namespace Dune
//! obtain number of sub-entities of the current entity //! obtain number of sub-entities of the current entity
unsigned int subEntities (unsigned int cc) const unsigned int subEntities (unsigned int cc) const
{ {
return hostEntity().subEntities( cc ); return hostEntity().subEntities(cc);
} }
//! return EntitySeed of host grid entity //! return EntitySeed of host grid entity
...@@ -269,71 +246,6 @@ namespace Dune ...@@ -269,71 +246,6 @@ namespace Dune
return hostEntity_; 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: private:
...@@ -404,26 +316,26 @@ namespace Dune ...@@ -404,26 +316,26 @@ namespace Dune
LevelIntersectionIterator ilevelbegin () const LevelIntersectionIterator ilevelbegin () const
{ {
using LevelIntersectionIteratorImpl = CGeo::IntersectionIterator<Grid, typename HostGrid::LevelIntersectionIterator>; using IteratorImpl = CGeo::IntersectionIterator<Grid, typename HostGrid::LevelIntersectionIterator>;
return LevelIntersectionIteratorImpl(*this, Super::hostEntity().ilevelbegin()); return IteratorImpl(*this, Super::hostEntity().ilevelbegin());
} }
LevelIntersectionIterator ilevelend () const LevelIntersectionIterator ilevelend () const
{ {
using LevelIntersectionIteratorImpl = CGeo::IntersectionIterator<Grid, typename HostGrid::LevelIntersectionIterator>; using IteratorImpl = CGeo::IntersectionIterator<Grid, typename HostGrid::LevelIntersectionIterator>;
return LevelIntersectionIteratorImpl(*this, Super::hostEntity().ilevelend()); return IteratorImpl(*this, Super::hostEntity().ilevelend());
} }
LeafIntersectionIterator ileafbegin () const LeafIntersectionIterator ileafbegin () const
{ {
using LeafIntersectionIteratorImpl = CGeo::IntersectionIterator<Grid, typename HostGrid::LeafIntersectionIterator>; using IteratorImpl = CGeo::IntersectionIterator<Grid, typename HostGrid::LeafIntersectionIterator>;
return LeafIntersectionIteratorImpl(*this, Super::hostEntity().ileafbegin()); return IteratorImpl(*this, Super::hostEntity().ileafbegin());
} }
LeafIntersectionIterator ileafend () const LeafIntersectionIterator ileafend () const
{ {
using LeafIntersectionIteratorImpl = CGeo::IntersectionIterator<Grid, typename HostGrid::LeafIntersectionIterator>; using IteratorImpl = CGeo::IntersectionIterator<Grid, typename HostGrid::LeafIntersectionIterator>;
return LeafIntersectionIteratorImpl(*this, Super::hostEntity().ileafend()); return IteratorImpl(*this, Super::hostEntity().ileafend());
} }
bool hasBoundaryIntersections () const bool hasBoundaryIntersections () const
...@@ -453,14 +365,14 @@ namespace Dune ...@@ -453,14 +365,14 @@ namespace Dune
HierarchicIterator hbegin (int maxLevel) const HierarchicIterator hbegin (int maxLevel) const
{ {
using HierarchicIteratorImpl = CGeo::HierarchicIterator<Grid>; using IteratorImpl = CGeo::HierarchicIterator<Grid>;
return HierarchicIteratorImpl(Super::grid(), Super::hostEntity().hbegin(maxLevel)); return IteratorImpl(Super::grid(), Super::hostEntity().hbegin(maxLevel));
} }
HierarchicIterator hend (int maxLevel) const HierarchicIterator hend (int maxLevel) const
{ {
using HierarchicIteratorImpl = CGeo::HierarchicIterator<Grid>; using IteratorImpl = CGeo::HierarchicIterator<Grid>;
return HierarchicIteratorImpl(Super::grid(), Super::hostEntity().hend(maxLevel)); return IteratorImpl(Super::grid(), Super::hostEntity().hend(maxLevel));
} }
bool isRegular () const bool isRegular () const
...@@ -480,7 +392,6 @@ namespace Dune ...@@ -480,7 +392,6 @@ namespace Dune
}; };
} // namespace CGeo } // namespace CGeo
} // namespace Dune } // namespace Dune
#endif // DUNE_CURVED_SURFACE_GRID_ENTITY_HH #endif // DUNE_CURVED_SURFACE_GRID_ENTITY_HH
...@@ -47,20 +47,22 @@ namespace Dune ...@@ -47,20 +47,22 @@ namespace Dune
}; };
\endcode \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 CoordFunction coordinate function
* \tparam lagrangeOrder Polynomial order of local lagrange basis function in geometry
* parametrization
* *
* \nosubgrouping * \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 class CurvedSurfaceGrid
: public GridDefaultImplementation<HostGrid::dimension, CoordFunction::dimRange, typename HostGrid::ctype, : public GridDefaultImplementation<HG::dimension, CoordFunction::dimRange, typename HG::ctype,
CGeo::GridFamily<HostGrid, CoordFunction, lagrangeOrder, Allocator> > CGeo::GridFamily<HG, CoordFunction, lagrangeOrder, Allocator> >
, public CGeo::BackupRestoreFacilities<CurvedSurfaceGrid<HostGrid, CoordFunction, lagrangeOrder, Allocator> > , public CGeo::BackupRestoreFacilities<CurvedSurfaceGrid<HG, CoordFunction, lagrangeOrder, Allocator> >
{ {
using Self = CurvedSurfaceGrid; using Self = CurvedSurfaceGrid;
using Super = GridDefaultImplementation<HostGrid::dimension, CoordFunction::dimRange, typename HostGrid::ctype, using Super = GridDefaultImplementation<HG::dimension, CoordFunction::dimRange, typename HG::ctype,
CGeo::GridFamily<HostGrid, CoordFunction, lagrangeOrder, Allocator> >; CGeo::GridFamily<HG, CoordFunction, lagrangeOrder, Allocator> >;
// friend declarations // friend declarations
friend class CGeo::HierarchicIterator<const Self>; friend class CGeo::HierarchicIterator<const Self>;
...@@ -74,7 +76,9 @@ namespace Dune ...@@ -74,7 +76,9 @@ namespace Dune
template< class, class > friend class CGeo::CommDataHandle; template< class, class > friend class CGeo::CommDataHandle;
public: public:
using GridFamily = CGeo::GridFamily<HostGrid, CoordFunction, lagrangeOrder, Allocator>; using GridFamily = CGeo::GridFamily<HG, CoordFunction, lagrangeOrder, Allocator>;
using HostGrid = HG;
/** \name Traits /** \name Traits
* \{ */ * \{ */
...@@ -221,21 +225,16 @@ namespace Dune ...@@ -221,21 +225,16 @@ namespace Dune
: hostGrid_(std::move(hostGrid)) : hostGrid_(std::move(hostGrid))
, coordFunction_(wrap_or_move(std::forward<Param>(param))) , coordFunction_(wrap_or_move(std::forward<Param>(param)))
, levelIndexSets_(hostGrid_->maxLevel()+1, nullptr, allocator) , levelIndexSets_(hostGrid_->maxLevel()+1, nullptr, allocator)
, storageAllocator_(allocator)
{} {}
//! destructor //! destructor
~CurvedSurfaceGrid () ~CurvedSurfaceGrid ()
{ {
for(auto &mapEntry : std::get<0>(geometryCache_)) delete mapEntry.second; for (unsigned int i = 0; i < levelIndexSets_.size(); ++i)
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 )
{ {
if( levelIndexSets_[ i ] ) if (levelIndexSets_[i])
delete( levelIndexSets_[ i ] ); delete (levelIndexSets_[i]);
} }
} }
...@@ -304,7 +303,7 @@ namespace Dune ...@@ -304,7 +303,7 @@ namespace Dune
/** /**
* \returns number of boundary segments within the macro grid * \returns number of boundary segments within the macro grid
*/ */
size_t numBoundarySegments () const std::size_t numBoundarySegments () const
{ {
return hostGrid().numBoundarySegments(); return hostGrid().numBoundarySegments();
} }
...@@ -543,16 +542,6 @@ namespace Dune ...@@ -543,16 +542,6 @@ namespace Dune
return entity.impl().hostEntity(); 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: private:
std::shared_ptr<HostGrid> hostGrid_; std::shared_ptr<HostGrid> hostGrid_;
std::shared_ptr<CoordFunction> coordFunction_; std::shared_ptr<CoordFunction> coordFunction_;
...@@ -563,7 +552,6 @@ namespace Dune ...@@ -563,7 +552,6 @@ namespace Dune
mutable LeafIndexSet leafIndexSet_; mutable LeafIndexSet leafIndexSet_;
mutable GlobalIdSet globalIdSet_; mutable GlobalIdSet globalIdSet_;
mutable LocalIdSet localIdSet_; mutable LocalIdSet localIdSet_;
mutable typename Allocator::template rebind<char>::other storageAllocator_;
private: private:
template <class Indices> template <class Indices>
...@@ -575,7 +563,7 @@ namespace Dune ...@@ -575,7 +563,7 @@ namespace Dune
using type = std::tuple< using type = std::tuple<
std::map< std::map<
typename HostGrid::Traits::LocalIdSet::IdType, typename HostGrid::Traits::LocalIdSet::IdType,
typename Traits::template Codim<codims>::GeometryImpl* typename Traits::template Codim<codims>::GeometryImpl
>... >...
>; >;
}; };
......
...@@ -8,7 +8,6 @@ ...@@ -8,7 +8,6 @@
#include <dune/curvedsurfacegrid/capabilities.hh> #include <dune/curvedsurfacegrid/capabilities.hh>
#include <dune/curvedsurfacegrid/entity.hh> #include <dune/curvedsurfacegrid/entity.hh>
#include <dune/curvedsurfacegrid/entityseed.hh> #include <dune/curvedsurfacegrid/entityseed.hh>
//#include <dune/curvedsurfacegrid/geometry.hh>
#include <dune/curvedsurfacegrid/gridview.hh> #include <dune/curvedsurfacegrid/gridview.hh>
#include <dune/curvedsurfacegrid/intersection.hh> #include <dune/curvedsurfacegrid/intersection.hh>
#include <dune/curvedsurfacegrid/intersectioniterator.hh> #include <dune/curvedsurfacegrid/intersectioniterator.hh>
...@@ -41,15 +40,18 @@ namespace Dune ...@@ -41,15 +40,18 @@ namespace Dune
static const int dimension = HostGrid::dimension; static const int dimension = HostGrid::dimension;
static const int dimensionworld = CoordFunction::dimRange; static const int dimensionworld = CoordFunction::dimRange;
using LeafIntersection = Dune::Intersection<const Grid, CGeo::Intersection<const Grid, typename HostGrid::LeafIntersection> >; using LeafIntersection
using LevelIntersection = Dune::Intersection<const Grid, CGeo::Intersection<const Grid, typename HostGrid::LevelIntersection> >; = 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 using LeafIntersectionIterator
= Dune::IntersectionIterator<const Grid, CGeo::IntersectionIterator<const Grid, typename HostGrid::LeafIntersectionIterator>, CGeo::Intersection<const Grid, typename HostGrid::LeafIntersection> >; = Dune::IntersectionIterator<const Grid, CGeo::IntersectionIterator<const Grid, typename HostGrid::LeafIntersectionIterator>, CGeo::Intersection<const Grid, typename HostGrid::LeafIntersection> >;
using LevelIntersectionIterator using LevelIntersectionIterator
= Dune::IntersectionIterator<const Grid, CGeo::IntersectionIterator<const Grid, typename HostGrid::LevelIntersectionIterator >, CGeo::Intersection<const Grid, typename HostGrid::LevelIntersection> >; = 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 > template< int codim >
struct Codim struct Codim
...@@ -59,7 +61,8 @@ namespace Dune ...@@ -59,7 +61,8 @@ namespace Dune
// geometry types // geometry types
using GeometryImpl = GeometryImplTemplate<dimension-codim, dimensionworld, const Grid>; 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; using LocalGeometry = typename HostGrid::template Codim<codim>::LocalGeometry;
// entity types // entity types
...@@ -71,10 +74,12 @@ namespace Dune ...@@ -71,10 +74,12 @@ namespace Dune
template< PartitionIteratorType pitype > template< PartitionIteratorType pitype >
struct Partition 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 LeafIterator = Dune::EntityIterator<codim, const Grid, LeafIteratorImp>;