39    bool update_(
typename VolumeVariables::PrimaryVariables& priVars,
 
   40                 const VolumeVariables& volVars,
 
   41                 std::size_t dofIdxGlobal,
 
   42                 const GlobalPosition& globalPos)
 
   44        using PrimaryVariables = 
typename VolumeVariables::PrimaryVariables;
 
   45        using Scalar = 
typename PrimaryVariables::value_type;
 
   46        using Indices = 
typename VolumeVariables::Indices;
 
   47        using FluidSystem = 
typename VolumeVariables::FluidSystem;
 
   50        bool wouldSwitch = 
false;
 
   51        auto phasePresence = priVars.state();
 
   52        auto newPhasePresence = phasePresence;
 
   55        if (phasePresence == Indices::threePhases)
 
   61            if (volVars.saturation(FluidSystem::gPhaseIdx) <= Smin)
 
   66                    std::cout << 
"Gas phase disappears at dof " << dofIdxGlobal
 
   67                              << 
", coordinates: " << globalPos << 
", sg: " 
   68                              << volVars.saturation(FluidSystem::gPhaseIdx) << std::endl;
 
   69                newPhasePresence = Indices::wnPhaseOnly;
 
   71                priVars[Indices::switch1Idx] = volVars.moleFraction(FluidSystem::wPhaseIdx, FluidSystem::gCompIdx);
 
   73            else if (volVars.saturation(FluidSystem::wPhaseIdx) <= Smin)
 
   78                    std::cout << 
"Water phase disappears at dof " << dofIdxGlobal
 
   79                              << 
", coordinates: " << globalPos << 
", sw: " 
   80                              << volVars.saturation(FluidSystem::wPhaseIdx) << std::endl;
 
   81                newPhasePresence = Indices::gnPhaseOnly;
 
   83                priVars[Indices::switch1Idx] = volVars.moleFraction(FluidSystem::gPhaseIdx, FluidSystem::wCompIdx);
 
   85            else if (volVars.saturation(FluidSystem::nPhaseIdx) <= Smin)
 
   90                    std::cout << 
"NAPL phase disappears at dof " << dofIdxGlobal
 
   91                              << 
", coordinates: " << globalPos << 
", sn: " 
   92                              << volVars.saturation(FluidSystem::nPhaseIdx) << std::endl;
 
   93                newPhasePresence = Indices::wgPhaseOnly;
 
   95                priVars[Indices::switch2Idx] = volVars.moleFraction(FluidSystem::gPhaseIdx, FluidSystem::nCompIdx);
 
   98        else if (phasePresence == Indices::wPhaseOnly)
 
  100            bool gasPresent = 
false;
 
  101            bool nonwettingPresent = 
false;
 
  104            Scalar xwg = volVars.moleFraction(FluidSystem::gPhaseIdx, FluidSystem::wCompIdx);
 
  105            Scalar xgg = volVars.moleFraction(FluidSystem::gPhaseIdx, FluidSystem::gCompIdx);
 
  106            Scalar xng = volVars.moleFraction(FluidSystem::gPhaseIdx, FluidSystem::nCompIdx);
 
  114            if (xwg + xgg + xng > xgMax)
 
  121            if (xwg + xgg + xng > xgMax)
 
  125                    std::cout << 
"gas phase appears at dof " << dofIdxGlobal
 
  126                              << 
", coordinates: " << globalPos << 
", xwg + xgg + xng: " 
  127                              << xwg + xgg + xng << std::endl;
 
  132            Scalar xnn = volVars.moleFraction(FluidSystem::nPhaseIdx, FluidSystem::nCompIdx);
 
  152                    std::cout << 
"NAPL phase appears at dof " << dofIdxGlobal
 
  153                              << 
", coordinates: " << globalPos << 
", xnn: " 
  155                nonwettingPresent = 
true;
 
  158            if (gasPresent && !nonwettingPresent)
 
  160                newPhasePresence = Indices::wgPhaseOnly;
 
  161                priVars[Indices::switch1Idx] = 0.9999;
 
  162                priVars[Indices::switch2Idx] = 0.0001;
 
  164            else if (gasPresent && nonwettingPresent)
 
  166                newPhasePresence = Indices::threePhases;
 
  167                priVars[Indices::switch1Idx] = 0.9999;
 
  168                priVars[Indices::switch2Idx] = 0.0001;
 
  170            else if (!gasPresent && nonwettingPresent)
 
  172                newPhasePresence = Indices::wnPhaseOnly;
 
  173                priVars[Indices::switch1Idx] = volVars.moleFraction(FluidSystem::wPhaseIdx, FluidSystem::gCompIdx);
 
  174                priVars[Indices::switch2Idx] = 0.0001;
 
  177        else if (phasePresence == Indices::gnPhaseOnly)
 
  179            bool nonwettingPresent = 
