GCC Code Coverage Report


Directory: ../../../builds/dumux-repositories/
File: /builds/dumux-repositories/dumux/dumux/multidomain/facet/box/darcyslaw.hh
Date: 2024-09-21 20:52:54
Exec Total Coverage
Lines: 45 49 91.8%
Functions: 7 7 100.0%
Branches: 59 112 52.7%

Line Branch Exec Source
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 // SPDX-FileCopyrightInfo: Copyright © DuMux Project contributors, see AUTHORS.md in root folder
5 // SPDX-License-Identifier: GPL-3.0-or-later
6 //
7 /*!
8 * \file
9 * \ingroup FacetCoupling
10 * \copydoc Dumux::BoxFacetCouplingDarcysLaw
11 */
12 #ifndef DUMUX_DISCRETIZATION_BOX_FACET_COUPLING_DARCYS_LAW_HH
13 #define DUMUX_DISCRETIZATION_BOX_FACET_COUPLING_DARCYS_LAW_HH
14
15 #include <vector>
16 #include <cmath>
17
18 #include <dune/common/exceptions.hh>
19 #include <dune/common/fvector.hh>
20 #include <dune/common/float_cmp.hh>
21
22 #include <dumux/common/parameters.hh>
23 #include <dumux/common/properties.hh>
24
25 #include <dumux/discretization/method.hh>
26 #include <dumux/discretization/extrusion.hh>
27 #include <dumux/flux/cvfe/darcyslaw.hh>
28
29 namespace Dumux {
30
31 /*!
32 * \ingroup FacetCoupling
33 * \brief Darcy's law for the box scheme in the context of coupled models
34 * where coupling occurs across the facets of the bulk domain elements
35 * with a lower-dimensional domain living on these facets.
36 */
37 template<class Scalar, class GridGeometry>
38 class BoxFacetCouplingDarcysLaw
39 {
40 using DefaultDarcysLaw = CVFEDarcysLaw<Scalar, GridGeometry>;
41
42 using FVElementGeometry = typename GridGeometry::LocalView;
43 using SubControlVolume = typename GridGeometry::SubControlVolume;
44 using SubControlVolumeFace = typename GridGeometry::SubControlVolumeFace;
45 using Extrusion = Extrusion_t<GridGeometry>;
46 using GridView = typename GridGeometry::GridView;
47 using Element = typename GridView::template Codim<0>::Entity;
48 using CoordScalar = typename GridView::ctype;
49 using GlobalPosition = typename Element::Geometry::GlobalCoordinate;
50
51 static constexpr int dim = GridView::dimension;
52 static constexpr int dimWorld = GridView::dimensionworld;
53
54 public:
55
56 template<class Problem, class ElementVolumeVariables, class ElementFluxVarsCache>
57 10192472 static Scalar flux(const Problem& problem,
58 const Element& element,
59 const FVElementGeometry& fvGeometry,
60 const ElementVolumeVariables& elemVolVars,
61 const SubControlVolumeFace& scvf,
62 const int phaseIdx,
63 const ElementFluxVarsCache& elemFluxVarCache)
64 {
65 // if this scvf is not on an interior boundary, use the standard law
66
2/2
✓ Branch 0 taken 9071256 times.
✓ Branch 1 taken 820216 times.
10192472 if (!scvf.interiorBoundary())
67 9306720 return DefaultDarcysLaw::flux(problem, element, fvGeometry, elemVolVars, scvf, phaseIdx, elemFluxVarCache);
68
69
5/8
✓ Branch 0 taken 20 times.
✓ Branch 1 taken 820196 times.
✓ Branch 3 taken 20 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 20 times.
✗ Branch 7 not taken.
✓ Branch 9 taken 20 times.
✗ Branch 10 not taken.
885752 static const Scalar xi = getParamFromGroup<Scalar>(problem.paramGroup(), "FacetCoupling.Xi", 1.0);
70
2/4
✗ Branch 0 not taken.
✓ Branch 1 taken 820216 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 820216 times.
885752 if ( !Dune::FloatCmp::eq(xi, 1.0, 1e-6) )
71 DUNE_THROW(Dune::NotImplemented, "Xi != 1.0 cannot be used with the Box-Facet-Coupling scheme");
72
73 // get some references for convenience
74
2/2
✓ Branch 0 taken 15 times.
✓ Branch 1 taken 171745 times.
885752 const auto& fluxVarCache = elemFluxVarCache[scvf];
75
2/2
✓ Branch 0 taken 15 times.
✓ Branch 1 taken 171745 times.
885752 const auto& shapeValues = fluxVarCache.shapeValues();
76
4/4
✓ Branch 0 taken 15 times.
✓ Branch 1 taken 171745 times.
✓ Branch 2 taken 15 times.
✓ Branch 3 taken 171745 times.
1771504 const auto& insideScv = fvGeometry.scv(scvf.insideScvIdx());
77
2/2
✓ Branch 0 taken 15 times.
✓ Branch 1 taken 171745 times.
885752 const auto& insideVolVars = elemVolVars[insideScv];
78
79 // evaluate user-defined interior boundary types
80
2/2
✓ Branch 0 taken 15 times.
✓ Branch 1 taken 171745 times.
885752 const auto bcTypes = problem.interiorBoundaryTypes(element, scvf);
81
82
5/8
✓ Branch 0 taken 20 times.
✓ Branch 1 taken 820196 times.
✓ Branch 3 taken 20 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 20 times.
✗ Branch 7 not taken.
✓ Branch 9 taken 20 times.
✗ Branch 10 not taken.
885752 static const bool enableGravity = getParamFromGroup<bool>(problem.paramGroup(), "Problem.EnableGravity");
83
84 // on interior Neumann boundaries, evaluate the flux using the facet permeability
85
4/4
✓ Branch 0 taken 816136 times.
✓ Branch 1 taken 4080 times.
✓ Branch 2 taken 816136 times.
✓ Branch 3 taken 4080 times.
1771504 if (bcTypes.hasOnlyNeumann())
86 {
87 // interpolate pressure/density to scvf integration point
88 881672 Scalar p = 0.0;
89 881672 Scalar rho = 0.0;
90
4/4
✓ Branch 0 taken 3220064 times.
✓ Branch 1 taken 816136 times.
✓ Branch 2 taken 3220064 times.
✓ Branch 3 taken 816136 times.
8718800 for (const auto& scv : scvs(fvGeometry))
91 {
92 3477728 const auto& volVars = elemVolVars[scv];
93 6955456 p += volVars.pressure(phaseIdx)*shapeValues[scv.indexInElement()][0];
94 6955456 rho += volVars.density(phaseIdx)*shapeValues[scv.indexInElement()][0];
95 }
96
97 // compute tpfa flux from integration point to facet centerline
98 1763344 const auto& facetVolVars = problem.couplingManager().getLowDimVolVars(element, scvf);
99
100 using std::sqrt;
101 // If this is a surface grid, use the square root of the facet extrusion factor
102 // as an approximate average distance from scvf ip to facet center
103 using std::sqrt;
104 881672 const auto a = facetVolVars.extrusionFactor();
105 881672 auto gradP = scvf.unitOuterNormal();
106 881672 gradP *= dim == dimWorld ? 0.5*a : 0.5*sqrt(a);
107 881672 gradP /= gradP.two_norm2();
108 1763344 gradP *= (facetVolVars.pressure(phaseIdx) - p);
109
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 816136 times.
881672 if (enableGravity)
110 gradP.axpy(-rho, problem.spatialParams().gravity(scvf.center()));
111
112 // apply facet permeability and return the flux
113 881672 return -1.0*Extrusion::area(fvGeometry, scvf)
114 881672 *insideVolVars.extrusionFactor()
115 2645016 *vtmv(scvf.unitOuterNormal(), facetVolVars.permeability(), gradP);
116 }
117
118 // on interior Dirichlet boundaries use the facet pressure and evaluate flux
119
2/4
✓ Branch 0 taken 4080 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4080 times.
✗ Branch 3 not taken.
8160 else if (bcTypes.hasOnlyDirichlet())
120 {
121 // create vector with nodal pressures
122
3/8
✓ Branch 1 taken 4080 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 4080 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 4080 times.
✗ Branch 8 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
12240 std::vector<Scalar> pressures(element.subEntities(dim));
123
4/4
✓ Branch 0 taken 12240 times.
✓ Branch 1 taken 4080 times.
✓ Branch 2 taken 12240 times.
✓ Branch 3 taken 4080 times.
32640 for (const auto& scv : scvs(fvGeometry))
124 48960 pressures[scv.localDofIndex()] = elemVolVars[scv].pressure(phaseIdx);
125
126 // substitute with facet pressures for those scvs touching this facet
127
4/4
✓ Branch 0 taken 20400 times.
✓ Branch 1 taken 4080 times.
✓ Branch 2 taken 20400 times.
✓ Branch 3 taken 4080 times.
28560 for (const auto& scvfJ : scvfs(fvGeometry))
128
3/4
✓ Branch 0 taken 8160 times.
✓ Branch 1 taken 12240 times.
✓ Branch 4 taken 8160 times.
✗ Branch 5 not taken.
20400 if (scvfJ.interiorBoundary() && scvfJ.facetIndexInElement() == scvf.facetIndexInElement())
129 24480 pressures[ fvGeometry.scv(scvfJ.insideScvIdx()).localDofIndex() ]
130
2/4
✓ Branch 1 taken 8160 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 8160 times.
✗ Branch 5 not taken.
16320 = problem.couplingManager().getLowDimVolVars(element, scvfJ).pressure(phaseIdx);
131
132 // evaluate gradP - rho*g at integration point
133 4080 Scalar rho(0.0);
134 4080 Dune::FieldVector<Scalar, dimWorld> gradP(0.0);
135
4/4
✓ Branch 0 taken 12240 times.
✓ Branch 1 taken 4080 times.
✓ Branch 2 taken 12240 times.
✓ Branch 3 taken 4080 times.
32640 for (const auto& scv : scvs(fvGeometry))
136 {
137 36720 rho += elemVolVars[scv].density(phaseIdx)*shapeValues[scv.indexInElement()][0];
138 48960 gradP.axpy(pressures[scv.localDofIndex()], fluxVarCache.gradN(scv.indexInElement()));
139 }
140
141
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4080 times.
4080 if (enableGravity)
142 gradP.axpy(-rho, problem.spatialParams().gravity(scvf.center()));
143
144 // apply matrix permeability and return the flux
145 4080 return -1.0*Extrusion::area(fvGeometry, scvf)
146 4080 *insideVolVars.extrusionFactor()
147
1/2
✓ Branch 0 taken 4080 times.
✗ Branch 1 not taken.
12240 *vtmv(scvf.unitOuterNormal(), insideVolVars.permeability(), gradP);
148 }
149
150 // mixed boundary types are not supported
151 else
152 DUNE_THROW(Dune::NotImplemented, "Mixed boundary types are not supported");
153 }
154
155 // compute transmissibilities ti for analytical jacobians
156 template<class Problem, class ElementVolumeVariables, class FluxVarCache>
157 static std::vector<Scalar> calculateTransmissibilities(const Problem& problem,
158 const Element& element,
159 const FVElementGeometry& fvGeometry,
160 const ElementVolumeVariables& elemVolVars,
161 const SubControlVolumeFace& scvf,
162 const FluxVarCache& fluxVarCache)
163 {
164 DUNE_THROW(Dune::NotImplemented, "transmissibilty computation for BoxFacetCouplingDarcysLaw");
165 }
166 };
167
168 } // end namespace Dumux
169
170 #endif
171