3.2-git
DUNE for Multi-{Phase, Component, Scale, Physics, ...} flow and transport in porous media
multidomain/facet/box/darcyslaw.hh
Go to the documentation of this file.
1// -*- mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2// vi: set et ts=4 sw=4 sts=4:
3/*****************************************************************************
4 * See the file COPYING for full copying permissions. *
5 * *
6 * This program is free software: you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation, either version 3 of the License, or *
9 * (at your option) any later version. *
10 * *
11 * This program is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU General Public License for more details. *
15 * *
16 * You should have received a copy of the GNU General Public License *
17 * along with this program. If not, see <http://www.gnu.org/licenses/>. *
18 *****************************************************************************/
24#ifndef DUMUX_DISCRETIZATION_BOX_FACET_COUPLING_DARCYS_LAW_HH
25#define DUMUX_DISCRETIZATION_BOX_FACET_COUPLING_DARCYS_LAW_HH
26
27#include <vector>
28#include <cmath>
29
30#include <dune/common/exceptions.hh>
31#include <dune/common/fvector.hh>
32#include <dune/common/float_cmp.hh>
33
36
39
40namespace Dumux {
41
48template<class Scalar, class GridGeometry>
50{
52
53 using FVElementGeometry = typename GridGeometry::LocalView;
54 using SubControlVolume = typename FVElementGeometry::SubControlVolume;
55 using SubControlVolumeFace = typename FVElementGeometry::SubControlVolumeFace;
56 using GridView = typename GridGeometry::GridView;
57 using Element = typename GridView::template Codim<0>::Entity;
58 using CoordScalar = typename GridView::ctype;
59 using GlobalPosition = typename Element::Geometry::GlobalCoordinate;
60
61 static constexpr int dim = GridView::dimension;
62 static constexpr int dimWorld = GridView::dimensionworld;
63
64public:
65
66 template<class Problem, class ElementVolumeVariables, class ElementFluxVarsCache>
67 static Scalar flux(const Problem& problem,
68 const Element& element,
69 const FVElementGeometry& fvGeometry,
70 const ElementVolumeVariables& elemVolVars,
71 const SubControlVolumeFace& scvf,
72 const int phaseIdx,
73 const ElementFluxVarsCache& elemFluxVarCache)
74 {
75 // if this scvf is not on an interior boundary, use the standard law
76 if (!scvf.interiorBoundary())
77 return DefaultBoxDarcysLaw::flux(problem, element, fvGeometry, elemVolVars, scvf, phaseIdx, elemFluxVarCache);
78
79 static const Scalar xi = getParamFromGroup<Scalar>(problem.paramGroup(), "FacetCoupling.Xi", 1.0);
80 if ( !Dune::FloatCmp::eq(xi, 1.0, 1e-6) )
81 DUNE_THROW(Dune::NotImplemented, "Xi != 1.0 cannot be used with the Box-Facet-Coupling scheme");
82
83 // get some references for convenience
84 const auto& fluxVarCache = elemFluxVarCache[scvf];
85 const auto& shapeValues = fluxVarCache.shapeValues();
86 const auto& insideScv = fvGeometry.scv(scvf.insideScvIdx());
87 const auto& insideVolVars = elemVolVars[insideScv];
88
89 // evaluate user-defined interior boundary types
90 const auto bcTypes = problem.interiorBoundaryTypes(element, scvf);
91
92 static const bool enableGravity = getParamFromGroup<bool>(problem.paramGroup(), "Problem.EnableGravity");
93
94 // on interior Neumann boundaries, evaluate the flux using the facet permeability
95 if (bcTypes.hasOnlyNeumann())
96 {
97 // interpolate pressure/density to scvf integration point
98 Scalar p = 0.0;
99 Scalar rho = 0.0;
100 for (const auto& scv : scvs(fvGeometry))
101 {
102 const auto& volVars = elemVolVars[scv];
103 p += volVars.pressure(phaseIdx)*shapeValues[scv.indexInElement()][0];
104 rho += volVars.density(phaseIdx)*shapeValues[scv.indexInElement()][0];
105 }
106
107 // compute tpfa flux from integration point to facet centerline
108 const auto& facetVolVars = problem.couplingManager().getLowDimVolVars(element, scvf);
109
110 using std::sqrt;
111 // If this is a surface grid, use the square root of the facet extrusion factor
112 // as an approximate average distance from scvf ip to facet center
113 using std::sqrt;
114 const auto a = facetVolVars.extrusionFactor();
115 auto gradP = scvf.unitOuterNormal();
116 gradP *= dim == dimWorld ? 0.5*a : 0.5*sqrt(a);
117 gradP /= gradP.two_norm2();
118 gradP *= (facetVolVars.pressure(phaseIdx) - p);
119 if (enableGravity)
120 gradP.axpy(-rho, problem.spatialParams().gravity(scvf.center()));
121
122 // apply facet permeability and return the flux
123 return -1.0*scvf.area()
124 *insideVolVars.extrusionFactor()
125 *vtmv(scvf.unitOuterNormal(), facetVolVars.permeability(), gradP);
126 }
127
128 // on interior Dirichlet boundaries use the facet pressure and evaluate flux
129 else if (bcTypes.hasOnlyDirichlet())
130 {
131 // create vector with nodal pressures
132 std::vector<Scalar> pressures(element.subEntities(dim));
133 for (const auto& scv : scvs(fvGeometry))
134 pressures[scv.localDofIndex()] = elemVolVars[scv].pressure(phaseIdx);
135
136 // substitute with facet pressures for those scvs touching this facet
137 for (const auto& scvfJ : scvfs(fvGeometry))
138 if (scvfJ.interiorBoundary() && scvfJ.facetIndexInElement() == scvf.facetIndexInElement())
139 pressures[ fvGeometry.scv(scvfJ.insideScvIdx()).localDofIndex() ]
140 = problem.couplingManager().getLowDimVolVars(element, scvfJ).pressure(phaseIdx);
141
142 // evaluate gradP - rho*g at integration point
143 Scalar rho(0.0);
144 Dune::FieldVector<Scalar, dimWorld> gradP(0.0);
145 for (const auto& scv : scvs(fvGeometry))
146 {
147 rho += elemVolVars[scv].density(phaseIdx)*shapeValues[scv.indexInElement()][0];
148 gradP.axpy(pressures[scv.localDofIndex()], fluxVarCache.gradN(scv.indexInElement()));
149 }
150
151 if (enableGravity)
152 gradP.axpy(-rho, problem.spatialParams().gravity(scvf.center()));
153
154 // apply matrix permeability and return the flux
155 return -1.0*scvf.area()
156 *insideVolVars.extrusionFactor()
157 *vtmv(scvf.unitOuterNormal(), insideVolVars.permeability(), gradP);
158 }
159
160 // mixed boundary types are not supported
161 else
162 DUNE_THROW(Dune::NotImplemented, "Mixed boundary types are not supported");
163 }
164
165 // compute transmissibilities ti for analytical jacobians
166 template<class Problem, class ElementVolumeVariables, class FluxVarCache>
167 static std::vector<Scalar> calculateTransmissibilities(const Problem& problem,
168 const Element& element,
169 const FVElementGeometry& fvGeometry,
170 const ElementVolumeVariables& elemVolVars,
171 const SubControlVolumeFace& scvf,
172 const FluxVarCache& fluxVarCache)
173 {
174 DUNE_THROW(Dune::NotImplemented, "transmissibilty computation for BoxFacetCouplingDarcysLaw");
175 }
176};
177
178} // end namespace Dumux
179
180#endif
The infrastructure to retrieve run-time parameters from Dune::ParameterTrees.
The available discretization methods in Dumux.
Dune::DenseMatrix< MAT >::value_type vtmv(const Dune::DenseVector< V1 > &v1, const Dune::DenseMatrix< MAT > &M, const Dune::DenseVector< V2 > &v2)
Evaluates the scalar product of a vector v2, projected by a matrix M, with a vector v1.
Definition: math.hh:840
Definition: adapt.hh:29
Darcy's law for the box scheme.
Definition: flux/box/darcyslaw.hh:63
static Scalar flux(const Problem &problem, const Element &element, const FVElementGeometry &fvGeometry, const ElementVolumeVariables &elemVolVars, const SubControlVolumeFace &scvf, const int phaseIdx, const ElementFluxVarsCache &elemFluxVarCache)
Definition: flux/box/darcyslaw.hh:75
Darcy's law for the box scheme in the context of coupled models where coupling occurs across the face...
Definition: multidomain/facet/box/darcyslaw.hh:50
static Scalar flux(const Problem &problem, const Element &element, const FVElementGeometry &fvGeometry, const ElementVolumeVariables &elemVolVars, const SubControlVolumeFace &scvf, const int phaseIdx, const ElementFluxVarsCache &elemFluxVarCache)
Definition: multidomain/facet/box/darcyslaw.hh:67
static std::vector< Scalar > calculateTransmissibilities(const Problem &problem, const Element &element, const FVElementGeometry &fvGeometry, const ElementVolumeVariables &elemVolVars, const SubControlVolumeFace &scvf, const FluxVarCache &fluxVarCache)
Definition: multidomain/facet/box/darcyslaw.hh:167
Declares all properties used in Dumux.
Specialization of Darcy's Law for the box method.