GCC Code Coverage Report


Directory: ../../../builds/dumux-repositories/
File: /builds/dumux-repositories/dumux/test/multidomain/embedded/1d3d/root_soil_benchmark/problem_soil.hh
Date: 2024-05-04 19:09:25
Exec Total Coverage
Lines: 55 62 88.7%
Functions: 4 6 66.7%
Branches: 39 78 50.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 EmbeddedTests
10 * \brief The soil problem for the benchmark cases C1.2a/b from Schnepf et al (2020) https://doi.org/10.3389/fpls.2020.00316
11 */
12 #ifndef DUMUX_TEST_ROOT_SOIL_BENCHMARK_SOIL_PROBLEM_HH
13 #define DUMUX_TEST_ROOT_SOIL_BENCHMARK_SOIL_PROBLEM_HH
14
15 #include <dumux/common/math.hh>
16 #include <dumux/common/parameters.hh>
17 #include <dumux/common/properties.hh>
18 #include <dumux/common/boundarytypes.hh>
19 #include <dumux/common/numeqvector.hh>
20
21 #include <dumux/porousmediumflow/problem.hh>
22
23 namespace Dumux {
24
25 /*!
26 * \ingroup EmbeddedTests
27 * \brief The soil problem for the benchmark cases C1.2a/b from Schnepf et al (2020) https://doi.org/10.3389/fpls.2020.00316
28 */
29 template <class TypeTag>
30 class SoilProblem : public PorousMediumFlowProblem<TypeTag>
31 {
32 using ParentType = PorousMediumFlowProblem<TypeTag>;
33 using Scalar = GetPropType<TypeTag, Properties::Scalar>;
34 using GridGeometry = GetPropType<TypeTag, Properties::GridGeometry>;
35 using GridView = typename GridGeometry::GridView;
36 using FVElementGeometry = typename GridGeometry::LocalView;
37 using SubControlVolume = typename GridGeometry::SubControlVolume;
38 using GlobalPosition = typename GridGeometry::GlobalCoordinate;
39 using Element = typename GridView::template Codim<0>::Entity;
40 using PrimaryVariables = GetPropType<TypeTag, Properties::PrimaryVariables>;
41 using NumEqVector = Dumux::NumEqVector<PrimaryVariables>;
42 using SolutionVector = GetPropType<TypeTag, Properties::SolutionVector>;
43 using GridVariables = GetPropType<TypeTag, Properties::GridVariables>;
44 using BoundaryTypes = Dumux::BoundaryTypes<PrimaryVariables::size()>;
45 using PointSource = GetPropType<TypeTag, Properties::PointSource>;
46 using Indices = typename GetPropType<TypeTag, Properties::ModelTraits>::Indices;
47 using CouplingManager = GetPropType<TypeTag, Properties::CouplingManager>;
48
49 public:
50 2 SoilProblem(std::shared_ptr<const GridGeometry> gridGeometry,
51 std::shared_ptr<CouplingManager> couplingManager)
52 : ParentType(gridGeometry, "Soil")
53
5/18
✓ 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.
✗ Branch 25 not taken.
✗ Branch 26 not taken.
6 , couplingManager_(couplingManager)
54 {
55 // read parameters from input file
56
3/6
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
✗ Branch 7 not taken.
✓ Branch 8 taken 2 times.
4 name_ = getParamFromGroup<std::string>(this->paramGroup(), "Problem.Name");
57
58
6/14
✓ 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 9 taken 2 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 2 times.
✗ Branch 12 not taken.
✓ Branch 13 taken 2 times.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
10 if (hasParam("BoundaryConditions.InitialSoilSaturationTop"))
59 {
60
1/2
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
2 const auto sw = getParam<Scalar>("BoundaryConditions.InitialSoilSaturationTop");
61 10 pcTop_ = this->spatialParams().fluidMatrixInteractionAtPos(this->gridGeometry().bBoxMax()).pc(sw);
62 }
63 else
64 {
65 const auto pw = getParam<Scalar>("BoundaryConditions.InitialSoilPressureTop");
66 pcTop_ = nonwettingReferencePressure() - pw;
67 }
68
69
1/2
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
2 kernelWidthFactor_ = getParam<Scalar>("MixedDimension.KernelWidthFactor");
70 2 }
71
72 const std::string& name() const
73
1/2
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
2 { return name_; }
74
75 Scalar nonwettingReferencePressure() const
76 { return 1.0e5; }
77
78 BoundaryTypes boundaryTypesAtPos(const GlobalPosition &globalPos) const
79 {
80
2/4
✗ Branch 0 not taken.
✓ Branch 1 taken 8617435 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 5820635 times.
14438070 BoundaryTypes values;
81
2/4
✗ Branch 0 not taken.
✓ Branch 1 taken 8617435 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 5820635 times.
14438070 values.setAllNeumann();
82 return values;
83 }
84
85 template<class ElementVolumeVariables>
86 41429083 NumEqVector source(const Element &element,
87 const FVElementGeometry& fvGeometry,
88 const ElementVolumeVariables& elemVolVars,
89 const SubControlVolume &scv) const
90 {
91 41429083 NumEqVector values(0.0);
92
93 124287249 const auto eIdx = this->gridGeometry().elementMapper().index(element);
94 124287249 const auto& sourceIds = this->couplingManager().bulkSourceIds(eIdx);
95 124287249 const auto& sourceWeights = this->couplingManager().bulkSourceWeights(eIdx);
96
97
4/4
✓ Branch 0 taken 289574608 times.
✓ Branch 1 taken 41429082 times.
✓ Branch 2 taken 289574608 times.
✓ Branch 3 taken 41429082 times.
620578297 for (int i = 0; i < sourceIds.size(); ++i)
98 {
99 289574608 const auto id = sourceIds[i];
100 289574608 const auto weight = sourceWeights[i];
101
102 // compute source at every integration point
103 868723824 const Scalar p0 = this->couplingManager().bulkPriVars(id)[Indices::pressureIdx];
104 868723824 const Scalar pRoot = this->couplingManager().lowDimPriVars(id)[Indices::pressureIdx];
105 868723824 const Scalar radius = this->couplingManager().radius(id);
106 289574608 const Scalar kernelRadius = kernelWidthFactor_*radius;
107 868723824 const Scalar Kr = this->couplingManager().Kr(id);
108 289574608 const Scalar density = 1000;
109 289574608 const Scalar viscosity = 1e-3;
110 868723824 const Scalar delta = this->couplingManager().averageDistance(id);
111
112 // sink defined as radial flow Jr * density [m^2 s-1]* [kg m-3]
113 868723824 const auto lEIdx = this->couplingManager().pointSourceData(id).lowDimElementIdx();
114 868723824 const auto bEIdx = this->couplingManager().pointSourceData(id).bulkElementIdx();
115 289574608 const auto sourceValue = this->couplingManager().reconstruction().computeSource(
116 bEIdx, lEIdx, p0, pRoot, kernelRadius, radius, Kr, density, viscosity, id, delta
117 );
118 289574607 values[Indices::conti0EqIdx] += sourceValue*weight;
119 }
120
121 41429082 const auto volume = scv.volume()*elemVolVars[scv].extrusionFactor();
122 41429082 values[Indices::conti0EqIdx] /= volume;
123
124 41429082 return values;
125 }
126
127 15360 PrimaryVariables initialAtPos(const GlobalPosition &globalPos) const
128 {
129
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 15358 times.
15360 PrimaryVariables priVars(0.0);
130
4/6
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 15358 times.
✓ Branch 3 taken 2 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 2 times.
✗ Branch 7 not taken.
15360 static const bool initialGravityProfile = getParam<bool>("BoundaryConditions.InitialGravityProfile");
131
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 15360 times.
15360 if (initialGravityProfile)
132 priVars[0] = nonwettingReferencePressure() - pcTop_ - 9.81*1000*(globalPos[2] - this->gridGeometry().bBoxMax()[2]);
133 else
134 15360 priVars[0] = nonwettingReferencePressure() - pcTop_;
135 15360 return priVars;
136 }
137
138 //! Called after every time step
139 //! Output the total global exchange term
140 451 void computeSourceIntegral(const SolutionVector& sol, const GridVariables& gridVars)
141 {
142 451 PrimaryVariables source(0.0);
143
1/2
✓ Branch 3 taken 3464131 times.
✗ Branch 4 not taken.
6928713 for (const auto& element : elements(this->gridGeometry().gridView()))
144 {
145 6927360 auto fvGeometry = localView(this->gridGeometry());
146 3463680 fvGeometry.bindElement(element);
147
148 10391040 auto elemVolVars = localView(gridVars.curGridVolVars());
149 3463680 elemVolVars.bindElement(element, fvGeometry, sol);
150
151
5/6
✓ Branch 0 taken 3463680 times.
✓ Branch 1 taken 3463680 times.
✓ Branch 2 taken 3463680 times.
✓ Branch 3 taken 3463680 times.
✓ Branch 5 taken 3463680 times.
✗ Branch 6 not taken.
13854720 for (auto&& scv : scvs(fvGeometry))
152 {
153
1/2
✓ Branch 1 taken 3463680 times.
✗ Branch 2 not taken.
3463680 auto pointSources = this->source(element, fvGeometry, elemVolVars, scv);
154 3463680 pointSources *= scv.volume()*elemVolVars[scv].extrusionFactor();
155 3463680 source += pointSources;
156 }
157 }
158
159 902 std::cout << "Global integrated source (soil): " << source << " (kg/s) / "
160 902 << source*3600*24*1000 << " (g/day)" << '\n';
161
162 451 }
163
164 //! Get the coupling manager
165 const CouplingManager& couplingManager() const
166 1903163980 { return *couplingManager_; }
167
168 private:
169 Scalar pcTop_;
170 Scalar kernelWidthFactor_;
171
172 static constexpr Scalar eps_ = 1.5e-7;
173 std::string name_;
174
175 std::shared_ptr<CouplingManager> couplingManager_;
176 };
177
178 } // end namespace Dumux
179
180 #endif
181