GCC Code Coverage Report


Directory: ../../../builds/dumux-repositories/
File: /builds/dumux-repositories/dumux/dumux/material/constraintsolvers/computefromreferencephase.hh
Date: 2024-09-21 20:52:54
Exec Total Coverage
Lines: 13 13 100.0%
Functions: 6 13 46.2%
Branches: 7 12 58.3%

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 ConstraintSolvers
10 * \brief Computes all quantities of a generic fluid state if a
11 * reference phase has been specified.
12 *
13 * This makes it is possible to specify just one phase and let the
14 * remaining ones be calculated by the constraint solver. This
15 * constraint solver assumes thermodynamic equilibrium
16 */
17 #ifndef DUMUX_COMPUTE_FROM_REFERENCE_PHASE_HH
18 #define DUMUX_COMPUTE_FROM_REFERENCE_PHASE_HH
19
20 #include <dumux/material/constraintsolvers/compositionfromfugacities.hh>
21
22 #include <dune/common/fvector.hh>
23 #include <dune/common/fmatrix.hh>
24
25 #include <dumux/common/exceptions.hh>
26
27 namespace Dumux {
28
29 /*!
30 * \ingroup ConstraintSolvers
31 * \brief Computes all quantities of a generic fluid state if a
32 * reference phase has been specified.
33 *
34 * This makes it is possible to specify just one phase and let the
35 * remaining ones be calculated by the constraint solver. This
36 * constraint solver assumes thermodynamic equilibrium. It assumes the
37 * following quantities to be set:
38 *
39 * - composition (mole+mass fractions) of the *reference* phase \f$x^\kappa_\beta\f$
40 * - temperature of the *reference* phase \f$T_\beta\f$
41 * - saturations of *all* phases \f$S_\alpha\f$, \f$S_\beta\f$
42 * - pressures of *all* phases \f$p_\alpha\f$, \f$p_\beta\f$
43 *
44 * \f$ f^\kappa_\beta = f^\kappa_\alpha = \Phi^\kappa_\alpha(\{x^\lambda_\alpha \}, T_\alpha, p_\alpha) p_\alpha x^\kappa_\alpha\; \f$,
45 *
46 * \f$ p_\alpha = p_\beta + p_{c\beta\alpha}\; \f$,
47 *
48 * after calling the solve() method the following quantities are
49 * calculated in addition:
50 *
51 * - temperature of *all* phases \f$T_\alpha\f$, \f$T_\beta\f$
52 * - density, molar density, molar volume of *all* phases
53 * \f$\rho_\alpha\f$, \f$\rho_\beta\f$, \f$\rho_{mol, \alpha}\f$, \f$\rho_{mol, \beta}\f$,
54 * \f$V_{mol, \alpha}\f$, \f$V_{mol, \beta}\f$
55 * - composition in mole and mass fractions and molarities of *all* phases
56 * \f$x^\kappa_\alpha\f$, \f$x^\kappa_\beta\f$, \f$X^\kappa_\alpha\f$, \f$X^\kappa_\beta\f$,
57 * \f$c^\kappa_\alpha\f$, \f$c^\kappa_\beta\f$
58 * - mean molar masses of *all* phases \f$M_\alpha\f$, \f$M_\beta\f$
59 * - fugacity coefficients of *all* components in *all* phases
60 * \f$\Phi^\kappa_\alpha\f$, \f$\Phi^\kappa_\beta\f$
61 */
62 template <class Scalar, class FluidSystem>
63 class ComputeFromReferencePhase
64 {
65 enum { numPhases = FluidSystem::numPhases };
66 enum { numComponents = FluidSystem::numComponents };
67 using CompositionFromFugacities = Dumux::CompositionFromFugacities<Scalar, FluidSystem>;
68 using ComponentVector = Dune::FieldVector<Scalar, numComponents>;
69
70 public:
71 /*!
72 * \brief Computes all quantities of a generic fluid state if a
73 * reference phase has been specified.
74 *
75 * This makes it is possible to specify just one phase and let the
76 * remaining ones be calculated by the constraint solver. This
77 * constraint solver assumes thermodynamic equilibrium. It assumes the
78 * following quantities to be set:
79 *
80 * - composition (mole+mass fractions) of the *reference* phase
81 * - temperature of the *all* phases
82 * - saturations of *all* phases
83 * - pressures of *all* phases
84 *
85 * after calling the solve() method the following quantities are
86 * calculated in addition:
87 *
88 * - temperature of *all* phases
89 * - density, molar density, molar volume of *all* phases
90 * - composition in mole and mass fractions and molaries of *all* phases
91 * - mean molar masses of *all* phases
92 * - fugacity coefficients of *all* components in *all* phases
93 *
94 * \param fluidState Thermodynamic state of the fluids
95 * \param paramCache Container for cache parameters
96 * \param refPhaseIdx The phase index of the reference phase
97 */
98 template <class FluidState, class ParameterCache>
99 15650873 static void solve(FluidState &fluidState,
100 ParameterCache &paramCache,
101 int refPhaseIdx)
102 {
103 15650873 ComponentVector fugVec;
104
105 // compute the density and enthalpy of the
106 // reference phase
107 15650873 paramCache.updatePhase(fluidState, refPhaseIdx);
108
0/2
✗ Branch 0 not taken.
✗ Branch 1 not taken.
15650873 fluidState.setDensity(refPhaseIdx,
109 FluidSystem::density(fluidState,
110 paramCache,
111 refPhaseIdx));
112 15650873 fluidState.setMolarDensity(refPhaseIdx,
113 FluidSystem::molarDensity(fluidState,
114 paramCache,
115 refPhaseIdx));
116
117 // compute the fugacities of all components in the reference phase
118
2/2
✓ Branch 0 taken 49924573 times.
✓ Branch 1 taken 15650873 times.
65575446 for (int compIdx = 0; compIdx < numComponents; ++compIdx)
119 {
120
0/2
✗ Branch 0 not taken.
✗ Branch 1 not taken.
49924573 fluidState.setFugacityCoefficient(refPhaseIdx,
121 compIdx,
122 FluidSystem::fugacityCoefficient(fluidState,
123 paramCache,
124 refPhaseIdx,
125 compIdx));
126 149773719 fugVec[compIdx] = fluidState.fugacity(refPhaseIdx, compIdx);
127 }
128
129 // compute all quantities for the non-reference phases
130
2/2
✓ Branch 0 taken 31301746 times.
✓ Branch 1 taken 15650873 times.
46952619 for (int phaseIdx = 0; phaseIdx < numPhases; ++phaseIdx)
131 {
132
2/2
✓ Branch 0 taken 15650873 times.
✓ Branch 1 taken 15650873 times.
31301746 if (phaseIdx == refPhaseIdx)
133 continue; // reference phase is already calculated
134
135
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 15650873 times.
15650873 CompositionFromFugacities::guessInitial(fluidState, paramCache, phaseIdx, fugVec);
136 15650873 CompositionFromFugacities::solve(fluidState, paramCache, phaseIdx, fugVec);
137 }
138 15650873 }
139 };
140
141 } // end namespace Dumux
142
143 #endif
144