25#ifndef DUMUX_2PNC_PRIMARY_VARIABLE_SWITCH_HH
26#define DUMUX_2PNC_PRIMARY_VARIABLE_SWITCH_HH
45 using ParentType::ParentType;
49 template<
class VolumeVariables,
class IndexType,
class GlobalPosition>
50 bool update_(
typename VolumeVariables::PrimaryVariables& priVars,
51 const VolumeVariables& volVars,
52 IndexType dofIdxGlobal,
53 const GlobalPosition& globalPos)
55 using Scalar =
typename VolumeVariables::PrimaryVariables::value_type;
57 using FluidSystem =
typename VolumeVariables::FluidSystem;
58 static constexpr int phase0Idx = FluidSystem::phase0Idx;
59 static constexpr int phase1Idx = FluidSystem::phase1Idx;
60 static constexpr int comp0Idx = FluidSystem::comp0Idx;
61 static constexpr int comp1Idx = FluidSystem::comp1Idx;
63 static constexpr auto numComponents = VolumeVariables::numFluidComponents();
64 static constexpr bool useMoles = VolumeVariables::useMoles();
65 static_assert(useMoles || numComponents < 3,
"!useMoles is only implemented for numComponents < 3.");
66 static constexpr auto numMajorComponents = VolumeVariables::numFluidPhases();
67 static constexpr auto formulation = VolumeVariables::priVarFormulation();
69 "Chosen TwoPFormulation not supported!");
71 using Indices =
typename VolumeVariables::Indices;
72 static constexpr int switchIdx = Indices::switchIdx;
75 bool wouldSwitch =
false;
87 if (volVars.saturation(phase0Idx) <= Smin)
92 std::cout <<
"First phase (" << FluidSystem::phaseName(phase0Idx) <<
")"
93 <<
" disappears at dof " << dofIdxGlobal
94 <<
", coordinates: " << globalPos
95 <<
", S_" << FluidSystem::phaseName(phase0Idx) <<
": " << volVars.saturation(phase0Idx)
97 newPhasePresence = Indices::secondPhaseOnly;
101 priVars[switchIdx] = volVars.moleFraction(phase1Idx, comp0Idx);
103 priVars[switchIdx] = volVars.massFraction(phase1Idx, comp0Idx);
107 for (
int compIdx = numMajorComponents; compIdx < numComponents; ++compIdx)
108 priVars[compIdx] = volVars.moleFraction(phase1Idx, compIdx);
110 for (
int compIdx = numMajorComponents; compIdx < numComponents; ++compIdx)
111 priVars[compIdx] = volVars.massFraction(phase1Idx, compIdx);
115 else if (volVars.saturation(phase1Idx) <= Smin)
120 std::cout <<
"Second phase (" << FluidSystem::phaseName(phase1Idx) <<
")"
121 <<
" disappears at dof " << dofIdxGlobal
122 <<
", coordinates: " << globalPos
123 <<
", S_" << FluidSystem::phaseName(phase1Idx) <<
": " << volVars.saturation(phase1Idx)
125 newPhasePresence = Indices::firstPhaseOnly;
129 priVars[switchIdx] = volVars.moleFraction(phase0Idx, comp1Idx);
131 priVars[switchIdx] = volVars.massFraction(phase0Idx, comp1Idx);
139 for (
int compIdx = 0; compIdx < numComponents; compIdx++)
140 x0Sum += volVars.moleFraction(phase0Idx, compIdx);
151 std::cout <<
"Second phase (" << FluidSystem::phaseName(phase0Idx) <<
")"
152 <<
" appears at dof " << dofIdxGlobal
153 <<
", coordinates: " << globalPos
154 <<
", sum x^i_" << FluidSystem::phaseName(phase0Idx) <<
": " << x0Sum
156 newPhasePresence = Indices::bothPhases;
160 priVars[switchIdx] = 0.0001;
162 priVars[switchIdx] = 0.9999;
165 for (
int compIdx = numMajorComponents; compIdx < numComponents; ++compIdx)
166 priVars[compIdx] = volVars.moleFraction(phase0Idx,compIdx);
175 for (
int compIdx = 0; compIdx < numComponents; compIdx++)
176 x1Sum += volVars.moleFraction(phase1Idx, compIdx);
187 std::cout <<
"Second phase (" << FluidSystem::phaseName(phase1Idx) <<
")"
188 <<
" appears at dof " << dofIdxGlobal
189 <<
", coordinates: " << globalPos
190 <<
", sum x^i_" << FluidSystem::phaseName(phase1Idx) <<
": " << x1Sum
192 newPhasePresence = Indices::bothPhases;
195 priVars[switchIdx] = 0.9999;
197 priVars[switchIdx] = 0.0001;
201 priVars.setState(newPhasePresence);
Defines an enumeration for the formulations accepted by the two-phase model.
@ p1s0
first phase saturation and second phase pressure as primary variables
@ p0s1
first phase pressure and second phase saturation as primary variables
Adaption of the non-isothermal two-phase two-component flow model to problems with CO2.
Definition: adapt.hh:29
std::string phasePresence() noexcept
I/O name of phase presence.
Definition: name.hh:147
The primary variable switch controlling the phase presence state variable.
Definition: 2pnc/primaryvariableswitch.hh:41
bool update_(typename VolumeVariables::PrimaryVariables &priVars, const VolumeVariables &volVars, IndexType dofIdxGlobal, const GlobalPosition &globalPos)
Definition: 2pnc/primaryvariableswitch.hh:50
The primary variable switch controlling the phase presence state variable.
Definition: compositional/primaryvariableswitch.hh:61
std::vector< bool > wasSwitched_
Definition: compositional/primaryvariableswitch.hh:445
int verbosity() const
The verbosity level.
Definition: compositional/primaryvariableswitch.hh:283
The primary variable switch base class for compositional models.