From f74a044d648e17a675484fa69467e06db3fda728 Mon Sep 17 00:00:00 2001 From: Markus Wolff <markus.wolff@twt-gmbh.de> Date: Tue, 10 Aug 2010 06:46:47 +0000 Subject: [PATCH] changed asImp_() function to return reference instead of pointer git-svn-id: svn://svn.iws.uni-stuttgart.de/DUMUX/dumux/trunk@4036 2fb0f335-1f38-0410-981e-8018bf24f1b0 --- .../2p/diffusion/diffusionproblem2p.hh | 14 +----- dumux/decoupled/2p/impes/impesproblem2p.hh | 9 +--- .../2p/transport/transportproblem2p.hh | 10 +---- dumux/decoupled/common/impesproblem.hh | 44 +++++++++---------- dumux/decoupled/common/onemodelproblem.hh | 44 ++++--------------- 5 files changed, 34 insertions(+), 87 deletions(-) diff --git a/dumux/decoupled/2p/diffusion/diffusionproblem2p.hh b/dumux/decoupled/2p/diffusion/diffusionproblem2p.hh index cf69e6a179..3421f40e82 100644 --- a/dumux/decoupled/2p/diffusion/diffusionproblem2p.hh +++ b/dumux/decoupled/2p/diffusion/diffusionproblem2p.hh @@ -113,7 +113,7 @@ public: */ Scalar temperature() const { - return asImp_()->temperature(); + return this->asImp_()->temperature(); } ; @@ -147,18 +147,6 @@ public: // \} private: - //! Returns the implementation of the problem (i.e. static polymorphism) - Implementation *asImp_() - { - return static_cast<Implementation *> (this); - } - - //! \copydoc asImp_() - const Implementation *asImp_() const - { - return static_cast<const Implementation *> (this); - } - GlobalPosition gravity_; // fluids and material properties diff --git a/dumux/decoupled/2p/impes/impesproblem2p.hh b/dumux/decoupled/2p/impes/impesproblem2p.hh index f1c82e0841..3eb33684c6 100644 --- a/dumux/decoupled/2p/impes/impesproblem2p.hh +++ b/dumux/decoupled/2p/impes/impesproblem2p.hh @@ -98,7 +98,7 @@ public: * This method MUST be overwritten by the actual problem. */ Scalar temperature() const - { return asImp_()->temperature(); }; + { return this->asImp_()->temperature(); }; /*! * \brief Returns the acceleration due to gravity. @@ -126,13 +126,6 @@ public: private: //! Returns the implementation of the problem (i.e. static polymorphism) - Implementation *asImp_() - { return static_cast<Implementation *>(this); } - - //! \copydoc asImp_() - const Implementation *asImp_() const - { return static_cast<const Implementation *>(this); } - GlobalPosition gravity_; // fluids and material properties diff --git a/dumux/decoupled/2p/transport/transportproblem2p.hh b/dumux/decoupled/2p/transport/transportproblem2p.hh index 795cad9bd1..35b5fd6efd 100644 --- a/dumux/decoupled/2p/transport/transportproblem2p.hh +++ b/dumux/decoupled/2p/transport/transportproblem2p.hh @@ -77,7 +77,7 @@ public: * This method MUST be overwritten by the actual problem. */ Scalar temperature() const - { return asImp_()->temperature(); }; + { return this->asImp_()->temperature(); }; /*! * \brief Returns the acceleration due to gravity. @@ -104,14 +104,6 @@ public: // \} private: - //! Returns the implementation of the problem (i.e. static polymorphism) - Implementation *asImp_() - { return static_cast<Implementation *>(this); } - - //! \copydoc asImp_() - const Implementation *asImp_() const - { return static_cast<const Implementation *>(this); } - GlobalPosition gravity_; // fluids and material properties diff --git a/dumux/decoupled/common/impesproblem.hh b/dumux/decoupled/common/impesproblem.hh index 843fa1b829..727a0ff986 100644 --- a/dumux/decoupled/common/impesproblem.hh +++ b/dumux/decoupled/common/impesproblem.hh @@ -98,19 +98,19 @@ public: variables_(gridView), dt_(0) { -// // calculate the bounding box of the grid view -// VertexIterator vIt = gridView.template begin<dim>(); -// const VertexIterator vEndIt = gridView.template end<dim>(); -// for (; vIt!=vEndIt; ++vIt) { -// for (int i=0; i<dim; i++) { -// bboxMin_[i] = std::min(bboxMin_[i], vIt->geometry().corner(0)[i]); -// bboxMax_[i] = std::max(bboxMax_[i], vIt->geometry().corner(0)[i]); -// } -// } - - pressModel_ = new PressureModel(*asImp_()); - satModel_ = new SaturationModel(*asImp_()); - model_ = new IMPESModel(*asImp_()) ; + // calculate the bounding box of the grid view + VertexIterator vIt = gridView.template begin<dim>(); + const VertexIterator vEndIt = gridView.template end<dim>(); + for (; vIt!=vEndIt; ++vIt) { + for (int i=0; i<dim; i++) { + bboxMin_[i] = std::min(bboxMin_[i], vIt->geometry().corner(0)[i]); + bboxMax_[i] = std::max(bboxMax_[i], vIt->geometry().corner(0)[i]); + } + } + + pressModel_ = new PressureModel(asImp_()); + satModel_ = new SaturationModel(asImp_()); + model_ = new IMPESModel(asImp_()) ; } //! destructor @@ -157,7 +157,7 @@ public: { // allocate temporary vectors for the updates typedef TransportSolutionType Solution; - Solution k1 = (*asImp_()).variables().transportedQuantity(); + Solution k1 = asImp_().variables().transportedQuantity(); Scalar t = timeManager().time(); @@ -182,7 +182,7 @@ public: timeManager().setTimeStepSize(dt_); // explicit Euler: Sat <- Sat + dt*N(Sat) - (*asImp_()).variables().transportedQuantity() += (k1 *= timeManager().timeStepSize()); + asImp_().variables().transportedQuantity() += (k1 *= timeManager().timeStepSize()); } /*! @@ -195,7 +195,7 @@ public: */ void postTimeStep() { - (*asImp_()).pressureModel().updateMaterialLaws(); + asImp_().pressureModel().updateMaterialLaws(); }; /*! @@ -376,7 +376,7 @@ public: typedef Dumux::Restart Restarter; Restarter res; - res.serializeBegin(*asImp_()); + res.serializeBegin(asImp_()); std::cerr << "Serialize to file " << res.fileName() << "\n"; timeManager_.serialize(res); @@ -397,7 +397,7 @@ public: typedef Dumux::Restart Restarter; Restarter res; - res.deserializeBegin(*asImp_(), t); + res.deserializeBegin(asImp_(), t); std::cerr << "Deserialize from file " << res.fileName() << "\n"; timeManager_.deserialize(res); @@ -423,12 +423,12 @@ public: protected: //! Returns the implementation of the problem (i.e. static polymorphism) - Implementation *asImp_() - { return static_cast<Implementation *>(this); } + Implementation &asImp_() + { return *static_cast<Implementation *>(this); } //! \copydoc asImp_() - const Implementation *asImp_() const - { return static_cast<const Implementation *>(this); } + const Implementation &asImp_() const + { return *static_cast<const Implementation *>(this); } VtkMultiWriter& resultWriter() { diff --git a/dumux/decoupled/common/onemodelproblem.hh b/dumux/decoupled/common/onemodelproblem.hh index 5d70c800b2..0a8f16437c 100644 --- a/dumux/decoupled/common/onemodelproblem.hh +++ b/dumux/decoupled/common/onemodelproblem.hh @@ -96,8 +96,7 @@ public: bboxMax_(-std::numeric_limits<double>::max()), timeManager_(verbose), variables_(gridView), - dt_(0), - resultWriter_(asImp_()->name()) + dt_(0) { // // calculate the bounding box of the grid view // VertexIterator vIt = gridView.template begin<dim>(); @@ -109,7 +108,7 @@ public: // } // } - model_ = new Model(*asImp_()) ; + model_ = new Model(asImp_()) ; } //! destructor @@ -118,29 +117,6 @@ public: delete model_; } - /*! - * \name Simulation steering - */ - // \{ - - /*! - * \brief Start the simulation procedure. - * - * This method is usually called by the main() function and simply - * uses Dumux::TimeManager::runSimulation() to do the actual - * work. - */ -/* - bool simulate(Scalar dtInitial, Scalar tEnd) - { - // set the initial time step and the time where the simulation ends - timeManager_.setEndTime(tEnd); - timeManager_.setTimeStepSize(dtInitial); - timeManager_.runSimulation(*asImp_()); - return true; - }; -*/ - /*! * \brief Called by the Dumux::TimeManager in order to @@ -174,7 +150,7 @@ public: { // allocate temporary vectors for the updates typedef typename Model::SolutionType Solution; - Solution k1 = (*asImp_()).variables().saturation(); + Solution k1 = asImp_().variables().saturation(); dt_ = 1e100; Scalar t = timeManager().time(); @@ -187,7 +163,7 @@ public: timeManager().setTimeStepSize(dt_); // explicit Euler: Sat <- Sat + dt*N(Sat) - (*asImp_()).variables().saturation() += (k1 *= dt_); + asImp_().variables().saturation() += (k1 *= dt_); } /*! @@ -382,9 +358,7 @@ public: typedef Dumux::Restart Restarter; Restarter res; - res.deserializeBegin(gridView(), - asImp_()->name(), - t); + res.deserializeBegin(asImp_(), t); std::cerr << "Deserialize from file " << res.fileName() << "\n"; timeManager_.deserialize(res); @@ -398,12 +372,12 @@ public: protected: //! Returns the implementation of the problem (i.e. static polymorphism) - Implementation *asImp_() - { return static_cast<Implementation *>(this); } + Implementation &asImp_() + { return *static_cast<Implementation *>(this); } //! \copydoc asImp_() - const Implementation *asImp_() const - { return static_cast<const Implementation *>(this); } + const Implementation &asImp_() const + { return *static_cast<const Implementation *>(this); } VtkMultiWriter& resultWriter() { -- GitLab