20 #ifndef OPM_COMP_WELL_FLASH_HPP 21 #define OPM_COMP_WELL_FLASH_HPP 23 #include <opm/material/Constants.hpp> 24 #include <opm/material/constraintsolvers/PTFlash.hpp> 25 #include <opm/material/densead/Math.hpp> 26 #include <opm/material/fluidstates/CompositionalFluidState.hpp> 28 #include <opm/input/eclipse/EclipseState/Compositional/CompositionalConfig.hpp> 31 #include <type_traits> 53 template <
typename Flu
idSystem,
typename T>
55 const typename FluidSystem::Scalar flash_tolerance = 1.e-6)
57 using Scalar =
typename FluidSystem::Scalar;
58 using EOSType = CompositionalConfig::EOSType;
60 bool single_phase =
false;
61 if constexpr (std::is_same_v<T, Scalar>) {
62 single_phase = PTFlash<Scalar, FluidSystem>::flash_solve_scalar_(fluid_state,
"ssi", flash_tolerance, EOSType::PR);
64 single_phase = PTFlash<Scalar, FluidSystem>::solve(fluid_state,
"ssi", flash_tolerance, EOSType::PR);
67 constexpr Scalar R = Constants<Scalar>::R;
68 typename FluidSystem::template ParameterCache<T> param_cache {EOSType::PR};
69 param_cache.updatePhase(fluid_state, FluidSystem::oilPhaseIdx);
70 const auto Z_L = (param_cache.molarVolume(FluidSystem::oilPhaseIdx) * fluid_state.pressure(FluidSystem::oilPhaseIdx)) /
71 (R * fluid_state.temperature(FluidSystem::oilPhaseIdx));
72 param_cache.updatePhase(fluid_state, FluidSystem::gasPhaseIdx);
73 const auto Z_V = (param_cache.molarVolume(FluidSystem::gasPhaseIdx) * fluid_state.pressure(FluidSystem::gasPhaseIdx)) /
74 (R * fluid_state.temperature(FluidSystem::gasPhaseIdx));
76 auto L = fluid_state.L();
79 if (L > 0.9 && Z_L > 0.8) {
81 fluid_state.setLvalue(L);
82 }
else if (L < 0.1 && Z_V < 0.5) {
84 fluid_state.setLvalue(L);
87 T So = max((L * Z_L / (L * Z_L + (1 - L) * Z_V)), 0.0);
88 T Sg = max(1 - So, 0.0);
93 fluid_state.setSaturation(FluidSystem::oilPhaseIdx, So);
94 fluid_state.setSaturation(FluidSystem::gasPhaseIdx, Sg);
96 fluid_state.setCompressFactor(FluidSystem::oilPhaseIdx, Z_L);
97 fluid_state.setCompressFactor(FluidSystem::gasPhaseIdx, Z_V);
99 fluid_state.setDensity(FluidSystem::oilPhaseIdx, FluidSystem::density(fluid_state, param_cache, FluidSystem::oilPhaseIdx));
100 fluid_state.setDensity(FluidSystem::gasPhaseIdx, FluidSystem::density(fluid_state, param_cache, FluidSystem::gasPhaseIdx));
111 template <
typename Flu
idSystem,
typename T,
typename Scalar>
112 std::array<T, FluidSystem::numComponents>
114 const Scalar wellbore_volume)
116 std::array<T, FluidSystem::numComponents> component_masses;
118 const auto& so = fluid_state.saturation(FluidSystem::oilPhaseIdx);
119 const auto& sg = fluid_state.saturation(FluidSystem::gasPhaseIdx);
120 const auto& density_oil = fluid_state.density(FluidSystem::oilPhaseIdx);
121 const auto& density_gas = fluid_state.density(FluidSystem::gasPhaseIdx);
123 for (
unsigned comp_idx = 0; comp_idx < FluidSystem::numComponents; ++comp_idx) {
124 const auto oil_mass_fraction = fluid_state.massFraction(FluidSystem::oilPhaseIdx, comp_idx);
125 const auto gas_mass_fraction = fluid_state.massFraction(FluidSystem::gasPhaseIdx, comp_idx);
126 component_masses[comp_idx] = (oil_mass_fraction * density_oil * so +
127 gas_mass_fraction * density_gas * sg) * wellbore_volume;
130 return component_masses;
135 #endif // OPM_COMP_WELL_FLASH_HPP std::array< T, FluidSystem::numComponents > wellboreComponentMasses(const CompositionalFluidState< T, FluidSystem > &fluid_state, const Scalar wellbore_volume)
Mass [kg] of each component held in the wellbore control volume, given an already-flashed two-phase f...
Definition: CompWellFlash.hpp:113
Structs needed for tpfalinearizer and its gpuparams struct extracted to be defined in one place that ...
Definition: blackoilbioeffectsmodules.hh:45
void flashWellboreFluidState(CompositionalFluidState< T, FluidSystem > &fluid_state, const typename FluidSystem::Scalar flash_tolerance=1.e-6)
Flash the wellbore fluid at its current (pressure, temperature, overall composition) and fill in the ...
Definition: CompWellFlash.hpp:54