24#ifndef DUMUX_BRINE_CO2_FLUID_SYSTEM_HH
25#define DUMUX_BRINE_CO2_FLUID_SYSTEM_HH
29#include <dune/common/exceptions.hh>
50#include <dumux/material/components/co2tables.inc>
53namespace FluidSystems {
63 template<
bool useConstantSalinity>
74 static constexpr int BrineIdx = 0;
85 static constexpr int H2OIdx = 0;
86 static constexpr int NaClIdx = 2;
87 static constexpr int comp2Idx = 2;
95template<
bool salinityIsConstant,
bool fastButSimplifiedRelations = false>
112template<
class Scalar,
115 class Policy = BrineCO2DefaultPolicy<
true> >
117:
public Base<Scalar, BrineCO2<Scalar, CO2Table, H2OType, Policy>>
127 static constexpr bool useConstantSalinity = Policy::useConstantSalinity();
132 using BrineType =
typename std::conditional_t< useConstantSalinity,
144 static constexpr int BrineOrH2OIdx = 0;
146 static constexpr int NaClIdx = 2;
172 struct BrineAdapterPolicy
176 static constexpr int phaseIdx(
int brinePhaseIdx) {
return liquidPhaseIdx; }
177 static constexpr int compIdx(
int brineCompIdx)
179 switch (brineCompIdx)
189 template<
class Flu
idState>
205 DUNE_THROW(Dune::InvalidStateException,
"Invalid phase index " << phaseIdx);
219 static constexpr bool isGas(
int phaseIdx)
221 assert(0 <= phaseIdx && phaseIdx <
numPhases);
233 assert(0 <= phaseIdx && phaseIdx <
numPhases);
257 assert(0 <= phaseIdx && phaseIdx <
numPhases);
274 assert(0 <= phaseIdx && phaseIdx <
numPhases);
288 if (useConstantSalinity)
291 return name[compIdx];
298 return name[compIdx];
309 if (useConstantSalinity)
330 init(273.15, 623.15, 100,
335 static void init(Scalar startTemp, Scalar endTemp,
int tempSteps,
336 Scalar startPressure, Scalar endPressure,
int pressureSteps)
338 std::cout <<
"The Brine-CO2 fluid system was configured with the following policy:\n";
339 std::cout <<
" - use constant salinity: " << std::boolalpha << Policy::useConstantSalinity() <<
"\n";
340 std::cout <<
" - use CO2 gas density as gas mixture density: " << std::boolalpha << Policy::useCO2GasDensityAsGasMixtureDensity() << std::endl;
342 if (H2O::isTabulated)
343 H2O::init(startTemp, endTemp, tempSteps, startPressure, endPressure, pressureSteps);
355 template <
class Flu
idState>
356 static Scalar
density(
const FluidState& fluidState,
int phaseIdx)
358 Scalar T = fluidState.temperature(phaseIdx);
360 return liquidDensityMixture_(fluidState);
364 if (Policy::useCO2GasDensityAsGasMixtureDensity())
366 return CO2::gasDensity(fluidState.temperature(phaseIdx), fluidState.pressure(phaseIdx));
370 Scalar rho_gH2O = H2O::gasDensity(T, fluidState.partialPressure(
gasPhaseIdx, BrineOrH2OIdx));
372 return (rho_gH2O + rho_gCO2);
376 DUNE_THROW(Dune::InvalidStateException,
"Invalid phase index.");
389 template <
class Flu
idState>
392 Scalar T = fluidState.temperature(phaseIdx);
394 return density(fluidState, phaseIdx)/fluidState.averageMolarMass(phaseIdx);
397 if (Policy::useCO2GasDensityAsGasMixtureDensity())
402 Scalar rhoMolar_gH2O = H2O::gasMolarDensity(T, fluidState.partialPressure(
gasPhaseIdx, BrineOrH2OIdx));
404 return rhoMolar_gH2O + rhoMolar_gCO2;
407 DUNE_THROW(Dune::InvalidStateException,
"Invalid phase index.");
421 template <
class Flu
idState>
422 static Scalar
viscosity(
const FluidState& fluidState,
int phaseIdx)
424 Scalar T = fluidState.temperature(phaseIdx);
425 Scalar p = fluidState.pressure(phaseIdx);
434 DUNE_THROW(Dune::InvalidStateException,
"Invalid phase index.");
464 template <
class Flu
idState>
479 Scalar T = fluidState.temperature(phaseIdx);
484 assert(pl > 0 && pg > 0);
496 xlCO2 = max(0.0, min(1.0, xlCO2));
497 xgH2O = max(0.0, min(1.0, xgH2O));
501 if (compIdx == BrineOrH2OIdx)
502 return (xgH2O/xlH2O)*(pg/pl);
504 else if (compIdx ==
CO2Idx)
505 return (xgCO2/xlCO2)*(pg/pl);
508 else if (!useConstantSalinity && compIdx == NaClIdx)
511 DUNE_THROW(Dune::InvalidStateException,
"Invalid component index.");
514 DUNE_THROW(Dune::InvalidStateException,
"Invalid phase index.");
524 template <
class Flu
idState>
529 Scalar T = fluidState.temperature(phaseIdx);
530 Scalar p = fluidState.pressure(phaseIdx);
548 DUNE_THROW(Dune::InvalidStateException,
"Invalid phase index.");
578 template <
class Flu
idState>
580 { DUNE_THROW(Dune::NotImplemented,
"Diffusion coefficients"); }
591 template <
class Flu
idState>
600 if (compIIdx > compJIdx)
603 swap(compIIdx, compJIdx);
606 Scalar T = fluidState.temperature(phaseIdx);
607 Scalar p = fluidState.pressure(phaseIdx);
610 if (compIIdx == BrineOrH2OIdx && compJIdx ==
CO2Idx)
612 if (!useConstantSalinity && compIIdx == BrineOrH2OIdx && compJIdx == NaClIdx)
618 DUNE_THROW(Dune::NotImplemented,
"Binary diffusion coefficient of components " <<
619 compIIdx <<
" and " << compJIdx <<
" in phase " << phaseIdx);
623 if (compIIdx == BrineOrH2OIdx && compJIdx ==
CO2Idx)
629 else if (!useConstantSalinity && compIIdx ==
CO2Idx && compJIdx == NaClIdx)
632 DUNE_THROW(Dune::NotImplemented,
"Binary diffusion coefficient of components " <<
633 compIIdx <<
" and " << compJIdx <<
" in phase " << phaseIdx);
636 DUNE_THROW(Dune::InvalidStateException,
"Invalid phase index.");
646 template <
class Flu
idState>
647 static Scalar
enthalpy(
const FluidState& fluidState,
int phaseIdx)
649 Scalar T = fluidState.temperature(phaseIdx);
650 Scalar p = fluidState.pressure(phaseIdx);
664 const Scalar delta_hCO2 = (-57.4375 + T * 0.1325) * 1000/44;
667 const Scalar hw = H2O::liquidEnthalpy(T, p)/1e3;
671 return (h_ls1 - X_CO2_w*hw + hg*X_CO2_w)*1e3;
677 result += H2O::gasEnthalpy(T, p)*fluidState.massFraction(
gasPhaseIdx, BrineOrH2OIdx);
683 DUNE_THROW(Dune::InvalidStateException,
"Invalid phase index.");
692 template <
class Flu
idState>
695 const Scalar T = fluidState.temperature(phaseIdx);
696 const Scalar p = fluidState.pressure(phaseIdx);
700 if (componentIdx == BrineOrH2OIdx)
701 return H2O::liquidEnthalpy(T, p);
702 else if (componentIdx ==
CO2Idx)
704 else if (componentIdx == NaClIdx)
705 DUNE_THROW(Dune::NotImplemented,
"The component enthalpy for NaCl is not implemented.");
706 DUNE_THROW(Dune::InvalidStateException,
"Invalid component index " << componentIdx);
710 if (componentIdx == BrineOrH2OIdx)
711 return H2O::gasEnthalpy(T, p);
712 else if (componentIdx ==
CO2Idx)
714 else if (componentIdx == NaClIdx)
715 DUNE_THROW(Dune::InvalidStateException,
"Implementation assumes NaCl not to be present in gas phase");
716 DUNE_THROW(Dune::InvalidStateException,
"Invalid component index " << componentIdx);
718 DUNE_THROW(Dune::InvalidStateException,
"Invalid phase index " << phaseIdx);
731 template <
class Flu
idState>
736 fluidState.pressure(phaseIdx) )
742 DUNE_THROW(Dune::InvalidStateException,
"Invalid phase index.");
756 template <
class Flu
idState>
762 fluidState.pressure(phaseIdx) )
767 fluidState.pressure(phaseIdx));
769 DUNE_THROW(Dune::InvalidStateException,
"Invalid phase index.");
780 template<
class Flu
idState>
781 static Scalar liquidDensityMixture_(
const FluidState& fluidState)
791 "defined above 273.15K (T = " << T <<
")");
795 "defined below 250MPa (p = " << p <<
")");
798 Scalar rho_pure = H2O::liquidDensity(T, p);
802 if (useConstantSalinity)
809 Scalar xlBrine = min(1.0, max(0.0, fluidState.moleFraction(
liquidPhaseIdx, BrineOrH2OIdx)));
811 Scalar sumx = xlBrine + xlCO2;
815 rho_lCO2 = liquidDensityWaterCO2_(T, p, xlBrine, xlCO2);
820 auto xlH2O = fluidState.moleFraction(
liquidPhaseIdx, BrineOrH2OIdx);
822 const auto sumMoleFrac = xlH2O + xlCO2;
823 xlH2O = xlH2O/sumMoleFrac;
824 xlCO2 = xlCO2/sumMoleFrac;
825 rho_lCO2 = liquidDensityWaterCO2_(T, p, xlH2O, xlCO2);
830 : VariableSalinityBrine::
density( BrineAdapter<FluidState>(fluidState),
834 Scalar contribCO2 = rho_lCO2 - rho_pure;
838 return rho_brine + contribCO2;
852 static Scalar liquidDensityWaterCO2_(Scalar
temperature,
858 const Scalar M_H2O = H2O::molarMass();
861 const Scalar rho_pure = H2O::liquidDensity(
temperature, pl);
866 const Scalar M_T = M_H2O * xlH2O + M_CO2 * xlCO2;
867 const Scalar V_phi = (37.51 +
870 tempC*5.044e-7))) / 1.0e6;
871 return 1/(xlCO2 * V_phi/M_T + M_H2O * xlH2O / (rho_pure * M_T));
A collection of input/output field names for common physical quantities.
A class for the CO2 fluid properties.
Tabulates all thermodynamic properties of a given untabulated chemical species.
A generic template for tabulated material laws that depend on two parameters.
Adapter class for fluid states with different indices.
Relations valid for an ideal gas.
Binary coefficients for CO2 and brine.
The infrastructure to retrieve run-time parameters from Dune::ParameterTrees.
bool CheckDefined(const T &value)
Make valgrind complain if the object occupied by an object is undefined.
Definition: valgrind.hh:72
make the local view function available whenever we use the grid geometry
Definition: adapt.hh:29
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:40
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:76
static Scalar gasDiffCoeff(Scalar temperature, Scalar pressure)
Binary diffusion coefficient of water in the CO2 phase.
Definition: brine_co2.hh:55
A class for the brine fluid properties.
Definition: components/brine.hh:57
static Scalar liquidViscosity(Scalar temperature, Scalar pressure)
The dynamic viscosity of pure brine.
Definition: components/brine.hh:410
static const Scalar liquidEnthalpy(Scalar T, Scalar p)
Specific enthalpy of liquid brine .
Definition: components/brine.hh:156
static Scalar molarMass()
The molar mass in of brine. This assumes that the salt is pure NaCl.
Definition: components/brine.hh:84
static Scalar salinity()
Return the constant salinity.
Definition: components/brine.hh:74
static Scalar liquidThermalConductivity(Scalar temperature, Scalar pressure)
Thermal conductivity of a brine .
Definition: components/brine.hh:435
static const Scalar liquidHeatCapacity(Scalar temperature, Scalar pressure)
Specific isobaric heat capacity of brine .
Definition: components/brine.hh:215
static constexpr bool liquidIsCompressible()
Returns true if the liquid phase is assumed to be compressible.
Definition: components/brine.hh:298
static std::string name()
A human readable name for the brine.
Definition: components/brine.hh:68
static constexpr bool gasIsIdeal()
Returns true if the gas phase is assumed to be ideal.
Definition: components/brine.hh:286
static Scalar liquidDensity(Scalar temperature, Scalar pressure)
The density of pure brine at a given pressure and temperature .
Definition: components/brine.hh:311
A class for the CO2 fluid properties.
Definition: co2.hh:56
static Scalar gasThermalConductivity(Scalar temperature, Scalar pressure)
Thermal conductivity of CO2.
Definition: co2.hh:398
static Scalar liquidEnthalpy(Scalar temperature, Scalar pressure)
Specific enthalpy of liquid CO2 .
Definition: co2.hh:179
static constexpr Scalar molarMass()
The mass in of one mole of CO2.
Definition: co2.hh:71
static Scalar gasMolarDensity(Scalar temperature, Scalar pressure)
The molar density of CO2 gas in at a given pressure and temperature.
Definition: co2.hh:243
static Scalar gasDensity(Scalar temperature, Scalar pressure)
The density of CO2 at a given pressure and temperature .
Definition: co2.hh:225
static constexpr bool gasIsIdeal()
Returns true if the gas phase is assumed to be ideal.
Definition: co2.hh:125
static std::string name()
A human readable name for the CO2.
Definition: co2.hh:65
static Scalar gasViscosity(Scalar temperature, Scalar pressure)
The dynamic viscosity of CO2. Equations given in: - Vesovic et al., 1990.
Definition: co2.hh:326
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:303
static Scalar gasEnthalpy(Scalar temperature, Scalar pressure)
Specific enthalpy of gaseous CO2 .
Definition: co2.hh:161
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:48
static Scalar thermalConductivity(const FluidState &fluidState, int phaseIdx)
Thermal conductivity of a fluid phase .
Definition: fluidsystems/brine.hh:483
static Scalar viscosity(const FluidState &fluidState, int phaseIdx=liquidPhaseIdx)
Return the viscosity of the phase.
Definition: fluidsystems/brine.hh:282
static constexpr int H2OIdx
index of the water component
Definition: fluidsystems/brine.hh:63
static Scalar heatCapacity(const FluidState &fluidState, int phaseIdx)
Specific isobaric heat capacity of a fluid phase. .
Definition: fluidsystems/brine.hh:501
static Scalar molarMass(int compIdx)
Return the molar mass of a component in .
Definition: fluidsystems/brine.hh:167
static Scalar enthalpy(const FluidState &fluidState, int phaseIdx)
Given a phase's composition, temperature and pressure, return its specific enthalpy .
Definition: fluidsystems/brine.hh:337
static constexpr int NaClIdx
index of the NaCl component
Definition: fluidsystems/brine.hh:64
static constexpr int liquidPhaseIdx
The one considered phase is liquid.
Definition: fluidsystems/brine.hh:61
static bool isCompressible(int phaseIdx=liquidPhaseIdx)
Returns true if and only if a fluid phase is assumed to be compressible.
Definition: fluidsystems/brine.hh:126
static std::string componentName(int compIdx)
Return the human readable name of a component.
Definition: fluidsystems/brine.hh:153
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:445
Class that exports some indices that should be provided by the BrineAir fluid system....
Definition: brineco2.hh:64
Default policy for the Brine-CO2 fluid system.
Definition: brineco2.hh:97
static constexpr bool useCO2GasDensityAsGasMixtureDensity()
Definition: brineco2.hh:99
static constexpr bool useConstantSalinity()
Definition: brineco2.hh:98
A compositional fluid with brine (H2O & NaCl) and carbon dioxide as components in both the liquid and...
Definition: brineco2.hh:119
static constexpr int CO2Idx
Definition: brineco2.hh:167
static constexpr int numComponents
Definition: brineco2.hh:155
static Scalar enthalpy(const FluidState &fluidState, int phaseIdx)
Given the phase composition, return the specific phase enthalpy .
Definition: brineco2.hh:647
static constexpr bool isCompressible(int phaseIdx)
Returns true if and only if a fluid phase is assumed to be compressible.
Definition: brineco2.hh:272
static constexpr int phase0Idx
index of the first phase
Definition: brineco2.hh:160
static constexpr int comp0Idx
Definition: brineco2.hh:163
H2OType H2O
Definition: brineco2.hh:151
static Scalar molarMass(int compIdx)
Return the molar mass of a component in .
Definition: brineco2.hh:306
static constexpr int numPhases
Definition: brineco2.hh:156
static Scalar heatCapacity(const FluidState &fluidState, int phaseIdx)
Specific isobaric heat capacity of a fluid phase .
Definition: brineco2.hh:757
static std::string componentName(int compIdx)
Return the human readable name of a component.
Definition: brineco2.hh:285
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:592
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:356
static Scalar viscosity(const FluidState &fluidState, int phaseIdx)
Calculate the dynamic viscosity of a fluid phase .
Definition: brineco2.hh:422
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:579
static void init()
Definition: brineco2.hh:328
static constexpr bool isGas(int phaseIdx)
Return whether a phase is gaseous.
Definition: brineco2.hh:219
static constexpr int phase1Idx
index of the second phase
Definition: brineco2.hh:161
static constexpr int gasPhaseIdx
index of the gas phase
Definition: brineco2.hh:159
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:231
static std::string phaseName(int phaseIdx)
Return the human readable name of a fluid phase.
Definition: brineco2.hh:198
static Scalar thermalConductivity(const FluidState &fluidState, int phaseIdx)
Thermal conductivity of a fluid phase .
Definition: brineco2.hh:732
static constexpr int liquidPhaseIdx
index of the liquid phase
Definition: brineco2.hh:158
static Scalar fugacityCoefficient(const FluidState &fluidState, int phaseIdx, int compIdx)
Returns the fugacity coefficient of a component in a phase.
Definition: brineco2.hh:465
static constexpr bool isMiscible()
Returns whether the fluids are miscible.
Definition: brineco2.hh:211
BrineType Brine
Definition: brineco2.hh:152
static void init(Scalar startTemp, Scalar endTemp, int tempSteps, Scalar startPressure, Scalar endPressure, int pressureSteps)
Definition: brineco2.hh:335
static constexpr int comp1Idx
Definition: brineco2.hh:164
static Scalar componentEnthalpy(const FluidState &fluidState, int phaseIdx, int componentIdx)
Returns the specific enthalpy of a component in a specific phase.
Definition: brineco2.hh:693
static bool isIdealMixture(int phaseIdx)
Returns true if and only if a fluid phase is assumed to be an ideal mixture.
Definition: brineco2.hh:255
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:525
static Scalar molarDensity(const FluidState &fluidState, int phaseIdx)
The molar density of a fluid phase in .
Definition: brineco2.hh:390
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.