GCC Code Coverage Report


Directory: ../../../builds/dumux-repositories/
File: /builds/dumux-repositories/dumux/test/multidomain/boundary/stokesdarcy/1p2c_2p2c/problem_darcy.hh
Date: 2024-09-21 20:52:54
Exec Total Coverage
Lines: 45 50 90.0%
Functions: 6 9 66.7%
Branches: 55 106 51.9%

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 BoundaryTests
10 * \brief A simple Darcy test problem (cell-centered finite volume method).
11 */
12
13 #ifndef DUMUX_DARCY2P2C_SUBPROBLEM_HH
14 #define DUMUX_DARCY2P2C_SUBPROBLEM_HH
15
16 #include <dumux/common/boundarytypes.hh>
17 #include <dumux/common/numeqvector.hh>
18 #include <dumux/multidomain/boundary/stokesdarcy/couplingdata.hh>
19 #include <dumux/porousmediumflow/problem.hh>
20 #include "spatialparams.hh"
21
22 namespace Dumux {
23 template <class TypeTag>
24 class DarcySubProblem;
25
26 template <class TypeTag>
27 class DarcySubProblem : public PorousMediumFlowProblem<TypeTag>
28 {
29 using ParentType = PorousMediumFlowProblem<TypeTag>;
30 using GridView = typename GetPropType<TypeTag, Properties::GridGeometry>::GridView;
31 using Scalar = GetPropType<TypeTag, Properties::Scalar>;
32 using PrimaryVariables = GetPropType<TypeTag, Properties::PrimaryVariables>;
33 using NumEqVector = Dumux::NumEqVector<PrimaryVariables>;
34 using BoundaryTypes = Dumux::BoundaryTypes<GetPropType<TypeTag, Properties::ModelTraits>::numEq()>;
35 using VolumeVariables = GetPropType<TypeTag, Properties::VolumeVariables>;
36 using FVElementGeometry = typename GetPropType<TypeTag, Properties::GridGeometry>::LocalView;
37 using SubControlVolume = typename FVElementGeometry::SubControlVolume;
38 using SubControlVolumeFace = typename FVElementGeometry::SubControlVolumeFace;
39 using GridGeometry = GetPropType<TypeTag, Properties::GridGeometry>;
40 using GridVariables = GetPropType<TypeTag, Properties::GridVariables>;
41 using ElementVolumeVariables = typename GridVariables::GridVolumeVariables::LocalView;
42 using ElementFluxVariablesCache = typename GridVariables::GridFluxVariablesCache::LocalView;
43
44 using FluidSystem = GetPropType<TypeTag, Properties::FluidSystem>;
45
46 // copy some indices for convenience
47 using Indices = typename GetPropType<TypeTag, Properties::ModelTraits>::Indices;
48 enum {
49 // primary variable indices
50 conti0EqIdx = Indices::conti0EqIdx,
51 contiWEqIdx = Indices::conti0EqIdx + FluidSystem::H2OIdx,
52 contiNEqIdx = Indices::conti0EqIdx + FluidSystem::AirIdx,
53 pressureIdx = Indices::pressureIdx,
54 switchIdx = Indices::switchIdx
55 };
56
57 using Element = typename GridView::template Codim<0>::Entity;
58 using GlobalPosition = typename Element::Geometry::GlobalCoordinate;
59
60 using CouplingManager = GetPropType<TypeTag, Properties::CouplingManager>;
61
62 using DiffusionCoefficientAveragingType = typename StokesDarcyCouplingOptions::DiffusionCoefficientAveragingType;
63
64 public:
65 2 DarcySubProblem(std::shared_ptr<const GridGeometry> gridGeometry,
66 std::shared_ptr<CouplingManager> couplingManager)
67
5/16
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
✓ Branch 8 taken 2 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 2 times.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✓ Branch 13 taken 2 times.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 23 not taken.
✗ Branch 24 not taken.
6 : ParentType(gridGeometry, "Darcy"), eps_(1e-7), couplingManager_(couplingManager)
68 {
69
2/4
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
4 pressure_ = getParamFromGroup<Scalar>(this->paramGroup(), "Problem.Pressure");
70
1/2
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
2 initialSw_ = getParamFromGroup<Scalar>(this->paramGroup(), "Problem.Saturation");
71
1/2
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
2 initialPhasePresence_ = getParamFromGroup<int>(this->paramGroup(), "Problem.InitPhasePresence");
72
73
2/6
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
2 diffCoeffAvgType_ = StokesDarcyCouplingOptions::stringToEnum(DiffusionCoefficientAveragingType{},
74
1/2
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
2 getParamFromGroup<std::string>(this->paramGroup(), "Problem.InterfaceDiffusionCoefficientAvg"));
75
8/24
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 2 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 2 times.
✗ Branch 11 not taken.
✗ Branch 13 not taken.
✓ Branch 14 taken 2 times.
✗ Branch 15 not taken.
✓ Branch 16 taken 2 times.
✗ Branch 17 not taken.
✓ Branch 18 taken 2 times.
✗ Branch 19 not taken.
✓ Branch 20 taken 2 times.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
✗ Branch 24 not taken.
✗ Branch 25 not taken.
✗ Branch 26 not taken.
✗ Branch 27 not taken.
✗ Branch 28 not taken.
2 problemName_ = getParam<std::string>("Vtk.OutputName") + "_" + getParamFromGroup<std::string>(this->paramGroup(), "Problem.Name");
76 2 }
77
78 /*!
79 * \brief The problem name.
80 */
81 const std::string& name() const
82 {
83
1/2
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
2 return problemName_;
84 }
85
86 template<class SolutionVector, class GridVariables>
87 79 void printWaterMass(const SolutionVector& curSol,
88 const GridVariables& gridVariables,
89 const Scalar timeStepSize)
90
91 {
92 // compute the mass in the entire domain
93 79 Scalar massWater = 0.0;
94
95 // bulk elements
96
2/4
✓ Branch 1 taken 79 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 79 times.
✗ Branch 5 not taken.
237 auto fvGeometry = localView(this->gridGeometry());
97
2/4
✓ Branch 1 taken 79 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 79 times.
✗ Branch 5 not taken.
158 auto elemVolVars = localView(gridVariables.curGridVolVars());
98
5/10
✓ Branch 1 taken 79 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 79 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 79 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 5135 times.
✗ Branch 10 not taken.
✓ Branch 12 taken 5056 times.
✗ Branch 13 not taken.
10349 for (const auto& element : elements(this->gridGeometry().gridView()))
99 {
100
1/2
✓ Branch 1 taken 5056 times.
✗ Branch 2 not taken.
5056 fvGeometry.bindElement(element);
101
1/2
✓ Branch 1 taken 5056 times.
✗ Branch 2 not taken.
5056 elemVolVars.bindElement(element, fvGeometry, curSol);
102
103
2/2
✓ Branch 0 taken 5056 times.
✓ Branch 1 taken 5056 times.
10112 for (auto&& scv : scvs(fvGeometry))
104 {
105 5056 const auto& volVars = elemVolVars[scv];
106
2/2
✓ Branch 0 taken 10112 times.
✓ Branch 1 taken 5056 times.
15168 for(int phaseIdx = 0; phaseIdx < FluidSystem::numPhases; ++phaseIdx)
107 {
108
1/2
✓ Branch 1 taken 10112 times.
✗ Branch 2 not taken.
10112 massWater += volVars.massFraction(phaseIdx, FluidSystem::H2OIdx)*volVars.density(phaseIdx)
109 30336 * scv.volume() * volVars.saturation(phaseIdx) * volVars.porosity() * volVars.extrusionFactor();
110 }
111 }
112 }
113
114
2/4
✓ Branch 4 taken 79 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 79 times.
✗ Branch 8 not taken.
316 std::cout << std::setprecision(15) << "mass of water is: " << massWater << std::endl;
115 79 }
116
117 /*!
118 * \name Boundary conditions
119 */
120 // \{
121 /*!
122 * \brief Specifies which kind of boundary condition should be
123 * used for which equation on a given boundary control volume.
124 *
125 * \param element The element
126 * \param scvf The boundary sub control volume face
127 */
128 60580 BoundaryTypes boundaryTypes(const Element &element, const SubControlVolumeFace &scvf) const
129 {
130 60580 BoundaryTypes values;
131 60580 values.setAllNeumann();
132
133
2/2
✓ Branch 0 taken 24352 times.
✓ Branch 1 taken 36228 times.
60580 if (couplingManager().isCoupledEntity(CouplingManager::darcyIdx, scvf))
134 values.setAllCouplingNeumann();
135
136 60580 return values;
137 }
138
139 /*!
140 * \brief Evaluates the boundary conditions for a Dirichlet control volume.
141 *
142 * \param element The element for which the Dirichlet boundary condition is set
143 * \param scvf The boundary sub control volume face
144 *
145 * For this method, the \a values parameter stores primary variables.
146 */
147 PrimaryVariables dirichlet(const Element &element, const SubControlVolumeFace &scvf) const
148 {
149 PrimaryVariables values(0.0);
150 values = initialAtPos(scvf.center());
151
152 return values;
153 }
154
155 /*!
156 * \brief Evaluates the boundary conditions for a Neumann control volume.
157 *
158 * \param element The element for which the Neumann boundary condition is set
159 * \param fvGeometry The fvGeometry
160 * \param elemVolVars The element volume variables
161 * \param elemFluxVarsCache Flux variables caches for all faces in stencil
162 * \param scvf The boundary sub control volume face
163 */
164 50852 NumEqVector neumann(const Element& element,
165 const FVElementGeometry& fvGeometry,
166 const ElementVolumeVariables& elemVolVars,
167 const ElementFluxVariablesCache& elemFluxVarsCache,
168 const SubControlVolumeFace& scvf) const
169 {
170 50852 NumEqVector values(0.0);
171
172
2/2
✓ Branch 0 taken 21920 times.
✓ Branch 1 taken 28932 times.
50852 if (couplingManager().isCoupledEntity(CouplingManager::darcyIdx, scvf))
173 {
174 #if !NONISOTHERMAL
175 9600 values = couplingManager().couplingData().massCouplingCondition(element, fvGeometry, elemVolVars, scvf, diffCoeffAvgType_);
176 #else
177 12320 const auto massFlux = couplingManager().couplingData().massCouplingCondition(element, fvGeometry, elemVolVars, scvf, diffCoeffAvgType_);
178
179
2/2
✓ Branch 0 taken 24640 times.
✓ Branch 1 taken 12320 times.
36960 for(int i = 0; i< massFlux.size(); ++i)
180 73920 values[i] = massFlux[i];
181
182 12320 values[Indices::energyEqIdx] = couplingManager().couplingData().energyCouplingCondition(element, fvGeometry, elemVolVars, scvf, diffCoeffAvgType_);
183 #endif
184 }
185
186 50852 return values;
187 }
188
189 // \}
190
191 /*!
192 * \name Volume terms
193 */
194 // \{
195 /*!
196 * \brief Evaluates the source term for all phases within a given
197 * sub control volume.
198 *
199 * \param element The element for which the source term is set
200 * \param fvGeometry The fvGeometry
201 * \param elemVolVars The element volume variables
202 * \param scv The sub control volume
203 *
204 * For this method, the \a values variable stores the rate mass
205 * of a component is generated or annihilated per volume
206 * unit. Positive values mean that mass is created, negative ones
207 * mean that it vanishes.
208 */
209 NumEqVector source(const Element &element,
210 const FVElementGeometry& fvGeometry,
211 const ElementVolumeVariables& elemVolVars,
212 const SubControlVolume &scv) const
213 116416 { return NumEqVector(0.0); }
214
215 // \}
216
217 /*!
218 * \brief Evaluates the initial value for a control volume.
219 *
220 * For this method, the \a priVars parameter stores primary
221 * variables.
222 */
223 PrimaryVariables initialAtPos(const GlobalPosition &globalPos) const
224 {
225 128 PrimaryVariables values(0.0);
226 256 values.setState(initialPhasePresence_);
227
228 1152 values[pressureIdx] = pressure_ + 1000. * this->spatialParams().gravity(globalPos)[1] * (globalPos[1] - this->gridGeometry().bBoxMax()[1]);
229 256 values[switchIdx] = initialSw_;
230
231 #if NONISOTHERMAL
232 192 values[Indices::temperatureIdx] = this->spatialParams().temperatureAtPos(globalPos);
233 #endif
234 return values;
235 }
236
237 // \}
238
239 //! Get the coupling manager
240 const CouplingManager& couplingManager() const
241
10/10
✓ Branch 0 taken 21920 times.
✓ Branch 1 taken 28932 times.
✓ Branch 2 taken 21920 times.
✓ Branch 3 taken 28932 times.
✓ Branch 6 taken 10800 times.
✓ Branch 7 taken 15900 times.
✓ Branch 8 taken 24352 times.
✓ Branch 9 taken 36228 times.
✓ Branch 10 taken 13552 times.
✓ Branch 11 taken 20328 times.
247504 { return *couplingManager_; }
242
243 private:
244 bool onLeftBoundary_(const GlobalPosition &globalPos) const
245 { return globalPos[0] < this->gridGeometry().bBoxMin()[0] + eps_; }
246
247 bool onRightBoundary_(const GlobalPosition &globalPos) const
248 { return globalPos[0] > this->gridGeometry().bBoxMax()[0] - eps_; }
249
250 bool onLowerBoundary_(const GlobalPosition &globalPos) const
251 { return globalPos[1] < this->gridGeometry().bBoxMin()[1] + eps_; }
252
253 bool onUpperBoundary_(const GlobalPosition &globalPos) const
254 { return globalPos[1] > this->gridGeometry().bBoxMax()[1] - eps_; }
255
256 Scalar pressure_;
257 Scalar initialSw_;
258 int initialPhasePresence_;
259 std::string problemName_;
260 Scalar eps_;
261
262 std::shared_ptr<CouplingManager> couplingManager_;
263 DiffusionCoefficientAveragingType diffCoeffAvgType_;
264 };
265 } // end namespace Dumux
266
267 #endif
268