GCC Code Coverage Report


Directory: ../../../builds/dumux-repositories/
File: /builds/dumux-repositories/dumux/test/multidomain/embedded/1d3d/1p_richards/problem_soil.hh
Date: 2024-05-04 19:09:25
Exec Total Coverage
Lines: 37 43 86.0%
Functions: 9 15 60.0%
Branches: 63 125 50.4%

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
25 #include <dumux/porousmediumflow/problem.hh>
26 #include <dumux/multidomain/embedded/couplingmanager1d3d_projection.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 GridView = typename GridGeometry::GridView;
42 using FVElementGeometry = typename GridGeometry::LocalView;
43 using SubControlVolume = typename GridGeometry::SubControlVolume;
44 using GlobalPosition = typename GridGeometry::GlobalCoordinate;
45 using Element = typename GridView::template Codim<0>::Entity;
46 using PrimaryVariables = GetPropType<TypeTag, Properties::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 Indices = typename GetPropType<TypeTag, Properties::ModelTraits>::Indices;
52 using CouplingManager = GetPropType<TypeTag, Properties::CouplingManager>;
53
54 public:
55 3 SoilProblem(std::shared_ptr<const GridGeometry> gridGeometry,
56 std::shared_ptr<CouplingManager> couplingManager)
57 : ParentType(gridGeometry, "Soil")
58
5/16
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 3 times.
✗ Branch 5 not taken.
✓ Branch 8 taken 3 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 3 times.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✓ Branch 13 taken 3 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.
9 , couplingManager_(couplingManager)
59 {
60 // read parameters from input file
61
9/26
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 3 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 3 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 3 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 3 times.
✗ Branch 14 not taken.
✗ Branch 16 not taken.
✓ Branch 17 taken 3 times.
✗ Branch 18 not taken.
✓ Branch 19 taken 3 times.
✗ Branch 20 not taken.
✓ Branch 21 taken 3 times.
✗ Branch 22 not taken.
✓ Branch 23 taken 3 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.
✗ Branch 30 not taken.
✗ Branch 31 not taken.
6 name_ = getParam<std::string>("Vtk.OutputName") + "_" + getParamFromGroup<std::string>(this->paramGroup(), "Problem.Name");
62
1/2
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
3 initPressure_ = getParam<Scalar>("BoundaryConditions.InitialSoilPressure");
63 3 }
64
65 /*!
66 * \name Problem parameters
67 */
68 // \{
69
70 /*!
71 * \brief The problem name.
72 *
73 * This is used as a prefix for files generated by the simulation.
74 */
75 const std::string& name() const
76
1/2
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
3 { return name_; }
77
78 /*
79 * \brief Returns the reference pressure [Pa] of the nonwetting
80 * fluid phase within a finite volume.
81 *
82 * This problem assumes a constant reference pressure of 1 bar.
83 */
84 Scalar nonwettingReferencePressure() const
85 { return 1.0e5; }
86
87
88 // \}
89
90 /*!
91 * \name Boundary conditions
92 */
93 // \{
94
95 /*!
96 * \brief Specifies which kind of boundary condition should be
97 * used for which equation on a given boundary segment.
98 *
99 * \param globalPos The position for which the bc type should be evaluated
100 */
101 BoundaryTypes boundaryTypesAtPos(const GlobalPosition &globalPos) const
102 {
103
3/4
✓ Branch 0 taken 1090688 times.
✓ Branch 1 taken 48384 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 25056 times.
1164128 BoundaryTypes values;
104
3/4
✓ Branch 0 taken 1090688 times.
✓ Branch 1 taken 48384 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 25056 times.
1164128 values.setAllNeumann();
105 return values;
106 }
107
108 // \}
109
110 /*!
111 * \name Volume terms
112 */
113 // \{
114
115 /*!
116 * \brief Applies a vector of point sources which are possibly solution dependent.
117 *
118 * \param pointSources A vector of Dumux::PointSource s that contain
119 source values for all phases and space positions.
120 *
121 * For this method, the \a values method of the point source
122 * has to return the absolute mass rate in kg/s. Positive values mean
123 * that mass is created, negative ones mean that it vanishes.
124 */
125 void addPointSources(std::vector<PointSource>& pointSources) const
126
1/2
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
3 { pointSources = this->couplingManager().bulkPointSources(); }
127
128 /*!
129 * \brief Evaluates the point sources (added by addPointSources)
130 * for all phases within a given sub control volume.
131 *
132 * This is the method for the case where the point source is
133 * solution dependent and requires some quantities that
134 * are specific to the fully-implicit method.
135 *
136 * \param source A single point source
137 * \param element The finite element
138 * \param fvGeometry The finite-volume geometry
139 * \param elemVolVars All volume variables for the element
140 * \param scv The sub-control volume within the element
141 *
142 * For this method, the \a values() method of the point sources returns
143 * the absolute rate mass generated or annihilated in kg/s. Positive values mean
144 * that mass is created, negative ones mean that it vanishes.
145 */
146 template<class ElementVolumeVariables>
147 6357043 void pointSource(PointSource& source,
148 const Element &element,
149 const FVElementGeometry& fvGeometry,
150 const ElementVolumeVariables& elemVolVars,
151 const SubControlVolume &scv) const
152 {
153 // compute source at every integration point
154 19071129 const Scalar pressure3D = this->couplingManager().bulkPriVars(source.id())[Indices::pressureIdx];
155 19071129 const Scalar pressure1D = this->couplingManager().lowDimPriVars(source.id())[Indices::pressureIdx];
156
157 10762948 const auto& spatialParams = this->couplingManager().problem(Dune::index_constant<1>{}).spatialParams();
158 19071129 const auto lowDimElementIdx = this->couplingManager().pointSourceData(source.id()).lowDimElementIdx();
159 6357043 const Scalar Kr = spatialParams.Kr(lowDimElementIdx);
160
161 // sink defined as radial flow Jr * density [m^2 s-1]* [kg m-3]
162 6357043 const auto density = 1000;
163 6357043 Scalar sourceValue = Kr *(pressure1D - pressure3D)*density;
164
165 // For the projection method, we are integrating over the two-dimensional root surface
166 // so surface is included in the weight/integration element.
167 // All other currently implemented schemes are implicit interface schemes
168 // that assume cylindrical segments, so we multiply with the cylinder surface here
169 if constexpr(CouplingManager::couplingMode != Embedded1d3dCouplingMode::projection)
170 {
171 14665224 const Scalar rootRadius = this->couplingManager().radius(source.id());
172 4888408 sourceValue *= 2*M_PI*rootRadius;
173 }
174
175 12714086 source = sourceValue*source.quadratureWeight()*source.integrationElement();
176 6357043 }
177
178 /*!
179 * \brief Evaluates the initial value for a control volume.
180 *
181 * \param globalPos The position for which the initial condition should be evaluated
182 *
183 * For this method, the \a values parameter stores primary
184 * variables.
185 */
186 PrimaryVariables initialAtPos(const GlobalPosition &globalPos) const
187 {
188 11654 PrimaryVariables priVars({initPressure_});
189 return priVars;
190 }
191
192 //! Called after every time step
193 //! Output the total global exchange term
194 21 void computeSourceIntegral(const SolutionVector& sol, const GridVariables& gridVars)
195 {
196
1/2
✓ Branch 1 taken 14 times.
✗ Branch 2 not taken.
21 PrimaryVariables source(0.0);
197
2/6
✓ Branch 1 taken 14 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 14 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
42 auto fvGeometry = localView(this->gridGeometry());
198
2/4
✓ Branch 1 taken 14 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 14 times.
✗ Branch 5 not taken.
42 auto elemVolVars = localView(gridVars.curGridVolVars());
199
13/20
✓ Branch 1 taken 14 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 12103 times.
✓ Branch 4 taken 14 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 14 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 12103 times.
✓ Branch 10 taken 7 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 7 times.
✗ Branch 14 not taken.
✓ Branch 15 taken 57568 times.
✓ Branch 16 taken 7 times.
✓ Branch 17 taken 57568 times.
✓ Branch 18 taken 7 times.
✓ Branch 20 taken 57568 times.
✗ Branch 21 not taken.
✓ Branch 23 taken 57568 times.
✗ Branch 24 not taken.
106015 for (const auto& element : elements(this->gridGeometry().gridView()))
200 {
201
1/2
✓ Branch 1 taken 57568 times.
✗ Branch 2 not taken.
81760 fvGeometry.bindElement(element);
202
1/2
✓ Branch 1 taken 57568 times.
✗ Branch 2 not taken.
81760 elemVolVars.bindElement(element, fvGeometry, sol);
203
204
7/8
✓ Branch 0 taken 327040 times.
✓ Branch 1 taken 69664 times.
✓ Branch 2 taken 339136 times.
✓ Branch 3 taken 81760 times.
✓ Branch 4 taken 12096 times.
✓ Branch 5 taken 12096 times.
✓ Branch 7 taken 12096 times.
✗ Branch 8 not taken.
841792 for (auto&& scv : scvs(fvGeometry))
205 {
206
1/2
✓ Branch 1 taken 242368 times.
✗ Branch 2 not taken.
339136 auto pointSources = this->scvPointSources(element, fvGeometry, elemVolVars, scv);
207 666176 pointSources *= scv.volume()*elemVolVars[scv].extrusionFactor();
208 339136 source += pointSources;
209 }
210 }
211
212
1/2
✓ Branch 2 taken 14 times.
✗ Branch 3 not taken.
42 std::cout << "Global integrated source (soil): " << source << " (kg/s) / "
213
3/6
✓ Branch 1 taken 14 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 14 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 7 times.
✗ Branch 8 not taken.
42 << source*3600*24*1000 << " (g/day)" << '\n';
214
215 21 }
216
217 //! Get the coupling manager
218 const CouplingManager& couplingManager() const
219
8/15
✗ Branch 2 not taken.
✓ Branch 3 taken 6357043 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 6357043 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 6357043 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 6357043 times.
✓ Branch 11 taken 1 times.
✗ Branch 12 not taken.
✓ Branch 14 taken 1 times.
✓ Branch 15 taken 2 times.
✗ Branch 16 not taken.
✓ Branch 18 taken 2 times.
✗ Branch 19 not taken.
12714092 { return *couplingManager_; }
220
221 private:
222 Scalar initPressure_;
223
224 static constexpr Scalar eps_ = 1.5e-7;
225 std::string name_;
226
227 std::shared_ptr<CouplingManager> couplingManager_;
228 };
229
230 } // end namespace Dumux
231
232 #endif
233