13#ifndef DUMUX_2PNC_PRIMARY_VARIABLE_SWITCH_HH
14#define DUMUX_2PNC_PRIMARY_VARIABLE_SWITCH_HH
33 using ParentType::ParentType;
37 template<
class VolumeVariables,
class IndexType,
class GlobalPosition>
38 bool update_(
typename VolumeVariables::PrimaryVariables& priVars,
39 const VolumeVariables& volVars,
40 IndexType dofIdxGlobal,
41 const GlobalPosition& globalPos)
43 using Scalar =
typename VolumeVariables::PrimaryVariables::value_type;
45 using FluidSystem =
typename VolumeVariables::FluidSystem;
46 static constexpr int phase0Idx = FluidSystem::phase0Idx;
47 static constexpr int phase1Idx = FluidSystem::phase1Idx;
48 static constexpr int comp0Idx = FluidSystem::comp0Idx;
49 static constexpr int comp1Idx = FluidSystem::comp1Idx;
51 static constexpr auto numComponents = VolumeVariables::numFluidComponents();
52 static constexpr bool useMoles = VolumeVariables::useMoles();
53 static_assert(useMoles || numComponents < 3,
"!useMoles is only implemented for numComponents < 3.");
54 static constexpr auto numMajorComponents = VolumeVariables::numFluidPhases();
55 static constexpr auto formulation = VolumeVariables::priVarFormulation();
57 "Chosen TwoPFormulation not supported!");
59 using Indices =
typename VolumeVariables::Indices;
60 static constexpr int switchIdx = Indices::switchIdx;
63 bool wouldSwitch =
false;
75 if (volVars.saturation(phase0Idx) <= Smin)
80 std::cout <<
"First phase (" << FluidSystem::phaseName(phase0Idx) <<
")"
81 <<
" disappears at dof " << dofIdxGlobal
82 <<
", coordinates: " << globalPos
83 <<
", S_" << FluidSystem::phaseName(phase0Idx) <<
": " << volVars.saturation(phase0Idx)
85 newPhasePresence = Indices::secondPhaseOnly;
89 priVars[switchIdx] = volVars.moleFraction(phase1Idx, comp0Idx);
91 priVars[switchIdx] = volVars.massFraction(phase1Idx, comp0Idx);
95 for (
int compIdx = numMajorComponents; compIdx < numComponents; ++compIdx)
96 priVars[compIdx] = volVars.moleFraction(phase1Idx, compIdx);
98 for (
int compIdx = numMajorComponents; compIdx < numComponents; ++compIdx)
99 priVars[compIdx] = volVars.massFraction(phase1Idx, compIdx);
103 else if (volVars.saturation(phase1Idx) <= Smin)
108 std::cout <<
"Second phase (" << FluidSystem::phaseName(phase1Idx) <<
")"
109 <<
" disappears at dof " << dofIdxGlobal
110 <<
", coordinates: " << globalPos
111 <<
", S_" << FluidSystem::phaseName(phase1Idx) <<
": " << volVars.saturation(phase1Idx)
113 newPhasePresence = Indices::firstPhaseOnly;
117 priVars[switchIdx] = volVars.moleFraction(phase0Idx, comp1Idx);
119 priVars[switchIdx] = volVars.massFraction(phase0Idx, comp1Idx);
127 for (
int compIdx = 0; compIdx < numComponents; compIdx++)
128 x0Sum += volVars.moleFraction(phase0Idx, compIdx);
139 std::cout <<
"Second phase (" << FluidSystem::phaseName(phase0Idx) <<
")"
140 <<
" appears at dof " << dofIdxGlobal
141 <<
", coordinates: " << globalPos
142 <<
", sum x^i_" << FluidSystem::phaseName(phase0Idx) <<
": " << x0Sum
144 newPhasePresence = Indices::bothPhases;
148 priVars[switchIdx] = 0.0001;
150 priVars[switchIdx] = 0.9999;
153 for (
int compIdx = numMajorComponents; compIdx < numComponents; ++compIdx)
154 priVars[compIdx] = volVars.moleFraction(phase0Idx,compIdx);
163 for (
int compIdx = 0; compIdx < numComponents; compIdx++)
164 x1Sum += volVars.moleFraction(phase1Idx, compIdx);
175 std::cout <<
"Second phase (" << FluidSystem::phaseName(phase1Idx) <<
")"
176 <<
" appears at dof " << dofIdxGlobal
177 <<
", coordinates: " << globalPos
178 <<
", sum x^i_" << FluidSystem::phaseName(phase1Idx) <<
": " << x1Sum
180 newPhasePresence = Indices::bothPhases;
183 priVars[switchIdx] = 0.9999;
185 priVars[switchIdx] = 0.0001;
189 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 controlling the phase presence state variable.
Definition: 2pnc/primaryvariableswitch.hh:29
bool update_(typename VolumeVariables::PrimaryVariables &priVars, const VolumeVariables &volVars, IndexType dofIdxGlobal, const GlobalPosition &globalPos)
Definition: 2pnc/primaryvariableswitch.hh:38
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