From 8b2f6ef13f309fc0ed08aef1955cf1ecdbacbbf5 Mon Sep 17 00:00:00 2001 From: Kilian Weishaupt Date: Mon, 24 Jul 2017 17:32:49 +0200 Subject: [PATCH 1/8] [box][globalVolVars] Make volVars public --- dumux/discretization/box/globalvolumevariables.hh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dumux/discretization/box/globalvolumevariables.hh b/dumux/discretization/box/globalvolumevariables.hh index dc069bd3fe..ac5ae9b68f 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_; } -- GitLab From eb4937a5066593fdcd97ceed16c4d6a2a906ec7c Mon Sep 17 00:00:00 2001 From: Kilian Weishaupt Date: Mon, 24 Jul 2017 17:34:42 +0200 Subject: [PATCH 2/8] [cc][globalVolVars] Provide volVars with same interface as box *volVars(elementIdx, localIdx) --- .../discretization/cellcentered/globalvolumevariables.hh | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/dumux/discretization/cellcentered/globalvolumevariables.hh b/dumux/discretization/cellcentered/globalvolumevariables.hh index 8a9b9a7883..b70f940cf0 100644 --- a/dumux/discretization/cellcentered/globalvolumevariables.hh +++ b/dumux/discretization/cellcentered/globalvolumevariables.hh @@ -124,6 +124,15 @@ public: VolumeVariables& volVars(const SubControlVolume scv) { return volumeVariables_[scv.dofIndex()]; } + + // required for compatibility with the box method + const VolumeVariables& volVars(const IndexType scvIdx, const IndexType localIdx) const + { return volumeVariables_[scvIdx]; } + + // required for compatibility with the box method + VolumeVariables& volVars(const IndexType scvIdx, const IndexType localIdx) + { return volumeVariables_[scvIdx]; } + private: const Problem& problem_() const { return *problemPtr_; } -- GitLab From 7ad36090d2e2d1312c9c8f6d429c732d9cf98972 Mon Sep 17 00:00:00 2001 From: Kilian Weishaupt Date: Mon, 24 Jul 2017 17:35:25 +0200 Subject: [PATCH 3/8] [compositional] Adapt priVarSwitch to new interface --- .../porousmediumflow/compositional/primaryvariableswitch.hh | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/dumux/porousmediumflow/compositional/primaryvariableswitch.hh b/dumux/porousmediumflow/compositional/primaryvariableswitch.hh index 72e4777d2a..d8f507cba4 100644 --- a/dumux/porousmediumflow/compositional/primaryvariableswitch.hh +++ b/dumux/porousmediumflow/compositional/primaryvariableswitch.hh @@ -131,6 +131,8 @@ public: auto fvGeometry = localView(problem.model().globalFvGeometry()); fvGeometry.bindElement(element); + const auto eIdx = problem.elementMapper().index(element); + auto curElemSol = problem.model().elementSolution(element, curSol); auto& curGlobalVolVars = problem.model().nonConstCurGlobalVolVars(); @@ -145,8 +147,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(scv); + auto&& volVars = curGlobalVolVars.volVars(eIdx, scv.indexInElement()); volVars.update(curElemSol, problem, element, scv); if (asImp_().update_(curSol[dofIdxGlobal], volVars, dofIdxGlobal, scv.dofPosition())) -- GitLab From 392221c6b7981e831a366bc0740cf1217a6edbc8 Mon Sep 17 00:00:00 2001 From: Kilian Weishaupt Date: Mon, 24 Jul 2017 17:43:09 +0200 Subject: [PATCH 4/8] [2p2c] Adapt to new volVar interface --- dumux/porousmediumflow/2p2c/implicit/model.hh | 38 ++++++++++--------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/dumux/porousmediumflow/2p2c/implicit/model.hh b/dumux/porousmediumflow/2p2c/implicit/model.hh index 7639dc78c2..a1bc9e00d7 100644 --- a/dumux/porousmediumflow/2p2c/implicit/model.hh +++ b/dumux/porousmediumflow/2p2c/implicit/model.hh @@ -214,31 +214,35 @@ public: auto dofIdxGlobal = scv.dofIndex(); if (priVarSwitch_().wasSwitched(dofIdxGlobal)) { + const auto eIdx = this->problem_().elementMapper().index(element); const auto elemSol = this->elementSolution(element, this->curSol()); - this->nonConstCurGlobalVolVars().volVars(scv).update(elemSol, - this->problem_(), - element, - scv); + this->nonConstCurGlobalVolVars().volVars(eIdx, scv.indexInElement()).update(elemSol, + this->problem_(), + element, + scv); } } } - // handle the boundary volume variables - for (auto&& scvf : scvfs(fvGeometry)) + // handle the boundary volume variables for cell-centered models + 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()) + for (auto&& scvf : scvfs(fvGeometry)) { - const auto insideScvIdx = scvf.insideScvIdx(); - const auto& insideScv = fvGeometry.scv(insideScvIdx); - const auto elemSol = ElementSolutionVector{this->problem_().dirichlet(element, scvf)}; + // 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); + this->nonConstCurGlobalVolVars().volVars(scvf.outsideScvIdx(), 0/*indexInElement*/).update(elemSol, this->problem_(), element, insideScv); + } } } } -- GitLab From eef20848efb09a886cccad83ac4f663d17adba41 Mon Sep 17 00:00:00 2001 From: Kilian Weishaupt Date: Mon, 24 Jul 2017 18:17:54 +0200 Subject: [PATCH 5/8] [2pnc][model] Adapt to new volVar interface --- dumux/porousmediumflow/2pnc/implicit/model.hh | 44 ++++++++++++++----- 1 file changed, 34 insertions(+), 10 deletions(-) diff --git a/dumux/porousmediumflow/2pnc/implicit/model.hh b/dumux/porousmediumflow/2pnc/implicit/model.hh index af6cd2f524..b92e92a9d0 100644 --- a/dumux/porousmediumflow/2pnc/implicit/model.hh +++ b/dumux/porousmediumflow/2pnc/implicit/model.hh @@ -111,6 +111,7 @@ class TwoPNCModel: public GET_PROP_TYPE(TypeTag, BaseModel) using GridView = typename GET_PROP_TYPE(TypeTag, GridView); using FluidSystem = typename GET_PROP_TYPE(TypeTag, FluidSystem); using VolumeVariables = typename GET_PROP_TYPE(TypeTag, VolumeVariables); + using ElementSolutionVector = typename GET_PROP_TYPE(TypeTag, ElementSolutionVector); static constexpr int dim = GridView::dimension; static constexpr int dimWorld = GridView::dimensionworld; @@ -229,26 +230,49 @@ public: // update the secondary variables if global caching is enabled // \note we only updated if phase presence changed as the volume variables // are already updated once by the switch - if (switchFlag_) + for (const auto& element : elements(this->problem_().gridView())) { - for (const auto& element : elements(this->problem_().gridView())) - { - // make sure FVElementGeometry & vol vars are bound to the element - auto fvGeometry = localView(this->globalFvGeometry()); - fvGeometry.bindElement(element); + // make sure FVElementGeometry & vol vars are bound to the element + auto fvGeometry = localView(this->globalFvGeometry()); + fvGeometry.bindElement(element); + if (switchFlag_) + { for (auto&& scv : scvs(fvGeometry)) { auto dofIdxGlobal = scv.dofIndex(); if (priVarSwitch_().wasSwitched(dofIdxGlobal)) { - this->nonConstCurGlobalVolVars().volVars(scv).update(this->curSol()[dofIdxGlobal], - this->problem_(), - element, - scv); + const auto eIdx = this->problem_().elementMapper().index(element); + const auto elemSol = this->elementSolution(element, this->curSol()); + this->nonConstCurGlobalVolVars().volVars(eIdx, scv.indexInElement()).update(elemSol, + this->problem_(), + element, + scv); } } + } + + // handle the boundary volume variables for cell-centered models + if(!isBox) + { + 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(scvf.outsideScvIdx(), 0/*indexInElement*/).update(elemSol, this->problem_(), element, insideScv); + } + } } } } -- GitLab From 206798e06f0c44c010603fdf22cee5b7b46aa464 Mon Sep 17 00:00:00 2001 From: Kilian Weishaupt Date: Mon, 24 Jul 2017 18:18:09 +0200 Subject: [PATCH 6/8] [2pncmin][model] Adapt to new volVar interface --- .../2pncmin/implicit/model.hh | 40 +++++++++++-------- 1 file changed, 23 insertions(+), 17 deletions(-) diff --git a/dumux/porousmediumflow/2pncmin/implicit/model.hh b/dumux/porousmediumflow/2pncmin/implicit/model.hh index b418c7e07e..b9d7159df8 100644 --- a/dumux/porousmediumflow/2pncmin/implicit/model.hh +++ b/dumux/porousmediumflow/2pncmin/implicit/model.hh @@ -121,6 +121,7 @@ class TwoPNCMinModel: public GET_PROP_TYPE(TypeTag, BaseModel) using GridView = typename GET_PROP_TYPE(TypeTag, GridView); using FVElementGeometry = typename GET_PROP_TYPE(TypeTag, FVElementGeometry); using VolumeVariables = typename GET_PROP_TYPE(TypeTag, VolumeVariables); + using ElementSolutionVector = typename GET_PROP_TYPE(TypeTag, ElementSolutionVector); using Indices = typename GET_PROP_TYPE(TypeTag, Indices); enum { @@ -233,30 +234,35 @@ public: auto dofIdxGlobal = scv.dofIndex(); if (priVarSwitch_().wasSwitched(dofIdxGlobal)) { - this->nonConstCurGlobalVolVars().volVars(scv).update(this->curSol()[dofIdxGlobal], - this->problem_(), - element, - scv); + const auto eIdx = this->problem_().elementMapper().index(element); + const auto elemSol = this->elementSolution(element, this->curSol()); + this->nonConstCurGlobalVolVars().volVars(eIdx, scv.indexInElement()).update(elemSol, + this->problem_(), + element, + scv); } } } - // handle the boundary volume variables - for (auto&& scvf : scvfs(fvGeometry)) + // handle the boundary volume variables for cell-centered models + 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()) + for (auto&& scvf : scvfs(fvGeometry)) { - const auto insideScvIdx = scvf.insideScvIdx(); - const auto& insideScv = fvGeometry.scv(insideScvIdx); - const auto dirichletPriVars = this->problem_().dirichlet(element, scvf); + // 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(dirichletPriVars, this->problem_(), element, insideScv); + this->nonConstCurGlobalVolVars().volVars(scvf.outsideScvIdx(), 0/*indexInElement*/).update(elemSol, this->problem_(), element, insideScv); + } } } } -- GitLab From 452489ff12cce6610b1ce13bb523e8efddee6a26 Mon Sep 17 00:00:00 2001 From: Kilian Weishaupt Date: Mon, 24 Jul 2017 18:18:25 +0200 Subject: [PATCH 7/8] [3p3c][model] Adapt to new volVar interface --- dumux/porousmediumflow/3p3c/implicit/model.hh | 45 ++++++++++++++----- 1 file changed, 34 insertions(+), 11 deletions(-) diff --git a/dumux/porousmediumflow/3p3c/implicit/model.hh b/dumux/porousmediumflow/3p3c/implicit/model.hh index 5d50e45d42..15f4010914 100644 --- a/dumux/porousmediumflow/3p3c/implicit/model.hh +++ b/dumux/porousmediumflow/3p3c/implicit/model.hh @@ -106,6 +106,7 @@ class ThreePThreeCModel: public GET_PROP_TYPE(TypeTag, BaseModel) using PrimaryVariables = typename GET_PROP_TYPE(TypeTag, PrimaryVariables); using VolumeVariables = typename GET_PROP_TYPE(TypeTag, VolumeVariables); using SolutionVector = typename GET_PROP_TYPE(TypeTag, SolutionVector); + using ElementSolutionVector = typename GET_PROP_TYPE(TypeTag, ElementSolutionVector); using Indices = typename GET_PROP_TYPE(TypeTag, Indices); enum { @@ -198,27 +199,49 @@ public: // update the secondary variables if global caching is enabled // \note we only updated if phase presence changed as the volume variables // are already updated once by the switch - if (switchFlag_) + for (const auto& element : elements(this->problem_().gridView())) { - for (const auto& element : elements(this->problem_().gridView())) - { - // make sure FVElementGeometry & vol vars are bound to the element - auto fvGeometry = localView(this->globalFvGeometry()); - fvGeometry.bindElement(element); + // make sure FVElementGeometry & vol vars are bound to the element + auto fvGeometry = localView(this->globalFvGeometry()); + fvGeometry.bindElement(element); + if (switchFlag_) + { for (auto&& scv : scvs(fvGeometry)) { auto dofIdxGlobal = scv.dofIndex(); if (priVarSwitch_().wasSwitched(dofIdxGlobal)) { - - this->nonConstCurGlobalVolVars().volVars(scv).update(this->curSol()[dofIdxGlobal], - this->problem_(), - element, - scv); + const auto eIdx = this->problem_().elementMapper().index(element); + const auto elemSol = this->elementSolution(element, this->curSol()); + this->nonConstCurGlobalVolVars().volVars(eIdx, scv.indexInElement()).update(elemSol, + this->problem_(), + element, + scv); } } + } + // handle the boundary volume variables for cell-centered models + if(!isBox) + { + 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(scvf.outsideScvIdx(), 0/*indexInElement*/).update(elemSol, this->problem_(), element, insideScv); + } + } } } } -- GitLab From 7575218be4bd5b35a457738972e02db3a9574ea3 Mon Sep 17 00:00:00 2001 From: Kilian Weishaupt Date: Mon, 24 Jul 2017 18:21:18 +0200 Subject: [PATCH 8/8] [compositional][privarSwitch] Always update volVars in case of caching * The check for visited was too early --- .../compositional/primaryvariableswitch.hh | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/dumux/porousmediumflow/compositional/primaryvariableswitch.hh b/dumux/porousmediumflow/compositional/primaryvariableswitch.hh index d8f507cba4..64bd67763f 100644 --- a/dumux/porousmediumflow/compositional/primaryvariableswitch.hh +++ b/dumux/porousmediumflow/compositional/primaryvariableswitch.hh @@ -139,20 +139,21 @@ public: for (auto&& scv : scvs(fvGeometry)) { + // Update volVars on which grounds we decide + // if we need to switch the primary variables + auto&& volVars = curGlobalVolVars.volVars(eIdx, scv.indexInElement()); + volVars.update(curElemSol, problem, element, scv); + 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 - // if we need to switch the primary variables - auto&& volVars = curGlobalVolVars.volVars(eIdx, scv.indexInElement()); - volVars.update(curElemSol, problem, element, scv); if (asImp_().update_(curSol[dofIdxGlobal], volVars, dofIdxGlobal, scv.dofPosition())) switched = true; - } } } -- GitLab