1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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
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
//! Core data structures shared across all VLE engine modules.
//!
//! These structs represent the fundamental objects in a VLE calculation:
//!
//! - **Component**: A single pure chemical substance with its thermodynamic properties
//! (critical point, acentric factor, heat capacity coefficients, etc.). Properties
//! come from databases like DIPPR or are fit to experimental data.
//!
//! - **Mixture**: A collection of components with their mole fractions, plus the
//! model selections (which EOS, activity model, mixing rule to use).
//!
//! - **Flow**: A process stream at specific T, P conditions with known phase
//! compositions. Represents the liquid, vapor, or feed stream in a flash calculation.
//!
//! - **Tolerances**: Convergence criteria for iterative calculations. Flash calculations
//! are solved by Newton-Raphson or successive substitution, and these thresholds
//! determine when the iteration has converged.
//!
//! - **ReferenceState**: The thermodynamic reference point for enthalpy and entropy.
//! H and S are always relative to a chosen reference — typically ideal gas at 298 K
//! and 101.325 kPa, or saturated liquid/vapor at a reference temperature.
//!
//! ## Field naming conventions
//!
//! Fields use standard thermodynamic notation where possible:
//! - `tc`, `pc`, `vc`, `zc` — critical temperature/pressure/volume/compressibility
//! - `omega` — acentric factor (ω), measures molecular non-sphericity
//! - `tb` — normal boiling point temperature
//! - `mw` — molecular weight (g/mol)
//! - `cp_coeffs` — ideal gas heat capacity polynomial coefficients
//!
//! ## Units
//!
//! All fields use the engine's canonical units (see lib.rs):
//! - Temperature: K | Pressure: kPa | Volume: cm³/mol | Energy: kJ/kmol
// `use` imports types from other modules so we can refer to them by
// their short name (e.g., `MixingRule`) instead of the full path
// (e.g., `crate::mixing::MixingRule`).
//
// `crate::` means "start from the root of this crate (library)".
// The curly braces `{LiquidModel, VaporModel}` import multiple
// types from the same module in a single line.
use crate;
use crateMixingRule;
use crateSatPressureModel;
/// Universal gas constant in **kJ/(kmol·K)**.
///
/// This value matches both legacy codebases and is used consistently
/// throughout all thermodynamic calculations.
pub const R_GAS: f64 = 8.31451;
/// Pure component thermodynamic properties.
///
/// Union of all fields from both legacy codebases:
/// - VB6: `clsCriticalProps.cls` + `clsOtherProps.cls` + `clsQbicsPure.cls`
/// - Pascal: `Registro` record type in `TERMOI.PAS`
///
/// Not all fields are needed for every calculation. For example, `dipole_moment`
/// and `solubility_param` are only used by polar-capable EOS variants and the
/// Scatchard-Hildebrand activity model, respectively.
// Auto-implement Debug and Clone for this struct:
// Debug — allows printing with {:?} for debugging (e.g., println!("{:?}", comp))
// Clone — allows creating a deep copy via .clone()
// Note: unlike the enums (which also derive Copy), structs containing
// heap-allocated data like String cannot derive Copy — they must use
// .clone() explicitly to make a copy.
// `impl Default for Component` provides a default constructor, so you
// can create a Component with all fields set to zero/empty by calling
// `Component::default()`. This is Rust's standard trait for "give me a
// blank instance". We implement it manually here (instead of using
// #[derive(Default)]) because the result is the same but being explicit
// makes the initial values clear. `Self` is shorthand for `Component`.
/// A multicomponent mixture with model selections.
///
/// Groups a set of components with their mole fractions and the user's choice
/// of thermodynamic models. Also stores binary interaction parameters (kij for
/// EOS mixing rules, Aij for activity models).
///
/// Maps to VB6 `clsAllProps.cls` + model selection fields from `clsLVE.cls`.
/// A process stream at specified conditions.
///
/// Represents a liquid, vapor, or feed stream in a flash calculation.
/// After a flash converges, the liquid and vapor Flow objects contain the
/// equilibrium compositions and thermodynamic properties of each phase.
///
/// Maps to VB6 `clsFlow.cls` (LiquidFlow, VaporFlow, FeedFlow in `clsLVE.cls`).
/// Convergence tolerances for iterative VLE calculations.
///
/// Flash calculations use Newton-Raphson or successive substitution to solve
/// the equilibrium equations. These tolerances define when the iteration has
/// converged. Defaults match the VB6 `clsTolerances.cls` values.
/// Thermodynamic reference state for enthalpy and entropy calculations.
///
/// Enthalpy (H) and entropy (S) are always relative to a chosen reference point.
/// The three standard choices are:
/// - **Saturated liquid** at reference T, P — common in chemical engineering
/// - **Saturated vapor** at reference T, P
/// - **Ideal gas** at reference T, P — the most fundamental reference
///
/// Maps to VB6 `clsReferencesSt.cls`.
/// Phase choice for the thermodynamic reference state.
///
/// Maps to VB6 `TADiPRefSt` enum in `clsReferencesSt.cls`.
/// Liquid molar volume model selection.
///
/// Used when the activity coefficient approach needs liquid volumes (e.g., Wilson
/// model, Scatchard-Hildebrand). Maps to VB6 `TADiPvlModel` enum.
/// Type of VLE flash calculation.
///
/// Maps to VB6 `TypeCalculation` enum in `clsLVE.cls`.
/// Dimensionless vs. dimensional flag for thermodynamic properties.
///
/// Some internal calculations work with dimensionless residual properties
/// (HR/RT, SR/R) while the final API returns dimensional values.
/// Maps to VB6 `TADiPdim` enum.