diff --git a/dumux/discretization/box/elementvolumevariables.hh b/dumux/discretization/box/elementvolumevariables.hh index 83bf970d29db07c657fce480e070c26803ffa46c..7620bd076c541477cdf2b314317dfe7c2fc11dfc 100644 --- a/dumux/discretization/box/elementvolumevariables.hh +++ b/dumux/discretization/box/elementvolumevariables.hh @@ -79,7 +79,8 @@ public: // function to prepare the vol vars within the element void bindElement(const Element& element, const FVElementGeometry& fvGeometry, - const SolutionVector& sol) + const SolutionVector& sol, + const bool isOldSol = false) { eIdx_ = globalVolVars().problem_().elementMapper().index(element); } @@ -126,7 +127,8 @@ public: // specialization for box models void bindElement(const Element& element, const FVElementGeometry& fvGeometry, - const SolutionVector& sol) + const SolutionVector& sol, + const bool isOldSol = false) { // get the solution at the dofs of the element auto elemSol = globalVolVars().problem_().model().elementSolution(element, sol); @@ -137,7 +139,7 @@ public: { // TODO: INTERFACE SOLVER // globalVolVars().problem_().model().boxInterfaceConditionSolver().updateScvVolVars(element, scv, sol); - volumeVariables_[scv.index()].update(elemSol, globalVolVars().problem_(), element, scv); + volumeVariables_[scv.index()].update(elemSol, globalVolVars().problem_(), element, scv, isOldSol); } } diff --git a/dumux/discretization/box/globalvolumevariables.hh b/dumux/discretization/box/globalvolumevariables.hh index fe77856b8e9538c407a992cfd45d6b6ca8158635..e6c98acf7aba3376313e904bb758a4a3e0cac4cf 100644 --- a/dumux/discretization/box/globalvolumevariables.hh +++ b/dumux/discretization/box/globalvolumevariables.hh @@ -96,13 +96,13 @@ public: friend inline ElementVolumeVariables localView(const BoxGlobalVolumeVariables& global) { return ElementVolumeVariables(global); } -private: const VolumeVariables& volVars(const IndexType eIdx, const IndexType scvIdx) const { return volumeVariables_[eIdx][scvIdx]; } VolumeVariables& volVars(const IndexType eIdx, const IndexType scvIdx) { return volumeVariables_[eIdx][scvIdx]; } + private: const Problem& problem_() const { return *problemPtr_; } diff --git a/dumux/discretization/cellcentered/globalvolumevariables.hh b/dumux/discretization/cellcentered/globalvolumevariables.hh index 8a0a4ef294d95ebc467f980de90d8d52c8ef0305..b3ca5cfaadb00d922523ddaf75bd1f342137cdee 100644 --- a/dumux/discretization/cellcentered/globalvolumevariables.hh +++ b/dumux/discretization/cellcentered/globalvolumevariables.hh @@ -118,6 +118,15 @@ public: VolumeVariables& volVars(const IndexType scvIdx) { return volumeVariables_[scvIdx]; } + + // required for compatibility with the box method + const VolumeVariables& volVars(const IndexType dummyElementIdx, const IndexType scvIdx) const + { return volumeVariables_[scvIdx]; } + + // required for compatibility with the box method + VolumeVariables& volVars(const IndexType dummyElementIdx, const IndexType scvIdx) + { return volumeVariables_[scvIdx]; } + private: const Problem& problem_() const { return *problemPtr_; } diff --git a/dumux/discretization/cellcentered/tpfa/elementvolumevariables.hh b/dumux/discretization/cellcentered/tpfa/elementvolumevariables.hh index 8a6c442dc82e6ed0399d00016705e62a1dd564b5..d07fd1eef97243299e1c0b09b2da3f1d88ea7e69 100644 --- a/dumux/discretization/cellcentered/tpfa/elementvolumevariables.hh +++ b/dumux/discretization/cellcentered/tpfa/elementvolumevariables.hh @@ -76,7 +76,8 @@ public: // function to prepare the vol vars within the element void bindElement(const Element& element, const FVElementGeometry& fvGeometry, - const SolutionVector& sol) + const SolutionVector& sol, + const bool isOldSol = false) {} //! The global volume variables object we are a restriction of @@ -201,7 +202,8 @@ public: // specialization for cc models void bindElement(const Element& element, const FVElementGeometry& fvGeometry, - const SolutionVector& sol) + const SolutionVector& sol, + const bool isOldSol = false) { clear(); @@ -214,7 +216,8 @@ public: volumeVariables_[0].update(globalVolVars().problem_().model().elementSolution(element, sol), globalVolVars().problem_(), element, - scv); + scv, + isOldSol); volVarIndices_[0] = scv.index(); } diff --git a/dumux/implicit/box/localjacobian.hh b/dumux/implicit/box/localjacobian.hh index f032f83b6921bea7860befd25f201b5c2e5cdd83..eb66f12372238ed5dc66dda91a84d3d195f45b79 100644 --- a/dumux/implicit/box/localjacobian.hh +++ b/dumux/implicit/box/localjacobian.hh @@ -119,7 +119,7 @@ public: curElemVolVars.bind(element, fvGeometry, this->model_().curSol()); auto prevElemVolVars = localView(this->model_().prevGlobalVolVars()); - prevElemVolVars.bindElement(element, fvGeometry, this->model_().prevSol()); + prevElemVolVars.bindElement(element, fvGeometry, this->model_().prevSol(), /*isOldSol*/true); auto elemFluxVarsCache = localView(this->model_().globalFluxVarsCache()); elemFluxVarsCache.bind(element, fvGeometry, curElemVolVars); diff --git a/dumux/implicit/cellcentered/localjacobian.hh b/dumux/implicit/cellcentered/localjacobian.hh index da7b6dd878e9fa39bd87415be4c49cdcf76a8595..f43b18bc239a3c859c843090ebee9538e84c861d 100644 --- a/dumux/implicit/cellcentered/localjacobian.hh +++ b/dumux/implicit/cellcentered/localjacobian.hh @@ -132,7 +132,7 @@ public: curElemVolVars.bind(element, fvGeometry, this->model_().curSol()); auto prevElemVolVars = localView(this->model_().prevGlobalVolVars()); - prevElemVolVars.bindElement(element, fvGeometry, this->model_().prevSol()); + prevElemVolVars.bindElement(element, fvGeometry, this->model_().prevSol(), /*isOldSol*/true); auto elemFluxVarsCache = localView(this->model_().globalFluxVarsCache()); elemFluxVarsCache.bind(element, fvGeometry, curElemVolVars); diff --git a/dumux/implicit/localresidual.hh b/dumux/implicit/localresidual.hh index 207c47b0790100ad5462cb998ff87654c113690b..b45442c870a20498a45ee9b86e8449b58e3795c0 100644 --- a/dumux/implicit/localresidual.hh +++ b/dumux/implicit/localresidual.hh @@ -108,7 +108,7 @@ public: curElemVolVars.bind(element, fvGeometry, problem().model().curSol()); auto prevElemVolVars = localView(problem().model().prevGlobalVolVars()); - prevElemVolVars.bindElement(element, fvGeometry, problem().model().prevSol()); + prevElemVolVars.bindElement(element, fvGeometry, problem().model().prevSol(), true); auto elemFluxVarsCache = localView(problem().model().globalFluxVarsCache()); elemFluxVarsCache.bindElement(element, fvGeometry, curElemVolVars); @@ -138,7 +138,7 @@ public: curElemVolVars.bindElement(element, fvGeometry, problem().model().curSol()); auto prevElemVolVars = localView(problem().model().prevGlobalVolVars()); - prevElemVolVars.bindElement(element, fvGeometry, problem().model().prevSol()); + prevElemVolVars.bindElement(element, fvGeometry, problem().model().prevSol(), true); asImp_().evalStorage_(fvGeometry, prevElemVolVars, curElemVolVars); } diff --git a/dumux/porousmediumflow/2p2c/implicit/model.hh b/dumux/porousmediumflow/2p2c/implicit/model.hh index 91d1579ba0e9ac21689a15e30b719a19d4846e45..a69f0854341f3e08690f96d2fccffab72da63d43 100644 --- a/dumux/porousmediumflow/2p2c/implicit/model.hh +++ b/dumux/porousmediumflow/2p2c/implicit/model.hh @@ -207,6 +207,8 @@ public: auto fvGeometry = localView(this->globalFvGeometry()); fvGeometry.bindElement(element); + const auto eIdx = this->problem_().elementMapper().index(element); + if (switchFlag_) { for (auto&& scv : scvs(fvGeometry)) @@ -215,7 +217,7 @@ public: if (priVarSwitch_().wasSwitched(dofIdxGlobal)) { const auto elemSol = this->elementSolution(element, this->curSol()); - this->nonConstCurGlobalVolVars().volVars(scv.index()).update(elemSol, + this->nonConstCurGlobalVolVars().volVars(eIdx, scv.index()).update(elemSol, this->problem_(), element, scv); @@ -223,9 +225,11 @@ public: } } - // handle the boundary volume variables - for (auto&& scvf : scvfs(fvGeometry)) + if(!isBox) { + // handle the boundary volume variables + for (auto&& scvf : scvfs(fvGeometry)) + { // if we are not on a boundary, skip the rest if (!scvf.boundary()) continue; @@ -238,8 +242,9 @@ public: const auto& insideScv = fvGeometry.scv(insideScvIdx); const auto elemSol = ElementSolutionVector{this->problem_().dirichlet(element, scvf)}; - this->nonConstCurGlobalVolVars().volVars(scvf.outsideScvIdx()).update(elemSol, this->problem_(), element, insideScv); + this->nonConstCurGlobalVolVars().volVars(eIdx, scvf.outsideScvIdx()).update(elemSol, this->problem_(), element, insideScv); } + } } } } diff --git a/dumux/porousmediumflow/2p2c/implicit/volumevariables.hh b/dumux/porousmediumflow/2p2c/implicit/volumevariables.hh index 3ade74813bbf4db9acd9d7362079c3e09f2eeb00..a16e6921a350152710d3fe3654509209c4c5569b 100644 --- a/dumux/porousmediumflow/2p2c/implicit/volumevariables.hh +++ b/dumux/porousmediumflow/2p2c/implicit/volumevariables.hh @@ -116,11 +116,12 @@ public: void update(const ElementSolution &elemSol, const Problem &problem, const Element &element, - const SubControlVolume& scv) + const SubControlVolume& scv, + const bool isOldSol = false) { ParentType::update(elemSol, problem, element, scv); - completeFluidState(elemSol, problem, element, scv, fluidState_); + completeFluidState(elemSol, problem, element, scv, fluidState_, isOldSol); ///////////// // calculate the remaining quantities @@ -165,12 +166,13 @@ public: const Problem& problem, const Element& element, const SubControlVolume& scv, - FluidState& fluidState) + FluidState& fluidState, + const bool isOldSol) { Scalar t = ParentType::temperature(elemSol, problem, element, scv); fluidState.setTemperature(t); - auto phasePresence = problem.model().priVarSwitch().phasePresence(scv.dofIndex()); + auto phasePresence = problem.model().priVarSwitch().phasePresence(scv.dofIndex(), isOldSol); const auto& priVars = ParentType::extractDofPriVars(elemSol, scv); ///////////// diff --git a/dumux/porousmediumflow/compositional/primaryvariableswitch.hh b/dumux/porousmediumflow/compositional/primaryvariableswitch.hh index 6a031ea3e8adcc7f604908abfd50679307b0e556..df1feba264e2bfd2f58d39b264ea59e3e4875baf 100644 --- a/dumux/porousmediumflow/compositional/primaryvariableswitch.hh +++ b/dumux/porousmediumflow/compositional/primaryvariableswitch.hh @@ -84,9 +84,9 @@ public: oldPhasePresence_ = phasePresence_; } - int phasePresence(IndexType dofIdxGlobal) const + int phasePresence(IndexType dofIdxGlobal, const bool isOldSol = false) const { - return phasePresence_[dofIdxGlobal]; + return isOldSol ? oldPhasePresence_[dofIdxGlobal] : phasePresence_[dofIdxGlobal]; } bool wasSwitched(IndexType dofIdxGlobal) const @@ -151,24 +151,24 @@ public: auto dofIdxGlobal = scv.dofIndex(); if (!visited_[dofIdxGlobal]) { + visited_[dofIdxGlobal] = true; + // Note this implies that volume variables don't differ // in any sub control volume associated with the dof! - visited_[dofIdxGlobal] = true; // Compute temporary volVars on which grounds we decide // if we need to switch the primary variables auto&& volVars = elemVolVars[scv]; volVars.update(curElemSol, problem, element, scv); - if (asImp_().update_(curSol[dofIdxGlobal], volVars, dofIdxGlobal, scv.dofPosition())) + if(asImp_().update_(curSol[dofIdxGlobal], volVars, dofIdxGlobal, scv.dofPosition())) switched = true; - } } } // make sure that if there was a variable switch in an // other partition we will also set the switch flag for our partition. - if (problem.gridView().comm().size() > 1) + if(problem.gridView().comm().size() > 1) switched = problem.gridView().comm().max(switched); return switched; @@ -186,6 +186,8 @@ public: auto fvGeometry = localView(problem.model().globalFvGeometry()); fvGeometry.bindElement(element); + const auto eIdx = problem.model().elementMapper().index(element); + auto curElemSol = problem.model().elementSolution(element, curSol); auto& curGlobalVolVars = problem.model().nonConstCurGlobalVolVars(); @@ -193,19 +195,18 @@ public: for (auto&& scv : scvs(fvGeometry)) { auto dofIdxGlobal = scv.dofIndex(); - if (!visited_[dofIdxGlobal]) + + // get volVars on which grounds we decide + // if we need to switch the primary variables + auto&& volVars = curGlobalVolVars.volVars(eIdx, scv.index()); + volVars.update(curElemSol, problem, element, scv); + + if(!visited_[dofIdxGlobal]) { - // Note this implies that volume variables don't differ - // in any sub control volume associated with the dof! visited_[dofIdxGlobal] = true; - // Compute temporary volVars on which grounds we decide - // if we need to switch the primary variables - auto&& volVars = curGlobalVolVars.volVars(scv.index()); - volVars.update(curElemSol, problem, element, scv); - - if (asImp_().update_(curSol[dofIdxGlobal], volVars, dofIdxGlobal, scv.dofPosition())) - switched = true; + if(asImp_().update_(curSol[dofIdxGlobal], volVars, dofIdxGlobal, scv.dofPosition())) + switched = true; } } }