Flash and equilibrium¶
Initial estimates¶
torch_flash.initialization
¶
Phase-equilibrium initial estimates.
wilson_k_values
¶
wilson_k_values(
components: ComponentSet,
temperature: Tensor,
pressure: Tensor,
) -> Tensor
Evaluate Wilson initial vapor-to-liquid equilibrium ratios.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
components
|
ComponentSet
|
Ordered critical temperatures, critical pressures, and acentric factors. |
required |
temperature
|
Tensor
|
Temperature in K with arbitrary leading batch dimensions. |
required |
pressure
|
Tensor
|
Positive pressure in Pa, broadcast-compatible with |
required |
Returns:
| Type | Description |
|---|---|
Tensor
|
Positive dimensionless K-value estimates with shape
|
Notes
These are initialization estimates, not converged equilibrium ratios and not a phase-stability criterion.
Source code in src/torch_flash/initialization.py
Flash and stability¶
torch_flash.flash
¶
Stability-tested phase-equilibrium flash calculations.
BinaryThreePhaseInvariant
dataclass
¶
BinaryThreePhaseInvariant(
temperature: Tensor,
pressure: Tensor,
phase_compositions: Tensor,
residual_norm: Tensor,
iterations: int,
converged: bool,
)
Solved binary three-phase invariant used by a grid flash.
Attributes:
| Name | Type | Description |
|---|---|---|
temperature |
Tensor
|
Scalar invariant temperature in K. |
pressure |
Tensor
|
Scalar invariant pressure in Pa. |
phase_compositions |
Tensor
|
Tensor with shape |
residual_norm |
Tensor
|
Maximum absolute dimensionless log-fugacity mismatch among the three phases. |
iterations |
int
|
Number of damped autodiff-Newton iterations attempted. |
converged |
bool
|
Whether |
Notes
A binary three-phase invariant fixes phase compositions and pressure at a
specified temperature, but it does not uniquely fix all three phase
fractions. :func:flash_grid applies a positive centered lever-rule
representative only for feeds strictly inside the outer phase-composition
interval.
BinaryThreePhaseInvariantBatch
dataclass
¶
BinaryThreePhaseInvariantBatch(
temperature: Tensor,
pressure: Tensor,
phase_compositions: Tensor,
residual_norm: Tensor,
iterations: Tensor,
converged: Tensor,
)
Independent binary three-phase invariants solved in one tensor batch.
Attributes:
| Name | Type | Description |
|---|---|---|
temperature, pressure |
State temperatures in K and solved pressures in Pa with shape
|
|
phase_compositions |
Tensor
|
Sorted binary phase compositions with shape |
residual_norm |
Tensor
|
Per-state maximum dimensionless log-fugacity mismatch. |
iterations |
Tensor
|
Per-state damped-Newton iteration counts. |
converged |
Tensor
|
Per-state residual-convergence flags. |
GridEquilibrium
dataclass
¶
GridEquilibrium(
temperatures: Tensor,
pressures: Tensor,
feeds: Tensor,
grid_shape: tuple[int, ...],
phase_fractions: Tensor,
phase_compositions: Tensor,
phase_counts: Tensor,
gibbs_reduction: Tensor,
fugacity_residual: Tensor,
material_balance_residual: Tensor,
converged: Tensor,
elapsed_seconds: float,
batched_search_seconds: float,
refinement_seconds: float,
difficult_state_count: int,
topology_audit_count: int,
initial_fallback_replacements: int,
topology_audit_replacements: int,
)
Padded phase-equilibrium results over independent TP states.
State fields are flattened in row-major order. grid_shape records the
original temperature/pressure batch shape so callers can reshape any
per-state tensor without reconstructing axis lengths.
Attributes:
| Name | Type | Description |
|---|---|---|
temperatures |
Tensor
|
Flattened temperatures in K with shape |
pressures |
Tensor
|
Flattened pressures in Pa with shape |
feeds |
Tensor
|
Normalized overall mole fractions with shape
|
grid_shape |
tuple[int, ...]
|
Original non-scalar batch shape of the input temperatures and pressures. |
phase_fractions |
Tensor
|
Molar phase fractions with shape |
phase_compositions |
Tensor
|
Equilibrium mole fractions with shape
|
phase_counts |
Tensor
|
Number of retained distinct phases per state, from one through three. |
gibbs_reduction |
Tensor
|
Dimensionless reduction in |
fugacity_residual |
Tensor
|
Maximum absolute log-fugacity mismatch among retained phases. |
material_balance_residual |
Tensor
|
Maximum absolute component mole-fraction material-balance residual. |
converged |
Tensor
|
Per-state flag requiring both fugacity and material-balance gates. Callers must inspect this tensor before interpreting phase counts. |
elapsed_seconds |
float
|
Total wall-clock seconds for the grid call. |
batched_search_seconds |
float
|
Wall-clock seconds spent in stability, vectorized two-phase work, and initial Gibbs candidate discovery. |
refinement_seconds |
float
|
Wall-clock seconds spent refining and auditing difficult states. |
difficult_state_count |
int
|
Number of states sent to the difficult-state Gibbs fallback. For
:func: |
topology_audit_count |
int
|
Number of distinct additional cells selected by the two-dimensional
enclosed-cell and three-phase-boundary continuation audits. This is
zero for :func: |
initial_fallback_replacements |
int
|
Number of first-pass grid candidates replaced by a lower-Gibbs, converged difficult-state result. |
topology_audit_replacements |
int
|
Number of already-installed grid candidates replaced by a lower-Gibbs, converged result during the subsequent two-dimensional audits. |
Notes
Root selection, physical phase identification, and equilibrium phase count
are separate. Use :func:identify_grid_phases to label the returned
equilibrium compositions. Grid flashes are solver operations with
discrete phase-count decisions; returned tensors are diagnostic results,
not a differentiable end-to-end flash mapping.
GridFlashOptions
dataclass
¶
GridFlashOptions(
chunk_size: int = 2048,
random_allocation_starts: int = 8,
random_seed: int = 20260724,
fallback_workers: int = 1,
debug: bool = False,
phase_fraction_tolerance: float = 0.0001,
phase_composition_merge_tolerance: float = 0.002,
gibbs_reduction_tolerance: float = 2e-07,
fugacity_tolerance: float = 1e-08,
material_balance_tolerance: float = 5e-11,
flash_newton_tolerance: float = 1e-11,
stability_tolerance: float = 1e-07,
independent_reflash_starts: int = 4,
stability_iterations: int = 40,
two_phase_substitution_iterations: int = 30,
two_phase_newton_iterations: int = 8,
gibbs_fallback_adam_iterations: int = 80,
three_phase_newton_iterations: int = 48,
)
Numerical controls for batched phase-count-discovering TP flashes.
The defaults target float64 reference calculations. Tolerances are applied to dimensionless log-fugacity or composition residuals unless stated otherwise. Changing a start count, merge tolerance, or Gibbs acceptance tolerance can change which basin is selected; these fields are therefore part of the scientific configuration rather than hidden performance switches.
Attributes:
| Name | Type | Description |
|---|---|---|
chunk_size |
int
|
Maximum number of independent states passed to one batched stability or fixed two-phase kernel. It bounds temporary tensor size; it does not subdivide or couple the thermodynamic problem. |
random_allocation_starts |
int
|
Number of reproducible random three-phase component-allocation starts added to the deterministic Wilson and component-rich starts. |
random_seed |
int
|
PyTorch generator seed used only for random allocation starts. |
fallback_workers |
int
|
Number of Python threads used for the final sparse scalar refinement. The batched search is already vectorized. Values above one may be slower when PyTorch intra-operation threading is also enabled. |
debug |
bool
|
Print fallback candidate counts and Newton acceptance summaries. Library results and numerical tolerances are unchanged. |
phase_fraction_tolerance |
float
|
Minimum retained molar phase fraction. Smaller phases are treated as disappearing and removed after refinement. |
phase_composition_merge_tolerance |
float
|
Maximum absolute mole-fraction difference for merging two candidate phase compositions. |
gibbs_reduction_tolerance |
float
|
Minimum dimensionless reduction in |
fugacity_tolerance |
float
|
Maximum absolute log-fugacity equality residual accepted for a multiphase result. |
material_balance_tolerance |
float
|
Maximum absolute component mole-fraction material-balance residual. |
flash_newton_tolerance |
float
|
Maximum residual used to terminate each scalar equal-fugacity Newton refinement. |
stability_tolerance |
float
|
Tangent-plane-distance and stability-iteration tolerance. A state is treated as unstable when its minimum TPD is less than the negative of this value. |
independent_reflash_starts |
int
|
Number of lowest-Gibbs starts independently refined by
:func: |
stability_iterations |
int
|
Maximum successive-substitution passes in each batched stability calculation. |
two_phase_substitution_iterations |
int
|
Maximum fixed-substitution passes before the batched two-phase Newton correction. |
two_phase_newton_iterations |
int
|
Maximum batched autodiff-Newton corrections for a known two-phase state. |
gibbs_fallback_adam_iterations |
int
|
Adam iterations applied simultaneously to the sparse difficult-state component-allocation problems. |
three_phase_newton_iterations |
int
|
Maximum batched autodiff-Newton corrections for candidate three-phase states. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If an iteration, chunk, worker, or independent-start count is not
positive; if |
GridPhaseIdentification
dataclass
¶
GridPhaseIdentification(
methods: tuple[PhaseIdentificationCriterion, ...],
phase_identity_codes: Tensor,
criterion_values: Tensor,
thresholds: Tensor,
ambiguous: Tensor,
region_codes: Tensor,
elapsed_seconds: float,
method_elapsed_seconds: tuple[float, ...],
)
Physical identities evaluated at every equilibrium composition.
Attributes:
| Name | Type | Description |
|---|---|---|
methods |
tuple[PhaseIdentificationCriterion, ...]
|
Ordered phase-identification criteria. This is the leading axis of all returned tensors. |
phase_identity_codes |
Tensor
|
Integer tensor with shape |
criterion_values |
Tensor
|
Native scalar criterion values with the same padded shape as
|
thresholds |
Tensor
|
Decision threshold in the same units as each criterion value. |
ambiguous |
Tensor
|
Boolean ambiguity flags with shape |
region_codes |
Tensor
|
Integer tensor with shape |
elapsed_seconds |
float
|
Wall-clock seconds spent evaluating all requested methods. |
method_elapsed_seconds |
tuple[float, ...]
|
Wall-clock seconds for each complete method pass, in |
Notes
The "three-phase" region is deliberately identity-neutral. Individual
phase codes retain whether a criterion returned LLV, LLL, or another
combination. Scalar diagnostic values are detached to avoid retaining one
higher-order autodiff graph per grid cell. Call :func:identify_phase
directly when derivatives of a criterion with respect to state or model
parameters are required.
PhaseRegionBoundaryCurve
dataclass
¶
One adaptively localized boundary of a classified phase region.
Attributes:
| Name | Type | Description |
|---|---|---|
region_code |
int
|
Index into :data: |
temperature, pressure |
Ordered one-dimensional curve coordinates in K and Pa. Their lengths match and are at least two. |
|
closed |
bool
|
Whether graph traversal returned to the first refined grid edge. |
Notes
The curve connects equilibrium classifications and is not a coexistence continuation solve. Its vertices are localized by re-flashing bisection states on grid edges whose endpoint region codes differ.
PhaseRegionBoundarySet
dataclass
¶
PhaseRegionBoundarySet(
curves: tuple[PhaseRegionBoundaryCurve, ...],
refined_edge_count: int,
refinement_state_count: int,
failed_midpoint_count: int,
ambiguous_cell_count: int,
maximum_temperature_bracket: float,
maximum_pressure_bracket: float,
)
Adaptively refined boundaries and localization diagnostics.
Attributes:
| Name | Type | Description |
|---|---|---|
curves |
tuple[PhaseRegionBoundaryCurve, ...]
|
Connected phase-region boundary curves. Different region codes can share a physical interface and therefore have coincident curves. |
refined_edge_count |
int
|
Number of unique coarse-grid edges whose endpoint classifications differ. |
refinement_state_count |
int
|
Total midpoint states submitted to batched flashes. |
failed_midpoint_count |
int
|
Number of midpoint flashes that did not pass the flash convergence gate. Such classifications remain explicit in the bisection audit. |
ambiguous_cell_count |
int
|
Number of checkerboard marching-squares cells resolved with the deterministic isolated-corner convention. |
maximum_temperature_bracket, maximum_pressure_bracket |
Largest final edge-bracket widths in K and Pa. |
TrustRegionGridPolishResult
dataclass
¶
TrustRegionGridPolishResult(
equilibrium: GridEquilibrium,
attempted: Tensor,
converged: Tensor,
iterations: Tensor,
accepted_steps: Tensor,
rejected_steps: Tensor,
gradient_norm: Tensor,
minimum_hessian_eigenvalue: Tensor,
minimum_tpd: Tensor,
maximum_phase_composition_change: Tensor,
elapsed_seconds: float,
)
Batched NLVM Trust-Region audit of a phase-discovered grid.
Attributes:
| Name | Type | Description |
|---|---|---|
equilibrium |
GridEquilibrium
|
Copy of the supplied grid with every attempted multiphase state replaced by the Trust-Region result. A one-phase state whose Trust-Region TPD minimum is negative is promoted to a two-phase Trust-Region flash when the instability supplies a physical seed. |
attempted |
Tensor
|
Boolean tensor with shape |
converged |
Tensor
|
Per-state Trust-Region convergence flags. Unattempted states are false. A true value requires the optimization, fugacity, material balance, positive-fraction, and separated-phase gates. |
iterations, accepted_steps, rejected_steps |
Per-state outer iteration and step-decision counts. Unattempted rows contain zero. |
|
gradient_norm |
Tensor
|
Final infinity norm of the dimensionless Gibbs objective gradient. |
minimum_hessian_eigenvalue |
Tensor
|
Smallest eigenvalue of the final symmetrized exact Hessian. |
minimum_tpd |
Tensor
|
Final modified tangent-plane-distance minimum for audited one-phase states. Multiphase rows contain NaN. |
maximum_phase_composition_change |
Tensor
|
Largest absolute mole-fraction change from the independently discovered seed, comparing the preserved phase rows. |
elapsed_seconds |
float
|
Wall-clock seconds spent in the Trust-Region audit. |
Notes
This result validates a local fixed-phase-count solver against phase
counts discovered independently. It is not itself a global phase-count
proof. Inspect attempted and converged before using the polished
equilibrium.
batched_tangent_plane_stability
¶
batched_tangent_plane_stability(
model: StateModel,
state: ChemicalState,
*,
initial_compositions: Tensor | None = None,
tolerance: float = 1e-07,
max_iterations: int = 40,
) -> BatchedStabilityResult
Screen independent states with vectorized tangent-plane iterations.
Michelsen's stationary-point substitution is applied to all states and trial compositions in tensor batches. This routine is intended as the inexpensive first stage of a grid flash: clearly unstable cells seed a phase-split calculation, while non-converged or near-zero TPD cells remain explicit candidates for a stricter stability fallback.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
StateModel
|
Homogeneous-state model supporting batched stable-root fugacity coefficients. |
required |
state
|
ChemicalState
|
One-dimensional temperature and pressure batches. Composition may be common to the batch or contain one row per state. |
required |
initial_compositions
|
Tensor | None
|
Optional trial compositions with shape |
None
|
tolerance
|
float
|
Maximum absolute stationary-point log-mole update. |
1e-07
|
max_iterations
|
int
|
Maximum vectorized successive-substitution passes. |
40
|
Returns:
| Type | Description |
|---|---|
BatchedStabilityResult
|
Per-state TPD minima, trial compositions, convergence diagnostics, and stability decisions. |
Notes
The normalized TPD at a stationary point is -log(sum(W)). A
non-converged nonnegative result is not a global stability proof; callers
performing automatic phase discovery should send those cells to a strict
fallback or retain an ambiguity flag.
Source code in src/torch_flash/flash/batched.py
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 | |
batched_two_phase_flash
¶
batched_two_phase_flash(
model: StateModel,
state: ChemicalState,
*,
initial_k_values: Tensor | None = None,
phase_roots: tuple[PhaseKind, PhaseKind] = (
"liquid",
"vapor",
),
tolerance: float = 1e-08,
substitution_iterations: int = 12,
newton_iterations: int = 16,
) -> BatchedTwoPhaseFlashResult
Solve independent known-two-phase TP states in one tensor batch.
The hybrid algorithm performs vectorized successive substitution followed
by block-diagonal Newton updates obtained with PyTorch autodiff. Inputs
must have Kmin < 1 < Kmax for every state.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
StateModel
|
Homogeneous-state model supporting batched log fugacity coefficients. |
required |
state
|
ChemicalState
|
Temperatures in K and pressures in Pa as one-dimensional tensors of
shape |
required |
initial_k_values
|
Tensor | None
|
Optional positive vapor-to-liquid ratios of shape
|
None
|
phase_roots
|
tuple[PhaseKind, PhaseKind]
|
Cubic-root requests for the denominator and numerator phases,
respectively. The default |
('liquid', 'vapor')
|
tolerance
|
float
|
Per-state convergence threshold for the maximum absolute log-fugacity residual. |
1e-08
|
substitution_iterations
|
int
|
Maximum vectorized successive-substitution passes. |
12
|
newton_iterations
|
int
|
Maximum block-diagonal Newton passes after substitution. |
16
|
Returns:
| Type | Description |
|---|---|
BatchedTwoPhaseFlashResult
|
Per-state phase fractions, compositions, K values, convergence flags, residuals, and the shared number of executed iteration passes. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If batch shapes are inconsistent, iteration controls are invalid,
initial K values are invalid, or a state does not satisfy
|
Notes
converged is reported per state and additionally requires a physical
vapor fraction in [0, 1].
This routine does not perform tangent-plane stability analysis. That separation is intentional: an envelope or another phase classifier can cheaply select thousands of known two-phase grid cells, while ambiguous cells can be sent to the full scalar stability-tested flash.
Source code in src/torch_flash/flash/batched.py
233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 | |
flash_grid
¶
flash_grid(
model: StateModel,
state: ChemicalState,
*,
options: GridFlashOptions | None = None,
binary_invariants: tuple[
BinaryThreePhaseInvariant, ...
] = (),
) -> GridEquilibrium
Flash independent states with batched screening and sparse Gibbs fallback.
The temperature and pressure tensors must have the same non-scalar batch shape. The composition can be common to the batch or have that batch shape as leading dimensions. Two-dimensional batches additionally receive a topology audit and a Gibbs-gated continuation audit along resolved three-phase boundaries.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
StateModel
|
Homogeneous-state thermodynamic model supplying differentiable log-fugacity coefficients, cubic critical constants for Wilson starts, and stable-root selection. |
required |
state
|
ChemicalState
|
Batched TP states. Temperature is in K, pressure is in Pa, and composition contains mole fractions on the final axis. Temperature and pressure must have the same non-scalar batch shape. Composition can be common to all states or have matching leading dimensions. |
required |
options
|
GridFlashOptions | None
|
Numerical controls. Defaults target float64 reference calculations. The model, state, and all options are reused across the batch without changing process-wide PyTorch runtime settings. |
None
|
binary_invariants
|
tuple[BinaryThreePhaseInvariant, ...]
|
Optional converged binary three-phase solutions. A matching temperature and pressure uses their fixed phase compositions and a positive centered lever rule for feeds inside the outer composition interval. |
()
|
Returns:
| Type | Description |
|---|---|
GridEquilibrium
|
Padded phase fractions, compositions, convergence diagnostics, and
timing counters flattened in row-major order with |
Raises:
| Type | Description |
|---|---|
ValueError
|
If temperature and pressure are scalar or have different shapes, the composition batch does not match, a numerical option is invalid, or a supplied binary invariant is malformed. |
RuntimeError
|
If model evaluation, an optimizer, or an autodiff Newton system fails. |
Notes
The hierarchy is:
- batched tangent-plane stability screening;
- a batched known-two-phase flash for unstable feeds;
- stability screening of both returned phases;
- sparse three-phase Gibbs-allocation minimization and autodiff Newton refinement for failed or child-unstable states; and
- for two-dimensional batches, an independent reflash of lower-phase cells bracketed by higher-phase states and of two-phase cells on the advancing boundary of a resolved three-phase region.
The two-dimensional audits only propose candidates. Three-phase continuation advances to a neighboring cell until no new lower-Gibbs split is accepted. Every replacement still requires lower Gibbs energy plus fugacity and material-balance convergence; visual smoothness never overrides the thermodynamic gates.
Forward-only screening runs without graph retention. Gibbs minimization
uses PyTorch autograd and Newton Jacobians use torch.func.jacrev.
Phase-count decisions, merging, and padded output assembly are discrete,
so call-level gradients through GridEquilibrium are not defined. Use
homogeneous property APIs and :func:identify_phase when a differentiable
diagnostic is required.
chunk_size limits memory but does not introduce thermodynamic coupling.
The states remain independent. On CPU, configure dtype and thread count
once before constructing the model; library calls never change global
PyTorch thread settings.
Source code in src/torch_flash/flash/grid.py
3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 3672 3673 3674 3675 3676 3677 3678 3679 3680 3681 3682 3683 3684 3685 3686 3687 3688 3689 3690 3691 3692 3693 3694 3695 3696 3697 3698 3699 3700 3701 3702 3703 3704 3705 3706 3707 3708 3709 3710 3711 3712 3713 3714 3715 3716 3717 3718 3719 3720 3721 3722 3723 3724 3725 3726 3727 3728 3729 3730 3731 3732 3733 3734 3735 3736 3737 3738 3739 3740 3741 3742 3743 3744 3745 3746 3747 3748 3749 3750 3751 3752 3753 3754 3755 3756 3757 3758 3759 3760 3761 3762 3763 3764 3765 3766 3767 3768 3769 3770 3771 3772 3773 3774 3775 3776 3777 3778 3779 3780 3781 3782 3783 3784 3785 3786 3787 3788 3789 3790 3791 3792 3793 3794 3795 3796 3797 3798 3799 3800 3801 3802 3803 3804 3805 3806 3807 3808 3809 3810 3811 3812 3813 3814 3815 3816 3817 3818 3819 3820 3821 3822 3823 3824 3825 3826 3827 3828 3829 3830 3831 3832 3833 3834 3835 3836 3837 3838 3839 3840 3841 3842 3843 3844 3845 3846 3847 3848 3849 3850 3851 3852 3853 3854 3855 3856 3857 3858 3859 3860 3861 3862 3863 3864 3865 3866 3867 3868 3869 3870 3871 3872 3873 3874 3875 3876 3877 3878 3879 3880 3881 3882 3883 3884 3885 3886 3887 3888 3889 3890 3891 3892 3893 3894 3895 3896 3897 3898 3899 3900 3901 3902 3903 3904 3905 3906 3907 3908 3909 3910 3911 3912 3913 3914 3915 3916 3917 3918 3919 3920 3921 3922 3923 3924 3925 3926 3927 3928 3929 3930 3931 3932 3933 3934 3935 3936 3937 3938 3939 3940 3941 3942 3943 3944 3945 3946 3947 3948 3949 3950 3951 3952 3953 3954 3955 3956 3957 3958 3959 3960 3961 3962 3963 3964 3965 3966 3967 3968 3969 3970 3971 3972 3973 3974 3975 3976 3977 3978 3979 3980 3981 3982 3983 3984 3985 3986 3987 3988 3989 3990 3991 3992 3993 3994 3995 3996 3997 3998 3999 4000 4001 4002 4003 4004 4005 4006 4007 4008 4009 4010 4011 4012 4013 4014 | |
flash_grid_oracle
¶
flash_grid_oracle(
model: StateModel,
state: ChemicalState,
*,
options: GridFlashOptions | None = None,
binary_invariants: tuple[
BinaryThreePhaseInvariant, ...
] = (),
) -> GridEquilibrium
Independently apply multistart Gibbs minimization to every TP state.
This deliberately slower path bypasses stability and two-phase screening.
It is intended as a small-batch correctness oracle for :func:flash_grid.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
StateModel
|
Homogeneous-state model supplying differentiable log-fugacity coefficients and Wilson critical-property initialization data. |
required |
state
|
ChemicalState
|
Batched TP states. Temperature is in K, pressure is in Pa, and composition contains mole fractions on the final axis. Temperature and pressure must share one non-scalar batch shape; composition can be common or have matching leading dimensions. |
required |
options
|
GridFlashOptions | None
|
Numerical controls. |
None
|
binary_invariants
|
tuple[BinaryThreePhaseInvariant, ...]
|
Optional converged binary invariant solutions. A matching temperature and pressure uses their fixed phase compositions and a positive centered lever rule. |
()
|
Returns:
| Type | Description |
|---|---|
GridEquilibrium
|
Padded one-, two-, or three-phase results with explicit fugacity, material-balance, Gibbs-reduction, convergence, and timing diagnostics. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If batch shapes, compositions, options, or a supplied invariant are invalid. |
RuntimeError
|
If a model evaluation or strict scalar refinement fails. |
Notes
Every multicomponent state is optimized independently from the same deterministic and seeded-random start library. The oracle is algorithmic verification, not an independent physical model. Compare phase count, Gibbs energy, and residuals; agreement alone does not validate the EoS parameterization.
Candidate minimization and equal-fugacity Newton Jacobians use PyTorch autodiff. Phase selection and padding are discrete, so the returned record is not an end-to-end differentiable flash result.
Source code in src/torch_flash/flash/grid.py
2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 | |
identify_grid_phases
¶
identify_grid_phases(
model: StateModel,
equilibrium: GridEquilibrium,
*,
methods: tuple[
PhaseIdentificationCriterion, ...
] = DEFAULT_GRID_PHASE_IDENTIFICATION_METHODS,
phase: PhaseKind = "stable",
volume_to_covolume_threshold: float = 1.75,
pseudo_critical_temperature_factor: float = 1.0,
ambiguity_relative_tolerance: float = 0.05,
pip_denominator_relative_tolerance: float | None = None,
pip_autodiff_chunk_size: int = 4096,
response_autodiff_chunk_size: int = 2048,
) -> GridPhaseIdentification
Identify each equilibrium phase and summarize paper-style regions.
Equilibrium phase count and physical identity remain separate: this function never changes the flash result. Each method is applied to every converged phase at its equilibrium composition.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
StateModel
|
Homogeneous-state model used to produce |
required |
equilibrium
|
GridEquilibrium
|
Result returned by :func: |
required |
methods
|
tuple[PhaseIdentificationCriterion, ...]
|
Unique ordered criteria to evaluate. The default is the five Bennett and Schmidt methods plus the Venkatarathnam-Oellrich pressure-derivative parameter. |
DEFAULT_GRID_PHASE_IDENTIFICATION_METHODS
|
phase
|
PhaseKind
|
Homogeneous EoS root request used while evaluating each already
separated equilibrium composition. |
'stable'
|
volume_to_covolume_threshold
|
float
|
Dimensionless Pedersen |
1.75
|
pseudo_critical_temperature_factor
|
float
|
Positive factor multiplying Li's volume-weighted pseudo-critical temperature. Bennett and Schmidt use one. |
1.0
|
ambiguity_relative_tolerance
|
float
|
Nonnegative relative band around each criterion threshold. It changes
only |
0.05
|
pip_denominator_relative_tolerance
|
float | None
|
Optional scaled singularity threshold for the dimensionless
Venkatarathnam-Oellrich criterion. |
None
|
pip_autodiff_chunk_size
|
int
|
Positive maximum number of independent equilibrium phases passed to one batched forward-mode autodiff evaluation of the Venkatarathnam-Oellrich parameter. Smaller chunks reduce temporary memory; larger chunks reduce repeated nested-JVP setup and result assembly. The default balances throughput with temporary memory for multicomponent CPU batches. This setting does not couple states or change the defining equations. |
4096
|
response_autodiff_chunk_size
|
int
|
Positive maximum number of independent equilibrium phases passed to one batched forward-mode autodiff evaluation of either response derivative criterion. Each requested method is evaluated independently; work is not shared between methods. |
2048
|
Returns:
| Type | Description |
|---|---|
GridPhaseIdentification
|
Per-phase identities, native criterion values and thresholds, ambiguity flags, paper-style region codes, total elapsed time, and one measured elapsed time per requested method. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If no method is requested, a method is repeated, the equilibrium arrays are inconsistent, or a criterion option is invalid. |
TypeError
|
If the model lacks a property required by a requested method and that method cannot report itself as unavailable. |
Notes
A non-converged equilibrium state or an unavailable/unknown phase identity
maps to the "unavailable" region. For two phases, any vapor-like phase
maps to "LV" and otherwise to "LL". Three phases share one plotting
category; inspect phase_identity_codes for the exact labels.
The two response-derivative criteria and the
Venkatarathnam-Oellrich pressure-derivative parameter evaluate first and
second PyTorch autodiff derivatives at every equilibrium composition. The
Li pseudo-critical-temperature and Perschke negative-flash algebra is also
evaluated over one leading phase batch when the required component
properties are tensors; models without those properties retain the scalar
unavailable-result behavior. Each requested method is executed as an
independent complete pass, so method_elapsed_seconds represents the
practical single-method workload rather than shared multi-method work. The
returned grid tensors are detached intentionally; the scalar
:func:identify_phase API retains its autodiff graph.
Source code in src/torch_flash/flash/grid.py
506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 | |
polish_grid_equilibrium_with_trust_region
¶
polish_grid_equilibrium_with_trust_region(
model: StateModel,
equilibrium: GridEquilibrium,
*,
tolerance: float = 1e-08,
material_balance_tolerance: float = 5e-11,
phase_fraction_tolerance: float = 1e-10,
phase_composition_merge_tolerance: float = 0.002,
max_iterations: int = 100,
chunk_size: int = 128,
) -> TrustRegionGridPolishResult
Audit a phase-discovered grid with batched Trust-Region minimization.
The calculation implements the improved mole-number (NLVM) Gibbs
formulation of Petitfrere and Nichita with one dependent reference phase
per component. Independently screened one-phase states are audited with
the paper's modified-TPD Trust-Region objective. The phase count and
starting compositions come from a completed :func:flash_grid or
:func:flash_grid_oracle result. States sharing a phase count are
evaluated in PyTorch batches; their exact Hessian blocks remain
mathematically independent.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
StateModel
|
Homogeneous-state model used to produce |
required |
equilibrium
|
GridEquilibrium
|
Phase-discovered grid containing temperatures in K, pressures in Pa, normalized feeds, phase fractions, and phase compositions. |
required |
tolerance
|
float
|
Maximum dimensionless Gibbs-gradient and log-fugacity residual. |
1e-08
|
material_balance_tolerance
|
float
|
Maximum absolute component mole-fraction reconstruction residual. |
5e-11
|
phase_fraction_tolerance
|
float
|
Minimum positive molar fraction for every preserved phase. |
1e-10
|
phase_composition_merge_tolerance
|
float
|
Minimum maximum-component distance between every phase pair. |
0.002
|
max_iterations
|
int
|
Maximum accepted-or-rejected Trust-Region iterations per state. |
100
|
chunk_size
|
int
|
Maximum number of equal-phase-count states whose thermodynamic objectives, gradients, and exact Hessians are evaluated together. |
128
|
Returns:
| Type | Description |
|---|---|
TrustRegionGridPolishResult
|
Polished equilibrium plus per-state optimization, residual, curvature, and seed-change diagnostics. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If controls are invalid, grid arrays are inconsistent, a discovered phase count lies outside one through three, or an attempted feed is not strictly positive. |
Notes
This operation follows M. Petitfrere and D. V. Nichita, "Robust and efficient Trust-Region based stability analysis and multiphase flash calculations", Fluid Phase Equilibria 362 (2014), 51-68, equations (8)-(15) and sections 3.1-3.4, doi:10.1016/j.fluid.2013.08.039.
Phase discovery and local minimization answer different questions. The independent grid supplies the initial phase count and branch seeds. A negative one-phase Trust-Region TPD minimum may correct that count from one to two, but a local fixed-count minimum is still not a global stability proof.
Source code in src/torch_flash/flash/grid.py
3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 | |
refine_flash_grid_phase_boundaries
¶
refine_flash_grid_phase_boundaries(
model: StateModel,
temperature_axis: Tensor,
pressure_axis: Tensor,
composition: Tensor,
region_codes: Tensor,
converged: Tensor,
*,
identification_method: PhaseIdentificationCriterion = "pedersen-volume-to-covolume",
region_labels: tuple[str, ...] = (
"LV",
"LL",
"three-phase",
),
refinement_iterations: int = 8,
flash_options: GridFlashOptions | None = None,
) -> PhaseRegionBoundarySet
Refine classified phase-region boundaries by batched edge bisection.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
StateModel
|
Homogeneous-state model used for both the supplied grid and all refinement flashes. |
required |
temperature_axis
|
Tensor
|
Strictly increasing one-dimensional grid coordinates in K and Pa. |
required |
pressure_axis
|
Tensor
|
Strictly increasing one-dimensional grid coordinates in K and Pa. |
required |
composition
|
Tensor
|
Fixed overall mole-fraction vector for the complete grid. |
required |
region_codes
|
Tensor
|
Two-dimensional integer classification with shape
|
required |
converged
|
Tensor
|
Boolean grid with the same shape. Edges touching a failed coarse state are excluded rather than relabeled. |
required |
identification_method
|
PhaseIdentificationCriterion
|
One physical phase-identification criterion applied to every
refinement flash. It must match the criterion used to construct
|
'pedersen-volume-to-covolume'
|
region_labels
|
tuple[str, ...]
|
Region labels to connect into curves. The default returns vapor-liquid, liquid-liquid, and identity-neutral three-phase boundaries. |
('LV', 'LL', 'three-phase')
|
refinement_iterations
|
int
|
Batched bisection passes per unique crossing edge. Eight passes reduce each coarse coordinate interval by a factor of 256. |
8
|
flash_options
|
GridFlashOptions | None
|
Optional :class: |
None
|
Returns:
| Type | Description |
|---|---|
PhaseRegionBoundarySet
|
Connected curves and explicit refinement diagnostics. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If axes, grid arrays, composition, labels, or numerical controls are invalid. |
Notes
A coarse grid remains responsible for global topology. This operation spends additional equilibrium solves only on edges whose endpoint region codes differ, then connects the refined crossings with a marching-squares graph. It removes half-cell contour quantization without pretending that interpolation alone solves the phase-equilibrium equations.
Classification and graph connectivity are discrete and intentionally
non-differentiable. Midpoint flashes retain the convergence, fugacity, and
material-balance gates of :func:flash_grid. A failed midpoint leaves its
edge bracket unchanged for that pass; it is counted rather than silently
used as a phase classification.
Source code in src/torch_flash/flash/grid.py
4017 4018 4019 4020 4021 4022 4023 4024 4025 4026 4027 4028 4029 4030 4031 4032 4033 4034 4035 4036 4037 4038 4039 4040 4041 4042 4043 4044 4045 4046 4047 4048 4049 4050 4051 4052 4053 4054 4055 4056 4057 4058 4059 4060 4061 4062 4063 4064 4065 4066 4067 4068 4069 4070 4071 4072 4073 4074 4075 4076 4077 4078 4079 4080 4081 4082 4083 4084 4085 4086 4087 4088 4089 4090 4091 4092 4093 4094 4095 4096 4097 4098 4099 4100 4101 4102 4103 4104 4105 4106 4107 4108 4109 4110 4111 4112 4113 4114 4115 4116 4117 4118 4119 4120 4121 4122 4123 4124 4125 4126 4127 4128 4129 4130 4131 4132 4133 4134 4135 4136 4137 4138 4139 4140 4141 4142 4143 4144 4145 4146 4147 4148 4149 4150 4151 4152 4153 4154 4155 4156 4157 4158 4159 4160 4161 4162 4163 4164 4165 4166 4167 4168 4169 4170 4171 4172 4173 4174 4175 4176 4177 4178 4179 4180 4181 4182 4183 4184 4185 4186 4187 4188 4189 4190 4191 4192 4193 4194 4195 4196 4197 4198 4199 4200 4201 4202 4203 4204 4205 4206 4207 4208 4209 4210 4211 4212 4213 4214 4215 4216 4217 4218 4219 4220 4221 4222 4223 4224 4225 4226 4227 4228 4229 4230 4231 4232 4233 4234 4235 4236 4237 4238 4239 4240 4241 4242 4243 4244 4245 4246 4247 4248 4249 4250 4251 4252 4253 4254 4255 4256 4257 4258 4259 4260 4261 4262 4263 4264 4265 4266 4267 4268 4269 4270 4271 4272 4273 4274 4275 4276 4277 4278 4279 4280 4281 4282 4283 4284 4285 4286 4287 4288 4289 4290 4291 4292 4293 4294 4295 4296 4297 4298 4299 4300 4301 4302 4303 4304 4305 4306 4307 4308 4309 4310 4311 4312 4313 4314 4315 4316 4317 4318 4319 4320 4321 4322 4323 4324 4325 4326 4327 4328 4329 4330 4331 4332 4333 4334 4335 4336 4337 4338 4339 4340 4341 4342 4343 4344 4345 4346 4347 4348 4349 4350 4351 4352 4353 4354 4355 | |
solve_batched_binary_three_phase_invariants
¶
solve_batched_binary_three_phase_invariants(
model: StateModel,
temperature: Tensor,
initial_pressure: Tensor,
initial_phase_compositions: Tensor,
*,
phase_roots: tuple[PhaseKind, PhaseKind, PhaseKind] = (
"liquid",
"liquid",
"vapor",
),
tolerance: float = 1e-11,
max_iterations: int = 12,
method: Literal["newton", "trust-region"] = "newton",
) -> BinaryThreePhaseInvariantBatch
Close independent binary three-phase invariants in one PyTorch batch.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
StateModel
|
Two-component homogeneous-state model shared by every state. |
required |
temperature
|
Tensor
|
One-dimensional state temperatures in K and positive branch pressure estimates in Pa. |
required |
initial_pressure
|
Tensor
|
One-dimensional state temperatures in K and positive branch pressure estimates in Pa. |
required |
initial_phase_compositions
|
Tensor
|
Strictly interior normalized guesses with shape |
required |
phase_roots
|
tuple[PhaseKind, PhaseKind, PhaseKind]
|
Common EoS roots used for the three phases. |
('liquid', 'liquid', 'vapor')
|
tolerance
|
float
|
Maximum per-state dimensionless log-fugacity residual. |
1e-11
|
max_iterations
|
int
|
Maximum batched damped-Newton or trust-region iterations. |
12
|
method
|
Literal['newton', 'trust-region']
|
|
'newton'
|
Returns:
| Type | Description |
|---|---|
BinaryThreePhaseInvariantBatch
|
Solved pressures, sorted compositions, and per-state diagnostics. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If shapes, guesses, roots, or numerical controls are invalid. |
Notes
This function solves the same four isofugacity equations as
:func:solve_binary_three_phase_invariant. States execute jointly as a
tensor batch but remain mathematically independent. Gradients through the
model parameters and converged local branches are preserved.
Source code in src/torch_flash/flash/grid.py
1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 | |
solve_binary_three_phase_invariant
¶
solve_binary_three_phase_invariant(
model: StateModel,
temperature: Tensor,
initial_pressure: Tensor,
initial_phase_compositions: Tensor,
*,
phase_roots: tuple[PhaseKind, PhaseKind, PhaseKind] = (
"liquid",
"liquid",
"vapor",
),
tolerance: float = 1e-11,
max_iterations: int = 12,
method: Literal["newton", "trust-region"] = "newton",
) -> BinaryThreePhaseInvariant
Close a binary three-phase invariant with an autodiff nonlinear solve.
The unknowns are the first-component mole fraction of each phase and the logarithm of pressure. Temperature is fixed. Equal component fugacities provide the four residual equations.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
StateModel
|
Two-component homogeneous-state model supplying differentiable log-fugacity coefficients. |
required |
temperature
|
Tensor
|
Scalar invariant temperature in K. |
required |
initial_pressure
|
Tensor
|
Positive scalar pressure guess in Pa. |
required |
initial_phase_compositions
|
Tensor
|
Strictly interior normalized guesses with shape |
required |
phase_roots
|
tuple[PhaseKind, PhaseKind, PhaseKind]
|
EoS roots used for the three guessed phases. The default represents two liquid roots and one vapor root. |
('liquid', 'liquid', 'vapor')
|
tolerance
|
float
|
Maximum absolute dimensionless log-fugacity mismatch required for convergence. |
1e-11
|
max_iterations
|
int
|
Maximum damped-Newton or trust-region iterations. |
12
|
method
|
Literal['newton', 'trust-region']
|
|
'newton'
|
Returns:
| Type | Description |
|---|---|
BinaryThreePhaseInvariant
|
Solved pressure, phase compositions sorted by first-component mole
fraction, residual, iteration count, and convergence flag. A failed
solve is returned explicitly with |
Raises:
| Type | Description |
|---|---|
ValueError
|
If temperature or pressure is not scalar, guesses do not have shape
|
RuntimeError
|
If PyTorch cannot solve the Newton linear system or the model fails at a trial state. |
Notes
Both methods solve the same four isofugacity equations with respect to
three composition logits and log pressure. The Newton method uses
:func:torch.func.jacrev and a residual-decreasing backtracking line
search. The trust-region method follows the exact-Hessian restricted-step
strategy of M. Petitfrere and D. V. Nichita, Fluid Phase Equilibria 362
(2014), 51-68, sections 3.1-3.4,
doi:10.1016/j.fluid.2013.08.039.
Both are local branch solves. A residual-converged result can still be the algebraic solution in which two phases coincide; callers must retain a phase-separation gate and use physically informed multiple starts.
Source code in src/torch_flash/flash/grid.py
1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 | |
multiphase_flash
¶
multiphase_flash(
model: StateModel,
state: ChemicalState,
*,
initial_k_values: Tensor | None = None,
tolerance: float = 1e-08,
max_iterations: int = 100,
) -> FlashResult
Solve a fixed-phase-count PT flash by generalized substitution.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
StateModel
|
Homogeneous-state model providing phase fugacity coefficients and properties. |
required |
state
|
ChemicalState
|
Feed state with temperature in K, pressure in Pa, and a one-dimensional overall mole-fraction vector. |
required |
initial_k_values
|
Tensor | None
|
Positive composition ratios to the reference liquid phase, with shape
|
None
|
tolerance
|
float
|
Convergence threshold for the maximum absolute log-fugacity residual. |
1e-08
|
max_iterations
|
int
|
Maximum generalized substitution/Newton iterations. |
100
|
Returns:
| Type | Description |
|---|---|
FlashResult
|
Fractions, phase properties, convergence status, fugacity residual, and generalized material-balance diagnostics. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the composition is batched or default K values cannot be generated. |
Warns:
| Type | Description |
|---|---|
ExperimentalModelWarning
|
On every call, because automatic phase discovery is not yet a global stability algorithm. |
ConvergenceWarning
|
If the fixed-phase-count equilibrium iterations do not converge. |
Notes
The number of phases is fixed by initial_k_values; this routine does
not prove that the selected phase count is globally stable. For VLL or VLW
calculations, supply physically informed initial ratios and inspect
FlashResult.converged, the residual, phase fractions, material balance,
and an independent stability analysis.
Source code in src/torch_flash/flash/multiphase.py
168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 | |
multiphase_trust_region_flash
¶
multiphase_trust_region_flash(
model: StateModel,
state: ChemicalState,
*,
initial_k_values: Tensor | None = None,
phase_roots: tuple[PhaseKind, ...] | None = None,
tolerance: float = 1e-08,
max_iterations: int = 100,
raise_on_failure: bool = False,
) -> FlashResult
Minimize fixed-count multiphase Gibbs energy by a dense trust region.
This implements the improved mole-number (NLVM) formulation of M. Petitfrere and D. V. Nichita, "Robust and efficient Trust-Region based stability analysis and multiphase flash calculations", Fluid Phase Equilibria 362 (2014), 51-68, equations (8)-(15) and sections 3.1-3.4, doi:10.1016/j.fluid.2013.08.039. For every component, the phase containing the largest initial amount is the dependent reference phase. All other phase amounts are independent, and component material balance is exact at every accepted step.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
StateModel
|
Homogeneous-state model providing fugacity coefficients and phase properties. |
required |
state
|
ChemicalState
|
Scalar temperature in K, pressure in Pa, and one strictly positive feed-composition vector. |
required |
initial_k_values
|
Tensor | None
|
Positive ratios to the first phase, shaped
|
None
|
phase_roots
|
tuple[PhaseKind, ...] | None
|
EoS root request for each fixed phase. When omitted, the first phase is liquid, the second vapor, and later phases liquid. |
None
|
tolerance
|
float
|
Maximum dimensionless chemical-potential residual and trust-region gradient norm. |
1e-08
|
max_iterations
|
int
|
Maximum accepted-or-rejected trust-region iterations. |
100
|
raise_on_failure
|
bool
|
Raise |
False
|
Returns:
| Type | Description |
|---|---|
FlashResult
|
Fixed-count phase fractions and properties, convergence status, chemical-potential residual, and trust-region diagnostics. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If state shapes, feed fractions, K values, phase roots, or numerical controls are invalid. |
RuntimeError
|
If convergence fails and |
Warns:
| Type | Description |
|---|---|
ExperimentalModelWarning
|
On every call because this operation does not discover the globally stable phase count. |
ConvergenceWarning
|
If the local minimum fails the physical or residual gates. |
Notes
This is a local fixed-phase-count minimization. Multiple stability starts remain necessary, and a converged stationary point does not prove global stability. Exact autodiff Hessians are appropriate for small dense phase systems; their cost can dominate ordinary two-phase states.
Source code in src/torch_flash/flash/multiphase.py
325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 | |
solve_generalized_rachford_rice
¶
solve_generalized_rachford_rice(
composition: Tensor,
k_values: Tensor,
*,
tolerance: float = 1e-12,
max_iterations: int = 100,
) -> tuple[Tensor, Tensor, int, bool]
Solve multiphase material balance for phase ratios to a reference phase.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
composition
|
Tensor
|
Overall mole fractions with shape |
required |
k_values
|
Tensor
|
Positive ratios to the reference-phase composition, with shape
|
required |
tolerance
|
float
|
Convergence threshold for the maximum absolute generalized Rachford--Rice residual. |
1e-12
|
max_iterations
|
int
|
Maximum safeguarded Newton iterations. |
100
|
Returns:
| Type | Description |
|---|---|
tuple
|
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If shapes are inconsistent or any equilibrium ratio is nonpositive. |
Notes
converged reports the material-balance solve only. Fugacity equality
must be checked separately by the enclosing multiphase flash.
Source code in src/torch_flash/flash/multiphase.py
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 | |
tangent_plane_stability
¶
tangent_plane_stability(
model: StateModel,
state: ChemicalState,
*,
reference_phase: PhaseKind = "stable",
initial_compositions: tuple[Tensor, ...] | None = None,
tolerance: float = 1e-09,
max_iterations: int = 40,
minimizer: Literal[
"line-search-newton", "trust-region"
] = "line-search-newton",
) -> StabilityResult
Assess local phase stability by minimizing tangent-plane distance.
The feed composition is evaluated as the reference state, and each trial composition is optimized in independent log-ratio coordinates. A negative normalized tangent-plane distance (TPD) identifies a composition that can lower the Gibbs energy. Multiple starting points are therefore important: the optimization is local and a single stationary point is not a global stability proof.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
StateModel
|
Homogeneous-state model providing log fugacity coefficients. |
required |
state
|
ChemicalState
|
Feed state. Temperature is in K, pressure is in Pa, and
|
required |
reference_phase
|
PhaseKind
|
Root requested when evaluating the feed fugacity coefficients.
Trial phases are evaluated with the model's |
'stable'
|
initial_compositions
|
tuple[Tensor, ...] | None
|
Optional trial mole-fraction vectors. Values are made positive and normalized before optimization. When omitted, the feed, Wilson-based vapor/liquid trials when available, and component-rich trials are used. |
None
|
tolerance
|
float
|
Maximum absolute gradient component used by each local minimization.
The stability decision allows a numerical margin of |
1e-09
|
max_iterations
|
int
|
Maximum Newton/globalization iterations for each starting point. |
40
|
minimizer
|
Literal['line-search-newton', 'trust-region']
|
Local TPD minimizer. |
'line-search-newton'
|
Returns:
| Type | Description |
|---|---|
StabilityResult
|
Lowest TPD found, its trial composition, local-solver diagnostics, and the resulting stability classification. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the feed composition is batched rather than one-dimensional. |
Notes
StabilityResult.converged describes the local minimization associated
with the reported minimum. Callers should not interpret a non-converged
nonnegative TPD as conclusive evidence of stability.
Source code in src/torch_flash/flash/stability.py
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 | |
two_phase_flash
¶
two_phase_flash(
model: StateModel,
state: ChemicalState,
*,
initial_k_values: Tensor | None = None,
check_stability: bool = True,
tolerance: float = 1e-08,
max_iterations: int = 100,
raise_on_failure: bool = False,
) -> FlashResult
Solve a scalar isothermal-isobaric two-phase flash.
The solver optionally applies Michelsen tangent-plane stability analysis, solves the material balance with the safeguarded Rachford--Rice solver, and enforces equality of component fugacities using successive substitution followed by autodiff-assembled Newton steps.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
StateModel
|
Homogeneous-state model providing phase fugacity coefficients and properties. |
required |
state
|
ChemicalState
|
Feed state with temperature in K, pressure in Pa, and one
mole-fraction vector of shape |
required |
initial_k_values
|
Tensor | None
|
Positive initial vapor-to-liquid equilibrium ratios with shape
|
None
|
check_stability
|
bool
|
Run tangent-plane stability analysis before attempting a split. A stable feed returns a one-phase result. |
True
|
tolerance
|
float
|
Convergence threshold for the maximum absolute log-fugacity residual. |
1e-08
|
max_iterations
|
int
|
Maximum phase-equilibrium iterations after initialization. |
100
|
raise_on_failure
|
bool
|
Raise |
False
|
Returns:
| Type | Description |
|---|---|
FlashResult
|
Phase fractions, identified phase properties, convergence status, iteration count, and residual diagnostics. For a two-phase result, fractions are ordered liquid then vapor before phase identification. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the composition is batched, suitable initial K values cannot be constructed, or no finite two-phase material-balance root is found. |
RuntimeError
|
If convergence fails and |
Warns:
| Type | Description |
|---|---|
ConvergenceWarning
|
If the requested split does not converge and |
Notes
The reported equilibrium residual is
max_i |log(K_i) - (log(phi_i^L) - log(phi_i^V))|. A converged
Rachford--Rice solve is necessary but is not by itself evidence of phase
equilibrium.
Source code in src/torch_flash/flash/two_phase.py
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 | |
two_phase_trust_region_flash
¶
two_phase_trust_region_flash(
model: StateModel,
state: ChemicalState,
*,
initial_k_values: Tensor | None = None,
phase_roots: tuple[PhaseKind, PhaseKind] = (
"liquid",
"vapor",
),
check_stability: bool = True,
tolerance: float = 1e-08,
max_iterations: int = 100,
raise_on_failure: bool = False,
) -> FlashResult
Minimize two-phase Gibbs energy with an exact dense trust region.
The formulation follows M. Petitfrere and D. V. Nichita, "Robust and efficient Trust-Region based stability analysis and multiphase flash calculations", Fluid Phase Equilibria 362 (2014), 51-68, equations (8)-(15) and sections 3.1-3.4, doi:10.1016/j.fluid.2013.08.039. Direct component mole amounts in the initially smaller phase are independent variables; the corresponding amounts in the reference phase are dependent, so component material balance is exact at every accepted step. PyTorch autodiff supplies the exact gradient and Hessian.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
StateModel
|
Homogeneous-state fugacity model. |
required |
state
|
ChemicalState
|
Scalar temperature in K, pressure in Pa, and one feed-composition vector. |
required |
initial_k_values
|
Tensor | None
|
Optional positive vapor-to-liquid ratios. Wilson values are used when omitted. |
None
|
phase_roots
|
tuple[PhaseKind, PhaseKind]
|
Root requests for the two candidate phases. |
('liquid', 'vapor')
|
check_stability
|
bool
|
Run trust-region tangent-plane stability first. A stable feed returns one homogeneous phase without minimizing a split. |
True
|
tolerance
|
float
|
Maximum dimensionless log-fugacity residual and trust-region gradient tolerance. |
1e-08
|
max_iterations
|
int
|
Maximum trust-region iterations. |
100
|
raise_on_failure
|
bool
|
Raise |
False
|
Returns:
| Type | Description |
|---|---|
FlashResult
|
Phase fractions, properties, convergence flag, fugacity residual, and trust-region diagnostics. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If state shapes, phase roots, iteration controls, or initial ratios are invalid. |
RuntimeError
|
If the split fails and |
Warns:
| Type | Description |
|---|---|
ConvergenceWarning
|
If the trust-region stationary point does not also pass fugacity and phase-fraction gates. |
Notes
This is a local two-phase minimization. It does not replace multistart
stability analysis or prove that no third phase has lower Gibbs energy.
The default :func:two_phase_flash remains preferable for ordinary
well-conditioned vapor-liquid states unless matched benchmarks establish
a trust-region advantage.
Source code in src/torch_flash/flash/two_phase.py
220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 | |
Material balance¶
torch_flash.material_balance
¶
Material-balance equations.
rachford_rice_numpy
¶
rachford_rice_numpy(
composition: NDArray[float64],
k_values: NDArray[float64],
*,
tolerance: float = 1e-15,
max_iterations: int = 100,
) -> tuple[
int, NDArray[float64], NDArray[float64], float, float
]
NumPy compatibility wrapper matching the Whitson contest signature.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
composition
|
NDArray[float64]
|
One-dimensional overall mole-fraction array. |
required |
k_values
|
NDArray[float64]
|
One-dimensional positive vapor-to-liquid equilibrium ratios with the
same length as |
required |
tolerance
|
float
|
Accepted for signature compatibility; the delegated double-double solver controls its internal stopping criterion. |
1e-15
|
max_iterations
|
int
|
Accepted for signature compatibility and not used by the delegated solver. |
100
|
Returns:
| Type | Description |
|---|---|
tuple
|
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If inputs are not equally sized vectors or no finite root is bracketed. |
Notes
This exact-compatibility path delegates to the MIT-licensed
chemicals dependency. Its implementation applies double-double
arithmetic to the transformed/bounded formulation of Leibovici and Neoschil,
Fluid Phase Equilibria 74 (1992), 303-308,
doi:10.1016/0378-3812(92)85069-K. The dependency notice is retained in
THIRD_PARTY_NOTICES.md.
Source code in src/torch_flash/material_balance/rachford_rice.py
Saturation, envelopes, and binary equilibrium loci¶
torch_flash.envelope
¶
Saturation points and phase-envelope tracing.
Thermodynamic formulation and continuation context follow Michelsen and Mollerup, Thermodynamic Models: Fundamentals & Computational Aspects, 2nd ed. (2007), chapter 12, ISBN 978-87-989961-3-2.
SaturationPoint
dataclass
¶
SaturationPoint(
temperature: Tensor,
pressure: Tensor,
incipient_composition: Tensor,
k_values: Tensor,
kind: SaturationKind,
iterations: int,
converged: bool,
residual_norm: Tensor,
)
One bubble- or dew-point solution.
Attributes:
| Name | Type | Description |
|---|---|---|
temperature |
Tensor
|
Specified absolute temperature in K. |
pressure |
Tensor
|
Solved saturation pressure in Pa. |
incipient_composition |
Tensor
|
Normalized composition of the incipient phase. |
k_values |
Tensor
|
Final equilibrium ratios in feed-component order. |
kind |
SaturationKind
|
|
iterations |
int
|
Number of Newton iterations reported by the final solve. |
converged |
bool
|
Whether the complete equilibrium/closure residual met tolerance. |
residual_norm |
Tensor
|
Maximum absolute dimensionless residual. |
PhaseTransitionPoint
dataclass
¶
PhaseTransitionPoint(
temperature: Tensor,
pressure: Tensor,
parent_composition: Tensor,
incipient_composition: Tensor,
phase_kinds: tuple[PhaseKind, PhaseKind],
iterations: int,
converged: bool,
residual_norm: Tensor,
phase_separation: Tensor,
)
One locally solved incipient-phase pressure at specified T and feed.
Attributes:
| Name | Type | Description |
|---|---|---|
temperature |
Tensor
|
Specified absolute temperature in K. |
pressure |
Tensor
|
Solved transition pressure in Pa. |
parent_composition |
Tensor
|
Specified normalized composition of the disappearing parent phase. |
incipient_composition |
Tensor
|
Solved normalized composition of the emerging phase. |
phase_kinds |
tuple[PhaseKind, PhaseKind]
|
Algebraic EoS roots requested for the parent and incipient phases. |
iterations |
int
|
Number of damped-Newton iterations performed. |
converged |
bool
|
Whether both the fugacity residual and requested phase separation passed. |
residual_norm |
Tensor
|
Maximum absolute dimensionless log-fugacity residual. |
phase_separation |
Tensor
|
Maximum absolute component mole-fraction difference between phases. |
PhaseTransitionBatch
dataclass
¶
PhaseTransitionBatch(
temperature: Tensor,
pressure: Tensor,
parent_composition: Tensor,
incipient_composition: Tensor,
phase_kinds: tuple[PhaseKind, PhaseKind],
iterations: Tensor,
solver_converged: Tensor,
converged: Tensor,
residual_norm: Tensor,
phase_separation: Tensor,
)
Independent local transition-pressure solutions in one tensor batch.
Attributes:
| Name | Type | Description |
|---|---|---|
temperature |
Tensor
|
Absolute temperatures with shape |
pressure |
Tensor
|
Solved transition pressures with shape |
parent_composition, incipient_composition |
Normalized compositions with shape |
|
phase_kinds |
tuple[PhaseKind, PhaseKind]
|
Common algebraic EoS roots for the parent and incipient phases. |
iterations |
Tensor
|
Per-state damped-Newton iteration counts with shape |
solver_converged |
Tensor
|
Per-state fugacity-residual convergence flags. |
converged |
Tensor
|
Per-state flags requiring both fugacity convergence and the requested minimum phase separation. |
residual_norm |
Tensor
|
Per-state maximum dimensionless log-fugacity residual. |
phase_separation |
Tensor
|
Per-state maximum absolute component-composition difference. |
PhaseTransitionState
dataclass
¶
PhaseTransitionState(
temperature: Tensor,
reference_pressure: Tensor,
parent_composition: Tensor,
boundary_kind: PhaseBoundaryKind,
minimum_pressure: Tensor | float | None = None,
maximum_pressure: Tensor | float | None = None,
initial_incipient_compositions: tuple[Tensor, ...] = (),
initial_three_phase_compositions: tuple[
Tensor, ...
] = (),
)
One reference state for a local phase-transition calculation.
Attributes:
| Name | Type | Description |
|---|---|---|
temperature |
Tensor
|
Scalar absolute temperature in K. |
reference_pressure |
Tensor
|
Positive scalar pressure in Pa used to initialize and, when multiple disconnected roots are found, identify the corresponding local branch. |
parent_composition |
Tensor
|
Strictly positive parent/overall composition vector. |
boundary_kind |
PhaseBoundaryKind
|
|
minimum_pressure, maximum_pressure |
Optional positive scalar pressure bounds in Pa. If omitted, the
evaluator uses one quarter and four times |
|
initial_incipient_compositions |
tuple[Tensor, ...]
|
Optional two-phase incipient-composition starts. Generic Wilson, uniform, and component-rich starts are used when empty. |
initial_three_phase_compositions |
tuple[Tensor, ...]
|
Optional binary three-phase starts with shape |
PhaseTransitionEvaluation
dataclass
¶
PhaseTransitionEvaluation(
state: PhaseTransitionState,
pressure: Tensor,
phase_compositions: Tensor,
residual_norm: Tensor,
phase_separation: Tensor,
iterations: int,
solver_converged: bool,
converged: bool,
solver: Literal["newton", "trust-region"] = "newton",
)
Selected physical result for one :class:PhaseTransitionState.
Attributes:
| Name | Type | Description |
|---|---|---|
state |
PhaseTransitionState
|
Reference state and branch specification. |
pressure |
Tensor
|
Selected calculated transition pressure in Pa, or NaN if no candidate produced a finite pressure. |
phase_compositions |
Tensor
|
Selected incipient composition with shape |
residual_norm |
Tensor
|
Maximum absolute dimensionless log-fugacity mismatch. |
phase_separation |
Tensor
|
Maximum two-phase component difference or minimum adjacent binary three-phase composition difference. |
iterations |
int
|
Nonlinear iterations reported by the selected candidate. |
solver_converged |
bool
|
Whether fugacity equations converged before the phase-separation gate. |
converged |
bool
|
Whether fugacity and physical phase-separation gates both passed. |
solver |
Literal['newton', 'trust-region']
|
Nonlinear method that produced the selected candidate. |
PhaseEnvelopeSet
dataclass
¶
PhaseEnvelopeSet(
vapor_liquid: dict[
SaturationKind, tuple[SaturationPoint, ...]
],
liquid_liquid: tuple[
tuple[PhaseTransitionPoint, ...], ...
],
)
Fixed-composition vapor-liquid and liquid-liquid phase boundaries.
Attributes:
| Name | Type | Description |
|---|---|---|
vapor_liquid |
dict[SaturationKind, tuple[SaturationPoint, ...]]
|
Bubble and dew branches on the requested vapor-liquid temperature sequence. Failed points remain explicit. |
liquid_liquid |
tuple[tuple[PhaseTransitionPoint, ...], ...]
|
Independently continued liquid-liquid branches, each ordered by increasing temperature and retaining explicit failed points. |
BinaryVLEPoint
dataclass
¶
BinaryVLEPoint(
temperature: Tensor,
pressure: Tensor,
liquid_composition: Tensor,
vapor_composition: Tensor,
iterations: int,
converged: bool,
residual_norm: Tensor,
)
Coexisting binary liquid and vapor compositions at fixed T and P.
Attributes:
| Name | Type | Description |
|---|---|---|
temperature, pressure |
Specified temperature in K and pressure in Pa. |
|
liquid_composition, vapor_composition |
Two-component normalized mole-fraction vectors. |
|
iterations |
int
|
Number of nonlinear iterations performed. |
converged |
bool
|
Whether fugacity equality converged and the phases remain separated by the requested minimum distance. |
residual_norm |
Tensor
|
Maximum absolute dimensionless equilibrium residual. |
FixedVaporRatioVLEPoint
dataclass
¶
FixedVaporRatioVLEPoint(
temperature: Tensor,
pressure: Tensor,
liquid_composition: Tensor,
vapor_composition: Tensor,
variable_vapor_component: int,
iterations: int,
converged: bool,
residual_norm: Tensor,
phase_separation: Tensor,
)
VLE compositions at fixed T, P, and dry-vapor component ratio.
Attributes:
| Name | Type | Description |
|---|---|---|
temperature, pressure |
Specified temperature in K and pressure in Pa. |
|
liquid_composition, vapor_composition |
Solved normalized liquid and vapor mole-fraction vectors. Ratios among the non-variable vapor components equal the specified reference ratio. |
|
variable_vapor_component |
int
|
Component index whose vapor fraction was solved independently. |
iterations |
int
|
Number of damped-Newton iterations performed. |
converged |
bool
|
Whether the fugacity residual met tolerance and the two phases remain physically separated. |
residual_norm |
Tensor
|
Maximum absolute dimensionless log-fugacity residual. |
phase_separation |
Tensor
|
Maximum absolute component mole-fraction difference between phases. |
BinaryVLEPointWithVolumes
dataclass
¶
BinaryVLEPointWithVolumes(
temperature: Tensor,
pressure: Tensor,
liquid_composition: Tensor,
vapor_composition: Tensor,
iterations: int,
converged: bool,
residual_norm: Tensor,
liquid_molar_volume: Tensor,
vapor_molar_volume: Tensor,
)
Bases: BinaryVLEPoint
Binary fixed-pressure coexistence point retaining both molar volumes.
This result extends :class:BinaryVLEPoint with the liquid and vapor
molar volumes used by a volume-based equilibrium solver. The container is
named for its reusable thermodynamic payload; the currently producing
operation, :func:binary_helmholtz_vle_point, carries the Helmholtz-model
restriction.
Attributes:
| Name | Type | Description |
|---|---|---|
temperature, pressure |
Specified temperature in K and pressure in Pa. |
|
liquid_composition, vapor_composition |
Solved normalized binary phase compositions. |
|
iterations, converged, residual_norm |
Nonlinear iteration count, physical-convergence status, and maximum absolute dimensionless residual. |
|
liquid_molar_volume, vapor_molar_volume |
Coexisting molar volumes in m3/mol retained for continuation. |
BinaryBubblePoint
dataclass
¶
BinaryBubblePoint(
temperature: Tensor,
pressure: Tensor,
liquid_composition: Tensor,
vapor_composition: Tensor,
iterations: int,
converged: bool,
residual_norm: Tensor,
)
Binary bubble pressure and incipient vapor at specified T, x.
Attributes:
| Name | Type | Description |
|---|---|---|
temperature |
Tensor
|
Specified temperature in K. |
pressure |
Tensor
|
Solved bubble pressure in Pa. |
liquid_composition |
Tensor
|
Specified normalized binary liquid composition. |
vapor_composition |
Tensor
|
Solved normalized incipient-vapor composition. |
iterations, converged, residual_norm |
Nonlinear iteration count, convergence status, and maximum absolute dimensionless residual. |
BinaryBubbleTemperature
dataclass
¶
BinaryBubbleTemperature(
temperature: Tensor,
pressure: Tensor,
liquid_composition: Tensor,
vapor_composition: Tensor,
iterations: int,
converged: bool,
residual_norm: Tensor,
phase_separation: Tensor,
)
Binary bubble temperature and incipient vapor at specified P, x.
Attributes:
| Name | Type | Description |
|---|---|---|
temperature |
Tensor
|
Solved bubble temperature in K. |
pressure |
Tensor
|
Specified pressure in Pa. |
liquid_composition |
Tensor
|
Specified normalized binary liquid composition. |
vapor_composition |
Tensor
|
Solved normalized incipient-vapor composition. |
iterations, converged, residual_norm |
Nonlinear iteration count, physical-convergence status, and maximum absolute dimensionless log-fugacity residual. |
|
phase_separation |
Tensor
|
Maximum absolute liquid-vapor mole-fraction difference. This is reported separately because the algebraic homogeneous solution is not a two-phase bubble point. |
BinaryBubblePointWithVolumes
dataclass
¶
BinaryBubblePointWithVolumes(
temperature: Tensor,
pressure: Tensor,
liquid_composition: Tensor,
vapor_composition: Tensor,
iterations: int,
converged: bool,
residual_norm: Tensor,
liquid_molar_volume: Tensor,
vapor_molar_volume: Tensor,
)
Bases: BinaryBubblePoint
Binary bubble point retaining the coexisting phase molar volumes.
This result extends :class:BinaryBubblePoint with the liquid and vapor
molar volumes used by a volume-based equilibrium solver. The payload is a
thermodynamic result rather than an equation-of-state implementation:
any compatible algorithm can populate it. A Helmholtz-specific public
operation currently produces it in :func:binary_helmholtz_bubble_point.
Attributes:
| Name | Type | Description |
|---|---|---|
temperature, pressure |
Specified temperature in K and solved bubble pressure in Pa. |
|
liquid_composition, vapor_composition |
Specified binary liquid composition and solved incipient-vapor composition. |
|
iterations, converged, residual_norm |
Nonlinear iteration count, convergence status, and maximum absolute dimensionless residual. |
|
liquid_molar_volume, vapor_molar_volume |
Coexisting molar volumes in m3/mol. Reusing them as continuation variables can avoid nested liquid and vapor density inversions. |
BinaryPxyIsotherm
dataclass
¶
BinaryPxyIsotherm(
temperature: Tensor,
pressure: Tensor,
liquid_composition: Tensor,
vapor_composition: Tensor,
iterations: Tensor,
converged: Tensor,
residual_norm: Tensor,
phase_separation: Tensor,
)
Liquid-composition continuation of a binary pressure-composition trace.
Attributes:
| Name | Type | Description |
|---|---|---|
temperature |
Tensor
|
Specified scalar temperature in K. |
pressure |
Tensor
|
Attempted bubble pressures in Pa. |
liquid_composition, vapor_composition |
Coexisting binary composition arrays with shape |
|
iterations |
Tensor
|
Nonlinear iteration count for every attempted point. |
converged |
Tensor
|
Physical-convergence mask requiring the nonlinear residual and minimum phase separation to pass. |
residual_norm |
Tensor
|
Maximum absolute dimensionless equilibrium residual at every point. |
phase_separation |
Tensor
|
Maximum absolute liquid-vapor mole-fraction difference. |
BinaryTxyIsobar
dataclass
¶
BinaryTxyIsobar(
pressure: Tensor,
temperature: Tensor,
liquid_composition: Tensor,
vapor_composition: Tensor,
iterations: Tensor,
converged: Tensor,
residual_norm: Tensor,
phase_separation: Tensor,
)
Liquid-composition continuation of a binary temperature-composition trace.
Attributes:
| Name | Type | Description |
|---|---|---|
pressure |
Tensor
|
Specified scalar pressure in Pa. |
temperature |
Tensor
|
Attempted bubble temperatures in K. |
liquid_composition, vapor_composition |
Coexisting binary composition arrays with shape |
|
iterations |
Tensor
|
Nonlinear iteration count for every attempted point. |
converged |
Tensor
|
Physical-convergence mask requiring both the nonlinear residual and minimum phase separation to pass. |
residual_norm |
Tensor
|
Maximum absolute dimensionless equilibrium residual at every point. |
phase_separation |
Tensor
|
Maximum absolute liquid-vapor mole-fraction difference. |
BinaryFixedCompositionBoundary
dataclass
¶
BinaryFixedCompositionBoundary(
temperature: Tensor,
bubble_pressure: Tensor,
dew_pressure: Tensor,
bubble_converged: Tensor,
bubble_above_reporting_limit: Tensor,
dew_converged: Tensor,
dew_below_scan: Tensor,
bubble_separation: Tensor,
bubble_residual: Tensor,
dew_residual: Tensor,
)
Pressure boundaries of a binary two-phase region at fixed composition.
Attributes:
| Name | Type | Description |
|---|---|---|
temperature |
Tensor
|
Requested one-dimensional temperature grid in K. |
bubble_pressure, dew_pressure |
Upper and lower boundary pressures in Pa. Missing crossings are NaN; an upper boundary above the requested reporting limit is clipped to that limit. |
|
bubble_converged, dew_converged |
Whether each boundary was resolved from physically separated, residual-converged bubble points. |
|
bubble_above_reporting_limit |
Tensor
|
Whether the upper boundary lies at or above the reporting limit. |
dew_below_scan |
Tensor
|
Whether the lower crossing lies below the liquid-composition scan. |
bubble_separation |
Tensor
|
Vapor-liquid separation in the selected volatile-component coordinate at the upper boundary. |
bubble_residual, dew_residual |
Conservative dimensionless residual associated with each interpolated boundary. |
BinaryPhaseEquilibriumPoint
dataclass
¶
BinaryPhaseEquilibriumPoint(
temperature: Tensor,
pressure: Tensor,
phase1_composition: Tensor,
phase2_composition: Tensor,
phase_kinds: tuple[PhaseKind, PhaseKind],
iterations: int,
converged: bool,
residual_norm: Tensor,
)
Coexisting binary compositions for a requested pair of phase roots.
Attributes:
| Name | Type | Description |
|---|---|---|
temperature, pressure |
Specified temperature in K and pressure in Pa. |
|
phase1_composition, phase2_composition |
Solved normalized binary phase compositions. |
|
phase_kinds |
tuple[PhaseKind, PhaseKind]
|
Algebraic root requested for each phase. |
iterations, converged, residual_norm |
Nonlinear iteration count, convergence/separation status, and maximum absolute dimensionless residual. |
BinaryCriticalPoint
dataclass
¶
BinaryCriticalPoint(
temperature: Tensor,
pressure: Tensor,
molar_volume: Tensor,
composition: Tensor,
iterations: int,
converged: bool,
residual_norm: Tensor,
)
Binary-mixture critical point at a specified overall composition.
Attributes:
| Name | Type | Description |
|---|---|---|
temperature, pressure |
Solved critical temperature in K and pressure in Pa. |
|
molar_volume |
Tensor
|
Solved critical molar volume in m3/mol. |
composition |
Tensor
|
Specified normalized binary composition. |
iterations |
int
|
Number of nonlinear iterations performed. |
converged |
bool
|
Whether the criticality residual met tolerance. |
residual_norm |
Tensor
|
Maximum absolute scaled criticality residual. |
saturation_point
¶
saturation_point(
model: StateModel,
temperature: Tensor,
composition: Tensor,
kind: SaturationKind,
*,
initial_pressure: Tensor | None = None,
initial_k_values: Tensor | None = None,
tolerance: float = 1e-08,
max_iterations: int = 40,
substitution_iterations: int | None = None,
) -> SaturationPoint
Calculate an isothermal bubble or dew point with full Newton updates.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
StateModel
|
Homogeneous-state model providing liquid and vapor fugacity coefficients and critical constants for default initialization. |
required |
temperature
|
Tensor
|
Scalar temperature in K. |
required |
composition
|
Tensor
|
Feed-phase mole-fraction vector. |
required |
kind
|
SaturationKind
|
|
required |
initial_pressure
|
Tensor | None
|
Optional positive pressure estimate in Pa. |
None
|
initial_k_values
|
Tensor | None
|
Optional positive vapor-to-liquid equilibrium-ratio vector. |
None
|
tolerance
|
float
|
Maximum absolute equilibrium/closure residual. |
1e-08
|
max_iterations
|
int
|
Maximum nonlinear iterations. |
40
|
substitution_iterations
|
int | None
|
Number of Michelsen substitution passes before Newton. |
None
|
Returns:
| Type | Description |
|---|---|
SaturationPoint
|
Pressure, incipient composition, K values, and explicit nonlinear convergence diagnostics. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If kind, initialization, component data, or iteration controls are invalid. |
Notes
substitution_iterations=None applies up to 20 Michelsen successive-
substitution steps before Newton. A continuation driver with a nearby
converged state can reduce this count; :func:phase_envelope does so only
after a two-point secant predictor is available. Both the initializer and
Newton iterates are confined to the same finite ln(K) and pressure
bounds.
Source code in src/torch_flash/envelope.py
589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 | |
phase_transition_pressure
¶
phase_transition_pressure(
model: StateModel,
temperature: Tensor,
parent_composition: Tensor,
*,
phase_kinds: tuple[PhaseKind, PhaseKind] = (
"liquid",
"vapor",
),
initial_pressure: Tensor | None = None,
initial_incipient_composition: Tensor | None = None,
minimum_pressure: Tensor | float | None = None,
maximum_pressure: Tensor | float | None = None,
minimum_phase_separation: float = 1e-06,
tolerance: float = 1e-08,
max_iterations: int = 40,
) -> PhaseTransitionPoint
Solve a local incipient-phase pressure at specified T and composition.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
StateModel
|
Homogeneous-state fugacity model. |
required |
temperature
|
Tensor
|
Scalar absolute temperature in K. |
required |
parent_composition
|
Tensor
|
Strictly positive parent-phase mole fractions. At an incipient transition this equals the specified overall composition. |
required |
phase_kinds
|
tuple[PhaseKind, PhaseKind]
|
Algebraic EoS roots for the parent and incipient phases. Use
|
('liquid', 'vapor')
|
initial_pressure
|
Tensor | None
|
Positive pressure estimate in Pa. It is required unless
|
None
|
initial_incipient_composition
|
Tensor | None
|
Strictly positive incipient-phase composition estimate. It is required when both phases request the same root because the homogeneous composition is also an algebraic solution. |
None
|
minimum_pressure
|
Tensor | float | None
|
Optional positive pressure bounds in Pa. Bounds are important when disconnected L-L branches exist. |
None
|
maximum_pressure
|
Tensor | float | None
|
Optional positive pressure bounds in Pa. Bounds are important when disconnected L-L branches exist. |
None
|
minimum_phase_separation
|
float
|
Minimum maximum-component mole-fraction difference required to accept the result as two distinct phases. |
1e-06
|
tolerance
|
float
|
Maximum absolute dimensionless log-fugacity residual. |
1e-08
|
max_iterations
|
int
|
Maximum damped-Newton iterations. |
40
|
Returns:
| Type | Description |
|---|---|
PhaseTransitionPoint
|
Pressure, incipient composition, roots, and explicit residual, iteration, convergence, and phase-separation diagnostics. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If a state, root, initialization, bound, or numerical control is invalid. |
Notes
The formulation follows the isofugacity and incipient-phase equations in
Michelsen and Mollerup, Thermodynamic Models: Fundamentals &
Computational Aspects, 2nd ed. (2007), chapter 12,
ISBN 978-87-989961-3-2. The first n-1 unknowns are incipient-phase
composition logits and the final unknown is logarithmic pressure.
This is a local branch calculation, not a stability proof or automatic
phase-topology search. Initial estimates and pressure bounds select among
disconnected roots. A residual-converged homogeneous solution is returned
with converged=False when it fails minimum_phase_separation.
Source code in src/torch_flash/envelope.py
778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 | |
solve_batched_phase_transition_pressures
¶
solve_batched_phase_transition_pressures(
model: StateModel,
temperature: Tensor,
parent_composition: Tensor,
*,
phase_kinds: tuple[PhaseKind, PhaseKind],
initial_pressure: Tensor,
initial_incipient_composition: Tensor,
minimum_pressure: Tensor | float | None = None,
maximum_pressure: Tensor | float | None = None,
minimum_phase_separation: float = 1e-06,
tolerance: float = 1e-08,
max_iterations: int = 40,
) -> PhaseTransitionBatch
Solve independent local transition pressures in one PyTorch batch.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
StateModel
|
Homogeneous-state fugacity model shared by every state. |
required |
temperature
|
Tensor
|
Absolute temperatures with shape |
required |
parent_composition
|
Tensor
|
Strictly positive parent-phase mole fractions with shape
|
required |
phase_kinds
|
tuple[PhaseKind, PhaseKind]
|
Common algebraic roots for parent and incipient phases. Batch liquid-vapor and liquid-liquid states separately. |
required |
initial_pressure
|
Tensor
|
Positive branch pressure estimates with shape |
required |
initial_incipient_composition
|
Tensor
|
Strictly positive branch composition estimates with shape
|
required |
minimum_pressure
|
Tensor | float | None
|
Optional positive scalar or |
None
|
maximum_pressure
|
Tensor | float | None
|
Optional positive scalar or |
None
|
minimum_phase_separation
|
float
|
Minimum maximum-component mole-fraction difference required for a physical two-phase result. |
1e-06
|
tolerance
|
float
|
Maximum per-state dimensionless log-fugacity residual. |
1e-08
|
max_iterations
|
int
|
Maximum batched damped-Newton iterations. |
40
|
Returns:
| Type | Description |
|---|---|
PhaseTransitionBatch
|
Pressures, phase compositions, and explicit per-state diagnostics. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If tensor shapes, states, roots, bounds, or numerical controls are invalid. |
Notes
This is the batched form of :func:phase_transition_pressure. It solves
the same local isofugacity equations and preserves gradients through every
state. All states execute together in one tensor batch; they do not share
material balance or alter one another's branch seed.
Source code in src/torch_flash/envelope.py
1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 | |
evaluate_phase_transition_state
¶
evaluate_phase_transition_state(
model: StateModel,
state: PhaseTransitionState,
*,
tolerance: float = 1e-08,
max_iterations: int = 40,
minimum_phase_separation: float = 0.002,
exhaustive_two_phase_starts: bool = False,
three_phase_solver: ThreePhaseSolver = "newton",
) -> PhaseTransitionEvaluation
Evaluate and select a physical branch at one reference state.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
StateModel
|
Homogeneous-state fugacity model. |
required |
state
|
PhaseTransitionState
|
Temperature, reference pressure, composition, transition identity, optional bounds, and optional multi-start compositions. |
required |
tolerance
|
float
|
Maximum absolute dimensionless log-fugacity residual. |
1e-08
|
max_iterations
|
int
|
Maximum nonlinear iterations per candidate. |
40
|
minimum_phase_separation
|
float
|
Minimum two-phase component difference or adjacent binary three-phase composition difference. |
0.002
|
exhaustive_two_phase_starts
|
bool
|
Evaluate every declared liquid-vapor start before selecting the closest physical pressure. By default, the ordered Wilson, uniform, and component-rich starts are lazy fallbacks: the first physical liquid-vapor result is returned. Liquid-liquid and three-phase searches remain exhaustive. |
False
|
three_phase_solver
|
ThreePhaseSolver
|
|
'newton'
|
Returns:
| Type | Description |
|---|---|
PhaseTransitionEvaluation
|
First physical ordered liquid-vapor candidate unless exhaustive search
is requested. Exhaustive searches select the candidate closest in
logarithmic pressure to |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the boundary identity, state tensors, numerical controls, or a three-phase non-binary composition are invalid. |
Notes
Two-phase candidates solve the incipient equations documented by
:func:phase_transition_pressure. Binary three-phase candidates use
:func:torch_flash.flash.solve_binary_three_phase_invariant. Both follow
the isofugacity formulation of Michelsen and Mollerup,
Thermodynamic Models: Fundamentals & Computational Aspects, 2nd ed.
(2007), chapter 12, ISBN 978-87-989961-3-2.
The reference pressure identifies a disconnected experimental or application branch; it is not included as an equilibrium residual. Candidate selection is discrete and therefore not differentiable. The selected pressure and residual retain their PyTorch parameter graph.
Source code in src/torch_flash/envelope.py
1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 | |
evaluate_phase_transition_states
¶
evaluate_phase_transition_states(
model: StateModel,
states: Sequence[PhaseTransitionState],
*,
tolerance: float = 1e-08,
max_iterations: int = 40,
minimum_phase_separation: float = 0.002,
exhaustive_two_phase_starts: bool = False,
three_phase_solver: ThreePhaseSolver = "newton",
) -> tuple[PhaseTransitionEvaluation, ...]
Evaluate independent phase-transition reference states.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
StateModel
|
Homogeneous-state model shared by all supplied states. |
required |
states
|
Sequence[PhaseTransitionState]
|
Independent states whose composition length must match |
required |
tolerance
|
float
|
|
1e-08
|
max_iterations
|
float
|
|
1e-08
|
minimum_phase_separation
|
float
|
|
1e-08
|
exhaustive_two_phase_starts
|
bool
|
Controls passed to :func: |
False
|
three_phase_solver
|
bool
|
Controls passed to :func: |
False
|
Returns:
| Type | Description |
|---|---|
tuple
|
One explicit evaluation per input state, preserving input order. |
Notes
States are independent and may select disconnected branches through their reference pressures. No material balance is imposed between states.
Source code in src/torch_flash/envelope.py
1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 | |
continue_phase_transition_branch
¶
continue_phase_transition_branch(
model: StateModel,
temperatures: Tensor,
initial_point: PhaseTransitionPoint,
*,
minimum_pressure: Tensor | float | None = None,
maximum_pressure: Tensor | float | None = None,
minimum_phase_separation: float = 1e-06,
tolerance: float = 1e-08,
max_iterations: int = 40,
) -> tuple[PhaseTransitionPoint, ...]
Continue one incipient two-phase branch over a temperature sequence.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
StateModel
|
Homogeneous-state fugacity model used for every continuation point. |
required |
temperatures
|
Tensor
|
Nonempty one-dimensional temperature sequence in K, ordered in the desired continuation direction. |
required |
initial_point
|
PhaseTransitionPoint
|
Converged branch seed supplying the parent composition, phase-root pair, pressure, and incipient-phase composition. |
required |
minimum_pressure
|
Tensor | float | None
|
Optional positive pressure bounds in Pa applied to every point. Bounds can isolate a disconnected liquid-liquid branch. |
None
|
maximum_pressure
|
Tensor | float | None
|
Optional positive pressure bounds in Pa applied to every point. Bounds can isolate a disconnected liquid-liquid branch. |
None
|
minimum_phase_separation
|
float
|
Minimum maximum-component mole-fraction difference required to accept two physically distinct phases. |
1e-06
|
tolerance
|
float
|
Maximum absolute dimensionless log-fugacity residual. |
1e-08
|
max_iterations
|
int
|
Maximum damped-Newton iterations per temperature. |
40
|
Returns:
| Type | Description |
|---|---|
tuple
|
One :class: |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the temperature grid is invalid or |
Notes
The local equilibrium equations are those of
:func:phase_transition_pressure, following Michelsen and Mollerup,
Thermodynamic Models: Fundamentals & Computational Aspects, 2nd ed.
(2007), chapter 12, ISBN 978-87-989961-3-2. Previous-point continuation is
a numerical branch-tracking choice made explicitly by torch-flash.
The caller controls direction, spacing, and pressure bounds because these
choices can select among disconnected phase-transition branches.
Continuation initial states are detached between points. Each returned solve can still carry parameter derivatives, but the discrete decision to retain or reject an initializer is not differentiable.
Source code in src/torch_flash/envelope.py
1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 | |
phase_envelope
¶
phase_envelope(
model: StateModel,
temperatures: Tensor,
composition: Tensor,
*,
kinds: tuple[SaturationKind, ...] = ("bubble", "dew"),
accelerated: bool = True,
) -> dict[SaturationKind, tuple[SaturationPoint, ...]]
Trace bubble/dew branches over a specified temperature grid.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
StateModel
|
Homogeneous-state model for saturation calculations. |
required |
temperatures
|
Tensor
|
One-dimensional temperature sequence in K, in desired continuation order. |
required |
composition
|
Tensor
|
Feed mole-fraction vector. |
required |
kinds
|
tuple[SaturationKind, ...]
|
Bubble and/or dew branches to trace. |
('bubble', 'dew')
|
accelerated
|
bool
|
Use two-point secant prediction after two converged points. |
True
|
Returns:
| Type | Description |
|---|---|
dict
|
Mapping from saturation kind to one :class: |
Notes
After two converged points, a secant predictor extrapolates ln(K) and
ln(P) to the next temperature. Two successive-substitution corrections
then keep the estimate on the physical branch before Newton. This avoids
repeating the full 20-step initializer at every dense-grid point. A
failed accelerated point, or one that abruptly collapses toward the
algebraic K=1 solution, is retried with the original robust
initializer. Set accelerated=False to reproduce the former previous-
point/full-initializer algorithm for numerical comparison.
Source code in src/torch_flash/envelope.py
2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 | |
trace_phase_envelope_set
¶
trace_phase_envelope_set(
model: StateModel,
composition: Tensor,
vapor_liquid_temperatures: Tensor,
*,
liquid_liquid_seeds: Sequence[
PhaseTransitionEvaluation
] = (),
liquid_liquid_temperatures: Tensor | None = None,
minimum_pressure: Tensor | float | None = None,
maximum_pressure: Tensor | float | None = None,
minimum_phase_separation: float = 0.002,
tolerance: float = 1e-08,
max_iterations: int = 40,
vapor_liquid_closure_points: int = 20,
vapor_liquid_closure_log_k: float = 0.001,
) -> PhaseEnvelopeSet
Trace a complete fixed-composition fluid phase-boundary set.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
StateModel
|
Homogeneous-state fugacity model. |
required |
composition
|
Tensor
|
Fixed overall/parent mole-fraction vector. |
required |
vapor_liquid_temperatures
|
Tensor
|
Ordered temperature grid in K for both bubble and dew branches. |
required |
liquid_liquid_seeds
|
Sequence[PhaseTransitionEvaluation]
|
Residual- and separation-converged liquid-liquid reference evaluations. If several observations converge to the same branch, only the lowest- and highest-pressure distinct seeds are retained. |
()
|
liquid_liquid_temperatures
|
Tensor | None
|
Ordered temperature grid in K for each liquid-liquid branch. Required
when |
None
|
minimum_pressure
|
Tensor | float | None
|
Optional liquid-liquid continuation bounds in Pa. |
None
|
maximum_pressure
|
Tensor | float | None
|
Optional liquid-liquid continuation bounds in Pa. |
None
|
minimum_phase_separation
|
float
|
Minimum maximum-component composition difference for a physical liquid-liquid point. |
0.002
|
tolerance
|
float
|
Maximum absolute dimensionless log-fugacity residual. |
1e-08
|
max_iterations
|
int
|
Maximum nonlinear iterations per liquid-liquid continuation point. |
40
|
vapor_liquid_closure_points
|
int
|
Number of logarithmically spaced log-K continuation points used to approach each bubble/dew critical endpoint after fixed-temperature tracing. |
20
|
vapor_liquid_closure_log_k
|
float
|
Positive absolute controlled-component log-K target at the final critical-closure point. |
0.001
|
Returns:
| Type | Description |
|---|---|
PhaseEnvelopeSet
|
Bubble/dew branches and every distinct seeded liquid-liquid branch. Failed continuation points remain explicit. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If liquid-liquid seeds do not match the supplied composition or a continuation grid is missing. |
Notes
Bubble/dew tracing starts with :func:phase_envelope, then switches from
temperature to a selected log-K continuation coordinate through
:func:continue_saturation_branch. This passes the cricondentherm and
approaches the mixture critical endpoint without accepting the algebraic
K=1 root. Fixed-temperature points after the closure seed are replaced
by the ordered log-K continuation; failed continuation points remain
explicit. Liquid-liquid tracing uses
:func:continue_phase_transition_branch in both temperature directions
from each selected seed. The formulation follows Michelsen and Mollerup,
Thermodynamic Models: Fundamentals & Computational Aspects, 2nd ed.
(2007), chapter 12, ISBN 978-87-989961-3-2.
Temperature continuation can end at a critical merge or fail at a turning point. Such points are retained as non-converged; the result does not silently interpolate across a missing segment.
Source code in src/torch_flash/envelope.py
2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 | |
continue_saturation_branch
¶
continue_saturation_branch(
model: StateModel,
composition: Tensor,
initial_point: SaturationPoint,
target_log_k_values: Tensor,
*,
controlled_component: int = 0,
tolerance: float = 1e-09,
max_iterations: int = 60,
accelerated: bool = True,
) -> tuple[SaturationPoint, ...]
Continue a saturation branch using one ln(K_i) as coordinate.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
StateModel
|
Homogeneous-state model for saturation fugacity coefficients. |
required |
composition
|
Tensor
|
Feed mole-fraction vector. |
required |
initial_point
|
SaturationPoint
|
Converged bubble or dew point defining the initial branch. |
required |
target_log_k_values
|
Tensor
|
One-dimensional continuation coordinates in requested traversal order. |
required |
controlled_component
|
int
|
Component index whose log K value defines the coordinate. |
0
|
tolerance
|
float
|
Maximum absolute augmented-system residual. |
1e-09
|
max_iterations
|
int
|
Maximum Newton iterations per target. |
60
|
accelerated
|
bool
|
Use a two-point secant predictor when available. |
True
|
Returns:
| Type | Description |
|---|---|
tuple
|
One :class: |
Raises:
| Type | Description |
|---|---|
ValueError
|
If shapes, component index, or initial saturation kind are invalid. |
Notes
Temperature continuation becomes singular at a cricondentherm and can
jump to the algebraic K=1 solution near a mixture critical point.
Replacing temperature by a selected log-K value yields a square
(ln K, ln P, ln T) system that can pass both features. Points are
returned in the order of target_log_k_values and must not be sorted by
temperature when plotting a retrograde branch.
The caller controls step size through the supplied targets. A failed point
remains in the returned sequence with converged=False so scientific
workflows can expose, rather than silently interpolate across, a
continuation failure.
The default secant predictor extrapolates all continuation variables from
the previous two converged coordinates. Set accelerated=False to use
the former previous-point initializer for performance comparisons.
Source code in src/torch_flash/envelope.py
2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 | |
binary_critical_point
¶
binary_critical_point(
model: StateModel,
composition: Tensor,
*,
initial_temperature: Tensor | None = None,
initial_pressure: Tensor | None = None,
tolerance: float = 1e-09,
max_iterations: int = 30,
) -> BinaryCriticalPoint
Solve the binary mixture criticality conditions with autodiff.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
StateModel
|
Smooth homogeneous-state model providing stable-root Gibbs properties. |
required |
composition
|
Tensor
|
Strictly interior two-component mole-fraction vector. |
required |
initial_temperature
|
Tensor | None
|
Optional positive scalar estimates in K and Pa. Composition-weighted critical constants are used when omitted. |
None
|
initial_pressure
|
Tensor | None
|
Optional positive scalar estimates in K and Pa. Composition-weighted critical constants are used when omitted. |
None
|
tolerance
|
float
|
Maximum absolute scaled criticality residual. |
1e-09
|
max_iterations
|
int
|
Maximum damped-Newton iterations. |
30
|
Returns:
| Type | Description |
|---|---|
BinaryCriticalPoint
|
Solved temperature, pressure, volume, composition, and convergence diagnostics. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If composition is not binary/interior or initial estimates are not positive scalars. |
Notes
At fixed T and P, the second and third derivatives of the reduced
molar Gibbs energy of mixing with respect to the first mole fraction both
vanish at a binary critical point. Newton's Jacobian therefore uses up to
fourth-order PyTorch derivatives of the model; no hand-coded EoS
derivative expressions are required.
This composition-space formulation is specific to a binary mixture and a smooth homogeneous root. It is not a general multicomponent critical-locus solver.
Source code in src/torch_flash/envelope.py
2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 | |
binary_phase_equilibrium_point
¶
binary_phase_equilibrium_point(
model: StateModel,
temperature: Tensor,
pressure: Tensor,
initial_phase1_composition: Tensor,
initial_phase2_composition: Tensor,
*,
phase_kinds: tuple[PhaseKind, PhaseKind] = (
"stable",
"stable",
),
tolerance: float = 1e-08,
max_iterations: int = 30,
minimum_phase_separation: float = 1e-06,
) -> BinaryPhaseEquilibriumPoint
Solve binary phase coexistence at fixed T and P.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
StateModel
|
Homogeneous-state fugacity model. |
required |
temperature
|
Tensor
|
Scalar temperature in K and pressure in Pa. |
required |
pressure
|
Tensor
|
Scalar temperature in K and pressure in Pa. |
required |
initial_phase1_composition
|
Tensor
|
Initial two-component mole-fraction vectors. |
required |
initial_phase2_composition
|
Tensor
|
Initial two-component mole-fraction vectors. |
required |
phase_kinds
|
tuple[PhaseKind, PhaseKind]
|
Root request for each coexisting phase. |
('stable', 'stable')
|
tolerance
|
float
|
Maximum absolute component log-fugacity residual. |
1e-08
|
max_iterations
|
int
|
Maximum substitution/Newton iterations. |
30
|
minimum_phase_separation
|
float
|
Minimum absolute mole-fraction separation needed to reject the homogeneous algebraic solution. |
1e-06
|
Returns:
| Type | Description |
|---|---|
BinaryPhaseEquilibriumPoint
|
Coexisting compositions, root requests, and convergence diagnostics. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If roots, shapes, or the separation threshold are invalid. |
Notes
("stable", "stable") is appropriate for mutual-solubility work where
the hydrocarbon-rich phase may switch between liquid and vapor with
conditions. Explicit roots support LLE ("liquid", "liquid") and VLE
("liquid", "vapor"). The algebraic equal-composition solution is
rejected because it is a homogeneous state, not phase coexistence.
Source code in src/torch_flash/envelope.py
2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 | |
fixed_vapor_ratio_vle_point
¶
fixed_vapor_ratio_vle_point(
model: StateModel,
temperature: Tensor,
pressure: Tensor,
dry_vapor_composition: Tensor,
variable_vapor_component: int,
*,
initial_liquid_composition: Tensor | None = None,
initial_variable_vapor_fraction: Tensor | None = None,
phase_kinds: tuple[PhaseKind, PhaseKind] = (
"liquid",
"vapor",
),
tolerance: float = 1e-08,
max_iterations: int = 40,
minimum_phase_separation: float = 1e-06,
) -> FixedVaporRatioVLEPoint
Solve VLE at fixed temperature, pressure, and dry-vapor composition.
The selected variable vapor component is excluded from
dry_vapor_composition. Its saturated vapor mole fraction and every
liquid-phase mole fraction are solved simultaneously from component
fugacity equality. For example, a water-saturated H2/N2 gas is represented
by dry_vapor_composition=[0.75, 0.25, 0] and
variable_vapor_component=2 in an (H2, N2, H2O) model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
StateModel
|
Homogeneous-state model providing liquid and vapor fugacity coefficients. |
required |
temperature
|
Tensor
|
Finite positive scalar temperature in K and pressure in Pa. |
required |
pressure
|
Tensor
|
Finite positive scalar temperature in K and pressure in Pa. |
required |
dry_vapor_composition
|
Tensor
|
One-dimensional nonnegative component ratio in model order. The variable component entry must be exactly zero; every other modeled component must be present with a positive ratio. The vector is normalized internally. |
required |
variable_vapor_component
|
int
|
Index of the vapor component whose saturated fraction is solved. |
required |
initial_liquid_composition
|
Tensor | None
|
Optional strictly positive liquid composition. The default is 0.1 mol % dissolved dry gas, distributed in the specified dry-gas ratio. |
None
|
initial_variable_vapor_fraction
|
Tensor | None
|
Optional strictly interior estimate for the variable component vapor fraction. A Wilson estimate is used when omitted. |
None
|
phase_kinds
|
tuple[PhaseKind, PhaseKind]
|
Homogeneous root requested for the liquid-rich and vapor-rich states. |
('liquid', 'vapor')
|
tolerance
|
float
|
Positive maximum absolute dimensionless log-fugacity residual. |
1e-08
|
max_iterations
|
int
|
Positive damped-Newton iteration limit. |
40
|
minimum_phase_separation
|
float
|
Nonnegative minimum of |
1e-06
|
Returns:
| Type | Description |
|---|---|
FixedVaporRatioVLEPoint
|
Coexisting compositions, solved component index, nonlinear diagnostics, and phase separation. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If scalar state inputs, component ratios, initial values, phase roots, or solver controls are invalid. |
Notes
The square nonlinear system enforces
ln(x_i phi_i^L) = ln(y_i phi_i^V) for every component. Independent
liquid log-ratios and one vapor logit keep both compositions strictly
inside their simplices. The vapor parametrization preserves all specified
non-variable component ratios exactly, avoiding an arbitrary overall-feed
assumption for experiments that report a saturated gas composition but
not the coexisting liquid composition.
Fugacity equality and fixed-composition phase-equilibrium context follow Michelsen and Mollerup, Thermodynamic Models: Fundamentals & Computational Aspects, 2nd ed. (2007), chapters 8 and 12, ISBN 978-87-989961-3-2. Newton Jacobians are assembled by PyTorch automatic differentiation; no equation-of-state-specific derivatives are embedded here.
Source code in src/torch_flash/envelope.py
2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 | |
binary_vle_point
¶
binary_vle_point(
model: StateModel,
temperature: Tensor,
pressure: Tensor,
initial_liquid_composition: Tensor,
initial_vapor_composition: Tensor,
*,
tolerance: float = 1e-08,
max_iterations: int = 30,
minimum_phase_separation: float = 1e-06,
) -> BinaryVLEPoint
Solve a binary liquid-vapor coexistence point at fixed T and P.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
StateModel
|
Homogeneous-state model used for liquid and vapor fugacity coefficients. |
required |
temperature
|
Tensor
|
Scalar temperature in K. |
required |
pressure
|
Tensor
|
Scalar pressure in Pa. |
required |
initial_liquid_composition
|
Tensor
|
Initial two-component mole-fraction vectors. |
required |
initial_vapor_composition
|
Tensor
|
Initial two-component mole-fraction vectors. |
required |
tolerance
|
float
|
Maximum absolute component log-fugacity residual. |
1e-08
|
max_iterations
|
int
|
Maximum substitution/Newton iterations. |
30
|
minimum_phase_separation
|
float
|
Minimum absolute mole-fraction difference required to reject the algebraic homogeneous solution. |
1e-06
|
Returns:
| Type | Description |
|---|---|
BinaryVLEPoint
|
Liquid and vapor compositions plus convergence diagnostics. |
Notes
A result is converged only when fugacity equality passes and the two
compositions remain separated by more than
minimum_phase_separation.
Source code in src/torch_flash/envelope.py
3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 | |
binary_helmholtz_vle_point
¶
binary_helmholtz_vle_point(
model: HelmholtzStateModel,
temperature: Tensor,
pressure: Tensor,
initial_point: BinaryBubblePointWithVolumes
| BinaryVLEPointWithVolumes,
*,
tolerance: float = 1e-08,
max_iterations: int = 30,
minimum_phase_separation: float = 1e-06,
) -> BinaryVLEPointWithVolumes
Solve binary fixed-pressure coexistence using explicit phase volumes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
HelmholtzStateModel
|
Two-component Helmholtz state model providing residual Helmholtz energy and pressure as functions of temperature, molar volume, and composition. |
required |
temperature
|
Tensor
|
One finite positive scalar temperature in K. |
required |
pressure
|
Tensor
|
One finite positive scalar coexistence pressure in Pa. |
required |
initial_point
|
BinaryBubblePointWithVolumes | BinaryVLEPointWithVolumes
|
Nearby coexistence point containing strictly positive liquid/vapor compositions and molar volumes. It can be a bubble point or another fixed-pressure point from the same branch. |
required |
tolerance
|
float
|
Positive maximum absolute dimensionless residual for both component chemical-potential equalities and the two pressure equations. |
1e-08
|
max_iterations
|
int
|
Positive maximum number of damped-Newton iterations. |
30
|
minimum_phase_separation
|
float
|
Nonnegative minimum |
1e-06
|
Returns:
| Type | Description |
|---|---|
BinaryVLEPointWithVolumes
|
Specified state, solved coexisting compositions and molar volumes, and explicit convergence diagnostics. Floating outputs preserve the initial-point dtype and device. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If |
ValueError
|
If the specified state, initial compositions or volumes, tolerance, iteration count, or separation threshold is invalid. |
Notes
The four Newton variables are the liquid and vapor composition logits and the logarithms of both molar densities. The residual contains equality of the two component chemical potentials and equality of each phase pressure to the specified pressure. This is the volume-based phase-equilibrium formulation described by Kunz, Klimeck, Wagner, and Jaeschke, The GERG-2004 Wide-Range Equation of State for Natural Gases and Other Mixtures, GERG Technical Monograph 15 (2007), Sec. 5.4.3, ISBN 978-3-18-355706-6. Retaining both volumes removes nested density-root inversions from continuation residual evaluations.
Before the coupled solve, each supplied phase volume is pressure-matched by a bounded one-dimensional Newton correction at its supplied composition. This retains the nearby density root while preventing modest continuation-predictor errors in both volumes from steering the coupled solve toward the homogeneous root.
The discrete physical-separation decision is non-differentiable. The returned tensors otherwise preserve their PyTorch graphs.
Source code in src/torch_flash/envelope.py
3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 | |
binary_bubble_point
¶
binary_bubble_point(
model: StateModel,
temperature: Tensor,
liquid_composition: Tensor,
*,
initial_pressure: Tensor | None = None,
initial_vapor_composition: Tensor | None = None,
minimum_pressure: Tensor | float | None = None,
maximum_pressure: Tensor | float | None = None,
tolerance: float = 1e-08,
max_iterations: int = 30,
) -> BinaryBubblePoint
Solve binary bubble pressure and vapor composition at fixed T, x.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
StateModel
|
Homogeneous-state fugacity model with critical constants for default initialization. |
required |
temperature
|
Tensor
|
Scalar temperature in K. |
required |
liquid_composition
|
Tensor
|
Strictly positive binary liquid mole fractions. |
required |
initial_pressure
|
Tensor | None
|
Optional positive pressure estimate in Pa. |
None
|
initial_vapor_composition
|
Tensor | None
|
Optional strictly positive binary vapor estimate. |
None
|
minimum_pressure
|
Tensor | float | None
|
Optional positive pressure bounds in Pa. |
None
|
maximum_pressure
|
Tensor | float | None
|
Optional positive pressure bounds in Pa. |
None
|
tolerance
|
float
|
Maximum absolute component log-fugacity residual. |
1e-08
|
max_iterations
|
int
|
Maximum damped-Newton iterations. |
30
|
Returns:
| Type | Description |
|---|---|
BinaryBubblePoint
|
Bubble pressure, liquid/vapor compositions, and convergence diagnostics. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If composition, initialization, or pressure bounds are invalid. |
Notes
The two unknowns are the log pressure and the logit of the first vapor
mole fraction. Unlike a fixed-T,P coexistence calculation, this
formulation remains well posed at a homogeneous azeotrope where
x == y. Optional pressure bounds can exclude disconnected,
physically irrelevant roots in highly non-ideal systems.
Source code in src/torch_flash/envelope.py
3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 | |
binary_bubble_temperature
¶
binary_bubble_temperature(
model: StateModel,
pressure: Tensor,
liquid_composition: Tensor,
*,
initial_temperature: Tensor | None = None,
initial_vapor_composition: Tensor | None = None,
minimum_temperature: Tensor | float | None = None,
maximum_temperature: Tensor | float | None = None,
tolerance: float = 1e-08,
max_iterations: int = 30,
minimum_phase_separation: float = 1e-06,
) -> BinaryBubbleTemperature
Solve binary bubble temperature and vapor composition at fixed P, x.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
StateModel
|
Homogeneous-state fugacity model with critical constants for default initialization. |
required |
pressure
|
Tensor
|
Specified finite positive scalar pressure in Pa. |
required |
liquid_composition
|
Tensor
|
Strictly positive binary liquid mole fractions. |
required |
initial_temperature
|
Tensor | None
|
Optional finite positive temperature estimate in K. The composition-weighted critical temperature is used when omitted. |
None
|
initial_vapor_composition
|
Tensor | None
|
Optional strictly positive binary vapor estimate. Wilson equilibrium ratios initialize the vapor when omitted. |
None
|
minimum_temperature
|
Tensor | float | None
|
Optional finite positive temperature bounds in K. |
None
|
maximum_temperature
|
Tensor | float | None
|
Optional finite positive temperature bounds in K. |
None
|
tolerance
|
float
|
Positive maximum absolute component log-fugacity residual. |
1e-08
|
max_iterations
|
int
|
Positive damped-Newton iteration limit. |
30
|
minimum_phase_separation
|
float
|
Nonnegative minimum of |
1e-06
|
Returns:
| Type | Description |
|---|---|
BinaryBubbleTemperature
|
Bubble temperature, specified pressure, coexisting compositions, and explicit convergence diagnostics. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the state, composition, bounds, or solver controls are invalid. |
Notes
The unknowns are the log temperature and the logit of the first vapor mole fraction. Fugacity equality is enforced with liquid and vapor roots, following Michelsen and Mollerup, Thermodynamic Models: Fundamentals & Computational Aspects, 2nd ed. (2007), chapter 12, ISBN 978-87-989961-3-2. The Jacobian is assembled by PyTorch automatic differentiation, so equation-of-state-specific temperature derivatives are not embedded in this solver.
A converged nonlinear residual is not sufficient near a critical endpoint:
the homogeneous x == y solution is rejected unless the requested
minimum_phase_separation is exceeded.
Source code in src/torch_flash/envelope.py
3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 3672 3673 3674 3675 3676 3677 3678 3679 3680 3681 3682 3683 3684 3685 3686 3687 3688 3689 3690 3691 3692 3693 3694 3695 3696 3697 3698 3699 3700 3701 3702 3703 3704 3705 3706 3707 3708 3709 3710 3711 3712 3713 3714 3715 3716 3717 3718 3719 3720 3721 3722 3723 3724 3725 3726 3727 3728 3729 3730 3731 3732 3733 3734 3735 3736 | |
trace_binary_pxy_isotherm
¶
trace_binary_pxy_isotherm(
model: StateModel,
temperature: Tensor,
liquid_first_fractions: Tensor,
*,
initial_pressure: Tensor | None = None,
initial_vapor_composition: Tensor | None = None,
minimum_pressure: Tensor | float | None = None,
maximum_pressure: Tensor | float | None = None,
tolerance: float = 1e-08,
max_iterations: int = 30,
minimum_phase_separation: float = 1e-06,
) -> BinaryPxyIsotherm
Trace a binary P-x-y isotherm with liquid-composition continuation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
StateModel
|
Homogeneous-state fugacity model. |
required |
temperature
|
Tensor
|
Specified finite positive scalar temperature in K. |
required |
liquid_first_fractions
|
Tensor
|
One-dimensional, strictly interior liquid mole fractions of the first component, in the requested continuation order. |
required |
initial_pressure
|
Tensor | None
|
Optional estimates for the first point. Every physically converged point initializes the next one. |
None
|
initial_vapor_composition
|
Tensor | None
|
Optional estimates for the first point. Every physically converged point initializes the next one. |
None
|
minimum_pressure
|
Tensor | float | None
|
Optional positive pressure bounds in Pa passed to every bubble solve. |
None
|
maximum_pressure
|
Tensor | float | None
|
Optional positive pressure bounds in Pa passed to every bubble solve. |
None
|
tolerance
|
float
|
Positive damped-Newton controls. |
1e-08
|
max_iterations
|
float
|
Positive damped-Newton controls. |
1e-08
|
minimum_phase_separation
|
float
|
Nonnegative minimum of |
1e-06
|
Returns:
| Type | Description |
|---|---|
BinaryPxyIsotherm
|
Attempted pressures, compositions, and pointwise convergence
diagnostics in the same order as |
Notes
This fugacity-based driver is valid for any :class:StateModel.
:func:trace_binary_helmholtz_pxy_isotherm is a distinct volume-based
continuation algorithm for :class:HelmholtzStateModel models and can
follow composition folds that are not single-valued in liquid
composition.
The phase-equilibrium formulation follows Michelsen and Mollerup, Thermodynamic Models: Fundamentals & Computational Aspects, 2nd ed. (2007), chapter 12, ISBN 978-87-989961-3-2.
Source code in src/torch_flash/envelope.py
3739 3740 3741 3742 3743 3744 3745 3746 3747 3748 3749 3750 3751 3752 3753 3754 3755 3756 3757 3758 3759 3760 3761 3762 3763 3764 3765 3766 3767 3768 3769 3770 3771 3772 3773 3774 3775 3776 3777 3778 3779 3780 3781 3782 3783 3784 3785 3786 3787 3788 3789 3790 3791 3792 3793 3794 3795 3796 3797 3798 3799 3800 3801 3802 3803 3804 3805 3806 3807 3808 3809 3810 3811 3812 3813 3814 3815 3816 3817 3818 3819 3820 3821 3822 3823 3824 3825 3826 3827 3828 3829 3830 3831 3832 3833 3834 3835 3836 3837 3838 3839 3840 3841 3842 3843 3844 3845 3846 3847 3848 3849 3850 3851 3852 3853 3854 3855 | |
trace_binary_txy_isobar
¶
trace_binary_txy_isobar(
model: StateModel,
pressure: Tensor,
liquid_first_fractions: Tensor,
*,
initial_temperature: Tensor | None = None,
initial_vapor_composition: Tensor | None = None,
minimum_temperature: Tensor | float | None = None,
maximum_temperature: Tensor | float | None = None,
tolerance: float = 1e-08,
max_iterations: int = 30,
minimum_phase_separation: float = 1e-06,
) -> BinaryTxyIsobar
Trace a binary T-x-y isobar with liquid-composition continuation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
StateModel
|
Homogeneous-state fugacity model. |
required |
pressure
|
Tensor
|
Specified finite positive scalar pressure in Pa. |
required |
liquid_first_fractions
|
Tensor
|
One-dimensional, strictly interior liquid mole fractions of the first component, in the requested continuation order. |
required |
initial_temperature
|
Tensor | None
|
Optional estimates for the first point. Every physically converged point initializes the next one. |
None
|
initial_vapor_composition
|
Tensor | None
|
Optional estimates for the first point. Every physically converged point initializes the next one. |
None
|
minimum_temperature
|
Tensor | float | None
|
Optional positive temperature bounds in K passed to every bubble solve. |
None
|
maximum_temperature
|
Tensor | float | None
|
Optional positive temperature bounds in K passed to every bubble solve. |
None
|
tolerance
|
float
|
Positive damped-Newton controls. |
1e-08
|
max_iterations
|
float
|
Positive damped-Newton controls. |
1e-08
|
minimum_phase_separation
|
float
|
Nonnegative minimum of |
1e-06
|
Returns:
| Type | Description |
|---|---|
BinaryTxyIsobar
|
Attempted temperatures, compositions, and pointwise convergence
diagnostics in the same order as |
Notes
Every point is solved by :func:binary_bubble_temperature; both liquid
and vapor branches therefore come from one fugacity-equality calculation.
The continuation order is scientifically significant near critical
endpoints and should be selected to begin on a well-separated branch.
The phase-equilibrium formulation follows Michelsen and Mollerup, Thermodynamic Models: Fundamentals & Computational Aspects, 2nd ed. (2007), chapter 12, ISBN 978-87-989961-3-2.
Source code in src/torch_flash/envelope.py
3858 3859 3860 3861 3862 3863 3864 3865 3866 3867 3868 3869 3870 3871 3872 3873 3874 3875 3876 3877 3878 3879 3880 3881 3882 3883 3884 3885 3886 3887 3888 3889 3890 3891 3892 3893 3894 3895 3896 3897 3898 3899 3900 3901 3902 3903 3904 3905 3906 3907 3908 3909 3910 3911 3912 3913 3914 3915 3916 3917 3918 3919 3920 3921 3922 3923 3924 3925 3926 3927 3928 3929 3930 3931 3932 3933 3934 3935 3936 3937 3938 3939 3940 3941 3942 3943 3944 3945 3946 3947 3948 3949 3950 3951 3952 3953 3954 3955 3956 3957 3958 3959 3960 3961 3962 3963 3964 3965 3966 3967 3968 3969 3970 3971 3972 3973 | |
binary_helmholtz_bubble_point
¶
binary_helmholtz_bubble_point(
model: HelmholtzStateModel,
temperature: Tensor,
liquid_composition: Tensor,
*,
initial_point: BinaryBubblePointWithVolumes
| None = None,
initial_pressure: Tensor | None = None,
initial_vapor_composition: Tensor | None = None,
minimum_pressure: Tensor | float | None = None,
maximum_pressure: Tensor | float | None = None,
tolerance: float = 1e-08,
max_iterations: int = 30,
) -> BinaryBubblePointWithVolumes
Solve a binary bubble point using phase volumes as Newton variables.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
HelmholtzStateModel
|
Helmholtz state model providing residual Helmholtz energy, pressure, molar-volume roots, and critical constants. |
required |
temperature
|
Tensor
|
Scalar temperature in K. |
required |
liquid_composition
|
Tensor
|
Strictly positive binary liquid mole fractions. |
required |
initial_point
|
BinaryBubblePointWithVolumes | None
|
Previously converged volume-formulation point used as the continuation estimate. When omitted, the pressure formulation initializes the first point. |
None
|
initial_pressure
|
Tensor | None
|
Optional positive pressure estimate in Pa for first-point initialization. |
None
|
initial_vapor_composition
|
Tensor | None
|
Optional strictly positive vapor estimate for first-point initialization. |
None
|
minimum_pressure
|
Tensor | float | None
|
Optional positive pressure bounds in Pa. |
None
|
maximum_pressure
|
Tensor | float | None
|
Optional positive pressure bounds in Pa. |
None
|
tolerance
|
float
|
Maximum absolute dimensionless equilibrium residual. |
1e-08
|
max_iterations
|
int
|
Maximum damped-Newton iterations. |
30
|
Returns:
| Type | Description |
|---|---|
BinaryBubblePointWithVolumes
|
Bubble pressure, both phase compositions and volumes, and explicit nonlinear convergence diagnostics. |
Notes
With no initial_point, the pressure formulation supplies a robust
first point and its two density roots. Continuation then solves directly
for vapor composition, liquid density, and vapor density from equality of
both component fugacities and pressure. This is the volume-based GERG
phase-equilibrium formulation described by Kunz, Klimeck, Wagner, and
Jaeschke, The GERG-2004 Wide-Range Equation of State for Natural Gases
and Other Mixtures, GERG Technical Monograph 15 (2007), Sec. 5.4.3,
ISBN 978-3-18-355706-6. It eliminates density inversion from every outer
residual evaluation.
A failed direct solve remains explicitly non-converged. Callers tracing a
difficult branch can retry without initial_point to invoke the robust
pressure initializer.
Source code in src/torch_flash/envelope.py
3976 3977 3978 3979 3980 3981 3982 3983 3984 3985 3986 3987 3988 3989 3990 3991 3992 3993 3994 3995 3996 3997 3998 3999 4000 4001 4002 4003 4004 4005 4006 4007 4008 4009 4010 4011 4012 4013 4014 4015 4016 4017 4018 4019 4020 4021 4022 4023 4024 4025 4026 4027 4028 4029 4030 4031 4032 4033 4034 4035 4036 4037 4038 4039 4040 4041 4042 4043 4044 4045 4046 4047 4048 4049 4050 4051 4052 4053 4054 4055 4056 4057 4058 4059 4060 4061 4062 4063 4064 4065 4066 4067 4068 4069 4070 4071 4072 4073 4074 4075 4076 4077 4078 4079 4080 4081 4082 4083 4084 4085 4086 4087 4088 4089 4090 4091 4092 4093 4094 4095 4096 4097 4098 4099 4100 4101 4102 4103 4104 4105 4106 4107 4108 4109 4110 4111 4112 4113 4114 4115 4116 4117 4118 4119 4120 4121 4122 4123 4124 4125 4126 4127 4128 4129 4130 4131 4132 4133 4134 4135 4136 4137 4138 4139 4140 4141 4142 4143 4144 4145 4146 4147 4148 4149 4150 4151 4152 4153 4154 4155 4156 4157 4158 4159 4160 4161 4162 4163 4164 4165 4166 4167 4168 4169 4170 4171 4172 4173 4174 4175 4176 4177 4178 4179 4180 4181 4182 4183 4184 4185 4186 4187 4188 4189 4190 4191 4192 4193 4194 4195 4196 4197 4198 4199 4200 4201 4202 4203 4204 4205 4206 4207 4208 4209 4210 4211 4212 4213 4214 | |
trace_binary_helmholtz_pxy_isotherm
¶
trace_binary_helmholtz_pxy_isotherm(
model: HelmholtzStateModel,
temperature: Tensor,
liquid_compositions: Tensor,
*,
minimum_pressure: Tensor | float | None = None,
maximum_pressure: Tensor | float | None = None,
tolerance: float = 1e-08,
max_iterations: int = 30,
minimum_phase_separation: float = 1e-05,
minimum_pressure_step_separation_ratio: float = 0.1,
stop_on_failure: bool = True,
composition_failure_refinement_steps: int = 0,
continue_in_pressure_on_failure: bool = False,
pressure_continuation_points: int = 25,
pressure_failure_refinement_steps: int = 0,
) -> BinaryPxyIsotherm
Trace a binary pressure-composition isotherm by bubble continuation.
Each row of liquid_compositions specifies a successive liquid point.
The first state uses the pressure-formulation initializer; later states
reuse both coexisting phase volumes in
:func:binary_helmholtz_bubble_point. This exposes a high-level p-x-y
workflow without embedding continuation logic in an application study.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
HelmholtzStateModel
|
Two-component Helmholtz state model with pressure, molar-volume, and residual-Helmholtz methods. |
required |
temperature
|
Tensor
|
One finite positive scalar temperature in K. |
required |
liquid_compositions
|
Tensor
|
Ordered, strictly positive liquid mole fractions with shape
|
required |
minimum_pressure
|
Tensor | float | None
|
Optional finite positive pressure bounds in Pa. When a converged point
reaches 99.5% of |
None
|
maximum_pressure
|
Tensor | float | None
|
Optional finite positive pressure bounds in Pa. When a converged point
reaches 99.5% of |
None
|
tolerance
|
float
|
Positive maximum absolute dimensionless equilibrium residual. |
1e-08
|
max_iterations
|
int
|
Positive maximum damped-Newton iteration count per point. |
30
|
minimum_phase_separation
|
float
|
Nonnegative minimum of |
1e-05
|
minimum_pressure_step_separation_ratio
|
float
|
Positive ratio, no greater than one, between a candidate phase separation and the preceding accepted separation during fixed-pressure continuation. A larger contraction is treated as a branch jump and triggers pressure refinement instead of accepting a nearly homogeneous algebraic root. |
0.1
|
stop_on_failure
|
bool
|
Stop after the first rejected point once a physical branch has begun. |
True
|
composition_failure_refinement_steps
|
int
|
Number of bisection refinements between the last accepted liquid composition and the first rejected one. Refinement approaches a critical endpoint or a turning point in the liquid-composition parametrization without requiring a uniformly fine input grid. |
0
|
continue_in_pressure_on_failure
|
bool
|
After refinement, continue at increasing fixed pressures from the last
accepted coexistence state to |
False
|
pressure_continuation_points
|
int
|
Number of logarithmically spaced fixed-pressure solves used by the pressure continuation, including its final pressure. |
25
|
pressure_failure_refinement_steps
|
int
|
Number of logarithmic bisection refinements between the last accepted and first rejected fixed-pressure states. This approaches the critical endpoint of a closed curve without uniformly refining the entire pressure path. |
0
|
Returns:
| Type | Description |
|---|---|
BinaryPxyIsotherm
|
Attempted pressures, both phase compositions, iterations, residuals, separation, and a physical-convergence mask. All floating tensors retain the input composition dtype and device. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If temperature, compositions, tolerances, or iteration settings are invalid, or if pressure continuation is requested without compatible stopping and pressure-bound settings. Pressure-bound validation is otherwise delegated to the point solver. |
Notes
The equilibrium equations and reuse of prior solutions as initial estimates follow Kunz, Klimeck, Wagner, and Jaeschke, The GERG-2004 Wide-Range Equation of State for Natural Gases and Other Mixtures, GERG Technical Monograph 15 (2007), Sec. 5.4.3, ISBN 978-3-18-355706-6, and Michelsen and Mollerup, Thermodynamic Models, 2nd ed. (2007), chapter 12, ISBN 978-87-989961-3-2.
Liquid-composition continuation becomes singular at a fold of an open or
closed phase boundary. The optional fallback changes the continuation
coordinate to pressure and solves coexistence with
:func:binary_helmholtz_vle_point. An open branch continues to the
requested pressure bound; a closed branch is refined toward its critical
endpoint after the first rejected pressure. Fixed-pressure initial states
use a bounded secant extrapolation of both composition logits and both
logarithmic phase volumes. A candidate whose phase split contracts by more
than minimum_pressure_step_separation_ratio is rejected as a possible
jump to the algebraic homogeneous root and causes pressure refinement. The
routine never forces a physically open branch to close. Bisection and the
discrete accept/stop/coordinate-switch decisions are not differentiable,
but accepted equilibrium tensors preserve their PyTorch graphs.
Source code in src/torch_flash/envelope.py
4217 4218 4219 4220 4221 4222 4223 4224 4225 4226 4227 4228 4229 4230 4231 4232 4233 4234 4235 4236 4237 4238 4239 4240 4241 4242 4243 4244 4245 4246 4247 4248 4249 4250 4251 4252 4253 4254 4255 4256 4257 4258 4259 4260 4261 4262 4263 4264 4265 4266 4267 4268 4269 4270 4271 4272 4273 4274 4275 4276 4277 4278 4279 4280 4281 4282 4283 4284 4285 4286 4287 4288 4289 4290 4291 4292 4293 4294 4295 4296 4297 4298 4299 4300 4301 4302 4303 4304 4305 4306 4307 4308 4309 4310 4311 4312 4313 4314 4315 4316 4317 4318 4319 4320 4321 4322 4323 4324 4325 4326 4327 4328 4329 4330 4331 4332 4333 4334 4335 4336 4337 4338 4339 4340 4341 4342 4343 4344 4345 4346 4347 4348 4349 4350 4351 4352 4353 4354 4355 4356 4357 4358 4359 4360 4361 4362 4363 4364 4365 4366 4367 4368 4369 4370 4371 4372 4373 4374 4375 4376 4377 4378 4379 4380 4381 4382 4383 4384 4385 4386 4387 4388 4389 4390 4391 4392 4393 4394 4395 4396 4397 4398 4399 4400 4401 4402 4403 4404 4405 4406 4407 4408 4409 4410 4411 4412 4413 4414 4415 4416 4417 4418 4419 4420 4421 4422 4423 4424 4425 4426 4427 4428 4429 4430 4431 4432 4433 4434 4435 4436 4437 4438 4439 4440 4441 4442 4443 4444 4445 4446 4447 4448 4449 4450 4451 4452 4453 4454 4455 4456 4457 4458 4459 4460 4461 4462 4463 4464 4465 4466 4467 4468 4469 4470 4471 4472 4473 4474 4475 4476 4477 4478 4479 4480 4481 4482 4483 4484 4485 4486 4487 4488 4489 4490 4491 4492 4493 4494 4495 4496 4497 4498 4499 4500 4501 4502 4503 4504 4505 4506 4507 4508 4509 4510 4511 4512 4513 4514 4515 4516 4517 4518 4519 4520 4521 4522 4523 4524 4525 4526 4527 4528 4529 4530 4531 4532 4533 4534 4535 4536 4537 4538 4539 4540 4541 4542 4543 4544 4545 4546 4547 4548 4549 4550 4551 4552 4553 4554 4555 4556 4557 4558 4559 4560 4561 4562 4563 4564 4565 4566 4567 4568 4569 4570 4571 4572 4573 4574 4575 4576 4577 4578 4579 4580 4581 4582 4583 4584 4585 4586 4587 4588 4589 4590 4591 4592 4593 4594 4595 4596 4597 4598 4599 4600 4601 4602 4603 4604 4605 4606 4607 4608 4609 4610 4611 4612 4613 4614 4615 4616 4617 | |
trace_binary_helmholtz_fixed_composition_boundary
¶
trace_binary_helmholtz_fixed_composition_boundary(
model: HelmholtzStateModel,
temperatures: Tensor,
overall_composition: Tensor,
*,
volatile_component_index: int = 1,
reporting_pressure_limit: Tensor | float,
maximum_pressure: Tensor | float,
minimum_pressure: Tensor | float = 1000.0,
minimum_volatile_liquid_fraction: float = 1e-05,
transition_volatile_liquid_fraction: float = 0.05,
lean_scan_points: int = 12,
rich_scan_points: int = 15,
tolerance: float = 1e-08,
max_iterations: int = 25,
minimum_phase_separation: float = 1e-05,
) -> BinaryFixedCompositionBoundary
Trace a binary two-phase pressure band at fixed overall composition.
At each temperature, this routine continues the bubble locus from a
volatile-component-lean liquid toward the specified overall composition.
The first crossing of y[volatile_component_index] through the overall
fraction gives the lower (dew) boundary. The upper boundary is the bubble
state at x == z or, beyond a critical composition, the return crossing
of the vapor branch. Previous-temperature solutions initialize matching
liquid-composition points.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
HelmholtzStateModel
|
Two-component Helmholtz state model. |
required |
temperatures
|
Tensor
|
Nonempty one-dimensional ordered temperature grid in K. Either increasing or decreasing order is accepted. |
required |
overall_composition
|
Tensor
|
Strictly positive binary overall mole fractions. |
required |
volatile_component_index
|
int
|
Component coordinate expected to be enriched in the vapor phase,
either |
1
|
reporting_pressure_limit
|
Tensor | float
|
Positive reporting limit in Pa. Upper boundaries beyond it are clipped
and identified by |
required |
maximum_pressure
|
Tensor | float
|
Positive numerical bubble-solver ceiling in Pa, strictly greater than
or equal to |
required |
minimum_pressure
|
Tensor | float
|
Positive numerical bubble-solver floor in Pa. |
1000.0
|
minimum_volatile_liquid_fraction
|
float
|
Positive starting mole fraction for the volatile-component scan. |
1e-05
|
transition_volatile_liquid_fraction
|
float
|
Positive fraction separating geometric lean-side spacing from linear spacing toward the overall composition. |
0.05
|
lean_scan_points
|
int
|
Number of geometric and linear scan points. Each must be at least two. |
12
|
rich_scan_points
|
int
|
Number of geometric and linear scan points. Each must be at least two. |
12
|
tolerance
|
float
|
Positive maximum absolute dimensionless equilibrium residual. |
1e-08
|
max_iterations
|
int
|
Positive maximum damped-Newton iterations per bubble point. |
25
|
minimum_phase_separation
|
float
|
Positive minimum |
1e-05
|
Returns:
| Type | Description |
|---|---|
BinaryFixedCompositionBoundary
|
Boundary pressures in Pa plus convergence, out-of-range, separation, and residual diagnostics on the requested temperature grid. Floating outputs preserve the input dtype and device. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If state grids, compositions, pressure limits, scan settings, or nonlinear tolerances are invalid. |
Notes
This is a fixed-composition specialization of bubble-locus continuation
and crossing interpolation. The phase-equilibrium equations,
Newton-Raphson solution, and continuation initial estimates follow Kunz,
Klimeck, Wagner, and Jaeschke, The GERG-2004 Wide-Range Equation of State
for Natural Gases and Other Mixtures, GERG Technical Monograph 15 (2007),
Sec. 5.4.3 and Table 5.3, ISBN 978-3-18-355706-6. Log-pressure
interpolation and pressure-limit clipping are numerical continuation
choices made explicitly by torch-flash, not additional equilibrium
equations. Discrete branch and clipping decisions are non-differentiable.
Source code in src/torch_flash/envelope.py
4628 4629 4630 4631 4632 4633 4634 4635 4636 4637 4638 4639 4640 4641 4642 4643 4644 4645 4646 4647 4648 4649 4650 4651 4652 4653 4654 4655 4656 4657 4658 4659 4660 4661 4662 4663 4664 4665 4666 4667 4668 4669 4670 4671 4672 4673 4674 4675 4676 4677 4678 4679 4680 4681 4682 4683 4684 4685 4686 4687 4688 4689 4690 4691 4692 4693 4694 4695 4696 4697 4698 4699 4700 4701 4702 4703 4704 4705 4706 4707 4708 4709 4710 4711 4712 4713 4714 4715 4716 4717 4718 4719 4720 4721 4722 4723 4724 4725 4726 4727 4728 4729 4730 4731 4732 4733 4734 4735 4736 4737 4738 4739 4740 4741 4742 4743 4744 4745 4746 4747 4748 4749 4750 4751 4752 4753 4754 4755 4756 4757 4758 4759 4760 4761 4762 4763 4764 4765 4766 4767 4768 4769 4770 4771 4772 4773 4774 4775 4776 4777 4778 4779 4780 4781 4782 4783 4784 4785 4786 4787 4788 4789 4790 4791 4792 4793 4794 4795 4796 4797 4798 4799 4800 4801 4802 4803 4804 4805 4806 4807 4808 4809 4810 4811 4812 4813 4814 4815 4816 4817 4818 4819 4820 4821 4822 4823 4824 4825 4826 4827 4828 4829 4830 4831 4832 4833 4834 4835 4836 4837 4838 4839 4840 4841 4842 4843 4844 4845 4846 4847 4848 4849 4850 4851 4852 4853 4854 4855 4856 4857 4858 4859 4860 4861 4862 4863 4864 4865 4866 4867 4868 4869 4870 4871 4872 4873 4874 4875 4876 4877 4878 4879 4880 4881 4882 4883 4884 4885 4886 4887 4888 4889 4890 4891 4892 4893 4894 4895 4896 4897 4898 4899 4900 4901 4902 4903 4904 4905 4906 4907 4908 4909 4910 4911 4912 4913 4914 4915 4916 4917 4918 4919 4920 4921 4922 4923 4924 4925 4926 4927 4928 4929 4930 4931 4932 4933 4934 4935 4936 4937 4938 4939 4940 4941 4942 4943 4944 4945 4946 4947 4948 4949 4950 4951 4952 4953 4954 4955 4956 4957 4958 4959 4960 4961 4962 4963 4964 4965 4966 4967 4968 4969 4970 4971 4972 4973 4974 4975 4976 4977 4978 4979 4980 4981 4982 4983 4984 4985 4986 4987 4988 4989 4990 4991 4992 4993 4994 4995 4996 4997 4998 4999 5000 5001 5002 5003 5004 5005 5006 5007 5008 5009 5010 5011 5012 5013 5014 5015 5016 5017 5018 5019 5020 5021 5022 5023 5024 5025 5026 5027 5028 5029 5030 5031 5032 5033 5034 5035 5036 5037 5038 5039 5040 5041 5042 5043 5044 5045 5046 5047 5048 5049 5050 5051 5052 5053 5054 5055 5056 5057 5058 5059 5060 5061 | |