Class PhaseSrkCPAandersonMixing

All Implemented Interfaces:
Serializable, Cloneable, PhaseCPAInterface, PhaseEosInterface, PhaseInterface, ThermodynamicConstantsInterface

public class PhaseSrkCPAandersonMixing extends PhaseSrkCPAs
Anderson-accelerated nested CPA phase solver.

Retains the outer Halley iteration for molar volume from Michelsen's nested approach but replaces the inner successive substitution (SS) loop with Anderson acceleration (mixing depth m=3). For the site fraction equations X_k = 1 / (1 + sum_j n_j Delta_kj X_j / V), Anderson mixing achieves superlinear convergence (equivalent to GMRES for linear problems), typically converging in 3-5 iterations compared to 5-15 for plain SS.

The outer loop and derivative computation (initCPAMatrix) follow the standard nested approach, using the implicit function theorem to compute dF_CPA/dV from the converged X and Hessian.

References:

  • D.G.M. Anderson, Iterative procedures for nonlinear integral equations, J. ACM 12 (1965) 547-560.
  • H.F. Walker and P. Ni, Anderson acceleration for fixed-point iterations, SIAM J. Numer. Anal. 49 (2011) 1715-1735.
  • M.L. Michelsen, Robust and efficient solution procedures for association models, Ind. Eng. Chem. Res. 45 (2006) 8449-8453.
