GCC Code Coverage Report


Directory: ../../../builds/dumux-repositories/
File: /builds/dumux-repositories/dumux/test/porousmediumflow/1pnc/1p3c/properties.hh
Date: 2024-09-21 20:52:54
Exec Total Coverage
Lines: 15 21 71.4%
Functions: 6 10 60.0%
Branches: 13 62 21.0%

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 OnePNCTests
10 * \brief Definition of a problem for a 1p3c problem:
11 * Component transport of N2, CO2 and H2 using the Maxwell-Stefan diffusion law.
12 */
13
14 #ifndef DUMUX_1P3C_TEST_PROBLEM_PROPERTIES_HH
15 #define DUMUX_1P3C_TEST_PROBLEM_PROPERTIES_HH
16
17 #if HAVE_DUNE_UGGRID
18 #include <dune/grid/uggrid.hh>
19 #endif
20 #include <dune/grid/yaspgrid.hh>
21
22 #include <dumux/discretization/cctpfa.hh>
23 #include <dumux/discretization/box.hh>
24 #include <dumux/discretization/evalsolution.hh>
25 #include <dumux/discretization/evalgradients.hh>
26 #include <dumux/porousmediumflow/1pnc/model.hh>
27
28 #include <dumux/material/idealgas.hh>
29 #include <dumux/material/fluidsystems/base.hh>
30
31 #include "problem.hh"
32 #include "../1p2c/spatialparams.hh"
33
34
35 #include <dumux/flux/maxwellstefanslaw.hh>
36
37 namespace Dumux::Properties {
38
39 // Create new type tags
40 namespace TTag {
41 struct MaxwellStefanOnePThreeCTest { using InheritsFrom = std::tuple<OnePNC>; };
42 struct MaxwellStefanOnePThreeCTestBox { using InheritsFrom = std::tuple<MaxwellStefanOnePThreeCTest, BoxModel>; };
43 struct MaxwellStefanOnePThreeCTestCCTpfa { using InheritsFrom = std::tuple<MaxwellStefanOnePThreeCTest, CCTpfaModel>; };
44 } // end namespace TTag
45
46 // Set the grid type
47 #if HAVE_DUNE_UGGRID
48 template<class TypeTag>
49 struct Grid<TypeTag, TTag::MaxwellStefanOnePThreeCTest> { using type = Dune::UGGrid<2>; };
50 #else
51 template<class TypeTag>
52 struct Grid<TypeTag, TTag::MaxwellStefanOnePThreeCTest> { using type = Dune::YaspGrid<2>; };
53 #endif
54
55 // Set the problem property
56 template<class TypeTag>
57 struct Problem<TypeTag, TTag::MaxwellStefanOnePThreeCTest> { using type = MaxwellStefanOnePThreeCTestProblem<TypeTag>; };
58
59 /*!
60 * \ingroup OnePNCTests
61 * \brief A simple fluid system with three components for testing the multi-component diffusion with the Maxwell-Stefan formulation.
62 */
63 template<class TypeTag>
64 class H2N2CO2FluidSystem
65 : public FluidSystems::Base<GetPropType<TypeTag, Properties::Scalar>, H2N2CO2FluidSystem<TypeTag>>
66
67 {
68 using Scalar = GetPropType<TypeTag, Properties::Scalar>;
69 using ThisType = H2N2CO2FluidSystem<TypeTag>;
70 using Base = FluidSystems::Base<Scalar, ThisType>;
71 using IdealGas = Dumux::IdealGas<Scalar>;
72
73 public:
74 //! The number of phases
75 static constexpr int numPhases = 1;
76 static constexpr int numComponents = 3;
77
78 static constexpr int H2Idx = 0; //first major component
79 static constexpr int N2Idx = 1; //second major component
80 static constexpr int CO2Idx = 2; //secondary component
81
82 //! Human readable component name (index compIdx) (for vtk output)
83 12 static std::string componentName(int compIdx)
84
2/6
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 12 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
12 { return "MaxwellStefan_" + std::to_string(compIdx); }
85
86 //! Human readable phase name (index phaseIdx) (for velocity vtk output)
87 static std::string phaseName(int phaseIdx = 0)
88
0/4
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
48 { return "Gas"; }
89
90 //! Molar mass in kg/mol of the component with index compIdx
91
1/2
✓ Branch 0 taken 18329740 times.
✗ Branch 1 not taken.
18329740 static Scalar molarMass(unsigned int compIdx)
92 {
93 switch (compIdx)
94 {
95 case H2Idx: return 0.002;
96 case N2Idx: return 0.028;
97 case CO2Idx:return 0.044;
98 }
99 DUNE_THROW(Dune::InvalidStateException, "Invalid component index " << compIdx);;
100 }
101
102 using Base::binaryDiffusionCoefficient;
103 /*!
104 * \brief Given a phase's composition, temperature and pressure,
105 * returns the binary diffusion coefficient \f$\mathrm{[m^2/s]}\f$ for components
106 * \f$i\f$ and \f$j\f$ in this phase.
107 *
108 * \param fluidState An arbitrary fluid state
109 * \param phaseIdx The index of the fluid phase to consider
110 * \param compIIdx The index of the first component to consider
111 * \param compJIdx The index of the second component to consider
112 */
113 template <class FluidState>
114 1170912 static Scalar binaryDiffusionCoefficient(const FluidState &fluidState,
115 int phaseIdx,
116 int compIIdx,
117 int compJIdx)
118 {
119
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1170912 times.
1170912 if (compIIdx > compJIdx)
120 {
121 using std::swap;
122 swap(compIIdx, compJIdx);
123 }
124
125
4/4
✓ Branch 0 taken 780608 times.
✓ Branch 1 taken 390304 times.
✓ Branch 2 taken 390304 times.
✓ Branch 3 taken 390304 times.
1170912 if (compIIdx == H2Idx && compJIdx == N2Idx)
126 return 83.3e-6;
127
3/4
✓ Branch 0 taken 390304 times.
✓ Branch 1 taken 390304 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 390304 times.
780608 if (compIIdx == H2Idx && compJIdx == CO2Idx)
128 return 68.0e-6;
129
2/4
✓ Branch 0 taken 390304 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 390304 times.
390304 if (compIIdx == N2Idx && compJIdx == CO2Idx)
130 return 16.8e-6;
131 DUNE_THROW(Dune::InvalidStateException,
132 "Binary diffusion coefficient of components "
133 << compIIdx << " and " << compJIdx << " is undefined!\n");
134 }
135 using Base::density;
136 /*!
137 * \brief Given a phase's composition, temperature, pressure, and
138 * the partial pressures of all components, returns its
139 * density \f$\mathrm{[kg/m^3]}\f$.
140 *
141 * \param phaseIdx index of the phase
142 * \param fluidState the fluid state
143 */
144 template <class FluidState>
145 static Scalar density(const FluidState &fluidState,
146 const int phaseIdx)
147 {
148 780608 Scalar T = fluidState.temperature(phaseIdx);
149 780608 Scalar p = fluidState.pressure(phaseIdx);
150 1170912 return IdealGas::molarDensity(T, p) * fluidState.averageMolarMass(0);
151 }
152
153 using Base::viscosity;
154 /*!
155 * \brief Calculates the dynamic viscosity of a fluid phase \f$\mathrm{[Pa*s]}\f$
156 *
157 * \param fluidState An arbitrary fluid state
158 * \param phaseIdx The index of the fluid phase to consider
159 */
160 template <class FluidState>
161 static Scalar viscosity(const FluidState &fluidState,
162 int phaseIdx)
163 {
164 return 1e-6;
165 }
166
167 using Base::molarDensity;
168 /*!
169 * \brief The molar density \f$\rho_{mol,\alpha}\f$
170 * of a fluid phase \f$\alpha\f$ in \f$\mathrm{[mol/m^3]}\f$
171 *
172 * The molar density for the simple relation is defined by the
173 * mass density \f$\rho_\alpha\f$ and the molar mass of the main component \f$M_\kappa\f$:
174 *
175 * \f[\rho_{mol,\alpha} = \frac{\rho_\alpha}{M_\kappa} \;.\f]
176 */
177 template <class FluidState>
178 static Scalar molarDensity(const FluidState &fluidState, int phaseIdx)
179 {
180 780608 Scalar T = fluidState.temperature(phaseIdx);
181 780608 Scalar p = fluidState.pressure(phaseIdx);
182 390304 return IdealGas::molarDensity(T,p);
183 }
184 };
185
186 // Set fluid configuration
187 template<class TypeTag>
188 struct FluidSystem<TypeTag, TTag::MaxwellStefanOnePThreeCTest>
189 {using type = H2N2CO2FluidSystem<TypeTag>; };
190
191 // Set the spatial parameters
192 template<class TypeTag>
193 struct SpatialParams<TypeTag, TTag::MaxwellStefanOnePThreeCTest>
194 {
195 using GridGeometry = GetPropType<TypeTag, Properties::GridGeometry>;
196 using Scalar = GetPropType<TypeTag, Properties::Scalar>;
197 using type = OnePNCTestSpatialParams<GridGeometry, Scalar>;
198 };
199
200 // Define whether mole(true) or mass (false) fractions are used
201 template<class TypeTag>
202 struct UseMoles<TypeTag, TTag::MaxwellStefanOnePThreeCTest> { static constexpr bool value = true; };
203
204 //! Here we set FicksLaw or MaxwellStefansLaw
205 template<class TypeTag>
206 struct MolecularDiffusionType<TypeTag, TTag::MaxwellStefanOnePThreeCTest> { using type = MaxwellStefansLaw<TypeTag>; };
207
208 } // end namespace Properties
209
210 #endif
211