false;
 
  180            bool wettingPresent = 
false;
 
  186            if (volVars.saturation(FluidSystem::nPhaseIdx) <= Smin)
 
  191                    std::cout << 
"NAPL phase disappears at dof " << dofIdxGlobal
 
  192                              << 
", coordinates: " << globalPos << 
", sn: " 
  193                              << volVars.saturation(FluidSystem::nPhaseIdx) << std::endl;
 
  194                nonwettingPresent = 
true;
 
  199            Scalar xww = volVars.moleFraction(FluidSystem::wPhaseIdx, FluidSystem::wCompIdx);
 
  216                    std::cout << 
"water phase appears at dof " << dofIdxGlobal
 
  217                              << 
", coordinates: " << globalPos << 
", xww=xwg*pg/pwsat : " 
  219                wettingPresent = 
true;
 
  222            if (wettingPresent && !nonwettingPresent)
 
  224                newPhasePresence = Indices::threePhases;
 
  225                priVars[Indices::switch1Idx] = 0.0001;
 
  226                priVars[Indices::switch2Idx] = volVars.saturation(FluidSystem::nPhaseIdx);
 
  228            else if (wettingPresent && nonwettingPresent)
 
  230                newPhasePresence = Indices::wgPhaseOnly;
 
  231                priVars[Indices::switch1Idx] = 0.0001;
 
  232                priVars[Indices::switch2Idx] = volVars.moleFraction(FluidSystem::gPhaseIdx, FluidSystem::nCompIdx);
 
  234            else if (!wettingPresent && nonwettingPresent)
 
  236                newPhasePresence = Indices::gPhaseOnly;
 
  237                priVars[Indices::switch1Idx] = volVars.moleFraction(FluidSystem::gPhaseIdx, FluidSystem::wCompIdx);
 
  238                priVars[Indices::switch2Idx] = volVars.moleFraction(FluidSystem::gPhaseIdx, FluidSystem::nCompIdx);
 
  241        else if (phasePresence == Indices::wnPhaseOnly)
 
  243            bool nonwettingPresent = 
false;
 
  244            bool gasPresent = 
false;
 
  250            if (volVars.saturation(FluidSystem::nPhaseIdx) <= Smin)
 
  255                    std::cout << 
"NAPL phase disappears at dof " << dofIdxGlobal
 
  256                              << 
", coordinates: " << globalPos << 
", sn: " 
  257                              << volVars.saturation(FluidSystem::nPhaseIdx) << std::endl;
 
  258                nonwettingPresent = 
true;
 
  263            Scalar xwg = volVars.moleFraction(FluidSystem::gPhaseIdx, FluidSystem::wCompIdx);
 
  264            Scalar xgg = volVars.moleFraction(FluidSystem::gPhaseIdx, FluidSystem::gCompIdx);
 
  265            Scalar xng = volVars.moleFraction(FluidSystem::gPhaseIdx, FluidSystem::nCompIdx);
 
  272            if (xwg + xgg + xng > xgMax)
 
  279            if (xwg + xgg + xng > xgMax)
 
  283                    std::cout << 
"gas phase appears at dof " << dofIdxGlobal
 
  284                              << 
", coordinates: " << globalPos << 
", xwg + xgg + xng: " 
  285                              << xwg + xgg + xng << std::endl;
 
  289            if (gasPresent && !nonwettingPresent)
 
  291                newPhasePresence = Indices::threePhases;
 
  292                priVars[Indices::switch1Idx] = volVars.saturation(FluidSystem::wPhaseIdx);
 
  293                priVars[Indices::switch2Idx] = volVars.saturation(FluidSystem::nPhaseIdx);
 
  295            else if (gasPresent && nonwettingPresent)
 
  297                newPhasePresence = Indices::wgPhaseOnly;
 
  298                priVars[Indices::switch1Idx] = volVars.saturation(FluidSystem::wPhaseIdx);
 
  299                priVars[Indices::switch2Idx] = volVars.moleFraction(FluidSystem::gPhaseIdx, FluidSystem::nCompIdx);
 
  301            else if (!gasPresent && nonwettingPresent)
 
  303                newPhasePresence = Indices::wPhaseOnly;
 
  304                priVars[Indices::switch1Idx] = volVars.moleFraction(FluidSystem::wPhaseIdx, FluidSystem::gCompIdx);
 
  305                priVars[Indices::switch2Idx] = volVars.moleFraction(FluidSystem::wPhaseIdx, FluidSystem::nCompIdx);
 
  308        else if (phasePresence == Indices::gPhaseOnly)
 
  310            bool nonwettingPresent = 
false;
 
  311            bool wettingPresent = 
