API¶
torch_flash
¶
Differentiable phase-equilibrium calculations built on PyTorch.
CubicFractionProperties
dataclass
¶
Critical properties and acentric factors for cubic EoS adapters.
Source code in src/torch_flash/characterization/cubic.py
LumpedDistribution
dataclass
¶
Contiguous pseudo-components produced by a lumping rule.
Source code in src/torch_flash/characterization/types.py
PseudoComponentCut
dataclass
¶
One measured or estimated heavy-end cut, using SI units.
Source code in src/torch_flash/characterization/types.py
SCNDistribution
dataclass
¶
Discrete single-carbon-number representation of a plus fraction.
Source code in src/torch_flash/characterization/types.py
total_mole_fraction
property
¶
Return the total mole fraction represented by the distribution.
bulk_density
property
¶
Return ideal-volume-mixed bulk density in kg/m3, when available.
to
¶
Move continuous values to a common dtype/device.
Source code in src/torch_flash/characterization/types.py
Component
dataclass
¶
Shared pure-component properties in SI units.
acentric_factor may be unavailable for components whose bundled use is
restricted to a model-specific multifluid equation. Such a record can be
resolved by name but cannot be used to construct a cubic EoS until the user
supplies a complete custom component database or :class:ComponentSet.
Source code in src/torch_flash/components.py
ComponentDatabase
dataclass
¶
Validated canonical component database loaded from YAML.
Source code in src/torch_flash/components.py
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 | |
lookup
¶
Resolve a canonical name or alias.
Source code in src/torch_flash/components.py
ComponentSet
dataclass
¶
Vectorized component constants for use by PyTorch models.
Source code in src/torch_flash/components.py
to
¶
Move all tensors to a common dtype and device.
Source code in src/torch_flash/components.py
RuntimeConfig
dataclass
¶
Immutable snapshot of torch-flash's tensor and execution policy.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
device
|
device
|
Device used by named model, component, standard-state, and characterization factories when no explicit device is supplied. |
required |
dtype
|
dtype
|
Floating-point dtype used by those factories. Float64 is the scientific default; float32 is available for explicit lower-precision studies. |
required |
num_threads
|
int
|
Current PyTorch CPU intra-operation thread count. |
required |
num_interop_threads
|
int
|
Current PyTorch CPU inter-operation thread count. |
required |
deterministic
|
bool
|
Whether PyTorch deterministic algorithms are enabled. |
required |
deterministic_warn_only
|
bool
|
Whether unavailable deterministic algorithms warn instead of raising. |
required |
Source code in src/torch_flash/config.py
tensor_options
property
¶
Return keyword arguments for PyTorch tensor factory functions.
tensor
¶
Construct a copied tensor using this runtime policy by default.
Source code in src/torch_flash/config.py
as_tensor
¶
Convert data using this runtime policy without unnecessary copies.
Source code in src/torch_flash/config.py
ModelParameterSet
dataclass
¶
Validated model parameter set independent of tensor dtype and device.
Parameters can be supplied directly through this dataclass, read from a
custom YAML path, or selected from the bundled database by identifier.
The stored mappings are recursively read-only. Use :meth:as_dict when a
mutable deep copy is needed.
Source code in src/torch_flash/database.py
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 | |
from_document
classmethod
¶
Validate a model-parameter YAML document represented as a mapping.
Source code in src/torch_flash/database.py
BinaryBubblePoint
dataclass
¶
Binary bubble pressure and incipient-vapor composition at specified T, x.
Source code in src/torch_flash/envelope.py
BinaryCriticalPoint
dataclass
¶
Binary mixture critical point at a specified overall composition.
Source code in src/torch_flash/envelope.py
BinaryPhaseEquilibriumPoint
dataclass
¶
Coexisting binary compositions for any requested pair of phase roots.
Source code in src/torch_flash/envelope.py
BinaryVLEPoint
dataclass
¶
Coexisting binary phase compositions at specified temperature and pressure.
Source code in src/torch_flash/envelope.py
SaturationPoint
dataclass
¶
One bubble- or dew-point solution.
Source code in src/torch_flash/envelope.py
CPAEOS
¶
Bases: Module
SRK cubic-plus-association mixture model.
Source code in src/torch_flash/eos/cpa.py
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 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 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 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 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 | |
pure_parameters
¶
Return CPA's fitted SRK energy and covolume parameters.
Source code in src/torch_flash/eos/cpa.py
mixture_parameters
¶
Return conventionally mixed physical-term parameters.
Source code in src/torch_flash/eos/cpa.py
binary_interaction
¶
Return the symmetric physical-term kij matrix at temperature.
Source code in src/torch_flash/eos/cpa.py
association_strength
¶
Return Delta[i, A, j, B] association strengths in m3/mol.
Source code in src/torch_flash/eos/cpa.py
site_fractions
¶
Solve the CPA mass-action equations for unbonded site fractions.
Leading dimensions are broadcast as independent homogeneous states. The component axis is the final composition dimension.
Source code in src/torch_flash/eos/cpa.py
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 | |
residual_helmholtz_rt
¶
Return extensive Ares/(RT) for the combined CPA model.
Source code in src/torch_flash/eos/cpa.py
pressure
¶
Evaluate the published CPA pressure equation.
Source code in src/torch_flash/eos/cpa.py
molar_volume
¶
Solve the CPA volume root for a specified phase.
Source code in src/torch_flash/eos/cpa.py
select_z
¶
Return the CPA compressibility factor.
Source code in src/torch_flash/eos/cpa.py
log_fugacity_coefficients
¶
Return CPA log fugacity coefficients from Helmholtz derivatives.
Source code in src/torch_flash/eos/cpa.py
CPACharacterizedComponents
dataclass
¶
Characterized pseudo-components and their normalized cut fractions.
Source code in src/torch_flash/eos/cpa_heavy_end.py
CPAHeavyEndCorrelations
dataclass
¶
Published coefficients used by the CPA C7+ monomer correlations.
Source code in src/torch_flash/eos/cpa_heavy_end.py
CPAMonomerProperties
dataclass
¶
Intermediate and final CPA monomer characterization results.
Source code in src/torch_flash/eos/cpa_heavy_end.py
CubicEOS
¶
Bases: Module
Generalized cubic equation of state with differentiable parameters.
Source code in src/torch_flash/eos/cubic.py
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 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 | |
component_volume_translation
¶
Return additive component volume shifts at temperature.
Source code in src/torch_flash/eos/cubic.py
pure_parameters
¶
Return temperature-dependent pure a_i and constant b_i.
Source code in src/torch_flash/eos/cubic.py
mixture_parameters
¶
Return mixed attraction and covolume parameters.
Source code in src/torch_flash/eos/cubic.py
dimensionless_parameters
¶
Return conventional cubic parameters A and B.
Source code in src/torch_flash/eos/cubic.py
z_factors
¶
Return sorted real compressibility-factor roots.
Source code in src/torch_flash/eos/cubic.py
select_z
¶
Select a physical liquid, vapor, or minimum-Gibbs root.
Source code in src/torch_flash/eos/cubic.py
molar_volume
¶
Return translated molar volume in m3/mol.
Source code in src/torch_flash/eos/cubic.py
pressure
¶
Evaluate pressure at a homogeneous T, v, x state.
Source code in src/torch_flash/eos/cubic.py
residual_helmholtz_rt
¶
Return extensive residual Helmholtz energy divided by RT.
Source code in src/torch_flash/eos/cubic.py
log_fugacity_coefficients
¶
Return component log fugacity coefficients.
The quadratic rule uses the standard closed form. Non-quadratic mixing rules use an autodifferentiated residual Helmholtz energy, preserving the exact composition dependence of the selected rule.
Source code in src/torch_flash/eos/cubic.py
GaoBTerms
dataclass
¶
Gao-B critical-region residual Helmholtz terms.
Source code in src/torch_flash/eos/multifluid.py
HelmholtzTerms
dataclass
¶
Power, exponential, Gaussian, and GERG-special terms.
The full form is n*delta^d*tau^t*exp(-delta^l
-eta*(delta-epsilon)^2-beta*(tau-gamma)^2
-linear_density*(delta-linear_shift)). Setting the optional arrays to
zero recovers the power-exponential subset. The final linear-density
factor is the binary departure form used by GERG-2008.
Source code in src/torch_flash/eos/multifluid.py
IdealHelmholtzTerms
dataclass
¶
Canonical pure-fluid ideal Helmholtz term tables.
Every component has lead, logarithmic, power, Planck--Einstein, and
optional GERG sinh/cosh terms. gas_scale is the ratio between the gas
constant of the original pure-fluid equation and the common mixture gas
constant. It multiplies the density-independent part only, preserving the
exact ideal-gas pressure limit.
Source code in src/torch_flash/eos/multifluid.py
MultiFluidEOS
¶
Bases: Module
Autodifferentiable multifluid Helmholtz model.
Source code in src/torch_flash/eos/multifluid.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 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 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 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 987 988 989 990 991 992 993 994 995 996 997 998 999 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 | |
reducing_functions
¶
Return mixture reducing temperature and molar density.
Source code in src/torch_flash/eos/multifluid.py
alpha_residual
¶
Return dimensionless molar residual Helmholtz energy.
Source code in src/torch_flash/eos/multifluid.py
alpha_ideal
¶
Return dimensionless molar ideal-gas Helmholtz energy.
Source code in src/torch_flash/eos/multifluid.py
alpha_total
¶
Return dimensionless total molar Helmholtz energy.
Source code in src/torch_flash/eos/multifluid.py
residual_helmholtz_rt
¶
Return extensive residual Helmholtz energy divided by RT.
Source code in src/torch_flash/eos/multifluid.py
helmholtz_rt
¶
Return extensive total Helmholtz energy divided by RT.
Source code in src/torch_flash/eos/multifluid.py
molar_helmholtz_energy
¶
Return total molar Helmholtz energy in J/mol.
Source code in src/torch_flash/eos/multifluid.py
molar_entropy
¶
Return total molar entropy in J/(mol K).
Source code in src/torch_flash/eos/multifluid.py
molar_internal_energy
¶
Return total molar internal energy in J/mol.
Source code in src/torch_flash/eos/multifluid.py
molar_heat_capacity_cv
¶
Return isochoric molar heat capacity in J/(mol K).
Source code in src/torch_flash/eos/multifluid.py
molar_heat_capacity_cp
¶
Return isobaric molar heat capacity in J/(mol K).
Source code in src/torch_flash/eos/multifluid.py
molar_enthalpy
¶
Return total molar enthalpy in J/mol.
Source code in src/torch_flash/eos/multifluid.py
molar_gibbs_energy
¶
Return total molar Gibbs energy in J/mol.
Source code in src/torch_flash/eos/multifluid.py
chemical_potentials
¶
Return total component chemical potentials in J/mol.
Source code in src/torch_flash/eos/multifluid.py
speed_of_sound
¶
Return homogeneous-phase speed of sound in m/s.
Source code in src/torch_flash/eos/multifluid.py
pressure
¶
Return pressure from a residual-Helmholtz density derivative.
Leading state dimensions are broadcast. The summed scalar objective
used by torch.func.grad differentiates independent batch entries
elementwise because the Helmholtz kernel contains no cross-state terms.
Source code in src/torch_flash/eos/multifluid.py
molar_volume
¶
Solve and select a homogeneous density root.
Phase-specific states first use a differentiable logarithmic-density Newton solve. If it fails, a logarithmic scan brackets every mechanically admissible positive root before bisection and Newton polishing. This conservative fallback matters because Helmholtz mixture models can have three density roots below the mixture critical locus, and an initial guess can cross a spinodal during phase-envelope calculations.
Source code in src/torch_flash/eos/multifluid.py
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 | |
select_z
¶
Return compressibility factor.
Source code in src/torch_flash/eos/multifluid.py
log_fugacity_coefficients
¶
Return log fugacity coefficients from composition derivatives.
Source code in src/torch_flash/eos/multifluid.py
MultifluidMetadata
dataclass
¶
Identity and validation scope of one coefficient set.
Source code in src/torch_flash/eos/multifluid.py
NonAnalyticTerms
dataclass
¶
Span-Wagner non-analytic critical-region residual terms.
Source code in src/torch_flash/eos/multifluid.py
VolumeTranslation
dataclass
¶
Component translations in the additive torch-flash convention.
reference_shift is in m3/mol, temperature_slope in
m3/(mol K), and reference_temperature in K. A published positive
Péneloux c therefore appears as a negative reference_shift.
Source code in src/torch_flash/eos/volume_translation.py
constant
classmethod
¶
Construct a temperature-independent additive translation.
at_temperature
¶
Return each component's additive shift at temperature.
Source code in src/torch_flash/eos/volume_translation.py
to
¶
Move translation coefficients to a common dtype and device.
Source code in src/torch_flash/eos/volume_translation.py
CubicInteractionParameters
dataclass
¶
Symmetric dimensionless kij and lij matrices.
Source code in src/torch_flash/parameters/cubic_interactions.py
PPR78GroupContributionParameters
dataclass
¶
Selected PPR78 group fractions and universal interaction tensors.
Source code in src/torch_flash/parameters/group_contribution.py
ThermalProperties
dataclass
¶
Caloric and response properties of one homogeneous phase.
All quantities are molar SI except the Joule-Thomson coefficient (K/Pa)
and speed of sound (m/s). reduced_* free energies are dimensionless
molar quantities divided by R*T.
Source code in src/torch_flash/properties/thermal.py
ThermodynamicDerivatives
dataclass
¶
First homogeneous-state derivatives.
Component derivatives are provided in both unconstrained softmax-logit
coordinates and n-1 independent mole fractions, where the last mole
fraction is 1 - sum(x_independent). Temperature and pressure
derivatives hold composition fixed.
Mole-number derivatives hold T and P fixed and are evaluated at
n_i = x_i mol (a one-mole total basis). Because all returned
properties are intensive, the corresponding derivative at another total
amount is this value divided by that amount in mol.
Fugacity derivatives have Pa per coordinate units.
dlog_fugacity_* differentiates the dimensionless
ln(f_i / p_standard). Chemical-potential derivatives have J/mol per
coordinate units; the reduced variants differentiate mu_i / (R*T).
Molar-volume derivatives have m3/mol per coordinate units.
Source code in src/torch_flash/properties/state.py
IdealGasPolynomial
¶
Bases: Module
Polynomial ideal-gas heat-capacity standard state.
For m columns, the heat capacity is
sum(c[j]*T**j, j=0..m-1) in J/(mol K). Four columns recover
Pedersen's Eq. 8.4; five columns support the Poling data bank. Reference
enthalpies and entropies make the otherwise arbitrary caloric datum
explicit and allow the coefficients to be fitted with PyTorch.
Source code in src/torch_flash/standard_state.py
heat_capacity
¶
Return ideal-gas component heat capacities in J/(mol K).
Source code in src/torch_flash/standard_state.py
enthalpy
¶
Return ideal-gas component enthalpies in J/mol.
Source code in src/torch_flash/standard_state.py
entropy
¶
Return ideal-gas component entropy at standard pressure in J/(mol K).
Source code in src/torch_flash/standard_state.py
chemical_potential
¶
Return ideal-gas standard chemical potentials in J/mol.
BatchedTwoPhaseFlashResult
dataclass
¶
Fixed two-phase flash results for a batch of known unstable states.
Source code in src/torch_flash/types.py
ChemicalState
dataclass
¶
Specified temperature, pressure, and overall composition.
Source code in src/torch_flash/types.py
FlashResult
dataclass
¶
Equilibrium phases and numerical diagnostics.
Source code in src/torch_flash/types.py
phase_identifications
property
¶
Per-phase physical-identification diagnostics.
PhaseIdentification
dataclass
¶
Likely physical identity of a homogeneous phase.
kind is deliberately separate from the EoS root requested through
:class:PhaseProperties. For the Pedersen cubic-EoS criterion,
criterion_value is V/b and threshold is normally 1.75. For
density ordering, they are the phase molar volume and the geometric-mean
separator between the two least-dense phases. The Boolean ambiguous
marks values within the configured relative band around the separator.
Phase identification is a naming diagnostic; it does not change the equilibrium calculation or any thermodynamic property.
Source code in src/torch_flash/types.py
PhaseProperties
dataclass
¶
Thermodynamic properties of one homogeneous phase.
Fugacities are in Pa and log_fugacities are the dimensionless
ln(f_i / p_standard) values. Chemical potentials and molar free
energies are in J/mol. reduced_* chemical potentials and energies are
dimensionless quantities divided by R*T. Total quantities use the
standard-state convention selected by phase_properties; the reduced
residual quantities are reference-independent EoS departures.
Source code in src/torch_flash/types.py
activity_model
¶
activity_model(parameter_set, names=None, *, dtype=None, device=None, trainable=False, covolumes=None, group_assignments=None)
Construct NRTL, HV-NRTL, Wilson, or original UNIFAC from YAML.
The requested component order may differ from the stored order; vectors
and matrices are permuted consistently. For custom fitting workflows, the
model classes continue to accept explicit tensors directly. UNIFAC uses
bundled fragmentations selected by names or explicit
group_assignments.
Source code in src/torch_flash/activity/named.py
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 | |
unifac_groups_from_identifiers
¶
Fragment molecules with the optional MIT-licensed ugropy package.
SMILES inputs are recommended for reproducibility. Name lookup delegates
to PubChem and therefore requires network access and may change outside
torch-flash. Fragmentation is discrete; inspect every returned map
before using it in regression or safety-critical calculations.
Source code in src/torch_flash/activity/unifac.py
unifac_model
¶
unifac_model(parameter_set='unifac-original', names=None, *, group_assignments=None, dtype=None, device=None, trainable=False)
Construct original UNIFAC from cached YAML or explicit parameters.
names select bundled, audited component fragmentations. Arbitrary
molecules use group_assignments, where each mapping may be keyed by
subgroup key, published subgroup number, or an unambiguous subgroup name.
The optional :func:unifac_groups_from_identifiers adapter can generate
these mappings with ugropy.
Source code in src/torch_flash/activity/unifac.py
equal_weight_lump
¶
Lump contiguous SCN cuts into approximately equal-weight groups.
Critical properties supplied through properties use Pedersen's
weight-average rule (2024, Eqs. 5.29-5.31). Molar mass is mole averaged;
density, when present, preserves ideal mixed volume.
Source code in src/torch_flash/characterization/lumping.py
pedersen_cubic_properties
¶
Map characterized SCN cuts to SRK or PR properties.
Implements Pedersen et al. (2024), Eqs. 5.1-5.5 and Table 5.3. The correlation coefficients are EoS-specific; the input distribution and density split remain model-neutral.
Source code in src/torch_flash/characterization/cubic.py
pedersen_density_split
¶
pedersen_density_split(distribution, plus_density, *, anchor_density=None, anchor_carbon_number=None, parameter_set='characterization.pedersen-2024')
Assign rho_N = C + D ln(CN) while matching bulk plus density.
Density inputs and results are SI (kg/m3). If no measured anchor is provided, Pedersen's suggested C6 density ratio is applied to the carbon number immediately preceding the plus fraction.
Source code in src/torch_flash/characterization/distributions.py
pedersen_logarithmic_split
¶
pedersen_logarithmic_split(plus_mole_fraction, plus_molar_mass, *, first_carbon_number=7, max_carbon_number=None, parameter_set='characterization.pedersen-2024', dtype=None, device=None)
Split a plus fraction with Pedersen's logarithmic molar distribution.
The finite distribution satisfies both plus-fraction mole and molar-mass balances (Pedersen et al., 2024, Eqs. 5.10-5.12). Molecular weights use Eq. 5.22. Measured extended compositions should be preferred whenever available, as emphasized by the source.
Source code in src/torch_flash/characterization/distributions.py
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 118 119 120 121 122 123 124 | |
whitson_gamma_split
¶
whitson_gamma_split(plus_mole_fraction, plus_molar_mass, *, first_carbon_number=7, max_carbon_number=80, shape=None, minimum_molar_mass=None, parameter_set='characterization.whitson-2000', dtype=None, device=None)
Discretize Whitson's shifted gamma distribution into SCN-like bins.
The last requested bin contains the complete tail to infinite molecular
weight, so total moles and average molar mass are preserved exactly apart
from floating-point roundoff. shape=1 gives the exponential special
case discussed by both Whitson and Pedersen.
Source code in src/torch_flash/characterization/distributions.py
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 | |
canonical_component_name
¶
Return the canonical torch-flash name for a name or alias.
Source code in src/torch_flash/components.py
clear_component_caches
¶
component
¶
Look up a component by canonical name or alias.
component_set
¶
Build vectorized cubic-EoS constants from a component database.
Omitted tensor options follow the process-wide :mod:torch_flash.config
policy. Explicit dtype or device arguments override that policy.
Source code in src/torch_flash/components.py
load_component_database
¶
Load the bundled or a custom SI component YAML database once.
Source code in src/torch_flash/components.py
configure
¶
configure(*, device=None, dtype=None, num_threads=None, num_interop_threads=None, deterministic=None, deterministic_warn_only=None)
Set the process-wide torch-flash runtime policy before model creation.
device="auto" selects the first available CUDA, XPU, or MPS device
that supports the requested dtype, falling back to CPU. device="gpu"
performs the same search but raises if no accelerator supports the dtype.
The dtype becomes PyTorch's default floating dtype. The selected device is
applied only by torch-flash factories and :class:RuntimeConfig tensor
helpers; this function deliberately does not call
:func:torch.set_default_device, which adds overhead to every Python-level
PyTorch API call.
PyTorch thread counts and deterministic-algorithm flags are inherently
process-wide. In particular, num_interop_threads can be changed only
once and before inter-operation parallel work starts; PyTorch's failure is
reported with an actionable error.
Source code in src/torch_flash/config.py
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 | |
get_config
¶
Return the current immutable torch-flash runtime configuration.
Source code in src/torch_flash/config.py
available_parameter_sets
¶
Return bundled parameter-set identifiers, optionally filtered by kind.
Source code in src/torch_flash/database.py
clear_parameter_caches
¶
Clear parsed YAML caches, primarily for custom-file development.
load_model_parameters
¶
Load a bundled identifier, custom YAML path, or explicit parameter set.
Parsed bundled and custom files are cached by identifier or resolved path.
Call :func:clear_parameter_caches after intentionally modifying a custom
file in a long-running process.
Source code in src/torch_flash/database.py
binary_bubble_point
¶
binary_bubble_point(model, temperature, liquid_composition, *, initial_pressure=None, initial_vapor_composition=None, minimum_pressure=None, maximum_pressure=None, tolerance=1e-08, max_iterations=30)
Solve binary bubble pressure and vapor composition at fixed T, x.
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
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 | |
binary_critical_point
¶
binary_critical_point(model, composition, *, initial_temperature=None, initial_pressure=None, tolerance=1e-09, max_iterations=30)
Solve the binary mixture criticality conditions with autodiff.
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
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 | |
binary_phase_equilibrium_point
¶
binary_phase_equilibrium_point(model, temperature, pressure, initial_phase1_composition, initial_phase2_composition, *, phase_kinds=('stable', 'stable'), tolerance=1e-08, max_iterations=30, minimum_phase_separation=1e-06)
Solve binary phase coexistence at fixed T and P.
("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
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 | |
binary_vle_point
¶
binary_vle_point(model, temperature, pressure, initial_liquid_composition, initial_vapor_composition, *, tolerance=1e-08, max_iterations=30, minimum_phase_separation=1e-06)
Solve binary liquid-vapor coexistence at fixed T and P.
Source code in src/torch_flash/envelope.py
continue_saturation_branch
¶
continue_saturation_branch(model, composition, initial_point, target_log_k_values, *, controlled_component=0, tolerance=1e-09, max_iterations=60, accelerated=True)
Continue a saturation branch using one ln(K_i) as coordinate.
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
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 | |
phase_envelope
¶
Trace bubble/dew branches over a specified temperature grid.
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
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 | |
saturation_point
¶
saturation_point(model, temperature, composition, kind, *, initial_pressure=None, initial_k_values=None, tolerance=1e-08, max_iterations=40, substitution_iterations=None)
Calculate an isothermal bubble or dew point with full Newton updates.
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
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 | |
cpa_components_from_cuts
¶
cpa_components_from_cuts(cuts, *, parameter_set='cpa.yan-2009-reservoir-fluids', dtype=None, device=None)
Characterize analyzed C7+ cuts and normalize their internal fractions.
This function covers the EoS-parameter step of a plus-fraction workflow. It deliberately does not invent a carbon-number distribution when only a bulk C7+ molecular weight is known; splitting or lumping must be performed upstream with measured cuts or an explicitly selected Whitson/Pedersen distribution model.
Source code in src/torch_flash/eos/cpa_heavy_end.py
cpa_eos
¶
cpa_eos(names, parameter_set='cpa.folas-2005', *, kij=None, kij_a=None, kij_b=None, lij=None, cross_association_energy=None, cross_association_volume=None, combining_rule=None, trainable=False, trainable_lij=False, association_iterations=10, association_newton_iterations=8, dtype=None, device=None)
Construct CPA from a bundled/custom YAML set or use :class:CPAEOS.
Direct construction with a tuple of :class:CPAComponent remains the
explicit in-memory API for fitting new species or parameterizations.
lij optionally modifies the physical SRK co-volume rule;
trainable_lij controls it independently of the attraction parameters.
Source code in src/torch_flash/eos/cpa.py
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 | |
cpa_folas_2005
¶
cpa_folas_2005(names, *, kij=None, lij=None, combining_rule='ECR', trainable=False, trainable_lij=False, dtype=None, device=None)
Construct CPA with the Folas et al. (2005), Table 1, pure parameters.
Reference: doi:10.1021/ie048832j.
Source code in src/torch_flash/eos/cpa.py
cpa_heavy_end_correlations
¶
Load and validate CPA heavy-end correlation coefficients.
Source code in src/torch_flash/eos/cpa_heavy_end.py
cpa_monomer_properties
¶
cpa_monomer_properties(normal_boiling_temperature, specific_gravity, parameter_set='cpa.yan-2009-reservoir-fluids')
Calculate CPA monomer properties for one narrow heavy-end cut.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
normal_boiling_temperature
|
float
|
Atmospheric normal boiling temperature in K. |
required |
specific_gravity
|
float
|
Dimensionless liquid specific gravity used by the source characterization. |
required |
Source code in src/torch_flash/eos/cpa_heavy_end.py
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 | |
cpa_oliveira_2007
¶
cpa_oliveira_2007(names, *, kij=None, lij=None, cross_association_energy=None, cross_association_volume=None, trainable=False, trainable_lij=False, dtype=None, device=None)
Construct the hydrocarbon-water CPA parameterization of Oliveira et al.
Pure parameters and constant physical-term interactions are from Tables 1-3 of Oliveira, Coutinho, and Queimada, Fluid Phase Equilibria 258 (2007) 58-66, doi:10.1016/j.fluid.2007.05.023. Aromatic-water solvation uses the paper's modified CR-1 cross-association parameters.
Source code in src/torch_flash/eos/cpa.py
cpa_pseudocomponent
¶
cpa_pseudocomponent(name, normal_boiling_temperature, specific_gravity, molar_mass, parameter_set='cpa.yan-2009-reservoir-fluids')
Create a non-associating CPA pseudo-component for a heavy-end cut.
Source code in src/torch_flash/eos/cpa_heavy_end.py
cpa_yan_2009
¶
cpa_yan_2009(names, *, kij=None, kij_a=None, kij_b=None, lij=None, trainable=False, trainable_lij=False, dtype=None, device=None)
Construct reservoir-fluid CPA with Yan et al.'s A + B/T water BIPs.
Reference: Yan, Kontogeorgis, and Stenby, Fluid Phase Equilibria 276 (2009) 75-85, doi:10.1016/j.fluid.2008.10.007.
Source code in src/torch_flash/eos/cpa.py
cubic_constants
¶
Construct typed cubic constants from YAML or an explicit parameter set.
Source code in src/torch_flash/eos/cubic.py
cubic_eos
¶
cubic_eos(components, parameter_set, *, kij=None, kij_a=None, kij_b=None, lij=None, trainable=False, trainable_lij=False, mixing=None, volume_translation=None)
Construct a cubic EoS from bundled YAML or explicit typed constants.
Supply kij for a constant quadratic interaction matrix, or both
kij_a and kij_b for kij(T) = kij_a + kij_b/T. The latter
coefficients are dimensionless and kelvin, respectively. Supply lij
for bij = 0.5*(bi+bj)*(1-lij); omitting it recovers the conventional
linear covolume rule. trainable controls attraction interactions;
trainable_lij independently enables co-volume fitting from the
supplied matrix or from zero.
Source code in src/torch_flash/eos/cubic.py
density_matched_translation
¶
Match a reference density with an additive component translation.
All inputs use SI units. The returned shift is
M/rho - v_eos, while the equivalent published Péneloux coefficient is
its negative.
Source code in src/torch_flash/eos/volume_translation.py
eoscg2021
¶
eoscg2021(names=None, *, dtype=None, device=None, trainable=False, parameter_set='multifluid.eos-cg-2021')
Construct the complete native 16-component EOS-CG-2021 Helmholtz model.
Reference: Neumann et al. (2023), doi:10.1007/s10765-023-03263-6, including its supplementary tables.
Source code in src/torch_flash/eos/named.py
gerg2008
¶
gerg2008(names=None, *, dtype=None, device=None, trainable=False, parameter_set='multifluid.gerg-2008')
Construct the complete native 21-component GERG-2008 Helmholtz model.
Reference: Kunz and Wagner (2012), doi:10.1021/je300655b.
Source code in src/torch_flash/eos/named.py
multifluid_eos
¶
Construct a native multifluid EoS from YAML or explicit parameters.
Source code in src/torch_flash/eos/named.py
pedersen_peneloux_translation
¶
Return the Pedersen light-component SRK/PR Péneloux translation.
SRK uses Pedersen Eq. 4.46 and PR uses the Jhaveri-Youngren Eq. 4.49. These correlations were fitted for nonhydrocarbons and hydrocarbons lighter than C7; heavier fractions should use density matching or a characterized parameter set.
Source code in src/torch_flash/eos/volume_translation.py
pedersen_temperature_dependent_translation
¶
pedersen_temperature_dependent_translation(model, reference_density, *, pressure=101325.0, source=_PEDERSEN_SOURCE)
Fit Pedersen's linear C7+ translation using Eqs. 5.7-5.9.
reference_density is in kg/m3 at 288.15 K by default. The ASTM
correlation supplies the target density at 353.15 K, and the parent cubic
EoS supplies the unshifted liquid volumes at both temperatures.
Source code in src/torch_flash/eos/volume_translation.py
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 | |
peng_robinson_1976
¶
peng_robinson_1976(components, *, kij=None, kij_a=None, kij_b=None, lij=None, trainable=False, trainable_lij=False, mixing=None, volume_translation=None)
Construct the original 1976 Peng-Robinson equation of state.
Source code in src/torch_flash/eos/cubic.py
peng_robinson_1978
¶
peng_robinson_1978(components, *, kij=None, kij_a=None, kij_b=None, lij=None, trainable=False, trainable_lij=False, mixing=None, volume_translation=None)
Construct the 1978 Peng-Robinson acentric-factor variant.
Source code in src/torch_flash/eos/cubic.py
predictive_peng_robinson_1978
¶
predictive_peng_robinson_1978(components, *, parameter_set=DEFAULT_PPR78_GROUP_CONTRIBUTION, group_counts=None, trainable=False, volume_translation=None)
Construct PPR78 with group-contribution kij(T).
The default parameter set is the original six-group saturated-hydrocarbon
fit of Jaubert and Mutelet (2004), doi:10.1016/j.fluid.2004.06.059.
Custom YAML parameter sets and explicit component group counts use the
same path. trainable=True exposes the unique universal A/B group
interactions as PyTorch parameters.
PPR78 was derived with the linear covolume rule, so co-volume interactions are intentionally not accepted by this named constructor.
Source code in src/torch_flash/eos/cubic.py
rackett_compressibility_factor
¶
Return Z_RA = 0.29056 - 0.08775 omega from Pedersen Eq. 4.47.
Source code in src/torch_flash/eos/volume_translation.py
soave_redlich_kwong
¶
soave_redlich_kwong(components, *, kij=None, kij_a=None, kij_b=None, lij=None, trainable=False, trainable_lij=False, mixing=None, volume_translation=None)
Construct the 1972 Soave-Redlich-Kwong equation of state.
Source code in src/torch_flash/eos/cubic.py
whitson_volume_translation
¶
Return Whitson Tables 4.2-4.3 translations.
Named light components and normal paraffins through n-decane use the
tabulated s_i = c_i/b_i values. Any other component requires a family
entry and uses s_i = 1 - A0/M_i**A1 with M in g/mol.
Source code in src/torch_flash/eos/volume_translation.py
batched_two_phase_flash
¶
batched_two_phase_flash(model, state, *, initial_k_values=None, tolerance=1e-08, substitution_iterations=12, newton_iterations=16)
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. 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
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 | |
multiphase_flash
¶
Solve a fixed-phase-count PT flash by generalized substitution.
The initial release supports arbitrary fixed phase counts but automated phase discovery is conservative. For VLL/VLW work, supplying physically informed initial K values remains recommended.
Source code in src/torch_flash/flash/multiphase.py
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 | |
solve_generalized_rachford_rice
¶
Solve multiphase material balance for phase ratios to a reference phase.
k_values has shape (nphases - 1, ncomponents). The returned phase
fractions place the reference phase first.
Source code in src/torch_flash/flash/multiphase.py
tangent_plane_stability
¶
tangent_plane_stability(model, state, *, reference_phase='stable', initial_compositions=None, tolerance=1e-09, max_iterations=40)
Minimize normalized tangent-plane distance from several trial phases.
Source code in src/torch_flash/flash/stability.py
two_phase_flash
¶
two_phase_flash(model, state, *, initial_k_values=None, check_stability=True, tolerance=1e-08, max_iterations=100, raise_on_failure=False)
Solve an isothermal two-phase flash by hybrid substitution/Newton steps.
Source code in src/torch_flash/flash/two_phase.py
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 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 | |
rachford_rice_numpy
¶
NumPy compatibility wrapper matching the Whitson contest signature.
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
binary_interaction
¶
Return a symmetric kij matrix from YAML model parameters.
Source code in src/torch_flash/parameters/petroleum.py
cubic_interaction_parameters
¶
Load general van der Waals one-fluid kij and lij matrices.
The YAML payload declares component_order, optional numeric
defaults, and unordered first|second pair records. Missing pair
fields use the declared defaults, which are zero when omitted.
Source code in src/torch_flash/parameters/cubic_interactions.py
pedersen_binary_interaction
¶
Return Pedersen et al. (2024), Table 4.2, kij values.
This is a distinct parameterization from Whitson's Table A-3. The source's aggregate C7+ entries are used for n-heptane through n-decane.
Source code in src/torch_flash/parameters/petroleum.py
ppr78_group_contribution_parameters
¶
ppr78_group_contribution_parameters(components, source=DEFAULT_PPR78_GROUP_CONTRIBUTION, *, group_counts=None)
Load PPR78 group parameters for components.
source may be the bundled identifier, a custom YAML path, or an
in-memory :class:~torch_flash.database.ModelParameterSet. Explicit
group_counts override only the component decompositions; the source
still supplies the group inventory and interaction matrices.
Source code in src/torch_flash/parameters/group_contribution.py
ppr78_mixing
¶
ppr78_mixing(components, source=DEFAULT_PPR78_GROUP_CONTRIBUTION, *, group_counts=None, trainable=False)
Construct PPR78 mixing from bundled, custom-file, or API parameters.
Source code in src/torch_flash/parameters/group_contribution.py
whitson_binary_interaction
¶
Return Whitson and Brule (2000), Table A-3, kij values.
The source's C7+ values are applied from n-heptane through n-decane. The printed H2S/C7+ value is not silently extrapolated by carbon number.
Source code in src/torch_flash/parameters/petroleum.py
fugacities_tv
¶
Return component fugacities in Pa from an explicit T-V-n state.
Source code in src/torch_flash/properties/state.py
identify_flash_phases
¶
Fill unavailable multiphase identities by molar-volume ordering.
Existing V/b identifications are preserved. If no phase has a cubic
covolume diagnostic, the least-dense phase (largest molar volume) is
labeled vapor and the remaining phases liquid. Near-equal leading volumes
are returned as ambiguous unknown because density ordering cannot
distinguish liquid-liquid equilibrium from a vapor-liquid split.
Source code in src/torch_flash/properties/phase_identification.py
identify_phase
¶
identify_phase(model, state, phase='stable', *, threshold=DEFAULT_VOLUME_TO_COVOLUME_THRESHOLD, ambiguity_relative_tolerance=DEFAULT_AMBIGUITY_RELATIVE_TOLERANCE)
Identify a scalar homogeneous state using the Pedersen V/b rule.
The default threshold of 1.75 is documented by Pedersen et al. for SRK and
PR. Models that expose compatible cubic-family mixture_parameters can
use the same machinery, but a non-SRK/PR threshold requires independent
validation. If the model does not expose a covolume, unknown is
returned rather than inferring physical identity from the selected root.
Source code in src/torch_flash/properties/phase_identification.py
log_fugacities_tv
¶
Return ln(f_i/p_standard) from an explicit T-V-n state.
volume is the total physical volume in m3 and moles are component
amounts in mol. The identity
ln(f_i/p_standard) = ln(n_i*R*T/(V*p_standard)) + d(A^R/RT)/dn_i
provides an independent Helmholtz-route check of the usual TP fugacity calculation. The model's residual Helmholtz energy must be extensive and referenced to an ideal gas at the same physical volume.
Source code in src/torch_flash/properties/state.py
phase_properties
¶
Evaluate a homogeneous state, without any equilibrium calculation.
Fugacities are returned in Pa and logarithmic fugacities are
ln(f_i / p_standard) with p_standard = 1 bar. Chemical potentials
and total free energies use a zero ideal-gas standard chemical potential
at that pressure unless standard_state is supplied. The corresponding
dimensionless chemical potential is mu_i / (R*T); it is the
thermodynamically meaningful alternative to ln(mu_i), which is not
generally defined for a dimensional, reference-dependent quantity that
may be negative.
Absolute caloric reference terms are deliberately not invented; returned enthalpy and entropy are residual quantities.
The reduced molar free energies are
reduced_gibbs_energy = g/(R*T) and
reduced_helmholtz_energy = a/(R*T), with a = g - P*v. The
reference-independent departures follow
g^R/(R*T) = sum(x_i*ln(phi_i)) and
a^R/(R*T) = g^R/(R*T) - Z + 1 + ln(Z), where
Z = P*v/(R*T).
At an exactly zero mole fraction, the logarithmic component properties
use the smallest positive value of the tensor dtype as a finite trace
limit. state_derivatives instead requires a strictly positive,
interior composition because logarithmic composition derivatives are
singular on the simplex boundary.
Source code in src/torch_flash/properties/state.py
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 | |
state_derivatives
¶
Autodifferentiate TP state properties in several composition coordinates.
Source code in src/torch_flash/properties/state.py
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 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 | |
thermal_properties
¶
thermal_properties(model, state, standard_state, phase='stable', *, reference_pressure=STANDARD_PRESSURE, molar_mass=None)
Evaluate Pedersen Chapter 8 properties at a specified state.
No phase-equilibrium calculation is performed. The requested phase root
remains fixed while differentiating. A volume-translated cubic receives
Pedersen's P*DeltaV enthalpy correction (Eq. 8.12).
The entropy pressure term in Eq. 8.17 is interpreted as
-R*ln(P/Pref); the glyph in the printed 2024 edition can resemble
T, but dimensional consistency and the ideal-gas identity require
the gas constant. Helmholtz energy follows a = g - P*v. Reduced total
free energies use the supplied caloric reference, while reduced residual
free energies are reference-independent EoS departures.
Source code in src/torch_flash/properties/thermal.py
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 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 | |
volume_to_covolume_ratio
¶
Return the differentiable cubic-family V/b phase diagnostic.
Leading batch dimensions are supported. Cubic volume translations are
excluded because Pedersen's criterion uses the volume entering the cubic
repulsive term. A model without mixture_parameters has no defined
covolume and raises TypeError.
Source code in src/torch_flash/properties/phase_identification.py
ideal_gas_polynomial
¶
ideal_gas_polynomial(names, parameter_set, *, dtype=None, device=None, reference_temperature=None, trainable=False)
Construct an ideal-gas polynomial from YAML or explicit parameters.
Source code in src/torch_flash/standard_state.py
poling_ideal_gas
¶
Construct a named Poling ideal-gas standard state.
The tabulated fits cover 50-1000 K for gases through propane and 200-1000 K for C4-C10. Argon and helium are the monatomic ideal-gas limits. This function deliberately does not extrapolate or clip temperatures; callers remain responsible for checking those source ranges in their application.
Source code in src/torch_flash/standard_state.py
lbc_pseudocomponent_critical_volume
¶
Estimate a C7+ critical molar volume from Pedersen Eq. 10.41.
Parameters are SI: molar mass in kg/mol and liquid density in kg/m3. The returned critical molar volume is in m3/mol. The underlying empirical equation uses g/mol, g/cm3, and ft3/lbmol.
Source code in src/torch_flash/transport/viscosity.py
lbc_viscosity
¶
lbc_viscosity(temperature, molar_density, composition, components, *, critical_volume=None, coefficients=None)
Return Lohrenz-Bray-Clark mixture viscosity in Pa s.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
temperature
|
Tensor
|
Temperature in K. |
required |
molar_density
|
Tensor
|
Homogeneous-phase molar density in mol/m3, normally obtained from the same EoS used by the flash calculation. |
required |
composition
|
Tensor
|
One mole-fraction vector. |
required |
components
|
ComponentSet
|
Critical temperatures, pressures, molar masses, and volumes. |
required |
critical_volume
|
Tensor | None
|
Optional m3/mol values overriding the component data. This is the principal LBC tuning parameter for petroleum pseudocomponents. |
None
|
coefficients
|
Tensor | None
|
Optional trainable or fitted |
None
|
Notes
The Stiel-Thodos reducing parameters use K, atm, and g/mol, as required by the published numerical constants. LBC is empirical and often needs pseudocomponent critical-volume or coefficient tuning for heavy oils.
Source code in src/torch_flash/transport/viscosity.py
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 | |
pedersen_viscosity
¶
Return Pedersen CSP mixture viscosity in Pa s.
Source code in src/torch_flash/transport/viscosity.py
torch_flash.config
¶
Process-wide runtime configuration for native torch-flash models.
The configuration is intentionally read when model or data tensors are constructed, not inside thermodynamic kernels. Existing model instances are therefore unaffected by later configuration changes and hot-path calls do not pay for repeated policy lookups.
RuntimeConfig
dataclass
¶
Immutable snapshot of torch-flash's tensor and execution policy.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
device
|
device
|
Device used by named model, component, standard-state, and characterization factories when no explicit device is supplied. |
required |
dtype
|
dtype
|
Floating-point dtype used by those factories. Float64 is the scientific default; float32 is available for explicit lower-precision studies. |
required |
num_threads
|
int
|
Current PyTorch CPU intra-operation thread count. |
required |
num_interop_threads
|
int
|
Current PyTorch CPU inter-operation thread count. |
required |
deterministic
|
bool
|
Whether PyTorch deterministic algorithms are enabled. |
required |
deterministic_warn_only
|
bool
|
Whether unavailable deterministic algorithms warn instead of raising. |
required |
Source code in src/torch_flash/config.py
tensor_options
property
¶
Return keyword arguments for PyTorch tensor factory functions.
tensor
¶
Construct a copied tensor using this runtime policy by default.
Source code in src/torch_flash/config.py
as_tensor
¶
Convert data using this runtime policy without unnecessary copies.
Source code in src/torch_flash/config.py
get_config
¶
Return the current immutable torch-flash runtime configuration.
Source code in src/torch_flash/config.py
configure
¶
configure(*, device=None, dtype=None, num_threads=None, num_interop_threads=None, deterministic=None, deterministic_warn_only=None)
Set the process-wide torch-flash runtime policy before model creation.
device="auto" selects the first available CUDA, XPU, or MPS device
that supports the requested dtype, falling back to CPU. device="gpu"
performs the same search but raises if no accelerator supports the dtype.
The dtype becomes PyTorch's default floating dtype. The selected device is
applied only by torch-flash factories and :class:RuntimeConfig tensor
helpers; this function deliberately does not call
:func:torch.set_default_device, which adds overhead to every Python-level
PyTorch API call.
PyTorch thread counts and deterministic-algorithm flags are inherently
process-wide. In particular, num_interop_threads can be changed only
once and before inter-operation parallel work starts; PyTorch's failure is
reported with an actionable error.
Source code in src/torch_flash/config.py
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 | |
resolve_tensor_options
¶
Resolve optional factory arguments against the current runtime policy.
Source code in src/torch_flash/config.py
torch_flash.eos
¶
Equation-of-state implementations.
CPAEOS
¶
Bases: Module
SRK cubic-plus-association mixture model.
Source code in src/torch_flash/eos/cpa.py
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 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 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 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 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 | |
pure_parameters
¶
Return CPA's fitted SRK energy and covolume parameters.
Source code in src/torch_flash/eos/cpa.py
mixture_parameters
¶
Return conventionally mixed physical-term parameters.
Source code in src/torch_flash/eos/cpa.py
binary_interaction
¶
Return the symmetric physical-term kij matrix at temperature.
Source code in src/torch_flash/eos/cpa.py
association_strength
¶
Return Delta[i, A, j, B] association strengths in m3/mol.
Source code in src/torch_flash/eos/cpa.py
site_fractions
¶
Solve the CPA mass-action equations for unbonded site fractions.
Leading dimensions are broadcast as independent homogeneous states. The component axis is the final composition dimension.
Source code in src/torch_flash/eos/cpa.py
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 | |
residual_helmholtz_rt
¶
Return extensive Ares/(RT) for the combined CPA model.
Source code in src/torch_flash/eos/cpa.py
pressure
¶
Evaluate the published CPA pressure equation.
Source code in src/torch_flash/eos/cpa.py
molar_volume
¶
Solve the CPA volume root for a specified phase.
Source code in src/torch_flash/eos/cpa.py
select_z
¶
Return the CPA compressibility factor.
Source code in src/torch_flash/eos/cpa.py
log_fugacity_coefficients
¶
Return CPA log fugacity coefficients from Helmholtz derivatives.
Source code in src/torch_flash/eos/cpa.py
CPAComponent
dataclass
¶
Pure-component CPA parameters and optional petroleum pseudo-properties.
critical_pressure, acentric_factor, and molar_mass normally
come from the shared component database. Petroleum pseudo-components can
instead carry those three initialization properties directly.
Source code in src/torch_flash/eos/cpa.py
CPACharacterizedComponents
dataclass
¶
Characterized pseudo-components and their normalized cut fractions.
Source code in src/torch_flash/eos/cpa_heavy_end.py
CPAHeavyEndCorrelations
dataclass
¶
Published coefficients used by the CPA C7+ monomer correlations.
Source code in src/torch_flash/eos/cpa_heavy_end.py
CPAMonomerProperties
dataclass
¶
Intermediate and final CPA monomer characterization results.
Source code in src/torch_flash/eos/cpa_heavy_end.py
CubicConstants
dataclass
¶
Definition of a generalized cubic EoS.
Source code in src/torch_flash/eos/cubic.py
CubicEOS
¶
Bases: Module
Generalized cubic equation of state with differentiable parameters.
Source code in src/torch_flash/eos/cubic.py
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 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 | |
component_volume_translation
¶
Return additive component volume shifts at temperature.
Source code in src/torch_flash/eos/cubic.py
pure_parameters
¶
Return temperature-dependent pure a_i and constant b_i.
Source code in src/torch_flash/eos/cubic.py
mixture_parameters
¶
Return mixed attraction and covolume parameters.
Source code in src/torch_flash/eos/cubic.py
dimensionless_parameters
¶
Return conventional cubic parameters A and B.
Source code in src/torch_flash/eos/cubic.py
z_factors
¶
Return sorted real compressibility-factor roots.
Source code in src/torch_flash/eos/cubic.py
select_z
¶
Select a physical liquid, vapor, or minimum-Gibbs root.
Source code in src/torch_flash/eos/cubic.py
molar_volume
¶
Return translated molar volume in m3/mol.
Source code in src/torch_flash/eos/cubic.py
pressure
¶
Evaluate pressure at a homogeneous T, v, x state.
Source code in src/torch_flash/eos/cubic.py
residual_helmholtz_rt
¶
Return extensive residual Helmholtz energy divided by RT.
Source code in src/torch_flash/eos/cubic.py
log_fugacity_coefficients
¶
Return component log fugacity coefficients.
The quadratic rule uses the standard closed form. Non-quadratic mixing rules use an autodifferentiated residual Helmholtz energy, preserving the exact composition dependence of the selected rule.
Source code in src/torch_flash/eos/cubic.py
GaoBTerms
dataclass
¶
Gao-B critical-region residual Helmholtz terms.
Source code in src/torch_flash/eos/multifluid.py
HelmholtzTerms
dataclass
¶
Power, exponential, Gaussian, and GERG-special terms.
The full form is n*delta^d*tau^t*exp(-delta^l
-eta*(delta-epsilon)^2-beta*(tau-gamma)^2
-linear_density*(delta-linear_shift)). Setting the optional arrays to
zero recovers the power-exponential subset. The final linear-density
factor is the binary departure form used by GERG-2008.
Source code in src/torch_flash/eos/multifluid.py
IdealHelmholtzTerms
dataclass
¶
Canonical pure-fluid ideal Helmholtz term tables.
Every component has lead, logarithmic, power, Planck--Einstein, and
optional GERG sinh/cosh terms. gas_scale is the ratio between the gas
constant of the original pure-fluid equation and the common mixture gas
constant. It multiplies the density-independent part only, preserving the
exact ideal-gas pressure limit.
Source code in src/torch_flash/eos/multifluid.py
MultiFluidEOS
¶
Bases: Module
Autodifferentiable multifluid Helmholtz model.
Source code in src/torch_flash/eos/multifluid.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 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 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 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 987 988 989 990 991 992 993 994 995 996 997 998 999 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 | |
reducing_functions
¶
Return mixture reducing temperature and molar density.
Source code in src/torch_flash/eos/multifluid.py
alpha_residual
¶
Return dimensionless molar residual Helmholtz energy.
Source code in src/torch_flash/eos/multifluid.py
alpha_ideal
¶
Return dimensionless molar ideal-gas Helmholtz energy.
Source code in src/torch_flash/eos/multifluid.py
alpha_total
¶
Return dimensionless total molar Helmholtz energy.
Source code in src/torch_flash/eos/multifluid.py
residual_helmholtz_rt
¶
Return extensive residual Helmholtz energy divided by RT.
Source code in src/torch_flash/eos/multifluid.py
helmholtz_rt
¶
Return extensive total Helmholtz energy divided by RT.
Source code in src/torch_flash/eos/multifluid.py
molar_helmholtz_energy
¶
Return total molar Helmholtz energy in J/mol.
Source code in src/torch_flash/eos/multifluid.py
molar_entropy
¶
Return total molar entropy in J/(mol K).
Source code in src/torch_flash/eos/multifluid.py
molar_internal_energy
¶
Return total molar internal energy in J/mol.
Source code in src/torch_flash/eos/multifluid.py
molar_heat_capacity_cv
¶
Return isochoric molar heat capacity in J/(mol K).
Source code in src/torch_flash/eos/multifluid.py
molar_heat_capacity_cp
¶
Return isobaric molar heat capacity in J/(mol K).
Source code in src/torch_flash/eos/multifluid.py
molar_enthalpy
¶
Return total molar enthalpy in J/mol.
Source code in src/torch_flash/eos/multifluid.py
molar_gibbs_energy
¶
Return total molar Gibbs energy in J/mol.
Source code in src/torch_flash/eos/multifluid.py
chemical_potentials
¶
Return total component chemical potentials in J/mol.
Source code in src/torch_flash/eos/multifluid.py
speed_of_sound
¶
Return homogeneous-phase speed of sound in m/s.
Source code in src/torch_flash/eos/multifluid.py
pressure
¶
Return pressure from a residual-Helmholtz density derivative.
Leading state dimensions are broadcast. The summed scalar objective
used by torch.func.grad differentiates independent batch entries
elementwise because the Helmholtz kernel contains no cross-state terms.
Source code in src/torch_flash/eos/multifluid.py
molar_volume
¶
Solve and select a homogeneous density root.
Phase-specific states first use a differentiable logarithmic-density Newton solve. If it fails, a logarithmic scan brackets every mechanically admissible positive root before bisection and Newton polishing. This conservative fallback matters because Helmholtz mixture models can have three density roots below the mixture critical locus, and an initial guess can cross a spinodal during phase-envelope calculations.
Source code in src/torch_flash/eos/multifluid.py
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 | |
select_z
¶
Return compressibility factor.
Source code in src/torch_flash/eos/multifluid.py
log_fugacity_coefficients
¶
Return log fugacity coefficients from composition derivatives.
Source code in src/torch_flash/eos/multifluid.py
MultifluidMetadata
dataclass
¶
Identity and validation scope of one coefficient set.
Source code in src/torch_flash/eos/multifluid.py
NonAnalyticTerms
dataclass
¶
Span-Wagner non-analytic critical-region residual terms.
Source code in src/torch_flash/eos/multifluid.py
VolumeTranslation
dataclass
¶
Component translations in the additive torch-flash convention.
reference_shift is in m3/mol, temperature_slope in
m3/(mol K), and reference_temperature in K. A published positive
Péneloux c therefore appears as a negative reference_shift.
Source code in src/torch_flash/eos/volume_translation.py
constant
classmethod
¶
Construct a temperature-independent additive translation.
at_temperature
¶
Return each component's additive shift at temperature.
Source code in src/torch_flash/eos/volume_translation.py
to
¶
Move translation coefficients to a common dtype and device.
Source code in src/torch_flash/eos/volume_translation.py
cpa_eos
¶
cpa_eos(names, parameter_set='cpa.folas-2005', *, kij=None, kij_a=None, kij_b=None, lij=None, cross_association_energy=None, cross_association_volume=None, combining_rule=None, trainable=False, trainable_lij=False, association_iterations=10, association_newton_iterations=8, dtype=None, device=None)
Construct CPA from a bundled/custom YAML set or use :class:CPAEOS.
Direct construction with a tuple of :class:CPAComponent remains the
explicit in-memory API for fitting new species or parameterizations.
lij optionally modifies the physical SRK co-volume rule;
trainable_lij controls it independently of the attraction parameters.
Source code in src/torch_flash/eos/cpa.py
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 | |
cpa_folas_2005
¶
cpa_folas_2005(names, *, kij=None, lij=None, combining_rule='ECR', trainable=False, trainable_lij=False, dtype=None, device=None)
Construct CPA with the Folas et al. (2005), Table 1, pure parameters.
Reference: doi:10.1021/ie048832j.
Source code in src/torch_flash/eos/cpa.py
cpa_oliveira_2007
¶
cpa_oliveira_2007(names, *, kij=None, lij=None, cross_association_energy=None, cross_association_volume=None, trainable=False, trainable_lij=False, dtype=None, device=None)
Construct the hydrocarbon-water CPA parameterization of Oliveira et al.
Pure parameters and constant physical-term interactions are from Tables 1-3 of Oliveira, Coutinho, and Queimada, Fluid Phase Equilibria 258 (2007) 58-66, doi:10.1016/j.fluid.2007.05.023. Aromatic-water solvation uses the paper's modified CR-1 cross-association parameters.
Source code in src/torch_flash/eos/cpa.py
cpa_yan_2009
¶
cpa_yan_2009(names, *, kij=None, kij_a=None, kij_b=None, lij=None, trainable=False, trainable_lij=False, dtype=None, device=None)
Construct reservoir-fluid CPA with Yan et al.'s A + B/T water BIPs.
Reference: Yan, Kontogeorgis, and Stenby, Fluid Phase Equilibria 276 (2009) 75-85, doi:10.1016/j.fluid.2008.10.007.
Source code in src/torch_flash/eos/cpa.py
cpa_components_from_cuts
¶
cpa_components_from_cuts(cuts, *, parameter_set='cpa.yan-2009-reservoir-fluids', dtype=None, device=None)
Characterize analyzed C7+ cuts and normalize their internal fractions.
This function covers the EoS-parameter step of a plus-fraction workflow. It deliberately does not invent a carbon-number distribution when only a bulk C7+ molecular weight is known; splitting or lumping must be performed upstream with measured cuts or an explicitly selected Whitson/Pedersen distribution model.
Source code in src/torch_flash/eos/cpa_heavy_end.py
cpa_heavy_end_correlations
¶
Load and validate CPA heavy-end correlation coefficients.
Source code in src/torch_flash/eos/cpa_heavy_end.py
cpa_monomer_properties
¶
cpa_monomer_properties(normal_boiling_temperature, specific_gravity, parameter_set='cpa.yan-2009-reservoir-fluids')
Calculate CPA monomer properties for one narrow heavy-end cut.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
normal_boiling_temperature
|
float
|
Atmospheric normal boiling temperature in K. |
required |
specific_gravity
|
float
|
Dimensionless liquid specific gravity used by the source characterization. |
required |
Source code in src/torch_flash/eos/cpa_heavy_end.py
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 | |
cpa_pseudocomponent
¶
cpa_pseudocomponent(name, normal_boiling_temperature, specific_gravity, molar_mass, parameter_set='cpa.yan-2009-reservoir-fluids')
Create a non-associating CPA pseudo-component for a heavy-end cut.
Source code in src/torch_flash/eos/cpa_heavy_end.py
cubic_constants
¶
Construct typed cubic constants from YAML or an explicit parameter set.
Source code in src/torch_flash/eos/cubic.py
cubic_eos
¶
cubic_eos(components, parameter_set, *, kij=None, kij_a=None, kij_b=None, lij=None, trainable=False, trainable_lij=False, mixing=None, volume_translation=None)
Construct a cubic EoS from bundled YAML or explicit typed constants.
Supply kij for a constant quadratic interaction matrix, or both
kij_a and kij_b for kij(T) = kij_a + kij_b/T. The latter
coefficients are dimensionless and kelvin, respectively. Supply lij
for bij = 0.5*(bi+bj)*(1-lij); omitting it recovers the conventional
linear covolume rule. trainable controls attraction interactions;
trainable_lij independently enables co-volume fitting from the
supplied matrix or from zero.
Source code in src/torch_flash/eos/cubic.py
peng_robinson_1976
¶
peng_robinson_1976(components, *, kij=None, kij_a=None, kij_b=None, lij=None, trainable=False, trainable_lij=False, mixing=None, volume_translation=None)
Construct the original 1976 Peng-Robinson equation of state.
Source code in src/torch_flash/eos/cubic.py
peng_robinson_1978
¶
peng_robinson_1978(components, *, kij=None, kij_a=None, kij_b=None, lij=None, trainable=False, trainable_lij=False, mixing=None, volume_translation=None)
Construct the 1978 Peng-Robinson acentric-factor variant.
Source code in src/torch_flash/eos/cubic.py
predictive_peng_robinson_1978
¶
predictive_peng_robinson_1978(components, *, parameter_set=DEFAULT_PPR78_GROUP_CONTRIBUTION, group_counts=None, trainable=False, volume_translation=None)
Construct PPR78 with group-contribution kij(T).
The default parameter set is the original six-group saturated-hydrocarbon
fit of Jaubert and Mutelet (2004), doi:10.1016/j.fluid.2004.06.059.
Custom YAML parameter sets and explicit component group counts use the
same path. trainable=True exposes the unique universal A/B group
interactions as PyTorch parameters.
PPR78 was derived with the linear covolume rule, so co-volume interactions are intentionally not accepted by this named constructor.
Source code in src/torch_flash/eos/cubic.py
soave_redlich_kwong
¶
soave_redlich_kwong(components, *, kij=None, kij_a=None, kij_b=None, lij=None, trainable=False, trainable_lij=False, mixing=None, volume_translation=None)
Construct the 1972 Soave-Redlich-Kwong equation of state.
Source code in src/torch_flash/eos/cubic.py
eoscg2021
¶
eoscg2021(names=None, *, dtype=None, device=None, trainable=False, parameter_set='multifluid.eos-cg-2021')
Construct the complete native 16-component EOS-CG-2021 Helmholtz model.
Reference: Neumann et al. (2023), doi:10.1007/s10765-023-03263-6, including its supplementary tables.
Source code in src/torch_flash/eos/named.py
gerg2008
¶
gerg2008(names=None, *, dtype=None, device=None, trainable=False, parameter_set='multifluid.gerg-2008')
Construct the complete native 21-component GERG-2008 Helmholtz model.
Reference: Kunz and Wagner (2012), doi:10.1021/je300655b.
Source code in src/torch_flash/eos/named.py
multifluid_eos
¶
Construct a native multifluid EoS from YAML or explicit parameters.
Source code in src/torch_flash/eos/named.py
density_matched_translation
¶
Match a reference density with an additive component translation.
All inputs use SI units. The returned shift is
M/rho - v_eos, while the equivalent published Péneloux coefficient is
its negative.
Source code in src/torch_flash/eos/volume_translation.py
pedersen_peneloux_translation
¶
Return the Pedersen light-component SRK/PR Péneloux translation.
SRK uses Pedersen Eq. 4.46 and PR uses the Jhaveri-Youngren Eq. 4.49. These correlations were fitted for nonhydrocarbons and hydrocarbons lighter than C7; heavier fractions should use density matching or a characterized parameter set.
Source code in src/torch_flash/eos/volume_translation.py
pedersen_temperature_dependent_translation
¶
pedersen_temperature_dependent_translation(model, reference_density, *, pressure=101325.0, source=_PEDERSEN_SOURCE)
Fit Pedersen's linear C7+ translation using Eqs. 5.7-5.9.
reference_density is in kg/m3 at 288.15 K by default. The ASTM
correlation supplies the target density at 353.15 K, and the parent cubic
EoS supplies the unshifted liquid volumes at both temperatures.
Source code in src/torch_flash/eos/volume_translation.py
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 | |
rackett_compressibility_factor
¶
Return Z_RA = 0.29056 - 0.08775 omega from Pedersen Eq. 4.47.
Source code in src/torch_flash/eos/volume_translation.py
whitson_volume_translation
¶
Return Whitson Tables 4.2-4.3 translations.
Named light components and normal paraffins through n-decane use the
tabulated s_i = c_i/b_i values. Any other component requires a family
entry and uses s_i = 1 - A0/M_i**A1 with M in g/mol.
Source code in src/torch_flash/eos/volume_translation.py
torch_flash.activity
¶
Excess-Gibbs-energy activity models.
NRTL
¶
Bases: Module
Non-random two-liquid excess Gibbs energy model.
interaction stores :math:g_{ij}-g_{jj} in J/mol and may be made
trainable. nonrandomness is the dimensionless :math:alpha_{ij}.
See Renon and Prausnitz, AIChE Journal 14 (1968), 135-144,
doi:10.1002/aic.690140124.
Source code in src/torch_flash/activity/models.py
excess_gibbs_rt
¶
Return dimensionless molar excess Gibbs energy, gE/(RT).
Source code in src/torch_flash/activity/models.py
log_activity_coefficients
¶
Return log(gamma) from an autodifferentiated extensive gE.
Source code in src/torch_flash/activity/models.py
AnchoredHuronVidalNRTL
¶
Bases: Module
Fit-ready HV-NRTL model anchored at two temperatures.
Directly regressing :math:A_{ij} and :math:B_{ij} in
:math:\tau_{ij}=A_{ij}/T+B_{ij} is poorly scaled and can be strongly
correlated over a finite experimental temperature interval. This exactly
equivalent parameterization stores trainable values of :math:\tau_{ij}
at two user-selected temperatures and interpolates linearly in
:math:1/T.
The optional trainable non-randomness matrix is kept symmetric and within
explicit open bounds by a sigmoid transform. Diagonal interactions remain
exactly zero. Call :meth:freeze after fitting to obtain the standard
:class:HuronVidalNRTL representation used by parameter databases.
Source code in src/torch_flash/activity/models.py
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 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 | |
tau_at_lower_temperature
property
¶
Return the lower-anchor interaction matrix with an exact zero diagonal.
tau_at_upper_temperature
property
¶
Return the upper-anchor interaction matrix with an exact zero diagonal.
temperature_coefficient
property
¶
Return dimensionless :math:B_{ij} for tau = A/T + B.
tau_matrix
¶
Return the interaction matrix, interpolated linearly in inverse T.
Source code in src/torch_flash/activity/models.py
excess_gibbs_rt
¶
Return the covolume-weighted HV excess Gibbs energy, gE/(RT).
Source code in src/torch_flash/activity/models.py
log_activity_coefficients
¶
Return log(gamma) by differentiating the extensive HV gE.
Source code in src/torch_flash/activity/models.py
freeze
¶
Return a detached standard HV-NRTL model for prediction or storage.
Source code in src/torch_flash/activity/models.py
HuronVidalNRTL
¶
Bases: Module
Covolume-weighted NRTL model used by the original HV formulation.
The dimensionless interaction energy is
.. math::
\tau_{ji}(T) = A_{ji}/T + B_{ji},
where energy_over_r stores :math:A in kelvin and
temperature_coefficient stores the dimensionless linear coefficient
:math:B. The excess Gibbs energy is the modified NRTL expression from
Huron and Vidal (1979), with :math:x_j b_j replacing :math:x_j in the
local-composition sums. Consequently its parameters must be fitted for
the HV infinite-pressure reference; ordinary low-pressure NRTL parameters
are not interchangeable.
Reference: Huron and Vidal, Fluid Phase Equilibria 3 (1979), 255-271, doi:10.1016/0378-3812(79)80001-1.
Source code in src/torch_flash/activity/models.py
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 | |
tau_matrix
¶
Return the dimensionless, temperature-dependent interaction matrix.
excess_gibbs_rt
¶
Return the covolume-weighted HV excess Gibbs energy, gE/(RT).
Source code in src/torch_flash/activity/models.py
log_activity_coefficients
¶
Return log(gamma) by differentiating the extensive HV gE.
Source code in src/torch_flash/activity/models.py
Wilson
¶
Bases: Module
Wilson excess Gibbs model with energy and molar-volume parameters.
See Wilson, Journal of the American Chemical Society 86 (1964), 127-130, doi:10.1021/ja01056a002.
Source code in src/torch_flash/activity/models.py
lambda_matrix
¶
Return the temperature-dependent Wilson Lambda matrix.
Source code in src/torch_flash/activity/models.py
excess_gibbs_rt
¶
Return dimensionless molar excess Gibbs energy, gE/(RT).
Source code in src/torch_flash/activity/models.py
log_activity_coefficients
¶
Return the analytical Wilson log(gamma) expression.
Source code in src/torch_flash/activity/models.py
UNIFAC
¶
Bases: Module
Original UNIFAC excess-Gibbs-energy model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
group_counts
|
Tensor
|
Component-by-subgroup occurrence matrix :math: |
required |
relative_volume
|
Tensor
|
Selected subgroup :math: |
required |
relative_surface_area
|
Tensor
|
Selected subgroup :math: |
required |
subgroup_main_indices
|
Tensor
|
Zero-based index of the selected main group for each subgroup. |
required |
interaction
|
Tensor
|
Directed selected-main-group matrix :math: |
required |
coordination_number
|
float
|
Lattice coordination number :math: |
10.0
|
trainable
|
bool
|
Store the main-group interaction matrix as an |
False
|
Notes
The model is vectorized over all leading dimensions of temperature and composition. PyTorch autodiff can therefore differentiate activities, excess Gibbs energy, and temperature/composition derivatives on CPU or GPU. Group assignment is discrete and is intentionally not trainable.
Source code in src/torch_flash/activity/unifac.py
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 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 | |
molecular_relative_volume
property
¶
Return component molecular volume parameters :math:r_i.
molecular_relative_surface_area
property
¶
Return component molecular surface parameters :math:q_i.
interaction_factors
¶
Return :math:\Psi_{mn}=\exp(-a_{mn}/T).
Source code in src/torch_flash/activity/unifac.py
combinatorial_log_activity_coefficients
¶
Return the original Flory-Huggins/Staverman-Guggenheim term.
Source code in src/torch_flash/activity/unifac.py
residual_log_activity_coefficients
¶
Return the solution-of-groups residual contribution.
Source code in src/torch_flash/activity/unifac.py
log_activity_coefficients
¶
Return log(gamma) for original UNIFAC.
Source code in src/torch_flash/activity/unifac.py
excess_gibbs_rt
¶
Return dimensionless molar excess Gibbs energy, gE/(RT).
Source code in src/torch_flash/activity/unifac.py
activity_model
¶
activity_model(parameter_set, names=None, *, dtype=None, device=None, trainable=False, covolumes=None, group_assignments=None)
Construct NRTL, HV-NRTL, Wilson, or original UNIFAC from YAML.
The requested component order may differ from the stored order; vectors
and matrices are permuted consistently. For custom fitting workflows, the
model classes continue to accept explicit tensors directly. UNIFAC uses
bundled fragmentations selected by names or explicit
group_assignments.
Source code in src/torch_flash/activity/named.py
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 | |
unifac_groups_from_identifiers
¶
Fragment molecules with the optional MIT-licensed ugropy package.
SMILES inputs are recommended for reproducibility. Name lookup delegates
to PubChem and therefore requires network access and may change outside
torch-flash. Fragmentation is discrete; inspect every returned map
before using it in regression or safety-critical calculations.
Source code in src/torch_flash/activity/unifac.py
unifac_model
¶
unifac_model(parameter_set='unifac-original', names=None, *, group_assignments=None, dtype=None, device=None, trainable=False)
Construct original UNIFAC from cached YAML or explicit parameters.
names select bundled, audited component fragmentations. Arbitrary
molecules use group_assignments, where each mapping may be keyed by
subgroup key, published subgroup number, or an unambiguous subgroup name.
The optional :func:unifac_groups_from_identifiers adapter can generate
these mappings with ugropy.
Source code in src/torch_flash/activity/unifac.py
torch_flash.mixing
¶
Mixing rules for equations of state.
HuronVidalMixing
¶
Bases: Module
Original infinite-pressure Huron-Vidal mixing rule.
The implementation follows Michelsen and Mollerup, chapter 7, Eq. 7:
a/(bRT) = sum(x_i a_i/(b_i RT)) - gE/(Delta RT).
Primary source: Huron and Vidal (1979), doi:10.1016/0378-3812(79)80001-1. The implementation convention follows Michelsen and Mollerup, Thermodynamic Models, 2nd ed. (2007), chapter 7, ISBN 978-87-989961-3-2.
Source code in src/torch_flash/mixing/rules.py
forward
¶
Return mixture a and b parameters.
Source code in src/torch_flash/mixing/rules.py
PPR78Mixing
¶
Bases: Module
Predictive PR78 group-contribution attraction mixing.
This is Eq. (5) of Jaubert and Mutelet (2004),
doi:10.1016/j.fluid.2004.06.059. For component group fractions
:math:\\alpha_{ik}, the method evaluates
.. math::
k_{ij}(T) = \frac{ -\frac12\sum_{kl}\Delta\alpha_{ij,k}\Delta\alpha_{ij,l} A_{kl}(T_r/T)^{B_{kl}/A_{kl}-1} -(\sqrt{a_i}/b_i-\sqrt{a_j}/b_j)^2 }{ 2\sqrt{a_i a_j}/(b_i b_j) }.
group_a and group_b are symmetric pressure-valued group
interaction matrices. Only their unique off-diagonal entries are stored,
avoiding redundant degrees of freedom during fitting. The paper derives
the correlation with the conventional linear covolume rule, which this
class preserves.
Source code in src/torch_flash/mixing/rules.py
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 | |
group_interaction_energy
¶
Return :math:A_{kl}(298.15/T)^{B_{kl}/A_{kl}-1} in pascals.
Source code in src/torch_flash/mixing/rules.py
kij
¶
Evaluate the symmetric component BIP matrix.
pure_a and pure_b must be the PR78 pure-component parameters
at temperature. This dependence is essential: PPR78 is not a
standalone A + B/T law.
Source code in src/torch_flash/mixing/rules.py
cross_a
¶
Return PPR78 unlike attraction parameters.
Source code in src/torch_flash/mixing/rules.py
partial_b
¶
Return partial covolumes for the PPR78 linear covolume rule.
forward
¶
Return PPR78 mixture a and linear mixture b.
Source code in src/torch_flash/mixing/rules.py
QuadraticMixing
¶
Bases: Module
van der Waals one-fluid mixing with kij and lij parameters.
The unlike attraction and covolume parameters are
aij = sqrt(ai*aj)*(1-kij) and
bij = 0.5*(bi+bj)*(1-lij), respectively.
lij=0 recovers the conventional linear covolume rule exactly and uses
a dedicated O(N) evaluation path.
This convention is also exposed by ThermoPack's get_lij/set_lij
cubic interface.
Source code in src/torch_flash/mixing/rules.py
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 118 119 120 121 122 123 124 | |
forward
¶
Return mixture a and b parameters.
Source code in src/torch_flash/mixing/rules.py
cross_a
¶
cross_b
¶
partial_b
¶
Return partial molar covolumes d(n*b_mix)/d(n_i).
Source code in src/torch_flash/mixing/rules.py
TemperatureDependentQuadraticMixing
¶
Bases: Module
van der Waals mixing with kij(T) = Aij + Bij/T.
Aij is dimensionless and Bij is in kelvin. This form is used by
Yan et al. for petroleum CPA calculations involving light hydrocarbons
and water (Fluid Phase Equilibria 276, 2009, 75-85,
doi:10.1016/j.fluid.2008.10.007).
Source code in src/torch_flash/mixing/rules.py
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 | |
kij
¶
Evaluate the interaction matrix at temperature in kelvin.
Source code in src/torch_flash/mixing/rules.py
forward
¶
Return mixture a and b parameters.
Source code in src/torch_flash/mixing/rules.py
cross_a
¶
Return temperature-dependent unlike energy parameters.
cross_b
¶
partial_b
¶
Return partial molar covolumes d(n*b_mix)/d(n_i).
Source code in src/torch_flash/mixing/rules.py
torch_flash.flash
¶
Stability-tested phase-equilibrium flash calculations.
batched_two_phase_flash
¶
batched_two_phase_flash(model, state, *, initial_k_values=None, tolerance=1e-08, substitution_iterations=12, newton_iterations=16)
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. 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
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 | |
multiphase_flash
¶
Solve a fixed-phase-count PT flash by generalized substitution.
The initial release supports arbitrary fixed phase counts but automated phase discovery is conservative. For VLL/VLW work, supplying physically informed initial K values remains recommended.
Source code in src/torch_flash/flash/multiphase.py
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 | |
solve_generalized_rachford_rice
¶
Solve multiphase material balance for phase ratios to a reference phase.
k_values has shape (nphases - 1, ncomponents). The returned phase
fractions place the reference phase first.
Source code in src/torch_flash/flash/multiphase.py
tangent_plane_stability
¶
tangent_plane_stability(model, state, *, reference_phase='stable', initial_compositions=None, tolerance=1e-09, max_iterations=40)
Minimize normalized tangent-plane distance from several trial phases.
Source code in src/torch_flash/flash/stability.py
two_phase_flash
¶
two_phase_flash(model, state, *, initial_k_values=None, check_stability=True, tolerance=1e-08, max_iterations=100, raise_on_failure=False)
Solve an isothermal two-phase flash by hybrid substitution/Newton steps.
Source code in src/torch_flash/flash/two_phase.py
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 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 | |
torch_flash.material_balance
¶
Material-balance equations.
rachford_rice_numpy
¶
NumPy compatibility wrapper matching the Whitson contest signature.
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
torch_flash.properties
¶
Homogeneous-state thermodynamic property calculations.
ThermodynamicDerivatives
dataclass
¶
First homogeneous-state derivatives.
Component derivatives are provided in both unconstrained softmax-logit
coordinates and n-1 independent mole fractions, where the last mole
fraction is 1 - sum(x_independent). Temperature and pressure
derivatives hold composition fixed.
Mole-number derivatives hold T and P fixed and are evaluated at
n_i = x_i mol (a one-mole total basis). Because all returned
properties are intensive, the corresponding derivative at another total
amount is this value divided by that amount in mol.
Fugacity derivatives have Pa per coordinate units.
dlog_fugacity_* differentiates the dimensionless
ln(f_i / p_standard). Chemical-potential derivatives have J/mol per
coordinate units; the reduced variants differentiate mu_i / (R*T).
Molar-volume derivatives have m3/mol per coordinate units.
Source code in src/torch_flash/properties/state.py
ThermalProperties
dataclass
¶
Caloric and response properties of one homogeneous phase.
All quantities are molar SI except the Joule-Thomson coefficient (K/Pa)
and speed of sound (m/s). reduced_* free energies are dimensionless
molar quantities divided by R*T.
Source code in src/torch_flash/properties/thermal.py
identify_flash_phases
¶
Fill unavailable multiphase identities by molar-volume ordering.
Existing V/b identifications are preserved. If no phase has a cubic
covolume diagnostic, the least-dense phase (largest molar volume) is
labeled vapor and the remaining phases liquid. Near-equal leading volumes
are returned as ambiguous unknown because density ordering cannot
distinguish liquid-liquid equilibrium from a vapor-liquid split.
Source code in src/torch_flash/properties/phase_identification.py
identify_phase
¶
identify_phase(model, state, phase='stable', *, threshold=DEFAULT_VOLUME_TO_COVOLUME_THRESHOLD, ambiguity_relative_tolerance=DEFAULT_AMBIGUITY_RELATIVE_TOLERANCE)
Identify a scalar homogeneous state using the Pedersen V/b rule.
The default threshold of 1.75 is documented by Pedersen et al. for SRK and
PR. Models that expose compatible cubic-family mixture_parameters can
use the same machinery, but a non-SRK/PR threshold requires independent
validation. If the model does not expose a covolume, unknown is
returned rather than inferring physical identity from the selected root.
Source code in src/torch_flash/properties/phase_identification.py
volume_to_covolume_ratio
¶
Return the differentiable cubic-family V/b phase diagnostic.
Leading batch dimensions are supported. Cubic volume translations are
excluded because Pedersen's criterion uses the volume entering the cubic
repulsive term. A model without mixture_parameters has no defined
covolume and raises TypeError.
Source code in src/torch_flash/properties/phase_identification.py
fugacities_tv
¶
Return component fugacities in Pa from an explicit T-V-n state.
Source code in src/torch_flash/properties/state.py
log_fugacities_tv
¶
Return ln(f_i/p_standard) from an explicit T-V-n state.
volume is the total physical volume in m3 and moles are component
amounts in mol. The identity
ln(f_i/p_standard) = ln(n_i*R*T/(V*p_standard)) + d(A^R/RT)/dn_i
provides an independent Helmholtz-route check of the usual TP fugacity calculation. The model's residual Helmholtz energy must be extensive and referenced to an ideal gas at the same physical volume.
Source code in src/torch_flash/properties/state.py
phase_properties
¶
Evaluate a homogeneous state, without any equilibrium calculation.
Fugacities are returned in Pa and logarithmic fugacities are
ln(f_i / p_standard) with p_standard = 1 bar. Chemical potentials
and total free energies use a zero ideal-gas standard chemical potential
at that pressure unless standard_state is supplied. The corresponding
dimensionless chemical potential is mu_i / (R*T); it is the
thermodynamically meaningful alternative to ln(mu_i), which is not
generally defined for a dimensional, reference-dependent quantity that
may be negative.
Absolute caloric reference terms are deliberately not invented; returned enthalpy and entropy are residual quantities.
The reduced molar free energies are
reduced_gibbs_energy = g/(R*T) and
reduced_helmholtz_energy = a/(R*T), with a = g - P*v. The
reference-independent departures follow
g^R/(R*T) = sum(x_i*ln(phi_i)) and
a^R/(R*T) = g^R/(R*T) - Z + 1 + ln(Z), where
Z = P*v/(R*T).
At an exactly zero mole fraction, the logarithmic component properties
use the smallest positive value of the tensor dtype as a finite trace
limit. state_derivatives instead requires a strictly positive,
interior composition because logarithmic composition derivatives are
singular on the simplex boundary.
Source code in src/torch_flash/properties/state.py
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 | |
state_derivatives
¶
Autodifferentiate TP state properties in several composition coordinates.
Source code in src/torch_flash/properties/state.py
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 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 | |
thermal_properties
¶
thermal_properties(model, state, standard_state, phase='stable', *, reference_pressure=STANDARD_PRESSURE, molar_mass=None)
Evaluate Pedersen Chapter 8 properties at a specified state.
No phase-equilibrium calculation is performed. The requested phase root
remains fixed while differentiating. A volume-translated cubic receives
Pedersen's P*DeltaV enthalpy correction (Eq. 8.12).
The entropy pressure term in Eq. 8.17 is interpreted as
-R*ln(P/Pref); the glyph in the printed 2024 edition can resemble
T, but dimensional consistency and the ideal-gas identity require
the gas constant. Helmholtz energy follows a = g - P*v. Reduced total
free energies use the supplied caloric reference, while reduced residual
free energies are reference-independent EoS departures.
Source code in src/torch_flash/properties/thermal.py
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 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 | |
torch_flash.transport
¶
Transport-property correlations.
lbc_pseudocomponent_critical_volume
¶
Estimate a C7+ critical molar volume from Pedersen Eq. 10.41.
Parameters are SI: molar mass in kg/mol and liquid density in kg/m3. The returned critical molar volume is in m3/mol. The underlying empirical equation uses g/mol, g/cm3, and ft3/lbmol.
Source code in src/torch_flash/transport/viscosity.py
lbc_viscosity
¶
lbc_viscosity(temperature, molar_density, composition, components, *, critical_volume=None, coefficients=None)
Return Lohrenz-Bray-Clark mixture viscosity in Pa s.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
temperature
|
Tensor
|
Temperature in K. |
required |
molar_density
|
Tensor
|
Homogeneous-phase molar density in mol/m3, normally obtained from the same EoS used by the flash calculation. |
required |
composition
|
Tensor
|
One mole-fraction vector. |
required |
components
|
ComponentSet
|
Critical temperatures, pressures, molar masses, and volumes. |
required |
critical_volume
|
Tensor | None
|
Optional m3/mol values overriding the component data. This is the principal LBC tuning parameter for petroleum pseudocomponents. |
None
|
coefficients
|
Tensor | None
|
Optional trainable or fitted |
None
|
Notes
The Stiel-Thodos reducing parameters use K, atm, and g/mol, as required by the published numerical constants. LBC is empirical and often needs pseudocomponent critical-volume or coefficient tuning for heavy oils.
Source code in src/torch_flash/transport/viscosity.py
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 | |
methane_viscosity
¶
Return methane dynamic viscosity in Pa s from Eq. 10.6.
Although the 2024 textbook prose labels the correlation density as mol/L, the published Hanley coefficients require mass density in kg/L (numerically equal to g/cm3). Using molar density inside the fractional powers produces viscosities two orders of magnitude too large at reservoir pressures.
Source code in src/torch_flash/transport/viscosity.py
pedersen_viscosity
¶
Return Pedersen CSP mixture viscosity in Pa s.
Source code in src/torch_flash/transport/viscosity.py
torch_flash.backends
¶
Optional validation backends.
BackendCapabilities
dataclass
¶
Explicit numerical and model-identity capability flags.
Source code in src/torch_flash/backends/base.py
CoolPropBackend
¶
CoolProp AbstractState wrapper.
This backend is intended for independent validation and frozen baselines.
It is CPU-only and not differentiable. HEOS uses multifluid mixture
machinery with GERG-style reducing/departure functions but is not labeled
as the published GERG-2008 coefficient set. Exact GERG through REFPROP
requires a licensed REFPROP installation configured by the user.
Source code in src/torch_flash/backends/coolprop.py
16 17 18 19 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 118 119 120 121 122 123 | |
select_z
¶
Return CoolProp compressibility factor.
Source code in src/torch_flash/backends/coolprop.py
molar_volume
¶
Return CoolProp molar volume.
Source code in src/torch_flash/backends/coolprop.py
log_fugacity_coefficients
¶
Return CoolProp log fugacity coefficients.
Source code in src/torch_flash/backends/coolprop.py
TeqpBackend
¶
Wrap a teqp residual model as a homogeneous-state model.
teqp is deliberately optional and all values cross a CPU/NumPy boundary, so this adapter is for validation rather than differentiable production calculations. The GERG constructor uses the published hard-coded GERG-2008 residual coefficient set shipped by teqp.
Source code in src/torch_flash/backends/teqp.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 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 | |
canonical_peng_robinson
classmethod
¶
Construct teqp's canonical Peng-Robinson model.
Source code in src/torch_flash/backends/teqp.py
gerg2008
classmethod
¶
Construct teqp's exact GERG-2008 residual model.
Source code in src/torch_flash/backends/teqp.py
eoscg_2015
classmethod
¶
Construct the complete 2015 EOS-CG multifluid model shipped by teqp.
The six-component scope is CO2, water, nitrogen, oxygen, argon, and carbon monoxide. teqp loads the pure-fluid Helmholtz equations plus the Gernert--Span binary reducing and departure parameters from its versioned CoolProp-format data files.
Source code in src/torch_flash/backends/teqp.py
molar_volume
¶
Return a teqp molar-volume root in m3/mol.
Source code in src/torch_flash/backends/teqp.py
pressure
¶
Return pressure at a prescribed homogeneous density.
Source code in src/torch_flash/backends/teqp.py
select_z
¶
Return compressibility factor.
Source code in src/torch_flash/backends/teqp.py
log_fugacity_coefficients
¶
Return teqp residual-model fugacity coefficients.