@dnv-plant/typescriptpws 1.0.27 → 1.0.38
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/index.ts +17 -4
- package/package.json +1 -1
- package/src/calculations/applicationTools.ts +368 -0
- package/src/calculations/discharge.ts +1817 -0
- package/src/calculations/dispersion.ts +511 -0
- package/src/calculations/dispersionView.ts +2544 -0
- package/src/calculations/fireball.ts +458 -0
- package/src/calculations/jetFire.ts +760 -0
- package/src/calculations/lateExplosion.ts +937 -0
- package/src/calculations/linkedRunners.ts +3724 -0
- package/src/calculations/poolFire.ts +458 -0
- package/src/calculations/properties.ts +382 -0
- package/src/calculations/radiation.ts +3521 -0
- package/src/calculations/standalones.ts +432 -0
- package/src/calculations/toxics.ts +469 -0
- package/src/calculations/utilities.ts +3320 -0
- package/src/constants.ts +2 -2
- package/src/entities.ts +2 -2
- package/src/entity-schemas.ts +2 -2
- package/src/enums.ts +2 -2
- package/src/materials.ts +2 -2
- package/src/utilities.ts +2 -2
- package/src/calculations.ts +0 -17774
|
@@ -0,0 +1,937 @@
|
|
|
1
|
+
/***********************************************************************
|
|
2
|
+
* This file has been auto-generated by a code generation tool.
|
|
3
|
+
* Version: 1.0.38
|
|
4
|
+
* Date/time: 24 Mar 2025 16:46:20
|
|
5
|
+
* Template: templates/typescriptpws/calculations.razor.
|
|
6
|
+
***********************************************************************/
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
import * as Enums from "../enums";
|
|
11
|
+
import * as Entities from "../entities";
|
|
12
|
+
import * as EntitySchemas from "../entity-schemas";
|
|
13
|
+
import { getAnalyticsApiTarget, getClientAliasId, postRequest } from "../utilities";
|
|
14
|
+
|
|
15
|
+
import Joi from "joi";
|
|
16
|
+
import { AxiosResponse } from "axios";
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
class CalculationRequestBase {
|
|
20
|
+
/**
|
|
21
|
+
* Calculation request base class.
|
|
22
|
+
*/
|
|
23
|
+
constructor() {
|
|
24
|
+
// Base class initialization code
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
class CalculationBase {
|
|
29
|
+
resultCode?: Enums.ResultCode = Enums.ResultCode.SUCCESS;
|
|
30
|
+
messages: string[] = [];
|
|
31
|
+
calculationElapsedTime?: number = 0.0;
|
|
32
|
+
operationId?: string = "";
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Post JSON to URL and time the call
|
|
36
|
+
*/
|
|
37
|
+
async postRequest(url: string, data: string): Promise<AxiosResponse> {
|
|
38
|
+
return postRequest(url, data);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Utility method to print the messages returned by the calculation.
|
|
43
|
+
*/
|
|
44
|
+
printMessages(): void {
|
|
45
|
+
if (this.messages && this.messages.length > 0) {
|
|
46
|
+
this.messages.forEach((message) => console.log(message));
|
|
47
|
+
} else {
|
|
48
|
+
console.log("No messages");
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Utility method to handle a failed response.
|
|
54
|
+
*/
|
|
55
|
+
handleFailedResponse(response: AxiosResponse): void {
|
|
56
|
+
try {
|
|
57
|
+
const validatedFailedResponse = new CalculationFailedResponseSchema().validate(response.data);
|
|
58
|
+
|
|
59
|
+
this.resultCode = validatedFailedResponse.resultCode;
|
|
60
|
+
this.messages.push(...(validatedFailedResponse.messages ?? []));
|
|
61
|
+
this.calculationElapsedTime = validatedFailedResponse.calculationElapsedTime;
|
|
62
|
+
this.operationId = validatedFailedResponse.operationId;
|
|
63
|
+
} catch (error) {
|
|
64
|
+
if (error instanceof Error) {
|
|
65
|
+
this.messages.push(`Failed to parse response: ${error.message}`);
|
|
66
|
+
} else {
|
|
67
|
+
this.messages.push("An unknown error occurred during response parsing.");
|
|
68
|
+
}
|
|
69
|
+
console.error("Failed to parse response:", error);
|
|
70
|
+
} finally {
|
|
71
|
+
this.messages.push(`${response.statusText} (Status code: ${response.status})`);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
class CalculationResponseBase {
|
|
77
|
+
resultCode?: Enums.ResultCode;
|
|
78
|
+
messages?: string[];
|
|
79
|
+
calculationElapsedTime?: number;
|
|
80
|
+
operationId?: string;
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Calculation response base class.
|
|
84
|
+
*/
|
|
85
|
+
constructor(
|
|
86
|
+
resultCode?: Enums.ResultCode,
|
|
87
|
+
messages?: string[],
|
|
88
|
+
calculationElapsedTime?: number,
|
|
89
|
+
operationId?: string
|
|
90
|
+
) {
|
|
91
|
+
this.resultCode = resultCode;
|
|
92
|
+
this.messages = messages;
|
|
93
|
+
this.calculationElapsedTime = calculationElapsedTime;
|
|
94
|
+
this.operationId = operationId;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
class CalculationFailedResponse extends CalculationResponseBase {
|
|
99
|
+
/**
|
|
100
|
+
* Calculation failed response class.
|
|
101
|
+
*/
|
|
102
|
+
constructor(
|
|
103
|
+
resultCode?: Enums.ResultCode,
|
|
104
|
+
messages: string[] = [],
|
|
105
|
+
calculationElapsedTime: number = 0,
|
|
106
|
+
operationId: string = ""
|
|
107
|
+
) {
|
|
108
|
+
super(resultCode, messages, calculationElapsedTime, operationId);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
class CalculationFailedResponseSchema {
|
|
113
|
+
schema: Joi.ObjectSchema;
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Calculation failed response schema.
|
|
117
|
+
*/
|
|
118
|
+
constructor() {
|
|
119
|
+
this.schema = Joi.object({
|
|
120
|
+
resultCode: Joi.string()
|
|
121
|
+
.valid(...Object.values(Enums.ResultCode))
|
|
122
|
+
.required(),
|
|
123
|
+
messages: Joi.array().items(Joi.string()).required(),
|
|
124
|
+
calculationElapsedTime: Joi.number().required(),
|
|
125
|
+
operationId: Joi.string().required(),
|
|
126
|
+
}).unknown(true);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
validate(data: {
|
|
130
|
+
resultCode: Enums.ResultCode;
|
|
131
|
+
messages: string[];
|
|
132
|
+
calculationElapsedTime: number;
|
|
133
|
+
operationId: string;
|
|
134
|
+
}) {
|
|
135
|
+
const { error, value } = this.schema.validate(data);
|
|
136
|
+
if (error) throw new Error(`Validation error: ${error.details.map((x) => x.message).join(", ")}`);
|
|
137
|
+
return this.makeCalculationFailedResponse(value);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
makeCalculationFailedResponse(data: {
|
|
141
|
+
resultCode: Enums.ResultCode;
|
|
142
|
+
messages: string[];
|
|
143
|
+
calculationElapsedTime: number;
|
|
144
|
+
operationId: string;
|
|
145
|
+
}) {
|
|
146
|
+
return new CalculationFailedResponse(data.resultCode, data.messages, data.calculationElapsedTime, data.operationId);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
export interface LateExplosionCalculationRequestSchemaData {
|
|
151
|
+
material: Entities.Material;
|
|
152
|
+
scalarUdmOutputs: Entities.ScalarUdmOutputs;
|
|
153
|
+
weather: Entities.Weather;
|
|
154
|
+
dispersionRecords: Entities.DispersionRecord[];
|
|
155
|
+
dispersionRecordCount: number;
|
|
156
|
+
substrate: Entities.Substrate;
|
|
157
|
+
dispersionOutputConfig: Entities.DispersionOutputConfig;
|
|
158
|
+
explosionOutputConfig: Entities.ExplosionOutputConfig;
|
|
159
|
+
explosionParameters: Entities.ExplosionParameters;
|
|
160
|
+
explosionConfinedVolumes: Entities.ExplosionConfinedVolume[];
|
|
161
|
+
explosionConfinedVolumeCount: number;
|
|
162
|
+
dispersionParameters: Entities.DispersionParameters;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
class LateExplosionCalculationRequest extends CalculationRequestBase {
|
|
166
|
+
material: Entities.Material;
|
|
167
|
+
scalarUdmOutputs: Entities.ScalarUdmOutputs;
|
|
168
|
+
weather: Entities.Weather;
|
|
169
|
+
dispersionRecords: Entities.DispersionRecord[];
|
|
170
|
+
dispersionRecordCount: number;
|
|
171
|
+
substrate: Entities.Substrate;
|
|
172
|
+
dispersionOutputConfig: Entities.DispersionOutputConfig;
|
|
173
|
+
explosionOutputConfig: Entities.ExplosionOutputConfig;
|
|
174
|
+
explosionParameters: Entities.ExplosionParameters;
|
|
175
|
+
explosionConfinedVolumes: Entities.ExplosionConfinedVolume[];
|
|
176
|
+
explosionConfinedVolumeCount: number;
|
|
177
|
+
dispersionParameters: Entities.DispersionParameters;
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* LateExplosion calculation request class.
|
|
181
|
+
*
|
|
182
|
+
* @param {Entities.Material} material - A Material entity with post-discharge composition.
|
|
183
|
+
* @param {Entities.ScalarUdmOutputs} scalarUdmOutputs - Scalar dispersion results.
|
|
184
|
+
* @param {Entities.Weather} weather - A Weather entity.
|
|
185
|
+
* @param {Entities.DispersionRecord[]} dispersionRecords - An array of Dispersion Records.
|
|
186
|
+
* @param {number} dispersionRecordCount - Number of Dispersion Records.
|
|
187
|
+
* @param {Entities.Substrate} substrate - A Substrate entity.
|
|
188
|
+
* @param {Entities.DispersionOutputConfig} dispersionOutputConfig - A Dispersion Output Config.
|
|
189
|
+
* @param {Entities.ExplosionOutputConfig} explosionOutputConfig - An Explosion Output Config.
|
|
190
|
+
* @param {Entities.ExplosionParameters} explosionParameters - An Explosion Parameters entity.
|
|
191
|
+
* @param {Entities.ExplosionConfinedVolume[]} explosionConfinedVolumes - An array of Explosion Confined Volumes.
|
|
192
|
+
* @param {number} explosionConfinedVolumeCount - Number of Explosion Confined Volumes.
|
|
193
|
+
* @param {Entities.DispersionParameters} dispersionParameters - A Dispersion Parameters entity.
|
|
194
|
+
*/
|
|
195
|
+
constructor(
|
|
196
|
+
material: Entities.Material,
|
|
197
|
+
scalarUdmOutputs: Entities.ScalarUdmOutputs,
|
|
198
|
+
weather: Entities.Weather,
|
|
199
|
+
dispersionRecords: Entities.DispersionRecord[],
|
|
200
|
+
dispersionRecordCount: number,
|
|
201
|
+
substrate: Entities.Substrate,
|
|
202
|
+
dispersionOutputConfig: Entities.DispersionOutputConfig,
|
|
203
|
+
explosionOutputConfig: Entities.ExplosionOutputConfig,
|
|
204
|
+
explosionParameters: Entities.ExplosionParameters,
|
|
205
|
+
explosionConfinedVolumes: Entities.ExplosionConfinedVolume[],
|
|
206
|
+
explosionConfinedVolumeCount: number,
|
|
207
|
+
dispersionParameters: Entities.DispersionParameters
|
|
208
|
+
) {
|
|
209
|
+
super();
|
|
210
|
+
this.material = material;
|
|
211
|
+
this.scalarUdmOutputs = scalarUdmOutputs;
|
|
212
|
+
this.weather = weather;
|
|
213
|
+
this.dispersionRecords = dispersionRecords;
|
|
214
|
+
this.dispersionRecordCount = dispersionRecordCount;
|
|
215
|
+
this.substrate = substrate;
|
|
216
|
+
this.dispersionOutputConfig = dispersionOutputConfig;
|
|
217
|
+
this.explosionOutputConfig = explosionOutputConfig;
|
|
218
|
+
this.explosionParameters = explosionParameters;
|
|
219
|
+
this.explosionConfinedVolumes = explosionConfinedVolumes;
|
|
220
|
+
this.explosionConfinedVolumeCount = explosionConfinedVolumeCount;
|
|
221
|
+
this.dispersionParameters = dispersionParameters;
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
export class LateExplosionCalculationRequestSchema {
|
|
226
|
+
schema: Joi.ObjectSchema;
|
|
227
|
+
propertyTypes: Record<string, string>;
|
|
228
|
+
|
|
229
|
+
/**
|
|
230
|
+
* Schema for the LateExplosion calculation request.
|
|
231
|
+
*/
|
|
232
|
+
constructor() {
|
|
233
|
+
this.schema = Joi.object({
|
|
234
|
+
material: new EntitySchemas.MaterialSchema().schema,
|
|
235
|
+
scalarUdmOutputs: new EntitySchemas.ScalarUdmOutputsSchema().schema,
|
|
236
|
+
weather: new EntitySchemas.WeatherSchema().schema,
|
|
237
|
+
dispersionRecords: Joi.array().items(new EntitySchemas.DispersionRecordSchema().schema).allow(null),
|
|
238
|
+
dispersionRecordCount: Joi.number().integer(),
|
|
239
|
+
substrate: new EntitySchemas.SubstrateSchema().schema,
|
|
240
|
+
dispersionOutputConfig: new EntitySchemas.DispersionOutputConfigSchema().schema,
|
|
241
|
+
explosionOutputConfig: new EntitySchemas.ExplosionOutputConfigSchema().schema,
|
|
242
|
+
explosionParameters: new EntitySchemas.ExplosionParametersSchema().schema,
|
|
243
|
+
explosionConfinedVolumes: Joi.array().items(new EntitySchemas.ExplosionConfinedVolumeSchema().schema).allow(null),
|
|
244
|
+
explosionConfinedVolumeCount: Joi.number().integer(),
|
|
245
|
+
dispersionParameters: new EntitySchemas.DispersionParametersSchema().schema,
|
|
246
|
+
}).unknown(true);
|
|
247
|
+
|
|
248
|
+
this.propertyTypes = {
|
|
249
|
+
material: "Entities.Material",
|
|
250
|
+
scalarUdmOutputs: "Entities.ScalarUdmOutputs",
|
|
251
|
+
weather: "Entities.Weather",
|
|
252
|
+
dispersionRecords: "Entities.DispersionRecord[]",
|
|
253
|
+
dispersionRecordCount: "number",
|
|
254
|
+
substrate: "Entities.Substrate",
|
|
255
|
+
dispersionOutputConfig: "Entities.DispersionOutputConfig",
|
|
256
|
+
explosionOutputConfig: "Entities.ExplosionOutputConfig",
|
|
257
|
+
explosionParameters: "Entities.ExplosionParameters",
|
|
258
|
+
explosionConfinedVolumes: "Entities.ExplosionConfinedVolume[]",
|
|
259
|
+
explosionConfinedVolumeCount: "number",
|
|
260
|
+
dispersionParameters: "Entities.DispersionParameters",
|
|
261
|
+
};
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
validate(data: LateExplosionCalculationRequestSchemaData): LateExplosionCalculationRequest {
|
|
265
|
+
const { error, value } = this.schema.validate(data, { abortEarly: false });
|
|
266
|
+
if (error) {
|
|
267
|
+
throw new Error(`Validation error: ${error.details.map((x) => x.message).join(", ")}`);
|
|
268
|
+
}
|
|
269
|
+
return this.makeCalculationRequest(value);
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
makeCalculationRequest(data: LateExplosionCalculationRequestSchemaData): LateExplosionCalculationRequest {
|
|
273
|
+
return new LateExplosionCalculationRequest(
|
|
274
|
+
data.material,
|
|
275
|
+
data.scalarUdmOutputs,
|
|
276
|
+
data.weather,
|
|
277
|
+
data.dispersionRecords,
|
|
278
|
+
data.dispersionRecordCount,
|
|
279
|
+
data.substrate,
|
|
280
|
+
data.dispersionOutputConfig,
|
|
281
|
+
data.explosionOutputConfig,
|
|
282
|
+
data.explosionParameters,
|
|
283
|
+
data.explosionConfinedVolumes,
|
|
284
|
+
data.explosionConfinedVolumeCount,
|
|
285
|
+
data.dispersionParameters
|
|
286
|
+
);
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
export class LateExplosionCalculation extends CalculationBase {
|
|
291
|
+
material: Entities.Material;
|
|
292
|
+
scalarUdmOutputs: Entities.ScalarUdmOutputs;
|
|
293
|
+
weather: Entities.Weather;
|
|
294
|
+
dispersionRecords: Entities.DispersionRecord[];
|
|
295
|
+
dispersionRecordCount: number;
|
|
296
|
+
substrate: Entities.Substrate;
|
|
297
|
+
dispersionOutputConfig: Entities.DispersionOutputConfig;
|
|
298
|
+
explosionOutputConfig: Entities.ExplosionOutputConfig;
|
|
299
|
+
explosionParameters: Entities.ExplosionParameters;
|
|
300
|
+
explosionConfinedVolumes: Entities.ExplosionConfinedVolume[];
|
|
301
|
+
explosionConfinedVolumeCount: number;
|
|
302
|
+
dispersionParameters: Entities.DispersionParameters;
|
|
303
|
+
explosionUnifConfOverpressureResult?: Entities.ExplosionOverpressureResult;
|
|
304
|
+
explosionUnconfOverpressureResult?: Entities.ExplosionOverpressureResult;
|
|
305
|
+
|
|
306
|
+
/**
|
|
307
|
+
* Calculates the explosion overpressures from a flammable cloud, including delayed ignition. The method can switch between a "Uniform confined" approach where the multi-energy explosion calculations will model a single confined source that contains the entire mass of the cloud, or a "User-defined" approach where the user can specify explosion volumes with different strengths. The results produced are for the worst-case explosion determined by exploding the cloud at 10 m intervals in the downwind direction.
|
|
308
|
+
*
|
|
309
|
+
* @param {Entities.Material} material - A Material entity with post-discharge composition.
|
|
310
|
+
* @param {Entities.ScalarUdmOutputs} scalarUdmOutputs - Scalar dispersion results.
|
|
311
|
+
* @param {Entities.Weather} weather - A Weather entity.
|
|
312
|
+
* @param {Entities.DispersionRecord[]} dispersionRecords - An array of Dispersion Records.
|
|
313
|
+
* @param {number} dispersionRecordCount - Number of Dispersion Records.
|
|
314
|
+
* @param {Entities.Substrate} substrate - A Substrate entity.
|
|
315
|
+
* @param {Entities.DispersionOutputConfig} dispersionOutputConfig - A Dispersion Output Config.
|
|
316
|
+
* @param {Entities.ExplosionOutputConfig} explosionOutputConfig - An Explosion Output Config.
|
|
317
|
+
* @param {Entities.ExplosionParameters} explosionParameters - An Explosion Parameters entity.
|
|
318
|
+
* @param {Entities.ExplosionConfinedVolume[]} explosionConfinedVolumes - An array of Explosion Confined Volumes.
|
|
319
|
+
* @param {number} explosionConfinedVolumeCount - Number of Explosion Confined Volumes.
|
|
320
|
+
* @param {Entities.DispersionParameters} dispersionParameters - A Dispersion Parameters entity.
|
|
321
|
+
*/
|
|
322
|
+
constructor(
|
|
323
|
+
material: Entities.Material,
|
|
324
|
+
scalarUdmOutputs: Entities.ScalarUdmOutputs,
|
|
325
|
+
weather: Entities.Weather,
|
|
326
|
+
dispersionRecords: Entities.DispersionRecord[],
|
|
327
|
+
dispersionRecordCount: number,
|
|
328
|
+
substrate: Entities.Substrate,
|
|
329
|
+
dispersionOutputConfig: Entities.DispersionOutputConfig,
|
|
330
|
+
explosionOutputConfig: Entities.ExplosionOutputConfig,
|
|
331
|
+
explosionParameters: Entities.ExplosionParameters,
|
|
332
|
+
explosionConfinedVolumes: Entities.ExplosionConfinedVolume[],
|
|
333
|
+
explosionConfinedVolumeCount: number,
|
|
334
|
+
dispersionParameters: Entities.DispersionParameters
|
|
335
|
+
) {
|
|
336
|
+
super();
|
|
337
|
+
this.material = material;
|
|
338
|
+
this.scalarUdmOutputs = scalarUdmOutputs;
|
|
339
|
+
this.weather = weather;
|
|
340
|
+
this.dispersionRecords = dispersionRecords;
|
|
341
|
+
this.dispersionRecordCount = dispersionRecordCount;
|
|
342
|
+
this.substrate = substrate;
|
|
343
|
+
this.dispersionOutputConfig = dispersionOutputConfig;
|
|
344
|
+
this.explosionOutputConfig = explosionOutputConfig;
|
|
345
|
+
this.explosionParameters = explosionParameters;
|
|
346
|
+
this.explosionConfinedVolumes = explosionConfinedVolumes;
|
|
347
|
+
this.explosionConfinedVolumeCount = explosionConfinedVolumeCount;
|
|
348
|
+
this.dispersionParameters = dispersionParameters;
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
async run() {
|
|
352
|
+
try {
|
|
353
|
+
const request = new LateExplosionCalculationRequest(
|
|
354
|
+
this.material,
|
|
355
|
+
this.scalarUdmOutputs,
|
|
356
|
+
this.weather,
|
|
357
|
+
this.dispersionRecords,
|
|
358
|
+
this.dispersionRecordCount,
|
|
359
|
+
this.substrate,
|
|
360
|
+
this.dispersionOutputConfig,
|
|
361
|
+
this.explosionOutputConfig,
|
|
362
|
+
this.explosionParameters,
|
|
363
|
+
this.explosionConfinedVolumes,
|
|
364
|
+
this.explosionConfinedVolumeCount,
|
|
365
|
+
this.dispersionParameters
|
|
366
|
+
);
|
|
367
|
+
|
|
368
|
+
const schema = new LateExplosionCalculationRequestSchema();
|
|
369
|
+
const validatedRequest = schema.validate(request);
|
|
370
|
+
|
|
371
|
+
const requestJson = JSON.stringify(validatedRequest);
|
|
372
|
+
const url = `${getAnalyticsApiTarget()}calculatelateexplosion?clientId=${getClientAliasId()}`;
|
|
373
|
+
|
|
374
|
+
this.resultCode = Enums.ResultCode.UNEXPECTED_APPLICATION_ERROR;
|
|
375
|
+
|
|
376
|
+
const response = await this.postRequest(url, requestJson);
|
|
377
|
+
|
|
378
|
+
if (response.status >= 200 && response.status < 300) {
|
|
379
|
+
const schema = new LateExplosionCalculationResponseSchema();
|
|
380
|
+
const validatedResponse = schema.validate(response.data);
|
|
381
|
+
|
|
382
|
+
this.resultCode = validatedResponse.resultCode;
|
|
383
|
+
if (this.resultCode === Enums.ResultCode.SUCCESS) {
|
|
384
|
+
this.explosionUnifConfOverpressureResult = validatedResponse.explosionUnifConfOverpressureResult;
|
|
385
|
+
this.explosionUnconfOverpressureResult = validatedResponse.explosionUnconfOverpressureResult;
|
|
386
|
+
this.resultCode = validatedResponse.resultCode;
|
|
387
|
+
this.messages = validatedResponse.messages ?? [];
|
|
388
|
+
this.calculationElapsedTime = validatedResponse.calculationElapsedTime;
|
|
389
|
+
this.operationId = validatedResponse.operationId;
|
|
390
|
+
} else {
|
|
391
|
+
this.messages.push(...(validatedResponse.messages ?? []));
|
|
392
|
+
}
|
|
393
|
+
} else {
|
|
394
|
+
this.handleFailedResponse(response);
|
|
395
|
+
}
|
|
396
|
+
} catch (error) {
|
|
397
|
+
if (error instanceof Error) {
|
|
398
|
+
this.messages.push(`Error: ${error.message}`);
|
|
399
|
+
} else {
|
|
400
|
+
this.messages.push(`Unexpected error: ${JSON.stringify(error)}`);
|
|
401
|
+
}
|
|
402
|
+
console.error(error);
|
|
403
|
+
this.resultCode = Enums.ResultCode.UNEXPECTED_APPLICATION_ERROR;
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
return this.resultCode;
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
toString() {
|
|
410
|
+
const parts = ["* LateExplosion"];
|
|
411
|
+
|
|
412
|
+
parts.push(`explosionUnifConfOverpressureResult: ${String(this.explosionUnifConfOverpressureResult)}`);
|
|
413
|
+
parts.push(`explosionUnconfOverpressureResult: ${String(this.explosionUnconfOverpressureResult)}`);
|
|
414
|
+
parts.push(`resultCode: ${String(this.resultCode)}`);
|
|
415
|
+
parts.push("*** messages:");
|
|
416
|
+
parts.push(`messages: ${this.messages !== undefined ? this.messages : "(None)"}`);
|
|
417
|
+
parts.push(`calculationElapsedTime: ${this.calculationElapsedTime !== undefined ? this.calculationElapsedTime : "(None)"}`);
|
|
418
|
+
parts.push(`operationId: ${this.operationId !== undefined ? this.operationId : "(None)"}`);
|
|
419
|
+
|
|
420
|
+
return parts.join("\n");
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
export class LateExplosionCalculationResponse extends CalculationResponseBase {
|
|
425
|
+
explosionUnifConfOverpressureResult: Entities.ExplosionOverpressureResult;
|
|
426
|
+
explosionUnconfOverpressureResult: Entities.ExplosionOverpressureResult;
|
|
427
|
+
|
|
428
|
+
/**
|
|
429
|
+
* LateExplosion calculation response class.
|
|
430
|
+
*
|
|
431
|
+
* @param {Entities.ExplosionOverpressureResult} explosionUnifConfOverpressureResult - Uniform confined Explosion Overpressure Result.
|
|
432
|
+
* @param {Entities.ExplosionOverpressureResult} explosionUnconfOverpressureResult - Unconfined Explosion Overpressure Result.
|
|
433
|
+
*/
|
|
434
|
+
constructor(
|
|
435
|
+
explosionUnifConfOverpressureResult: Entities.ExplosionOverpressureResult,
|
|
436
|
+
explosionUnconfOverpressureResult: Entities.ExplosionOverpressureResult,
|
|
437
|
+
resultCode: Enums.ResultCode,
|
|
438
|
+
messages: string[],
|
|
439
|
+
calculationElapsedTime: number,
|
|
440
|
+
operationId: string
|
|
441
|
+
) {
|
|
442
|
+
super();
|
|
443
|
+
this.explosionUnifConfOverpressureResult = explosionUnifConfOverpressureResult;
|
|
444
|
+
this.explosionUnconfOverpressureResult = explosionUnconfOverpressureResult;
|
|
445
|
+
this.resultCode = resultCode;
|
|
446
|
+
this.messages = messages;
|
|
447
|
+
this.calculationElapsedTime = calculationElapsedTime;
|
|
448
|
+
this.operationId = operationId;
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
initialiseFromDictionary(data: { [key: string]: unknown }) {
|
|
452
|
+
if (data.explosionUnifConfOverpressureResult) {
|
|
453
|
+
this.explosionUnifConfOverpressureResult = new Entities.ExplosionOverpressureResult();
|
|
454
|
+
this.explosionUnifConfOverpressureResult.initialiseFromDictionary(data.explosionUnifConfOverpressureResult as { [key: string]: unknown });
|
|
455
|
+
}
|
|
456
|
+
if (data.explosionUnconfOverpressureResult) {
|
|
457
|
+
this.explosionUnconfOverpressureResult = new Entities.ExplosionOverpressureResult();
|
|
458
|
+
this.explosionUnconfOverpressureResult.initialiseFromDictionary(data.explosionUnconfOverpressureResult as { [key: string]: unknown });
|
|
459
|
+
}
|
|
460
|
+
if (data.resultCode !== undefined && (typeof data.resultCode === "string" || typeof data.resultCode === "number")) {
|
|
461
|
+
this.resultCode = data.resultCode as Enums.ResultCode;
|
|
462
|
+
}
|
|
463
|
+
this.messages = this.messages ?? [];
|
|
464
|
+
if (data.messages && Array.isArray(data.messages)) {
|
|
465
|
+
this.messages.push(...data.messages);
|
|
466
|
+
}
|
|
467
|
+
if (data.calculationElapsedTime !== undefined && typeof data.calculationElapsedTime === "number") {
|
|
468
|
+
this.calculationElapsedTime = data.calculationElapsedTime as number;
|
|
469
|
+
}
|
|
470
|
+
if (data.operationId !== undefined && typeof data.operationId === "string") {
|
|
471
|
+
this.operationId = data.operationId as string;
|
|
472
|
+
}
|
|
473
|
+
}
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
export interface LateExplosionCalculationResponseSchemaData {
|
|
477
|
+
explosionUnifConfOverpressureResult: Entities.ExplosionOverpressureResult;
|
|
478
|
+
explosionUnconfOverpressureResult: Entities.ExplosionOverpressureResult;
|
|
479
|
+
resultCode: Enums.ResultCode;
|
|
480
|
+
messages: string[];
|
|
481
|
+
calculationElapsedTime: number;
|
|
482
|
+
operationId: string;
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
export class LateExplosionCalculationResponseSchema {
|
|
486
|
+
schema: Joi.ObjectSchema;
|
|
487
|
+
propertyTypes: Record<string, string>;
|
|
488
|
+
|
|
489
|
+
/**
|
|
490
|
+
* Schema for the LateExplosion calculation response.
|
|
491
|
+
*/
|
|
492
|
+
constructor() {
|
|
493
|
+
this.schema = Joi.object({
|
|
494
|
+
explosionUnifConfOverpressureResult: new EntitySchemas.ExplosionOverpressureResultSchema().schema,
|
|
495
|
+
explosionUnconfOverpressureResult: new EntitySchemas.ExplosionOverpressureResultSchema().schema,
|
|
496
|
+
resultCode: Joi.string().valid(...Object.values(Enums.ResultCode)),
|
|
497
|
+
messages: Joi.array().items(Joi.string()),
|
|
498
|
+
calculationElapsedTime: Joi.number().unsafe(),
|
|
499
|
+
operationId: Joi.string().uuid().allow(null),
|
|
500
|
+
}).unknown(true);
|
|
501
|
+
|
|
502
|
+
this.propertyTypes = {
|
|
503
|
+
explosionUnifConfOverpressureResult: "Entities.ExplosionOverpressureResult",
|
|
504
|
+
explosionUnconfOverpressureResult: "Entities.ExplosionOverpressureResult",
|
|
505
|
+
};
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
validate(data: LateExplosionCalculationResponseSchemaData): LateExplosionCalculationResponse {
|
|
509
|
+
const { error, value } = this.schema.validate(data, { abortEarly: false });
|
|
510
|
+
if (error) {
|
|
511
|
+
throw new Error(`Validation error: ${error.details.map((x) => x.message).join(", ")}`);
|
|
512
|
+
}
|
|
513
|
+
return this.makeCalculationResponse(value);
|
|
514
|
+
}
|
|
515
|
+
|
|
516
|
+
makeCalculationResponse(data: LateExplosionCalculationResponseSchemaData): LateExplosionCalculationResponse {
|
|
517
|
+
return new LateExplosionCalculationResponse(
|
|
518
|
+
data.explosionUnifConfOverpressureResult,
|
|
519
|
+
data.explosionUnconfOverpressureResult,
|
|
520
|
+
data.resultCode,
|
|
521
|
+
data.messages,
|
|
522
|
+
data.calculationElapsedTime,
|
|
523
|
+
data.operationId
|
|
524
|
+
);
|
|
525
|
+
}
|
|
526
|
+
}
|
|
527
|
+
|
|
528
|
+
export interface LateExplosionToOPLevelsCalculationRequestSchemaData {
|
|
529
|
+
material: Entities.Material;
|
|
530
|
+
scalarUdmOutputs: Entities.ScalarUdmOutputs;
|
|
531
|
+
weather: Entities.Weather;
|
|
532
|
+
dispersionRecords: Entities.DispersionRecord[];
|
|
533
|
+
dispersionRecordCount: number;
|
|
534
|
+
substrate: Entities.Substrate;
|
|
535
|
+
dispersionOutputConfig: Entities.DispersionOutputConfig;
|
|
536
|
+
explosionOutputConfigs: Entities.ExplosionOutputConfig[];
|
|
537
|
+
explosionOutputConfigCount: number;
|
|
538
|
+
explosionParameters: Entities.ExplosionParameters;
|
|
539
|
+
explosionConfinedVolumes: Entities.ExplosionConfinedVolume[];
|
|
540
|
+
explosionConfinedVolumeCount: number;
|
|
541
|
+
dispersionParameters: Entities.DispersionParameters;
|
|
542
|
+
}
|
|
543
|
+
|
|
544
|
+
class LateExplosionToOPLevelsCalculationRequest extends CalculationRequestBase {
|
|
545
|
+
material: Entities.Material;
|
|
546
|
+
scalarUdmOutputs: Entities.ScalarUdmOutputs;
|
|
547
|
+
weather: Entities.Weather;
|
|
548
|
+
dispersionRecords: Entities.DispersionRecord[];
|
|
549
|
+
dispersionRecordCount: number;
|
|
550
|
+
substrate: Entities.Substrate;
|
|
551
|
+
dispersionOutputConfig: Entities.DispersionOutputConfig;
|
|
552
|
+
explosionOutputConfigs: Entities.ExplosionOutputConfig[];
|
|
553
|
+
explosionOutputConfigCount: number;
|
|
554
|
+
explosionParameters: Entities.ExplosionParameters;
|
|
555
|
+
explosionConfinedVolumes: Entities.ExplosionConfinedVolume[];
|
|
556
|
+
explosionConfinedVolumeCount: number;
|
|
557
|
+
dispersionParameters: Entities.DispersionParameters;
|
|
558
|
+
|
|
559
|
+
/**
|
|
560
|
+
* LateExplosionToOPLevels calculation request class.
|
|
561
|
+
*
|
|
562
|
+
* @param {Entities.Material} material - A Material entity with post-discharge composition.
|
|
563
|
+
* @param {Entities.ScalarUdmOutputs} scalarUdmOutputs - Scalar dispersion results.
|
|
564
|
+
* @param {Entities.Weather} weather - A Weather entity.
|
|
565
|
+
* @param {Entities.DispersionRecord[]} dispersionRecords - Cloud definition.
|
|
566
|
+
* @param {number} dispersionRecordCount - Number of Dispersion Records.
|
|
567
|
+
* @param {Entities.Substrate} substrate - A Substrate entity.
|
|
568
|
+
* @param {Entities.DispersionOutputConfig} dispersionOutputConfig - A Dispersion Output Config entity.
|
|
569
|
+
* @param {Entities.ExplosionOutputConfig[]} explosionOutputConfigs - An array of Explosion Output Configs.
|
|
570
|
+
* @param {number} explosionOutputConfigCount - Number of Explosion Output Configs.
|
|
571
|
+
* @param {Entities.ExplosionParameters} explosionParameters - Explosion parameters.
|
|
572
|
+
* @param {Entities.ExplosionConfinedVolume[]} explosionConfinedVolumes - An array of Explosion Confined Volumes.
|
|
573
|
+
* @param {number} explosionConfinedVolumeCount - Number of Explosion Confined Volumes.
|
|
574
|
+
* @param {Entities.DispersionParameters} dispersionParameters - A Dispersion Parameters entity.
|
|
575
|
+
*/
|
|
576
|
+
constructor(
|
|
577
|
+
material: Entities.Material,
|
|
578
|
+
scalarUdmOutputs: Entities.ScalarUdmOutputs,
|
|
579
|
+
weather: Entities.Weather,
|
|
580
|
+
dispersionRecords: Entities.DispersionRecord[],
|
|
581
|
+
dispersionRecordCount: number,
|
|
582
|
+
substrate: Entities.Substrate,
|
|
583
|
+
dispersionOutputConfig: Entities.DispersionOutputConfig,
|
|
584
|
+
explosionOutputConfigs: Entities.ExplosionOutputConfig[],
|
|
585
|
+
explosionOutputConfigCount: number,
|
|
586
|
+
explosionParameters: Entities.ExplosionParameters,
|
|
587
|
+
explosionConfinedVolumes: Entities.ExplosionConfinedVolume[],
|
|
588
|
+
explosionConfinedVolumeCount: number,
|
|
589
|
+
dispersionParameters: Entities.DispersionParameters
|
|
590
|
+
) {
|
|
591
|
+
super();
|
|
592
|
+
this.material = material;
|
|
593
|
+
this.scalarUdmOutputs = scalarUdmOutputs;
|
|
594
|
+
this.weather = weather;
|
|
595
|
+
this.dispersionRecords = dispersionRecords;
|
|
596
|
+
this.dispersionRecordCount = dispersionRecordCount;
|
|
597
|
+
this.substrate = substrate;
|
|
598
|
+
this.dispersionOutputConfig = dispersionOutputConfig;
|
|
599
|
+
this.explosionOutputConfigs = explosionOutputConfigs;
|
|
600
|
+
this.explosionOutputConfigCount = explosionOutputConfigCount;
|
|
601
|
+
this.explosionParameters = explosionParameters;
|
|
602
|
+
this.explosionConfinedVolumes = explosionConfinedVolumes;
|
|
603
|
+
this.explosionConfinedVolumeCount = explosionConfinedVolumeCount;
|
|
604
|
+
this.dispersionParameters = dispersionParameters;
|
|
605
|
+
}
|
|
606
|
+
}
|
|
607
|
+
|
|
608
|
+
export class LateExplosionToOPLevelsCalculationRequestSchema {
|
|
609
|
+
schema: Joi.ObjectSchema;
|
|
610
|
+
propertyTypes: Record<string, string>;
|
|
611
|
+
|
|
612
|
+
/**
|
|
613
|
+
* Schema for the LateExplosionToOPLevels calculation request.
|
|
614
|
+
*/
|
|
615
|
+
constructor() {
|
|
616
|
+
this.schema = Joi.object({
|
|
617
|
+
material: new EntitySchemas.MaterialSchema().schema,
|
|
618
|
+
scalarUdmOutputs: new EntitySchemas.ScalarUdmOutputsSchema().schema,
|
|
619
|
+
weather: new EntitySchemas.WeatherSchema().schema,
|
|
620
|
+
dispersionRecords: Joi.array().items(new EntitySchemas.DispersionRecordSchema().schema).allow(null),
|
|
621
|
+
dispersionRecordCount: Joi.number().integer(),
|
|
622
|
+
substrate: new EntitySchemas.SubstrateSchema().schema,
|
|
623
|
+
dispersionOutputConfig: new EntitySchemas.DispersionOutputConfigSchema().schema,
|
|
624
|
+
explosionOutputConfigs: Joi.array().items(new EntitySchemas.ExplosionOutputConfigSchema().schema).allow(null),
|
|
625
|
+
explosionOutputConfigCount: Joi.number().integer(),
|
|
626
|
+
explosionParameters: new EntitySchemas.ExplosionParametersSchema().schema,
|
|
627
|
+
explosionConfinedVolumes: Joi.array().items(new EntitySchemas.ExplosionConfinedVolumeSchema().schema).allow(null),
|
|
628
|
+
explosionConfinedVolumeCount: Joi.number().integer(),
|
|
629
|
+
dispersionParameters: new EntitySchemas.DispersionParametersSchema().schema,
|
|
630
|
+
}).unknown(true);
|
|
631
|
+
|
|
632
|
+
this.propertyTypes = {
|
|
633
|
+
material: "Entities.Material",
|
|
634
|
+
scalarUdmOutputs: "Entities.ScalarUdmOutputs",
|
|
635
|
+
weather: "Entities.Weather",
|
|
636
|
+
dispersionRecords: "Entities.DispersionRecord[]",
|
|
637
|
+
dispersionRecordCount: "number",
|
|
638
|
+
substrate: "Entities.Substrate",
|
|
639
|
+
dispersionOutputConfig: "Entities.DispersionOutputConfig",
|
|
640
|
+
explosionOutputConfigs: "Entities.ExplosionOutputConfig[]",
|
|
641
|
+
explosionOutputConfigCount: "number",
|
|
642
|
+
explosionParameters: "Entities.ExplosionParameters",
|
|
643
|
+
explosionConfinedVolumes: "Entities.ExplosionConfinedVolume[]",
|
|
644
|
+
explosionConfinedVolumeCount: "number",
|
|
645
|
+
dispersionParameters: "Entities.DispersionParameters",
|
|
646
|
+
};
|
|
647
|
+
}
|
|
648
|
+
|
|
649
|
+
validate(data: LateExplosionToOPLevelsCalculationRequestSchemaData): LateExplosionToOPLevelsCalculationRequest {
|
|
650
|
+
const { error, value } = this.schema.validate(data, { abortEarly: false });
|
|
651
|
+
if (error) {
|
|
652
|
+
throw new Error(`Validation error: ${error.details.map((x) => x.message).join(", ")}`);
|
|
653
|
+
}
|
|
654
|
+
return this.makeCalculationRequest(value);
|
|
655
|
+
}
|
|
656
|
+
|
|
657
|
+
makeCalculationRequest(data: LateExplosionToOPLevelsCalculationRequestSchemaData): LateExplosionToOPLevelsCalculationRequest {
|
|
658
|
+
return new LateExplosionToOPLevelsCalculationRequest(
|
|
659
|
+
data.material,
|
|
660
|
+
data.scalarUdmOutputs,
|
|
661
|
+
data.weather,
|
|
662
|
+
data.dispersionRecords,
|
|
663
|
+
data.dispersionRecordCount,
|
|
664
|
+
data.substrate,
|
|
665
|
+
data.dispersionOutputConfig,
|
|
666
|
+
data.explosionOutputConfigs,
|
|
667
|
+
data.explosionOutputConfigCount,
|
|
668
|
+
data.explosionParameters,
|
|
669
|
+
data.explosionConfinedVolumes,
|
|
670
|
+
data.explosionConfinedVolumeCount,
|
|
671
|
+
data.dispersionParameters
|
|
672
|
+
);
|
|
673
|
+
}
|
|
674
|
+
}
|
|
675
|
+
|
|
676
|
+
export class LateExplosionToOPLevelsCalculation extends CalculationBase {
|
|
677
|
+
material: Entities.Material;
|
|
678
|
+
scalarUdmOutputs: Entities.ScalarUdmOutputs;
|
|
679
|
+
weather: Entities.Weather;
|
|
680
|
+
dispersionRecords: Entities.DispersionRecord[];
|
|
681
|
+
dispersionRecordCount: number;
|
|
682
|
+
substrate: Entities.Substrate;
|
|
683
|
+
dispersionOutputConfig: Entities.DispersionOutputConfig;
|
|
684
|
+
explosionOutputConfigs: Entities.ExplosionOutputConfig[];
|
|
685
|
+
explosionOutputConfigCount: number;
|
|
686
|
+
explosionParameters: Entities.ExplosionParameters;
|
|
687
|
+
explosionConfinedVolumes: Entities.ExplosionConfinedVolume[];
|
|
688
|
+
explosionConfinedVolumeCount: number;
|
|
689
|
+
dispersionParameters: Entities.DispersionParameters;
|
|
690
|
+
explosionUnifConfOverpressureResults?: Entities.ExplosionOverpressureResult[];
|
|
691
|
+
explosionUnconfOverpressureResults?: Entities.ExplosionOverpressureResult[];
|
|
692
|
+
|
|
693
|
+
/**
|
|
694
|
+
* Calculates the explosion overpressures from a flammable cloud, including delayed ignition. The method can switch between a "Uniform confined" approach where the multi-energy explosion calculations will model a single confined source that contains the entire mass of the cloud, or a "User-defined" approach where the user can specify explosion volumes with different strengths. The results produced are for the worst-case explosion determined by exploding the cloud at 10 m intervals in the downwind direction. This calculation determines the worst-case explosion to various overpressure levels as specified by the array of explosion output configs.
|
|
695
|
+
*
|
|
696
|
+
* @param {Entities.Material} material - A Material entity with post-discharge composition.
|
|
697
|
+
* @param {Entities.ScalarUdmOutputs} scalarUdmOutputs - Scalar dispersion results.
|
|
698
|
+
* @param {Entities.Weather} weather - A Weather entity.
|
|
699
|
+
* @param {Entities.DispersionRecord[]} dispersionRecords - Cloud definition.
|
|
700
|
+
* @param {number} dispersionRecordCount - Number of Dispersion Records.
|
|
701
|
+
* @param {Entities.Substrate} substrate - A Substrate entity.
|
|
702
|
+
* @param {Entities.DispersionOutputConfig} dispersionOutputConfig - A Dispersion Output Config entity.
|
|
703
|
+
* @param {Entities.ExplosionOutputConfig[]} explosionOutputConfigs - An array of Explosion Output Configs.
|
|
704
|
+
* @param {number} explosionOutputConfigCount - Number of Explosion Output Configs.
|
|
705
|
+
* @param {Entities.ExplosionParameters} explosionParameters - Explosion parameters.
|
|
706
|
+
* @param {Entities.ExplosionConfinedVolume[]} explosionConfinedVolumes - An array of Explosion Confined Volumes.
|
|
707
|
+
* @param {number} explosionConfinedVolumeCount - Number of Explosion Confined Volumes.
|
|
708
|
+
* @param {Entities.DispersionParameters} dispersionParameters - A Dispersion Parameters entity.
|
|
709
|
+
*/
|
|
710
|
+
constructor(
|
|
711
|
+
material: Entities.Material,
|
|
712
|
+
scalarUdmOutputs: Entities.ScalarUdmOutputs,
|
|
713
|
+
weather: Entities.Weather,
|
|
714
|
+
dispersionRecords: Entities.DispersionRecord[],
|
|
715
|
+
dispersionRecordCount: number,
|
|
716
|
+
substrate: Entities.Substrate,
|
|
717
|
+
dispersionOutputConfig: Entities.DispersionOutputConfig,
|
|
718
|
+
explosionOutputConfigs: Entities.ExplosionOutputConfig[],
|
|
719
|
+
explosionOutputConfigCount: number,
|
|
720
|
+
explosionParameters: Entities.ExplosionParameters,
|
|
721
|
+
explosionConfinedVolumes: Entities.ExplosionConfinedVolume[],
|
|
722
|
+
explosionConfinedVolumeCount: number,
|
|
723
|
+
dispersionParameters: Entities.DispersionParameters
|
|
724
|
+
) {
|
|
725
|
+
super();
|
|
726
|
+
this.material = material;
|
|
727
|
+
this.scalarUdmOutputs = scalarUdmOutputs;
|
|
728
|
+
this.weather = weather;
|
|
729
|
+
this.dispersionRecords = dispersionRecords;
|
|
730
|
+
this.dispersionRecordCount = dispersionRecordCount;
|
|
731
|
+
this.substrate = substrate;
|
|
732
|
+
this.dispersionOutputConfig = dispersionOutputConfig;
|
|
733
|
+
this.explosionOutputConfigs = explosionOutputConfigs;
|
|
734
|
+
this.explosionOutputConfigCount = explosionOutputConfigCount;
|
|
735
|
+
this.explosionParameters = explosionParameters;
|
|
736
|
+
this.explosionConfinedVolumes = explosionConfinedVolumes;
|
|
737
|
+
this.explosionConfinedVolumeCount = explosionConfinedVolumeCount;
|
|
738
|
+
this.dispersionParameters = dispersionParameters;
|
|
739
|
+
}
|
|
740
|
+
|
|
741
|
+
async run() {
|
|
742
|
+
try {
|
|
743
|
+
const request = new LateExplosionToOPLevelsCalculationRequest(
|
|
744
|
+
this.material,
|
|
745
|
+
this.scalarUdmOutputs,
|
|
746
|
+
this.weather,
|
|
747
|
+
this.dispersionRecords,
|
|
748
|
+
this.dispersionRecordCount,
|
|
749
|
+
this.substrate,
|
|
750
|
+
this.dispersionOutputConfig,
|
|
751
|
+
this.explosionOutputConfigs,
|
|
752
|
+
this.explosionOutputConfigCount,
|
|
753
|
+
this.explosionParameters,
|
|
754
|
+
this.explosionConfinedVolumes,
|
|
755
|
+
this.explosionConfinedVolumeCount,
|
|
756
|
+
this.dispersionParameters
|
|
757
|
+
);
|
|
758
|
+
|
|
759
|
+
const schema = new LateExplosionToOPLevelsCalculationRequestSchema();
|
|
760
|
+
const validatedRequest = schema.validate(request);
|
|
761
|
+
|
|
762
|
+
const requestJson = JSON.stringify(validatedRequest);
|
|
763
|
+
const url = `${getAnalyticsApiTarget()}calculatelateexplosiontooplevels?clientId=${getClientAliasId()}`;
|
|
764
|
+
|
|
765
|
+
this.resultCode = Enums.ResultCode.UNEXPECTED_APPLICATION_ERROR;
|
|
766
|
+
|
|
767
|
+
const response = await this.postRequest(url, requestJson);
|
|
768
|
+
|
|
769
|
+
if (response.status >= 200 && response.status < 300) {
|
|
770
|
+
const schema = new LateExplosionToOPLevelsCalculationResponseSchema();
|
|
771
|
+
const validatedResponse = schema.validate(response.data);
|
|
772
|
+
|
|
773
|
+
this.resultCode = validatedResponse.resultCode;
|
|
774
|
+
if (this.resultCode === Enums.ResultCode.SUCCESS) {
|
|
775
|
+
this.explosionUnifConfOverpressureResults = validatedResponse.explosionUnifConfOverpressureResults;
|
|
776
|
+
this.explosionUnconfOverpressureResults = validatedResponse.explosionUnconfOverpressureResults;
|
|
777
|
+
this.resultCode = validatedResponse.resultCode;
|
|
778
|
+
this.messages = validatedResponse.messages ?? [];
|
|
779
|
+
this.calculationElapsedTime = validatedResponse.calculationElapsedTime;
|
|
780
|
+
this.operationId = validatedResponse.operationId;
|
|
781
|
+
} else {
|
|
782
|
+
this.messages.push(...(validatedResponse.messages ?? []));
|
|
783
|
+
}
|
|
784
|
+
} else {
|
|
785
|
+
this.handleFailedResponse(response);
|
|
786
|
+
}
|
|
787
|
+
} catch (error) {
|
|
788
|
+
if (error instanceof Error) {
|
|
789
|
+
this.messages.push(`Error: ${error.message}`);
|
|
790
|
+
} else {
|
|
791
|
+
this.messages.push(`Unexpected error: ${JSON.stringify(error)}`);
|
|
792
|
+
}
|
|
793
|
+
console.error(error);
|
|
794
|
+
this.resultCode = Enums.ResultCode.UNEXPECTED_APPLICATION_ERROR;
|
|
795
|
+
}
|
|
796
|
+
|
|
797
|
+
return this.resultCode;
|
|
798
|
+
}
|
|
799
|
+
|
|
800
|
+
toString() {
|
|
801
|
+
const parts = ["* LateExplosionToOPLevels"];
|
|
802
|
+
|
|
803
|
+
parts.push("*** explosionUnifConfOverpressureResults:");
|
|
804
|
+
parts.push(
|
|
805
|
+
this.explosionUnifConfOverpressureResults && this.explosionUnifConfOverpressureResults.length > 0
|
|
806
|
+
? this.explosionUnifConfOverpressureResults.map((point) => `explosionUnifConfOverpressureResultsElement: ${point}`).join("\n")
|
|
807
|
+
: "explosionUnifConfOverpressureResults does not contain any elements"
|
|
808
|
+
);
|
|
809
|
+
parts.push("*** explosionUnconfOverpressureResults:");
|
|
810
|
+
parts.push(
|
|
811
|
+
this.explosionUnconfOverpressureResults && this.explosionUnconfOverpressureResults.length > 0
|
|
812
|
+
? this.explosionUnconfOverpressureResults.map((point) => `explosionUnconfOverpressureResultsElement: ${point}`).join("\n")
|
|
813
|
+
: "explosionUnconfOverpressureResults does not contain any elements"
|
|
814
|
+
);
|
|
815
|
+
parts.push(`resultCode: ${String(this.resultCode)}`);
|
|
816
|
+
parts.push("*** messages:");
|
|
817
|
+
parts.push(`messages: ${this.messages !== undefined ? this.messages : "(None)"}`);
|
|
818
|
+
parts.push(`calculationElapsedTime: ${this.calculationElapsedTime !== undefined ? this.calculationElapsedTime : "(None)"}`);
|
|
819
|
+
parts.push(`operationId: ${this.operationId !== undefined ? this.operationId : "(None)"}`);
|
|
820
|
+
|
|
821
|
+
return parts.join("\n");
|
|
822
|
+
}
|
|
823
|
+
}
|
|
824
|
+
|
|
825
|
+
export class LateExplosionToOPLevelsCalculationResponse extends CalculationResponseBase {
|
|
826
|
+
explosionUnifConfOverpressureResults: Entities.ExplosionOverpressureResult[];
|
|
827
|
+
explosionUnconfOverpressureResults: Entities.ExplosionOverpressureResult[];
|
|
828
|
+
|
|
829
|
+
/**
|
|
830
|
+
* LateExplosionToOPLevels calculation response class.
|
|
831
|
+
*
|
|
832
|
+
* @param {Entities.ExplosionOverpressureResult[]} explosionUnifConfOverpressureResults - An array of uniform confined Explosion Overpressure Results.
|
|
833
|
+
* @param {Entities.ExplosionOverpressureResult[]} explosionUnconfOverpressureResults - An array of unconfined Explosion Overpressure Results.
|
|
834
|
+
*/
|
|
835
|
+
constructor(
|
|
836
|
+
explosionUnifConfOverpressureResults: Entities.ExplosionOverpressureResult[],
|
|
837
|
+
explosionUnconfOverpressureResults: Entities.ExplosionOverpressureResult[],
|
|
838
|
+
resultCode: Enums.ResultCode,
|
|
839
|
+
messages: string[],
|
|
840
|
+
calculationElapsedTime: number,
|
|
841
|
+
operationId: string
|
|
842
|
+
) {
|
|
843
|
+
super();
|
|
844
|
+
this.explosionUnifConfOverpressureResults = explosionUnifConfOverpressureResults;
|
|
845
|
+
this.explosionUnconfOverpressureResults = explosionUnconfOverpressureResults;
|
|
846
|
+
this.resultCode = resultCode;
|
|
847
|
+
this.messages = messages;
|
|
848
|
+
this.calculationElapsedTime = calculationElapsedTime;
|
|
849
|
+
this.operationId = operationId;
|
|
850
|
+
}
|
|
851
|
+
|
|
852
|
+
initialiseFromDictionary(data: { [key: string]: unknown }) {
|
|
853
|
+
if (data.explosionUnifConfOverpressureResults && Array.isArray(data.explosionUnifConfOverpressureResults)) {
|
|
854
|
+
this.explosionUnifConfOverpressureResults = data.explosionUnifConfOverpressureResults.map(
|
|
855
|
+
(item) => {
|
|
856
|
+
const record = new Entities.ExplosionOverpressureResult();
|
|
857
|
+
record.initialiseFromDictionary(item);
|
|
858
|
+
return record;
|
|
859
|
+
}
|
|
860
|
+
);
|
|
861
|
+
}
|
|
862
|
+
if (data.explosionUnconfOverpressureResults && Array.isArray(data.explosionUnconfOverpressureResults)) {
|
|
863
|
+
this.explosionUnconfOverpressureResults = data.explosionUnconfOverpressureResults.map(
|
|
864
|
+
(item) => {
|
|
865
|
+
const record = new Entities.ExplosionOverpressureResult();
|
|
866
|
+
record.initialiseFromDictionary(item);
|
|
867
|
+
return record;
|
|
868
|
+
}
|
|
869
|
+
);
|
|
870
|
+
}
|
|
871
|
+
if (data.resultCode !== undefined && (typeof data.resultCode === "string" || typeof data.resultCode === "number")) {
|
|
872
|
+
this.resultCode = data.resultCode as Enums.ResultCode;
|
|
873
|
+
}
|
|
874
|
+
this.messages = this.messages ?? [];
|
|
875
|
+
if (data.messages && Array.isArray(data.messages)) {
|
|
876
|
+
this.messages.push(...data.messages);
|
|
877
|
+
}
|
|
878
|
+
if (data.calculationElapsedTime !== undefined && typeof data.calculationElapsedTime === "number") {
|
|
879
|
+
this.calculationElapsedTime = data.calculationElapsedTime as number;
|
|
880
|
+
}
|
|
881
|
+
if (data.operationId !== undefined && typeof data.operationId === "string") {
|
|
882
|
+
this.operationId = data.operationId as string;
|
|
883
|
+
}
|
|
884
|
+
}
|
|
885
|
+
}
|
|
886
|
+
|
|
887
|
+
export interface LateExplosionToOPLevelsCalculationResponseSchemaData {
|
|
888
|
+
explosionUnifConfOverpressureResults: Entities.ExplosionOverpressureResult[];
|
|
889
|
+
explosionUnconfOverpressureResults: Entities.ExplosionOverpressureResult[];
|
|
890
|
+
resultCode: Enums.ResultCode;
|
|
891
|
+
messages: string[];
|
|
892
|
+
calculationElapsedTime: number;
|
|
893
|
+
operationId: string;
|
|
894
|
+
}
|
|
895
|
+
|
|
896
|
+
export class LateExplosionToOPLevelsCalculationResponseSchema {
|
|
897
|
+
schema: Joi.ObjectSchema;
|
|
898
|
+
propertyTypes: Record<string, string>;
|
|
899
|
+
|
|
900
|
+
/**
|
|
901
|
+
* Schema for the LateExplosionToOPLevels calculation response.
|
|
902
|
+
*/
|
|
903
|
+
constructor() {
|
|
904
|
+
this.schema = Joi.object({
|
|
905
|
+
explosionUnifConfOverpressureResults: Joi.array().items(new EntitySchemas.ExplosionOverpressureResultSchema().schema).allow(null),
|
|
906
|
+
explosionUnconfOverpressureResults: Joi.array().items(new EntitySchemas.ExplosionOverpressureResultSchema().schema).allow(null),
|
|
907
|
+
resultCode: Joi.string().valid(...Object.values(Enums.ResultCode)),
|
|
908
|
+
messages: Joi.array().items(Joi.string()),
|
|
909
|
+
calculationElapsedTime: Joi.number().unsafe(),
|
|
910
|
+
operationId: Joi.string().uuid().allow(null),
|
|
911
|
+
}).unknown(true);
|
|
912
|
+
|
|
913
|
+
this.propertyTypes = {
|
|
914
|
+
explosionUnifConfOverpressureResults: "Entities.ExplosionOverpressureResult[]",
|
|
915
|
+
explosionUnconfOverpressureResults: "Entities.ExplosionOverpressureResult[]",
|
|
916
|
+
};
|
|
917
|
+
}
|
|
918
|
+
|
|
919
|
+
validate(data: LateExplosionToOPLevelsCalculationResponseSchemaData): LateExplosionToOPLevelsCalculationResponse {
|
|
920
|
+
const { error, value } = this.schema.validate(data, { abortEarly: false });
|
|
921
|
+
if (error) {
|
|
922
|
+
throw new Error(`Validation error: ${error.details.map((x) => x.message).join(", ")}`);
|
|
923
|
+
}
|
|
924
|
+
return this.makeCalculationResponse(value);
|
|
925
|
+
}
|
|
926
|
+
|
|
927
|
+
makeCalculationResponse(data: LateExplosionToOPLevelsCalculationResponseSchemaData): LateExplosionToOPLevelsCalculationResponse {
|
|
928
|
+
return new LateExplosionToOPLevelsCalculationResponse(
|
|
929
|
+
data.explosionUnifConfOverpressureResults,
|
|
930
|
+
data.explosionUnconfOverpressureResults,
|
|
931
|
+
data.resultCode,
|
|
932
|
+
data.messages,
|
|
933
|
+
data.calculationElapsedTime,
|
|
934
|
+
data.operationId
|
|
935
|
+
);
|
|
936
|
+
}
|
|
937
|
+
}
|