Class PhaseSrkCPAfullyImplicitReduced
- All Implemented Interfaces:
Serializable, Cloneable, PhaseCPAInterface, PhaseEosInterface, PhaseInterface, ThermodynamicConstantsInterface
Combines two acceleration strategies:
- Fully implicit coupled Newton-Raphson from Igben et al. (2026): simultaneous solution of molar volume and association site fractions, eliminating inner iterations.
- Site type reduction: groups equivalent association sites (same deltaNog row on same component) into types with multiplicities, reducing the system dimension from (n_s + 1) to (p + 1).
The Newton Jacobian is built analytically on the reduced (p+1)-dimensional system at every iteration (no Broyden approximation), solved via Gaussian elimination O(p^3). This gives both the per-iteration cost reduction of dimension reduction AND the quadratic convergence of full Newton.
Dimension reduction examples:
| System | n_s (full) | p (reduced) | Jacobian speedup |
|---|---|---|---|
| Pure water (4C) | 4 | 2 | 4.6x |
| Water + methanol (4C+2B) | 6 | 4 | 2.7x |
| Water + MEG (4C+4C) | 8 | 4 | 5.8x |
| NG + water + TEG | 8 | 4 | 5.8x |
- Version:
- 1.0
- Author:
- Even Solbraa
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate intCached ns used to build the current map (-1 = invalid).(package private) longNumber of molarVolume calls.(package private) static final doubleConvergence tolerance for the max residual.(package private) longNumber of solver fallbacks to the base class.(package private) longNumber of Jacobian evaluations (full Newton, no Broyden).(package private) intNumber of full sites (last call).(package private) intNumber of site types (last call).private static final org.apache.logging.log4j.LoggerLogger object for class.(package private) static final intMaximum iterations for the coupled Newton solver.(package private) static final doubleMaximum relative step size per iteration to prevent divergence.private intNumber of unique site types for the current system.(package private) static final doubleRestart threshold parameter alpha (supercritical detection).private static final longSerialization version UID.private int[]Maps individual site index to type index.(package private) longTotal 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 intprivate intprivate intprivate double[]private double[]private 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
ConstructorsConstructorDescriptionConstruct a PhaseSrkCPAfullyImplicitReduced phase. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddComponent(String name, double moles, double molesInPhase, int compNumber) Add component to component array and update moles variables.private voidbuildReducedJacobian(double[][] jac, double[] xType, double[] tMoles, double[] redSum, double totalVol, double gdv1, double zeta, double btemp, int dim, int p) Build the analytic Jacobian for the reduced (p+1)-dimensional system.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.longGet the total number of molarVolume calls.longGet the number of solver fallbacks to the base class.longGet the number of Jacobian evaluations.intGet the number of full sites from the last call.intGet the number of unique site types from the last call.longGet the total Newton iterations across all calls.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.private static booleansolveLinearSystem(double[][] a, double[] b, int n) Solve a linear system A*x = b in-place (b overwritten with solution) using Gaussian elimination with partial pivoting.private voidupdateDeltaWithG(int ns) Multiply delta by g-function 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. -
MAX_ITERATIONS
static final int MAX_ITERATIONSMaximum iterations for the coupled Newton solver.- See Also:
-
CONVERGENCE_TOL
static final double CONVERGENCE_TOLConvergence tolerance for the max residual.- See Also:
-
MAX_REL_STEP
static final double MAX_REL_STEPMaximum relative step size per iteration to prevent divergence.- See Also:
-
RESTART_ALPHA
static final double RESTART_ALPHARestart threshold parameter alpha (supercritical detection).- 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. -
workRedSum
private transient double[] workRedSum -
workXSiteFullRead
private transient double[] workXSiteFullRead -
workXType
private transient double[] workXType -
workTMoles
private transient double[] workTMoles -
workResidual
private transient double[] workResidual -
workJacobian
private transient double[][] workJacobian -
workDx
private transient double[] workDx -
workNewtonP
private transient int workNewtonP -
workNewtonNs
private transient int workNewtonNs -
callCount
long callCountNumber of molarVolume calls. -
totalIters
long totalItersTotal iterations across all calls. -
jacobianEvals
long jacobianEvalsNumber of Jacobian evaluations (full Newton, no Broyden). -
fallbackCount
long fallbackCountNumber of solver fallbacks to the base class. -
lastNumTypes
int lastNumTypesNumber of site types (last call). -
lastFullSites
int lastFullSitesNumber of full sites (last call). -
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
-
-
Constructor Details
-
PhaseSrkCPAfullyImplicitReduced
public PhaseSrkCPAfullyImplicitReduced()Construct a PhaseSrkCPAfullyImplicitReduced phase.
-
-
Method Details
-
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.
Fully implicit + reduced molar volume solver. Operates on the reduced (p+1)-dimensional system where p is the number of unique association site types. Uses full Newton Jacobian at every iteration (no Broyden approximation), solved via Gaussian elimination.
- 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.
-
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
-
buildReducedJacobian
private void buildReducedJacobian(double[][] jac, double[] xType, double[] tMoles, double[] redSum, double totalVol, double gdv1, double zeta, double btemp, int dim, int p) Build the analytic Jacobian for the reduced (p+1)-dimensional system.Block structure:
- J_XX[a][b]: site fraction block with multiplicity weighting
- j_X_zeta[a]: site fraction sensitivity to volume (via zeta)
- j_zeta_X[a]: volume equation sensitivity to site fractions
- j_zeta_zeta: volume equation self-sensitivity
- Parameters:
jac- Jacobian matrix to populate (dim x dim)xType- reduced site fraction values (length p)tMoles- moles per type (length p)redSum- precomputed reduced summation for each type (length p)totalVol- total volume Vgdv1- g'(V) - 1/Vzeta- current B/(nV)btemp- co-volume Bdim- system dimension (p+1)p- number of unique site types
-
updateDeltaWithG
private void updateDeltaWithG(int ns) Multiply delta by g-function for all individual sites.- Parameters:
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. Higher-order volume derivatives (FCPA, dFCPAdV, dFCPAdVdV, dFCPAdVdVdV) are computed using the type grouping, reducing linear system size from n_s to p.
- Overrides:
initCPAMatrixin classPhaseSrkCPA- Parameters:
type- a int
-
solveLinearSystem
private static boolean solveLinearSystem(double[][] a, double[] b, int n) Solve a 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- Returns:
- true if successful, false if singular
-
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.
-
getCallCount
public long getCallCount()Get the total number of molarVolume calls.- Returns:
- call count
-
getTotalIters
public long getTotalIters()Get the total Newton iterations across all calls.- Returns:
- total iteration count
-
getJacobianEvals
public long getJacobianEvals()Get the number of Jacobian evaluations.- Returns:
- Jacobian evaluation count
-
getFallbackCount
public long getFallbackCount()Get the number of solver fallbacks to the base class.- Returns:
- fallback count
-
getLastNumTypes
public int getLastNumTypes()Get the number of unique site types from the last call.- Returns:
- last number of unique types
-
getLastFullSites
public int getLastFullSites()Get the number of full sites from the last call.- Returns:
- last full site count
-