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-09-21 20:52:54
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 1 SoilProblem(std::shared_ptr<const GridGeometry> gridGeometry,
51 std::shared_ptr<CouplingManager> couplingManager)
52 : ParentType(gridGeometry, "Soil")
53
5/18
✓ 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.
✗ Branch 25 not taken.
✗ Branch 26 not taken.
3 , couplingManager_(couplingManager)
54 {
55 // read parameters from input file
56
3/6
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✗ Branch 7 not taken.
✓ Branch 8 taken 1 times.
2 name_ = getParamFromGroup<std::string>(this->paramGroup(), "Problem.Name");
57
58
6/14
✓ 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 9 taken 1 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 1 times.
✗ Branch 12 not taken.
✓ Branch 13 taken 1 times.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
5 if (hasParam("BoundaryConditions.InitialSoilSaturationTop"))
59 {
60
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 const auto sw = getParam<Scalar>("BoundaryConditions.InitialSoilSaturationTop");
61 5 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 1 times.
✗ Branch 2 not taken.
1 kernelWidthFactor_ = getParam<Scalar>("MixedDimension.KernelWidthFactor");
70 1 }
71
72 const std::string& name() const
73
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 { 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 4453851 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 3004379 times.
7458230 BoundaryTypes values;
81
2/4
✗ Branch 0 not taken.
✓ Branch 1 taken 4453851 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 3004379 times.
7458230 values.setAllNeumann();
82 return values;
83 }
84
85 template<class ElementVolumeVariables>
86 21403273 NumEqVector source(const Element &element,
87 const FVElementGeometry& fvGeometry,
88 const ElementVolumeVariables& elemVolVars,
89 const SubControlVolume &scv) const
90 {
91 21403273 NumEqVector values(0.0);
92
93 64209819 const auto eIdx = this->gridGeometry().elementMapper().index(element);
94 64209819 const auto& sourceIds = this->couplingManager().bulkSourceIds(eIdx);
95 64209819 const auto& sourceWeights = this->couplingManager().bulkSourceWeights(eIdx);
96
97
4/4
✓ Branch 0 taken 150023814 times.
✓ Branch 1 taken 21403272 times.
✓ Branch 2 taken 150023814 times.
✓ Branch 3 taken 21403272 times.
321450899 for (int i = 0; i < sourceIds.size(); ++i)
98 {
99 150023814 const auto id = sourceIds[i];
100 150023814 const auto weight = sourceWeights[i];
101
102 // compute source at every integration point
103 450071442 const Scalar p0 = this->couplingManager().bulkPriVars(id)[Indices::pressureIdx];
104 450071442 const Scalar pRoot = this->couplingManager().lowDimPriVars(id)[Indices::pressureIdx];
105 450071442 const Scalar radius = this->couplingManager().radius(id);
106 150023814 const Scalar kernelRadius = kernelWidthFactor_*radius;
107 450071442 const Scalar Kr = this->couplingManager().Kr(id);
108 150023814 const Scalar density = 1000;
109 150023814 const Scalar viscosity = 1e-3;
110 450071442 const Scalar delta = this->couplingManager().averageDistance(id);
111
112 // sink defined as radial flow Jr * density [m^2 s-1]* [kg m-3]
113 450071442 const auto lEIdx = this->couplingManager().pointSourceData(id).lowDimElementIdx();
114 450071442 const auto bEIdx = this->couplingManager().pointSourceData(id).bulkElementIdx();
115 150023814 const auto sourceValue = this->couplingManager().reconstruction().computeSource(
116 bEIdx, lEIdx, p0, pRoot, kernelRadius, radius, Kr, density, viscosity, id, delta
117 );
118 150023813 values[Indices::conti0EqIdx] += sourceValue*weight;
119 }
120
121 21403272 const auto volume = scv.volume()*elemVolVars[scv].extrusionFactor();
122 21403272 values[Indices::conti0EqIdx] /= volume;
123
124 21403272 return values;
125 }
126
127 7680 PrimaryVariables initialAtPos(const GlobalPosition &globalPos) const
128 {
129
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 7679 times.
7680 PrimaryVariables priVars(0.0);
130
4/6
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 7679 times.
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 1 times.
✗ Branch 7 not taken.
7680 static const bool initialGravityProfile = getParam<bool>("BoundaryConditions.InitialGravityProfile");
131
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 7680 times.
7680 if (initialGravityProfile)
132 priVars[0] = nonwettingReferencePressure() - pcTop_ - 9.81*1000*(globalPos[2] - this->gridGeometry().bBoxMax()[2]);
133 else
134 7680 priVars[0] = nonwettingReferencePressure() - pcTop_;
135 7680 return priVars;
136 }
137
138 //! Called after every time step
139 //! Output the total global exchange term
140 230 void computeSourceIntegral(const SolutionVector& sol, const GridVariables& gridVars)
141 {
142 230 PrimaryVariables source(0.0);
143
1/2
✓ Branch 3 taken 1766630 times.
✗ Branch 4 not taken.
3533490 for (const auto& element : elements(this->gridGeometry().gridView()))
144 {
145 3532800 auto fvGeometry = localView(this->gridGeometry());
146 1766400 fvGeometry.bindElement(element);
147
148 5299200 auto elemVolVars = localView(gridVars.curGridVolVars());
149 1766400 elemVolVars.bindElement(element, fvGeometry, sol);
150
151
5/6
✓ Branch 0 taken 1766400 times.
✓ Branch 1 taken 1766400 times.
✓ Branch 2 taken 1766400 times.
✓ Branch 3 taken 1766400 times.
✓ Branch 5 taken 1766400 times.
✗ Branch 6 not taken.
7065600 for (auto&& scv : scvs(fvGeometry))
152 {
153
1/2
✓ Branch 1 taken 1766400 times.
✗ Branch 2 not taken.
1766400 auto pointSources = this->source(element, fvGeometry, elemVolVars, scv);
154 1766400 pointSources *= scv.volume()*elemVolVars[scv].extrusionFactor();
155 1766400 source += pointSources;
156 }
157 }
158
159 460 std::cout << "Global integrated source (soil): " << source << " (kg/s) / "
160 460 << source*3600*24*1000 << " (g/day)" << '\n';
161
162 230 }
163
164 //! Get the coupling manager
165 const CouplingManager& couplingManager() const
166 985755976 { 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