@neutrium/thermo.eos.iapws97 2.0.2 → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/IAPWS97.ts CHANGED
@@ -1,39 +1,46 @@
1
- import {EquationOfState, State} from "@neutrium/thermo";
2
- import {solve as PT} from './PT';
3
- import {solve as PH} from './PH';
4
- import {solve as PS} from './PS';
5
- import {solve as HS} from './HS';
1
+ import { EquationOfState, State } from "@neutrium/thermo";
2
+ import { solve as PT } from './PT';
3
+ import { solve as PH } from './PH';
4
+ import { solve as PS } from './PS';
5
+ import { solve as HS } from './HS';
6
6
 
7
7
  export class IAPWS97_EoS extends EquationOfState
8
8
  {
9
- modes = [
10
- ['p','t'],
11
- ['p', 'h'],
12
- ['p', 's'],
13
- ['h', 's']
14
- ];
15
- name = "IAPWS97 formulations of the thermodynamic properties of water and steam";
9
+ modes = [
10
+ ['p','t'],
11
+ ['p', 'h'],
12
+ ['p', 's'],
13
+ ['h', 's']
14
+ ];
15
+ name = "IAPWS97 formulations of the thermodynamic properties of water and steam";
16
16
 
17
- public solve(inputs : any)
18
- {
19
- let mode = this.findModeIndex(inputs),
20
- r : State,
21
- p : number;
17
+ public solve(inputs : any) : State
18
+ {
19
+ let mode = this.findModeIndex(inputs),
20
+ r : State | null = null,
21
+ p : number | null = null;
22
22
 
23
- if (0 <= mode && mode <= 2)
24
- {
25
- p = inputs.p/1000000; // Convert Pa to MPa for the calculation
26
- }
23
+ if (0 <= mode && mode <= 2)
24
+ {
25
+ p = inputs.p/1000000; // Convert Pa to MPa for the calculation
26
+ }
27
27
 
28
- switch(mode)
29
- {
30
- case 0 : r = PT(p, inputs.t); break; // P-T mode
31
- case 1 : r = PH(p, inputs.h); break; // P-H mode
32
- case 2 : r = PS(p, inputs.s); break; // P-S mode
33
- case 3 : r = HS(inputs.h, inputs.s); break; // H-S mode
34
- default : throw new Error('Insufficent inputs provided.');
35
- }
28
+ if(p !== null)
29
+ {
30
+ switch(mode)
31
+ {
32
+ case 0 : r = PT(p, inputs.t); break; // P-T mode
33
+ case 1 : r = PH(p, inputs.h); break; // P-H mode
34
+ case 2 : r = PS(p, inputs.s); break; // P-S mode
35
+ case 3 : r = HS(inputs.h, inputs.s); break; // H-S mode
36
+ }
37
+ }
36
38
 
37
- return r;
38
- }
39
+ if (!r)
40
+ {
41
+ throw new Error('Failed to solve for the given inputs.');
42
+ }
43
+
44
+ return r;
45
+ }
39
46
  }