24#ifndef DUMUX_BRINE_CO2_FLUID_SYSTEM_HH
25#define DUMUX_BRINE_CO2_FLUID_SYSTEM_HH
29#include <dune/common/exceptions.hh>
54 template<
bool useConstantSalinity>
65 static constexpr int BrineIdx = 0;
76 static constexpr int H2OIdx = 0;
77 static constexpr int NaClIdx = 2;
78 static constexpr int comp2Idx = 2;
90template<
bool salinityIsConstant,
bool fastButSimplifiedRelations = false>
107template<
class Scalar,
110 class Policy = BrineCO2DefaultPolicy<
true> >
112:
public Base<Scalar, BrineCO2<Scalar, CO2Table, H2OType, Policy>>
122 static constexpr bool useConstantSalinity = Policy::useConstantSalinity();
127 using BrineType =
typename std::conditional_t< useConstantSalinity,
139 static constexpr int BrineOrH2OIdx = 0;
141 static constexpr int NaClIdx = 2;
167 struct BrineAdapterPolicy
171 static constexpr int phaseIdx(
int brinePhaseIdx) {
return liquidPhaseIdx; }
172 static constexpr int compIdx(
int brineCompIdx)
175 switch (brineCompIdx)
184 template<
class Flu
idState>
200 DUNE_THROW(Dune::InvalidStateException,
"Invalid phase index " << phaseIdx);
214 static constexpr bool isGas(
int phaseIdx)
216 assert(0 <= phaseIdx && phaseIdx <
numPhases);
228 assert(0 <= phaseIdx && phaseIdx <
numPhases);
252 assert(0 <= phaseIdx && phaseIdx <
numPhases);
269 assert(0 <= phaseIdx && phaseIdx <
numPhases);
283 if (useConstantSalinity)
286 return name[compIdx];
293 return name[compIdx];
304 if (useConstantSalinity)
325 init(273.15, 623.15, 100,
330 static void init(Scalar startTemp, Scalar endTemp,
int tempSteps,
331 Scalar startPressure, Scalar endPressure,
int pressureSteps)
333 std::cout <<
"The Brine-CO2 fluid system was configured with the following policy:\n";
334 std::cout <<
" - use constant salinity: " << std::boolalpha << Policy::useConstantSalinity() <<
"\n";
335 std::cout <<
" - use CO2 gas density as gas mixture density: " << std::boolalpha << Policy::useCO2GasDensityAsGasMixtureDensity() << std::endl;
337 if (H2O::isTabulated)
338 H2O::init(startTemp, endTemp, tempSteps, startPressure, endPressure, pressureSteps);
350 template <
class Flu
idState>
351 static Scalar
density(
const FluidState& fluidState,
int phaseIdx)
353 Scalar T = fluidState.temperature(phaseIdx);
355 return liquidDensityMixture_(fluidState);
359 if (Policy::useCO2GasDensityAsGasMixtureDensity())
361 return CO2::gasDensity(fluidState.temperature(phaseIdx), fluidState.pressure(phaseIdx));
365 Scalar rho_gH2O = H2O::gasDensity(T, fluidState.partialPressure(
gasPhaseIdx, BrineOrH2OIdx));
367 return (rho_gH2O + rho_gCO2);
371 DUNE_THROW(Dune::InvalidStateException,
"Invalid phase index.");
384 template <
class Flu
idState>
387 Scalar T = fluidState.temperature(phaseIdx);
389 return density(fluidState, phaseIdx)/fluidState.averageMolarMass(phaseIdx);
392 if (Policy::useCO2GasDensityAsGasMixtureDensity())
397 Scalar rhoMolar_gH2O = H2O::gasMolarDensity(T, fluidState.partialPressure(
gasPhaseIdx, BrineOrH2OIdx));
399 return rhoMolar_gH2O + rhoMolar_gCO2;
402 DUNE_THROW(Dune::InvalidStateException,
"Invalid phase index.");
416 template <
class Flu
idState>
417 static Scalar
viscosity(
const FluidState& fluidState,
int phaseIdx)
419 Scalar T = fluidState.temperature(phaseIdx);
420 Scalar p = fluidState.pressure(phaseIdx);
429 DUNE_THROW(Dune::InvalidStateException,
"Invalid phase index.");
459 template <
class Flu
idState>
474 Scalar T = fluidState.temperature(phaseIdx);
479 assert(pl > 0 && pg > 0);
491 xlCO2 = max(0.0, min(1.0, xlCO2));
492 xgH2O = max(0.0, min(1.0, xgH2O));
496 if (compIdx == BrineOrH2OIdx)
497 return (xgH2O/xlH2O)*(pg/pl);
499 else if (compIdx ==
CO2Idx)
500 return (xgCO2/xlCO2)*(pg/pl);
503 else if (!useConstantSalinity && compIdx == NaClIdx)
506 DUNE_THROW(Dune::InvalidStateException,
"Invalid component index.");
509 DUNE_THROW(Dune::InvalidStateException,
"Invalid phase index.");
519 template <
class Flu
idState>
524 Scalar T = fluidState.temperature(phaseIdx);
525 Scalar p = fluidState.pressure(phaseIdx);
543 DUNE_THROW(Dune::InvalidStateException,
"Invalid phase index.");
573 template <
class Flu
idState>
575 { DUNE_THROW(Dune::NotImplemented,
"Diffusion coefficients"); }
586 template <
class Flu
idState>
595 if (compIIdx > compJIdx)
598 swap(compIIdx, compJIdx);
601 Scalar T = fluidState.temperature(phaseIdx);
602 Scalar p = fluidState.pressure(phaseIdx);
605 if (compIIdx == BrineOrH2OIdx && compJIdx ==
CO2Idx)
607 if (!useConstantSalinity && compIIdx == BrineOrH2OIdx && compJIdx == NaClIdx)
613 DUNE_THROW(Dune::NotImplemented,
"Binary diffusion coefficient of components " <<
614 compIIdx <<
" and " << compJIdx <<
" in phase " << phaseIdx);
618 if (compIIdx == BrineOrH2OIdx && compJIdx ==
CO2Idx)
624 else if (!useConstantSalinity && compIIdx ==
CO2Idx && compJIdx == NaClIdx)
627 DUNE_THROW(Dune::NotImplemented,
"Binary diffusion coefficient of components " <<
628 compIIdx <<
" and " << compJIdx <<
" in phase " << phaseIdx);
631 DUNE_THROW(Dune::InvalidStateException,
"Invalid phase index.");
641 template <
class Flu
idState>
642 static Scalar
enthalpy(
const FluidState& fluidState,
int phaseIdx)
644 Scalar T = fluidState.temperature(phaseIdx);
645 Scalar p = fluidState.pressure(phaseIdx);
659 const Scalar delta_hCO2 = (-57.4375 + T * 0.1325) * 1000/44;
662 const Scalar hw = H2O::liquidEnthalpy(T, p)/1e3;
666 return (h_ls1 - X_CO2_w*hw + hg*X_CO2_w)*1e3;
671 return H2O::gasEnthalpy(T, p)*fluidState.massFraction(
gasPhaseIdx, BrineOrH2OIdx)
675 DUNE_THROW(Dune::InvalidStateException,
"Invalid phase index.");
684 template <
class Flu
idState>
687 const Scalar T = fluidState.temperature(phaseIdx);
688 const Scalar p = fluidState.pressure(phaseIdx);
692 if (componentIdx == BrineOrH2OIdx)
693 return H2O::liquidEnthalpy(T, p);
694 else if (componentIdx ==
CO2Idx)
696 else if (componentIdx == NaClIdx)
697 DUNE_THROW(Dune::NotImplemented,
"The component enthalpy for NaCl is not implemented.");
698 DUNE_THROW(Dune::InvalidStateException,
"Invalid component index " << componentIdx);
702 if (componentIdx == BrineOrH2OIdx)
703 return H2O::gasEnthalpy(T, p);
704 else if (componentIdx ==
CO2Idx)
706 else if (componentIdx == NaClIdx)
707 DUNE_THROW(Dune::InvalidStateException,
"Implementation assumes NaCl not to be present in gas phase");
708 DUNE_THROW(Dune::InvalidStateException,
"Invalid component index " << componentIdx);
710 DUNE_THROW(Dune::InvalidStateException,
"Invalid phase index " << phaseIdx);
723 template <
class Flu
idState>
728 fluidState.pressure(phaseIdx) )
734 DUNE_THROW(Dune::InvalidStateException,
"Invalid phase index.");
748 template <
class Flu
idState>
754 fluidState.pressure(phaseIdx) )
759 fluidState.pressure(phaseIdx));
761 DUNE_THROW(Dune::InvalidStateException,
"Invalid phase index.");
772 template<
class Flu
idState>
773 static Scalar liquidDensityMixture_(
const FluidState& fluidState)
780 "defined above 273.15K (T = " << T <<
")");
784 "defined below 250MPa (p = " << p <<
")");
787 Scalar rho_pure = H2O::liquidDensity(T, p);
791 if (useConstantSalinity)
798 Scalar xlBrine = min(1.0, max(0.0, fluidState.moleFraction(
liquidPhaseIdx, BrineOrH2OIdx)));
800 Scalar sumx = xlBrine + xlCO2;
804 rho_lCO2 = liquidDensityWaterCO2_(T, p, xlBrine, xlCO2);
809 auto xlH2O = fluidState.moleFraction(
liquidPhaseIdx, BrineOrH2OIdx);
811 const auto sumMoleFrac = xlH2O + xlCO2;
812 xlH2O = xlH2O/sumMoleFrac;
813 xlCO2 = xlCO2/sumMoleFrac;
814 rho_lCO2 = liquidDensityWaterCO2_(T, p, xlH2O, xlCO2);
819 : VariableSalinityBrine::
density( BrineAdapter<FluidState>(fluidState),
823 Scalar contribCO2 = rho_lCO2 - rho_pure;
827 return rho_brine + contribCO2;
841 static Scalar liquidDensityWaterCO2_(Scalar
temperature,
847 const Scalar M_H2O = H2O::molarMass();
850 const Scalar rho_pure = H2O::liquidDensity(
temperature, pl);
855 const Scalar M_T = M_H2O * xlH2O + M_CO2 * xlCO2;
856 const Scalar V_phi = (37.51 +
859 tempC*5.044e-7))) / 1.0e6;
860 return 1/(xlCO2 * V_phi/M_T + M_H2O * xlH2O / (rho_pure * M_T));
The infrastructure to retrieve run-time parameters from Dune::ParameterTrees.
A collection of input/output field names for common physical quantities.
Binary coefficients for CO2 and brine.
A class for the CO2 fluid properties.
Tabulates all thermodynamic properties of a given untabulated chemical species.
Adapter class for fluid states with different indices.
Relations valid for an ideal gas.
std::string temperature() noexcept
I/O name of temperature for equilibrium models.
Definition: name.hh:51
std::string gaseousPhase() noexcept
I/O name of gaseous phase.
Definition: name.hh:123
std::string liquidPhase() noexcept
I/O name of liquid phase.
Definition: name.hh:119
Exception thrown if a fixable numerical problem occurs.
Definition: exceptions.hh:39
Binary coefficients for brine and CO2.
Definition: brine_co2.hh:42
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:113
static Scalar liquidDiffCoeff(Scalar temperature, Scalar pressure)
Binary diffusion coefficient of CO2 in the brine phase.
Definition: brine_co2.hh:83
static Scalar gasDiffCoeff(Scalar temperature, Scalar pressure)
Binary diffusion coefficient of water in the CO2 phase.
Definition: brine_co2.hh:57
A class for the brine fluid properties.
Definition: components/brine.hh:56
static Scalar liquidViscosity(Scalar temperature, Scalar pressure)
The dynamic viscosity of pure brine.
Definition: components/brine.hh:419
static const Scalar liquidEnthalpy(Scalar T, Scalar p)
Specific enthalpy of liquid brine .
Definition: components/brine.hh:161
static Scalar molarMass()
The molar mass in of brine. This assumes that the salt is pure NaCl.
Definition: components/brine.hh:83
static Scalar salinity()
Return the constant salinity.
Definition: components/brine.hh:73
static Scalar liquidThermalConductivity(Scalar temperature, Scalar pressure)
Thermal conductivity of a brine .
Definition: components/brine.hh:443
static const Scalar liquidHeatCapacity(Scalar temperature, Scalar pressure)
Specific isobaric heat capacity of brine .
Definition: components/brine.hh:220
static constexpr bool liquidIsCompressible()
Returns true if the liquid phase is assumed to be compressible.
Definition: components/brine.hh:303
static std::string name()
A human readable name for the brine.
Definition: components/brine.hh:67
static constexpr bool gasIsIdeal()
Returns true if the gas phase is assumed to be ideal.
Definition: components/brine.hh:291
static Scalar liquidDensity(Scalar temperature, Scalar pressure)
The density of pure brine at a given pressure and temperature .
Definition: components/brine.hh:318
A class for the CO2 fluid properties.
Definition: co2.hh:57
static Scalar gasThermalConductivity(Scalar temperature, Scalar pressure)
Thermal conductivity of CO2.
Definition: co2.hh:399
static Scalar liquidEnthalpy(Scalar temperature, Scalar pressure)
Specific enthalpy of liquid CO2 .
Definition: co2.hh:180
static constexpr Scalar molarMass()
The mass in of one mole of CO2.
Definition: co2.hh:72
static Scalar gasMolarDensity(Scalar temperature, Scalar pressure)
The molar density of CO2 gas in at a given pressure and temperature.
Definition: co2.hh:244
static Scalar gasDensity(Scalar temperature, Scalar pressure)
The density of CO2 at a given pressure and temperature .
Definition: co2.hh:226
static constexpr bool gasIsIdeal()
Returns true if the gas phase is assumed to be ideal.
Definition: co2.hh:126
static std::string name()
A human readable name for the CO2.
Definition: co2.hh:66
static Scalar gasViscosity(Scalar temperature, Scalar pressure)
The dynamic viscosity of CO2. Equations given in: - Vesovic et al., 1990.
Definition: co2.hh:327
static Scalar liquidHeatCapacity(Scalar temperature, Scalar pressure)
Specific isobaric heat capacity of the component as a liquid. USE WITH CAUTION! Exploits enthalpy fu...
Definition: co2.hh:304
static Scalar gasEnthalpy(Scalar temperature, Scalar pressure)
Specific enthalpy of gaseous CO2 .
Definition: co2.hh:162
static std::string name()
A human readable name for the NaCl.
Definition: nacl.hh:52
Tabulates all thermodynamic properties of a given untabulated chemical species.
Definition: tabulatedcomponent.hh:82
Adapter class for fluid states with different indices.
Definition: adapter.hh:44
Fluid system base class.
Definition: fluidsystems/base.hh:45
static Scalar density(const FluidState &fluidState, int phaseIdx)
Calculate the density of a fluid phase.
Definition: fluidsystems/base.hh:134
static Scalar thermalConductivity(const FluidState &fluidState, int phaseIdx)
Thermal conductivity of a fluid phase .
Definition: fluidsystems/base.hh:390
static Scalar fugacityCoefficient(const FluidState &fluidState, int phaseIdx, int compIdx)
Calculate the fugacity coefficient of an individual component in a fluid phase.
Definition: fluidsystems/base.hh:197
static Scalar diffusionCoefficient(const FluidState &fluidState, int phaseIdx, int compIdx)
Calculate the binary molecular diffusion coefficient for a component in a fluid phase .
Definition: fluidsystems/base.hh:278
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/base.hh:326
static Scalar enthalpy(const FluidState &fluidState, int phaseIdx)
Given a phase's composition, temperature, pressure and density, calculate its specific enthalpy .
Definition: fluidsystems/base.hh:363
static Scalar molarDensity(const FluidState &fluidState, int phaseIdx)
Calculate the molar density of a fluid phase.
Definition: fluidsystems/base.hh:160
static Scalar viscosity(const FluidState &fluidState, int phaseIdx)
Calculate the dynamic viscosity of a fluid phase .
Definition: fluidsystems/base.hh:236
static Scalar heatCapacity(const FluidState &fluidState, int phaseIdx)
Specific isobaric heat capacity of a fluid phase .
Definition: fluidsystems/base.hh:424
A compositional single phase fluid system consisting of two components, which are H2O and NaCl.
Definition: fluidsystems/brine.hh:47
static Scalar thermalConductivity(const FluidState &fluidState, int phaseIdx)
Thermal conductivity of a fluid phase .
Definition: fluidsystems/brine.hh:462
static Scalar viscosity(const FluidState &fluidState, int phaseIdx=liquidPhaseIdx)
Return the viscosity of the phase.
Definition: fluidsystems/brine.hh:292
static constexpr int H2OIdx
index of the water component
Definition: fluidsystems/brine.hh:62
static Scalar heatCapacity(const FluidState &fluidState, int phaseIdx)
Specific isobaric heat capacity of a fluid phase. .
Definition: fluidsystems/brine.hh:484
static Scalar molarMass(int compIdx)
Return the molar mass of a component in .
Definition: fluidsystems/brine.hh:166
static Scalar enthalpy(const FluidState &fluidState, int phaseIdx)
Given a phase's composition, temperature and pressure, return its specific enthalpy .
Definition: fluidsystems/brine.hh:352
static constexpr int NaClIdx
index of the NaCl component
Definition: fluidsystems/brine.hh:63
static constexpr int liquidPhaseIdx
The one considered phase is liquid.
Definition: fluidsystems/brine.hh:60
static bool isCompressible(int phaseIdx=liquidPhaseIdx)
Returns true if and only if a fluid phase is assumed to be compressible.
Definition: fluidsystems/brine.hh:125
static std::string componentName(int compIdx)
Return the human readable name of a component.
Definition: fluidsystems/brine.hh:152
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:429
Class that exports some indices that should be provided by the BrineAir fluid system....
Definition: brineco2.hh:55
Default policy for the Brine-CO2 fluid system.
Definition: brineco2.hh:92
static constexpr bool useCO2GasDensityAsGasMixtureDensity()
Definition: brineco2.hh:94
static constexpr bool useConstantSalinity()
Definition: brineco2.hh:93
A compositional fluid with brine (H2O & NaCl) and carbon dioxide as components in both the liquid and...
Definition: brineco2.hh:114
static constexpr int CO2Idx
Definition: brineco2.hh:162
static constexpr int numComponents
Definition: brineco2.hh:150
static Scalar enthalpy(const FluidState &fluidState, int phaseIdx)
Given the phase composition, return the specific phase enthalpy .
Definition: brineco2.hh:642
static constexpr bool isCompressible(int phaseIdx)
Returns true if and only if a fluid phase is assumed to be compressible.
Definition: brineco2.hh:267
static constexpr int phase0Idx
index of the first phase
Definition: brineco2.hh:155
static constexpr int comp0Idx
Definition: brineco2.hh:158
H2OType H2O
Definition: brineco2.hh:146
static Scalar molarMass(int compIdx)
Return the molar mass of a component in .
Definition: brineco2.hh:301
static constexpr int numPhases
Definition: brineco2.hh:151
static Scalar heatCapacity(const FluidState &fluidState, int phaseIdx)
Specific isobaric heat capacity of a fluid phase .
Definition: brineco2.hh:749
static std::string componentName(int compIdx)
Return the human readable name of a component.
Definition: brineco2.hh:280
static Scalar binaryDiffusionCoefficient(const FluidState &fluidState, int phaseIdx, int compIIdx, int compJIdx)
Given the phase compositions, return the binary diffusion coefficient of two components in a phase.
Definition: brineco2.hh:587
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:351
static Scalar viscosity(const FluidState &fluidState, int phaseIdx)
Calculate the dynamic viscosity of a fluid phase .
Definition: brineco2.hh:417
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:574
static void init()
Definition: brineco2.hh:323
static constexpr bool isGas(int phaseIdx)
Return whether a phase is gaseous.
Definition: brineco2.hh:214
static constexpr int phase1Idx
index of the second phase
Definition: brineco2.hh:156
static constexpr int gasPhaseIdx
index of the gas phase
Definition: brineco2.hh:154
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:226
static std::string phaseName(int phaseIdx)
Return the human readable name of a fluid phase.
Definition: brineco2.hh:193
static Scalar thermalConductivity(const FluidState &fluidState, int phaseIdx)
Thermal conductivity of a fluid phase .
Definition: brineco2.hh:724
static constexpr int liquidPhaseIdx
index of the liquid phase
Definition: brineco2.hh:153
static Scalar fugacityCoefficient(const FluidState &fluidState, int phaseIdx, int compIdx)
Returns the fugacity coefficient of a component in a phase.
Definition: brineco2.hh:460
static constexpr bool isMiscible()
Returns whether the fluids are miscible.
Definition: brineco2.hh:206
BrineType Brine
Definition: brineco2.hh:147
static void init(Scalar startTemp, Scalar endTemp, int tempSteps, Scalar startPressure, Scalar endPressure, int pressureSteps)
Definition: brineco2.hh:330
static constexpr int comp1Idx
Definition: brineco2.hh:159
static Scalar componentEnthalpy(const FluidState &fluidState, int phaseIdx, int componentIdx)
Returns the specific enthalpy of a component in a specific phase.
Definition: brineco2.hh:685
static bool isIdealMixture(int phaseIdx)
Returns true if and only if a fluid phase is assumed to be an ideal mixture.
Definition: brineco2.hh:250
static Scalar equilibriumMoleFraction(const FluidState &fluidState, const ParameterCache ¶mCache, int phaseIdx)
Returns the equilibrium concentration of the dissolved component in a phase.
Definition: brineco2.hh:520
static Scalar molarDensity(const FluidState &fluidState, int phaseIdx)
The molar density of a fluid phase in .
Definition: brineco2.hh:385
The a parameter cache which does nothing.
Definition: nullparametercache.hh:34
A class for the brine fluid properties,.
A fluid system for brine, i.e. H2O with dissolved NaCl.