-
Notifications
You must be signed in to change notification settings - Fork 1
/
phase.js
46 lines (45 loc) · 1.16 KB
/
phase.js
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
/**
* Based on comparing the parameters to the critical constants
* return which phase the system is in
*
* @export
* @param {MolecularFluid} molecularFluid instance of the MolecularFluid class
* @param {Number} temperature in K
* @param {Numnber} pressure in bar
* @param {Number} volumen in L
* @returns {String} "supercritial", "gas", or "liquid" or null
*/
export function getPhase(molecularFluid, temperature, pressure, volume) {
let phase = null;
if (
(temperature > molecularFluid.criticalTemperature) &
(pressure > molecularFluid.criticalPressure)
) {
phase = 'supercritical';
} else {
if (molecularFluid.criticalVolume) {
if (volume > molecularFluid.criticalVolume) phase = 'gas';
} else {
phase = 'liquid';
}
}
return phase;
}
/**
* Comparing an array of fugacities to find out in which
* state the system is
* @export
* @param {Array<number>} phis An array of fugacities
* @returns {Number} Index of the state the system is in
*/
export function getPhasefromPhi(phis) {
if (phis.length === 1) {
return 0;
} else {
if (phis[1] < phis[0]) {
return 1;
} else {
return 0;
}
}
}