From 960021580a0e7b1827e6dc2e16401fe8967be2cd Mon Sep 17 00:00:00 2001 From: "Dennis.Glaeser" Date: Thu, 25 Jul 2019 14:46:42 +0200 Subject: [PATCH 1/4] [poromech][cm] reuse problem storage in base class --- .../poroelastic/couplingmanager.hh | 32 ++++++------------- .../poromechanics/el1p/spatialparams_1p.hh | 2 +- .../poromechanics/el2p/spatialparams_2p.hh | 2 +- 3 files changed, 12 insertions(+), 24 deletions(-) diff --git a/dumux/geomechanics/poroelastic/couplingmanager.hh b/dumux/geomechanics/poroelastic/couplingmanager.hh index 8ff6b08fbc..503e317fbc 100644 --- a/dumux/geomechanics/poroelastic/couplingmanager.hh +++ b/dumux/geomechanics/poroelastic/couplingmanager.hh @@ -138,8 +138,10 @@ public: std::shared_ptr< Problem > poroMechanicalProblem, const SolutionVector& curSol) { - // set up tuple containing the sub-problems - problemTuple_ = std::make_tuple(pmFlowProblem, poroMechanicalProblem); + // set the sub problems + this->setSubProblem(pmFlowProblem, pmFlowId); + this->setSubProblem(poroMechanicalProblem, poroMechId); + // copy the solution vector ParentType::updateSolution(curSol); // set up the coupling map pmfow -> poromechanics @@ -153,7 +155,7 @@ public: const Element& element, Dune::index_constant poroMechDomainId) const { - return pmFlowCouplingMap_[ problem().fvGridGeometry().elementMapper().index(element) ]; + return pmFlowCouplingMap_[ this->problem(pmFlowId).fvGridGeometry().elementMapper().index(element) ]; } /*! @@ -163,7 +165,7 @@ public: const Element& element, Dune::index_constant pmFlowDomainId) const { - const auto eIdx = problem().fvGridGeometry().elementMapper().index(element); + const auto eIdx = this->problem(pmFlowId).fvGridGeometry().elementMapper().index(element); return CouplingStencilType{ {eIdx} }; } @@ -185,11 +187,12 @@ public: // prepare the fvGeometry and the element volume variables // these quantities will be used later to obtain the effective pressure - auto fvGeometry = localView( problem().fvGridGeometry() ); + auto fvGeometry = localView( this->problem(pmFlowId).fvGridGeometry() ); auto elemVolVars = localView( assembler.gridVariables(Dune::index_constant()).curGridVolVars() ); fvGeometry.bindElement(element); elemVolVars.bindElement(element, fvGeometry, this->curSol()[Dune::index_constant()]); + poroMechCouplingContext_.pmFlowElement = element; poroMechCouplingContext_.pmFlowFvGeometry = std::make_unique< FVElementGeometry >(fvGeometry); poroMechCouplingContext_.pmFlowElemVolVars = std::make_unique< ElementVolumeVariables >(elemVolVars); @@ -346,16 +349,6 @@ public: poroMechLocalAssembler.elemBcTypes()); } - //! Return a const reference to one of the problems - template = 0> - const Problem& problem() const - { return *std::get<(id == PMFlowId ? 0 : 1)>(problemTuple_); } - - //! Return reference to one of the problems - template = 0> - Problem& problem() - { return *std::get<(id == PMFlowId ? 0 : 1)>(problemTuple_); } - //! Return the coupling context (used in mechanical sub-problem to compute effective pressure) const PoroMechanicsCouplingContext& poroMechanicsCouplingContext() const { return poroMechCouplingContext_; } @@ -376,8 +369,8 @@ private: void initializeCouplingMap_() { // some references for convenience - const auto& pmFlowGridGeom = problem().fvGridGeometry(); - const auto& poroMechGridGeom = problem().fvGridGeometry(); + const auto& pmFlowGridGeom = this->problem(pmFlowId).fvGridGeometry(); + const auto& poroMechGridGeom = this->problem(poroMechId).fvGridGeometry(); // make sure the two grids are really the same. Note that if the two grids // happen to have equal number of elements by chance, we don't detect this source of error. @@ -411,11 +404,6 @@ private: } } - // tuple for storing pointers to the sub-problems - using PMFlowProblemPtr = std::shared_ptr< Problem >; - using PoroMechanicalProblemPtr = std::shared_ptr< Problem >; - std::tuple problemTuple_; - // Container for storing the coupling element stencils for the pm flow domain std::vector< CouplingStencilType > pmFlowCouplingMap_; diff --git a/test/multidomain/poromechanics/el1p/spatialparams_1p.hh b/test/multidomain/poromechanics/el1p/spatialparams_1p.hh index cef1860068..206f850399 100644 --- a/test/multidomain/poromechanics/el1p/spatialparams_1p.hh +++ b/test/multidomain/poromechanics/el1p/spatialparams_1p.hh @@ -75,7 +75,7 @@ public: { static constexpr auto poroMechId = CouplingManager::poroMechId; - const auto& poroMechGridGeom = couplingManagerPtr_->template problem().fvGridGeometry(); + const auto& poroMechGridGeom = couplingManagerPtr_->problem(poroMechId).fvGridGeometry(); const auto poroMechElemSol = elementSolution(element, couplingManagerPtr_->curSol()[poroMechId], poroMechGridGeom); // evaluate the deformation-dependent porosity at the scv center diff --git a/test/multidomain/poromechanics/el2p/spatialparams_2p.hh b/test/multidomain/poromechanics/el2p/spatialparams_2p.hh index ca1bb83559..4cba433c4c 100644 --- a/test/multidomain/poromechanics/el2p/spatialparams_2p.hh +++ b/test/multidomain/poromechanics/el2p/spatialparams_2p.hh @@ -89,7 +89,7 @@ public: { static constexpr auto poroMechId = CouplingManager::poroMechId; - const auto& poroMechGridGeom = couplingManagerPtr_->template problem().fvGridGeometry(); + const auto& poroMechGridGeom = couplingManagerPtr_->problem(poroMechId).fvGridGeometry(); const auto poroMechElemSol = elementSolution(element, couplingManagerPtr_->curSol()[poroMechId], poroMechGridGeom); // evaluate the deformation-dependent porosity at the scv center -- GitLab From a1812ac44ae62ee8e1824f4c7166b5b8c303c36a Mon Sep 17 00:00:00 2001 From: "Dennis.Glaeser" Date: Thu, 25 Jul 2019 14:48:45 +0200 Subject: [PATCH 2/4] [poromech][cm] add interface to obtain pmflow vol vars --- dumux/geomechanics/poroelastic/couplingmanager.hh | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/dumux/geomechanics/poroelastic/couplingmanager.hh b/dumux/geomechanics/poroelastic/couplingmanager.hh index 503e317fbc..6db3c2ddcf 100644 --- a/dumux/geomechanics/poroelastic/couplingmanager.hh +++ b/dumux/geomechanics/poroelastic/couplingmanager.hh @@ -66,6 +66,7 @@ class PoroMechanicsCouplingManager : public virtual CouplingManager< MDTraits > template using PrimaryVariables = typename GridVariables::PrimaryVariables; template using GridVolumeVariables = typename GridVariables::GridVolumeVariables; template using ElementVolumeVariables = typename GridVolumeVariables::LocalView; + template using VolumeVariables = typename GridVolumeVariables::VolumeVariables; template using FVGridGeometry = typename GridVariables::GridGeometry; template using FVElementGeometry = typename FVGridGeometry::LocalView; template using GridView = typename FVGridGeometry::GridView; @@ -353,6 +354,15 @@ public: const PoroMechanicsCouplingContext& poroMechanicsCouplingContext() const { return poroMechCouplingContext_; } + + //! Return the porous medium flow variables an element/scv of the poromech domain couples to + const VolumeVariables& getPMFlowVolVars(const Element& element) const + { + //! If we do not yet have the queried object, build it first + const auto eIdx = this->problem(poroMechId).fvGridGeometry().elementMapper().index(element); + return (*poroMechCouplingContext_.pmFlowElemVolVars)[eIdx]; + } + /*! * \brief the solution vector of the coupled problem * \note in case of numeric differentiation the solution vector always carries the deflected solution -- GitLab From ed2dcf38033a5c16ffc36e11880739736d81e66b Mon Sep 17 00:00:00 2001 From: "Dennis.Glaeser" Date: Thu, 25 Jul 2019 14:49:21 +0200 Subject: [PATCH 3/4] [poromech][cm] deprecate getcouplingcontext function --- dumux/geomechanics/poroelastic/couplingmanager.hh | 1 + 1 file changed, 1 insertion(+) diff --git a/dumux/geomechanics/poroelastic/couplingmanager.hh b/dumux/geomechanics/poroelastic/couplingmanager.hh index 6db3c2ddcf..630ffcc3ac 100644 --- a/dumux/geomechanics/poroelastic/couplingmanager.hh +++ b/dumux/geomechanics/poroelastic/couplingmanager.hh @@ -351,6 +351,7 @@ public: } //! Return the coupling context (used in mechanical sub-problem to compute effective pressure) + [[deprecated("Obtain the volume variables directly calling getPMFlowVolVars(element). Will be removed after 3.1!")]] const PoroMechanicsCouplingContext& poroMechanicsCouplingContext() const { return poroMechCouplingContext_; } -- GitLab From 13f68da485a3953721ffb59b30707d3c3c44668e Mon Sep 17 00:00:00 2001 From: "Dennis.Glaeser" Date: Thu, 25 Jul 2019 14:50:38 +0200 Subject: [PATCH 4/4] =?UTF-8?q?[=C5=A7est][poromech]=20avoid=20deprecation?= =?UTF-8?q?=20warnings=20from=20cm?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../poromechanics/el1p/problem_poroelastic.hh | 17 ++++----- .../poromechanics/el2p/problem_poroelastic.hh | 35 ++++++++----------- 2 files changed, 20 insertions(+), 32 deletions(-) diff --git a/test/multidomain/poromechanics/el1p/problem_poroelastic.hh b/test/multidomain/poromechanics/el1p/problem_poroelastic.hh index 1a3859fc11..2194719b9e 100644 --- a/test/multidomain/poromechanics/el1p/problem_poroelastic.hh +++ b/test/multidomain/poromechanics/el1p/problem_poroelastic.hh @@ -138,11 +138,9 @@ public: Scalar effectiveFluidDensity(const Element& element, const SubControlVolume& scv) const { - // get context from coupling manager - // here, we know that the flow problem uses cell-centered finite volumes, - // thus, we simply take the volume variables of the element and return the density - const auto& context = couplingManager().poroMechanicsCouplingContext(); - return (*context.pmFlowElemVolVars)[scv.elementIndex()].density(); + // get porous medium flow volume variables from coupling manager + const auto pmFlowVolVars = couplingManager().getPMFlowVolVars(element); + return pmFlowVolVars.density(); } /*! @@ -154,12 +152,9 @@ public: const ElementVolumeVariables& elemVolVars, const FluxVarsCache& fluxVarsCache) const { - // get context from coupling manager - // here, we know that the flow problem uses cell-centered finite volumes, - // thus, we simply take the volume variables of the element and return the pressure - const auto& context = couplingManager().poroMechanicsCouplingContext(); - const auto eIdx = this->fvGridGeometry().elementMapper().index(element); - return (*context.pmFlowElemVolVars)[eIdx].pressure(); + // get porous medium flow volume variables from coupling manager + const auto pmFlowVolVars = couplingManager().getPMFlowVolVars(element); + return pmFlowVolVars.pressure(); } /*! diff --git a/test/multidomain/poromechanics/el2p/problem_poroelastic.hh b/test/multidomain/poromechanics/el2p/problem_poroelastic.hh index d4027b1500..4034d3ea08 100644 --- a/test/multidomain/poromechanics/el2p/problem_poroelastic.hh +++ b/test/multidomain/poromechanics/el2p/problem_poroelastic.hh @@ -139,16 +139,13 @@ public: */ Scalar effectiveFluidDensity(const Element& element, const SubControlVolume& scv) const { - // get context from coupling manager - const auto& context = couplingManager().poroMechanicsCouplingContext(); - - // here, we know that the flow problem uses cell-centered finite volumes, thus, - // we simply take the volume variables of the scv (i.e. element) to obtain fluid properties - const auto& facetVolVars = (*context.pmFlowElemVolVars)[scv.elementIndex()]; - Scalar wPhaseDensity = facetVolVars.density(FluidSystem::phase0Idx); - Scalar nPhaseDensity = facetVolVars.density(FluidSystem::phase1Idx); - Scalar Sw = facetVolVars.saturation(FluidSystem::phase0Idx); - Scalar Sn = facetVolVars.saturation(FluidSystem::phase1Idx); + // get porous medium flow volume variables from coupling manager + const auto pmFlowVolVars = couplingManager().getPMFlowVolVars(element); + + Scalar wPhaseDensity = pmFlowVolVars.density(FluidSystem::phase0Idx); + Scalar nPhaseDensity = pmFlowVolVars.density(FluidSystem::phase1Idx); + Scalar Sw = pmFlowVolVars.saturation(FluidSystem::phase0Idx); + Scalar Sn = pmFlowVolVars.saturation(FluidSystem::phase1Idx); return (wPhaseDensity * Sw + nPhaseDensity * Sn); } @@ -161,17 +158,13 @@ public: const ElementVolumeVariables& elemVolVars, const FluxVarsCache& fluxVarsCache) const { - // get context from coupling manager - const auto& context = couplingManager().poroMechanicsCouplingContext(); - - // here, we know that the flow problem uses cell-centered finite volumes, thus, - // we simply take the volume variables of the element to obtain fluid properties - const auto eIdx = this->fvGridGeometry().elementMapper().index(element); - const auto& facetVolVars = (*context.pmFlowElemVolVars)[eIdx]; - Scalar pw = facetVolVars.pressure(FluidSystem::phase0Idx); - Scalar pn = facetVolVars.pressure(FluidSystem::phase1Idx); - Scalar Sw = facetVolVars.saturation(FluidSystem::phase0Idx); - Scalar Sn = facetVolVars.saturation(FluidSystem::phase1Idx); + // get porous medium flow volume variables from coupling manager + const auto pmFlowVolVars = couplingManager().getPMFlowVolVars(element); + + Scalar pw = pmFlowVolVars.pressure(FluidSystem::phase0Idx); + Scalar pn = pmFlowVolVars.pressure(FluidSystem::phase1Idx); + Scalar Sw = pmFlowVolVars.saturation(FluidSystem::phase0Idx); + Scalar Sn = pmFlowVolVars.saturation(FluidSystem::phase1Idx); return (pw * Sw + pn * Sn); } -- GitLab