@dnv-plant/typescriptpws 1.0.70 → 1.0.73-alpha.1902013

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.
Files changed (215) hide show
  1. package/index.ts +2 -2
  2. package/jest.config.js +5 -0
  3. package/package.json +6 -6
  4. package/src/calculations/applicationTools.ts +2 -2
  5. package/src/calculations/discharge.ts +2 -2
  6. package/src/calculations/dispersion.ts +2 -2
  7. package/src/calculations/dispersionView.ts +2 -2
  8. package/src/calculations/fireball.ts +2 -2
  9. package/src/calculations/jetFire.ts +2 -2
  10. package/src/calculations/lateExplosion.ts +2 -2
  11. package/src/calculations/linkedRunners.ts +2 -2
  12. package/src/calculations/poolFire.ts +2 -2
  13. package/src/calculations/properties.ts +2 -2
  14. package/src/calculations/radiation.ts +2 -2
  15. package/src/calculations/standalones.ts +2 -2
  16. package/src/calculations/toxics.ts +2 -2
  17. package/src/calculations/utilities.ts +2 -2
  18. package/src/constants.ts +2 -2
  19. package/src/entities.ts +2 -2
  20. package/src/entity-schemas.ts +2 -2
  21. package/src/enums.ts +2 -2
  22. package/src/materials.ts +14 -14
  23. package/src/utilities.ts +2 -2
  24. package/tests/concentration-at-point-calculation/testCase116.test.ts +146 -0
  25. package/tests/concentration-at-point-calculation/testCase117.test.ts +142 -0
  26. package/tests/concentration-at-point-calculation/testCase118.test.ts +143 -0
  27. package/tests/concentration-at-point-calculation/testCase119.test.ts +149 -0
  28. package/tests/concentration-at-point-calculation/testCase120.test.ts +155 -0
  29. package/tests/constants/testConstants.test.ts +23 -0
  30. package/tests/convert-comp-mass-to-mole-calculation/testCase129.test.ts +74 -0
  31. package/tests/convert-comp-mass-to-mole-calculation/testCase130.test.ts +73 -0
  32. package/tests/convert-comp-mass-to-mole-calculation/testCase131.test.ts +73 -0
  33. package/tests/convert-comp-mass-to-mole-calculation/testCase132.test.ts +73 -0
  34. package/tests/convert-comp-mass-to-mole-calculation/testCase133.test.ts +73 -0
  35. package/tests/convert-comp-mole-to-mass-calculation/testCase134.test.ts +72 -0
  36. package/tests/convert-comp-mole-to-mass-calculation/testCase135.test.ts +72 -0
  37. package/tests/convert-comp-mole-to-mass-calculation/testCase136.test.ts +72 -0
  38. package/tests/convert-comp-mole-to-mass-calculation/testCase137.test.ts +72 -0
  39. package/tests/convert-comp-mole-to-mass-calculation/testCase138.test.ts +72 -0
  40. package/tests/distances-and-ellipses-to-radiation-levels-calculation/testCase64.test.ts +194 -0
  41. package/tests/distances-and-ellipses-to-radiation-levels-calculation/testCase65.test.ts +197 -0
  42. package/tests/distances-and-ellipses-to-radiation-levels-calculation/testCase66.test.ts +194 -0
  43. package/tests/distances-and-ellipses-to-radiation-levels-calculation/testCase67.test.ts +198 -0
  44. package/tests/distances-and-ellipses-to-radiation-levels-calculation/testCase68.test.ts +178 -0
  45. package/tests/distances-and-footprints-to-concentration-levels-calculation/testCase31a.test.ts +158 -0
  46. package/tests/distances-and-footprints-to-concentration-levels-calculation/testCase32a.test.ts +156 -0
  47. package/tests/distances-and-footprints-to-concentration-levels-calculation/testCase33a.test.ts +158 -0
  48. package/tests/distances-and-footprints-to-concentration-levels-calculation/testCase34a.test.ts +165 -0
  49. package/tests/distances-and-footprints-to-concentration-levels-calculation/testCase35a.test.ts +188 -0
  50. package/tests/distances-to-conc-levels-calculation/testCase121.test.ts +149 -0
  51. package/tests/distances-to-conc-levels-calculation/testCase122.test.ts +145 -0
  52. package/tests/distances-to-conc-levels-calculation/testCase123.test.ts +150 -0
  53. package/tests/distances-to-conc-levels-calculation/testCase124.test.ts +154 -0
  54. package/tests/distances-to-conc-levels-calculation/testCase125.test.ts +157 -0
  55. package/tests/entities/testVessel.test.ts +49 -0
  56. package/tests/fireball-calculation/testCase89.test.ts +151 -0
  57. package/tests/fireball-calculation/testCase90.test.ts +153 -0
  58. package/tests/fireball-calculation/testCase91.test.ts +152 -0
  59. package/tests/fireball-calculation/testCse92.test.ts +150 -0
  60. package/tests/flash-calculation/testCase26.test.ts +71 -0
  61. package/tests/flash-calculation/testCase27.test.ts +69 -0
  62. package/tests/flash-calculation/testCase28.test.ts +69 -0
  63. package/tests/flash-calculation/testCase29.test.ts +67 -0
  64. package/tests/flash-calculation/testCase30.test.ts +70 -0
  65. package/tests/general/operation-id-demo.test.ts +64 -0
  66. package/tests/get-component-by-id/get-component-by-id-METHANE.test.ts +35 -0
  67. package/tests/get-mass-from-vessel-calculation/testCase139.test.ts +65 -0
  68. package/tests/jet-fire-calculation/testCase36.test.ts +141 -0
  69. package/tests/jet-fire-calculation/testCase37.test.ts +148 -0
  70. package/tests/jet-fire-calculation/testCase38.test.ts +147 -0
  71. package/tests/jet-fire-calculation/testCase39.test.ts +146 -0
  72. package/tests/jet-fire-calculation/testCase40.test.ts +152 -0
  73. package/tests/late-explosion-calculation/testCase46.test.ts +157 -0
  74. package/tests/late-explosion-calculation/testCase47.test.ts +149 -0
  75. package/tests/late-explosion-calculation/testCase48.test.ts +176 -0
  76. package/tests/late-explosion-calculation/testCase49.test.ts +178 -0
  77. package/tests/late-explosion-calculation/testCase50.test.ts +176 -0
  78. package/tests/late-explosion-calculation/testCase74.test.ts +166 -0
  79. package/tests/late-explosion-calculation/testCase75.test.ts +163 -0
  80. package/tests/late-explosion-calculation/testCase76.test.ts +174 -0
  81. package/tests/late-explosion-calculation/testCase77.test.ts +175 -0
  82. package/tests/late-explosion-calculation/testCase78.test.ts +175 -0
  83. package/tests/lethality-distance-calculation/testCase60.test.ts +142 -0
  84. package/tests/linked-runners/user-defined-source-linked-run/test-uds-153.test.ts +121 -0
  85. package/tests/linked-runners/user-defined-source-linked-run/test-uds-154.test.ts +167 -0
  86. package/tests/linked-runners/user-defined-source-linked-run/test-uds-155.test.ts +202 -0
  87. package/tests/linked-runners/user-defined-source-linked-run/test-uds-156.test.ts +201 -0
  88. package/tests/linked-runners/vessel-leak-linked-run/test-vl-157.test.ts +182 -0
  89. package/tests/linked-runners/vessel-leak-linked-run/test-vl-158.test.ts +200 -0
  90. package/tests/linked-runners/vessel-leak-linked-run/test-vl-159.test.ts +158 -0
  91. package/tests/linked-runners/vessel-leak-linked-run/test-vl-160.test.ts +165 -0
  92. package/tests/linked-runners/vessel-line-rupture-linked-run/test-vlr-161.test.ts +161 -0
  93. package/tests/linked-runners/vessel-line-rupture-linked-run/test-vlr-162.test.ts +167 -0
  94. package/tests/linked-runners/vessel-line-rupture-linked-run/test-vlr-163.test.ts +177 -0
  95. package/tests/linked-runners/vessel-line-rupture-linked-run/test-vlr-164.test.ts +165 -0
  96. package/tests/linked-runners/vessel-relief-valve-linked-run/test-vrv-165.test.ts +166 -0
  97. package/tests/linked-runners/vessel-relief-valve-linked-run/test-vrv-166.test.ts +154 -0
  98. package/tests/linked-runners/vessel-relief-valve-linked-run/test-vrv-167.test.ts +157 -0
  99. package/tests/linked-runners/vessel-relief-valve-linked-run/test-vrv-168.test.ts +168 -0
  100. package/tests/load-mass-inventory-vessel-for-line-rupture-scenario-calculation/testCase126.test.ts +72 -0
  101. package/tests/load-mass-inventory-vessel-for-line-rupture-scenario-calculation/testCase127.test.ts +73 -0
  102. package/tests/load-mass-inventory-vessel-for-line-rupture-scenario-calculation/testCase128.test.ts +72 -0
  103. package/tests/load-mass-inventory-vessel-for-relief-valve-scenario-calculation/testCase103.test.ts +74 -0
  104. package/tests/load-mass-inventory-vessel-for-relief-valve-scenario-calculation/testCase104.test.ts +75 -0
  105. package/tests/load-mass-inventory-vessel-for-relief-valve-scenario-calculation/testCase105.test.ts +74 -0
  106. package/tests/long-pipe-calculation/testCase55.test.ts +88 -0
  107. package/tests/long-pipe-calculation/testCase56.test.ts +90 -0
  108. package/tests/long-pipe-calculation/testCase57.test.ts +88 -0
  109. package/tests/long-pipe-calculation/testCase58.test.ts +88 -0
  110. package/tests/long-pipe-calculation/testCase59.test.ts +88 -0
  111. package/tests/materials/test-get-component-by-cas-id-1-2-PROPYLENE-OXIDE.test.ts +23 -0
  112. package/tests/materials/test-get-component-by-cas-id-CARBON-MONOXIDE.test.ts +25 -0
  113. package/tests/materials/test-get-component-by-cas-id-METHANE.test.ts +22 -0
  114. package/tests/materials/test-get-component-by-id-1-2-PROPYLENE-OXIDE.test.ts +23 -0
  115. package/tests/materials/test-get-component-by-id-CARBON-MONOXIDE.test.ts +22 -0
  116. package/tests/materials/test-get-component-by-id-METHANE.test.ts +22 -0
  117. package/tests/materials/test-get-component-by-name-1-2-PROPYLENE-OXIDE.test.ts +24 -0
  118. package/tests/materials/test-get-component-by-name-CARBON-MONOXIDE.test.ts +23 -0
  119. package/tests/materials/test-get-component-by-name-METHANE.test.ts +25 -0
  120. package/tests/materials/test-get-components.test.ts +47 -0
  121. package/tests/materials/test-get-dippr-components.test.ts +28 -0
  122. package/tests/materials/test-get-dnv-components.test.ts +28 -0
  123. package/tests/materials/test-get-material-by-cas-id-1-2-PROPYLENE-OXIDE.test.ts +29 -0
  124. package/tests/materials/test-get-material-by-cas-id-CARBON-MONOXIDE.test.ts +31 -0
  125. package/tests/materials/test-get-material-by-cas-id-METHANE.test.ts +30 -0
  126. package/tests/materials/test-get-material-by-cas-id-ZERO.test.ts +31 -0
  127. package/tests/materials/test-get-material-by-id-1-2-PROPYLENE-OXIDE.test.ts +30 -0
  128. package/tests/materials/test-get-material-by-id-CARBON-MONOXIDE.test.ts +29 -0
  129. package/tests/materials/test-get-material-by-id-METHANE.test.ts +29 -0
  130. package/tests/materials/test-get-material-by-name-1-2-PROPYLENE-OXIDE.test.ts +29 -0
  131. package/tests/materials/test-get-material-by-name-CARBON-MONOXIDE.test.ts +29 -0
  132. package/tests/materials/test-get-material-by-name-METHANE.test.ts +29 -0
  133. package/tests/materials/test-get-materials.test.ts +32 -0
  134. package/tests/max-conc-distance-calculation/testCase106.test.ts +146 -0
  135. package/tests/max-conc-distance-calculation/testCase107.test.ts +148 -0
  136. package/tests/max-conc-distance-calculation/testCase108.test.ts +172 -0
  137. package/tests/max-conc-distance-calculation/testCase109.test.ts +146 -0
  138. package/tests/max-conc-distance-calculation/testCase110.test.ts +146 -0
  139. package/tests/max-conc-footprint-calculation/testCase31.test.ts +169 -0
  140. package/tests/max-conc-footprint-calculation/testCase32.test.ts +183 -0
  141. package/tests/max-conc-footprint-calculation/testCase33.test.ts +161 -0
  142. package/tests/max-conc-footprint-calculation/testCase34.test.ts +172 -0
  143. package/tests/max-conc-footprint-calculation/testCase35.test.ts +188 -0
  144. package/tests/max-distance-to-conc-calculation/testCase111.test.ts +138 -0
  145. package/tests/max-distance-to-conc-calculation/testCase112.test.ts +174 -0
  146. package/tests/max-distance-to-conc-calculation/testCase113.test.ts +153 -0
  147. package/tests/max-distance-to-conc-calculation/testCase114.test.ts +162 -0
  148. package/tests/max-distance-to-conc-calculation/testCase115.test.ts +167 -0
  149. package/tests/mixture-constant-properties-calculation/testCase97.test.ts +83 -0
  150. package/tests/mixture-constant-properties-calculation/testCase98.test.ts +90 -0
  151. package/tests/mixture-constant-properties-calculation/testCase99.test.ts +87 -0
  152. package/tests/pool-fire-calculation/testCase41.test.ts +153 -0
  153. package/tests/pool-fire-calculation/testCase41a.test.ts +141 -0
  154. package/tests/pool-fire-calculation/testCase42.test.ts +169 -0
  155. package/tests/pool-fire-calculation/testCase42a.test.ts +175 -0
  156. package/tests/pool-fire-calculation/testCase43.test.ts +161 -0
  157. package/tests/pool-fire-calculation/testCase43a.test.ts +157 -0
  158. package/tests/pool-fire-calculation/testCase44.test.ts +147 -0
  159. package/tests/pool-fire-calculation/testCase44a.test.ts +152 -0
  160. package/tests/pool-fire-calculation/testCase45.test.ts +176 -0
  161. package/tests/pool-fire-calculation/testCase45a.test.ts +182 -0
  162. package/tests/radiation-at-ponts/testCase69.test.ts +167 -0
  163. package/tests/radiation-at-ponts/testCase70.test.ts +179 -0
  164. package/tests/radiation-at-ponts/testCase71.test.ts +150 -0
  165. package/tests/radiation-at-ponts/testCase72.test.ts +166 -0
  166. package/tests/radiation-at-ponts/testCase73.test.ts +169 -0
  167. package/tests/radiation-contour-calculation/testCase51.test.ts +127 -0
  168. package/tests/radiation-contour-calculation/testCase52.test.ts +126 -0
  169. package/tests/radiation-contour-calculation/testCase53.test.ts +126 -0
  170. package/tests/radiation-contour-calculation/testCase54.test.ts +131 -0
  171. package/tests/relief-valve-min-temperature-calculation/testCase140.test.ts +49 -0
  172. package/tests/set-mixing-layer-height/testCase100.test.ts +36 -0
  173. package/tests/set-mixing-layer-height/testCase101.test.ts +36 -0
  174. package/tests/set-mixing-layer-height/testCase102.test.ts +36 -0
  175. package/tests/set-phase-to-be-released-for-leak-calculation/testCase150.test.ts +67 -0
  176. package/tests/set-phase-to-be-released-for-line-rupture-calculation/testCase151.test.ts +67 -0
  177. package/tests/set-phase-to-be-released-for-relief-valve-calculation/TestCase152.test.ts +61 -0
  178. package/tests/sideview/testCase31b.test.ts +150 -0
  179. package/tests/sideview/testCase32b.test.ts +145 -0
  180. package/tests/sideview/testCase33b.test.ts +130 -0
  181. package/tests/sideview/testCase34b.test.ts +153 -0
  182. package/tests/sideview/testCase35b.test.ts +140 -0
  183. package/tests/tank-fire-calculation/testCase79.test.ts +61 -0
  184. package/tests/tank-fire-calculation/testCase80.test.ts +67 -0
  185. package/tests/tank-fire-calculation/testCase81.test.ts +68 -0
  186. package/tests/tank-fire-calculation/testCase82.test.ts +68 -0
  187. package/tests/tank-fire-calculation/testCase83.test.ts +73 -0
  188. package/tests/utilities/convert-camel-case-to-snake-case.test.ts +7 -0
  189. package/tests/utilities/convert-snake-case-to-camel-case.test.ts +7 -0
  190. package/tests/vessel-catastrophic-rupture-calculation/testCase1.test.ts +83 -0
  191. package/tests/vessel-catastrophic-rupture-calculation/testCase2.test.ts +82 -0
  192. package/tests/vessel-catastrophic-rupture-calculation/testCase3.test.ts +91 -0
  193. package/tests/vessel-catastrophic-rupture-calculation/testCase4.test.ts +85 -0
  194. package/tests/vessel-catastrophic-rupture-calculation/testCase5.test.ts +84 -0
  195. package/tests/vessel-leak-calculation/testCase10.test.ts +108 -0
  196. package/tests/vessel-leak-calculation/testCase6.test.ts +113 -0
  197. package/tests/vessel-leak-calculation/testCase7.test.ts +123 -0
  198. package/tests/vessel-leak-calculation/testCase8.test.ts +102 -0
  199. package/tests/vessel-leak-calculation/testCase9.test.ts +106 -0
  200. package/tests/vessel-line-rupture-calculation/vlr-ammonia.test.ts +84 -0
  201. package/tests/vessel-line-rupture-calculation/vlr-ethaneMethane.test.ts +82 -0
  202. package/tests/vessel-line-rupture-calculation/vlr-nDecane.test.ts +79 -0
  203. package/tests/vessel-line-rupture-calculation/vlr-oxygen.test.ts +77 -0
  204. package/tests/vessel-line-rupture-calculation/vlr-propane.test.ts +77 -0
  205. package/tests/vessel-relief-valve-calculation/vrv-chlorine.test.ts +99 -0
  206. package/tests/vessel-relief-valve-calculation/vrv-hydrogen.test.ts +96 -0
  207. package/tests/vessel-relief-valve-calculation/vrv-methane.test.ts +80 -0
  208. package/tests/vessel-relief-valve-calculation/vrv-methaneH2s.test.ts +86 -0
  209. package/tests/vessel-relief-valve-calculation/vrv-nitrogen.test.ts +80 -0
  210. package/tests/vessel-state-calculation/vs-ammonia.test.ts +56 -0
  211. package/tests/vessel-state-calculation/vs-butane.test.ts +57 -0
  212. package/tests/vessel-state-calculation/vs-chlorine.test.ts +56 -0
  213. package/tests/vessel-state-calculation/vs-methane.test.ts +57 -0
  214. package/tests/vessel-state-calculation/vs-naturalGas.test.ts +59 -0
  215. package/tests/vessel-state-calculation/vs-nitrogenPentane.test.ts +58 -0
