ge_models.f90 Source File


This file depends on

sourcefile~~ge_models.f90~~EfferentGraph sourcefile~ge_models.f90 ge_models.f90 sourcefile~base.f90 base.f90 sourcefile~ge_models.f90->sourcefile~base.f90 sourcefile~constants.f90 constants.f90 sourcefile~ge_models.f90->sourcefile~constants.f90 sourcefile~substance.f90 substance.f90 sourcefile~base.f90->sourcefile~substance.f90 sourcefile~substance.f90->sourcefile~constants.f90

Files dependent on this one

sourcefile~~ge_models.f90~~AfferentGraph sourcefile~ge_models.f90 ge_models.f90 sourcefile~consistency_gemodel.f90 consistency_gemodel.f90 sourcefile~consistency_gemodel.f90->sourcefile~ge_models.f90 sourcefile~flash.f90 flash.f90 sourcefile~flash.f90->sourcefile~ge_models.f90 sourcefile~flash_second_order.f90 flash_second_order.f90 sourcefile~flash_second_order.f90->sourcefile~ge_models.f90 sourcefile~stability.f90 stability.f90 sourcefile~flash_second_order.f90->sourcefile~stability.f90 sourcefile~gemodel_adiff_api.f90 gemodel_adiff_api.f90 sourcefile~gemodel_adiff_api.f90->sourcefile~ge_models.f90 sourcefile~huron_vidal.f90 huron_vidal.f90 sourcefile~huron_vidal.f90->sourcefile~ge_models.f90 sourcefile~nrtl_hv.f90 nrtl_hv.f90 sourcefile~huron_vidal.f90->sourcefile~nrtl_hv.f90 sourcefile~models.f90 models.f90 sourcefile~models.f90->sourcefile~ge_models.f90 sourcefile~models.f90->sourcefile~huron_vidal.f90 sourcefile~implementations.f90 implementations.f90 sourcefile~models.f90->sourcefile~implementations.f90 sourcefile~implementations.f90~2 implementations.f90 sourcefile~models.f90->sourcefile~implementations.f90~2 sourcefile~gerg2008.f90 gerg2008.f90 sourcefile~models.f90->sourcefile~gerg2008.f90 sourcefile~pc_saft.f90 pc_saft.f90 sourcefile~models.f90->sourcefile~pc_saft.f90 sourcefile~nrtl.f90 nrtl.f90 sourcefile~nrtl.f90->sourcefile~ge_models.f90 sourcefile~nrtl_hv.f90->sourcefile~ge_models.f90 sourcefile~stability.f90->sourcefile~ge_models.f90 sourcefile~tapenade_ge_api.f90 tapenade_ge_api.f90 sourcefile~tapenade_ge_api.f90->sourcefile~ge_models.f90 sourcefile~unifac.f90 unifac.f90 sourcefile~unifac.f90->sourcefile~ge_models.f90 sourcefile~uniquac.f90 uniquac.f90 sourcefile~uniquac.f90->sourcefile~ge_models.f90 sourcefile~consistency.f90 consistency.f90 sourcefile~consistency.f90->sourcefile~consistency_gemodel.f90 sourcefile~critical.f90 critical.f90 sourcefile~critical.f90->sourcefile~stability.f90 sourcefile~dortmund.f90 dortmund.f90 sourcefile~dortmund.f90->sourcefile~unifac.f90 sourcefile~equilibria.f90 equilibria.f90 sourcefile~equilibria.f90->sourcefile~flash.f90 sourcefile~equilibria.f90->sourcefile~flash_second_order.f90 sourcefile~equilibria.f90->sourcefile~stability.f90 sourcefile~equilibria.f90->sourcefile~critical.f90 sourcefile~flash_mp.f90 flash_mp.f90 sourcefile~equilibria.f90->sourcefile~flash_mp.f90 sourcefile~generalized_isoline.f90 generalized_isoline.f90 sourcefile~equilibria.f90->sourcefile~generalized_isoline.f90 sourcefile~phase_envelopes_pt.f90 phase_envelopes_pt.f90 sourcefile~equilibria.f90->sourcefile~phase_envelopes_pt.f90 sourcefile~flash_mp.f90->sourcefile~stability.f90 sourcefile~fluids.f90 fluids.f90 sourcefile~fluids.f90->sourcefile~models.f90 sourcefile~generalized_isoline.f90->sourcefile~stability.f90 sourcefile~implementations.f90->sourcefile~nrtl.f90 sourcefile~implementations.f90->sourcefile~nrtl_hv.f90 sourcefile~implementations.f90->sourcefile~unifac.f90 sourcefile~implementations.f90->sourcefile~uniquac.f90 sourcefile~implementations.f90->sourcefile~dortmund.f90 sourcefile~psrk.f90 psrk.f90 sourcefile~implementations.f90->sourcefile~psrk.f90 sourcefile~implementations.f90~2->sourcefile~huron_vidal.f90 sourcefile~implementations.f90~2->sourcefile~implementations.f90 sourcefile~psrk.f90->sourcefile~unifac.f90 sourcefile~yaeos.f90 yaeos.f90 sourcefile~yaeos.f90->sourcefile~models.f90 sourcefile~yaeos.f90->sourcefile~consistency.f90 sourcefile~yaeos.f90->sourcefile~equilibria.f90 sourcefile~gerg2008.f90->sourcefile~implementations.f90~2 sourcefile~pc_saft.f90->sourcefile~critical.f90 sourcefile~phase_envelopes_pt.f90->sourcefile~critical.f90

