43    bool update_(
typename VolumeVariables::PrimaryVariables& priVars,
 
   44                 const VolumeVariables& volVars,
 
   45                 IndexType dofIdxGlobal,
 
   46                 const GlobalPosition& globalPos)
 
   48        using Scalar = 
typename VolumeVariables::PrimaryVariables::value_type;
 
   50        using FluidSystem = 
typename VolumeVariables::FluidSystem;
 
   51        static constexpr int phase0Idx = FluidSystem::phase0Idx;
 
   52        static constexpr int phase1Idx = FluidSystem::phase1Idx;
 
   53        static constexpr int comp0Idx = FluidSystem::comp0Idx;
 
   54        static constexpr int comp1Idx = FluidSystem::comp1Idx;
 
   56        static constexpr bool useMoles = VolumeVariables::useMoles();
 
   57        static constexpr auto formulation = VolumeVariables::priVarFormulation();
 
   59                        "Chosen TwoPFormulation not supported!");
 
   61        using Indices = 
typename VolumeVariables::Indices;
 
   62        static constexpr int switchIdx = Indices::switchIdx;
 
   65        bool wouldSwitch = 
false;
 
   66        int phasePresence = priVars.state();
 
   67        int newPhasePresence = phasePresence;
 
   70        typename FluidSystem::ParameterCache paramCache;
 
   73        if (phasePresence == Indices::secondPhaseOnly)
 
   76            Scalar xnw = volVars.moleFraction(phase1Idx, comp0Idx);
 
   77            Scalar xnwMax = FluidSystem::equilibriumMoleFraction(volVars.fluidState(), paramCache, phase1Idx);
 
   91                    std::cout << 
"First phase (" << FluidSystem::phaseName(phase0Idx) << 
") appears at dof " << dofIdxGlobal
 
   92                              << 
", coordinates: " << globalPos
 
   93                              << 
", x^" << FluidSystem::componentName(comp0Idx) << 
"_" << FluidSystem::phaseName(phase1Idx) << 
" > x_equilibrium: " 
   94                              << xnw << 
" > " << xnwMax << std::endl;
 
   95                newPhasePresence = Indices::bothPhases;
 
   97                    priVars[switchIdx] = 0.0;
 
   99                    priVars[switchIdx] = 1.0;
 
  102        else if (phasePresence == Indices::firstPhaseOnly)
 
  105            Scalar xwn = volVars.moleFraction(phase0Idx, comp1Idx);
 
  106            Scalar xwnMax = FluidSystem::equilibriumMoleFraction(volVars.fluidState(), paramCache, phase0Idx);
 
  120                    std::cout << 
"Second phase (" << FluidSystem::phaseName(phase1Idx) << 
") appears at dof " << dofIdxGlobal
 
  121                              << 
", coordinates: " << globalPos
 
  122                              << 
", x^" << FluidSystem::componentName(comp1Idx) << 
"_" << FluidSystem::phaseName(phase0Idx) << 
" > x_equilibrium: " 
  123                              << xwn << 
" > " << xwnMax << std::endl;
 
  124                newPhasePresence = Indices::bothPhases;
 
  126                    priVars[switchIdx] = 0.999;
 
  128                    priVars[switchIdx] = 0.001;
 
  132        else if (phasePresence == Indices::bothPhases)
 
  138            if (volVars.saturation(phase1Idx) <= Smin)
 
  143                    std::cout << 
"Second phase (" << FluidSystem::phaseName(phase1Idx) << 
") disappears at dof " << dofIdxGlobal
 
  144                              << 
", coordinates: " << globalPos
 
  145                              << 
", S_" << FluidSystem::phaseName(phase1Idx) << 
": " << volVars.saturation(phase1Idx)
 
  147                newPhasePresence = Indices::firstPhaseOnly;
 
  150                    priVars[switchIdx] = volVars.moleFraction(phase0Idx, comp1Idx);
 
  152                    priVars[switchIdx] = volVars.massFraction(phase0Idx, comp1Idx);
 
  154            else if (volVars.saturation(phase0Idx) <= Smin)
 
  159                    std::cout << 
"First phase (" << FluidSystem::phaseName(phase0Idx) << 
") disappears at dof " << dofIdxGlobal
 
  160                              << 
", coordinates: " << globalPos
 
  161                              << 
", S_" << FluidSystem::phaseName(phase0Idx) << 
": " << volVars.saturation(phase0Idx)
 
  163                newPhasePresence = Indices::secondPhaseOnly;
 
  166                    priVars[switchIdx] = volVars.moleFraction(phase1Idx, comp0Idx);
 
  168                    priVars[switchIdx] = volVars.massFraction(phase1Idx, comp0Idx);
 
  172        priVars.setState(newPhasePresence);
 
  174        return phasePresence != newPhasePresence;