From aafb803f4453b40b70d07421d654b08bcc3f036a Mon Sep 17 00:00:00 2001 From: Kilian Weishaupt Date: Fri, 30 Jun 2017 11:43:48 +0200 Subject: [PATCH 1/6] [compositional] Re-introduce bool "isOldSol" * During the update of the volVars, one has to destinguish between the old and new solution in order to pick the correct phasePresence given by the primaryVariableSwitch * This only matters when globalVolVarCaching is turned off --- .../cellcentered/tpfa/elementvolumevariables.hh | 9 ++++++--- dumux/implicit/cellcentered/localjacobian.hh | 2 +- .../porousmediumflow/2p2c/implicit/volumevariables.hh | 10 ++++++---- .../compositional/primaryvariableswitch.hh | 4 ++-- 4 files changed, 15 insertions(+), 10 deletions(-) diff --git a/dumux/discretization/cellcentered/tpfa/elementvolumevariables.hh b/dumux/discretization/cellcentered/tpfa/elementvolumevariables.hh index 8a6c442dc8..d07fd1eef9 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/cellcentered/localjacobian.hh b/dumux/implicit/cellcentered/localjacobian.hh index da7b6dd878..f43b18bc23 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/porousmediumflow/2p2c/implicit/volumevariables.hh b/dumux/porousmediumflow/2p2c/implicit/volumevariables.hh index 3ade74813b..a16e6921a3 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 6a031ea3e8..5c7f5357d4 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 -- GitLab From 8d8cc118f81cd1754090b556d2de3822305956f1 Mon Sep 17 00:00:00 2001 From: Kilian Weishaupt Date: Fri, 30 Jun 2017 13:56:36 +0200 Subject: [PATCH 2/6] [globalVolVars] Unify interface for box/cc * volVars can now always be called with (eIdx, scvIdx) * allows to use the box method with globalVolumeVariablesCache --- .../box/globalvolumevariables.hh | 2 +- .../cellcentered/globalvolumevariables.hh | 9 +++++ dumux/porousmediumflow/2p2c/implicit/model.hh | 39 +++++++++++-------- .../compositional/primaryvariableswitch.hh | 4 +- 4 files changed, 35 insertions(+), 19 deletions(-) diff --git a/dumux/discretization/box/globalvolumevariables.hh b/dumux/discretization/box/globalvolumevariables.hh index fe77856b8e..e6c98acf7a 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 8a0a4ef294..b3ca5cfaad 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/porousmediumflow/2p2c/implicit/model.hh b/dumux/porousmediumflow/2p2c/implicit/model.hh index 91d1579ba0..831ac28c55 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,23 +225,26 @@ public: } } - // handle the boundary volume variables - for (auto&& scvf : scvfs(fvGeometry)) + if(!isBox) { - // if we are not on a boundary, skip the rest - if (!scvf.boundary()) - continue; - - // check if boundary is a pure dirichlet boundary - const auto bcTypes = this->problem_().boundaryTypes(element, scvf); - if (bcTypes.hasOnlyDirichlet()) - { - const auto insideScvIdx = scvf.insideScvIdx(); - 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); - } + // handle the boundary volume variables + for (auto&& scvf : scvfs(fvGeometry)) + { + // if we are not on a boundary, skip the rest + if (!scvf.boundary()) + continue; + + // check if boundary is a pure dirichlet boundary + const auto bcTypes = this->problem_().boundaryTypes(element, scvf); + if (bcTypes.hasOnlyDirichlet()) + { + const auto insideScvIdx = scvf.insideScvIdx(); + const auto& insideScv = fvGeometry.scv(insideScvIdx); + const auto elemSol = ElementSolutionVector{this->problem_().dirichlet(element, scvf)}; + + this->nonConstCurGlobalVolVars().volVars(eIdx, scvf.outsideScvIdx()).update(elemSol, this->problem_(), element, insideScv); + } + } } } } diff --git a/dumux/porousmediumflow/compositional/primaryvariableswitch.hh b/dumux/porousmediumflow/compositional/primaryvariableswitch.hh index 5c7f5357d4..5b8fe28755 100644 --- a/dumux/porousmediumflow/compositional/primaryvariableswitch.hh +++ b/dumux/porousmediumflow/compositional/primaryvariableswitch.hh @@ -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(); @@ -200,7 +202,7 @@ public: 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()); + auto&& volVars = curGlobalVolVars.volVars(eIdx, scv.index()); volVars.update(curElemSol, problem, element, scv); if (asImp_().update_(curSol[dofIdxGlobal], volVars, dofIdxGlobal, scv.dofPosition())) -- GitLab From 3cd6fa79449e1c2eed3d10881a9ad30e595b86d2 Mon Sep 17 00:00:00 2001 From: Kilian Weishaupt Date: Fri, 30 Jun 2017 14:00:47 +0200 Subject: [PATCH 3/6] [compositional][priVarSwitch] Remove check for visited dof * when caching is enabled and using box, the volvars of each single scv must be updated, the process of updating must not be stopped after the dof has been visited once --- .../compositional/primaryvariableswitch.hh | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/dumux/porousmediumflow/compositional/primaryvariableswitch.hh b/dumux/porousmediumflow/compositional/primaryvariableswitch.hh index 5b8fe28755..1739584717 100644 --- a/dumux/porousmediumflow/compositional/primaryvariableswitch.hh +++ b/dumux/porousmediumflow/compositional/primaryvariableswitch.hh @@ -195,12 +195,7 @@ public: for (auto&& scv : scvs(fvGeometry)) { auto dofIdxGlobal = scv.dofIndex(); - 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 + // 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); @@ -208,7 +203,6 @@ public: if (asImp_().update_(curSol[dofIdxGlobal], volVars, dofIdxGlobal, scv.dofPosition())) switched = true; - } } } -- GitLab From 4342d852f80c3dd6187aa731793daef0eaa3cd5c Mon Sep 17 00:00:00 2001 From: Kilian Weishaupt Date: Fri, 30 Jun 2017 14:07:08 +0200 Subject: [PATCH 4/6] [2p2c][model] Fix indentation --- dumux/porousmediumflow/2p2c/implicit/model.hh | 28 +++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/dumux/porousmediumflow/2p2c/implicit/model.hh b/dumux/porousmediumflow/2p2c/implicit/model.hh index 831ac28c55..a69f085434 100644 --- a/dumux/porousmediumflow/2p2c/implicit/model.hh +++ b/dumux/porousmediumflow/2p2c/implicit/model.hh @@ -230,20 +230,20 @@ public: // handle the boundary volume variables for (auto&& scvf : scvfs(fvGeometry)) { - // if we are not on a boundary, skip the rest - if (!scvf.boundary()) - continue; - - // check if boundary is a pure dirichlet boundary - const auto bcTypes = this->problem_().boundaryTypes(element, scvf); - if (bcTypes.hasOnlyDirichlet()) - { - const auto insideScvIdx = scvf.insideScvIdx(); - const auto& insideScv = fvGeometry.scv(insideScvIdx); - const auto elemSol = ElementSolutionVector{this->problem_().dirichlet(element, scvf)}; - - this->nonConstCurGlobalVolVars().volVars(eIdx, scvf.outsideScvIdx()).update(elemSol, this->problem_(), element, insideScv); - } + // if we are not on a boundary, skip the rest + if (!scvf.boundary()) + continue; + + // check if boundary is a pure dirichlet boundary + const auto bcTypes = this->problem_().boundaryTypes(element, scvf); + if (bcTypes.hasOnlyDirichlet()) + { + const auto insideScvIdx = scvf.insideScvIdx(); + const auto& insideScv = fvGeometry.scv(insideScvIdx); + const auto elemSol = ElementSolutionVector{this->problem_().dirichlet(element, scvf)}; + + this->nonConstCurGlobalVolVars().volVars(eIdx, scvf.outsideScvIdx()).update(elemSol, this->problem_(), element, insideScv); + } } } } -- GitLab From 78ad9c67335efc9ba6893402f623b5d47c252903 Mon Sep 17 00:00:00 2001 From: Kilian Weishaupt Date: Tue, 4 Jul 2017 11:41:25 +0200 Subject: [PATCH 5/6] [compositional][priVarSwitch] Re-introduce visited query * For box, one dof must only be visited once, otherwise the current concept of the switch won't work properly --- .../compositional/primaryvariableswitch.hh | 25 +++++++++++-------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/dumux/porousmediumflow/compositional/primaryvariableswitch.hh b/dumux/porousmediumflow/compositional/primaryvariableswitch.hh index 1739584717..df1feba264 100644 --- a/dumux/porousmediumflow/compositional/primaryvariableswitch.hh +++ b/dumux/porousmediumflow/compositional/primaryvariableswitch.hh @@ -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; @@ -195,14 +195,19 @@ public: for (auto&& scv : scvs(fvGeometry)) { auto dofIdxGlobal = scv.dofIndex(); - // 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 (asImp_().update_(curSol[dofIdxGlobal], volVars, dofIdxGlobal, scv.dofPosition())) - switched = true; + // 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]) + { + visited_[dofIdxGlobal] = true; + if(asImp_().update_(curSol[dofIdxGlobal], volVars, dofIdxGlobal, scv.dofPosition())) + switched = true; + } } } -- GitLab From 60136aaae87a9be63aeea375b88ef5f482b4e2f9 Mon Sep 17 00:00:00 2001 From: Kilian Weishaupt Date: Tue, 4 Jul 2017 11:46:27 +0200 Subject: [PATCH 6/6] [compositional] Adapt oldSol concept for box volVars --- dumux/discretization/box/elementvolumevariables.hh | 8 +++++--- dumux/implicit/box/localjacobian.hh | 2 +- dumux/implicit/localresidual.hh | 4 ++-- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/dumux/discretization/box/elementvolumevariables.hh b/dumux/discretization/box/elementvolumevariables.hh index 83bf970d29..7620bd076c 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/implicit/box/localjacobian.hh b/dumux/implicit/box/localjacobian.hh index f032f83b69..eb66f12372 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/localresidual.hh b/dumux/implicit/localresidual.hh index 207c47b079..b45442c870 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); } -- GitLab