GCC Code Coverage Report


Directory: ../../../builds/dumux-repositories/
File: /builds/dumux-repositories/dumux/dumux/flux/box/dispersionflux.hh
Date: 2024-05-04 19:09:25
Exec Total Coverage
Lines: 27 27 100.0%
Functions: 7 7 100.0%
Branches: 14 14 100.0%

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 BoxFlux
10 * \brief This file contains the data which is required to calculate
11 * dispersive fluxes.
12 */
13 #ifndef DUMUX_DISCRETIZATION_BOX_DISPERSION_FLUX_HH
14 #define DUMUX_DISCRETIZATION_BOX_DISPERSION_FLUX_HH
15
16 #include <dune/common/fvector.hh>
17 #include <dune/common/fmatrix.hh>
18
19 #include <dumux/common/math.hh>
20 #include <dumux/common/properties.hh>
21 #include <dumux/discretization/method.hh>
22 #include <dumux/discretization/extrusion.hh>
23 #include <dumux/flux/traits.hh>
24 #include <dumux/flux/referencesystemformulation.hh>
25
26 namespace Dumux {
27
28 // forward declaration
29 template<class TypeTag, class DiscretizationMethod, ReferenceSystemFormulation referenceSystem>
30 class DispersionFluxImplementation;
31
32 /*!
33 * \ingroup BoxFlux
34 * \brief Specialization of a dispersion flux for the box method
35 */
36 template <class TypeTag, ReferenceSystemFormulation referenceSystem>
37 class DispersionFluxImplementation<TypeTag, DiscretizationMethods::Box, referenceSystem>
38 {
39 using Scalar = GetPropType<TypeTag, Properties::Scalar>;
40 using Problem = GetPropType<TypeTag, Properties::Problem>;
41 using FluidSystem = GetPropType<TypeTag, Properties::FluidSystem>;
42 using VolumeVariables = GetPropType<TypeTag, Properties::VolumeVariables>;
43 using GridGeometry = GetPropType<TypeTag, Properties::GridGeometry>;
44 using FVElementGeometry = typename GridGeometry::LocalView;
45 using SubControlVolume = typename GridGeometry::SubControlVolume;
46 using SubControlVolumeFace = typename GridGeometry::SubControlVolumeFace;
47 using Extrusion = Extrusion_t<GridGeometry>;
48 using ElementVolumeVariables = typename GetPropType<TypeTag, Properties::GridVolumeVariables>::LocalView;
49 using GridFluxVariablesCache = GetPropType<TypeTag, Properties::GridFluxVariablesCache>;
50 using ElementFluxVariablesCache = typename GridFluxVariablesCache::LocalView;
51 using FluxVarCache = typename GridFluxVariablesCache::FluxVariablesCache;
52 using FluxVariables = GetPropType<TypeTag, Properties::FluxVariables>;
53 using FluxTraits = typename Dumux::FluxTraits<FluxVariables>;
54 using BalanceEqOpts = GetPropType<TypeTag, Properties::BalanceEqOpts>;
55 using GridView = typename GetPropType<TypeTag, Properties::GridGeometry>::GridView;
56 using Element = typename GridView::template Codim<0>::Entity;
57 using ModelTraits = GetPropType<TypeTag, Properties::ModelTraits>;
58 using Indices = typename ModelTraits::Indices;
59
60 enum { dim = GridView::dimension} ;
61 enum { dimWorld = GridView::dimensionworld} ;
62 enum
63 {
64 numPhases = ModelTraits::numFluidPhases(),
65 numComponents = ModelTraits::numFluidComponents()
66 };
67
68 using DimWorldMatrix = Dune::FieldMatrix<Scalar, dimWorld, dimWorld>;
69 using ComponentFluxVector = Dune::FieldVector<Scalar, numComponents>;
70 using HeatFluxScalar = Scalar;
71
72 static constexpr bool stationaryVelocityField = FluxTraits::hasStationaryVelocityField();
73
74 public:
75
76 //return the reference system
77 static constexpr ReferenceSystemFormulation referenceSystemFormulation()
78 { return referenceSystem; }
79
80 /*!
81 * \brief Returns the dispersive fluxes of all components within
82 * a fluid phase across the given sub-control volume face.
83 * The computed fluxes are given in mole/s or kg/s, depending
84 * on the template parameter ReferenceSystemFormulation.
85 */
86 9667600 static ComponentFluxVector compositionalDispersionFlux(const Problem& problem,
87 const Element& element,
88 const FVElementGeometry& fvGeometry,
89 const ElementVolumeVariables& elemVolVars,
90 const SubControlVolumeFace& scvf,
91 const int phaseIdx,
92 const ElementFluxVariablesCache& elemFluxVarsCache)
93 {
94 9667600 ComponentFluxVector componentFlux(0.0);
95
96 9667600 const auto& fluxVarsCache = elemFluxVarsCache[scvf];
97 9667600 const auto& shapeValues = fluxVarsCache.shapeValues();
98
99 // density interpolation
100 9667600 Scalar rhoMassOrMole(0.0);
101
4/4
✓ Branch 0 taken 38670400 times.
✓ Branch 1 taken 9667600 times.
✓ Branch 2 taken 38670400 times.
✓ Branch 3 taken 9667600 times.
96676000 for (auto&& scv : scvs(fvGeometry))
102 {
103 77340800 const auto rho = massOrMolarDensity(elemVolVars[scv], referenceSystem, phaseIdx);
104 77340800 rhoMassOrMole += rho * shapeValues[scv.indexInElement()][0];
105 }
106
107
2/2
✓ Branch 0 taken 19335200 times.
✓ Branch 1 taken 9667600 times.
29002800 for (int compIdx = 0; compIdx < numComponents; compIdx++)
108 {
109 // collect the dispersion tensor, the fluxVarsCache and the shape values
110 19335200 const auto& dispersionTensor =
111 19335200 ModelTraits::CompositionalDispersionModel::compositionalDispersionTensor(problem, scvf, fvGeometry,
112 elemVolVars, elemFluxVarsCache,
113 phaseIdx, compIdx);
114
115 // the mole/mass fraction gradient
116 19335200 Dune::FieldVector<Scalar, dimWorld> gradX(0.0);
117
4/4
✓ Branch 0 taken 77340800 times.
✓ Branch 1 taken 19335200 times.
✓ Branch 2 taken 77340800 times.
✓ Branch 3 taken 19335200 times.
193352000 for (auto&& scv : scvs(fvGeometry))
118 {
119 154681600 const auto x = massOrMoleFraction(elemVolVars[scv], referenceSystem, phaseIdx, compIdx);
120 232022400 gradX.axpy(x, fluxVarsCache.gradN(scv.indexInElement()));
121 }
122
123 // compute the dispersion flux
124 58005600 componentFlux[compIdx] = -1.0 * rhoMassOrMole * vtmv(scvf.unitOuterNormal(), dispersionTensor, gradX) * scvf.area();
125 19335200 if (BalanceEqOpts::mainComponentIsBalanced(phaseIdx) && !FluidSystem::isTracerFluidSystem())
126 51945600 componentFlux[phaseIdx] -= componentFlux[compIdx];
127 }
128 9667600 return componentFlux;
129 }
130
131 /*!
132 * \brief Returns the thermal dispersive flux
133 * across the given sub-control volume face.
134 */
135 5600000 static HeatFluxScalar thermalDispersionFlux(const Problem& problem,
136 const Element& element,
137 const FVElementGeometry& fvGeometry,
138 const ElementVolumeVariables& elemVolVars,
139 const SubControlVolumeFace& scvf,
140 const int phaseIdx,
141 const ElementFluxVariablesCache& elemFluxVarsCache)
142 {
143 // collect the dispersion tensor
144 5600000 const auto& dispersionTensor =
145 5600000 ModelTraits::ThermalDispersionModel::thermalDispersionTensor(problem, scvf, fvGeometry,
146 elemVolVars, elemFluxVarsCache,
147 phaseIdx);
148 // compute the temperature gradient with the shape functions
149 5600000 const auto& fluxVarsCache = elemFluxVarsCache[scvf];
150 5600000 Dune::FieldVector<Scalar, GridView::dimensionworld> gradTemp(0.0);
151
4/4
✓ Branch 0 taken 22400000 times.
✓ Branch 1 taken 5600000 times.
✓ Branch 2 taken 22400000 times.
✓ Branch 3 taken 5600000 times.
56000000 for (auto&& scv : scvs(fvGeometry))
152 112000000 gradTemp.axpy(elemVolVars[scv].temperature(), fluxVarsCache.gradN(scv.indexInElement()));
153
154 // compute the heat conduction flux
155 11200000 return -1.0*vtmv(scvf.unitOuterNormal(), dispersionTensor, gradTemp)*Extrusion::area(fvGeometry, scvf);
156 }
157
158 };
159
160 } // end namespace Dumux
161
162 #endif
163