13#ifndef DUMUX_3P2CNI_PRIMARY_VARIABLE_SWITCH_HH
14#define DUMUX_3P2CNI_PRIMARY_VARIABLE_SWITCH_HH
32 using ParentType::ParentType;
37 template<
class VolumeVariables,
class GlobalPosition>
38 bool update_(
typename VolumeVariables::PrimaryVariables& priVars,
39 const VolumeVariables& volVars,
40 std::size_t dofIdxGlobal,
41 const GlobalPosition& globalPos)
43 using PrimaryVariables =
typename VolumeVariables::PrimaryVariables;
44 using Scalar =
typename PrimaryVariables::value_type;
45 using Indices =
typename VolumeVariables::Indices;
46 using FluidSystem =
typename VolumeVariables::FluidSystem;
49 bool wouldSwitch =
false;
53 if(VolumeVariables::onlyGasPhaseCanDisappear())
62 if (volVars.saturation(FluidSystem::gPhaseIdx) <= Smin)
67 std::cout <<
"Gas phase disappears at dof " << dofIdxGlobal
68 <<
", coordinates: " << globalPos <<
", sg: "
69 << volVars.saturation(FluidSystem::gPhaseIdx) << std::endl;
70 newPhasePresence = Indices::wnPhaseOnly;
72 priVars[Indices::pressureIdx] = volVars.fluidState().pressure(FluidSystem::wPhaseIdx);
73 priVars[Indices::switch1Idx] = volVars.fluidState().temperature();
82 Scalar xwg = volVars.fluidState().moleFraction(FluidSystem::gPhaseIdx, FluidSystem::wCompIdx);
83 Scalar xng = volVars.fluidState().moleFraction(FluidSystem::gPhaseIdx, FluidSystem::nCompIdx);
86 if (xwg + xng > xgMax)
93 if (xwg + xng > xgMax)
97 std::cout <<
"gas phase appears at dof " << dofIdxGlobal
98 <<
", coordinates: " << globalPos <<
", xwg + xng: "
99 << xwg + xng << std::endl;
105 newPhasePresence = Indices::threePhases;
106 priVars[Indices::pressureIdx] = volVars.pressure(FluidSystem::gPhaseIdx);
107 priVars[Indices::switch1Idx] = volVars.saturation(FluidSystem::wPhaseIdx);
121 if (volVars.saturation(FluidSystem::gPhaseIdx) <= Smin)
126 std::cout <<
"Gas phase disappears at dof " << dofIdxGlobal
127 <<
", coordinates: " << globalPos <<
", sg: "
128 << volVars.saturation(FluidSystem::gPhaseIdx) << std::endl;
129 newPhasePresence = FluidSystem::gPhaseIdx;
131 priVars[Indices::pressureIdx] = volVars.fluidState().pressure(FluidSystem::wPhaseIdx);
132 priVars[Indices::switch1Idx] = volVars.fluidState().temperature();
134 else if (volVars.saturation(FluidSystem::wPhaseIdx) <= Smin)
139 std::cout <<
"Water phase disappears at dof " << dofIdxGlobal
140 <<
", coordinates: " << globalPos <<
", sw: "
141 << volVars.saturation(FluidSystem::wPhaseIdx) << std::endl;
142 newPhasePresence = Indices::gnPhaseOnly;
144 priVars[Indices::switch1Idx] = volVars.fluidState().saturation(FluidSystem::nPhaseIdx);
145 priVars[Indices::switch2Idx] = volVars.fluidState().moleFraction(FluidSystem::nPhaseIdx, FluidSystem::wCompIdx);
147 else if (volVars.saturation(FluidSystem::nPhaseIdx) <= Smin)
152 std::cout <<
"NAPL phase disappears at dof " << dofIdxGlobal
153 <<
", coordinates: " << globalPos <<
", sn: "
154 << volVars.saturation(FluidSystem::nPhaseIdx) << std::endl;
155 newPhasePresence = Indices::wgPhaseOnly;
157 priVars[Indices::switch2Idx] = volVars.fluidState().moleFraction(FluidSystem::wPhaseIdx, FluidSystem::nCompIdx);
163 bool nonwettingFlag = 0;
166 Scalar xwg = volVars.fluidState().moleFraction(FluidSystem::gPhaseIdx, FluidSystem::wCompIdx);
167 Scalar xng = volVars.fluidState().moleFraction(FluidSystem::gPhaseIdx, FluidSystem::nCompIdx);
170 if (xwg + xng > xgMax)
177 if (xwg + xng > xgMax)
181 std::cout <<
"gas phase appears at dof " << dofIdxGlobal
182 <<
", coordinates: " << globalPos <<
", xwg + xng: "
183 << xwg + xng << std::endl;
188 Scalar xnn = volVars.fluidState().moleFraction(FluidSystem::nPhaseIdx, FluidSystem::nCompIdx);
208 std::cout <<
"NAPL phase appears at dof " << dofIdxGlobal
209 <<
", coordinates: " << globalPos <<
", xnn: "
214 if ((gasFlag == 1) && (nonwettingFlag == 0))
216 newPhasePresence = Indices::wgPhaseOnly;
217 priVars[Indices::switch1Idx] = 0.9999;
218 priVars[Indices::pressureIdx] = volVars.fluidState().pressure(FluidSystem::gPhaseIdx);
220 else if ((gasFlag == 1) && (nonwettingFlag == 1))
222 newPhasePresence = Indices::threePhases;
223 priVars[Indices::pressureIdx] = volVars.fluidState().pressure(FluidSystem::gPhaseIdx);
224 priVars[Indices::switch1Idx] = 0.999;
226 else if ((gasFlag == 0) && (nonwettingFlag == 1))
228 newPhasePresence = Indices::wnPhaseOnly;
229 priVars[Indices::switch2Idx] = 0.0001;
234 bool nonwettingFlag = 0;
235 bool wettingFlag = 0;
241 if (volVars.saturation(FluidSystem::nPhaseIdx) <= Smin)
246 std::cout <<
"NAPL phase disappears at dof " << dofIdxGlobal
247 <<
", coordinates: " << globalPos <<
", sn: "
248 << volVars.saturation(FluidSystem::nPhaseIdx) << std::endl;
254 Scalar xww = volVars.fluidState().moleFraction(FluidSystem::wPhaseIdx, FluidSystem::wCompIdx);
271 std::cout <<
"water phase appears at dof " << dofIdxGlobal
272 <<
", coordinates: " << globalPos <<
", xww=xwg*pg/pwsat : "
277 if ((wettingFlag == 1) && (nonwettingFlag == 0))
279 newPhasePresence = Indices::threePhases;
280 priVars[Indices::switch1Idx] = 0.0001;
281 priVars[Indices::switch2Idx] = volVars.saturation(FluidSystem::nPhaseIdx);
283 else if ((wettingFlag == 1) && (nonwettingFlag == 1))
285 newPhasePresence = Indices::wgPhaseOnly;
286 priVars[Indices::switch1Idx] = 0.0001;
287 priVars[Indices::switch2Idx] = volVars.fluidState().moleFraction(FluidSystem::wPhaseIdx, FluidSystem::nCompIdx);
289 else if ((wettingFlag == 0) && (nonwettingFlag == 1))
291 newPhasePresence = Indices::gPhaseOnly;
292 priVars[Indices::switch1Idx] = volVars.fluidState().temperature();
293 priVars[Indices::switch2Idx] = volVars.fluidState().moleFraction(FluidSystem::gPhaseIdx, FluidSystem::nCompIdx);
298 bool nonwettingFlag = 0;
305 if (volVars.saturation(FluidSystem::nPhaseIdx) <= Smin)
310 std::cout <<
"NAPL phase disappears at dof " << dofIdxGlobal
311 <<
", coordinates: " << globalPos <<
", sn: "
312 << volVars.saturation(FluidSystem::nPhaseIdx) << std::endl;
318 Scalar xwg = volVars.fluidState().moleFraction(FluidSystem::gPhaseIdx, FluidSystem::wCompIdx);
319 Scalar xng = volVars.fluidState().moleFraction(FluidSystem::gPhaseIdx, FluidSystem::nCompIdx);
322 if (xwg + xng > xgMax)
329 if (xwg + xng > xgMax)
333 std::cout <<
"gas phase appears at dof " << dofIdxGlobal
334 <<
", coordinates: " << globalPos <<
", xwg + xng: "
335 << xwg + xng << std::endl;
339 if ((gasFlag == 1) && (nonwettingFlag == 0))
341 newPhasePresence = Indices::threePhases;
342 priVars[Indices::pressureIdx] = volVars.pressure(FluidSystem::gPhaseIdx);
343 priVars[Indices::switch1Idx] = volVars.saturation(FluidSystem::wPhaseIdx);
345 else if ((gasFlag == 1) && (nonwettingFlag == 1))
347 newPhasePresence = Indices::wgPhaseOnly;
348 priVars[Indices::pressureIdx] = volVars.pressure(FluidSystem::gPhaseIdx);
349 priVars[Indices::switch1Idx] = volVars.temperature();
350 priVars[Indices::switch2Idx] = volVars.fluidState().moleFraction(FluidSystem::wPhaseIdx, FluidSystem::nCompIdx);
352 else if ((gasFlag == 0) && (nonwettingFlag == 1))
354 newPhasePresence = Indices::wPhaseOnly;
355 priVars[Indices::switch2Idx] = volVars.fluidState().moleFraction(FluidSystem::wPhaseIdx, FluidSystem::nCompIdx);
360 bool nonwettingFlag = 0;
361 bool wettingFlag = 0;
364 Scalar xnn = volVars.fluidState().moleFraction(FluidSystem::nPhaseIdx, FluidSystem::nCompIdx);
382 std::cout <<
"NAPL phase appears at dof " << dofIdxGlobal
383 <<
", coordinates: " << globalPos <<
", xnn: "
388 Scalar xww = volVars.fluidState().moleFraction(FluidSystem::wPhaseIdx, FluidSystem::wCompIdx);
405 std::cout <<
"water phase appears at dof " << dofIdxGlobal
406 <<
", coordinates: " << globalPos <<
", xww=xwg*pg/pwsat : "
410 if ((wettingFlag == 1) && (nonwettingFlag == 0))
412 newPhasePresence = Indices::wgPhaseOnly;
413 priVars[Indices::switch1Idx] = 0.0001;
414 priVars[Indices::switch2Idx] = volVars.fluidState().moleFraction(FluidSystem::wPhaseIdx, FluidSystem::nCompIdx);
416 else if ((wettingFlag == 1) && (nonwettingFlag == 1))
418 newPhasePresence = Indices::threePhases;
419 priVars[Indices::switch1Idx] = 0.0001;
420 priVars[Indices::switch2Idx] = 0.0001;
422 else if ((wettingFlag == 0) && (nonwettingFlag == 1))
424 newPhasePresence = Indices::gnPhaseOnly;
425 priVars[Indices::switch2Idx]
426 = volVars.fluidState().moleFraction(FluidSystem::wPhaseIdx, FluidSystem::nCompIdx);
431 bool nonwettingFlag = 0;
433 bool wettingFlag = 0;
436 Scalar xnn = volVars.fluidState().moleFraction(FluidSystem::nPhaseIdx, FluidSystem::nCompIdx);
453 std::cout <<
"NAPL phase appears at dof " << dofIdxGlobal
454 <<
", coordinates: " << globalPos <<
", xnn: "
459 Scalar Smin = -1.e-6;
463 if (volVars.saturation(FluidSystem::gPhaseIdx) <= Smin)
468 std::cout <<
"Gas phase disappears at dof " << dofIdxGlobal
469 <<
", coordinates: " << globalPos <<
", sg: "
470 << volVars.saturation(FluidSystem::gPhaseIdx) << std::endl;
478 if (volVars.saturation(FluidSystem::wPhaseIdx) <= Smin)
483 std::cout <<
"Water phase disappears at dof " << dofIdxGlobal
484 <<
", coordinates: " << globalPos <<
", sw: "
485 << volVars.saturation(FluidSystem::wPhaseIdx) << std::endl;
489 if ((gasFlag == 0) && (nonwettingFlag == 1) && (wettingFlag == 1))
491 newPhasePresence = Indices::gnPhaseOnly;
492 priVars[Indices::switch1Idx] = 0.0001;
493 priVars[Indices::switch2Idx] = volVars.fluidState().moleFraction(FluidSystem::nPhaseIdx, FluidSystem::wCompIdx);
496 else if ((gasFlag == 0) && (nonwettingFlag == 1) && (wettingFlag == 0))
498 newPhasePresence = Indices::threePhases;
499 priVars[Indices::switch2Idx] = 0.0001;
501 else if ((gasFlag == 1) && (nonwettingFlag == 0) && (wettingFlag == 0))
503 newPhasePresence = Indices::wPhaseOnly;
504 priVars[Indices::pressureIdx] = volVars.fluidState().pressure(FluidSystem::wPhaseIdx);
505 priVars[Indices::switch1Idx] = volVars.fluidState().temperature();
506 priVars[Indices::switch2Idx] = volVars.fluidState().moleFraction(FluidSystem::wPhaseIdx, FluidSystem::nCompIdx);
508 else if ((gasFlag == 0) && (nonwettingFlag == 0) && (wettingFlag == 1))
510 newPhasePresence = Indices::gPhaseOnly;
511 priVars[Indices::switch1Idx]
512 = volVars.fluidState().temperature();
513 priVars[Indices::switch2Idx]
514 = volVars.fluidState().moleFraction(FluidSystem::gPhaseIdx, FluidSystem::nCompIdx);
520 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: 3pwateroil/primaryvariableswitch.hh:27
bool update_(typename VolumeVariables::PrimaryVariables &priVars, const VolumeVariables &volVars, std::size_t dofIdxGlobal, const GlobalPosition &globalPos)
Definition: 3pwateroil/primaryvariableswitch.hh:38
Defines all properties used in Dumux.
The primary variable switch base class for compositional models.
std::string phasePresence() noexcept
I/O name of phase presence.
Definition: name.hh:135