Source Code

module yaeos__models_ge
   !! # Excess-Gibbs models
   !! Abstract API and thermodynamic property relations for activity models.
   !!
   !! # Description
   !! A `GeModel` implementation supplies the excess Gibbs energy and its
   !! temperature/composition derivatives. The base type derives activity
   !! coefficients and excess enthalpy, entropy, and heat capacity from those
   !! derivatives. Energies are extensive and expressed in the units of
   !! \(nRT\), i.e. bar L with the library's `R` [bar L / (mol K)].
   !!
   !! # Examples
   !! ```fortran
   !! model = NRTL(A, B, alpha)
   !! call model%ln_activity_coefficient(n, T, ln_gamma)
   !! ```
   use yaeos__constants, only: pr, R
   use yaeos__models_base, only: BaseModel
   implicit none

   type, extends(BaseModel), abstract :: GeModel
      !! # GeModel
      !! Abstract base for models defined by an excess Gibbs energy.
      !!
      !! # Description
      !! Derived types implement the `excess_gibbs` deferred procedure. The
      !! inherited methods calculate activity coefficients and excess
      !! thermodynamic properties using the Gibbs-energy identities.
      !!
      !! # Examples
      !! See `NRTL`, `UNIQUAC`, and `UNIFAC` for concrete models.
   contains
      procedure(excess_gibbs), deferred :: excess_gibbs
      procedure :: ln_activity_coefficient => ln_activity_coefficient
      procedure :: excess_enthalpy => excess_enthalpy
      procedure :: excess_entropy => excess_entropy
      procedure :: excess_Cp => excess_Cp
   end type

   abstract interface
      subroutine excess_gibbs(self, n, T, Ge, GeT, GeT2, Gen, GeTn, Gen2)
         !! Calculate Excess Gibbs and its derivatives.
         !!
         import pr, GeModel
         class(GeModel), intent(in) :: self !! Model
         real(pr), intent(in) ::n(:) !! Moles vector
         real(pr), intent(in) :: T !! Temperature [K]
         real(pr), optional, intent(out) :: Ge !! Excess Gibbs free energy
         real(pr), optional, intent(out) :: GeT !! \(\frac{dG^E}{dT}\)
         real(pr), optional, intent(out) :: GeT2 !! \(\frac{d^2G^E}{dT^2}\)
         real(pr), optional, intent(out) :: Gen(size(n)) !! \(\frac{dG^E}{dn}\)
         real(pr), optional, intent(out) :: GeTn(size(n))
         !! \(\frac{d^2G^E}{dTdn}\)
         real(pr), optional, intent(out) :: Gen2(size(n), size(n))
         !! \(\frac{d^2G^E}{dn^2}\)
      end subroutine
   end interface

