From a0fa87e81f003986bc54e1ce533b03c93765fce8 Mon Sep 17 00:00:00 2001 From: Markus Blatt Date: Tue, 1 Oct 2019 21:18:17 +0200 Subject: [PATCH] Make sure subclass functions are not called before subclass is initialized. This at least slightly improves the old design. In that design the subclass had no own constructor but inherited the one of the base class. That base class constructor called certain subclass functions (createGrids_, filterConnections_, updateOutputDir_, and finalizeInit_)that would initialize raw pointers of the subclass. Hence subclasses where not allowed to have non-pod members and those used later (e.g. deleted in the destructor) had to be initialized in these functions. The new (still ugly) design introduces constructors into the subclasses and skips inheriting constructors. Now one must call a base class function classImplementationInit which will still call the functions createGrids_, filterConnections_, updateOutputDir_, and finalizeInit_, but at least at this point the baseclass is fully constructed and the subclass is constructed as much as possible/needed (non-pod types will be initialized now.) --- ebos/eclalugridvanguard.hh | 9 +++++---- ebos/eclbasevanguard.hh | 23 +++++++++++++---------- ebos/eclcpgridvanguard.hh | 10 ++++++---- ebos/eclpolyhedralgridvanguard.hh | 9 +++++---- 4 files changed, 29 insertions(+), 22 deletions(-) diff --git a/ebos/eclalugridvanguard.hh b/ebos/eclalugridvanguard.hh index a22a41377..940119317 100644 --- a/ebos/eclalugridvanguard.hh +++ b/ebos/eclalugridvanguard.hh @@ -81,10 +81,11 @@ private: static const int dimension = Grid::dimension; public: - /*! - * \brief Inherit the constructors from the base class. - */ - using EclBaseVanguard::EclBaseVanguard; + EclAluGridVanguard(Simulator& simulator) + : EclBaseVanguard(simulator) + { + this->callImplementationInit(); + } ~EclAluGridVanguard() { diff --git a/ebos/eclbasevanguard.hh b/ebos/eclbasevanguard.hh index 51a01f325..25aca6e15 100644 --- a/ebos/eclbasevanguard.hh +++ b/ebos/eclbasevanguard.hh @@ -373,16 +373,6 @@ public: int outputInterval = EWOMS_GET_PARAM(TypeTag, int, EclOutputInterval); if (outputInterval >= 0) eclState_->getRestartConfig().overrideRestartWriteInterval(outputInterval); - - asImp_().createGrids_(); - asImp_().filterConnections_(); - asImp_().updateOutputDir_(); - asImp_().finalizeInit_(); - - if (enableExperiments) { - Opm::RelpermDiagnostics relpermDiagnostics; - relpermDiagnostics.diagnosis(*eclState_, *deck_, asImp_().grid()); - } } /*! @@ -538,6 +528,19 @@ public: std::unordered_set defunctWellNames() const { return std::unordered_set(); } +protected: + void callImplementationInit() + { + asImp_().createGrids_(); + asImp_().filterConnections_(); + asImp_().updateOutputDir_(); + asImp_().finalizeInit_(); + + if (enableExperiments) { + Opm::RelpermDiagnostics relpermDiagnostics; + relpermDiagnostics.diagnosis(*eclState_, *deck_, asImp_().grid()); + } + } private: void updateOutputDir_() { diff --git a/ebos/eclcpgridvanguard.hh b/ebos/eclcpgridvanguard.hh index 8c73319c7..f88c99b4d 100644 --- a/ebos/eclcpgridvanguard.hh +++ b/ebos/eclcpgridvanguard.hh @@ -70,6 +70,7 @@ class EclCpGridVanguard : public EclBaseVanguard typedef EclBaseVanguard ParentType; typedef typename GET_PROP_TYPE(TypeTag, Scalar) Scalar; + typedef typename GET_PROP_TYPE(TypeTag, Simulator) Simulator; typedef typename GET_PROP_TYPE(TypeTag, ElementMapper) ElementMapper; public: @@ -81,10 +82,11 @@ private: typedef Dune::CartesianIndexMapper CartesianIndexMapper; public: - /*! - * \brief Inherit the constructors from the base class. - */ - using EclBaseVanguard::EclBaseVanguard; + EclCpGridVanguard(Simulator& simulator) + : EclBaseVanguard(simulator) + { + this->callImplementationInit(); + } ~EclCpGridVanguard() { diff --git a/ebos/eclpolyhedralgridvanguard.hh b/ebos/eclpolyhedralgridvanguard.hh index df7383197..4ca53dfff 100644 --- a/ebos/eclpolyhedralgridvanguard.hh +++ b/ebos/eclpolyhedralgridvanguard.hh @@ -77,10 +77,11 @@ private: typedef CartesianIndexMapper* CartesianIndexMapperPointer; public: - /*! - * \brief Inherit the constructors from the base class. - */ - using EclBaseVanguard::EclBaseVanguard; + EclPolyhedralGridVanguard(Simulator& simulator) + : EclBaseVanguard(simulator) + { + this->callImplementationInit(); + } ~EclPolyhedralGridVanguard() {