GCC Code Coverage Report


Directory: ../../../builds/dumux-repositories/
File: /builds/dumux-repositories/dumux/test/porousmediumflow/1pncmin/nonisothermal/reaction.hh
Date: 2024-05-04 19:09:25
Exec Total Coverage
Lines: 41 58 70.7%
Functions: 1 1 100.0%
Branches: 17 32 53.1%

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 OnePNCMinTests
10 * \brief Class for the evaluation of the reaction rate of Calciumoxide to Halciumhydroxide
11 *
12 * It contains simple and advanced reaction kinetics according to Nagel et al. (2014) \cite nagel2014.
13 */
14
15 #ifndef DUMUX_THERMOCHEM_REACTION_HH
16 #define DUMUX_THERMOCHEM_REACTION_HH
17
18 namespace Dumux {
19
20 /*!
21 * \ingroup OnePNCMinTests
22 * \brief Class for the evaluation of the reaction rate of Calciumoxide to Halciumhydroxide
23 *
24 * It contains simple and advanced reaction kinetics according to Nagel et al. (2014) \cite nagel2014.
25 */
26 class ThermoChemReaction {
27
28 public:
29 /*!
30 * \brief Evaluates the reaction kinetics (see Nagel et al. 2014 \cite nagel2014).
31 */
32 template<class VolumeVariables>
33 typename VolumeVariables::PrimaryVariables::value_type
34 68416 thermoChemReaction(const VolumeVariables &volVars) const
35 {
36 using FluidSystem = typename VolumeVariables::FluidSystem;
37 using SolidSystem = typename VolumeVariables::SolidSystem;
38
39 static constexpr auto H2OIdx = FluidSystem::compIdx(FluidSystem::MultiPhaseFluidSystem::H2OIdx);
40 static constexpr int cPhaseIdx = SolidSystem::comp0Idx;
41 static constexpr int hPhaseIdx = SolidSystem::comp1Idx;
42
43 using Scalar = typename VolumeVariables::PrimaryVariables::value_type;
44
45 // calculate the equilibrium temperature Teq
46
1/2
✓ Branch 0 taken 68416 times.
✗ Branch 1 not taken.
68416 Scalar T= volVars.temperature();
47 68416 Scalar Teq = 0;
48
49 68416 Scalar moleFractionVapor = 1e-3;
50
51
2/4
✓ Branch 0 taken 68416 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 68416 times.
✗ Branch 3 not taken.
136832 if(volVars.moleFraction(0, H2OIdx) > 1e-3)
52 136832 moleFractionVapor = volVars.moleFraction(0, H2OIdx);
53
54
2/4
✗ Branch 0 not taken.
✓ Branch 1 taken 68416 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 68416 times.
136832 if(volVars.moleFraction(0, H2OIdx) >= 1.0) moleFractionVapor = 1;
55
56 68416 Scalar pV = volVars.pressure(0) *moleFractionVapor;
57 68416 Scalar vaporPressure = pV*1.0e-5;
58 68416 Scalar pFactor = log(vaporPressure);
59
60 68416 Teq = -12845;
61 68416 Teq /= (pFactor - 16.508); //the equilibrium temperature
62
63 136832 Scalar realSolidDensityAverage = (volVars.solidVolumeFraction(hPhaseIdx)*volVars.solidComponentDensity(hPhaseIdx)
64 136832 + volVars.solidVolumeFraction(cPhaseIdx)*volVars.solidComponentDensity(cPhaseIdx))
65 / (volVars.solidVolumeFraction(hPhaseIdx)
66 136832 + volVars.solidVolumeFraction(cPhaseIdx));
67
68
2/2
✓ Branch 1 taken 8 times.
✓ Branch 2 taken 68408 times.
68416 if(realSolidDensityAverage <= volVars.solidComponentDensity(cPhaseIdx))
69 {
70 16 realSolidDensityAverage = volVars.solidComponentDensity(cPhaseIdx);
71 }
72
73
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 68416 times.
68416 if(realSolidDensityAverage >= volVars.solidComponentDensity(hPhaseIdx))
74 {
75 realSolidDensityAverage = volVars.solidComponentDensity(hPhaseIdx);
76 }
77
78 68416 Scalar qMass = 0.0;
79
80 // discharge or hydration
81
1/2
✓ Branch 0 taken 68416 times.
✗ Branch 1 not taken.
68416 if (T < Teq){
82 68416 Scalar dXH_dt1 = 0.0;
83 68416 Scalar dXH_dt2 = 0.0;
84
85 68416 Scalar xH = (realSolidDensityAverage-volVars.solidComponentDensity(cPhaseIdx))/(volVars.solidComponentDensity(hPhaseIdx)- volVars.solidComponentDensity(cPhaseIdx));
86
87
2/2
✓ Branch 0 taken 520 times.
✓ Branch 1 taken 67896 times.
68416 if(xH < 1.0e-5) {xH = 1.0e-5; }
88
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 68416 times.
68416 if(xH >=1 ) {xH = 1 - 1e-5; }
89
90 68416 Scalar R = 8.314 ; // [J/molK]
91 68416 Scalar peq = 1e5*exp( (-12845)/T + 16.508);
92
93
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 68416 times.
68416 if(peq >= pV) {peq=899954;}
94
95 68416 Scalar dXH_dt = 0;
96
97 // reaction kinetics for T-Teq > 50 K
98
1/2
✓ Branch 0 taken 68416 times.
✗ Branch 1 not taken.
68416 if(Teq -T > 50.25){
99
100 68416 Scalar A =exp(-8.9486e4/(R*T));
101 68416 Scalar B = pow(((pV/peq)-1),0.83);
102 68416 Scalar D = 1-xH;
103 68416 Scalar C = pow((-log(D)),0.666);
104
105 68416 dXH_dt = 1.3945e4*A *B*3*D*C;
106
107 }
108
109 // reaction kinetics for T-Teq < 50 K
110
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 68416 times.
68416 if(Teq -T < 49.75){
111
112 Scalar E = exp(5.3332e4/T);
113 Scalar F = pow((pV*1e-5),6);
114 Scalar G = (1-xH);
115
116 dXH_dt = 1.004e-34 *E * F * G;
117
118 }
119
120 // linearization of the point of discontinuity
121
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 68416 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
68416 if(Teq-T <=50.25 && Teq-T >=49.75){
122
123 Scalar op = ((Teq-T)- 49.75)*2;
124 Scalar A =exp(-8.9486e4/(R*T));
125 Scalar B = pow(((pV/peq)-1),0.83);
126 Scalar D = 1-xH;
127 Scalar C = pow((-log(D)),0.666);
128 dXH_dt1 = 1.3945e4*A *B*3*D*C;
129
130 Scalar E = exp(5.3332e4/T);
131 Scalar F = pow((pV*1e-5),6);
132 Scalar G = (1-xH);
133 dXH_dt2 = 1.004e-34 *E * F * G;
134
135 dXH_dt = dXH_dt1*op + dXH_dt2*(1-op);
136 }
137
138 // no reaction at equilibrium
139
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 68416 times.
68416 if(Teq -T <= 0)
140 dXH_dt = 0;
141 68416 Scalar deltaRhoS = volVars.solidComponentDensity(hPhaseIdx) - volVars.solidComponentDensity(cPhaseIdx);
142 68416 qMass = dXH_dt*deltaRhoS;
143 }
144
145 68416 return qMass;
146 }
147
148
149 /*!
150 * \brief Evaluates the simple chemical reaction kinetics (see Nagel et al. 2014)
151 */
152 template<class VolumeVariables>
153 typename VolumeVariables::PrimaryVariables::value_type
154 thermoChemReactionSimple(const VolumeVariables &volVars) const
155 {
156 using FluidSystem = typename VolumeVariables::FluidSystem;
157 using SolidSystem = typename VolumeVariables::SolidSystem;
158
159 static constexpr auto H2OIdx = FluidSystem::compIdx(FluidSystem::MultiPhaseFluidSystem::H2OIdx);
160 static constexpr int cPhaseIdx = SolidSystem::comp0Idx;
161 static constexpr int hPhaseIdx = SolidSystem::comp1Idx;
162
163 using Scalar = typename VolumeVariables::PrimaryVariables::value_type;
164
165 // calculate the equilibrium temperature Teq
166 Scalar T= volVars.temperature();
167 Scalar Teq = 0;
168
169 Scalar moleFractionVapor = 1e-3;
170
171 if(volVars.moleFraction(0, H2OIdx) > 1e-3)
172 moleFractionVapor = volVars.moleFraction(0, H2OIdx);
173
174 if(volVars.moleFraction(0, H2OIdx) >= 1.0) moleFractionVapor = 1;
175
176 Scalar pV = volVars.pressure(0) *moleFractionVapor;
177 Scalar vaporPressure = pV*1.0e-5;
178 Scalar pFactor = log(vaporPressure);
179
180 Teq = -12845;
181 Teq /= (pFactor - 16.508); //the equilibrium temperature
182
183
184 Scalar realSolidDensityAverage = (volVars.solidVolumeFraction(hPhaseIdx)*volVars.solidComponentDensity(hPhaseIdx)
185 + volVars.solidVolumeFraction(cPhaseIdx)*volVars.solidComponentDensity(cPhaseIdx))
186 / (volVars.solidVolumeFraction(hPhaseIdx)
187 + volVars.solidVolumeFraction(cPhaseIdx));
188
189 if(realSolidDensityAverage <= volVars.solidComponentDensity(cPhaseIdx))
190 {
191 realSolidDensityAverage = volVars.solidComponentDensity(cPhaseIdx);
192 }
193
194 if(realSolidDensityAverage >= volVars.solidComponentDensity(hPhaseIdx))
195 {
196 realSolidDensityAverage = volVars.solidComponentDensity(hPhaseIdx);
197 }
198
199 Scalar qMass = 0.0;
200
201 // discharge or hydration
202 if (T < Teq){
203 Scalar massFracH2O_fPhase = volVars.massFraction(0, H2OIdx);
204 Scalar krh = 0.2;
205
206 Scalar rHydration = - massFracH2O_fPhase* (volVars.solidComponentDensity(hPhaseIdx)- realSolidDensityAverage)
207 * krh * (T-Teq)/ Teq;
208
209 qMass = rHydration;
210 }
211
212 // charge or hydration
213 else if(T > Teq){
214
215 Scalar krd = 0.05;
216
217 Scalar rDehydration = -(volVars.solidComponentDensity(cPhaseIdx)- realSolidDensityAverage)
218 * krd * (Teq-T)/ Teq;
219
220 qMass = rDehydration;
221 }
222
223 if(Teq -T == 0) qMass = 0;
224
225 return qMass;
226 }
227
228 };
229
230 } // end namespace Dumux
231
232 #endif
233