diff --git a/dumux/decoupled/1p/diffusion/diffusionproblem1p.hh b/dumux/decoupled/1p/diffusion/diffusionproblem1p.hh index 21b528d55ce5fd85f4f24a1961fca57cc49047c1..80584506d7fd2e8697cc6cba3354239971db001f 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 f9074dad6caeff9af71dd31a7cf8cb9067b1d594..bcedb25c8f50f17a95f4d3ab56a3527b46eb33c8 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 7d46bbfcf4d880ce576eb82f2789da23df149ba3..8dc3e6797883b6394a32558d38e7167ecfa4417d 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 f783e8b790aeb1ebd0b7b5ee8576cac809491003..9ddec50a461fd73fe1f652014fb9737030b14d72 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 330b660612e8166abe3182d72d72dbb69edf8133..a4f89bf830272ad3bc507db995b34e5b11f6ec9b 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 edb6f0ac9de27f337ff1150e5b1ca118e087082b..e2c9b69df481884361ba45d690ccf0d8c52ca3e1 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 0adafe8456a955a599d613ffe1602703d78c3513..fdb4ee1a97411c14c06736aa7627c6ebde2d4ab8 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 47a0facf5370c67f0c301fd9ebff0a3a808468ea..e3afcab4c1f9c7de579e198d9650c52f5afb964e 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 1d711254e16fb86294cfb6827fb8641f37fdb844..b1d8e55eb643cd35c2690529701b5daad928eb88 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 28c221c534c5c563edb628a23f38a843f640d8c5..d5522bb486ee9d8a25bb09b7e869ceb14a4f60ee 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 64f57c8a31cc5f0be852ac49548b88541ca12dc7..67779909fd535329d5b48c97dd4b2919bdcd96cb 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_; };