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 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 |
2/4✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
|
6 | , couplingManager_(couplingManager) |
54 | { | ||
55 | // read parameters from input file | ||
56 |
2/4✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✓ Branch 6 taken 2 times.
✗ Branch 7 not taken.
|
2 | name_ = getParamFromGroup<std::string>(this->paramGroup(), "Problem.Name"); |
57 | |||
58 |
2/4✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
|
4 | 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 | 2 | 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 | 2 | 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 |
2/4✗ Branch 0 not taken.
✓ Branch 1 taken 8617435 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 5820635 times.
|
14438070 | 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 | 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 | 41429083 | const auto eIdx = this->gridGeometry().elementMapper().index(element); | |
94 | 41429083 | const auto& sourceIds = this->couplingManager().bulkSourceIds(eIdx); | |
95 | 41429083 | const auto& sourceWeights = this->couplingManager().bulkSourceWeights(eIdx); | |
96 | |||
97 |
2/2✓ Branch 0 taken 289574608 times.
✓ Branch 1 taken 41429082 times.
|
331003690 | 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 | 289574608 | const Scalar p0 = this->couplingManager().bulkPriVars(id)[Indices::pressureIdx]; | |
104 | 289574608 | const Scalar pRoot = this->couplingManager().lowDimPriVars(id)[Indices::pressureIdx]; | |
105 | 289574608 | const Scalar radius = this->couplingManager().radius(id); | |
106 | 289574608 | const Scalar kernelRadius = kernelWidthFactor_*radius; | |
107 | 289574608 | const Scalar Kr = this->couplingManager().Kr(id); | |
108 | 289574608 | const Scalar density = 1000; | |
109 | 289574608 | const Scalar viscosity = 1e-3; | |
110 | 289574608 | const Scalar delta = this->couplingManager().averageDistance(id); | |
111 | |||
112 | // sink defined as radial flow Jr * density [m^2 s-1]* [kg m-3] | ||
113 | 289574608 | const auto lEIdx = this->couplingManager().pointSourceData(id).lowDimElementIdx(); | |
114 | 289574608 | 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 | 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.
|
10391942 | for (const auto& element : elements(this->gridGeometry().gridView())) |
144 | { | ||
145 | 3463680 | auto fvGeometry = localView(this->gridGeometry()); | |
146 | 3463680 | fvGeometry.bindElement(element); | |
147 | |||
148 | 3463680 | auto elemVolVars = localView(gridVars.curGridVolVars()); | |
149 | 3463680 | elemVolVars.bindElement(element, fvGeometry, sol); | |
150 | |||
151 |
2/2✓ Branch 0 taken 3463680 times.
✓ Branch 1 taken 3463680 times.
|
6927360 | 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 | 6927360 | pointSources *= scv.volume()*elemVolVars[scv].extrusionFactor(); | |
155 | 3463680 | source += pointSources; | |
156 | } | ||
157 | } | ||
158 | |||
159 | 451 | std::cout << "Global integrated source (soil): " << source << " (kg/s) / " | |
160 | 451 | << source*3600*24*1000 << " (g/day)" << '\n'; | |
161 | |||
162 | 451 | } | |
163 | |||
164 | //! Get the coupling manager | ||
165 | 331003691 | const CouplingManager& couplingManager() const | |
166 | 331003691 | { 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 |