From 928801b7b1b65d2a93875034f00de003fa96f7f0 Mon Sep 17 00:00:00 2001 From: Timo Koch <timo.koch@iws.uni-stuttgart.de> Date: Tue, 20 Nov 2018 14:19:44 +0100 Subject: [PATCH] [gridvars] Unify for stationary and instationary problems --- dumux/discretization/fvgridvariables.hh | 59 ++++++++++++------------- 1 file changed, 28 insertions(+), 31 deletions(-) diff --git a/dumux/discretization/fvgridvariables.hh b/dumux/discretization/fvgridvariables.hh index 73f81d913e..039fe29d42 100644 --- a/dumux/discretization/fvgridvariables.hh +++ b/dumux/discretization/fvgridvariables.hh @@ -28,6 +28,8 @@ #include <memory> #include <cassert> +#include <dune/common/deprecated.hh> + namespace Dumux { /*! @@ -68,53 +70,53 @@ public: , gridFluxVarsCache_(*problem) {} - //! update all variables + //! initialize all variables (stationary case) template<class SolutionVector> - void update(const SolutionVector& curSol, bool forceFluxCacheUpdate = false) + void init(const SolutionVector& curSol) { // resize and update the volVars with the initial solution curGridVolVars_.update(*fvGridGeometry_, curSol); - // update the flux variables caches - gridFluxVarsCache_.update(*fvGridGeometry_, curGridVolVars_, curSol, forceFluxCacheUpdate); + // update the flux variables caches (always force flux cache update on initialization) + gridFluxVarsCache_.update(*fvGridGeometry_, curGridVolVars_, curSol, true); + + // set the volvars of the previous time step in case we have an instationary problem + // note that this means some memory overhead in the case of enabled caching, however + // this it outweighted by the advantage of having a single grid variables object for + // stationary and instationary problems + prevGridVolVars_ = curGridVolVars_; } - //! update all variables after grid adaption + //! initialize all variables (instationary case) template<class SolutionVector> - void updateAfterGridAdaption(const SolutionVector& curSol) + DUNE_DEPRECATED_MSG("Use init(sol) instead. The class now works without modification for stationary and instationary cases.") + void init(const SolutionVector& curSol, const SolutionVector& initSol) { - // update (always force flux cache update as the grid changed) - update(curSol, true); - - // for instationary problems also update the variables - // for the previous time step to the new grid - if (!problemIsStationary_) - prevGridVolVars_ = curGridVolVars_; + // initialize current volvars and the flux var cache + init(initSol); } - //! initialize all variables (stationary case) + //! update all variables template<class SolutionVector> - void init(const SolutionVector& curSol) + void update(const SolutionVector& curSol, bool forceFluxCacheUpdate = false) { // resize and update the volVars with the initial solution curGridVolVars_.update(*fvGridGeometry_, curSol); - // update the flux variables caches (always force flux cache update on initialization) - gridFluxVarsCache_.update(*fvGridGeometry_, curGridVolVars_, curSol, true); + // update the flux variables caches + gridFluxVarsCache_.update(*fvGridGeometry_, curGridVolVars_, curSol, forceFluxCacheUpdate); } - //! initialize all variables (instationary case) + //! update all variables after grid adaption template<class SolutionVector> - void init(const SolutionVector& curSol, const SolutionVector& initSol) + void updateAfterGridAdaption(const SolutionVector& curSol) { - // remember that we have a stationary problem - problemIsStationary_ = false; - - // initialize current volvars and the flux var cache - init(curSol); + // update (always force flux cache update as the grid changed) + update(curSol, true); - // update the old time step vol vars with the initial solution - prevGridVolVars_.update(*fvGridGeometry_, initSol); + // for instationary problems also update the variables + // for the previous time step to the new grid + prevGridVolVars_ = curGridVolVars_; } /*! @@ -123,7 +125,6 @@ public: */ void advanceTimeStep() { - assert(!problemIsStationary_); prevGridVolVars_ = curGridVolVars_; } @@ -131,8 +132,6 @@ public: template<class SolutionVector> void resetTimeStep(const SolutionVector& solution) { - assert(!problemIsStationary_); - // set the new time step vol vars to old vol vars curGridVolVars_ = prevGridVolVars_; @@ -177,8 +176,6 @@ private: GridVolumeVariables prevGridVolVars_; //!< the previous time step's volume variables (primary and secondary variables) GridFluxVariablesCache gridFluxVarsCache_; //!< the flux variables cache - - bool problemIsStationary_ = true; }; } // end namespace Dumux -- GitLab