false;
 
  314            Scalar xnn = volVars.moleFraction(FluidSystem::nPhaseIdx, FluidSystem::nCompIdx);
 
  332                    std::cout << 
"NAPL phase appears at dof " << dofIdxGlobal
 
  333                              << 
", coordinates: " << globalPos << 
", xnn: " 
  335                nonwettingPresent = 
true;
 
  338            Scalar xww = volVars.moleFraction(FluidSystem::wPhaseIdx, FluidSystem::wCompIdx);
 
  355                    std::cout << 
"water phase appears at dof " << dofIdxGlobal
 
  356                              << 
", coordinates: " << globalPos << 
", xww=xwg*pg/pwsat : " 
  358                wettingPresent = 
true;
 
  360            if (wettingPresent && !nonwettingPresent)
 
  362                newPhasePresence = Indices::wgPhaseOnly;
 
  363                priVars[Indices::switch1Idx] = 0.0001;
 
  364                priVars[Indices::switch2Idx] = volVars.moleFraction(FluidSystem::gPhaseIdx, FluidSystem::nCompIdx);
 
  366            else if (wettingPresent && nonwettingPresent)
 
  368                newPhasePresence = Indices::threePhases;
 
  369                priVars[Indices::switch1Idx] = 0.0001;
 
  370                priVars[Indices::switch2Idx] = 0.0001;
 
  372            else if (!wettingPresent && nonwettingPresent)
 
  374                newPhasePresence = Indices::gnPhaseOnly;
 
  375                priVars[Indices::switch1Idx] = volVars.moleFraction(FluidSystem::gPhaseIdx, FluidSystem::wCompIdx);
 
  376                priVars[Indices::switch2Idx] = 0.0001;
 
  379        else if (phasePresence == Indices::wgPhaseOnly)
 
  381            bool nonwettingPresent = 
false;
 
  382            bool gasPresent = 
false;
 
  383            bool wettingPresent = 
false;
 
  386            Scalar xnn = volVars.moleFraction(FluidSystem::nPhaseIdx, FluidSystem::nCompIdx);
 
  403                    std::cout << 
"NAPL phase appears at dof " << dofIdxGlobal
 
  404                              << 
", coordinates: " << globalPos << 
", xnn: " 
  406                nonwettingPresent = 
true;
 
  409            Scalar Smin = -1.e-6;
 
  413            if (volVars.saturation(FluidSystem::gPhaseIdx) <= Smin)
 
  418                    std::cout << 
"Gas phase disappears at dof " << dofIdxGlobal
 
  419                              << 
", coordinates: " << globalPos << 
", sg: " 
  420                              << volVars.saturation(FluidSystem::gPhaseIdx) << std::endl;
 
  428            if (volVars.saturation(FluidSystem::wPhaseIdx) <= Smin)
 
  433                    std::cout << 
"Water phase disappears at dof " << dofIdxGlobal
 
  434                              << 
", coordinates: " << globalPos << 
", sw: " 
  435                              << volVars.saturation(FluidSystem::wPhaseIdx) << std::endl;
 
  436                wettingPresent = 
true;
 
  439            if (!gasPresent && nonwettingPresent && wettingPresent)
 
  441                newPhasePresence = Indices::gnPhaseOnly;
 
  442                priVars[Indices::switch1Idx] = volVars.moleFraction(FluidSystem::gPhaseIdx, FluidSystem::wCompIdx);
 
  443                priVars[Indices::switch2Idx] = 0.0001;
 
  445            else if (!gasPresent && nonwettingPresent && !wettingPresent)
 
  447                newPhasePresence = Indices::threePhases;
 
  448                priVars[Indices::switch1Idx] = volVars.saturation(FluidSystem::wPhaseIdx);
 
  449                priVars[Indices::switch2Idx] = 0.0;
 
  451            else if (gasPresent && !nonwettingPresent && !wettingPresent)
 
  453                newPhasePresence = Indices::wPhaseOnly;
 
  454                priVars[Indices::switch1Idx] = volVars.moleFraction(FluidSystem::wPhaseIdx, FluidSystem::gCompIdx);
 
  455                priVars[Indices::switch2Idx] = volVars.moleFraction(FluidSystem::wPhaseIdx, FluidSystem::nCompIdx);
 
  457            else if (!gasPresent && !nonwettingPresent && wettingPresent)
 
  459                newPhasePresence = Indices::gPhaseOnly;
 
  460                priVars[Indices::switch1Idx] = volVars.moleFraction(FluidSystem::gPhaseIdx, FluidSystem::wCompIdx);
 
  461                priVars[Indices::switch2Idx] = volVars.moleFraction(FluidSystem::gPhaseIdx, FluidSystem::nCompIdx);
 
  465        priVars.setState(newPhasePresence);
 
  467        return phasePresence != newPhasePresence;