contains

   subroutine ln_activity_coefficient(self, n, T, lngamma, dlngammadT, dlngammadn)
      !! # ln_activity_coefficient
      !!
      !! # Description
      !! Calculate natural logarithm of activity coefficients.
      !!
      !! \[
      !!  \ln \gamma_i = \frac{1}{RT} \frac{\partial G^E}{\partial n_i}
      !! \]
      !!
      class(GeModel), intent(in) :: self !! Model
      real(pr), intent(in) :: n(:) !! Moles vector
      real(pr), intent(in) :: T !! Temperature [K]
      real(pr), optional, intent(out) :: lngamma(:)
      !! Natural logarithm of activity coefficients
      real(pr), optional, intent(out) :: dlngammadT(size(n))
      !! \(\frac{d\ln \gamma_i}{dT}\)
      real(pr), optional, intent(out) :: dlngammadn(size(n),size(n))
      !! \(\frac{d\ln \gamma_i}{dn_j}\)

      real(pr) :: Ge
      real(pr) :: Gen(size(n))
      real(pr) :: GeTn(size(n))
      real(pr) :: Gen2(size(n), size(n))

      logical :: tt
      logical :: dt
      logical :: dn

      tt = present(lngamma)
      dt = present(dlngammadT)
      dn = present(dlngammadn)

      if (tt .and. .not. dt .and. .not. dn) then
         call self%excess_gibbs(n, T, Ge=Ge, Gen=Gen)
      else if (.not. dn) then
         call self%excess_gibbs(n, T, Ge=Ge, Gen=Gen, GeTn=GeTn)
      else
         call self%excess_gibbs(n, T, Ge=Ge, Gen=Gen, GeTn=GeTn, Gen2=Gen2)
      end if

      if (tt) lngamma = Gen / (R * T)
      if (dt) dlngammadT = (GeTn - Gen / T) / (R * T)
      if (dn) dlngammadn = Gen2 / (R * T)
   end subroutine

   subroutine excess_enthalpy(self, n, T, He, HeT, Hen)
      !! Calculate Excess enthalpy and its derivatives.
      !!
      !! \[
      !! H^E = G^E - T \frac{\partial G^E}{\partial T}
      !! \]
      !!
      !! ## References
      !! [1] https://en.wikipedia.org/wiki/Gibbs%E2%80%93Helmholtz_equation
      !!
      class(GeModel), intent(in) :: self !! Model
      real(pr), intent(in) :: n(:) !! Moles vector
      real(pr), intent(in) :: T !! Temperature [K]
      real(pr), optional, intent(out) :: He !! Excess enthalpy
      real(pr), optional, intent(out) :: HeT !! \(\frac{dH^E}{dT}\)
      real(pr), optional, intent(out) :: Hen(:) !! \(\frac{dH^E}{dn}\)

      real(pr) :: Ge
      real(pr) :: GeT
      real(pr) :: GeT2
      real(pr) :: Gen(size(n))
      real(pr) :: GeTn(size(n))

      call self%excess_gibbs(&
         n, T, Ge=Ge, GeT=GeT, GeT2=GeT2, Gen=Gen, GeTn=GeTn &
         )

      if (present(He)) He = Ge - T*GeT
      if (present(HeT)) HeT = -T * GeT2
      if (present(Hen)) Hen = Gen - T*GeTn
   end subroutine excess_enthalpy

   subroutine excess_entropy(self, n, T, Se, SeT, Sen)
      !! # excess_entropy
      !!
      !! # Description
      !! Calculate Excess entropy and its derivatives.
      !!
      !! \[
      !! S^E = \frac{H^E - G^E}{T}
      !! \]
      !!
      class(GeModel), intent(in) :: self !! Model
      real(pr), intent(in) :: n(:) !! Moles vector
      real(pr), intent(in) :: T !! Temperature [K]
      real(pr), optional, intent(out) :: Se !! Excess entropy
      real(pr), optional, intent(out) :: SeT !! \(\frac{dS^E}{dT}\)
      real(pr), optional, intent(out) :: Sen(:) !! \(\frac{dS^E}{dn}\)

      real(pr) :: Ge
      real(pr) :: GeT
      real(pr) :: GeT2
      real(pr) :: GeTn(size(n))

      call self%excess_gibbs(n, T, Ge=Ge, GeT=GeT, GeT2=GeT2, GeTn=GeTn)

      if (present(Se)) Se = -GeT
      if (present(SeT)) SeT = -GeT2
      if (present(Sen)) Sen = -GeTn
   end subroutine excess_entropy

   subroutine excess_Cp(self, n, T, Cpe)
      !! # excess_Cp
      !!
      !! # Description
      !! Calculate Excess heat capacity.
      !!
      !! \[
      !! C_p^E = -T \frac{\partial^2 G^E}{\partial T^2}
      !! \]
      !!
      class(GeModel), intent(in) :: self !! Model
      real(pr), intent(in) :: n(:) !! Moles vector
      real(pr), intent(in) :: T !! Temperature [K]
      real(pr), intent(out) :: Cpe !! Excess heat capacity [bar L / K]

      real(pr) :: Ge
      real(pr) :: GeT
      real(pr) :: GeT2
      real(pr) :: Gen(size(n))
      real(pr) :: GeTn(size(n))

      call self%excess_gibbs(&
         n, T, Ge=Ge, GeT=GeT, GeT2=GeT2, Gen=Gen, GeTn=GeTn &
         )

      Cpe = -T * GeT2
   end subroutine excess_Cp
end module