GCC Code Coverage Report


Directory: ../../../builds/dumux-repositories/
File: /builds/dumux-repositories/dumux/test/multidomain/embedded/1d3d/1p2c_richards2c/problem_soil.hh
Date: 2024-05-04 19:09:25
Exec Total Coverage
Lines: 50 56 89.3%
Functions: 4 6 66.7%
Branches: 42 92 45.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 EmbeddedTests
10 * \brief Definition of a problem, for the 1p2c problem:
11 * Component transport of oxygen in interstitial fluid.
12 */
13
14 #ifndef DUMUX_TISSUE_PROBLEM_HH
15 #define DUMUX_TISSUE_PROBLEM_HH
16
17 #include <dune/geometry/quadraturerules.hh>
18 #include <dune/localfunctions/lagrange/pqkfactory.hh>
19
20 #include <dumux/common/boundarytypes.hh>
21 #include <dumux/common/math.hh>
22 #include <dumux/common/parameters.hh>
23 #include <dumux/common/properties.hh>
24 #include <dumux/common/numeqvector.hh>
25
26 #include <dumux/porousmediumflow/problem.hh>
27
28 namespace Dumux {
29
30 /*!
31 * \ingroup EmbeddedTests
32 * \brief Definition of a problem, for the 1p2c problem:
33 * Component transport of oxygen in interstitial fluid.
34 */
35 template <class TypeTag>
36 class SoilProblem : public PorousMediumFlowProblem<TypeTag>
37 {
38 using ParentType = PorousMediumFlowProblem<TypeTag>;
39 using Scalar = GetPropType<TypeTag, Properties::Scalar>;
40 using GridGeometry = GetPropType<TypeTag, Properties::GridGeometry>;
41 using FVElementGeometry = typename GridGeometry::LocalView;
42 using SubControlVolume = typename GridGeometry::SubControlVolume;
43 using GridView = typename GridGeometry::GridView;
44 using GlobalPosition = typename GridGeometry::GlobalCoordinate;
45 using PrimaryVariables = GetPropType<TypeTag, Properties::PrimaryVariables>;
46 using NumEqVector = Dumux::NumEqVector<PrimaryVariables>;
47 using SolutionVector = GetPropType<TypeTag, Properties::SolutionVector>;
48 using GridVariables = GetPropType<TypeTag, Properties::GridVariables>;
49 using BoundaryTypes = Dumux::BoundaryTypes<GetPropType<TypeTag, Properties::ModelTraits>::numEq()>;
50 using PointSource = GetPropType<TypeTag, Properties::PointSource>;
51 using Element = typename GridView::template Codim<0>::Entity;
52
53 using CouplingManager = GetPropType<TypeTag, Properties::CouplingManager>;
54
55 public:
56 using FluidSystem = GetPropType<TypeTag, Properties::FluidSystem>;
57 enum Indices {
58 // world dimension
59 dim = GridView::dimension,
60 dimWorld = GridView::dimensionworld,
61
62 pressureIdx = 0,
63 transportCompIdx = 1,
64
65 conti0EqIdx = 0,
66 transportEqIdx = 1,
67
68 liquidPhaseIdx = FluidSystem::liquidPhaseIdx
69 };
70
71 1 SoilProblem(std::shared_ptr<const GridGeometry> gridGeometry,
72 std::shared_ptr<CouplingManager> couplingManager)
73 : ParentType(gridGeometry, "Soil")
74
5/16
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 8 taken 1 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 1 times.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✓ Branch 13 taken 1 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.
3 , couplingManager_(couplingManager)
75 {
76 //read parameters from input file
77
9/24
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 1 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 1 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 1 times.
✗ Branch 14 not taken.
✗ Branch 16 not taken.
✓ Branch 17 taken 1 times.
✗ Branch 18 not taken.
✓ Branch 19 taken 1 times.
✗ Branch 20 not taken.
✓ Branch 21 taken 1 times.
✗ Branch 22 not taken.
✓ Branch 23 taken 1 times.
✗ Branch 24 not taken.
✗ Branch 25 not taken.
✗ Branch 26 not taken.
✗ Branch 27 not taken.
✗ Branch 28 not taken.
✗ Branch 29 not taken.
2 name_ = getParam<std::string>("Vtk.OutputName") + "_" + getParamFromGroup<std::string>(this->paramGroup(), "Problem.Name");
78
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 contaminantMoleFraction_ = getParam<Scalar>("Problem.ContaminantMoleFraction");
79
80 // for initial conditions
81
1/4
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
1 const Scalar sw = getParam<Scalar>("Problem.InitTopSaturation", 0.3); // start with 30% saturation on top
82 5 pcTop_ = this->spatialParams().fluidMatrixInteractionAtPos(gridGeometry->bBoxMax()).pc(sw);
83 1 }
84
85 /*!
86 * \name Problem parameters
87 */
88 // \{
89
90 /*!
91 * \brief The problem name.
92 *
93 * This is used as a prefix for files generated by the simulation.
94 */
95 const std::string& name() const
96
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 { return name_; }
97
98 /*
99 * \brief Returns the reference pressure [Pa] of the nonwetting
100 * fluid phase within a finite volume.
101 *
102 * This problem assumes a constant reference pressure of 1 bar.
103 */
104 Scalar nonwettingReferencePressure() const
105 { return 1.0e5; }
106
107
108 // \}
109
110 /*!
111 * \name Boundary conditions
112 */
113 // \{
114
115 /*!
116 * \brief Specifies which kind of boundary condition should be
117 * used for which equation on a given boundary segment.
118 *
119 * \param globalPos The position for which the bc type should be evaluated
120 */
121 BoundaryTypes boundaryTypesAtPos(const GlobalPosition &globalPos) const
122 {
123 93708 BoundaryTypes values;
124
2/4
✗ Branch 0 not taken.
✓ Branch 1 taken 69768 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 23940 times.
93708 values.setAllNeumann();
125 return values;
126 }
127
128 /*!
129 * \brief Evaluates the boundary conditions for a Dirichlet boundary segment.
130 *
131 * \param globalPos The position for which the bc type should be evaluated
132 *
133 * For this method, the \a values parameter stores primary variables.
134 */
135 PrimaryVariables dirichletAtPos(const GlobalPosition &globalPos) const
136 { return initialAtPos(globalPos); }
137
138 // \}
139
140 /*!
141 * \name Volume terms
142 */
143 // \{
144
145 /*!
146 * \brief Applies a vector of point sources which are possibly solution dependent.
147 *
148 * \param pointSources A vector of Dumux::PointSource s that contain
149 source values for all phases and space positions.
150 *
151 * For this method, the \a values method of the point source
152 * has to return the absolute mass rate in kg/s. Positive values mean
153 * that mass is created, negative ones mean that it vanishes.
154 */
155 void addPointSources(std::vector<PointSource>& pointSources) const
156
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 { pointSources = this->couplingManager().bulkPointSources(); }
157
158 /*!
159 * \brief Evaluates the point sources (added by addPointSources)
160 * for all phases within a given sub control volume.
161 *
162 * This is the method for the case where the point source is
163 * solution dependent and requires some quantities that
164 * are specific to the fully-implicit method.
165 *
166 * \param source A single point source
167 * \param element The finite element
168 * \param fvGeometry The finite-volume geometry
169 * \param elemVolVars All volume variables for the element
170 * \param scv The sub control volume within the element
171 *
172 * For this method, the \a values() method of the point sources returns
173 * the absolute rate mass generated or annihilated in kg/s. Positive values mean
174 * that mass is created, negative ones mean that it vanishes.
175 */
176 template<class ElementVolumeVariables>
177 2853484 void pointSource(PointSource& source,
178 const Element &element,
179 const FVElementGeometry& fvGeometry,
180 const ElementVolumeVariables& elemVolVars,
181 const SubControlVolume &scv) const
182 {
183 2853484 NumEqVector sourceValues;
184
185 // compute source at every integration point
186 8560452 const auto priVars3D = this->couplingManager().bulkPriVars(source.id());
187 8560452 const auto priVars1D = this->couplingManager().lowDimPriVars(source.id());
188
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2853484 times.
2853484 const Scalar pressure3D = priVars3D[pressureIdx];
189
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2853484 times.
2853484 const Scalar pressure1D = priVars1D[pressureIdx];
190
191
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2853484 times.
2853484 const auto& spatialParams = this->couplingManager().problem(Dune::index_constant<1>{}).spatialParams();
192 8560452 const auto lowDimElementIdx = this->couplingManager().pointSourceData(source.id()).lowDimElementIdx();
193 2853484 const Scalar Kr = spatialParams.Kr(lowDimElementIdx);
194
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2853484 times.
2853484 const Scalar rootRadius = spatialParams.radius(lowDimElementIdx);
195
196 // sink defined as radial flow Jr * density [m^2 s-1]* [kg m-3]
197 2853484 const auto molarDensityH20 = 1000 / 0.018;
198
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2853484 times.
2853484 sourceValues[conti0EqIdx] = 2 * M_PI * rootRadius * Kr * (pressure1D - pressure3D) * molarDensityH20;
199
200
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2853484 times.
2853484 const Scalar x3D = priVars3D[transportCompIdx];
201
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2853484 times.
2853484 const Scalar x1D = priVars1D[transportCompIdx];
202
203 //! Advective transport over root wall
204 // compute correct upwind concentration
205
2/4
✗ Branch 0 not taken.
✓ Branch 1 taken 2853484 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 2853484 times.
5706968 if (sourceValues[conti0EqIdx] > 0)
206 sourceValues[transportEqIdx] = sourceValues[conti0EqIdx]*x1D;
207 else
208 8560452 sourceValues[transportEqIdx] = sourceValues[conti0EqIdx]*x3D;
209
210 //! Diffusive transport over root wall
211 2853484 const auto molarDensityD20 = 1000 / 0.020;
212 2853484 sourceValues[transportEqIdx] += 2 * M_PI * rootRadius * 1.0e-8 * (x1D - x3D) * molarDensityD20;
213
214 2853484 sourceValues *= source.quadratureWeight()*source.integrationElement();
215 5706968 source = sourceValues;
216 2853484 }
217
218 /*!
219 * \brief Evaluates the initial value for a control volume.
220 *
221 * \param globalPos The position for which the initial condition should be evaluated
222 *
223 * For this method, the \a values parameter stores primary
224 * variables.
225 */
226 3198 PrimaryVariables initialAtPos(const GlobalPosition &globalPos) const
227 {
228
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 3197 times.
3198 const auto& gg = this->gridGeometry();
229
3/4
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 3197 times.
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
3198 static const Scalar extend = 0.15*(gg.bBoxMax()[0]-gg.bBoxMin()[0]);
230 3198 const auto xTracer = [&]()
231 {
232 9594 auto contaminationPos = gg.bBoxMax()-gg.bBoxMin();
233 3198 contaminationPos[0] *= 0.26;
234 3198 contaminationPos[1] *= 0.56;
235 3198 contaminationPos[2] *= 0.26;
236 6396 contaminationPos += gg.bBoxMin();
237
238
2/2
✓ Branch 0 taken 216 times.
✓ Branch 1 taken 2982 times.
9594 if ((globalPos - contaminationPos).infinity_norm() < extend + eps_)
239 216 return contaminantMoleFraction_;
240 else
241 return 0.0;
242 3414 }();
243
244 3198 PrimaryVariables priVars(0.0);
245 //! Hydrostatic pressure profile
246 9594 priVars[pressureIdx] = (nonwettingReferencePressure() - pcTop_)
247 12792 -9.81*1000*(globalPos[dimWorld-1] - gg.bBoxMax()[dimWorld-1]);
248 6396 priVars[transportCompIdx] = xTracer;
249 3198 return priVars;
250 }
251
252 //! Get the coupling manager
253 const CouplingManager& couplingManager() const
254
6/12
✗ Branch 2 not taken.
✓ Branch 3 taken 2853484 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 2853484 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 2853484 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 2853484 times.
✓ Branch 11 taken 1 times.
✗ Branch 12 not taken.
✓ Branch 14 taken 1 times.
✗ Branch 15 not taken.
11413938 { return *couplingManager_; }
255
256 private:
257 Scalar pcTop_, contaminantMoleFraction_;
258
259 static constexpr Scalar eps_ = 1.5e-7;
260 std::string name_;
261
262 std::shared_ptr<CouplingManager> couplingManager_;
263 };
264
265 } // end namespace Dumux
266
267 #endif
268