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 | * | ||
10 | * \brief A test problem for the two-phase pore network model. | ||
11 | */ | ||
12 | #ifndef DUMUX_PNM2P_PROBLEM_HH | ||
13 | #define DUMUX_PNM2P_PROBLEM_HH | ||
14 | |||
15 | #include <dumux/common/boundarytypes.hh> | ||
16 | #include <dumux/common/parameters.hh> | ||
17 | #include <dumux/porenetwork/2p/model.hh> | ||
18 | #include <dumux/porousmediumflow/problem.hh> | ||
19 | |||
20 | namespace Dumux { | ||
21 | |||
22 | template <class TypeTag> | ||
23 | class DrainageProblem; | ||
24 | |||
25 | template <class TypeTag> | ||
26 | 2 | class DrainageProblem : public PorousMediumFlowProblem<TypeTag> | |
27 | { | ||
28 | using ParentType = PorousMediumFlowProblem<TypeTag>; | ||
29 | using Scalar = GetPropType<TypeTag, Properties::Scalar>; | ||
30 | using PrimaryVariables = GetPropType<TypeTag, Properties::PrimaryVariables>; | ||
31 | using BoundaryTypes = Dumux::BoundaryTypes<GetPropType<TypeTag, Properties::ModelTraits>::numEq()>; | ||
32 | using ElementVolumeVariables = typename GetPropType<TypeTag, Properties::GridVolumeVariables>::LocalView; | ||
33 | using FVElementGeometry = typename GetPropType<TypeTag, Properties::GridGeometry>::LocalView; | ||
34 | using SubControlVolume = typename FVElementGeometry::SubControlVolume; | ||
35 | using GridGeometry = GetPropType<TypeTag, Properties::GridGeometry>; | ||
36 | using GridView = typename GridGeometry::GridView; | ||
37 | using FluidSystem = GetPropType<TypeTag, Properties::FluidSystem>; | ||
38 | using GridVariables = GetPropType<TypeTag, Properties::GridVariables>; | ||
39 | |||
40 | // copy some indices for convenience | ||
41 | using Indices = typename GetPropType<TypeTag, Properties::ModelTraits>::Indices; | ||
42 | using Labels = GetPropType<TypeTag, Properties::Labels>; | ||
43 | enum { | ||
44 | pwIdx = Indices::pressureIdx, | ||
45 | snIdx = Indices::saturationIdx, | ||
46 | nPhaseIdx = FluidSystem::phase1Idx, | ||
47 | |||
48 | #if !ISOTHERMAL | ||
49 | temperatureIdx = Indices::temperatureIdx, | ||
50 | energyEqIdx = Indices::energyEqIdx, | ||
51 | #endif | ||
52 | }; | ||
53 | |||
54 | using Element = typename GridView::template Codim<0>::Entity; | ||
55 | using Vertex = typename GridView::template Codim<GridView::dimension>::Entity; | ||
56 | |||
57 | public: | ||
58 | template<class SpatialParams> | ||
59 | 2 | DrainageProblem(std::shared_ptr<const GridGeometry> gridGeometry, std::shared_ptr<SpatialParams> spatialParams) | |
60 |
7/20✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
✓ Branch 9 taken 2 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 2 times.
✗ Branch 12 not taken.
✓ Branch 13 taken 2 times.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✓ Branch 16 taken 2 times.
✓ Branch 18 taken 2 times.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
✗ Branch 24 not taken.
✗ Branch 25 not taken.
|
8 | : ParentType(gridGeometry, spatialParams) |
61 | { | ||
62 |
1/2✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
|
2 | vtpOutputFrequency_ = getParam<int>("Problem.VtpOutputFrequency"); |
63 |
1/2✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
|
2 | useFixedPressureAndSaturationBoundary_ = getParam<bool>("Problem.UseFixedPressureAndSaturationBoundary", false); |
64 |
1/2✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
|
2 | pc_ = getParam<Scalar>("Problem.CapillaryPressure"); |
65 | 2 | } | |
66 | |||
67 | /*! | ||
68 | * \name Simulation steering | ||
69 | */ | ||
70 | // \{ | ||
71 | |||
72 | /*! | ||
73 | * \name Problem parameters | ||
74 | */ | ||
75 | // \{ | ||
76 | |||
77 | ✗ | bool shouldWriteOutput(const int timeStepIndex, const GridVariables& gridVariables) const | |
78 | { | ||
79 |
2/4✗ Branch 0 not taken.
✗ Branch 1 not taken.
✓ Branch 2 taken 133 times.
✓ Branch 3 taken 93 times.
|
226 | if (vtpOutputFrequency_ < 0) |
80 | ✗ | return true; | |
81 | |||
82 |
1/4✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 133 times.
|
133 | if (vtpOutputFrequency_ == 0) |
83 | ✗ | return (timeStepIndex == 0 || gridVariables.gridFluxVarsCache().invasionState().hasChanged()); | |
84 | else | ||
85 |
1/16✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✓ Branch 9 taken 133 times.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
|
133 | return (timeStepIndex % vtpOutputFrequency_ == 0 || gridVariables.gridFluxVarsCache().invasionState().hasChanged()); |
86 | } | ||
87 | |||
88 | /*! | ||
89 | * \name Boundary conditions | ||
90 | */ | ||
91 | // \{ | ||
92 | //! Specifies which kind of boundary condition should be used for | ||
93 | //! which equation for a finite volume on the boundary. | ||
94 | 12474 | BoundaryTypes boundaryTypes(const Element& element, const SubControlVolume& scv) const | |
95 | { | ||
96 | 12474 | BoundaryTypes bcTypes; | |
97 | |||
98 | // If a global phase pressure difference (pn,inlet - pw,outlet) with fixed saturations is specified, use a Dirichlet BC here | ||
99 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 12474 times.
|
12474 | if (useFixedPressureAndSaturationBoundary_ && isInletPore_(scv)) |
100 | bcTypes.setAllDirichlet(); | ||
101 | 24948 | else if (isOutletPore_(scv)) | |
102 | bcTypes.setAllDirichlet(); | ||
103 | |||
104 | #if !ISOTHERMAL | ||
105 | 14784 | bcTypes.setDirichlet(temperatureIdx); | |
106 | #endif | ||
107 | 12474 | return bcTypes; | |
108 | } | ||
109 | |||
110 | |||
111 | //! Evaluate the boundary conditions for a Dirichlet control volume. | ||
112 | 9207 | PrimaryVariables dirichlet(const Element& element, | |
113 | const SubControlVolume& scv) const | ||
114 | { | ||
115 | 9207 | PrimaryVariables values(0.0); | |
116 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 9207 times.
|
9207 | values[pwIdx] = 1e5; |
117 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 9207 times.
|
9207 | values[snIdx] = 0.0; |
118 | |||
119 | // If a global phase pressure difference (pn,inlet - pw,outlet) is specified and the saturation shall also be fixed, apply: | ||
120 | // pw,inlet = pw,outlet = 1e5; pn,outlet = pw,outlet + pc(S=0) = pw,outlet; pn,inlet = pw,inlet + pc_ | ||
121 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 9207 times.
|
9207 | if (useFixedPressureAndSaturationBoundary_ && isInletPore_(scv)) |
122 | ✗ | values[snIdx] = 1.0 - this->spatialParams().fluidMatrixInteraction(element, scv, int()/*dummyElemsol*/).sw(pc_); | |
123 | |||
124 | #if !ISOTHERMAL | ||
125 | 14784 | if (isInletPore_(scv)) | |
126 | 9504 | values[temperatureIdx] = 273.15 + 15; | |
127 | else | ||
128 | 5280 | values[temperatureIdx] = 273.15 + 10; | |
129 | #endif | ||
130 | 9207 | return values; | |
131 | } | ||
132 | |||
133 | |||
134 | // \} | ||
135 | |||
136 | /*! | ||
137 | * \name Volume terms | ||
138 | */ | ||
139 | // \{ | ||
140 | |||
141 | //! Evaluate the source term for all phases within a given sub-control-volume. | ||
142 | 497310 | PrimaryVariables source(const Element& element, | |
143 | const FVElementGeometry& fvGeometry, | ||
144 | const ElementVolumeVariables& elemVolVars, | ||
145 | const SubControlVolume& scv) const | ||
146 | { | ||
147 | 1510014 | PrimaryVariables values(0.0); | |
148 | |||
149 | // If we do not want to use global phase pressure difference with fixed saturations and pressures, | ||
150 | // we can instead only fix the non-wetting phase pressure and allow the wetting phase saturation to changle freely | ||
151 | // by applying a Nitsche-type boundary condition which tries to minimize the difference between the present pn and the given value | ||
152 |
1/2✓ Branch 0 taken 1510014 times.
✗ Branch 1 not taken.
|
1510014 | if (!useFixedPressureAndSaturationBoundary_ && isInletPore_(scv)) |
153 | 198396 | values[snIdx] = (elemVolVars[scv].pressure(nPhaseIdx) - (1e5 + pc_)) * 1e8; | |
154 | |||
155 | 497310 | return values; | |
156 | } | ||
157 | // \} | ||
158 | |||
159 | //! Evaluate the initial value for a control volume. | ||
160 | 180 | PrimaryVariables initial(const Vertex& vertex) const | |
161 | { | ||
162 | 180 | PrimaryVariables values(0.0); | |
163 | 180 | values[pwIdx] = 1e5; | |
164 | |||
165 | // get global index of pore | ||
166 | 540 | const auto dofIdxGlobal = this->gridGeometry().vertexMapper().index(vertex); | |
167 | 360 | if (isInletPore_(dofIdxGlobal)) | |
168 | 20 | values[snIdx] = 0.5; | |
169 | else | ||
170 | 340 | values[snIdx] = 0.0; | |
171 | |||
172 | #if !ISOTHERMAL | ||
173 | 180 | values[temperatureIdx] = 273.15 + 10; | |
174 | #endif | ||
175 | 180 | return values; | |
176 | } | ||
177 | |||
178 | //! Evaluate the initial invasion state of a pore throat | ||
179 | ✗ | bool initialInvasionState(const Element& element) const | |
180 | ✗ | { return false; } | |
181 | |||
182 | // \} | ||
183 | |||
184 | private: | ||
185 | |||
186 | bool isInletPore_(const SubControlVolume& scv) const | ||
187 | { | ||
188 | 3034812 | return isInletPore_(scv.dofIndex()); | |
189 | } | ||
190 | |||
191 | bool isInletPore_(const std::size_t dofIdxGlobal) const | ||
192 | { | ||
193 |
24/30✓ Branch 0 taken 49599 times.
✓ Branch 1 taken 1460415 times.
✓ Branch 2 taken 49599 times.
✓ Branch 3 taken 1460415 times.
✓ Branch 4 taken 49599 times.
✓ Branch 5 taken 1460415 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✓ Branch 12 taken 4752 times.
✓ Branch 13 taken 2640 times.
✓ Branch 14 taken 4752 times.
✓ Branch 15 taken 2640 times.
✓ Branch 16 taken 4752 times.
✓ Branch 17 taken 2640 times.
✓ Branch 18 taken 5 times.
✓ Branch 19 taken 85 times.
✓ Branch 20 taken 5 times.
✓ Branch 21 taken 85 times.
✓ Branch 22 taken 5 times.
✓ Branch 23 taken 85 times.
✓ Branch 24 taken 5 times.
✓ Branch 25 taken 85 times.
✓ Branch 26 taken 5 times.
✓ Branch 27 taken 85 times.
✓ Branch 28 taken 5 times.
✓ Branch 29 taken 85 times.
|
4552758 | return this->gridGeometry().poreLabel(dofIdxGlobal) == Labels::inlet; |
194 | } | ||
195 | |||
196 | bool isOutletPore_(const SubControlVolume& scv) const | ||
197 | { | ||
198 |
6/6✓ Branch 0 taken 4455 times.
✓ Branch 1 taken 8019 times.
✓ Branch 2 taken 4455 times.
✓ Branch 3 taken 8019 times.
✓ Branch 4 taken 4455 times.
✓ Branch 5 taken 8019 times.
|
37422 | return this->gridGeometry().poreLabel(scv.dofIndex()) == Labels::outlet; |
199 | } | ||
200 | |||
201 | int vtpOutputFrequency_; | ||
202 | bool useFixedPressureAndSaturationBoundary_; | ||
203 | Scalar pc_; | ||
204 | }; | ||
205 | } //end namespace Dumux | ||
206 | |||
207 | #endif | ||
208 |