pressure_equality.f90 Source File


This file depends on

sourcefile~~pressure_equality.f90~~EfferentGraph sourcefile~pressure_equality.f90 pressure_equality.f90 sourcefile~ar_models.f90 ar_models.f90 sourcefile~pressure_equality.f90->sourcefile~ar_models.f90 sourcefile~constants.f90 constants.f90 sourcefile~pressure_equality.f90->sourcefile~constants.f90 sourcefile~ar_models.f90->sourcefile~constants.f90 sourcefile~base.f90 base.f90 sourcefile~ar_models.f90->sourcefile~base.f90 sourcefile~math.f90 math.f90 sourcefile~ar_models.f90->sourcefile~math.f90 sourcefile~substance.f90 substance.f90 sourcefile~base.f90->sourcefile~substance.f90 sourcefile~math.f90->sourcefile~constants.f90 sourcefile~auxiliar.f90~2 auxiliar.f90 sourcefile~math.f90->sourcefile~auxiliar.f90~2 sourcefile~continuation.f90 continuation.f90 sourcefile~math.f90->sourcefile~continuation.f90 sourcefile~linalg.f90 linalg.f90 sourcefile~math.f90->sourcefile~linalg.f90 sourcefile~auxiliar.f90~2->sourcefile~constants.f90 sourcefile~continuation.f90->sourcefile~constants.f90 sourcefile~continuation.f90->sourcefile~auxiliar.f90~2 sourcefile~continuation.f90->sourcefile~linalg.f90 sourcefile~linalg.f90->sourcefile~constants.f90 sourcefile~linalg.f90->sourcefile~auxiliar.f90~2 sourcefile~substance.f90->sourcefile~constants.f90

Files dependent on this one

sourcefile~~pressure_equality.f90~~AfferentGraph sourcefile~pressure_equality.f90 pressure_equality.f90 sourcefile~flash.f90 flash.f90 sourcefile~flash.f90->sourcefile~pressure_equality.f90 sourcefile~equilibria.f90 equilibria.f90 sourcefile~equilibria.f90->sourcefile~flash.f90 sourcefile~yaeos.f90 yaeos.f90 sourcefile~yaeos.f90->sourcefile~equilibria.f90

Source Code

module yaeos__solvers_pressure_equality
   !! # Fixed-volume two-phase pressure equality
   !! Solve phase pressure equality for a two-phase state at fixed temperature and total volume.
   !!
   !! # Description
   !! The routine treats the heavy-phase volume as the Newton unknown and
   !! obtains the light-phase volume from the overall volume balance. It returns
   !! the average phase pressure once the two phase pressures agree.
   !!
   !! # Examples
   !! ```fortran
   !! call pressure_equality_V_beta_xy(model, T, V, beta, x, y, Vx, Vy, P)
   !! ```
   use yaeos__constants, only: pr, R
   use yaeos__models_ar, only: ArModel

   implicit none

contains

   subroutine pressure_equality_V_beta_xy(model, T, V, beta, x, y, vx, vy, P)
      !! # pressure_equality_V_beta_xy
      !! Solve pressure equality between two phases at a given temperature,
      !! total volume, vapor molar fractions and compositions.
      !!
      !! # Description
      !! Uses \(V=(1-\beta)V_x+\beta V_y\) to express `Vy` as a function of
      !! `Vx`, then applies Newton iteration to \(P_x(V_x)-P_y(V_y)=0\). The
      !! liquid volume is constrained to remain above the model's covolume.
      !! A failure to converge within the internal iteration cap returns
      !! `P=-1` after 100 iterations and writes a warning to the error unit.
      !!
      !! # Examples
      !! See the module-level call pattern; `x` and `y` must be normalized
      !! phase compositions and `beta` is the light-phase fraction.
      use iso_fortran_env, only: error_unit

      class(ArModel), intent(in) :: model !! EOS used to evaluate both phase pressures.
      real(pr), intent(in) :: T !! Temperature [K]
      real(pr), intent(in) :: V !! Overall molar volume of the two-phase system [L/mol]
      real(pr), intent(in) :: beta !! Molar fraction of light-phase
      real(pr), intent(in) :: x(:) !! Molar fractions of heavy-phase
      real(pr), intent(in) :: y(:) !! Molar fractions of light-phase
      real(pr), intent(in out) :: Vx !! Heavy-phase molar volume [L/mol]
      real(pr), intent(in out) :: Vy !! Light-Phase molar volume [L/mol]
      real(pr), intent(out) :: P !! Pressure [bar]

      real(pr) :: Bx !! Heavy-phase covolume from `get_v0` [L/mol]
      real(pr) :: dVydVx !! Derivative of Vy wrt Vx

      ! Pressure equality newton functions
      real(pr) :: h !! Pressure-equality residual \(P_y - P_x\) [bar]
      real(pr) :: dh !! \(dh/dV_x\)
      real(pr) :: stepv

      real(pr) :: dPxdV
      real(pr) :: dPydV
      real(pr) :: Px
      real(pr) :: Py

      integer :: its !! Iteration count.

      dVydVx = -(1 - beta)/beta
      Bx = model%get_v0(x, 0.1_pr, T)

      ! First evaluation will be with Vx = 1.625*Bx
      if (Vx < Bx) Vx = 1.625_pr*Bx

      call model%pressure(x, Vx, T, Px, dpdv=dPxdV)

      do while (Px < 0 .or. dPxdV >= 0)
         Vx = Vx - 0.2*(Vx - Bx)
         call model%pressure(x, Vx, T, Px, dpdv=dPxdV)
      end do

      Vy = (V - (1 - beta)*Vx)/beta

      h = 1.0
      its = 0
      do while (abs(h) > 1.d-4)
         ! Newton for solving P equality, with Vx as independent variable
         its = its + 1

         call model%pressure(x, Vx, T, Px, dpdv=dPxdV)
         call model%pressure(y, Vy, T, Py, dpdv=dPydV)

         h = Py - Px
         dh = -dPydV * dVydVx - dPxdV
         stepv = -h/dh

         if (its >= 10) stepv = stepv/2

         Vx = Vx + stepv

         do while (Vx < 1.001*Bx)
            stepv = stepv/2
            Vx = Vx - stepv
         end do

         Vy = (v - (1 - beta)*Vx)/beta

         if (its >= 100) then
            write (error_unit, *) "WARN(FLASH_VT): volume convergence problems", Px, Py
            P = -1.0
            return
         end if
      end do

      call model%pressure(x, Vx, T, Px)
      call model%pressure(y, Vy, T, Py)
      P = (Px + Py) * 0.5_pr
   end subroutine pressure_equality_V_beta_xy
end module yaeos__solvers_pressure_equality