Skip to content
Snippets Groups Projects
Commit 41f2c460 authored by Robert K's avatar Robert K
Browse files

[bugfix][SphereGrid] Use shared_ptr to store host grid.

parent b668aaef
No related branches found
No related tags found
1 merge request!1Update to 2.8
......@@ -39,10 +39,10 @@ namespace Dune
: dgfHostFactory_( filename, comm ),
grid_( 0 )
{
HostGrid *hostGrid = dgfHostFactory_.grid();
assert( hostGrid != 0 );
std::shared_ptr< HostGrid > hostGrid( dgfHostFactory_.grid() );
assert( hostGrid );
std::ifstream input( filename.c_str() );
grid_ = new Grid( *hostGrid );
grid_ = new Grid( hostGrid );
}
Grid *grid () const
......
#ifndef DUNE_SPHEREGRID_GRID_HH
#define DUNE_SPHEREGRID_GRID_HH
#include <dune/common/shared_ptr.hh>
#include <dune/grid/common/grid.hh>
#include <dune/grid/common/hostgridinoutstreams.hh>
......@@ -253,24 +254,26 @@ namespace Dune
* The references to host grid and coordinate function are stored in the
* grid. Therefore, they must remain valid until the grid is destroyed.
*
* \param[in] hostGrid reference to the grid to wrap
* \param[in] hostGrid reference to the grid to wrap, memory managed elsewhere
*/
explicit SphereGrid ( HostGrid &hostGrid, MapToSphere mapToSphere = MapToSphere() )
: hostGrid_( &hostGrid ),
: hostGridPtr_( &hostGrid, Dune::null_deleter< HostGrid > () ),
mapToSphere_( mapToSphere ),
levelIndexSets_( hostGrid.maxLevel()+1, nullptr )
levelIndexSets_( hostGrid.maxLevel()+1 )
{}
/** \brief destructor
/** \brief constructor
*
* The references to host grid and coordinate function are stored in the
* grid. Therefore, they must remain valid until the grid is destroyed.
*
* \param[in] hostGrid shared_ptr to the grid to wrap (memory managed here)
*/
~SphereGrid ()
{
for( unsigned int i = 0; i < levelIndexSets_.size(); ++i )
{
if( levelIndexSets_[ i ] )
delete( levelIndexSets_[ i ] );
}
}
explicit SphereGrid ( const std::shared_ptr< HostGrid >& hostGridPtr, MapToSphere mapToSphere = MapToSphere() )
: hostGridPtr_( hostGridPtr ),
mapToSphere_( mapToSphere ),
levelIndexSets_( hostGrid().maxLevel()+1 )
{}
/** \} */
......@@ -428,9 +431,9 @@ namespace Dune
<< " requested." );
}
LevelIndexSet *&levelIndexSet = levelIndexSets_[ level ];
auto& levelIndexSet = levelIndexSets_[ level ];
if( !levelIndexSet )
levelIndexSet = new LevelIndexSet( hostGrid().levelIndexSet( level ) );
levelIndexSet.reset( new LevelIndexSet( hostGrid().levelIndexSet( level ) ) );
assert( levelIndexSet );
return *levelIndexSet;
}
......@@ -674,8 +677,8 @@ namespace Dune
/** \name Miscellaneous Methods
* \{ */
const HostGrid &hostGrid () const { return *hostGrid_; }
HostGrid &hostGrid () { return *hostGrid_; }
const HostGrid &hostGrid () const { assert( hostGridPtr_ ); return *hostGridPtr_; }
HostGrid &hostGrid () { assert( hostGridPtr_ ); return *hostGridPtr_; }
const MapToSphere &mapToSphere () const { return mapToSphere_; }
......@@ -692,12 +695,8 @@ namespace Dune
const int newNumLevels = maxLevel()+1;
const int oldNumLevels = levelIndexSets_.size();
for( int i = newNumLevels; i < oldNumLevels; ++i )
{
if( !levelIndexSets_[ i ] )
delete levelIndexSets_[ i ];
}
levelIndexSets_.resize( newNumLevels, nullptr );
levelIndexSets_.clear();
levelIndexSets_.resize( newNumLevels );
}
/** \} */
......@@ -711,9 +710,10 @@ namespace Dune
}
protected:
HostGrid *const hostGrid_;
std::shared_ptr< HostGrid > hostGridPtr_;
MapToSphere mapToSphere_;
mutable std::vector< LevelIndexSet * > levelIndexSets_;
mutable std::vector< std::unique_ptr< LevelIndexSet > > levelIndexSets_;
mutable LeafIndexSet leafIndexSet_;
mutable GlobalIdSet globalIdSet_;
mutable LocalIdSet localIdSet_;
......
add_subdirectory(alugrid)
add_subdirectory(metagrid)
add_python_targets(dune
__init__
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment