25#ifndef DUMUX_3P2CNI_PRIMARY_VARIABLE_SWITCH_HH
26#define DUMUX_3P2CNI_PRIMARY_VARIABLE_SWITCH_HH
44 using ParentType::ParentType;
49 template<
class VolumeVariables,
class GlobalPosition>
50 bool update_(
typename VolumeVariables::PrimaryVariables& priVars,
51 const VolumeVariables& volVars,
52 std::size_t dofIdxGlobal,
53 const GlobalPosition& globalPos)
55 using PrimaryVariables =
typename VolumeVariables::PrimaryVariables;
56 using Scalar =
typename PrimaryVariables::value_type;
57 using Indices =
typename VolumeVariables::Indices;
58 using FluidSystem =
typename VolumeVariables::FluidSystem;
61 bool wouldSwitch =
false;
65 if(VolumeVariables::onlyGasPhaseCanDisappear())
74 if (volVars.saturation(FluidSystem::gPhaseIdx) <= Smin)
79 std::cout <<
"Gas phase disappears at dof " << dofIdxGlobal
80 <<
", coordinates: " << globalPos <<
", sg: "
81 << volVars.saturation(FluidSystem::gPhaseIdx) << std::endl;
82 newPhasePresence = Indices::wnPhaseOnly;
84 priVars[Indices::pressureIdx] = volVars.fluidState().pressure(FluidSystem::wPhaseIdx);
85 priVars[Indices::switch1Idx] = volVars.fluidState().temperature();
94 Scalar xwg = volVars.fluidState().moleFraction(FluidSystem::gPhaseIdx, FluidSystem::wCompIdx);
95 Scalar xng = volVars.fluidState().moleFraction(FluidSystem::gPhaseIdx, FluidSystem::nCompIdx);
98 if (xwg + xng > xgMax)
105 if (xwg + xng > xgMax)
109 std::cout <<
"gas phase appears at dof " << dofIdxGlobal
110 <<
", coordinates: " << globalPos <<
", xwg + xng: "
111 << xwg + xng << std::endl;
117 newPhasePresence = Indices::threePhases;
118 priVars[Indices::pressureIdx] = volVars.pressure(FluidSystem::gPhaseIdx);
119 priVars[Indices::switch1Idx] = volVars.saturation(FluidSystem::wPhaseIdx);
133 if (volVars.saturation(FluidSystem::gPhaseIdx) <= Smin)
138 std::cout <<
"Gas phase disappears at dof " << dofIdxGlobal
139 <<
", coordinates: " << globalPos <<
", sg: "
140 << volVars.saturation(FluidSystem::gPhaseIdx) << std::endl;
141 newPhasePresence = FluidSystem::gPhaseIdx;
143 priVars[Indices::pressureIdx] = volVars.fluidState().pressure(FluidSystem::wPhaseIdx);
144 priVars[Indices::switch1Idx] = volVars.fluidState().temperature();
146 else if (volVars.saturation(FluidSystem::wPhaseIdx) <= Smin)
151 std::cout <<
"Water phase disappears at dof " << dofIdxGlobal
152 <<
", coordinates: " << globalPos <<
", sw: "
153 << volVars.saturation(FluidSystem::wPhaseIdx) << std::endl;
154 newPhasePresence = Indices::gnPhaseOnly;
156 priVars[Indices::switch1Idx] = volVars.fluidState().saturation(FluidSystem::nPhaseIdx);
157 priVars[Indices::switch2Idx] = volVars.fluidState().moleFraction(FluidSystem::nPhaseIdx, FluidSystem::wCompIdx);
159 else if (volVars.saturation(FluidSystem::nPhaseIdx) <= Smin)
164 std::cout <<
"NAPL phase disappears at dof " << dofIdxGlobal
165 <<
", coordinates: " << globalPos <<
", sn: "
166 << volVars.saturation(FluidSystem::nPhaseIdx) << std::endl;
167 newPhasePresence = Indices::wgPhaseOnly;
169 priVars[Indices::switch2Idx] = volVars.fluidState().moleFraction(FluidSystem::wPhaseIdx, FluidSystem::nCompIdx);
175 bool nonwettingFlag = 0;
178 Scalar xwg = volVars.fluidState().moleFraction(FluidSystem::gPhaseIdx, FluidSystem::wCompIdx);
179 Scalar xng = volVars.fluidState().moleFraction(FluidSystem::gPhaseIdx, FluidSystem::nCompIdx);
182 if (xwg + xng > xgMax)
189 if (xwg + xng > xgMax)
193 std::cout <<
"gas phase appears at dof " << dofIdxGlobal
194 <<
", coordinates: " << globalPos <<
", xwg + xng: "
195 << xwg + xng << std::endl;
200 Scalar xnn = volVars.fluidState().moleFraction(FluidSystem::nPhaseIdx, FluidSystem::nCompIdx);
220 std::cout <<
"NAPL phase appears at dof " << dofIdxGlobal
221 <<
", coordinates: " << globalPos <<
", xnn: "
226 if ((gasFlag == 1) && (nonwettingFlag == 0))
228 newPhasePresence = Indices::wgPhaseOnly;
229 priVars[Indices::switch1Idx] = 0.9999;
230 priVars[Indices::pressureIdx] = volVars.fluidState().pressure(FluidSystem::gPhaseIdx);
232 else if ((gasFlag == 1) && (nonwettingFlag == 1))
234 newPhasePresence = Indices::threePhases;
235 priVars[Indices::pressureIdx] = volVars.fluidState().pressure(FluidSystem::gPhaseIdx);
236 priVars[Indices::switch1Idx] = 0.999;
238 else if ((gasFlag == 0) && (nonwettingFlag == 1))
240 newPhasePresence = Indices::wnPhaseOnly;
241 priVars[Indices::switch2Idx] = 0.0001;
246 bool nonwettingFlag = 0;
247 bool wettingFlag = 0;
253 if (volVars.saturation(FluidSystem::nPhaseIdx) <= Smin)
258 std::cout <<
"NAPL phase disappears at dof " << dofIdxGlobal
259 <<
", coordinates: " << globalPos <<
", sn: "
260 << volVars.saturation(FluidSystem::nPhaseIdx) << std::endl;
266 Scalar xww = volVars.fluidState().moleFraction(FluidSystem::wPhaseIdx, FluidSystem::wCompIdx);
283 std::cout <<
"water phase appears at dof " << dofIdxGlobal
284 <<
", coordinates: " << globalPos <<
", xww=xwg*pg/pwsat : "
289 if ((wettingFlag == 1) && (nonwettingFlag == 0))
291 newPhasePresence = Indices::threePhases;
292 priVars[Indices::switch1Idx] = 0.0001;
293 priVars[Indices::switch2Idx] = volVars.saturation(FluidSystem::nPhaseIdx);
295 else if ((wettingFlag == 1) && (nonwettingFlag == 1))
297 newPhasePresence = Indices::wgPhaseOnly;
298 priVars[Indices::switch1Idx] = 0.0001;
299 priVars[Indices::switch2Idx] = volVars.fluidState().moleFraction(FluidSystem::wPhaseIdx, FluidSystem::nCompIdx);
301 else if ((wettingFlag == 0) && (nonwettingFlag == 1))
303 newPhasePresence = Indices::gPhaseOnly;
304 priVars[Indices::switch1Idx] = volVars.fluidState().temperature();
305 priVars[Indices::switch2Idx] = volVars.fluidState().moleFraction(FluidSystem::gPhaseIdx, FluidSystem::nCompIdx);
310 bool nonwettingFlag = 0;
317 if (volVars.saturation(FluidSystem::nPhaseIdx) <= Smin)
322 std::cout <<
"NAPL phase disappears at dof " << dofIdxGlobal
323 <<
", coordinates: " << globalPos <<
", sn: "
324 << volVars.saturation(FluidSystem::nPhaseIdx) << std::endl;
330 Scalar xwg = volVars.fluidState().moleFraction(FluidSystem::gPhaseIdx, FluidSystem::wCompIdx);
331 Scalar xng = volVars.fluidState().moleFraction(FluidSystem::gPhaseIdx, FluidSystem::nCompIdx);
334 if (xwg + xng > xgMax)
341 if (xwg + xng > xgMax)
345 std::cout <<
"gas phase appears at dof " << dofIdxGlobal
346 <<
", coordinates: " << globalPos <<
", xwg + xng: "
347 << xwg + xng << std::endl;
351 if ((gasFlag == 1) && (nonwettingFlag == 0))
353 newPhasePresence = Indices::threePhases;
354 priVars[Indices::pressureIdx] = volVars.pressure(FluidSystem::gPhaseIdx);
355 priVars[Indices::switch1Idx] = volVars.saturation(FluidSystem::wPhaseIdx);
357 else if ((gasFlag == 1) && (nonwettingFlag == 1))
359 newPhasePresence = Indices::wgPhaseOnly;
360 priVars[Indices::pressureIdx] = volVars.pressure(FluidSystem::gPhaseIdx);
361 priVars[Indices::switch1Idx] = volVars.temperature();
362 priVars[Indices::switch2Idx] = volVars.fluidState().moleFraction(FluidSystem::wPhaseIdx, FluidSystem::nCompIdx);
364 else if ((gasFlag == 0) && (nonwettingFlag == 1))
366 newPhasePresence = Indices::wPhaseOnly;
367 priVars[Indices::switch2Idx] = volVars.fluidState().moleFraction(FluidSystem::wPhaseIdx, FluidSystem::nCompIdx);
372 bool nonwettingFlag = 0;
373 bool wettingFlag = 0;
376 Scalar xnn = volVars.fluidState().moleFraction(FluidSystem::nPhaseIdx, FluidSystem::nCompIdx);
394 std::cout <<
"NAPL phase appears at dof " << dofIdxGlobal
395 <<
", coordinates: " << globalPos <<
", xnn: "
400 Scalar xww = volVars.fluidState().moleFraction(FluidSystem::wPhaseIdx, FluidSystem::wCompIdx);
417 std::cout <<
"water phase appears at dof " << dofIdxGlobal
418 <<
", coordinates: " << globalPos <<
", xww=xwg*pg/pwsat : "
422 if ((wettingFlag == 1) && (nonwettingFlag == 0))
424 newPhasePresence = Indices::wgPhaseOnly;
425 priVars[Indices::switch1Idx] = 0.0001;
426 priVars[Indices::switch2Idx] = volVars.fluidState().moleFraction(FluidSystem::wPhaseIdx, FluidSystem::nCompIdx);
428 else if ((wettingFlag == 1) && (nonwettingFlag == 1))
430 newPhasePresence = Indices::threePhases;
431 priVars[Indices::switch1Idx] = 0.0001;
432 priVars[Indices::switch2Idx] = 0.0001;
434 else if ((wettingFlag == 0) && (nonwettingFlag == 1))
436 newPhasePresence = Indices::gnPhaseOnly;
437 priVars[Indices::switch2Idx]
438 = volVars.fluidState().moleFraction(FluidSystem::wPhaseIdx, FluidSystem::nCompIdx);
443 bool nonwettingFlag = 0;
445 bool wettingFlag = 0;
448 Scalar xnn = volVars.fluidState().moleFraction(FluidSystem::nPhaseIdx, FluidSystem::nCompIdx);
465 std::cout <<
"NAPL phase appears at dof " << dofIdxGlobal
466 <<
", coordinates: " << globalPos <<
", xnn: "
471 Scalar Smin = -1.e-6;
475 if (volVars.saturation(FluidSystem::gPhaseIdx) <= Smin)
480 std::cout <<
"Gas phase disappears at dof " << dofIdxGlobal
481 <<
", coordinates: " << globalPos <<
", sg: "
482 << volVars.saturation(FluidSystem::gPhaseIdx) << std::endl;
490 if (volVars.saturation(FluidSystem::wPhaseIdx) <= Smin)
495 std::cout <<
"Water phase disappears at dof " << dofIdxGlobal
496 <<
", coordinates: " << globalPos <<
", sw: "
497 << volVars.saturation(FluidSystem::wPhaseIdx) << std::endl;
501 if ((gasFlag == 0) && (nonwettingFlag == 1) && (wettingFlag == 1))
503 newPhasePresence = Indices::gnPhaseOnly;
504 priVars[Indices::switch1Idx] = 0.0001;
505 priVars[Indices::switch2Idx] = volVars.fluidState().moleFraction(FluidSystem::nPhaseIdx, FluidSystem::wCompIdx);
508 else if ((gasFlag == 0) && (nonwettingFlag == 1) && (wettingFlag == 0))
510 newPhasePresence = Indices::threePhases;
511 priVars[Indices::switch2Idx] = 0.0001;
513 else if ((gasFlag == 1) && (nonwettingFlag == 0) && (wettingFlag == 0))
515 newPhasePresence = Indices::wPhaseOnly;
516 priVars[Indices::pressureIdx] = volVars.fluidState().pressure(FluidSystem::wPhaseIdx);
517 priVars[Indices::switch1Idx] = volVars.fluidState().temperature();
518 priVars[Indices::switch2Idx] = volVars.fluidState().moleFraction(FluidSystem::wPhaseIdx, FluidSystem::nCompIdx);
520 else if ((gasFlag == 0) && (nonwettingFlag == 0) && (wettingFlag == 1))
522 newPhasePresence = Indices::gPhaseOnly;
523 priVars[Indices::switch1Idx]
524 = volVars.fluidState().temperature();
525 priVars[Indices::switch2Idx]
526 = volVars.fluidState().moleFraction(FluidSystem::gPhaseIdx, FluidSystem::nCompIdx);
532 priVars.setState(newPhasePresence);
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: 3pwateroil/primaryvariableswitch.hh:39
bool update_(typename VolumeVariables::PrimaryVariables &priVars, const VolumeVariables &volVars, std::size_t dofIdxGlobal, const GlobalPosition &globalPos)
Definition: 3pwateroil/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
Declares all properties used in Dumux.
The primary variable switch base class for compositional models.