Class PhaseSrkCPAandersonMixing
- All Implemented Interfaces:
Serializable, Cloneable, PhaseCPAInterface, PhaseEosInterface, PhaseInterface, ThermodynamicConstantsInterface
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 Summary
FieldsModifier and TypeFieldDescriptionprivate static final intAnderson mixing depth (number of history vectors).private static longCalls where Anderson converged vs needed Newton fallback.private static longTotal molarVolume calls.private static final doubleInner loop convergence tolerance.private static final org.apache.logging.log4j.LoggerLogger object for class.private static final intMaximum inner (site fraction) iterations per outer step.private static final intMaximum outer (volume) iterations.private static longFallbacks to Newton in inner loop.private static final doubleOuter loop convergence tolerance.private static final longSerialization version UID.private static longTotal inner iterations across all calls.private static longTotal outer iterations across all calls.private double[][]private double[][]private double[]private double[]private double[]private intprivate double[]Fields inherited from class PhaseSrkCPA
activeAccosComp, assSiteNumber, cpamix, cpaon, cpaSelect, crossAccociationScheme, delta, deltaNog, dFCPAdT, dFCPAdTdT, dFCPAdTdV, dFCPAdV, dFCPAdVdV, dFCPAdVdVdV, dFdNtemp, FCPA, gcpa, gcpav, gcpavv, gcpavvv, hcpatot, Klkni, moleculeNumber, oldTotalNumberOfAccociationSites, selfAccociationScheme, totalNumberOfAccociationSitesFields inherited from class Phase
beta, calcMolarVolume, chemSyst, componentArray, diElectricConstant, mixingRuleType, molarVolume, numberOfComponents, numberOfMolesInPhase, phaseVolume, physicalPropertyHandler, pressure, pt, refPhase, temperature, thermoPropertyModelName, useVolumeCorrection, ZFields inherited from interface ThermodynamicConstantsInterface
atm, avagadroNumber, boltzmannConstant, electronCharge, faradayConstant, gravity, molarMassAir, normalStateTemperature, pi, planckConstant, R, referencePressure, referenceTemperature, standardStateTemperature, vacumPermittivity -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddComponent(String name, double moles, double molesInPhase, int compNumber) Add component to component array and update moles variables.clone()clone.private voidensureWorkArrays(int ns) Ensure work arrays are allocated for the given association site count.static StringGet profiling summary string.voidinitCPAMatrix(int type) initCPAMatrix.doublemolarVolume(double pressure, double temperature, double A, double B, PhaseType pt) molarVolume.doublemolarVolumeChangePhase(double pressure, double temperature, double A, double B, PhaseType pt) molarVolumeChangePhase.private voidreadXsiteFromComponents(double[] xSite) Read XA site fractions from component objects into flat array.static voidReset profiling counters.private voidsetXsiteOnComponents(double[] xSite) Set XA site fractions from flat array onto component objects.private static double[]solveAndersonLeastSquares(double[][] gMatrix, double[] gVec, int ns, int histLen) Solve the Anderson least-squares problem: min ||g - G * gamma||^2.private static booleansolveLinearSystem(double[][] a, double[] b, int n) Solve a linear system Ax = b in-place using Gaussian elimination with partial pivoting.private intsolveXAnderson(int ns) Solve the site fraction equations using Anderson-accelerated successive substitution.private voidUpdate delta = deltaNog * g.Methods inherited from class PhaseSrkCPAs
calc_g, calc_lngV, calc_lngVV, calc_lngVVVMethods inherited from class PhaseSrkCPA
calcDelta, calcdFdNtemp, calcPressure, calcRootVolFinder, calcXsitedV, croeneckerProduct, dFCPAdT, dFCPAdTdT, dFCPAdTdV, dFCPAdV, dFCPAdVdV, dFCPAdVdVdV, dFdT, dFdTdT, dFdTdV, dFdV, dFdVdV, dFdVdVdV, FCPA, getCpaMixingRule, getCrossAssosiationScheme, getdFdNtemp, getF, getGcpa, getGcpav, getHcpatot, getTotalNumberOfAccociationSites, init, initCPAMatrixOld, initOld2, molarVolume2, molarVolumeOld, setGcpav, setHcpatot, setMixingRule, setTotalNumberOfAccociationSites, solveX, solveX2, solveX2Old, solveXOldMethods inherited from class PhaseEos
calcA, calcAi, calcAij, calcAiT, calcAT, calcATT, calcB, calcBi, calcBij, calcf, calcg, calcPressuredV, dFdN, dFdNdN, dFdNdT, dFdNdV, dFdxdxMatrix, dFdxdxMatrixSimple, dFdxMatrix, dFdxMatrixSimple, displayInteractionCoefficients, equals, F, fb, FB, fBB, FBB, FBD, FBT, fBV, FBV, FD, FDT, FDV, Fn, FnB, FnV, FT, FTT, FTV, fv, FV, fVV, FVV, fVVV, FVVV, gb, gBB, gBV, geta, geta, getA, getAresTV, getAT, getATT, getb, getb, getB, getCpres, getCvres, getdPdrho, getdPdTVn, getdPdVTn, getdrhodN, getdrhodP, getdrhodT, getdTVndSVnJaobiMatrix, getdUdSdSVn, getdUdSdVn, getdUdSVn, getdUdVdVSn, getdUdVSn, getdVdrho, getEosMixingRule, getf_loc, getg, getGradientVector, getGresTP, getHresdP, getHresTP, getJouleThomsonCoefficient, getKappa, getMixingRule, getMixingRuleName, getPressureAttractive, getPressureRepulsive, getSoundSpeed, getSresTP, getSresTV, getUSVHessianMatrix, gV, gVV, gVVV, resetMixingRule, setMixingRuleGEModelMethods inherited from class Phase
addComponent, addMoles, addMolesChemReac, calcA, calcAT, calcDiElectricConstant, calcDiElectricConstantdT, calcDiElectricConstantdTdT, calcMolarVolume, calcR, getActivityCoefficient, getActivityCoefficient, getActivityCoefficient, getActivityCoefficientSymetric, getActivityCoefficientUnSymetric, getAiT, getAlpha0_EOSCG, getAlpha0_GERG2008, getAlpha0_Leachman, getAlpha0_Leachman, getAlpha0_Vega, getAlphares_EOSCG, getAlphares_GERG2008, getAlphares_Leachman, getAlphares_Leachman, getAlphares_Vega, getAntoineVaporPressure, getBeta, getBi, getComponent, getComponent, getcomponentArray, getComponentNames, getComponents, getComponentWithIndex, getComposition, getCompressibilityX, getCompressibilityY, getCorrectedVolume, getCp, getCp, getCp0, getCv, getCv, getDensity, getDensity, getDensity_AGA8, getDensity_EOSCG, getDensity_GERG2008, getDensity_Leachman, getDensity_Leachman, getDensity_Vega, getDielectricConstant, getEnthalpy, getEnthalpy, getEnthalpydP, getEnthalpydT, getEntropy, getEntropy, getEntropydP, getEntropydT, getExcessGibbsEnergy, getExcessGibbsEnergySymetric, getFlowRate, getFugacity, getFugacity, getGamma, getGibbsEnergy, getHelmholtzEnergy, getHID, getInfiniteDiluteFugacity, getInfiniteDiluteFugacity, getInitType, getInternalEnergy, getInternalEnergy, getIsobaricThermalExpansivity, getIsothermalCompressibility, getJouleThomsonCoefficient, getLogActivityCoefficient, getLogInfiniteDiluteFugacity, getLogInfiniteDiluteFugacity, getLogPureComponentFugacity, getLogPureComponentFugacity, getMass, getMeanIonicActivity, getMixGibbsEnergy, getMixingRuleType, getModelName, getMolalMeanIonicActivity, getMolarComposition, getMolarMass, getMolarMass, getMolarVolume, getMolarVolume, getMoleFraction, getNumberOfComponents, getNumberOfIonicComponents, getNumberOfMolecularComponents, getNumberOfMolesInPhase, getOsmoticCoefficient, getOsmoticCoefficientOfWater, getOsmoticCoefficientOfWaterMolality, getpH, getpH, getPhase, getPhysicalProperties, getPhysicalPropertyModel, getPressure, getPressure, getProperties_EOSCG, getProperties_GERG2008, getProperties_Leachman, getProperties_Leachman, getProperties_Vega, getPseudoCriticalPressure, getPseudoCriticalTemperature, getPureComponentFugacity, getPureComponentFugacity, getRefPhase, getRefPhase, getSoundSpeed, getTemperature, getTemperature, getThermalConductivity, getThermalConductivity, getThermoPropertyModelName, getTotalVolume, getType, getViscosity, getViscosity, getVolume, getVolume, getWaterDensity, getWtFrac, getWtFrac, getWtFraction, getWtFractionOfWaxFormingComponents, getZ, getZvolcorr, groupTBPfractions, hasComponent, hasPlusFraction, hasTBPFraction, initPhysicalProperties, initPhysicalProperties, initRefPhases, initRefPhases, isConstantPhaseVolume, isMixingRuleDefined, normalize, removeComponent, resetPhysicalProperties, setAttractiveTerm, setBeta, setComponentArray, setConstantPhaseVolume, setEmptyFluid, setInitType, setMolarVolume, setMoleFractions, setNumberOfComponents, setParams, setPhysicalProperties, setPhysicalPropertyModel, setPpm, setPressure, setProperties, setRefPhase, setRefPhase, setTemperature, setTotalVolume, setType, useVolumeCorrection, useVolumeCorrectionMethods inherited from class Object
finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface PhaseCPAInterface
calc_hCPAMethods inherited from interface PhaseEosInterface
calcPressuredV, dFdN, dFdNdN, dFdNdT, dFdNdV, displayInteractionCoefficients, F, getAresTV, getEosMixingRule, getMixingRuleName, getMolarVolume, getPressureAttractive, getPressureRepulsive, getSresTVMethods inherited from interface PhaseInterface
addMoles, addMolesChemReac, addMolesChemReac, calcA, calcAi, calcAij, calcAiT, calcAT, calcB, calcBi, calcBij, calcMolarVolume, calcR, fb, FB, fBB, FBB, FBD, FBT, fBV, FBV, FD, FDT, FDV, Fn, FnB, FnV, FT, FTT, FTV, fv, FV, fVV, FVV, gb, gBB, gBV, geta, getA, getActivityCoefficient, getActivityCoefficient, getActivityCoefficient, getActivityCoefficientSymetric, getActivityCoefficientUnSymetric, getAlpha0_EOSCG, getAlpha0_GERG2008, getAlpha0_Leachman, getAlpha0_Leachman, getAlpha0_Vega, getAlphares_EOSCG, getAlphares_GERG2008, getAlphares_Leachman, getAlphares_Leachman, getAlphares_Vega, getAntoineVaporPressure, getAT, getATT, getb, getB, getBeta, getComponent, getComponent, getcomponentArray, getComponentNames, getComponents, getComponentWithIndex, getComposition, getCompressibilityX, getCompressibilityY, getCorrectedVolume, getCp, getCp, getCp0, getCpres, getCv, getCv, getDensity, getDensity, getDensity_AGA8, getDensity_EOSCG, getDensity_GERG2008, getDensity_Leachman, getDensity_Leachman, getDensity_Vega, getdPdrho, getdPdTVn, getdPdVTn, getdrhodN, getdrhodP, getdrhodT, getEnthalpy, getEnthalpy, getEnthalpydP, getEnthalpydT, getEntropy, getEntropy, getEntropydP, getEntropydT, getExcessGibbsEnergy, getExcessGibbsEnergySymetric, getFlowRate, getFugacity, getFugacity, getg, getGamma, getGamma2, getGibbsEnergy, getGresTP, getHelmholtzEnergy, getHresTP, getInfiniteDiluteFugacity, getInitType, getInternalEnergy, getInternalEnergy, getIsobaricThermalExpansivity, getIsothermalCompressibility, getJouleThomsonCoefficient, getJouleThomsonCoefficient, getKappa, getLogActivityCoefficient, getLogInfiniteDiluteFugacity, getLogInfiniteDiluteFugacity, getLogPureComponentFugacity, getMass, getMeanIonicActivity, getMixGibbsEnergy, getMixingRule, getMixingRuleType, getModelName, getMolalMeanIonicActivity, getMolarComposition, getMolarMass, getMolarMass, getMolarVolume, getMoleFraction, getNumberOfComponents, getNumberOfIonicComponents, getNumberOfMolecularComponents, getNumberOfMolesInPhase, getOsmoticCoefficient, getOsmoticCoefficientOfWater, getOsmoticCoefficientOfWaterMolality, getpH, getpH, getPhase, getPhaseFraction, getPhaseTypeName, getPhysicalProperties, getPhysicalPropertyModel, getPressure, getPressure, getProperties_EOSCG, getProperties_GERG2008, getProperties_Leachman, getProperties_Leachman, getProperties_Vega, getPseudoCriticalPressure, getPseudoCriticalTemperature, getPureComponentFugacity, getPureComponentFugacity, getRefPhase, getRefPhase, getSoundSpeed, getSoundSpeed, getSresTP, getTemperature, getTemperature, getThermalConductivity, getThermalConductivity, getTotalVolume, getType, getViscosity, getViscosity, getVolume, getVolume, getWaterDensity, getWtFrac, getWtFrac, getWtFraction, getWtFractionOfWaxFormingComponents, getZ, getZvolcorr, gV, gVV, hasComponent, hasComponent, hasIons, hasPlusFraction, hasTBPFraction, init, init, initPhysicalProperties, initPhysicalProperties, initPhysicalProperties, initRefPhases, isAsphalteneRich, isConstantPhaseVolume, isMixingRuleDefined, normalize, removeComponent, resetMixingRule, resetPhysicalProperties, setAttractiveTerm, setBeta, setComponentArray, setConstantPhaseVolume, setEmptyFluid, setInitType, setMixingRule, setMixingRuleGEModel, setMolarVolume, setMoleFractions, setNumberOfComponents, setParams, setPhaseTypeName, setPhysicalProperties, setPhysicalProperties, setPhysicalPropertyModel, setPpm, setPressure, setProperties, setRefPhase, setRefPhase, setTemperature, setTotalVolume, setType, useVolumeCorrection, useVolumeCorrection
-
Field Details
-
serialVersionUID
private static final long serialVersionUIDSerialization version UID.- See Also:
-
logger
private static final org.apache.logging.log4j.Logger loggerLogger object for class. -
ANDERSON_M
private static final int ANDERSON_MAnderson mixing depth (number of history vectors).- See Also:
-
MAX_INNER_ITERS
private static final int MAX_INNER_ITERSMaximum inner (site fraction) iterations per outer step.- See Also:
-
INNER_TOL
private static final double INNER_TOLInner loop convergence tolerance.- See Also:
-
MAX_OUTER_ITERS
private static final int MAX_OUTER_ITERSMaximum outer (volume) iterations.- See Also:
-
OUTER_TOL
private static final double OUTER_TOLOuter loop convergence tolerance.- See Also:
-
callCount
private static volatile long callCountTotal molarVolume calls. -
totalOuterIters
private static volatile long totalOuterItersTotal outer iterations across all calls. -
totalInnerIters
private static volatile long totalInnerItersTotal inner iterations across all calls. -
andersonConvergedCount
private static volatile long andersonConvergedCountCalls where Anderson converged vs needed Newton fallback. -
newtonFallbackCount
private static volatile long newtonFallbackCountFallbacks 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
Get profiling summary string.- Returns:
- a summary of profiling data
-
clone
clone.
- Specified by:
clonein interfacePhaseInterface- Overrides:
clonein classPhaseSrkCPAs- Returns:
- a
PhaseInterfaceobject
-
addComponent
Add component to component array and update moles variables.
- Specified by:
addComponentin interfacePhaseInterface- Overrides:
addComponentin classPhaseSrkCPAs- 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:
molarVolumein interfacePhaseInterface- Overrides:
molarVolumein classPhaseSrkCPA- Parameters:
pressure- a doubletemperature- a doubleA- a doubleB- a doublept- 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 siteshistLen- 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:
initCPAMatrixin classPhaseSrkCPA- 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:
molarVolumeChangePhasein classPhaseSrkCPA- Parameters:
pressure- a doubletemperature- a doubleA- a doubleB- a doublept- the PhaseType of the phase- Returns:
- a double
- Throws:
IsNaNException- if any.TooManyIterationsException- if any.
-