25#ifndef DUMUX_3P3C_PRIMARY_VARIABLE_SWITCH_HH
26#define DUMUX_3P3C_PRIMARY_VARIABLE_SWITCH_HH
45 using ParentType::ParentType;
50 template<
class VolumeVariables,
class GlobalPosition>
51 bool update_(
typename VolumeVariables::PrimaryVariables& priVars,
52 const VolumeVariables& volVars,
53 std::size_t dofIdxGlobal,
54 const GlobalPosition& globalPos)
56 using PrimaryVariables =
typename VolumeVariables::PrimaryVariables;
57 using Scalar =
typename PrimaryVariables::value_type;
58 using Indices =
typename VolumeVariables::Indices;
59 using FluidSystem =
typename VolumeVariables::FluidSystem;
62 bool wouldSwitch =
false;
73 if (volVars.saturation(FluidSystem::gPhaseIdx) <= Smin)
78 std::cout <<
"Gas phase disappears at dof " << dofIdxGlobal
79 <<
", coordinates: " << globalPos <<
", sg: "
80 << volVars.saturation(FluidSystem::gPhaseIdx) << std::endl;
81 newPhasePresence = Indices::wnPhaseOnly;
83 priVars[Indices::switch1Idx] = volVars.moleFraction(FluidSystem::wPhaseIdx, FluidSystem::gCompIdx);
85 else if (volVars.saturation(FluidSystem::wPhaseIdx) <= Smin)
90 std::cout <<
"Water phase disappears at dof " << dofIdxGlobal
91 <<
", coordinates: " << globalPos <<
", sw: "
92 << volVars.saturation(FluidSystem::wPhaseIdx) << std::endl;
93 newPhasePresence = Indices::gnPhaseOnly;
95 priVars[Indices::switch1Idx] = volVars.moleFraction(FluidSystem::gPhaseIdx, FluidSystem::wCompIdx);
97 else if (volVars.saturation(FluidSystem::nPhaseIdx) <= Smin)
102 std::cout <<
"NAPL phase disappears at dof " << dofIdxGlobal
103 <<
", coordinates: " << globalPos <<
", sn: "
104 << volVars.saturation(FluidSystem::nPhaseIdx) << std::endl;
105 newPhasePresence = Indices::wgPhaseOnly;
107 priVars[Indices::switch2Idx] = volVars.moleFraction(FluidSystem::gPhaseIdx, FluidSystem::nCompIdx);
112 bool gasPresent =
false;
113 bool nonwettingPresent =
false;
116 Scalar xwg = volVars.moleFraction(FluidSystem::gPhaseIdx, FluidSystem::wCompIdx);
117 Scalar xgg = volVars.moleFraction(FluidSystem::gPhaseIdx, FluidSystem::gCompIdx);
118 Scalar xng = volVars.moleFraction(FluidSystem::gPhaseIdx, FluidSystem::nCompIdx);
126 if (xwg + xgg + xng > xgMax)
133 if (xwg + xgg + xng > xgMax)
137 std::cout <<
"gas phase appears at dof " << dofIdxGlobal
138 <<
", coordinates: " << globalPos <<
", xwg + xgg + xng: "
139 << xwg + xgg + xng << std::endl;
144 Scalar xnn = volVars.moleFraction(FluidSystem::nPhaseIdx, FluidSystem::nCompIdx);
164 std::cout <<
"NAPL phase appears at dof " << dofIdxGlobal
165 <<
", coordinates: " << globalPos <<
", xnn: "
167 nonwettingPresent =
true;
170 if (gasPresent && !nonwettingPresent)
172 newPhasePresence = Indices::wgPhaseOnly;
173 priVars[Indices::switch1Idx] = 0.9999;
174 priVars[Indices::switch2Idx] = 0.0001;
176 else if (gasPresent && nonwettingPresent)
178 newPhasePresence = Indices::threePhases;
179 priVars[Indices::switch1Idx] = 0.9999;
180 priVars[Indices::switch2Idx] = 0.0001;
182 else if (!gasPresent && nonwettingPresent)
184 newPhasePresence = Indices::wnPhaseOnly;
185 priVars[Indices::switch1Idx] = volVars.moleFraction(FluidSystem::wPhaseIdx, FluidSystem::gCompIdx);
186 priVars[Indices::switch2Idx] = 0.0001;
191 bool nonwettingPresent =
false;
192 bool wettingPresent =
false;
198 if (volVars.saturation(FluidSystem::nPhaseIdx) <= Smin)
203 std::cout <<
"NAPL phase disappears at dof " << dofIdxGlobal
204 <<
", coordinates: " << globalPos <<
", sn: "
205 << volVars.saturation(FluidSystem::nPhaseIdx) << std::endl;
206 nonwettingPresent =
true;
211 Scalar xww = volVars.moleFraction(FluidSystem::wPhaseIdx, FluidSystem::wCompIdx);
228 std::cout <<
"water phase appears at dof " << dofIdxGlobal
229 <<
", coordinates: " << globalPos <<
", xww=xwg*pg/pwsat : "
231 wettingPresent =
true;
234 if (wettingPresent && !nonwettingPresent)
236 newPhasePresence = Indices::threePhases;
237 priVars[Indices::switch1Idx] = 0.0001;
238 priVars[Indices::switch2Idx] = volVars.saturation(FluidSystem::nPhaseIdx);
240 else if (wettingPresent && nonwettingPresent)
242 newPhasePresence = Indices::wgPhaseOnly;
243 priVars[Indices::switch1Idx] = 0.0001;
244 priVars[Indices::switch2Idx] = volVars.moleFraction(FluidSystem::gPhaseIdx, FluidSystem::nCompIdx);
246 else if (!wettingPresent && nonwettingPresent)
248 newPhasePresence = Indices::gPhaseOnly;
249 priVars[Indices::switch1Idx] = volVars.moleFraction(FluidSystem::gPhaseIdx, FluidSystem::wCompIdx);
250 priVars[Indices::switch2Idx] = volVars.moleFraction(FluidSystem::gPhaseIdx, FluidSystem::nCompIdx);
255 bool nonwettingPresent =
false;
256 bool gasPresent =
false;
262 if (volVars.saturation(FluidSystem::nPhaseIdx) <= Smin)
267 std::cout <<
"NAPL phase disappears at dof " << dofIdxGlobal
268 <<
", coordinates: " << globalPos <<
", sn: "
269 << volVars.saturation(FluidSystem::nPhaseIdx) << std::endl;
270 nonwettingPresent =
true;
275 Scalar xwg = volVars.moleFraction(FluidSystem::gPhaseIdx, FluidSystem::wCompIdx);
276 Scalar xgg = volVars.moleFraction(FluidSystem::gPhaseIdx, FluidSystem::gCompIdx);
277 Scalar xng = volVars.moleFraction(FluidSystem::gPhaseIdx, FluidSystem::nCompIdx);
284 if (xwg + xgg + xng > xgMax)
291 if (xwg + xgg + xng > xgMax)
295 std::cout <<
"gas phase appears at dof " << dofIdxGlobal
296 <<
", coordinates: " << globalPos <<
", xwg + xgg + xng: "
297 << xwg + xgg + xng << std::endl;
301 if (gasPresent && !nonwettingPresent)
303 newPhasePresence = Indices::threePhases;
304 priVars[Indices::switch1Idx] = volVars.saturation(FluidSystem::wPhaseIdx);
305 priVars[Indices::switch2Idx] = volVars.saturation(FluidSystem::nPhaseIdx);
307 else if (gasPresent && nonwettingPresent)
309 newPhasePresence = Indices::wgPhaseOnly;
310 priVars[Indices::switch1Idx] = volVars.saturation(FluidSystem::wPhaseIdx);
311 priVars[Indices::switch2Idx] = volVars.moleFraction(FluidSystem::gPhaseIdx, FluidSystem::nCompIdx);
313 else if (!gasPresent && nonwettingPresent)
315 newPhasePresence = Indices::wPhaseOnly;
316 priVars[Indices::switch1Idx] = volVars.moleFraction(FluidSystem::wPhaseIdx, FluidSystem::gCompIdx);
317 priVars[Indices::switch2Idx] = volVars.moleFraction(FluidSystem::wPhaseIdx, FluidSystem::nCompIdx);
322 bool nonwettingPresent =
false;
323 bool wettingPresent =
false;
326 Scalar xnn = volVars.moleFraction(FluidSystem::nPhaseIdx, FluidSystem::nCompIdx);
344 std::cout <<
"NAPL phase appears at dof " << dofIdxGlobal
345 <<
", coordinates: " << globalPos <<
", xnn: "
347 nonwettingPresent =
true;
350 Scalar xww = volVars.moleFraction(FluidSystem::wPhaseIdx, FluidSystem::wCompIdx);
367 std::cout <<
"water phase appears at dof " << dofIdxGlobal
368 <<
", coordinates: " << globalPos <<
", xww=xwg*pg/pwsat : "
370 wettingPresent =
true;
372 if (wettingPresent && !nonwettingPresent)
374 newPhasePresence = Indices::wgPhaseOnly;
375 priVars[Indices::switch1Idx] = 0.0001;
376 priVars[Indices::switch2Idx] = volVars.moleFraction(FluidSystem::gPhaseIdx, FluidSystem::nCompIdx);
378 else if (wettingPresent && nonwettingPresent)
380 newPhasePresence = Indices::threePhases;
381 priVars[Indices::switch1Idx] = 0.0001;
382 priVars[Indices::switch2Idx] = 0.0001;
384 else if (!wettingPresent && nonwettingPresent)
386 newPhasePresence = Indices::gnPhaseOnly;
387 priVars[Indices::switch1Idx] = volVars.moleFraction(FluidSystem::gPhaseIdx, FluidSystem::wCompIdx);
388 priVars[Indices::switch2Idx] = 0.0001;
393 bool nonwettingPresent =
false;
394 bool gasPresent =
false;
395 bool wettingPresent =
false;
398 Scalar xnn = volVars.moleFraction(FluidSystem::nPhaseIdx, FluidSystem::nCompIdx);
415 std::cout <<
"NAPL phase appears at dof " << dofIdxGlobal
416 <<
", coordinates: " << globalPos <<
", xnn: "
418 nonwettingPresent =
true;
421 Scalar Smin = -1.e-6;
425 if (volVars.saturation(FluidSystem::gPhaseIdx) <= Smin)
430 std::cout <<
"Gas phase disappears at dof " << dofIdxGlobal
431 <<
", coordinates: " << globalPos <<
", sg: "
432 << volVars.saturation(FluidSystem::gPhaseIdx) << std::endl;
440 if (volVars.saturation(FluidSystem::wPhaseIdx) <= Smin)
445 std::cout <<
"Water phase disappears at dof " << dofIdxGlobal
446 <<
", coordinates: " << globalPos <<
", sw: "
447 << volVars.saturation(FluidSystem::wPhaseIdx) << std::endl;
448 wettingPresent =
true;
451 if (!gasPresent && nonwettingPresent && wettingPresent)
453 newPhasePresence = Indices::gnPhaseOnly;
454 priVars[Indices::switch1Idx] = volVars.moleFraction(FluidSystem::gPhaseIdx, FluidSystem::wCompIdx);
455 priVars[Indices::switch2Idx] = 0.0001;
457 else if (!gasPresent && nonwettingPresent && !wettingPresent)
459 newPhasePresence = Indices::threePhases;
460 priVars[Indices::switch1Idx] = volVars.saturation(FluidSystem::wPhaseIdx);
461 priVars[Indices::switch2Idx] = 0.0;
463 else if (gasPresent && !nonwettingPresent && !wettingPresent)
465 newPhasePresence = Indices::wPhaseOnly;
466 priVars[Indices::switch1Idx] = volVars.moleFraction(FluidSystem::wPhaseIdx, FluidSystem::gCompIdx);
467 priVars[Indices::switch2Idx] = volVars.moleFraction(FluidSystem::wPhaseIdx, FluidSystem::nCompIdx);
469 else if (!gasPresent && !nonwettingPresent && wettingPresent)
471 newPhasePresence = Indices::gPhaseOnly;
472 priVars[Indices::switch1Idx] = volVars.moleFraction(FluidSystem::gPhaseIdx, FluidSystem::wCompIdx);
473 priVars[Indices::switch2Idx] = volVars.moleFraction(FluidSystem::gPhaseIdx, FluidSystem::nCompIdx);
477 priVars.setState(newPhasePresence);
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: 3p3c/primaryvariableswitch.hh:40
bool update_(typename VolumeVariables::PrimaryVariables &priVars, const VolumeVariables &volVars, std::size_t dofIdxGlobal, const GlobalPosition &globalPos)
Definition: 3p3c/primaryvariableswitch.hh:51
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.