Version:
1.0
Author:
Even Solbraa
See Also:
  • Field Details

    • serialVersionUID

      private static final long serialVersionUID
      Serialization version UID.
      See Also:
    • logger

      private static final org.apache.logging.log4j.Logger logger
      Logger object for class.
    • ANDERSON_M

      private static final int ANDERSON_M
      Anderson mixing depth (number of history vectors).
      See Also:
    • MAX_INNER_ITERS

      private static final int MAX_INNER_ITERS
      Maximum inner (site fraction) iterations per outer step.
      See Also:
    • INNER_TOL

      private static final double INNER_TOL
      Inner loop convergence tolerance.
      See Also:
    • MAX_OUTER_ITERS

      private static final int MAX_OUTER_ITERS
      Maximum outer (volume) iterations.
      See Also:
    • OUTER_TOL

      private static final double OUTER_TOL
      Outer loop convergence tolerance.
      See Also:
    • callCount

      private static volatile long callCount
      Total molarVolume calls.
    • totalOuterIters

      private static volatile long totalOuterIters
      Total outer iterations across all calls.
    • totalInnerIters

      private static volatile long totalInnerIters
      Total inner iterations across all calls.
    • andersonConvergedCount

      private static volatile long andersonConvergedCount
      Calls where Anderson converged vs needed Newton fallback.
    • newtonFallbackCount

      private static volatile long newtonFallbackCount
      Fallbacks to Newton in inner loop.
    • workKlk

      private transient double[][] workKlk
    • workHess

      private transient double[][] workHess
    • workKsi

      private transient double[] workKsi
    • workM

      private transient double[] workM
    • workKlkKsi

      private transient double[] workKlkKsi
    • workXV

      private transient double[] workXV
    • workNs

      private transient int workNs
  • Constructor Details

    • PhaseSrkCPAandersonMixing

      public PhaseSrkCPAandersonMixing()
      Constructor for PhaseSrkCPAandersonMixing.
  • Method Details

    • resetProfileCounters

      public static void resetProfileCounters()
      Reset profiling counters.
    • getProfileSummary

      public static String getProfileSummary()
      Get profiling summary string.
      Returns:
      a summary of profiling data
    • clone

      public PhaseSrkCPAandersonMixing clone()

      clone.

      Specified by:
      clone in interface PhaseInterface
      Overrides:
      clone in class PhaseSrkCPAs
      Returns:
      a PhaseInterface object
    • addComponent

      public void addComponent(String name, double moles, double molesInPhase, int compNumber)

      Add component to component array and update moles variables.

      Specified by:
      addComponent in interface PhaseInterface
      Overrides:
      addComponent in class PhaseSrkCPAs
      Parameters:
      name - Name of component.
      moles - Total number of moles of component.
      molesInPhase - Number of moles in phase.
      compNumber - Index number of component in phase object component array.
    • molarVolume

      public double molarVolume(double pressure, double temperature, double A, double B, PhaseType pt) throws IsNaNException, TooManyIterationsException

      molarVolume.

      Molar volume calculation using the Halley outer loop for volume and Anderson-accelerated successive substitution for the site fraction inner loop. The Halley step uses the implicit function theorem to compute dF_CPA/dV derivatives.

      Specified by:
      molarVolume in interface PhaseInterface
      Overrides:
      molarVolume in class PhaseSrkCPA
      Parameters:
      pressure - a double
      temperature - a double
      A - a double
      B - a double
      pt - the PhaseType of the phase
      Returns:
      a double
      Throws:
      IsNaNException - if any.
      TooManyIterationsException - if any.
    • solveXAnderson

      private int solveXAnderson(int ns)
      Solve the site fraction equations using Anderson-accelerated successive substitution.

      The fixed-point map is: f_k(X) = 1 / (1 + sum_j n_j Delta_kj X_j / V). Anderson acceleration (mixing depth m=3) is applied to this map to achieve superlinear convergence. The algorithm uses QR-based least-squares for the mixing coefficients.

      Parameters:
      ns - number of association sites
      Returns:
      number of inner iterations used
    • solveAndersonLeastSquares

      private static double[] solveAndersonLeastSquares(double[][] gMatrix, double[] gVec, int ns, int histLen)
      Solve the Anderson least-squares problem: min ||g - G * gamma||^2.

      Uses the normal equations: (G^T G) gamma = G^T g. The system is at most m x m (typically 3x3) so a direct solve via Gaussian elimination is efficient and stable.

      Parameters:
      gMatrix - history of residual differences (m x ns, using rows 0..histLen-1)
      gVec - current residual vector (length ns)
      ns - number of association sites
      histLen - number of stored history vectors
      Returns:
      mixing coefficients gamma (length histLen)
    • ensureWorkArrays

      private void ensureWorkArrays(int ns)
      Ensure work arrays are allocated for the given association site count.
      Parameters:
      ns - number of association sites
    • initCPAMatrix

      public void initCPAMatrix(int type)

      initCPAMatrix.

      Override CPA matrix initialization for efficient volume derivative computation using Gaussian elimination instead of EJML matrix inversion. This avoids the dependency on hessianInvers which is only set during solveX().

      Overrides:
      initCPAMatrix in class PhaseSrkCPA
      Parameters:
      type - 1 for volume derivatives, 2+ for temperature/composition
    • solveLinearSystem

      private static boolean solveLinearSystem(double[][] a, double[] b, int n)
      Solve a linear system Ax = b in-place using Gaussian elimination with partial pivoting.
      Parameters:
      a - coefficient matrix (modified in place)
      b - right-hand side (solution on return)
      n - system dimension
      Returns:
      true if solve succeeded
    • updateDeltaWithG

      private void updateDeltaWithG()
      Update delta = deltaNog * g.
    • setXsiteOnComponents

      private void setXsiteOnComponents(double[] xSite)
      Set XA site fractions from flat array onto component objects.
      Parameters:
      xSite - array of site fractions
    • readXsiteFromComponents

      private void readXsiteFromComponents(double[] xSite)
      Read XA site fractions from component objects into flat array.
      Parameters:
      xSite - array to fill
    • molarVolumeChangePhase

      public double molarVolumeChangePhase(double pressure, double temperature, double A, double B, PhaseType pt) throws IsNaNException, TooManyIterationsException

      molarVolumeChangePhase.

      Overrides:
      molarVolumeChangePhase in class PhaseSrkCPA
      Parameters:
      pressure - a double
      temperature - a double
      A - a double
      B - a double
      pt - the PhaseType of the phase
      Returns:
      a double
      Throws:
      IsNaNException - if any.
      TooManyIterationsException - if any.