13#ifndef DUMUX_2P2C_CO2_PRIMARY_VARIABLE_SWITCH_HH
14#define DUMUX_2P2C_CO2_PRIMARY_VARIABLE_SWITCH_HH
38 using ParentType::ParentType;
42 template<
class VolumeVariables,
class IndexType,
class GlobalPosition>
43 bool update_(
typename VolumeVariables::PrimaryVariables& priVars,
44 const VolumeVariables& volVars,
45 IndexType dofIdxGlobal,
46 const GlobalPosition& globalPos)
48 using Scalar =
typename VolumeVariables::PrimaryVariables::value_type;
50 using FluidSystem =
typename VolumeVariables::FluidSystem;
51 static constexpr int phase0Idx = FluidSystem::phase0Idx;
52 static constexpr int phase1Idx = FluidSystem::phase1Idx;
53 static constexpr int comp0Idx = FluidSystem::comp0Idx;
54 static constexpr int comp1Idx = FluidSystem::comp1Idx;
56 static constexpr bool useMoles = VolumeVariables::useMoles();
57 static constexpr auto formulation = VolumeVariables::priVarFormulation();
59 "Chosen TwoPFormulation not supported!");
61 using Indices =
typename VolumeVariables::Indices;
62 static constexpr int switchIdx = Indices::switchIdx;
65 bool wouldSwitch =
false;
70 typename FluidSystem::ParameterCache paramCache;
76 Scalar xnw = volVars.moleFraction(phase1Idx, comp0Idx);
77 Scalar xnwMax = FluidSystem::equilibriumMoleFraction(volVars.fluidState(), paramCache, phase1Idx);
91 std::cout <<
"First phase (" << FluidSystem::phaseName(phase0Idx) <<
") appears at dof " << dofIdxGlobal
92 <<
", coordinates: " << globalPos
93 <<
", x^" << FluidSystem::componentName(comp0Idx) <<
"_" << FluidSystem::phaseName(phase1Idx) <<
" > x_equilibrium: "
94 << xnw <<
" > " << xnwMax << std::endl;
95 newPhasePresence = Indices::bothPhases;
97 priVars[switchIdx] = 0.0;
99 priVars[switchIdx] = 1.0;
105 Scalar xwn = volVars.moleFraction(phase0Idx, comp1Idx);
106 Scalar xwnMax = FluidSystem::equilibriumMoleFraction(volVars.fluidState(), paramCache, phase0Idx);
120 std::cout <<
"Second phase (" << FluidSystem::phaseName(phase1Idx) <<
") appears at dof " << dofIdxGlobal
121 <<
", coordinates: " << globalPos
122 <<
", x^" << FluidSystem::componentName(comp1Idx) <<
"_" << FluidSystem::phaseName(phase0Idx) <<
" > x_equilibrium: "
123 << xwn <<
" > " << xwnMax << std::endl;
124 newPhasePresence = Indices::bothPhases;
126 priVars[switchIdx] = 0.999;
128 priVars[switchIdx] = 0.001;
138 if (volVars.saturation(phase1Idx) <= Smin)
143 std::cout <<
"Second phase (" << FluidSystem::phaseName(phase1Idx) <<
") disappears at dof " << dofIdxGlobal
144 <<
", coordinates: " << globalPos
145 <<
", S_" << FluidSystem::phaseName(phase1Idx) <<
": " << volVars.saturation(phase1Idx)
147 newPhasePresence = Indices::firstPhaseOnly;
150 priVars[switchIdx] = volVars.moleFraction(phase0Idx, comp1Idx);
152 priVars[switchIdx] = volVars.massFraction(phase0Idx, comp1Idx);
154 else if (volVars.saturation(phase0Idx) <= Smin)
159 std::cout <<
"First phase (" << FluidSystem::phaseName(phase0Idx) <<
") disappears at dof " << dofIdxGlobal
160 <<
", coordinates: " << globalPos
161 <<
", S_" << FluidSystem::phaseName(phase0Idx) <<
": " << volVars.saturation(phase0Idx)
163 newPhasePresence = Indices::secondPhaseOnly;
166 priVars[switchIdx] = volVars.moleFraction(phase1Idx, comp0Idx);
168 priVars[switchIdx] = volVars.massFraction(phase1Idx, comp0Idx);
172 priVars.setState(newPhasePresence);
The primary variable switch controlling the phase presence state variable.
Definition: compositional/primaryvariableswitch.hh:49
std::vector< bool > wasSwitched_
Definition: compositional/primaryvariableswitch.hh:433
int verbosity() const
The verbosity level.
Definition: compositional/primaryvariableswitch.hh:271
The primary variable switch for the 2p2c-CO2 model controlling the phase presence state variable.
Definition: co2/primaryvariableswitch.hh:33
bool update_(typename VolumeVariables::PrimaryVariables &priVars, const VolumeVariables &volVars, IndexType dofIdxGlobal, const GlobalPosition &globalPos)
Definition: co2/primaryvariableswitch.hh:43
The primary variable switch base class for compositional models.
@ p1s0
first phase saturation and second phase pressure as primary variables
@ p0s1
first phase pressure and second phase saturation as primary variables
std::string phasePresence() noexcept
I/O name of phase presence.
Definition: name.hh:135