mirror of
https://github.com/OPM/opm-simulators.git
synced 2025-02-25 18:55:30 -06:00
grid managers: get rid of gridPointer(), make them robust to exceptions during construction
This commit is contained in:
@@ -79,8 +79,8 @@ class EclGridManager : public BaseGridManager<TypeTag>
|
||||
typedef typename GET_PROP_TYPE(TypeTag, Simulator) Simulator;
|
||||
typedef typename GET_PROP_TYPE(TypeTag, Grid) Grid;
|
||||
|
||||
typedef std::shared_ptr<Grid> GridPointer;
|
||||
typedef std::shared_ptr<const Grid> GridConstPointer;
|
||||
typedef std::unique_ptr<Grid> GridPointer;
|
||||
typedef std::unique_ptr<const Grid> GridConstPointer;
|
||||
static const int dim = Grid::dimension;
|
||||
|
||||
public:
|
||||
@@ -126,16 +126,16 @@ public:
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Return a pointer to the grid.
|
||||
* \brief Return a reference to the grid.
|
||||
*/
|
||||
GridPointer gridPointer()
|
||||
{ return grid_; }
|
||||
Grid& grid()
|
||||
{ return *grid_; }
|
||||
|
||||
/*!
|
||||
* \brief Return a pointer to the grid.
|
||||
* \brief Return a reference to the grid.
|
||||
*/
|
||||
GridConstPointer gridPointer() const
|
||||
{ return grid_; }
|
||||
const Grid& grid() const
|
||||
{ return *grid_; }
|
||||
|
||||
/*!
|
||||
* \brief Return a pointer to the parsed Eclipse deck
|
||||
|
||||
@@ -33,6 +33,7 @@
|
||||
#include <dune/common/version.hh>
|
||||
|
||||
#include <vector>
|
||||
#include <memory>
|
||||
|
||||
// some hacky defines for the grid manager
|
||||
#define FINGER_DIM 2
|
||||
@@ -81,6 +82,8 @@ class FingerGridManager : public BaseGridManager<TypeTag>
|
||||
typedef typename GET_PROP_TYPE(TypeTag, Simulator) Simulator;
|
||||
typedef typename GET_PROP_TYPE(TypeTag, Grid) Grid;
|
||||
|
||||
typedef std::unique_ptr<Grid> GridPointer;
|
||||
|
||||
enum { dim = FINGER_DIM };
|
||||
|
||||
public:
|
||||
@@ -116,7 +119,7 @@ public:
|
||||
FingerGridManager(Simulator &simulator)
|
||||
: ParentType(simulator)
|
||||
{
|
||||
grid_ = new Grid;
|
||||
gridPtr_.reset(new Grid);
|
||||
|
||||
Dune::FieldVector<int, dim> cellRes;
|
||||
Dune::FieldVector<Scalar, dim> upperRight;
|
||||
@@ -133,10 +136,7 @@ public:
|
||||
cellRes[2] = EWOMS_GET_PARAM(TypeTag, int, CellsZ);
|
||||
}
|
||||
|
||||
unsigned numRefinments
|
||||
= EWOMS_GET_PARAM(TypeTag, unsigned, GridGlobalRefinements);
|
||||
|
||||
Dune::GridFactory<Grid> factory(grid_);
|
||||
Dune::GridFactory<Grid> factory;
|
||||
|
||||
if (dim == 3) {
|
||||
Dune::FieldVector<double, dim> pos;
|
||||
@@ -265,32 +265,28 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
grid_ = factory.createGrid();
|
||||
grid_->globalRefine(numRefinments);
|
||||
gridPtr_.reset(factory.createGrid());
|
||||
|
||||
unsigned numRefinments = EWOMS_GET_PARAM(TypeTag, unsigned, GridGlobalRefinements);
|
||||
gridPtr_->globalRefine(numRefinments);
|
||||
|
||||
this->finalizeInit_();
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Destroy the grid.
|
||||
* \brief Return a reference to the grid.
|
||||
*/
|
||||
~FingerGridManager()
|
||||
{ delete grid_; }
|
||||
Grid& grid()
|
||||
{ return *gridPtr_; }
|
||||
|
||||
/*!
|
||||
* \brief Return a pointer to the grid.
|
||||
* \brief Return a reference to the grid.
|
||||
*/
|
||||
Grid* gridPointer()
|
||||
{ return grid_; }
|
||||
|
||||
/*!
|
||||
* \brief Return a pointer to the grid.
|
||||
*/
|
||||
const Grid* gridPointer() const
|
||||
{ return grid_; }
|
||||
const Grid& grid() const
|
||||
{ return *gridPtr_; }
|
||||
|
||||
private:
|
||||
Grid *grid_;
|
||||
GridPointer gridPtr_;
|
||||
};
|
||||
|
||||
} // namespace Ewoms
|
||||
|
||||
@@ -33,6 +33,7 @@
|
||||
#include <dune/common/version.hh>
|
||||
|
||||
#include <vector>
|
||||
#include <memory>
|
||||
|
||||
namespace Ewoms {
|
||||
template <class TypeTag>
|
||||
@@ -79,6 +80,8 @@ class LensGridManager : public BaseGridManager<TypeTag>
|
||||
typedef typename GET_PROP_TYPE(TypeTag, Simulator) Simulator;
|
||||
typedef typename GET_PROP_TYPE(TypeTag, Grid) Grid;
|
||||
|
||||
typedef std::unique_ptr<Grid> GridPointer;
|
||||
|
||||
static const int dim = Grid::dimension;
|
||||
|
||||
public:
|
||||
@@ -125,8 +128,6 @@ public:
|
||||
Dune::FieldVector<Scalar, dim> upperRight;
|
||||
Dune::FieldVector<Scalar, dim> lowerLeft;
|
||||
|
||||
grid_ = 0;
|
||||
|
||||
lowerLeft[1] = 0.0;
|
||||
upperRight[0] = EWOMS_GET_PARAM(TypeTag, Scalar, DomainSizeX);
|
||||
upperRight[1] = EWOMS_GET_PARAM(TypeTag, Scalar, DomainSizeY);
|
||||
@@ -141,38 +142,32 @@ public:
|
||||
unsigned numRefinements
|
||||
= EWOMS_GET_PARAM(TypeTag, unsigned, GridGlobalRefinements);
|
||||
|
||||
grid_ = new Dune::YaspGrid<dim>(
|
||||
gridPtr_.reset(new Dune::YaspGrid<dim>(
|
||||
#ifdef HAVE_MPI
|
||||
/*mpiCommunicator=*/Dune::MPIHelper::getCommunicator(),
|
||||
#endif
|
||||
/*upperRightCorner=*/upperRight,
|
||||
/*numCells=*/cellRes, isPeriodic,
|
||||
/*overlap=*/1);
|
||||
grid_->globalRefine(numRefinements);
|
||||
/*overlap=*/1));
|
||||
gridPtr_->globalRefine(numRefinements);
|
||||
|
||||
this->finalizeInit_();
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Destroy the grid
|
||||
* \brief Return a reference to the grid object.
|
||||
*/
|
||||
~LensGridManager()
|
||||
{ delete grid_; }
|
||||
Grid& grid()
|
||||
{ return *gridPtr_; }
|
||||
|
||||
/*!
|
||||
* \brief Return a pointer to the grid object.
|
||||
* \brief Return a constant reference to the grid object.
|
||||
*/
|
||||
Grid* gridPointer()
|
||||
{ return grid_; }
|
||||
|
||||
/*!
|
||||
* \brief Return a constant pointer to the grid object.
|
||||
*/
|
||||
const Grid* gridPointer() const
|
||||
{ return grid_; }
|
||||
const Grid& grid() const
|
||||
{ return *gridPtr_; }
|
||||
|
||||
private:
|
||||
Grid *grid_;
|
||||
GridPointer gridPtr_;
|
||||
};
|
||||
|
||||
} // namespace Ewoms
|
||||
|
||||
Reference in New Issue
Block a user