version 3.11-dev
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages Concepts
1padapter.hh
Go to the documentation of this file.
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//
12#ifndef DUMUX_FLUIDSYTEMS_ONEP_ADAPTER_HH
13#define DUMUX_FLUIDSYTEMS_ONEP_ADAPTER_HH
14
15#include <cassert>
16
17#include <dune/common/exceptions.hh>
18
21
22namespace Dumux::FluidSystems {
23
30template <class MPFluidSystem, int phase = 0>
32: public Base<typename MPFluidSystem::Scalar, OnePAdapter<MPFluidSystem, phase>>
33{
35
36 static_assert(phase < MPFluidSystem::numPhases, "Phase does not exist in multi-phase fluidsystem!");
37
38 struct AdapterPolicy
39 {
40 using FluidSystem = MPFluidSystem;
41
42 // the phase index is always zero, other phases than the chosen phase should never be called
43 static int phaseIdx(int mpFluidPhaseIdx)
44 { return 0; }
45
46 // the main component is currently excepted to have the same index as it's phase
47 // (see Fluidsystems::Base::getMainComponent for more information)
48 // so we swap the main component with the first component
49 // this mapping works in both ways since we are only swapping components
50 static constexpr int compIdx(int compIdx)
51 {
52 if (compIdx == 0)
53 return phase;
54 else if (compIdx == phase)
55 return 0;
56 else
57 return compIdx;
58 }
59 };
60
61 template<class FluidState>
62 static auto adaptFluidState(const FluidState& fluidState)
64
65public:
66 using Scalar = typename MPFluidSystem::Scalar;
68
70 using MultiPhaseFluidSystem = MPFluidSystem;
72 static constexpr int multiphaseFluidsystemPhaseIdx = phase;
73
75 static constexpr int numPhases = 1;
78 static constexpr int numComponents = MultiPhaseFluidSystem::isMiscible() ? MultiPhaseFluidSystem::numComponents : numPhases;
80 static constexpr int phase0Idx = 0;
81
83 static constexpr int compIdx(int multiPhaseFluidSystemCompIdx)
84 { return AdapterPolicy::compIdx(multiPhaseFluidSystemCompIdx); }
85
89 template<class ...Args>
90 static void init(Args&&... args)
91 { MultiPhaseFluidSystem::init(std::forward<Args>(args)...); }
92
93 /****************************************
94 * Fluid phase related static parameters
95 ****************************************/
101 static std::string phaseName(int phaseIdx = 0)
102 { return MultiPhaseFluidSystem::phaseName(phase); }
103
109 static std::string componentName(int compIdx)
110 { return MultiPhaseFluidSystem::componentName(AdapterPolicy::compIdx(compIdx)); }
111
115 static std::string name()
116 { return MultiPhaseFluidSystem::phaseName(phase); }
117
121 static constexpr bool isMiscible()
122 { return false; }
123
127 static constexpr bool isGas(int phaseIdx = 0)
128 { return MultiPhaseFluidSystem::isGas(phase); }
129
144 static constexpr bool isIdealMixture(int phaseIdx = 0)
145 { return MultiPhaseFluidSystem::isIdealMixture(phase); }
146
150 static constexpr bool isCompressible(int phaseIdx = 0)
151 { return MultiPhaseFluidSystem::isCompressible(phase); }
152
156 static constexpr bool viscosityIsConstant(int phaseIdx = 0)
157 { return MultiPhaseFluidSystem::viscosityIsConstant(phase); }
158
162 static constexpr bool isIdealGas(int phaseIdx = 0)
163 { return MultiPhaseFluidSystem::isIdealGas(phase); }
164
169 { return MultiPhaseFluidSystem::molarMass(AdapterPolicy::compIdx(compIdx)); }
170
173 template <class FluidState>
174 static Scalar density(const FluidState &fluidState, int phaseIdx = 0)
175 {
176 assert(phaseIdx == 0);
177 return MultiPhaseFluidSystem::density(adaptFluidState(fluidState), phase);
178 }
179
182 template <class FluidState>
183 static Scalar molarDensity(const FluidState &fluidState, int phaseIdx = 0)
184 {
185 assert(phaseIdx == 0);
186 return MultiPhaseFluidSystem::molarDensity(adaptFluidState(fluidState), phase);
187 }
188
191 template <class FluidState>
192 static Scalar enthalpy(const FluidState &fluidState, int phaseIdx = 0)
193 {
194 assert(phaseIdx == 0);
195 return MultiPhaseFluidSystem::enthalpy(adaptFluidState(fluidState), phase);
196 }
197
205 template <class FluidState>
206 static Scalar componentEnthalpy(const FluidState &fluidState,
207 int phaseIdx,
208 int compIdx)
209 {
210 assert(phaseIdx == 0);
211 return MultiPhaseFluidSystem::componentEnthalpy(adaptFluidState(fluidState), phase,
212 AdapterPolicy::compIdx(compIdx));
213 }
214
217 template <class FluidState>
218 static Scalar viscosity(const FluidState &fluidState, int phaseIdx = 0)
219 {
220 assert(phaseIdx == 0);
221 return MultiPhaseFluidSystem::viscosity(adaptFluidState(fluidState), phase);
222 }
223
226 template <class FluidState>
227 static Scalar fugacityCoefficient(const FluidState &fluidState,
228 int phaseIdx,
229 int compIdx)
230 {
231 assert(phaseIdx == 0);
232 return MultiPhaseFluidSystem::fugacityCoefficient(adaptFluidState(fluidState), phase,
233 AdapterPolicy::compIdx(compIdx));
234 }
235
238 template <class FluidState>
239 static Scalar diffusionCoefficient(const FluidState &fluidState,
240 int phaseIdx,
241 int compIdx)
242 {
243 assert(phaseIdx == 0);
244 return MultiPhaseFluidSystem::diffusionCoefficient(adaptFluidState(fluidState), phase,
245 AdapterPolicy::compIdx(compIdx));
246 }
247
250 template <class FluidState>
251 static Scalar binaryDiffusionCoefficient(const FluidState &fluidState,
252 int phaseIdx,
253 int compIIdx,
254 int compJIdx)
255 {
256 assert(phaseIdx == 0);
257 return MultiPhaseFluidSystem::binaryDiffusionCoefficient(adaptFluidState(fluidState), phase,
258 AdapterPolicy::compIdx(compIIdx),
259 AdapterPolicy::compIdx(compJIdx));
260 }
261
264 template <class FluidState>
265 static Scalar thermalConductivity(const FluidState &fluidState,
266 int phaseIdx = 0)
267 {
268 assert(phaseIdx == 0);
269 return MultiPhaseFluidSystem::thermalConductivity(adaptFluidState(fluidState), phase);
270 }
271
274 template <class FluidState>
275 static Scalar heatCapacity(const FluidState &fluidState,
276 int phaseIdx = 0)
277 {
278 assert(phaseIdx == 0);
279 return MultiPhaseFluidSystem::heatCapacity(adaptFluidState(fluidState), phase);
280 }
281
288 template <class FluidState>
289 static Scalar vaporPressure(const FluidState &fluidState,
290 int compIdx)
291 {
292 return MultiPhaseFluidSystem::vaporPressure(adaptFluidState(fluidState),
293 AdapterPolicy::compIdx(compIdx));
294 }
295};
296
297} // namespace Dumux::FluidSystems
298
299#endif
Adapter class for fluid states with different indices.
Adapter class for fluid states with different indices.
Definition: adapter.hh:32
Fluid system base class.
Definition: fluidsystems/base.hh:32
An adapter for multi-phase fluid systems to be used with (compositional) one-phase models.
Definition: 1padapter.hh:33
static Scalar componentEnthalpy(const FluidState &fluidState, int phaseIdx, int compIdx)
Returns the specific enthalpy of a component in a specific phase.
Definition: 1padapter.hh:206
static Scalar thermalConductivity(const FluidState &fluidState, int phaseIdx=0)
Thermal conductivity of a fluid phase .
Definition: 1padapter.hh:265
static Scalar viscosity(const FluidState &fluidState, int phaseIdx=0)
Calculate the dynamic viscosity of a fluid phase .
Definition: 1padapter.hh:218
static std::string phaseName(int phaseIdx=0)
Return the human readable name of a fluid phase.
Definition: 1padapter.hh:101
static void init(Args &&... args)
Initialize the fluid system's static parameters generically.
Definition: 1padapter.hh:90
static Scalar density(const FluidState &fluidState, int phaseIdx=0)
Calculate the density of a fluid phase.
Definition: 1padapter.hh:174
static constexpr int multiphaseFluidsystemPhaseIdx
the index of the phase we choose from the multi-phase fluid system
Definition: 1padapter.hh:72
static Scalar molarDensity(const FluidState &fluidState, int phaseIdx=0)
Calculate the molar density of a fluid phase.
Definition: 1padapter.hh:183
static Scalar vaporPressure(const FluidState &fluidState, int compIdx)
Vapor pressure of a component .
Definition: 1padapter.hh:289
static constexpr int numPhases
number of phases in the fluid system
Definition: 1padapter.hh:75
static constexpr int phase0Idx
number of components has to be the same as in the multi-phase fluid system as the composition needs t...
Definition: 1padapter.hh:80
static Scalar binaryDiffusionCoefficient(const FluidState &fluidState, int phaseIdx, int compIIdx, int compJIdx)
Given a phase's composition, temperature and pressure, return the binary diffusion coefficient for c...
Definition: 1padapter.hh:251
typename MPFluidSystem::Scalar Scalar
Definition: 1padapter.hh:66
static constexpr int compIdx(int multiPhaseFluidSystemCompIdx)
convert a component index of the multi-phase component index to the actual component index
Definition: 1padapter.hh:83
static Scalar enthalpy(const FluidState &fluidState, int phaseIdx=0)
Given a phase's composition, temperature, pressure and density, calculate its specific enthalpy .
Definition: 1padapter.hh:192
MPFluidSystem MultiPhaseFluidSystem
export the wrapped MultiPhaseFluidSystem type
Definition: 1padapter.hh:70
static Scalar molarMass(int compIdx)
The mass in of one mole of the component.
Definition: 1padapter.hh:168
static std::string componentName(int compIdx)
A human readable name for the component.
Definition: 1padapter.hh:109
static std::string name()
A human readable name for the component.
Definition: 1padapter.hh:115
static constexpr bool viscosityIsConstant(int phaseIdx=0)
Returns true if the fluid viscosity is constant.
Definition: 1padapter.hh:156
static constexpr bool isGas(int phaseIdx=0)
Returns whether the fluid is gaseous.
Definition: 1padapter.hh:127
static constexpr bool isMiscible()
There is only one phase, so no mass transfer between phases can occur.
Definition: 1padapter.hh:121
static Scalar fugacityCoefficient(const FluidState &fluidState, int phaseIdx, int compIdx)
Calculate the fugacity coefficient of an individual component in a fluid phase.
Definition: 1padapter.hh:227
static constexpr bool isIdealMixture(int phaseIdx=0)
Returns true if and only if a fluid phase is assumed to be an ideal mixture.
Definition: 1padapter.hh:144
static constexpr bool isIdealGas(int phaseIdx=0)
Returns true if the fluid is assumed to be an ideal gas.
Definition: 1padapter.hh:162
static constexpr int numComponents
Definition: 1padapter.hh:78
static Scalar heatCapacity(const FluidState &fluidState, int phaseIdx=0)
Specific isobaric heat capacity of a fluid phase .
Definition: 1padapter.hh:275
static constexpr bool isCompressible(int phaseIdx=0)
Returns true if the fluid is assumed to be compressible.
Definition: 1padapter.hh:150
static Scalar diffusionCoefficient(const FluidState &fluidState, int phaseIdx, int compIdx)
Calculate the binary molecular diffusion coefficient for a component in a fluid phase .
Definition: 1padapter.hh:239
The a parameter cache which does nothing.
Definition: nullparametercache.hh:22
Fluid system base class.
Definition: h2o.hh:901
std::string viscosity(int phaseIdx) noexcept
I/O name of viscosity for multiphase systems.
Definition: name.hh:62
std::string molarDensity(int phaseIdx) noexcept
I/O name of molar density for multiphase systems.
Definition: name.hh:71
std::string density(int phaseIdx) noexcept
I/O name of density for multiphase systems.
Definition: name.hh:53