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-FileCopyrightText: 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 root 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_ROOT_PROBLEM_HH | ||
13 | #define DUMUX_TEST_ROOT_SOIL_BENCHMARK_ROOT_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 | #include <dumux/porousmediumflow/problem.hh> | ||
21 | #include <dumux/discretization/evalsolution.hh> | ||
22 | #include <dumux/discretization/elementsolution.hh> | ||
23 | |||
24 | #include "couplingreconstruction.hh" | ||
25 | |||
26 | namespace Dumux { | ||
27 | |||
28 | /*! | ||
29 | * \ingroup EmbeddedTests | ||
30 | * \brief The root problem for the benchmark cases C1.2a/b from Schnepf et al (2020) https://doi.org/10.3389/fpls.2020.00316 | ||
31 | */ | ||
32 | template <class TypeTag> | ||
33 | class RootProblem : public PorousMediumFlowProblem<TypeTag> | ||
34 | { | ||
35 | using ParentType = PorousMediumFlowProblem<TypeTag>; | ||
36 | using Scalar = GetPropType<TypeTag, Properties::Scalar>; | ||
37 | using PointSource = GetPropType<TypeTag, Properties::PointSource>; | ||
38 | using Indices = typename GetPropType<TypeTag, Properties::ModelTraits>::Indices; | ||
39 | using PrimaryVariables = GetPropType<TypeTag, Properties::PrimaryVariables>; | ||
40 | using NumEqVector = Dumux::NumEqVector<PrimaryVariables>; | ||
41 | using BoundaryTypes = Dumux::BoundaryTypes<PrimaryVariables::size()>; | ||
42 | using GridGeometry = GetPropType<TypeTag, Properties::GridGeometry>; | ||
43 | using GridView = typename GridGeometry::GridView; | ||
44 | using FVElementGeometry = typename GridGeometry::LocalView; | ||
45 | using SubControlVolume = typename GridGeometry::SubControlVolume; | ||
46 | using SubControlVolumeFace = typename GridGeometry::SubControlVolumeFace; | ||
47 | using GlobalPosition = typename GridGeometry::GlobalCoordinate; | ||
48 | using SolutionVector = GetPropType<TypeTag, Properties::SolutionVector>; | ||
49 | using GridVariables = GetPropType<TypeTag, Properties::GridVariables>; | ||
50 | using Element = typename GridView::template Codim<0>::Entity; | ||
51 | using CouplingManager = GetPropType<TypeTag, Properties::CouplingManager>; | ||
52 | |||
53 | public: | ||
54 | enum BCType | ||
55 | { constCollarPressure, constTranspiration, cyclicTranspiration }; | ||
56 | |||
57 | template<class SpatialParams> | ||
58 | 2 | RootProblem(std::shared_ptr<const GridGeometry> gridGeometry, | |
59 | std::shared_ptr<SpatialParams> spatialParams, | ||
60 | std::shared_ptr<CouplingManager> couplingManager, | ||
61 | const GlobalPosition& domainSize) | ||
62 | : ParentType(gridGeometry, spatialParams, "Root") | ||
63 |
3/8✓ Branch 3 taken 2 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 2 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 2 times.
✗ Branch 8 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
|
8 | , couplingManager_(couplingManager) |
64 | { | ||
65 | // read parameters from input file | ||
66 |
1/2✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
|
2 | name_ = getParamFromGroup<std::string>(this->paramGroup(), "Problem.Name"); |
67 |
1/2✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
|
2 | criticalCollarPressure_ = getParam<Scalar>("BoundaryConditions.CriticalCollarPressure", -1.4e6); // in Pa |
68 |
1/2✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
|
2 | initialRootPressure_ = getParam<Scalar>("BoundaryConditions.InitialRootPressure", -1e5); // in Pa |
69 |
2/4✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
|
2 | dailyTranspirationRate_ = getParam<Scalar>("BoundaryConditions.DailyTranspirationRate", 1.0); // mm/day |
70 | 2 | dailyTranspirationRate_ *= domainSize[0]*domainSize[1]/86400.0; // kg/s (domain size in m, kg->g=mm->m) | |
71 | |||
72 |
1/2✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
|
2 | const auto bcType = getParam<std::string>("BoundaryConditions.BoundaryType", "CyclicTranspiration"); |
73 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | if (bcType == "CyclicTranspiration") bcType_ = BCType::cyclicTranspiration; |
74 | ✗ | else if (bcType == "ConstCollarPressure") bcType_ = BCType::constCollarPressure; | |
75 | ✗ | else if (bcType == "ConstTranspiration") bcType_ = BCType::constTranspiration; | |
76 | ✗ | else DUNE_THROW(Dune::InvalidStateException, "Unknown BCType: " << bcType); | |
77 | |||
78 |
1/2✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
|
2 | bcSmoothingParam_ = getParam<Scalar>("BoundaryConditions.SmoothingK", 0.1); |
79 |
1/2✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
|
2 | kernelWidthFactor_ = getParam<Scalar>("MixedDimension.KernelWidthFactor"); |
80 | 2 | } | |
81 | |||
82 | 2 | const std::string& name() const | |
83 |
1/2✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
|
2 | { return name_; } |
84 | |||
85 |
2/4✓ Branch 0 taken 116919 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 78969 times.
✗ Branch 3 not taken.
|
195888 | BoundaryTypes boundaryTypesAtPos(const GlobalPosition &globalPos) const |
86 | { | ||
87 |
2/4✓ Branch 0 taken 116919 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 78969 times.
✗ Branch 3 not taken.
|
195888 | BoundaryTypes values; |
88 | 195888 | values.setAllNeumann(); | |
89 | |||
90 |
2/4✓ Branch 0 taken 116919 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 78969 times.
✗ Branch 3 not taken.
|
195888 | if (bcType_ == BCType::constCollarPressure) |
91 | ✗ | if (globalPos[2] + eps_ > this->gridGeometry().bBoxMax()[2]) | |
92 | values.setAllDirichlet(); | ||
93 | |||
94 | return values; | ||
95 | } | ||
96 | |||
97 | ✗ | PrimaryVariables dirichletAtPos(const GlobalPosition& globalPos) const | |
98 | ✗ | { return PrimaryVariables(criticalCollarPressure_); } | |
99 | |||
100 | template<class ElementVolumeVariables, class ElementFluxVarsCache> | ||
101 | 262482 | NumEqVector neumann(const Element& element, | |
102 | const FVElementGeometry& fvGeometry, | ||
103 | const ElementVolumeVariables& elemVolVars, | ||
104 | const ElementFluxVarsCache& elemFluxVarsCache, | ||
105 | const SubControlVolumeFace& scvf) const | ||
106 | { | ||
107 | 262482 | NumEqVector values(0.0); | |
108 | |||
109 | // set transpiration rate at the root collar | ||
110 |
2/2✓ Branch 0 taken 3977 times.
✓ Branch 1 taken 127264 times.
|
262482 | const auto globalPos = scvf.center(); |
111 |
2/2✓ Branch 0 taken 3977 times.
✓ Branch 1 taken 127264 times.
|
262482 | if (globalPos[2] + eps_ > this->gridGeometry().bBoxMax()[2]) |
112 | { | ||
113 | // if the plant has water stress reduce the transpiration rate (imposing Dirichlet boundary condition weakly) | ||
114 | 7954 | const auto& volVars = elemVolVars[scvf.insideScvIdx()]; | |
115 | 7954 | const auto dist = fvGeometry.scv(scvf.insideScvIdx()).volume(); | |
116 | 7954 | const auto elemSol = elementSolution(element, elemVolVars, fvGeometry); | |
117 | 7954 | const auto p = evalSolution(element, element.geometry(), elemSol, globalPos)[0]; | |
118 | 7954 | const auto eIdx = this->gridGeometry().elementMapper().index(element); | |
119 |
2/2✓ Branch 0 taken 3648 times.
✓ Branch 1 taken 329 times.
|
7954 | const Scalar Kx = this->spatialParams().Kx(eIdx); |
120 | 7954 | const auto rho = volVars.density(0); | |
121 | 7954 | const Scalar criticalTranspiration = rho*Kx*(p - criticalCollarPressure_ - rho*9.81*dist)/dist; | |
122 |
2/2✓ Branch 0 taken 3648 times.
✓ Branch 1 taken 329 times.
|
7954 | values[Indices::conti0EqIdx] = smoothMin(potentialTranspirationRate(), criticalTranspiration, dailyTranspirationRate_*bcSmoothingParam_); |
123 | 7954 | values /= volVars.extrusionFactor() * scvf.area(); // convert from kg/s to kg/(s*m^2) | |
124 | } | ||
125 | |||
126 | 262482 | return values; | |
127 | } | ||
128 | |||
129 | //! Compute potential transpiration rate in kg/s | ||
130 | 5279 | Scalar potentialTranspirationRate() const | |
131 | { | ||
132 | // possibly make the transpiration rate dependent on the current root length for growth | ||
133 |
1/2✓ Branch 0 taken 5279 times.
✗ Branch 1 not taken.
|
5279 | if (bcType_ == BCType::cyclicTranspiration) |
134 | 5279 | return dailyTranspirationRate_*std::sin(time_*2.0*M_PI / 86400.0 - M_PI/2.0) + dailyTranspirationRate_; | |
135 | ✗ | else if (bcType_ == BCType::constTranspiration) | |
136 | ✗ | return dailyTranspirationRate_; | |
137 | else | ||
138 | return std::numeric_limits<Scalar>::max(); | ||
139 | } | ||
140 | |||
141 | 2 | void addPointSources(std::vector<PointSource>& pointSources) const | |
142 |
1/2✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
|
2 | { pointSources = this->couplingManager().lowDimPointSources(); } |
143 | |||
144 | template<class ElementVolumeVariables> | ||
145 | 9148794 | void pointSource(PointSource& source, | |
146 | const Element &element, | ||
147 | const FVElementGeometry& fvGeometry, | ||
148 | const ElementVolumeVariables& elemVolVars, | ||
149 | const SubControlVolume &scv) const | ||
150 | { | ||
151 | // compute source at every integration point | ||
152 | 9148794 | const auto id = source.id(); | |
153 | |||
154 | 9148794 | const Scalar p0 = this->couplingManager().bulkPriVars(id)[Indices::pressureIdx]; | |
155 | 9148794 | const Scalar pRoot = this->couplingManager().lowDimPriVars(id)[Indices::pressureIdx]; | |
156 | 9148794 | const Scalar radius = this->couplingManager().radius(id); | |
157 | 9148794 | const auto lEIdx = this->couplingManager().pointSourceData(id).lowDimElementIdx(); | |
158 | 9148794 | const auto bEIdx = this->couplingManager().pointSourceData(id).bulkElementIdx(); | |
159 | 9148794 | const Scalar Kr = this->spatialParams().Kr(lEIdx); | |
160 | 9148794 | const Scalar kernelRadius = kernelWidthFactor_*radius; | |
161 | 9148794 | const Scalar density = 1000; | |
162 | 9148794 | const Scalar viscosity = 1e-3; | |
163 | 9148794 | const Scalar delta = this->couplingManager().averageDistance(id); | |
164 | |||
165 | // sink defined as radial flow Jr * density [m^2 s-1]* [kg m-3] | ||
166 | 9148794 | const auto sourceValue = -1.0*this->couplingManager().reconstruction().computeSource( | |
167 | bEIdx, lEIdx, p0, pRoot, kernelRadius, radius, Kr, density, viscosity, id, delta | ||
168 | ); | ||
169 | 9148794 | source = sourceValue*source.quadratureWeight()*source.integrationElement(); | |
170 | 9148794 | } | |
171 | |||
172 | 2340 | PrimaryVariables initialAtPos(const GlobalPosition &globalPos) const | |
173 | { | ||
174 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2340 times.
|
2340 | if (bcType_ == BCType::constCollarPressure) |
175 | ✗ | return PrimaryVariables(criticalCollarPressure_); | |
176 | else | ||
177 | 2340 | return PrimaryVariables(initialRootPressure_); | |
178 | } | ||
179 | |||
180 | //! Called after every time step | ||
181 | //! Output the total global exchange term | ||
182 | //! Output the individual source terms into sourceTerms | ||
183 | 451 | void computeSourceIntegral(const SolutionVector& sol, const GridVariables& gridVars, | |
184 | std::vector<Scalar>& sourceTerms) | ||
185 | { | ||
186 | 451 | PrimaryVariables source(0.0); | |
187 |
2/2✓ Branch 2 taken 527670 times.
✓ Branch 3 taken 451 times.
|
1055791 | for (const auto& element : elements(this->gridGeometry().gridView())) |
188 | { | ||
189 | 527670 | auto fvGeometry = localView(this->gridGeometry()); | |
190 | 527670 | fvGeometry.bindElement(element); | |
191 | |||
192 | 527670 | auto elemVolVars = localView(gridVars.curGridVolVars()); | |
193 | elemVolVars.bindElement(element, fvGeometry, sol); | ||
194 | |||
195 | 527670 | PrimaryVariables localSource(0.0); | |
196 |
2/2✓ Branch 0 taken 527670 times.
✓ Branch 1 taken 527670 times.
|
1055340 | for (const auto& scv : scvs(fvGeometry)) |
197 | { | ||
198 |
1/2✓ Branch 1 taken 527670 times.
✗ Branch 2 not taken.
|
527670 | auto pointSources = this->scvPointSources(element, fvGeometry, elemVolVars, scv); |
199 | 1055340 | pointSources *= scv.volume()*elemVolVars[scv].extrusionFactor(); | |
200 | 527670 | localSource += pointSources; | |
201 | } | ||
202 | |||
203 | 527670 | const auto eIdx = this->gridGeometry().elementMapper().index(element); | |
204 | 527670 | sourceTerms[eIdx] = localSource[0]; | |
205 | 527670 | source += localSource; | |
206 | } | ||
207 | |||
208 | 451 | std::cout << "Global integrated source (root): " << source << " (kg/s) / " | |
209 | 451 | << source*3600*24*1000 << " (g/day)" << '\n'; | |
210 | 451 | } | |
211 | |||
212 | //! compute the actual transpiration rate | ||
213 | 434 | Scalar computeActualTranspirationRate(const SolutionVector& sol, const GridVariables& gridVars, bool verbose = true) const | |
214 | { | ||
215 | 434 | NumEqVector transpirationRate(0.0); | |
216 |
2/2✓ Branch 3 taken 507780 times.
✓ Branch 4 taken 434 times.
|
1015994 | for (const auto& element : elements(this->gridGeometry().gridView())) |
217 | { | ||
218 | 507780 | auto fvGeometry = localView(this->gridGeometry()); | |
219 | 507780 | fvGeometry.bindElement(element); | |
220 | |||
221 | 507780 | auto elemVolVars = localView(gridVars.curGridVolVars()); | |
222 | 507780 | elemVolVars.bindElement(element, fvGeometry, sol); | |
223 | |||
224 |
4/4✓ Branch 0 taken 14322 times.
✓ Branch 1 taken 1001238 times.
✓ Branch 2 taken 1015560 times.
✓ Branch 3 taken 507780 times.
|
1523340 | for (const auto& scvf : scvfs(fvGeometry)) |
225 |
2/2✓ Branch 0 taken 14322 times.
✓ Branch 1 taken 1001238 times.
|
1015560 | if (scvf.boundary()) |
226 |
1/2✓ Branch 1 taken 14322 times.
✗ Branch 2 not taken.
|
14322 | transpirationRate += this->neumann(element, fvGeometry, elemVolVars, 0.0, scvf) |
227 |
1/2✓ Branch 2 taken 14322 times.
✗ Branch 3 not taken.
|
14322 | *scvf.area()*elemVolVars[scvf.insideScvIdx()].extrusionFactor(); |
228 | } | ||
229 | |||
230 |
1/2✓ Branch 0 taken 434 times.
✗ Branch 1 not taken.
|
434 | if (verbose) |
231 | { | ||
232 | 434 | std::cout << "Actual transpiration rate: " << transpirationRate << " (kg/s) / " | |
233 | 434 | << transpirationRate[0]*86400*1000 << " (g/day)"; | |
234 |
1/2✓ Branch 0 taken 434 times.
✗ Branch 1 not taken.
|
434 | if (bcType_ != BCType::constCollarPressure) |
235 | 434 | std::cout << " / Potential transpiration rate: " << potentialTranspirationRate() << " (kg/s) / " | |
236 | 434 | << potentialTranspirationRate()*86400*1000 << " (g/day) / "; | |
237 | 434 | std::cout << std::endl; | |
238 | } | ||
239 | |||
240 | 434 | return transpirationRate[0]; | |
241 | } | ||
242 | |||
243 | //! Get the coupling manager | ||
244 | 9148796 | const CouplingManager& couplingManager() const | |
245 |
1/2✓ Branch 3 taken 2 times.
✗ Branch 4 not taken.
|
9148796 | { return *couplingManager_; } |
246 | |||
247 | //! set the current time for evaluation of time-dependent boundary conditions | ||
248 | 455 | void setTime(const Scalar t) | |
249 |
2/2✓ Branch 1 taken 451 times.
✓ Branch 2 taken 4 times.
|
455 | { time_= t; } |
250 | |||
251 | //! get the boundary condition type | ||
252 | 434 | BCType bcType() const | |
253 |
1/2✓ Branch 0 taken 434 times.
✗ Branch 1 not taken.
|
434 | { return bcType_; } |
254 | |||
255 | private: | ||
256 | Scalar initialRootPressure_, criticalCollarPressure_, dailyTranspirationRate_; | ||
257 | Scalar time_; | ||
258 | Scalar kernelWidthFactor_; | ||
259 | |||
260 | BCType bcType_; | ||
261 | Scalar bcSmoothingParam_; | ||
262 | |||
263 | static constexpr Scalar eps_ = 1.5e-7; | ||
264 | std::string name_; | ||
265 | |||
266 | std::shared_ptr<CouplingManager> couplingManager_; | ||
267 | }; | ||
268 | |||
269 | } // end namespace Dumux | ||
270 | |||
271 | #endif | ||
272 |