Class PhaseSrkCPAandersonReduced
- All Implemented Interfaces:
Serializable, Cloneable, PhaseCPAInterface, PhaseEosInterface, PhaseInterface, ThermodynamicConstantsInterface
Combines two orthogonal acceleration strategies:
- Site symmetry reduction: groups equivalent association sites (same bonding pattern on the same component) into unique site types, reducing the inner loop dimension from n_s to p.
- Anderson acceleration: replaces successive substitution with Anderson mixing (depth m=3) on the reduced p-dimensional site fraction vector, achieving superlinear convergence.
The outer Halley iteration for molar volume and the volume derivative computation
(initCPAMatrix(1)) also use the reduced dimension p, reducing the Hessian linear system
from O(n_s^3) to O(p^3).
This is a nested-family solver: site fractions are fully converged at each volume step before computing exact volume derivatives via the implicit function theorem. It therefore avoids the coupled-family equilibrium sensitivity documented for the Broyden and fully implicit solvers.
Dimension reduction examples:
| System | n_s (full) | p (reduced) | Reduction |
|---|---|---|---|
| Pure water (4C) | 4 | 2 | 50% |
| Water + methanol (4C+2B) | 6 | 4 | 33% |
| Water + MEG (4C+4C) | 8 | 4 | 50% |
| NG + water + TEG (4C+4C) | 8 | 4 | 50% |
- 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 intCached ns used to build the current map (-1 = invalid).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 intNumber of unique site types for the current system.private static final doubleOuter loop convergence tolerance.private static final longSerialization version UID.private int[]Maps individual site index to type index.private booleanWhen true,initCPAMatrix(1)skips theupdateDeltaWithG(ns)call.private static longTotal inner iterations across all calls.private static longTotal outer iterations across all calls.private int[]Component index for each type.private int[]Multiplicity (count of equivalent sites) for each type.private int[]Representative individual site index for each type.private double[][]private double[]private double[]private double[][]private double[]private double[][]private double[]private double[][]private double[]private double[]private double[][]private double[]private double[]private double[]private intprivate intprivate intprivate double[]private double[]private double[]private 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.private voidbuildSiteTypeMap(int ns) Build the site type map by grouping equivalent association sites.clone()clone.private voidensureWorkArrays(int p) Ensure reduced work arrays are allocated.private voidexpandAndSetSiteFractions(double[] xType, int ns) Expand reduced site fraction values to all individual sites on components.static longGet total Anderson converged count.static longGet total call count.static longGet total Newton fallback 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, int ns) Read individual site fractions from component objects into a flat array.static voidReset profiling counters.private static double[]solveAndersonLeastSquares(double[][] gMatrix, double[] gVec, int p, int histLen) Solve the Anderson least-squares problem: min ||g - G * gamma||^2.private static voidsolveLinearSystem(double[][] a, double[] b, int n) Solve the linear system A*x = b in-place (b overwritten with solution) using Gaussian elimination with partial pivoting.private intsolveXAndersonReduced(int p, double[] tMoles, int ns) Solve the reduced site fraction equations using Anderson-accelerated successive substitution.private voidupdateDeltaWithG(int ns) Update delta = deltaNog * g for all individual sites.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:
-
numTypes
private transient int numTypesNumber of unique site types for the current system. -
cachedNs
private transient int cachedNsCached ns used to build the current map (-1 = invalid). -
siteToType
private transient int[] siteToTypeMaps individual site index to type index. -
typeRepSite
private transient int[] typeRepSiteRepresentative individual site index for each type. -
typeMult
private transient int[] typeMultMultiplicity (count of equivalent sites) for each type. -
typeCompIdx
private transient int[] typeCompIdxComponent index for each type. -
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 -
workP
private transient int workP -
workXSiteFull
private transient double[] workXSiteFull -
workXTypeOuter
private transient double[] workXTypeOuter -
workTMolesOuter
private transient double[] workTMolesOuter -
workInnerKlk
private transient double[][] workInnerKlk -
workInnerXCurr
private transient double[] workInnerXCurr -
workInnerFX
private transient double[] workInnerFX -
workInnerGCurr
private transient double[] workInnerGCurr -
workInnerXNew
private transient double[] workInnerXNew -
workInnerGPrev
private transient double[] workInnerGPrev -
workInnerXPrev
private transient double[] workInnerXPrev -
workInnerGHist
private transient double[][] workInnerGHist -
workInnerXHist
private transient double[][] workInnerXHist -
workOuterP
private transient int workOuterP -
workOuterNs
private transient int workOuterNs -
skipDeltaUpdateInInitCPA
private transient boolean skipDeltaUpdateInInitCPAWhen true,initCPAMatrix(1)skips theupdateDeltaWithG(ns)call. Set by the Halley outer loop where delta has just been refreshed; cleared on exit. -
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.
-
-
Constructor Details
-
PhaseSrkCPAandersonReduced
public PhaseSrkCPAandersonReduced()Constructor for PhaseSrkCPAandersonReduced.
-
-
Method Details
-
resetProfileCounters
public static void resetProfileCounters()Reset profiling counters. -
getProfileSummary
Get profiling summary string.- Returns:
- a summary of profiling data
-
getCallCount
public static long getCallCount()Get total call count.- Returns:
- number of molarVolume calls
-
getAndersonConvergedCount
public static long getAndersonConvergedCount()Get total Anderson converged count.- Returns:
- number of inner loops converged by Anderson
-
getNewtonFallbackCount
public static long getNewtonFallbackCount()Get total Newton fallback count.- Returns:
- number of inner loops that fell back to Newton
-
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 on reduced site type fractions. The Halley step uses the implicit function theorem to compute dF_CPA/dV derivatives in the reduced p-dimensional space.
- 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.
-
solveXAndersonReduced
private int solveXAndersonReduced(int p, double[] tMoles, int ns) Solve the reduced site fraction equations using Anderson-accelerated successive substitution.The fixed-point map operates on p site type fractions instead of n_s individual fractions:
f_alpha(X) = 1 / (1 + sum_beta m_beta * n_beta * Delta(rep_a,rep_b) * X_beta / V)
Anderson acceleration (mixing depth m=3) is applied to this reduced map. After convergence, the p type fractions are expanded back to all n_s individual site fractions.
- Parameters:
p- number of unique site typestMoles- moles per site typens- total number of individual association sites- Returns:
- number of inner iterations used
-
solveAndersonLeastSquares
private static double[] solveAndersonLeastSquares(double[][] gMatrix, double[] gVec, int p, 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 p, using rows 0..histLen-1)gVec- current residual vector (length p)p- dimension of the vectors (number of site types)histLen- number of stored history vectors- Returns:
- mixing coefficients gamma (length histLen)
-
buildSiteTypeMap
private void buildSiteTypeMap(int ns) Build the site type map by grouping equivalent association sites.Two individual sites are equivalent if they belong to the same component and have identical deltaNog rows (same bonding pattern to all other sites). This corresponds to sites with the same charge in the CPA association scheme.
- Parameters:
ns- total number of individual association sites
-
expandAndSetSiteFractions
private void expandAndSetSiteFractions(double[] xType, int ns) Expand reduced site fraction values to all individual sites on components.- Parameters:
xType- reduced site fraction array (length p)ns- total number of individual sites
-
readXsiteFromComponents
private void readXsiteFromComponents(double[] xSite, int ns) Read individual site fractions from component objects into a flat array.- Parameters:
xSite- array to fill (length ns)ns- total number of individual sites
-
ensureWorkArrays
private void ensureWorkArrays(int p) Ensure reduced work arrays are allocated.- Parameters:
p- number of unique site types
-
initCPAMatrix
public void initCPAMatrix(int type) initCPAMatrix.
Override type 1 initialization to use reduced-dimension site type computation. Volume derivatives (FCPA, dFCPAdV, dFCPAdVdV, dFCPAdVdVdV) are computed using the type grouping, reducing the Hessian linear system from n_s to p dimensions.
- Overrides:
initCPAMatrixin classPhaseSrkCPA- Parameters:
type- a int
-
solveLinearSystem
private static void solveLinearSystem(double[][] a, double[] b, int n) Solve the linear system A*x = b in-place (b overwritten with solution) using Gaussian elimination with partial pivoting.- Parameters:
a- coefficient matrix (modified in-place)b- right-hand side vector (overwritten with solution)n- system dimension
-
updateDeltaWithG
private void updateDeltaWithG(int ns) Update delta = deltaNog * g for all individual sites.- Parameters:
ns- total number of individual sites
-
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.
-