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 BoundaryTests | ||
10 | * \brief A simple Darcy test problem (cell-centered finite volume method). | ||
11 | */ | ||
12 | |||
13 | #ifndef DUMUX_DARCY_SUBPROBLEM_HH | ||
14 | #define DUMUX_DARCY_SUBPROBLEM_HH | ||
15 | |||
16 | #include <dumux/common/boundarytypes.hh> | ||
17 | #include <dumux/common/properties.hh> | ||
18 | #include <dumux/common/parameters.hh> | ||
19 | #include <dumux/common/numeqvector.hh> | ||
20 | #include <dumux/common/timeloop.hh> | ||
21 | #include <dumux/porousmediumflow/problem.hh> | ||
22 | |||
23 | namespace Dumux { | ||
24 | |||
25 | template <class TypeTag> | ||
26 | class DarcySubProblem : public PorousMediumFlowProblem<TypeTag> | ||
27 | { | ||
28 | using ParentType = PorousMediumFlowProblem<TypeTag>; | ||
29 | using GridGeometry = GetPropType<TypeTag, Properties::GridGeometry>; | ||
30 | using GridView = typename GridGeometry::GridView; | ||
31 | using Scalar = GetPropType<TypeTag, Properties::Scalar>; | ||
32 | using PrimaryVariables = GetPropType<TypeTag, Properties::PrimaryVariables>; | ||
33 | using NumEqVector = Dumux::NumEqVector<PrimaryVariables>; | ||
34 | using BoundaryTypes = Dumux::BoundaryTypes<GetPropType<TypeTag, Properties::ModelTraits>::numEq()>; | ||
35 | using FVElementGeometry = typename GetPropType<TypeTag, Properties::GridGeometry>::LocalView; | ||
36 | using SubControlVolume = typename FVElementGeometry::SubControlVolume; | ||
37 | using SubControlVolumeFace = typename FVElementGeometry::SubControlVolumeFace; | ||
38 | using Element = typename GridView::template Codim<0>::Entity; | ||
39 | using Indices = typename GetPropType<TypeTag, Properties::ModelTraits>::Indices; | ||
40 | |||
41 | using GlobalPosition = typename Element::Geometry::GlobalCoordinate; | ||
42 | |||
43 | using CouplingManager = GetPropType<TypeTag, Properties::CouplingManager>; | ||
44 | using TimeLoopPtr = std::shared_ptr<TimeLoop<Scalar>>; | ||
45 | |||
46 | public: | ||
47 | 3 | DarcySubProblem(std::shared_ptr<const GridGeometry> gridGeometry, | |
48 | std::shared_ptr<CouplingManager> couplingManager) | ||
49 |
3/6✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 3 times.
✗ Branch 5 not taken.
✓ Branch 9 taken 3 times.
✗ Branch 10 not taken.
|
9 | : ParentType(gridGeometry, "Darcy"), eps_(1e-7), couplingManager_(couplingManager) |
50 | { | ||
51 |
3/6✓ 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.
|
6 | problemName_ = getParam<std::string>("Vtk.OutputName") + "_" + getParamFromGroup<std::string>(this->paramGroup(), "Problem.Name"); |
52 | |||
53 | // determine whether to simulate a vertical or horizontal flow configuration | ||
54 | 3 | verticalFlow_ = problemName_.find("vertical") != std::string::npos; | |
55 | 3 | } | |
56 | |||
57 | /*! | ||
58 | * \brief The problem name. | ||
59 | */ | ||
60 | 3 | const std::string& name() const | |
61 | { | ||
62 |
1/2✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
|
3 | return problemName_; |
63 | } | ||
64 | |||
65 | /*! | ||
66 | * \name Boundary conditions | ||
67 | */ | ||
68 | // \{ | ||
69 | |||
70 | /*! | ||
71 | * \brief Specifies which kind of boundary condition should be | ||
72 | * used for which equation on a given boundary control volume. | ||
73 | * | ||
74 | * \param element The element | ||
75 | * \param scvf The boundary sub control volume face | ||
76 | */ | ||
77 | 70200 | BoundaryTypes boundaryTypes(const Element& element, const SubControlVolumeFace& scvf) const | |
78 | { | ||
79 |
2/2✓ Branch 0 taken 140400 times.
✓ Branch 1 taken 70200 times.
|
210600 | BoundaryTypes values; |
80 | 70200 | values.setAllNeumann(); | |
81 | |||
82 |
2/2✓ Branch 0 taken 27120 times.
✓ Branch 1 taken 43080 times.
|
70200 | if (couplingManager().isCoupledEntity(CouplingManager::darcyIdx, scvf)) |
83 | 70200 | values.setAllCouplingNeumann(); | |
84 | |||
85 |
2/2✓ Branch 0 taken 47960 times.
✓ Branch 1 taken 22240 times.
|
70200 | if (verticalFlow_) |
86 | { | ||
87 | 47960 | if (onLowerBoundary_(scvf.center())) | |
88 | 70200 | values.setAllDirichlet(); | |
89 | } | ||
90 | |||
91 | 70200 | return values; | |
92 | } | ||
93 | |||
94 | /*! | ||
95 | * \brief Evaluates the boundary conditions for a Dirichlet control volume. | ||
96 | * | ||
97 | * \param element The element for which the Dirichlet boundary condition is set | ||
98 | * \param scvf The boundary subcontrolvolumeface | ||
99 | * | ||
100 | */ | ||
101 | 2540 | PrimaryVariables dirichlet(const Element &element, const SubControlVolumeFace &scvf) const | |
102 | { | ||
103 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2540 times.
|
2540 | PrimaryVariables values(0.0); |
104 | 2540 | values = initial(element); | |
105 | |||
106 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2540 times.
|
2540 | if (verticalFlow_) |
107 | { | ||
108 | // Check if this a pure diffusion problem. | ||
109 |
3/4✓ Branch 0 taken 2 times.
✓ Branch 1 taken 2538 times.
✓ Branch 3 taken 2 times.
✗ Branch 4 not taken.
|
2540 | static const bool isDiffusionProblem = problemName_.find("diffusion") != std::string::npos; |
110 | |||
111 | 2540 | Scalar bottomMoleFraction = 0.0; | |
112 | |||
113 |
2/2✓ Branch 0 taken 2280 times.
✓ Branch 1 taken 260 times.
|
2540 | if (isDiffusionProblem) |
114 | { | ||
115 | // For the diffusion problem, change the top mole fraction after some time | ||
116 | // in order to revert the concentration gradient. | ||
117 |
2/2✓ Branch 0 taken 160 times.
✓ Branch 1 taken 100 times.
|
260 | if (time() >= 1e10) |
118 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2540 times.
|
2540 | bottomMoleFraction = 1e-3; |
119 | } | ||
120 | |||
121 | 2540 | if(onLowerBoundary_(scvf.center())) | |
122 | 2540 | values[Indices::conti0EqIdx + 1] = bottomMoleFraction; | |
123 | } | ||
124 | |||
125 | 2540 | return values; | |
126 | } | ||
127 | |||
128 | /*! | ||
129 | * \brief Evaluates the boundary conditions for a Neumann control volume. | ||
130 | * | ||
131 | * \param element The element for which the Neumann boundary condition is set | ||
132 | * \param fvGeometry The fvGeometry | ||
133 | * \param elemVolVars The element volume variables | ||
134 | * \param elemFluxVarsCache Flux variables caches for all faces in stencil | ||
135 | * \param scvf The boundary sub control volume face | ||
136 | * | ||
137 | * For this method, the \a values variable stores primary variables. | ||
138 | */ | ||
139 | template<class ElementVolumeVariables, class ElementFluxVarsCache> | ||
140 | 44460 | NumEqVector neumann(const Element& element, | |
141 | const FVElementGeometry& fvGeometry, | ||
142 | const ElementVolumeVariables& elemVolVars, | ||
143 | const ElementFluxVarsCache& elemFluxVarsCache, | ||
144 | const SubControlVolumeFace& scvf) const | ||
145 | { | ||
146 | 44460 | NumEqVector values(0.0); | |
147 | |||
148 |
2/2✓ Branch 0 taken 22240 times.
✓ Branch 1 taken 22220 times.
|
44460 | if (couplingManager().isCoupledEntity(CouplingManager::darcyIdx, scvf)) |
149 | 22240 | values = couplingManager().couplingData().massCouplingCondition(element, fvGeometry, elemVolVars, scvf); | |
150 | |||
151 | 44460 | return values; | |
152 | } | ||
153 | |||
154 | // \} | ||
155 | |||
156 | /*! | ||
157 | * \name Volume terms | ||
158 | */ | ||
159 | // \{ | ||
160 | /*! | ||
161 | * \brief Evaluates the source term for all phases within a given | ||
162 | * sub control volume. | ||
163 | * | ||
164 | * \param element The element for which the source term is set | ||
165 | * \param fvGeometry The fvGeometry | ||
166 | * \param elemVolVars The element volume variables | ||
167 | * \param scv The sub control volume | ||
168 | */ | ||
169 | template<class ElementVolumeVariables> | ||
170 | 171600 | NumEqVector source(const Element &element, | |
171 | const FVElementGeometry& fvGeometry, | ||
172 | const ElementVolumeVariables& elemVolVars, | ||
173 | const SubControlVolume &scv) const | ||
174 | 343200 | { return NumEqVector(0.0); } | |
175 | |||
176 | // \} | ||
177 | |||
178 | /*! | ||
179 | * \brief Evaluates the initial value for a control volume. | ||
180 | * | ||
181 | * \param element The element | ||
182 | * | ||
183 | * For this method, the \a priVars parameter stores primary | ||
184 | * variables. | ||
185 | */ | ||
186 | PrimaryVariables initial(const Element &element) const | ||
187 | { | ||
188 | PrimaryVariables values(0.0); | ||
189 | values[Indices::pressureIdx] = 1e5; | ||
190 | |||
191 | return values; | ||
192 | } | ||
193 | |||
194 | // \} | ||
195 | |||
196 | //! Get the coupling manager | ||
197 | 114660 | const CouplingManager& couplingManager() const | |
198 |
4/4✓ Branch 0 taken 22240 times.
✓ Branch 1 taken 22220 times.
✓ Branch 3 taken 27120 times.
✓ Branch 4 taken 43080 times.
|
114660 | { return *couplingManager_; } |
199 | |||
200 | /*! | ||
201 | * \brief Sets the time loop pointer. | ||
202 | */ | ||
203 | 3 | void setTimeLoop(TimeLoopPtr timeLoop) | |
204 |
1/2✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
|
3 | { timeLoop_ = timeLoop; } |
205 | |||
206 | /*! | ||
207 | * \brief Returns the time. | ||
208 | */ | ||
209 | 260 | Scalar time() const | |
210 |
2/2✓ Branch 0 taken 160 times.
✓ Branch 1 taken 100 times.
|
260 | { return timeLoop_->time(); } |
211 | |||
212 | private: | ||
213 | bool onLeftBoundary_(const GlobalPosition &globalPos) const | ||
214 | { return globalPos[0] < this->gridGeometry().bBoxMin()[0] + eps_; } | ||
215 | |||
216 | bool onRightBoundary_(const GlobalPosition &globalPos) const | ||
217 | { return globalPos[0] > this->gridGeometry().bBoxMax()[0] - eps_; } | ||
218 | |||
219 |
3/4✗ Branch 0 not taken.
✓ Branch 1 taken 2540 times.
✓ Branch 2 taken 9460 times.
✓ Branch 3 taken 38500 times.
|
50500 | bool onLowerBoundary_(const GlobalPosition &globalPos) const |
220 |
3/4✗ Branch 0 not taken.
✓ Branch 1 taken 2540 times.
✓ Branch 2 taken 9460 times.
✓ Branch 3 taken 38500 times.
|
50500 | { return globalPos[1] < this->gridGeometry().bBoxMin()[1] + eps_; } |
221 | |||
222 | bool onUpperBoundary_(const GlobalPosition &globalPos) const | ||
223 | { return globalPos[1] > this->gridGeometry().bBoxMax()[1] - eps_; } | ||
224 | |||
225 | Scalar eps_; | ||
226 | std::string problemName_; | ||
227 | bool verticalFlow_; | ||
228 | std::shared_ptr<CouplingManager> couplingManager_; | ||
229 | TimeLoopPtr timeLoop_; | ||
230 | }; | ||
231 | } // end namespace Dumux | ||
232 | |||
233 | #endif | ||
234 |