12#ifndef DUMUX_BRINE_CO2_FLUID_SYSTEM_HH
13#define DUMUX_BRINE_CO2_FLUID_SYSTEM_HH
17#include <dune/common/exceptions.hh>
42 template<
bool useConstantSalinity>
53 static constexpr int BrineIdx = 0;
64 static constexpr int H2OIdx = 0;
65 static constexpr int NaClIdx = 2;
66 static constexpr int comp2Idx = 2;
78template<
bool salinityIsConstant,
bool fastButSimplifiedRelations = false>
95template<
class Scalar,
98 class Policy = BrineCO2DefaultPolicy<
true> >
100:
public Base<Scalar, BrineCO2<Scalar, CO2Component, H2OType, Policy>>
108 static constexpr bool useConstantSalinity = Policy::useConstantSalinity();
113 using BrineType =
typename std::conditional_t< useConstantSalinity,
125 static constexpr int BrineOrH2OIdx = 0;
127 static constexpr int NaClIdx = 2;
153 struct BrineAdapterPolicy
157 static constexpr int phaseIdx(
int brinePhaseIdx) {
return liquidPhaseIdx; }
158 static constexpr int compIdx(
int brineCompIdx)
161 switch (brineCompIdx)
170 template<
class Flu
idState>
186 DUNE_THROW(Dune::InvalidStateException,
"Invalid phase index " << phaseIdx);
200 static constexpr bool isGas(
int phaseIdx)
202 assert(0 <= phaseIdx && phaseIdx <
numPhases);
214 assert(0 <= phaseIdx && phaseIdx <
numPhases);
218 : (H2O::gasIsIdeal() && CO2::gasIsIdeal());
238 assert(0 <= phaseIdx && phaseIdx <
numPhases);
255 assert(0 <= phaseIdx && phaseIdx <
numPhases);
269 if (useConstantSalinity)
272 return name[compIdx];
279 return name[compIdx];
290 if (useConstantSalinity)
311 init(273.15, 623.15, 100,
316 static void init(Scalar startTemp, Scalar endTemp,
int tempSteps,
317 Scalar startPressure, Scalar endPressure,
int pressureSteps)
319 std::cout <<
"The Brine-CO2 fluid system was configured with the following policy:\n";
320 std::cout <<
" - use constant salinity: " << std::boolalpha << Policy::useConstantSalinity() <<
"\n";
321 std::cout <<
" - use CO2 gas density as gas mixture density: " << std::boolalpha << Policy::useCO2GasDensityAsGasMixtureDensity() << std::endl;
323 if (H2O::isTabulated)
324 H2O::init(startTemp, endTemp, tempSteps, startPressure, endPressure, pressureSteps);
336 template <
class Flu
idState>
337 static Scalar
density(
const FluidState& fluidState,
int phaseIdx)
339 Scalar T = fluidState.temperature(phaseIdx);
341 return liquidDensityMixture_(fluidState);
345 if (Policy::useCO2GasDensityAsGasMixtureDensity())
347 return CO2::gasDensity(fluidState.temperature(phaseIdx), fluidState.pressure(phaseIdx));
351 Scalar rho_gH2O = H2O::gasDensity(T, fluidState.partialPressure(
gasPhaseIdx, BrineOrH2OIdx));
352 Scalar rho_gCO2 = CO2::gasDensity(T, fluidState.partialPressure(
gasPhaseIdx,
CO2Idx));
353 return (rho_gH2O + rho_gCO2);
357 DUNE_THROW(Dune::InvalidStateException,
"Invalid phase index.");
362 template <
class Flu
idState>
365 Scalar T = fluidState.temperature(phaseIdx);
367 return density(fluidState, phaseIdx)/fluidState.averageMolarMass(phaseIdx);
370 if (Policy::useCO2GasDensityAsGasMixtureDensity())
371 return CO2::gasMolarDensity(fluidState.temperature(phaseIdx), fluidState.pressure(phaseIdx));
375 Scalar rhoMolar_gH2O = H2O::gasMolarDensity(T, fluidState.partialPressure(
gasPhaseIdx, BrineOrH2OIdx));
376 Scalar rhoMolar_gCO2 = CO2::gasMolarDensity(T, fluidState.partialPressure(
gasPhaseIdx,
CO2Idx));
377 return rhoMolar_gH2O + rhoMolar_gCO2;
380 DUNE_THROW(Dune::InvalidStateException,
"Invalid phase index.");
394 template <
class Flu
idState>
395 static Scalar
viscosity(
const FluidState& fluidState,
int phaseIdx)
397 Scalar T = fluidState.temperature(phaseIdx);
398 Scalar p = fluidState.pressure(phaseIdx);
405 return CO2::gasViscosity(T, p);
407 DUNE_THROW(Dune::InvalidStateException,
"Invalid phase index.");
412 template <
class Flu
idState>
427 Scalar T = fluidState.temperature(phaseIdx);
432 assert(pl > 0 && pg > 0);
444 xlCO2 = max(0.0, min(1.0, xlCO2));
445 xgH2O = max(0.0, min(1.0, xgH2O));
449 if (compIdx == BrineOrH2OIdx)
450 return (xgH2O/xlH2O)*(pg/pl);
452 else if (compIdx ==
CO2Idx)
453 return (xgCO2/xlCO2)*(pg/pl);
456 else if (!useConstantSalinity && compIdx == NaClIdx)
459 DUNE_THROW(Dune::InvalidStateException,
"Invalid component index.");
462 DUNE_THROW(Dune::InvalidStateException,
"Invalid phase index.");
471 template <
class Flu
idState>
476 Scalar T = fluidState.temperature(phaseIdx);
477 Scalar p = fluidState.pressure(phaseIdx);
495 DUNE_THROW(Dune::InvalidStateException,
"Invalid phase index.");
525 template <
class Flu
idState>
527 { DUNE_THROW(Dune::NotImplemented,
"Diffusion coefficients"); }
531 template <
class Flu
idState>
540 if (compIIdx > compJIdx)
543 swap(compIIdx, compJIdx);
546 Scalar T = fluidState.temperature(phaseIdx);
547 Scalar p = fluidState.pressure(phaseIdx);
550 if (compIIdx == BrineOrH2OIdx && compJIdx ==
CO2Idx)
552 if (!useConstantSalinity && compIIdx == BrineOrH2OIdx && compJIdx == NaClIdx)
558 DUNE_THROW(Dune::NotImplemented,
"Binary diffusion coefficient of components " <<
559 compIIdx <<
" and " << compJIdx <<
" in phase " << phaseIdx);
563 if (compIIdx == BrineOrH2OIdx && compJIdx ==
CO2Idx)
569 else if (!useConstantSalinity && compIIdx ==
CO2Idx && compJIdx == NaClIdx)
572 DUNE_THROW(Dune::NotImplemented,
"Binary diffusion coefficient of components " <<
573 compIIdx <<
" and " << compJIdx <<
" in phase " << phaseIdx);
576 DUNE_THROW(Dune::InvalidStateException,
"Invalid phase index.");
581 template <
class Flu
idState>
582 static Scalar
enthalpy(
const FluidState& fluidState,
int phaseIdx)
584 Scalar T = fluidState.temperature(phaseIdx);
585 Scalar p = fluidState.pressure(phaseIdx);
599 const Scalar delta_hCO2 = (-57.4375 + T * 0.1325) * 1000/44;
602 const Scalar hw = H2O::liquidEnthalpy(T, p)/1e3;
603 const Scalar hg = CO2::liquidEnthalpy(T, p)/1e3 + delta_hCO2;
606 return (h_ls1 - X_CO2_w*hw + hg*X_CO2_w)*1e3;
611 return H2O::gasEnthalpy(T, p)*fluidState.massFraction(
gasPhaseIdx, BrineOrH2OIdx)
615 DUNE_THROW(Dune::InvalidStateException,
"Invalid phase index.");
624 template <
class Flu
idState>
627 const Scalar T = fluidState.temperature(phaseIdx);
628 const Scalar p = fluidState.pressure(phaseIdx);
632 if (componentIdx == BrineOrH2OIdx)
633 return H2O::liquidEnthalpy(T, p);
634 else if (componentIdx ==
CO2Idx)
635 return CO2::liquidEnthalpy(T, p);
636 else if (componentIdx == NaClIdx)
637 DUNE_THROW(Dune::NotImplemented,
"The component enthalpy for NaCl is not implemented.");
638 DUNE_THROW(Dune::InvalidStateException,
"Invalid component index " << componentIdx);
642 if (componentIdx == BrineOrH2OIdx)
643 return H2O::gasEnthalpy(T, p);
644 else if (componentIdx ==
CO2Idx)
645 return CO2::gasEnthalpy(T, p);
646 else if (componentIdx == NaClIdx)
647 DUNE_THROW(Dune::InvalidStateException,
"Implementation assumes NaCl not to be present in gas phase");
648 DUNE_THROW(Dune::InvalidStateException,
"Invalid component index " << componentIdx);
650 DUNE_THROW(Dune::InvalidStateException,
"Invalid phase index " << phaseIdx);
663 template <
class Flu
idState>
668 fluidState.pressure(phaseIdx) )
672 return CO2::gasThermalConductivity(fluidState.temperature(phaseIdx), fluidState.pressure(phaseIdx));
674 DUNE_THROW(Dune::InvalidStateException,
"Invalid phase index.");
688 template <
class Flu
idState>
694 fluidState.pressure(phaseIdx) )
698 return CO2::liquidHeatCapacity(fluidState.temperature(phaseIdx),
699 fluidState.pressure(phaseIdx));
701 DUNE_THROW(Dune::InvalidStateException,
"Invalid phase index.");
712 template<
class Flu
idState>
713 static Scalar liquidDensityMixture_(
const FluidState& fluidState)
720 "defined above 273.15K (T = " << T <<
")");
724 "defined below 250MPa (p = " << p <<
")");
727 Scalar rho_pure = H2O::liquidDensity(T, p);
731 if (useConstantSalinity)
738 Scalar xlBrine = min(1.0, max(0.0, fluidState.moleFraction(
liquidPhaseIdx, BrineOrH2OIdx)));
740 Scalar sumx = xlBrine + xlCO2;
744 rho_lCO2 = liquidDensityWaterCO2_(T, p, xlBrine, xlCO2);
749 auto xlH2O = fluidState.moleFraction(
liquidPhaseIdx, BrineOrH2OIdx);
751 const auto sumMoleFrac = xlH2O + xlCO2;
752 xlH2O = xlH2O/sumMoleFrac;
753 xlCO2 = xlCO2/sumMoleFrac;
754 rho_lCO2 = liquidDensityWaterCO2_(T, p, xlH2O, xlCO2);
759 : VariableSalinityBrine::
density( BrineAdapter<FluidState>(fluidState),
763 Scalar contribCO2 = rho_lCO2 - rho_pure;
767 return rho_brine + contribCO2;
781 static Scalar liquidDensityWaterCO2_(Scalar
temperature,
786 const Scalar M_CO2 = CO2::molarMass();
787 const Scalar M_H2O = H2O::molarMass();
790 const Scalar rho_pure = H2O::liquidDensity(
temperature, pl);
795 const Scalar M_T = M_H2O * xlH2O + M_CO2 * xlCO2;
796 const Scalar V_phi = (37.51 +
799 tempC*5.044e-7))) / 1.0e6;
800 return 1/(xlCO2 * V_phi/M_T + M_H2O * xlH2O / (rho_pure * M_T));
Adapter class for fluid states with different indices.
Binary coefficients for CO2 and brine.
Binary coefficients for brine and CO2.
Definition: brine_co2.hh:32
static void calculateMoleFractions(const Scalar temperature, const Scalar pg, const Scalar salinity, const int knownPhaseIdx, Scalar &xlCO2, Scalar &ygH2O)
Returns the mol (!) fraction of CO2 in the liquid phase and the mol (!) fraction of H2O in the gas ph...
Definition: brine_co2.hh:102
static Scalar liquidDiffCoeff(Scalar temperature, Scalar pressure)
Binary diffusion coefficient of CO2 in the brine phase.
Definition: brine_co2.hh:72
static Scalar gasDiffCoeff(Scalar temperature, Scalar pressure)
Binary diffusion coefficient of water in the CO2 phase.
Definition: brine_co2.hh:46
A class for the brine fluid properties.
Definition: components/brine.hh:44
static Scalar liquidViscosity(Scalar temperature, Scalar pressure)
The dynamic viscosity of pure brine.
Definition: components/brine.hh:407
static const Scalar liquidEnthalpy(Scalar T, Scalar p)
Specific enthalpy of liquid brine .
Definition: components/brine.hh:149
static Scalar molarMass()
The molar mass in of brine. This assumes that the salt is pure NaCl.
Definition: components/brine.hh:71
static Scalar salinity()
Return the constant salinity.
Definition: components/brine.hh:61
static Scalar liquidThermalConductivity(Scalar temperature, Scalar pressure)
Thermal conductivity of a brine .
Definition: components/brine.hh:431
static const Scalar liquidHeatCapacity(Scalar temperature, Scalar pressure)
Specific isobaric heat capacity of brine .
Definition: components/brine.hh:208
static constexpr bool liquidIsCompressible()
Returns true if the liquid phase is assumed to be compressible.
Definition: components/brine.hh:291
static std::string name()
A human readable name for the brine.
Definition: components/brine.hh:55
static constexpr bool gasIsIdeal()
Returns true if the gas phase is assumed to be ideal.
Definition: components/brine.hh:279
static Scalar liquidDensity(Scalar temperature, Scalar pressure)
The density of pure brine at a given pressure and temperature .
Definition: components/brine.hh:306
static std::string name()
A human readable name for the NaCl.
Definition: nacl.hh:40
Tabulates all thermodynamic properties of a given component.
Definition: tabulatedcomponent.hh:672
Adapter class for fluid states with different indices.
Definition: adapter.hh:32
Fluid system base class.
Definition: fluidsystems/base.hh:33
A compositional fluid with brine (H2O & NaCl) and carbon dioxide as components in both the liquid and...
Definition: brineco2.hh:102
static Scalar viscosity(const FluidState &fluidState, int phaseIdx)
Calculate the dynamic viscosity of a fluid phase .
Definition: brineco2.hh:395
static constexpr int comp1Idx
Definition: brineco2.hh:145
static constexpr int liquidPhaseIdx
index of the liquid phase
Definition: brineco2.hh:139
CO2Component CO2
Definition: brineco2.hh:134
static constexpr int phase1Idx
index of the second phase
Definition: brineco2.hh:142
static Scalar equilibriumMoleFraction(const FluidState &fluidState, const ParameterCache ¶mCache, int phaseIdx)
Returns the equilibrium mole fraction of the dissolved component in a phase.
Definition: brineco2.hh:472
static constexpr int numComponents
Definition: brineco2.hh:136
static Scalar thermalConductivity(const FluidState &fluidState, int phaseIdx)
Thermal conductivity of a fluid phase .
Definition: brineco2.hh:664
static Scalar heatCapacity(const FluidState &fluidState, int phaseIdx)
Specific isobaric heat capacity of a fluid phase .
Definition: brineco2.hh:689
static void init(Scalar startTemp, Scalar endTemp, int tempSteps, Scalar startPressure, Scalar endPressure, int pressureSteps)
Definition: brineco2.hh:316
static constexpr bool isMiscible()
Returns whether the fluids are miscible.
Definition: brineco2.hh:192
static Scalar enthalpy(const FluidState &fluidState, int phaseIdx)
Definition: brineco2.hh:582
H2OType H2O
Definition: brineco2.hh:132
static Scalar componentEnthalpy(const FluidState &fluidState, int phaseIdx, int componentIdx)
Returns the specific enthalpy of a component in a specific phase.
Definition: brineco2.hh:625
static constexpr bool isGas(int phaseIdx)
Return whether a phase is gaseous.
Definition: brineco2.hh:200
static Scalar density(const FluidState &fluidState, int phaseIdx)
Given a phase's composition, temperature, pressure, and the partial pressures of all components,...
Definition: brineco2.hh:337
static constexpr bool isCompressible(int phaseIdx)
Returns true if and only if a fluid phase is assumed to be compressible.
Definition: brineco2.hh:253
static void init()
Definition: brineco2.hh:309
static constexpr int CO2Idx
Definition: brineco2.hh:148
static std::string phaseName(int phaseIdx)
Return the human readable name of a fluid phase.
Definition: brineco2.hh:179
static Scalar binaryDiffusionCoefficient(const FluidState &fluidState, int phaseIdx, int compIIdx, int compJIdx)
Definition: brineco2.hh:532
static constexpr bool isIdealGas(int phaseIdx)
Returns true if and only if a fluid phase is assumed to be an ideal gas.
Definition: brineco2.hh:212
static std::string componentName(int compIdx)
Return the human readable name of a component.
Definition: brineco2.hh:266
static bool isIdealMixture(int phaseIdx)
Returns true if and only if a fluid phase is assumed to be an ideal mixture.
Definition: brineco2.hh:236
static Scalar fugacityCoefficient(const FluidState &fluidState, int phaseIdx, int compIdx)
Calculate the fugacity coefficient of an individual component in a fluid phase.
Definition: brineco2.hh:413
static constexpr int comp0Idx
Definition: brineco2.hh:144
static Scalar molarMass(int compIdx)
Return the molar mass of a component in .
Definition: brineco2.hh:287
static constexpr int numPhases
Definition: brineco2.hh:137
BrineType Brine
Definition: brineco2.hh:133
static Scalar diffusionCoefficient(const FluidState &fluidState, int phaseIdx, int compIdx)
Calculate the molecular diffusion coefficient for a component in a fluid phase .
Definition: brineco2.hh:526
static Scalar molarDensity(const FluidState &fluidState, int phaseIdx)
Calculate the molar density of a fluid phase.
Definition: brineco2.hh:363
static constexpr int phase0Idx
index of the first phase
Definition: brineco2.hh:141
static constexpr int gasPhaseIdx
index of the gas phase
Definition: brineco2.hh:140
A compositional single phase fluid system consisting of two components, which are H2O and NaCl.
Definition: fluidsystems/brine.hh:35
static Scalar thermalConductivity(const FluidState &fluidState, int phaseIdx)
Thermal conductivity of a fluid phase .
Definition: fluidsystems/brine.hh:435
static Scalar viscosity(const FluidState &fluidState, int phaseIdx=liquidPhaseIdx)
Return the viscosity of the phase.
Definition: fluidsystems/brine.hh:276
static constexpr int H2OIdx
index of the water component
Definition: fluidsystems/brine.hh:49
static Scalar heatCapacity(const FluidState &fluidState, int phaseIdx)
Specific isobaric heat capacity of a fluid phase .
Definition: fluidsystems/brine.hh:451
static Scalar molarMass(int compIdx)
Return the molar mass of a component in .
Definition: fluidsystems/brine.hh:153
static Scalar enthalpy(const FluidState &fluidState, int phaseIdx)
Given a phase's composition, temperature and pressure, return its specific enthalpy .
Definition: fluidsystems/brine.hh:336
static constexpr int NaClIdx
index of the NaCl component
Definition: fluidsystems/brine.hh:50
static constexpr int liquidPhaseIdx
The one considered phase is liquid.
Definition: fluidsystems/brine.hh:47
static bool isCompressible(int phaseIdx=liquidPhaseIdx)
Returns true if and only if a fluid phase is assumed to be compressible.
Definition: fluidsystems/brine.hh:112
static std::string componentName(int compIdx)
Return the human readable name of a component.
Definition: fluidsystems/brine.hh:139
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: fluidsystems/brine.hh:402
The a parameter cache which does nothing.
Definition: nullparametercache.hh:22
Exception thrown if a fixable numerical problem occurs.
Definition: exceptions.hh:27
A class for the CO2 fluid properties.
A class for the brine fluid properties,.
A fluid system for brine, i.e. H2O with dissolved NaCl.
Relations valid for an ideal gas.
A collection of input/output field names for common physical quantities.
std::string temperature() noexcept
I/O name of temperature for equilibrium models.
Definition: name.hh:39
std::string gaseousPhase() noexcept
I/O name of gaseous phase.
Definition: name.hh:111
std::string liquidPhase() noexcept
I/O name of liquid phase.
Definition: name.hh:107
The infrastructure to retrieve run-time parameters from Dune::ParameterTrees.
Default policy for the Brine-CO2 fluid system.
Definition: brineco2.hh:80
static constexpr bool useCO2GasDensityAsGasMixtureDensity()
Definition: brineco2.hh:82
static constexpr bool useConstantSalinity()
Definition: brineco2.hh:81
Class that exports some indices that should be provided by the BrineCO2 fluid system....
Definition: brineco2.hh:43
Tabulates all thermodynamic properties of a given untabulated chemical species.