Class PhaseSrkCPAreduced
- All Implemented Interfaces:
Serializable, Cloneable, PhaseCPAInterface, PhaseEosInterface, PhaseInterface, ThermodynamicConstantsInterface
Reduces the coupled (n_s + 1)-dimensional Newton system to (p + 1) dimensions, where p is the number of unique association site types. Sites on the same component with identical bonding patterns (same delta row in the association matrix) are grouped into a single "type" with a multiplicity factor. This exploits the mathematical theorem that equivalent sites converge to equal site fractions at equilibrium.
Combined with Broyden rank-1 updates of the inverse Jacobian after initial convergence, this yields compounded speedup from both dimension reduction and reduced per-iteration cost.
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 TypeFieldDescription(package private) static final doubleMax residual below which Broyden updates are activated.(package private) longNumber of Broyden rank-1 updates.(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 full Jacobian evaluations.(package private) intNumber of full sites (last call).(package private) intNumber of site types (last call).(package private) static final intMaximum iterations for the coupled Newton/Broyden solver.(package private) static final doubleMaximum relative step.(package private) static final intMinimum full Newton steps before switching to Broyden.private intNumber of unique site types for the current system.private static final longSerialization version UID.private int[]Maps individual site index to type index.(package private) static final doubleRatio threshold for detecting stalling.(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 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, logger, 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 static voidbroydenUpdate(double[][] invJ, double[] dxVec, double[] dfVec, int n) Broyden "good" rank-1 update of the inverse Jacobian H.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 Broyden rank-1 updates.longGet the total number of molarVolume calls.longGet the number of fallbacks to the base class solver.longGet the total number of full Jacobian evaluations.intGet the total number of individual sites from the last molarVolume call.intGet the number of unique site types from the last molarVolume call.longGet the total Newton/Broyden iterations across all calls.voidinitCPAMatrix(int type) initCPAMatrix.private static booleaninvertMatrix(double[][] a, double[][] ainv, int n) Invert matrix A into Ainv using Gauss-Jordan elimination with partial pivoting.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.voidReset all profiling counters to zero.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 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:
-
MAX_ITERATIONS
static final int MAX_ITERATIONSMaximum iterations for the coupled Newton/Broyden solver.- See Also:
-
CONVERGENCE_TOL
static final double CONVERGENCE_TOLConvergence tolerance for the max residual.- See Also:
-
MIN_NEWTON_STEPS
static final int MIN_NEWTON_STEPSMinimum full Newton steps before switching to Broyden.- See Also:
-
BROYDEN_SWITCH_TOL
static final double BROYDEN_SWITCH_TOLMax residual below which Broyden updates are activated.- See Also:
-
STALL_RATIO
static final double STALL_RATIORatio threshold for detecting stalling.- See Also:
-
MAX_REL_STEP
static final double MAX_REL_STEPMaximum relative step.- See Also:
-
numTypes
private transient int numTypesNumber of unique site types for the current system. -
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. -
callCount
long callCountNumber of molarVolume calls. -
totalIters
long totalItersTotal iterations across all calls. -
jacobianEvals
long jacobianEvalsNumber of full Jacobian evaluations. -
broydenUpdates
long broydenUpdatesNumber of Broyden rank-1 updates. -
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
-
PhaseSrkCPAreduced
public PhaseSrkCPAreduced()Construct a PhaseSrkCPAreduced 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.
Reduced-dimension coupled Newton/Broyden molar volume solver. Exploits association site symmetry to work in (p+1) dimensions where p is the number of unique site types, combined with Broyden rank-1 inverse-Jacobian updates after the initial Newton phase.
- 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 — e.g., the two electron-donor sites of water (4C) have identical interactions with all other sites.
- 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
-
invertMatrix
private static boolean invertMatrix(double[][] a, double[][] ainv, int n) Invert matrix A into Ainv using Gauss-Jordan elimination with partial pivoting.- Parameters:
a- input matrix (will be modified by the elimination)ainv- output inverse matrixn- matrix dimension- Returns:
- true if successful, false if singular
-
broydenUpdate
private static void broydenUpdate(double[][] invJ, double[] dxVec, double[] dfVec, int n) Broyden "good" rank-1 update of the inverse Jacobian H.H_new = H + (dx - H*df) * (dx^T * H) / (dx^T * H * df). Cost: O(n^2).
- Parameters:
invJ- inverse Jacobian (updated in-place)dxVec- step vector x_{k+1} - x_kdfVec- residual change R(x_{k+1}) - R(x_k)n- system dimension
-
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 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
-
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/Broyden iterations across all calls.- Returns:
- total iterations
-
getJacobianEvals
public long getJacobianEvals()Get the total number of full Jacobian evaluations.- Returns:
- Jacobian evaluation count
-
getBroydenUpdates
public long getBroydenUpdates()Get the total number of Broyden rank-1 updates.- Returns:
- Broyden update count
-
getFallbackCount
public long getFallbackCount()Get the number of fallbacks to the base class solver.- Returns:
- fallback count
-
getLastNumTypes
public int getLastNumTypes()Get the number of unique site types from the last molarVolume call.- Returns:
- number of unique types (p)
-
getLastFullSites
public int getLastFullSites()Get the total number of individual sites from the last molarVolume call.- Returns:
- number of full sites (n_s)
-
resetProfiling
public void resetProfiling()Reset all profiling counters to zero.
-