From 03efb3f414a806d990f5515d4b116ead55b79f25 Mon Sep 17 00:00:00 2001 From: Bernd Flemisch <bernd@iws.uni-stuttgart.de> Date: Tue, 5 Feb 2013 06:45:44 +0000 Subject: [PATCH] Replace standard by smart pointers for decoupled. This partially implements FS#182. Reviewed by Benjamin and Markus. git-svn-id: svn://svn.iws.uni-stuttgart.de/DUMUX/dumux/trunk@10177 2fb0f335-1f38-0410-981e-8018bf24f1b0 --- .../1p/diffusion/diffusionproblem1p.hh | 19 ++------- .../2p/diffusion/diffusionproblem2p.hh | 19 ++------- dumux/decoupled/2p/impes/impesproblem2p.hh | 17 +------- .../2p/transport/fv/fvsaturation2p.hh | 20 +++------- .../2p/transport/transportproblem2p.hh | 16 +------- dumux/decoupled/2p2c/cellData2p2c.hh | 7 ++-- .../2p2c/cellData2p2cmultiphysics.hh | 12 +++--- .../decoupled/2p2c/fvpressure2p2cadaptive.hh | 4 +- dumux/decoupled/common/fv/fvtransport.hh | 10 +---- dumux/decoupled/common/impetproblem.hh | 39 +++++++------------ dumux/decoupled/common/onemodelproblem.hh | 34 +++++----------- 11 files changed, 50 insertions(+), 147 deletions(-) diff --git a/dumux/decoupled/1p/diffusion/diffusionproblem1p.hh b/dumux/decoupled/1p/diffusion/diffusionproblem1p.hh index 21b528d55c..80584506d7 100644 --- a/dumux/decoupled/1p/diffusion/diffusionproblem1p.hh +++ b/dumux/decoupled/1p/diffusion/diffusionproblem1p.hh @@ -77,8 +77,7 @@ public: DiffusionProblem1P(TimeManager &timeManager, const GridView &gridView) : ParentType(timeManager, gridView), gravity_(0) { - spatialParams_ = new SpatialParams(gridView); - newSpatialParams_ = true; + spatialParams_ = Dune::make_shared<SpatialParams>(gridView); gravity_ = 0; if (GET_PARAM_FROM_GROUP(TypeTag, bool, Problem, EnableGravity)) gravity_[dim - 1] = -9.81; @@ -93,7 +92,6 @@ public: DiffusionProblem1P(TimeManager &timeManager, const GridView &gridView, SpatialParams &spatialParams) : ParentType(timeManager, gridView), gravity_(0), spatialParams_(&spatialParams) { - newSpatialParams_ = false; gravity_ = 0; if (GET_PARAM_FROM_GROUP(TypeTag, bool, Problem, EnableGravity)) gravity_[dim - 1] = -9.81; @@ -106,8 +104,7 @@ public: DiffusionProblem1P(const GridView &gridView) : ParentType(gridView, false), gravity_(0) { - spatialParams_ = new SpatialParams(gridView); - newSpatialParams_ = true; + spatialParams_ = Dune::make_shared<SpatialParams>(gridView); gravity_ = 0; if (GET_PARAM_FROM_GROUP(TypeTag, bool, Problem, EnableGravity)) gravity_[dim - 1] = -9.81; @@ -121,20 +118,11 @@ public: DiffusionProblem1P(const GridView &gridView, SpatialParams &spatialParams) : ParentType(gridView, false), gravity_(0), spatialParams_(&spatialParams) { - newSpatialParams_ = false; gravity_ = 0; if (GET_PARAM_FROM_GROUP(TypeTag, bool, Problem, EnableGravity)) gravity_[dim - 1] = -9.81; } - virtual ~DiffusionProblem1P() - { - if (newSpatialParams_) - { - delete spatialParams_; - } - } - /*! * \name Problem parameters */ @@ -251,8 +239,7 @@ private: GlobalPosition gravity_; // fluids and material properties - SpatialParams* spatialParams_; - bool newSpatialParams_; + Dune::shared_ptr<SpatialParams> spatialParams_; }; } diff --git a/dumux/decoupled/2p/diffusion/diffusionproblem2p.hh b/dumux/decoupled/2p/diffusion/diffusionproblem2p.hh index f9074dad6c..bcedb25c8f 100644 --- a/dumux/decoupled/2p/diffusion/diffusionproblem2p.hh +++ b/dumux/decoupled/2p/diffusion/diffusionproblem2p.hh @@ -77,8 +77,7 @@ public: DiffusionProblem2P(TimeManager &timeManager, const GridView &gridView) : ParentType(timeManager, gridView), gravity_(0) { - spatialParams_ = new SpatialParams(gridView); - newSpatialParams_ = true; + spatialParams_ = Dune::make_shared<SpatialParams>(gridView); gravity_ = 0; if (GET_PARAM_FROM_GROUP(TypeTag, bool, Problem, EnableGravity)) gravity_[dim - 1] = -9.81; @@ -93,7 +92,6 @@ public: DiffusionProblem2P(TimeManager &timeManager, const GridView &gridView, SpatialParams &spatialParams) : ParentType(timeManager, gridView), gravity_(0), spatialParams_(&spatialParams) { - newSpatialParams_ = false; gravity_ = 0; if (GET_PARAM_FROM_GROUP(TypeTag, bool, Problem, EnableGravity)) gravity_[dim - 1] = -9.81; @@ -107,8 +105,7 @@ public: DiffusionProblem2P(const GridView &gridView) : ParentType(gridView, false), gravity_(0) { - spatialParams_ = new SpatialParams(gridView); - newSpatialParams_ = true; + spatialParams_ = Dune::make_shared<SpatialParams>(gridView); gravity_ = 0; if (GET_PARAM_FROM_GROUP(TypeTag, bool, Problem, EnableGravity)) gravity_[dim - 1] = -9.81; @@ -122,21 +119,11 @@ public: DiffusionProblem2P(const GridView &gridView, SpatialParams &spatialParams) : ParentType(gridView, false), gravity_(0), spatialParams_(&spatialParams) { - newSpatialParams_ = false; gravity_ = 0; if (GET_PARAM_FROM_GROUP(TypeTag, bool, Problem, EnableGravity)) gravity_[dim - 1] = -9.81; } - //! Destructor - virtual ~DiffusionProblem2P() - { - if (newSpatialParams_) - { - delete spatialParams_; - } - } - /*! * \name Problem parameters */ @@ -245,7 +232,7 @@ private: GlobalPosition gravity_; // fluids and material properties - SpatialParams* spatialParams_; + Dune::shared_ptr<SpatialParams> spatialParams_; bool newSpatialParams_; }; diff --git a/dumux/decoupled/2p/impes/impesproblem2p.hh b/dumux/decoupled/2p/impes/impesproblem2p.hh index 7d46bbfcf4..8dc3e67978 100644 --- a/dumux/decoupled/2p/impes/impesproblem2p.hh +++ b/dumux/decoupled/2p/impes/impesproblem2p.hh @@ -80,8 +80,7 @@ public: : ParentType(timeManager, gridView), gravity_(0) { - newSpatialParams_ = true; - spatialParams_ = new SpatialParams(gridView); + spatialParams_ = Dune::make_shared<SpatialParams>(gridView); gravity_ = 0; if (GET_PARAM_FROM_GROUP(TypeTag, bool, Problem, EnableGravity)) @@ -98,22 +97,11 @@ public: : ParentType(timeManager, gridView), gravity_(0),spatialParams_(&spatialParams) { - newSpatialParams_ = false; gravity_ = 0; if (GET_PARAM_FROM_GROUP(TypeTag, bool, Problem, EnableGravity)) gravity_[dim - 1] = - 9.81; } - - //! Destructor - virtual ~IMPESProblem2P() - { - if (newSpatialParams_) - { - delete spatialParams_; - } - } - /*! * \name Problem parameters */ @@ -204,8 +192,7 @@ private: GlobalPosition gravity_; // fluids and material properties - SpatialParams* spatialParams_; - bool newSpatialParams_; + Dune::shared_ptr<SpatialParams> spatialParams_; }; } diff --git a/dumux/decoupled/2p/transport/fv/fvsaturation2p.hh b/dumux/decoupled/2p/transport/fv/fvsaturation2p.hh index f783e8b790..9ddec50a46 100644 --- a/dumux/decoupled/2p/transport/fv/fvsaturation2p.hh +++ b/dumux/decoupled/2p/transport/fv/fvsaturation2p.hh @@ -401,26 +401,18 @@ public: DUNE_THROW(Dune::NotImplemented, "Velocity type not supported!"); } - capillaryFlux_ = new CapillaryFlux(problem); - gravityFlux_ = new GravityFlux(problem); - velocity_ = new Velocity(problem); + capillaryFlux_ = Dune::make_shared<CapillaryFlux>(problem); + gravityFlux_ = Dune::make_shared<GravityFlux>(problem); + velocity_ = Dune::make_shared<Velocity>(problem); vtkOutputLevel_ = GET_PARAM_FROM_GROUP(TypeTag, int, Vtk, OutputLevel); } - //! Destructor - ~FVSaturation2P() - { - delete capillaryFlux_; - delete gravityFlux_; - delete velocity_; - } - private: Problem& problem_; - Velocity* velocity_; - CapillaryFlux* capillaryFlux_; - GravityFlux* gravityFlux_; + Dune::shared_ptr<Velocity> velocity_; + Dune::shared_ptr<CapillaryFlux> capillaryFlux_; + Dune::shared_ptr<GravityFlux> gravityFlux_; int vtkOutputLevel_; diff --git a/dumux/decoupled/2p/transport/transportproblem2p.hh b/dumux/decoupled/2p/transport/transportproblem2p.hh index 330b660612..a4f89bf830 100644 --- a/dumux/decoupled/2p/transport/transportproblem2p.hh +++ b/dumux/decoupled/2p/transport/transportproblem2p.hh @@ -98,8 +98,7 @@ public: { cFLFactor_ = GET_PARAM_FROM_GROUP(TypeTag, Scalar, Impet, CFLFactor); - newSpatialParams_ = true; - spatialParams_ = new SpatialParams(gridView); + spatialParams_ = Dune::make_shared<SpatialParams>(gridView); gravity_ = 0; if (GET_PARAM_FROM_GROUP(TypeTag, bool, Problem, EnableGravity)) @@ -119,21 +118,11 @@ public: { cFLFactor_ = GET_PARAM_FROM_GROUP(TypeTag, Scalar, Impet, CFLFactor); - newSpatialParams_ = false; - gravity_ = 0; if (GET_PARAM_FROM_GROUP(TypeTag, bool, Problem, EnableGravity)) gravity_[dim - 1] = - 9.81; } - ~TransportProblem2P() - { - if (newSpatialParams_) - { - delete spatialParams_; - } - } - /*! * \name Problem parameters */ @@ -243,8 +232,7 @@ private: GlobalPosition gravity_; // material properties - SpatialParams* spatialParams_; - bool newSpatialParams_; + Dune::shared_ptr<SpatialParams> spatialParams_; Scalar cFLFactor_; }; diff --git a/dumux/decoupled/2p2c/cellData2p2c.hh b/dumux/decoupled/2p2c/cellData2p2c.hh index edb6f0ac9d..e2c9b69df4 100644 --- a/dumux/decoupled/2p2c/cellData2p2c.hh +++ b/dumux/decoupled/2p2c/cellData2p2c.hh @@ -84,13 +84,12 @@ protected: int globalIdx_; Scalar perimeter_; - FluidState* fluidState_; + Dune::shared_ptr<FluidState> fluidState_; FluxData fluxData_; public: //! Constructor for a local CellData object - CellData2P2C() : - fluidState_(0) + CellData2P2C() { for (int i = 0; i < numPhases;i++) { @@ -360,7 +359,7 @@ public: FluidState& manipulateFluidState() { if(!fluidState_) - fluidState_ = new FluidState; + fluidState_ = Dune::make_shared<FluidState>(); return *fluidState_; } diff --git a/dumux/decoupled/2p2c/cellData2p2cmultiphysics.hh b/dumux/decoupled/2p2c/cellData2p2cmultiphysics.hh index 0adafe8456..fdb4ee1a97 100644 --- a/dumux/decoupled/2p2c/cellData2p2cmultiphysics.hh +++ b/dumux/decoupled/2p2c/cellData2p2cmultiphysics.hh @@ -76,7 +76,7 @@ private: private: int subdomain_; int fluidStateType_; - SimpleFluidState* simpleFluidState_; + Dune::shared_ptr<SimpleFluidState> simpleFluidState_; // FluxData fluxData_; public: @@ -285,12 +285,11 @@ public: fluidStateType_ = simple; if(this->fluidState_) { - delete this->fluidState_; - this->fluidState_ = NULL; + this->fluidState_.template reset<FluidState>(0); } if(!simpleFluidState_) - simpleFluidState_ = new SimpleFluidState; + simpleFluidState_ = Dune::make_shared<SimpleFluidState>(); return *simpleFluidState_; } //! Allows manipulation of the complex fluid state @@ -303,12 +302,11 @@ public: fluidStateType_ = complex; if(simpleFluidState_) { - delete simpleFluidState_; - simpleFluidState_ = NULL; + simpleFluidState_.template reset<SimpleFluidState>(0); } if(!this->fluidState_) - this->fluidState_ = new FluidState; + this->fluidState_ = Dune::make_shared<FluidState>(); return *this->fluidState_; } diff --git a/dumux/decoupled/2p2c/fvpressure2p2cadaptive.hh b/dumux/decoupled/2p2c/fvpressure2p2cadaptive.hh index 47a0facf53..e3afcab4c1 100644 --- a/dumux/decoupled/2p2c/fvpressure2p2cadaptive.hh +++ b/dumux/decoupled/2p2c/fvpressure2p2cadaptive.hh @@ -228,7 +228,7 @@ protected: bool enableMPFA; //!< Enables mpfa method to calculate the fluxes near hanging nodes bool enableSecondHalfEdge; //!< If possible, 2 interaction volumes are used for the mpfa method near hanging nodes //! The 2p Mpfa pressure module, that is only used for the calulation of transmissibility of the second interaction volumes - FVMPFAL2PFABoundPressure2PAdaptive<TypeTag>* pressureModelAdaptive2p_; + Dune::shared_ptr<FVMPFAL2PFABoundPressure2PAdaptive<TypeTag> > pressureModelAdaptive2p_; }; @@ -1205,7 +1205,7 @@ int FVPressure2P2CAdaptive<TypeTag>::transmissibilityAdapter_(const Intersection if(!pressureModelAdaptive2p_) - pressureModelAdaptive2p_= new FVMPFAL2PFABoundPressure2PAdaptive<TypeTag>(problem()) ; + pressureModelAdaptive2p_= Dune::make_shared<FVMPFAL2PFABoundPressure2PAdaptive<TypeTag> >(problem()) ; // create Interaction Volume object Dumux::FVMPFALInteractionVolume<TypeTag> interactionVolume; diff --git a/dumux/decoupled/common/fv/fvtransport.hh b/dumux/decoupled/common/fv/fvtransport.hh index 1d711254e1..b1d8e55eb6 100644 --- a/dumux/decoupled/common/fv/fvtransport.hh +++ b/dumux/decoupled/common/fv/fvtransport.hh @@ -179,13 +179,7 @@ public: FVTransport(Problem& problem) : problem_(problem), switchNormals_(GET_PARAM_FROM_GROUP(TypeTag, bool, Impet, SwitchNormals)) { - evalCflFluxFunction_ = new EvalCflFluxFunction(problem); - } - - //! Destructor - ~FVTransport() - { - delete evalCflFluxFunction_; + evalCflFluxFunction_ = Dune::make_shared<EvalCflFluxFunction>(problem); } private: @@ -200,7 +194,7 @@ private: Problem& problem_; bool switchNormals_; - EvalCflFluxFunction* evalCflFluxFunction_; + Dune::shared_ptr<EvalCflFluxFunction> evalCflFluxFunction_; }; /*! \brief Calculate the update vector. diff --git a/dumux/decoupled/common/impetproblem.hh b/dumux/decoupled/common/impetproblem.hh index 28c221c534..d5522bb486 100644 --- a/dumux/decoupled/common/impetproblem.hh +++ b/dumux/decoupled/common/impetproblem.hh @@ -98,7 +98,6 @@ public: */ IMPETProblem(TimeManager &timeManager, const GridView &gridView) : gridView_(gridView), - grid_(0), bboxMin_(std::numeric_limits<double>::max()), bboxMax_(-std::numeric_limits<double>::max()), timeManager_(&timeManager), @@ -124,30 +123,18 @@ public: bboxMax_[i] = gridView.comm().max(bboxMax_[i]); } - pressModel_ = new PressureModel(asImp_()); + pressModel_ = Dune::make_shared<PressureModel>(asImp_()); - transportModel_ = new TransportModel(asImp_()); - model_ = new IMPETModel(asImp_()) ; + transportModel_ = Dune::make_shared<TransportModel>(asImp_()); + model_ = Dune::make_shared<IMPETModel>(asImp_()) ; // create an Object to handle adaptive grids if (adaptiveGrid) - gridAdapt_ = new GridAdaptModel(asImp_()); + gridAdapt_ = Dune::make_shared<GridAdaptModel>(asImp_()); - resultWriter_ = NULL; vtkOutputLevel_ = GET_PARAM_FROM_GROUP(TypeTag, int, Vtk, OutputLevel); } - //! destructor - virtual ~IMPETProblem () - { - delete pressModel_; - delete transportModel_; - delete model_; - delete resultWriter_; - if (adaptiveGrid) - delete gridAdapt_; - } - /*! * \brief Specifies which kind of boundary condition should be * used for which equation on a given boundary segment. @@ -774,7 +761,7 @@ public: std::cout << "Writing result file for current time step\n"; if (!resultWriter_) - resultWriter_ = new VtkMultiWriter(gridView_, asImp_().name()); + resultWriter_ = Dune::make_shared<VtkMultiWriter>(gridView_, asImp_().name()); if (adaptiveGrid) resultWriter_->gridChanged(); resultWriter_->beginWrite(timeManager().time() + timeManager().timeStepSize()); @@ -790,14 +777,14 @@ protected: VtkMultiWriter& resultWriter() { if (!resultWriter_) - resultWriter_ = new VtkMultiWriter(gridView_, asImp_().name()); + resultWriter_ = Dune::make_shared<VtkMultiWriter>(gridView_, asImp_().name()); return *resultWriter_; } //! \copydoc Dumux::IMPETProblem::resultWriter() VtkMultiWriter& resultWriter() const { if (!resultWriter_) - resultWriter_ = new VtkMultiWriter(gridView_, asImp_().name()); + resultWriter_ = Dune::make_shared<VtkMultiWriter>(gridView_, asImp_().name()); return *resultWriter_; } @@ -815,7 +802,7 @@ private: // for example. const GridView gridView_; // pointer to a possibly adaptive grid. - Grid* grid_; + Grid *grid_; GlobalPosition bboxMin_; GlobalPosition bboxMax_; @@ -824,15 +811,15 @@ private: Variables variables_; - PressureModel* pressModel_;//!< object including the pressure model - TransportModel* transportModel_;//!< object including the saturation model - IMPETModel* model_; + Dune::shared_ptr<PressureModel> pressModel_;//!< object including the pressure model + Dune::shared_ptr<TransportModel> transportModel_;//!< object including the saturation model + Dune::shared_ptr<IMPETModel> model_; - VtkMultiWriter *resultWriter_; + Dune::shared_ptr<VtkMultiWriter> resultWriter_; int outputInterval_; Scalar outputTimeInterval_; int vtkOutputLevel_; - GridAdaptModel* gridAdapt_; + Dune::shared_ptr<GridAdaptModel> gridAdapt_; }; } #endif diff --git a/dumux/decoupled/common/onemodelproblem.hh b/dumux/decoupled/common/onemodelproblem.hh index 64f57c8a31..67779909fd 100644 --- a/dumux/decoupled/common/onemodelproblem.hh +++ b/dumux/decoupled/common/onemodelproblem.hh @@ -94,7 +94,6 @@ public: : gridView_(gridView), bboxMin_(std::numeric_limits<double>::max()), bboxMax_(-std::numeric_limits<double>::max()), - deleteTimeManager_(true), variables_(gridView), outputInterval_(1) { @@ -108,11 +107,9 @@ public: } } - timeManager_ = new TimeManager(verbose); + timeManager_ = Dune::make_shared<TimeManager>(verbose); - model_ = new Model(asImp_()) ; - - resultWriter_ = NULL; + model_ = Dune::make_shared<Model>(asImp_()) ; } //! Constructs an object of type OneModelProblemProblem @@ -125,7 +122,6 @@ public: bboxMin_(std::numeric_limits<double>::max()), bboxMax_(-std::numeric_limits<double>::max()), timeManager_(&timeManager), - deleteTimeManager_(false), variables_(gridView), outputInterval_(1) { @@ -139,18 +135,7 @@ public: } } - model_ = new Model(asImp_()) ; - - resultWriter_ = NULL; - } - - //! destructor - virtual ~OneModelProblem () - { - delete model_; - delete resultWriter_; - if (deleteTimeManager_) - delete timeManager_; + model_ = Dune::make_shared<Model>(asImp_()) ; } /*! @@ -444,7 +429,7 @@ public: if (verbose && gridView().comm().rank() == 0) std::cout << "Writing result file for current time step\n"; if (!resultWriter_) - resultWriter_ = new VtkMultiWriter(gridView(), asImp_().name()); + resultWriter_ = Dune::make_shared<VtkMultiWriter>(gridView(), asImp_().name()); resultWriter_->beginWrite(timeManager().time() + timeManager().timeStepSize()); model().addOutputVtkFields(*resultWriter_); asImp_().addOutputVtkFields(); @@ -613,14 +598,14 @@ protected: VtkMultiWriter& resultWriter() { if (!resultWriter_) - resultWriter_ = new VtkMultiWriter(gridView_, asImp_().name()); + resultWriter_ = Dune::make_shared<VtkMultiWriter>(gridView_, asImp_().name()); return *resultWriter_; } VtkMultiWriter& resultWriter() const { if (!resultWriter_) - resultWriter_ = new VtkMultiWriter(gridView_, asImp_().name()); + resultWriter_ = Dune::make_shared<VtkMultiWriter>(gridView_, asImp_().name()); return *resultWriter_; } @@ -641,14 +626,13 @@ private: GlobalPosition bboxMin_; GlobalPosition bboxMax_; - TimeManager *timeManager_; - bool deleteTimeManager_; + Dune::shared_ptr<TimeManager> timeManager_; Variables variables_; - Model* model_; + Dune::shared_ptr<Model> model_; - VtkMultiWriter *resultWriter_; + Dune::shared_ptr<VtkMultiWriter> resultWriter_; int outputInterval_; }; -- GitLab