@@ -0,0 +1,143 @@
1
+ import { VesselLeakCalculation, VesselStateCalculation } from "../../src/calculations/discharge";
2
+ import { ConcentrationAtPointCalculation } from "../../src/calculations/dispersionView";
3
+ import { DispersionCalculation } from "../../src/calculations/dispersion";
4
+ import { Bund, DischargeParameters, DispersionOutputConfig, DispersionParameters, Material, MaterialComponent, State, Substrate, Vessel, Weather, Leak } from "../../src/entities";
5
+ import { AtmosphericStabilityClass, ResultCode, SurfaceType, TimeVaryingOption, VesselShape, WindProfileFlag } from "../../src/enums";
6
+ import { setAccessToken } from "../../src/utilities";
7
+ const accessToken = process.env.PWS_ACCESS_TOKEN;
8
+
9
+ if (!accessToken) {
10
+ throw new Error("ACCESS_TOKEN environment variable is not set.");
11
+ }
12
+
13
+ setAccessToken(accessToken);
14
+
15
+ describe('Test Case 118', () => {
16
+ test('Concentration at point calculation for CARBON DIOXIDE (TOXIC)', async () => {
17
+
18
+ // Set the case properties
19
+ const materialName = 'CARBON DIOXIDE (TOXIC)';
20
+ const stateTemperature = 280.0;
21
+ const statePressure = 8.0e6;
22
+ const vesselShape = VesselShape.VESSEL_SPHERE;
23
+ const vesselDiameter = 5.0;
24
+ const leakHoleDiameter = 0.008;
25
+ const timeVaryingOption = TimeVaryingOption.INITIAL_RATE;
26
+ const leakHoleHeightFraction = 0.5;
27
+ const surfaceType = SurfaceType.WATER;
28
+ const surfaceRoughness = 0.01;
29
+ const windSpeed = 4.0;
30
+ const stabilityClass = AtmosphericStabilityClass.STABILITY_C;
31
+ const endPointConcentration = 0.0;
32
+ const windProfileFlag = WindProfileFlag.LOGARITHMIC_PROFILE;
33
+
34
+ // Define the initial state of the vessel
35
+ const state = new State({
36
+ temperature: stateTemperature,
37
+ pressure: statePressure,
38
+ liquidFraction: 0.0
39
+ });
40
+
41
+ // Define the material contained by the vessel
42
+ const material = new Material(
43
+ {
44
+ name: materialName,
45
+ components: [new MaterialComponent({name:materialName, moleFraction: 1.0})]
46
+ });
47
+
48
+ // Create a vessel state calculation using the material and state
49
+ const vesselStateCalculation = new VesselStateCalculation(material, state);
50
+ const vesselStateResultCode = await vesselStateCalculation.run();
51
+
52
+ // Check the result of vessel state calculation
53
+ expect(vesselStateResultCode).toBe(ResultCode.SUCCESS);
54
+ console.log(`SUCCESS: vessel_state_calculation (${vesselStateCalculation.calculationElapsedTime}ms)`);
55
+
56
+ // Create a vessel for the leak calculation using the previously defined entities
57
+ const vessel = new Vessel({
58
+ state: vesselStateCalculation.outputState!,
59
+ material: vesselStateCalculation.material,
60
+ vesselConditions: vesselStateCalculation.vesselConditions,
61
+ diameter: vesselDiameter,
62
+ shape: vesselShape,
63
+ liquidFillFractionByVolume: 0.8
64
+ });
65
+
66
+ // Create a leak for the vessel leak calculation
67
+ const leak = new Leak({
68
+ holeDiameter: leakHoleDiameter,
69
+ holeHeightFraction: leakHoleHeightFraction,
70
+ timeVaryingOption: timeVaryingOption
71
+ });
72
+
73
+ // Create discharge parameters for the leak calculation
74
+ const dischargeParameters = new DischargeParameters();
75
+
76
+ // Create a vessel leak calculation
77
+ const vesselLeakCalculation = new VesselLeakCalculation(vessel, leak, dischargeParameters);
78
+ const leakResultCode = await vesselLeakCalculation.run();
79
+
80
+ // Check the result of vessel leak calculation
81
+ expect(leakResultCode).toBe(ResultCode.SUCCESS);
82
+ console.log(`SUCCESS: vessel_leak_calculation (${vesselLeakCalculation.calculationElapsedTime}ms)`);
83
+
84
+ // Set up entities for the dispersion calculation
85
+ const substrate = new Substrate({
86
+ surfaceType: surfaceType,
87
+ surfaceRoughness: surfaceRoughness
88
+ });
89
+
90
+ const weather = new Weather({
91
+ windSpeed: windSpeed,
92
+ stabilityClass: stabilityClass,
93
+ windProfileFlag: windProfileFlag
94
+ });
95
+
96
+ const dispersionParameters = new DispersionParameters();
97
+
98
+ const dispersionCalculation = new DispersionCalculation(
99
+ vesselLeakCalculation.exitMaterial!,
100
+ substrate,
101
+ vesselLeakCalculation.dischargeResult!,
102
+ vesselLeakCalculation.dischargeRecords!,
103
+ vesselLeakCalculation.dischargeRecords!.length,
104
+ weather,
105
+ dispersionParameters,
106
+ endPointConcentration
107
+ );
108
+
109
+ const dispersionResultCode = await dispersionCalculation.run();
110
+
111
+ // Check the result of the dispersion calculation
112
+ expect(dispersionResultCode).toBe(ResultCode.SUCCESS);
113
+ console.log(`SUCCESS: dispersion_calculation (${dispersionCalculation.calculationElapsedTime}ms)`);
114
+ console.log(`Final centreline concentration = ${dispersionCalculation.dispersionRecords![dispersionCalculation.dispersionRecords!.length - 1].centrelineConcentration}`);
115
+ console.log(`Final downwind distance = ${dispersionCalculation.dispersionRecords![dispersionCalculation.dispersionRecords!.length - 1].downwindDistance}`);
116
+
117
+ // Set up the entities for the concentration at point calculation
118
+ const dispersionOutputConfig = new DispersionOutputConfig({
119
+ concentration: endPointConcentration,
120
+ downwindDistance: 10
121
+ });
122
+
123
+ const concentrationAtPointCalculation = new ConcentrationAtPointCalculation(
124
+ dispersionCalculation.scalarUdmOutputs!,
125
+ weather,
126
+ dispersionCalculation.dispersionRecords!,
127
+ dispersionCalculation.dispersionRecords!.length,
128
+ substrate,
129
+ dispersionOutputConfig,
130
+ vesselLeakCalculation.exitMaterial!,
131
+ dispersionParameters
132
+ );
133
+
134
+ const concentrationResultCode = await concentrationAtPointCalculation.run();
135
+
136
+ // Check the result of concentration at point calculation
137
+ expect(concentrationResultCode).toBe(ResultCode.SUCCESS);
138
+
139
+ const expectedConcentration = 0.0040424883934447944;
140
+ expect(Math.abs(concentrationAtPointCalculation.concentration! - expectedConcentration) / expectedConcentration).toBeLessThan(1e-3);
141
+ console.log(`SUCCESS: concentration_at_point_calculation (${concentrationAtPointCalculation.calculationElapsedTime}ms)`);
142
+ });
143
+ });
@@ -0,0 +1,149 @@
1
+ import { VesselLineRuptureCalculation, VesselStateCalculation } from "../../src/calculations/discharge";
2
+ import { ConcentrationAtPointCalculation } from "../../src/calculations/dispersionView";
3
+ import { DispersionCalculation } from "../../src/calculations/dispersion";
4
+ import { Bund, DischargeParameters, DispersionOutputConfig, DispersionParameters, Material, MaterialComponent, State, Substrate, Vessel, Weather, LineRupture } from "../../src/entities";
5
+ import { AtmosphericStabilityClass, ResultCode, SurfaceType, VesselShape, WindProfileFlag } from "../../src/enums";
6
+ import { setAccessToken } from "../../src/utilities";
7
+
8
+ const accessToken = process.env.PWS_ACCESS_TOKEN;
9
+
10
+ if (!accessToken) {
11
+ throw new Error("ACCESS_TOKEN environment variable is not set.");
12
+ }
13
+
14
+ setAccessToken(accessToken);
15
+
16
+ describe('Test Case 119', () => {
17
+ test('Concentration at point calculation for AMMONIA', async () => {
18
+
19
+ // Set the case properties
20
+ const materialName = 'AMMONIA';
21
+ const stateTemperature = 290.0;
22
+ const statePressure = 7.0e6;
23
+ const stateLiquidFraction = 1.0;
24
+ const surfaceType = SurfaceType.LAND;
25
+ const surfaceRoughness = 0.183;
26
+ const windSpeed = 1.5;
27
+ const stabilityClass = AtmosphericStabilityClass.STABILITY_D;
28
+ const endPointConcentration = 0.0;
29
+ const specifyBund = true;
30
+ const bundHeight = 0.5;
31
+ const bundDiameter = 5.0;
32
+ const windProfileFlag = WindProfileFlag.LOGARITHMIC_PROFILE;
33
+
34
+ // Define the initial state of the vessel
35
+ const state = new State({
36
+ temperature: stateTemperature,
37
+ pressure: statePressure,
38
+ liquidFraction: stateLiquidFraction
39
+ });
40
+
41
+ // Define the material contained by the vessel
42
+ const material = new Material(
43
+ {
44
+ name: materialName,
45
+ components: [new MaterialComponent({name:materialName, moleFraction: 1.0})]
46
+ });
47
+
48
+ // Create a vessel state calculation using the material and state
49
+ const vesselStateCalculation = new VesselStateCalculation(material, state);
50
+ const vesselStateResultCode = await vesselStateCalculation.run();
51
+
52
+ // Check the result of vessel state calculation
53
+ expect(vesselStateResultCode).toBe(ResultCode.SUCCESS);
54
+ console.log(`SUCCESS: vessel_state_calculation (${vesselStateCalculation.calculationElapsedTime}ms)`);
55
+
56
+ // Create a vessel for the line rupture calculation using the previously defined entities
57
+ const vessel = new Vessel({
58
+ state: vesselStateCalculation.outputState!,
59
+ material: vesselStateCalculation.material,
60
+ vesselConditions: vesselStateCalculation.vesselConditions,
61
+ liquidFillFractionByVolume: 0.7,
62
+ shape: VesselShape.VESSEL_CUBOID,
63
+ height: 2.0,
64
+ width: 1.0,
65
+ length: 3.0
66
+ });
67
+
68
+ // Create a line rupture for the vessel line rupture calculation
69
+ const lineRupture = new LineRupture({
70
+ pipeDiameter: 0.1,
71
+ pipeLength: 1.0,
72
+ pipeHeightFraction: 0.1
73
+ });
74
+
75
+ // Create a vessel line rupture calculation
76
+ const vesselLineRuptureCalculation = new VesselLineRuptureCalculation(vessel, lineRupture, new DischargeParameters());
77
+ const lineRuptureResultCode = await vesselLineRuptureCalculation.run();
78
+
79
+ // Check the result of vessel line rupture calculation
80
+ expect(lineRuptureResultCode).toBe(ResultCode.SUCCESS);
81
+ console.log(`SUCCESS: vessel_line_rupture_calculation (${vesselLineRuptureCalculation.calculationElapsedTime}ms)`);
82
+
83
+ // Set up entities for the dispersion calculation
84
+ const bund = new Bund({
85
+ specifyBund: specifyBund,
86
+ bundHeight: bundHeight,
87
+ bundDiameter: bundDiameter
88
+ });
89
+
90
+ const substrate = new Substrate({
91
+ bund: bund,
92
+ surfaceType: surfaceType,
93
+ surfaceRoughness: surfaceRoughness
94
+ });
95
+
96
+ const weather = new Weather({
97
+ windSpeed: windSpeed,
98
+ stabilityClass: stabilityClass,
99
+ windProfileFlag: windProfileFlag
100
+ });
101
+
102
+ const dispersionParameters = new DispersionParameters();
103
+
104
+ const dispersionCalculation = new DispersionCalculation(
105
+ vesselLineRuptureCalculation.exitMaterial!,
106
+ substrate,
107
+ vesselLineRuptureCalculation.dischargeResult!,
108
+ vesselLineRuptureCalculation.dischargeRecords!,
109
+ vesselLineRuptureCalculation.dischargeRecords!.length,
110
+ weather,
111
+ dispersionParameters,
112
+ endPointConcentration
113
+ );
114
+
115
+ const dispersionResultCode = await dispersionCalculation.run();
116
+
117
+ // Check the result of dispersion calculation
118
+ expect(dispersionResultCode).toBe(ResultCode.SUCCESS);
119
+ console.log(`SUCCESS: dispersion_calculation (${dispersionCalculation.calculationElapsedTime}ms)`);
120
+
121
+ // Set up the entities for the concentration at point calculation
122
+ const dispersionOutputConfig = new DispersionOutputConfig({
123
+ concentration: endPointConcentration,
124
+ downwindDistance: 140,
125
+ time: 5,
126
+ elevation: 1
127
+ });
128
+
129
+ const concentrationAtPointCalculation = new ConcentrationAtPointCalculation(
130
+ dispersionCalculation.scalarUdmOutputs!,
131
+ weather,
132
+ dispersionCalculation.dispersionRecords!,
133
+ dispersionCalculation.dispersionRecords!.length,
134
+ substrate,
135
+ dispersionOutputConfig,
136
+ vesselLineRuptureCalculation.exitMaterial!,
137
+ dispersionParameters
138
+ );
139
+
140
+ const concentrationResultCode = await concentrationAtPointCalculation.run();
141
+
142
+ // Check the result of concentration at point calculation
143
+ expect(concentrationResultCode).toBe(ResultCode.SUCCESS);
144
+
145
+ const expectedConcentration = 2.593311923058257e-08;
146
+ expect(Math.abs(concentrationAtPointCalculation.concentration! - expectedConcentration) / expectedConcentration).toBeLessThan(1e-3);
147
+ console.log(`SUCCESS: concentration_at_point_calculation (${concentrationAtPointCalculation.calculationElapsedTime}ms)`);
148
+ });
149
+ });
@@ -0,0 +1,155 @@
1
+ import { VesselStateCalculation, VesselReliefValveCalculation} from "../../src/calculations/discharge";
2
+ import { ConcentrationAtPointCalculation } from "../../src/calculations/dispersionView";
3
+ import { DispersionCalculation } from "../../src/calculations/dispersion";
4
+ import { Material, MaterialComponent, State, ReliefValve, Vessel, Substrate, Bund, Weather, DispersionOutputConfig, DischargeParameters, DispersionParameters } from "../../src/entities";
5
+ import { AtmosphericStabilityClass, ResultCode, SurfaceType, VesselShape, WindProfileFlag } from "../../src/enums";
6
+ import { setAccessToken } from "../../src/utilities";
7
+
8
+ const accessToken = process.env.PWS_ACCESS_TOKEN;
9
+
10
+ if (!accessToken) {
11
+ throw new Error("ACCESS_TOKEN environment variable is not set.");
12
+ }
13
+
14
+ setAccessToken(accessToken);
15
+
16
+ describe('Test Case 120', () => {
17
+ test('Concentration at point calculation for CHLORINE', async () => {
18
+
19
+ // Set the case properties
20
+ const materialName = 'CHLORINE';
21
+ const stateTemperature = 320.0;
22
+ const statePressure = 1.0E+06;
23
+ const stateLiquidFraction = 1.0;
24
+ const vesselShape = VesselShape.HORIZONTAL_CYLINDER;
25
+ const vesselDiameter = 2.0;
26
+ const vesselLength = 5.0;
27
+ const liquidFillFractionByVolume = 0.7;
28
+ const reliefValvePipeDiameter = 0.02;
29
+ const reliefValvePipeLength = 10.0;
30
+ const reliefValvePipeHeightFraction = 1;
31
+ const reliefValveConstrictionDiameter = 0.02;
32
+ const surfaceType = SurfaceType.LAND;
33
+ const surfaceRoughness = 0.183;
34
+ const windSpeed = 1.5;
35
+ const stabilityClass = AtmosphericStabilityClass.STABILITY_D;
36
+ const endPointConcentration = 0.0;
37
+ const specifyBund = true;
38
+ const bundHeight = 0.5;
39
+ const bundDiameter = 5.0;
40
+ const windProfileFlag = WindProfileFlag.LOGARITHMIC_PROFILE;
41
+
42
+ // Define the initial state of the vessel
43
+ const state = new State({
44
+ temperature: stateTemperature,
45
+ pressure: statePressure,
46
+ liquidFraction: stateLiquidFraction
47
+ });
48
+
49
+ // Define the material contained by the vessel
50
+ const material = new Material(
51
+ {
52
+ name: materialName,
53
+ components: [new MaterialComponent({name:materialName, moleFraction: 1.0})]
54
+ });
55
+
56
+ // Create a vessel state calculation using the material and state
57
+ const vesselStateCalculation = new VesselStateCalculation(material, state);
58
+ const vesselStateResultCode = await vesselStateCalculation.run();
59
+
60
+ // Check the result of vessel state calculation
61
+ expect(vesselStateResultCode).toBe(ResultCode.SUCCESS);
62
+ console.log(`SUCCESS: vessel_state_calculation (${vesselStateCalculation.calculationElapsedTime}ms)`);
63
+
64
+ // Create a vessel for the relief valve calculation using the previously defined entities
65
+ const vessel = new Vessel({
66
+ state: vesselStateCalculation.outputState!,
67
+ material: vesselStateCalculation.material,
68
+ vesselConditions: vesselStateCalculation.vesselConditions,
69
+ liquidFillFractionByVolume: liquidFillFractionByVolume,
70
+ shape: vesselShape,
71
+ diameter: vesselDiameter,
72
+ length: vesselLength
73
+ });
74
+
75
+ // Create a relief valve for the vessel relief valve calculation
76
+ const reliefValve = new ReliefValve({
77
+ pipeDiameter: reliefValvePipeDiameter,
78
+ pipeLength: reliefValvePipeLength,
79
+ pipeHeightFraction: reliefValvePipeHeightFraction,
80
+ reliefValveConstrictionDiameter: reliefValveConstrictionDiameter
81
+ });
82
+
83
+ // Create a vessel relief valve calculation
84
+ const vesselReliefValveCalculation = new VesselReliefValveCalculation(vessel, reliefValve, new DischargeParameters());
85
+ const reliefValveResultCode = await vesselReliefValveCalculation.run();
86
+
87
+ // Check the result of vessel relief valve calculation
88
+ expect(reliefValveResultCode).toBe(ResultCode.SUCCESS);
89
+ console.log(`SUCCESS: vessel_relief_valve_calculation (${vesselReliefValveCalculation.calculationElapsedTime}ms)`);
90
+ console.log(`vessel_relief_valve_calculation.discharge_result.release_mass: ${vesselReliefValveCalculation.dischargeResult?.releaseMass} [kg]`);
91
+
92
+ // Set up entities for the dispersion calculation
93
+ const bund = new Bund({
94
+ specifyBund: specifyBund,
95
+ bundHeight: bundHeight,
96
+ bundDiameter: bundDiameter
97
+ });
98
+
99
+ const substrate = new Substrate({
100
+ bund: bund,
101
+ surfaceType: surfaceType,
102
+ surfaceRoughness: surfaceRoughness
103
+ });
104
+
105
+ const weather = new Weather({
106
+ windSpeed: windSpeed,
107
+ stabilityClass: stabilityClass,
108
+ windProfileFlag: windProfileFlag
109
+ });
110
+
111
+ const dispersionParameters = new DispersionParameters();
112
+
113
+ const dispersionCalculation = new DispersionCalculation(
114
+ vesselReliefValveCalculation.exitMaterial!,
115
+ substrate,
116
+ vesselReliefValveCalculation.dischargeResult!,
117
+ vesselReliefValveCalculation.dischargeRecords!,
118
+ vesselReliefValveCalculation.dischargeRecords!.length,
119
+ weather,
120
+ dispersionParameters,
121
+ endPointConcentration
122
+ );
123
+
124
+ const dispersionResultCode = await dispersionCalculation.run();
125
+
126
+ // Check the result of dispersion calculation
127
+ expect(dispersionResultCode).toBe(ResultCode.SUCCESS);
128
+ console.log(`SUCCESS: dispersion_calculation (${dispersionCalculation.calculationElapsedTime}ms)`);
129
+
130
+ // Set up entities for the concentration at point calculation
131
+ const dispersionOutputConfig = new DispersionOutputConfig({
132
+ concentration: endPointConcentration
133
+ });
134
+
135
+ const concentrationAtPointCalculation = new ConcentrationAtPointCalculation(
136
+ dispersionCalculation.scalarUdmOutputs!,
137
+ weather,
138
+ dispersionCalculation.dispersionRecords!,
139
+ dispersionCalculation.dispersionRecords!.length,
140
+ substrate,
141
+ dispersionOutputConfig,
142
+ vesselReliefValveCalculation.exitMaterial!,
143
+ dispersionParameters
144
+ );
145
+
146
+ const concentrationResultCode = await concentrationAtPointCalculation.run();
147
+
148
+ // Check the result of concentration at point calculation
149
+ expect(concentrationResultCode).toBe(ResultCode.SUCCESS);
150
+
151
+ const expectedConcentration = 0.0005274004825735066;
152
+ expect(Math.abs(concentrationAtPointCalculation.concentration! - expectedConcentration) / expectedConcentration).toBeLessThan(1e-3);
153
+ console.log(`SUCCESS: concentration_at_point_calculation (${concentrationAtPointCalculation.calculationElapsedTime}ms)`);
154
+ });
155
+ });
@@ -0,0 +1,23 @@
1
+ import { PWS_CLIENT_ID, REST_API_URI } from "../../src/constants"; // Adjust the import path as needed
2
+ import { setAccessToken } from "../../src/utilities";
3
+ const accessToken = process.env.PWS_ACCESS_TOKEN;
4
+
5
+ if (!accessToken) {
6
+ throw new Error("ACCESS_TOKEN environment variable is not set.");
7
+ }
8
+
9
+ setAccessToken(accessToken);
10
+
11
+ describe("Test Constants", () => {
12
+ // Mock environment variable for local run simulation
13
+
14
+
15
+ test("should verify PWS_CLIENT_ID", () => {
16
+ expect(PWS_CLIENT_ID).toBe("eeca6885-127e-4405-aa1f-3a8e69acc451");
17
+ });
18
+
19
+ test("should verify REST_API_URI", () => {
20
+ console.log("Running test_analytics_rest_api_uri");
21
+ expect(REST_API_URI).toBe("https://plantwebservices.dnv.com/api/");
22
+ });
23
+ });
@@ -0,0 +1,74 @@
1
+ import { ConvertCompositionMassToMoleCalculation } from "../../src/calculations/utilities";
2
+ import { Material, MaterialComponent } from "../../src/entities";
3
+ import { ResultCode } from "../../src/enums";
4
+ import { setAccessToken } from "../../src/utilities";
5
+ const accessToken = process.env.PWS_ACCESS_TOKEN;
6
+
7
+ if (!accessToken) {
8
+ throw new Error("ACCESS_TOKEN environment variable is not set.");
9
+ }
10
+
11
+ setAccessToken(accessToken);
12
+
13
+ describe('Test Case 129', () => {
14
+ test('Convert composition mass to mole calculation for ETHANE, BUTANE, and PROPANE', async () => {
15
+
16
+ // Define the test case properties
17
+ const materialName = 'ETHANE_BUTANE_PROPANE';
18
+ const compositionMass = [0.3, 0.5, 0.2];
19
+
20
+ // Define the material
21
+ const material = new Material({
22
+ name: materialName,
23
+ components: [
24
+ new MaterialComponent({ name: 'ETHANE', moleFraction: 0.3 }),
25
+ new MaterialComponent({ name: 'N-BUTANE', moleFraction: 0.5 }),
26
+ new MaterialComponent({ name: 'PROPANE', moleFraction: 0.2 })
27
+ ],
28
+ componentCount: 3
29
+ });
30
+
31
+ // Create a ConvertCompositionMassToMoleCalculation using the material and composition mass
32
+ const convertCompMassToMoleCalculation = new ConvertCompositionMassToMoleCalculation(
33
+ material,
34
+ compositionMass,
35
+ compositionMass.length
36
+ );
37
+
38
+ // Run the ConvertCompositionMassToMoleCalculation
39
+ console.log('Running convertCompMassToMoleCalculation...');
40
+ const resultCode = await convertCompMassToMoleCalculation.run();
41
+
42
+ // Print any messages
43
+ if (convertCompMassToMoleCalculation.messages.length > 0) {
44
+ console.log('Messages:');
45
+ convertCompMassToMoleCalculation.messages.forEach((message) => {
46
+ console.log(message);
47
+ });
48
+ }
49
+ expect(resultCode).toBe(ResultCode.SUCCESS);
50
+
51
+ // Log mole and mass fractions
52
+ console.log(`Mole fraction: ${convertCompMassToMoleCalculation.compositionMole}`);
53
+ console.log(`Mass fraction: ${convertCompMassToMoleCalculation.compositionMass}`);
54
+
55
+ // Ensure the properties are defined before using them
56
+ expect(convertCompMassToMoleCalculation.compositionMole).toBeDefined();
57
+ expect(convertCompMassToMoleCalculation.compositionMass).toBeDefined();
58
+
59
+ if (convertCompMassToMoleCalculation.compositionMole) {
60
+ // Regression check for the first mole fraction value
61
+ const expectedMoleFraction = 0.431622743966463;
62
+ const actualMoleFraction = convertCompMassToMoleCalculation.compositionMole[0];
63
+ const moleFractionDifference = Math.abs((actualMoleFraction - expectedMoleFraction) / expectedMoleFraction);
64
+
65
+ // Perform the regression check and fail if the difference is too large
66
+ expect(moleFractionDifference).toBeLessThan(1e-3);
67
+
68
+ console.log(`SUCCESS: convertCompMassToMoleCalculation (${convertCompMassToMoleCalculation.calculationElapsedTime}ms)`);
69
+ } else {
70
+ throw new Error('Composition mole data is undefined.');
71
+ }
72
+
73
+ });
74
+ });
@@ -0,0 +1,73 @@
1
+ import { ConvertCompositionMassToMoleCalculation } from "../../src/calculations/utilities";
2
+ import { Material, MaterialComponent } from "../../src/entities";
3
+ import { ResultCode } from "../../src/enums";
4
+ import { setAccessToken } from "../../src/utilities";
5
+ const accessToken = process.env.PWS_ACCESS_TOKEN;
6
+
7
+ if (!accessToken) {
8
+ throw new Error("ACCESS_TOKEN environment variable is not set.");
9
+ }
10
+
11
+ setAccessToken(accessToken);
12
+
13
+ describe('Test Case 130', () => {
14
+ test('Convert composition mass to mole calculation for ETHANE, METHANE, and PROPANE', async () => {
15
+
16
+ // Define the test case properties
17
+ const materialName = 'ETHANE_METHANE_PROPANE';
18
+ const compositionMass = [0.4, 0.2, 0.4];
19
+
20
+ // Define the material
21
+ const material = new Material({
22
+ name: materialName,
23
+ components: [
24
+ new MaterialComponent({ name: 'ETHANE', moleFraction: 0.4 }),
25
+ new MaterialComponent({ name: 'METHANE', moleFraction: 0.2 }),
26
+ new MaterialComponent({ name: 'PROPANE', moleFraction: 0.4 })
27
+ ],
28
+ componentCount: 3
29
+ });
30
+
31
+ // Create a ConvertCompositionMassToMoleCalculation using the material and composition mass
32
+ const convertCompMassToMoleCalculation = new ConvertCompositionMassToMoleCalculation(
33
+ material,
34
+ compositionMass,
35
+ compositionMass.length
36
+ );
37
+
38
+ // Run the ConvertCompositionMassToMoleCalculation
39
+ console.log('Running convertCompMassToMoleCalculation...');
40
+ const resultCode = await convertCompMassToMoleCalculation.run();
41
+
42
+ // Print any messages
43
+ if (convertCompMassToMoleCalculation.messages.length > 0) {
44
+ console.log('Messages:');
45
+ convertCompMassToMoleCalculation.messages.forEach((message) => {
46
+ console.log(message);
47
+ });
48
+ }
49
+ expect(resultCode).toBe(ResultCode.SUCCESS);
50
+
51
+ // Log mole and mass fractions
52
+ console.log(`Mole fraction: ${convertCompMassToMoleCalculation.compositionMole}`);
53
+ console.log(`Mass fraction: ${convertCompMassToMoleCalculation.compositionMass}`);
54
+
55
+ // Ensure the properties are defined before using them
56
+ expect(convertCompMassToMoleCalculation.compositionMole).toBeDefined();
57
+ expect(convertCompMassToMoleCalculation.compositionMass).toBeDefined();
58
+
59
+ if (convertCompMassToMoleCalculation.compositionMole) {
60
+ // Regression check for the first mole fraction value
61
+ const expectedMoleFraction = 0.3818147205269292;
62
+ const actualMoleFraction = convertCompMassToMoleCalculation.compositionMole[0];
63
+ const moleFractionDifference = Math.abs((actualMoleFraction - expectedMoleFraction) / expectedMoleFraction);
64
+
65
+ // Perform the regression check and fail if the difference is too large
66
+ expect(moleFractionDifference).toBeLessThan(1e-3);
67
+
68
+ console.log(`SUCCESS: convertCompMassToMoleCalculation (${convertCompMassToMoleCalculation.calculationElapsedTime}ms)`);
69
+ } else {
70
+ throw new Error('Composition mole data is undefined.');
71
+ }
72
+ });
73
+ });