@dnv-plant/typescriptpws 1.0.27 → 1.0.38-alpha.1846913
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 +2 -2
- 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,760 @@
|
|
|
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 JetFireCalculationRequestSchemaData {
|
|
151
|
+
material: Entities.Material;
|
|
152
|
+
dischargeRecords: Entities.DischargeRecord[];
|
|
153
|
+
dischargeRecordCount: number;
|
|
154
|
+
dischargeResult: Entities.DischargeResult;
|
|
155
|
+
weather: Entities.Weather;
|
|
156
|
+
substrate: Entities.Substrate;
|
|
157
|
+
flammableParameters: Entities.FlammableParameters;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
class JetFireCalculationRequest extends CalculationRequestBase {
|
|
161
|
+
material: Entities.Material;
|
|
162
|
+
dischargeRecords: Entities.DischargeRecord[];
|
|
163
|
+
dischargeRecordCount: number;
|
|
164
|
+
dischargeResult: Entities.DischargeResult;
|
|
165
|
+
weather: Entities.Weather;
|
|
166
|
+
substrate: Entities.Substrate;
|
|
167
|
+
flammableParameters: Entities.FlammableParameters;
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* JetFire calculation request class.
|
|
171
|
+
*
|
|
172
|
+
* @param {Entities.Material} material - A Material entity with post-discharge composition.
|
|
173
|
+
* @param {Entities.DischargeRecord[]} dischargeRecords - Discharge / source term definition.
|
|
174
|
+
* @param {number} dischargeRecordCount - Number of Discharge Records.
|
|
175
|
+
* @param {Entities.DischargeResult} dischargeResult - Discharge / source term definition.
|
|
176
|
+
* @param {Entities.Weather} weather - A Weather entity.
|
|
177
|
+
* @param {Entities.Substrate} substrate - A Substrate entity.
|
|
178
|
+
* @param {Entities.FlammableParameters} flammableParameters - A Flammable Parameters entity.
|
|
179
|
+
*/
|
|
180
|
+
constructor(
|
|
181
|
+
material: Entities.Material,
|
|
182
|
+
dischargeRecords: Entities.DischargeRecord[],
|
|
183
|
+
dischargeRecordCount: number,
|
|
184
|
+
dischargeResult: Entities.DischargeResult,
|
|
185
|
+
weather: Entities.Weather,
|
|
186
|
+
substrate: Entities.Substrate,
|
|
187
|
+
flammableParameters: Entities.FlammableParameters
|
|
188
|
+
) {
|
|
189
|
+
super();
|
|
190
|
+
this.material = material;
|
|
191
|
+
this.dischargeRecords = dischargeRecords;
|
|
192
|
+
this.dischargeRecordCount = dischargeRecordCount;
|
|
193
|
+
this.dischargeResult = dischargeResult;
|
|
194
|
+
this.weather = weather;
|
|
195
|
+
this.substrate = substrate;
|
|
196
|
+
this.flammableParameters = flammableParameters;
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
export class JetFireCalculationRequestSchema {
|
|
201
|
+
schema: Joi.ObjectSchema;
|
|
202
|
+
propertyTypes: Record<string, string>;
|
|
203
|
+
|
|
204
|
+
/**
|
|
205
|
+
* Schema for the JetFire calculation request.
|
|
206
|
+
*/
|
|
207
|
+
constructor() {
|
|
208
|
+
this.schema = Joi.object({
|
|
209
|
+
material: new EntitySchemas.MaterialSchema().schema,
|
|
210
|
+
dischargeRecords: Joi.array().items(new EntitySchemas.DischargeRecordSchema().schema).allow(null),
|
|
211
|
+
dischargeRecordCount: Joi.number().integer(),
|
|
212
|
+
dischargeResult: new EntitySchemas.DischargeResultSchema().schema,
|
|
213
|
+
weather: new EntitySchemas.WeatherSchema().schema,
|
|
214
|
+
substrate: new EntitySchemas.SubstrateSchema().schema,
|
|
215
|
+
flammableParameters: new EntitySchemas.FlammableParametersSchema().schema,
|
|
216
|
+
}).unknown(true);
|
|
217
|
+
|
|
218
|
+
this.propertyTypes = {
|
|
219
|
+
material: "Entities.Material",
|
|
220
|
+
dischargeRecords: "Entities.DischargeRecord[]",
|
|
221
|
+
dischargeRecordCount: "number",
|
|
222
|
+
dischargeResult: "Entities.DischargeResult",
|
|
223
|
+
weather: "Entities.Weather",
|
|
224
|
+
substrate: "Entities.Substrate",
|
|
225
|
+
flammableParameters: "Entities.FlammableParameters",
|
|
226
|
+
};
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
validate(data: JetFireCalculationRequestSchemaData): JetFireCalculationRequest {
|
|
230
|
+
const { error, value } = this.schema.validate(data, { abortEarly: false });
|
|
231
|
+
if (error) {
|
|
232
|
+
throw new Error(`Validation error: ${error.details.map((x) => x.message).join(", ")}`);
|
|
233
|
+
}
|
|
234
|
+
return this.makeCalculationRequest(value);
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
makeCalculationRequest(data: JetFireCalculationRequestSchemaData): JetFireCalculationRequest {
|
|
238
|
+
return new JetFireCalculationRequest(
|
|
239
|
+
data.material,
|
|
240
|
+
data.dischargeRecords,
|
|
241
|
+
data.dischargeRecordCount,
|
|
242
|
+
data.dischargeResult,
|
|
243
|
+
data.weather,
|
|
244
|
+
data.substrate,
|
|
245
|
+
data.flammableParameters
|
|
246
|
+
);
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
export class JetFireCalculation extends CalculationBase {
|
|
251
|
+
material: Entities.Material;
|
|
252
|
+
dischargeRecords: Entities.DischargeRecord[];
|
|
253
|
+
dischargeRecordCount: number;
|
|
254
|
+
dischargeResult: Entities.DischargeResult;
|
|
255
|
+
weather: Entities.Weather;
|
|
256
|
+
substrate: Entities.Substrate;
|
|
257
|
+
flammableParameters: Entities.FlammableParameters;
|
|
258
|
+
flameResult?: Entities.FlameResult;
|
|
259
|
+
flameRecords?: Entities.FlameRecord[];
|
|
260
|
+
|
|
261
|
+
/**
|
|
262
|
+
* Calculates the jet fire using the cone model from a continuous or time-varying release. It uses source terms as input, and the output can be used to run radiation models for prediction of thermal effects. For time-varying releases the jet fire model will
|
|
263
|
+
use average discharge data based on the averaging time for jet fires of 20 s. For continuous releases the model will use the
|
|
264
|
+
initial constant discharge data provided.
|
|
265
|
+
*
|
|
266
|
+
* @param {Entities.Material} material - A Material entity with post-discharge composition.
|
|
267
|
+
* @param {Entities.DischargeRecord[]} dischargeRecords - Discharge / source term definition.
|
|
268
|
+
* @param {number} dischargeRecordCount - Number of Discharge Records.
|
|
269
|
+
* @param {Entities.DischargeResult} dischargeResult - Discharge / source term definition.
|
|
270
|
+
* @param {Entities.Weather} weather - A Weather entity.
|
|
271
|
+
* @param {Entities.Substrate} substrate - A Substrate entity.
|
|
272
|
+
* @param {Entities.FlammableParameters} flammableParameters - A Flammable Parameters entity.
|
|
273
|
+
*/
|
|
274
|
+
constructor(
|
|
275
|
+
material: Entities.Material,
|
|
276
|
+
dischargeRecords: Entities.DischargeRecord[],
|
|
277
|
+
dischargeRecordCount: number,
|
|
278
|
+
dischargeResult: Entities.DischargeResult,
|
|
279
|
+
weather: Entities.Weather,
|
|
280
|
+
substrate: Entities.Substrate,
|
|
281
|
+
flammableParameters: Entities.FlammableParameters
|
|
282
|
+
) {
|
|
283
|
+
super();
|
|
284
|
+
this.material = material;
|
|
285
|
+
this.dischargeRecords = dischargeRecords;
|
|
286
|
+
this.dischargeRecordCount = dischargeRecordCount;
|
|
287
|
+
this.dischargeResult = dischargeResult;
|
|
288
|
+
this.weather = weather;
|
|
289
|
+
this.substrate = substrate;
|
|
290
|
+
this.flammableParameters = flammableParameters;
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
async run() {
|
|
294
|
+
try {
|
|
295
|
+
const request = new JetFireCalculationRequest(
|
|
296
|
+
this.material,
|
|
297
|
+
this.dischargeRecords,
|
|
298
|
+
this.dischargeRecordCount,
|
|
299
|
+
this.dischargeResult,
|
|
300
|
+
this.weather,
|
|
301
|
+
this.substrate,
|
|
302
|
+
this.flammableParameters
|
|
303
|
+
);
|
|
304
|
+
|
|
305
|
+
const schema = new JetFireCalculationRequestSchema();
|
|
306
|
+
const validatedRequest = schema.validate(request);
|
|
307
|
+
|
|
308
|
+
const requestJson = JSON.stringify(validatedRequest);
|
|
309
|
+
const url = `${getAnalyticsApiTarget()}calculatejetfire?clientId=${getClientAliasId()}`;
|
|
310
|
+
|
|
311
|
+
this.resultCode = Enums.ResultCode.UNEXPECTED_APPLICATION_ERROR;
|
|
312
|
+
|
|
313
|
+
const response = await this.postRequest(url, requestJson);
|
|
314
|
+
|
|
315
|
+
if (response.status >= 200 && response.status < 300) {
|
|
316
|
+
const schema = new JetFireCalculationResponseSchema();
|
|
317
|
+
const validatedResponse = schema.validate(response.data);
|
|
318
|
+
|
|
319
|
+
this.resultCode = validatedResponse.resultCode;
|
|
320
|
+
if (this.resultCode === Enums.ResultCode.SUCCESS) {
|
|
321
|
+
this.flameResult = validatedResponse.flameResult;
|
|
322
|
+
this.flameRecords = validatedResponse.flameRecords;
|
|
323
|
+
this.resultCode = validatedResponse.resultCode;
|
|
324
|
+
this.messages = validatedResponse.messages ?? [];
|
|
325
|
+
this.calculationElapsedTime = validatedResponse.calculationElapsedTime;
|
|
326
|
+
this.operationId = validatedResponse.operationId;
|
|
327
|
+
} else {
|
|
328
|
+
this.messages.push(...(validatedResponse.messages ?? []));
|
|
329
|
+
}
|
|
330
|
+
} else {
|
|
331
|
+
this.handleFailedResponse(response);
|
|
332
|
+
}
|
|
333
|
+
} catch (error) {
|
|
334
|
+
if (error instanceof Error) {
|
|
335
|
+
this.messages.push(`Error: ${error.message}`);
|
|
336
|
+
} else {
|
|
337
|
+
this.messages.push(`Unexpected error: ${JSON.stringify(error)}`);
|
|
338
|
+
}
|
|
339
|
+
console.error(error);
|
|
340
|
+
this.resultCode = Enums.ResultCode.UNEXPECTED_APPLICATION_ERROR;
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
return this.resultCode;
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
toString() {
|
|
347
|
+
const parts = ["* JetFire"];
|
|
348
|
+
|
|
349
|
+
parts.push(`flameResult: ${String(this.flameResult)}`);
|
|
350
|
+
parts.push("*** flameRecords:");
|
|
351
|
+
parts.push(
|
|
352
|
+
this.flameRecords && this.flameRecords.length > 0
|
|
353
|
+
? this.flameRecords.map((point) => `flameRecordsElement: ${point}`).join("\n")
|
|
354
|
+
: "flameRecords does not contain any elements"
|
|
355
|
+
);
|
|
356
|
+
parts.push(`resultCode: ${String(this.resultCode)}`);
|
|
357
|
+
parts.push("*** messages:");
|
|
358
|
+
parts.push(`messages: ${this.messages !== undefined ? this.messages : "(None)"}`);
|
|
359
|
+
parts.push(`calculationElapsedTime: ${this.calculationElapsedTime !== undefined ? this.calculationElapsedTime : "(None)"}`);
|
|
360
|
+
parts.push(`operationId: ${this.operationId !== undefined ? this.operationId : "(None)"}`);
|
|
361
|
+
|
|
362
|
+
return parts.join("\n");
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
export class JetFireCalculationResponse extends CalculationResponseBase {
|
|
367
|
+
flameResult: Entities.FlameResult;
|
|
368
|
+
flameRecords: Entities.FlameRecord[];
|
|
369
|
+
|
|
370
|
+
/**
|
|
371
|
+
* JetFire calculation response class.
|
|
372
|
+
*
|
|
373
|
+
* @param {Entities.FlameResult} flameResult - Flame scalar results.
|
|
374
|
+
* @param {Entities.FlameRecord[]} flameRecords - An array of jet fire Flame Records.
|
|
375
|
+
*/
|
|
376
|
+
constructor(
|
|
377
|
+
flameResult: Entities.FlameResult,
|
|
378
|
+
flameRecords: Entities.FlameRecord[],
|
|
379
|
+
resultCode: Enums.ResultCode,
|
|
380
|
+
messages: string[],
|
|
381
|
+
calculationElapsedTime: number,
|
|
382
|
+
operationId: string
|
|
383
|
+
) {
|
|
384
|
+
super();
|
|
385
|
+
this.flameResult = flameResult;
|
|
386
|
+
this.flameRecords = flameRecords;
|
|
387
|
+
this.resultCode = resultCode;
|
|
388
|
+
this.messages = messages;
|
|
389
|
+
this.calculationElapsedTime = calculationElapsedTime;
|
|
390
|
+
this.operationId = operationId;
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
initialiseFromDictionary(data: { [key: string]: unknown }) {
|
|
394
|
+
if (data.flameResult) {
|
|
395
|
+
this.flameResult = new Entities.FlameResult();
|
|
396
|
+
this.flameResult.initialiseFromDictionary(data.flameResult as { [key: string]: unknown });
|
|
397
|
+
}
|
|
398
|
+
if (data.flameRecords && Array.isArray(data.flameRecords)) {
|
|
399
|
+
this.flameRecords = data.flameRecords.map(
|
|
400
|
+
(item) => {
|
|
401
|
+
const record = new Entities.FlameRecord();
|
|
402
|
+
record.initialiseFromDictionary(item);
|
|
403
|
+
return record;
|
|
404
|
+
}
|
|
405
|
+
);
|
|
406
|
+
}
|
|
407
|
+
if (data.resultCode !== undefined && (typeof data.resultCode === "string" || typeof data.resultCode === "number")) {
|
|
408
|
+
this.resultCode = data.resultCode as Enums.ResultCode;
|
|
409
|
+
}
|
|
410
|
+
this.messages = this.messages ?? [];
|
|
411
|
+
if (data.messages && Array.isArray(data.messages)) {
|
|
412
|
+
this.messages.push(...data.messages);
|
|
413
|
+
}
|
|
414
|
+
if (data.calculationElapsedTime !== undefined && typeof data.calculationElapsedTime === "number") {
|
|
415
|
+
this.calculationElapsedTime = data.calculationElapsedTime as number;
|
|
416
|
+
}
|
|
417
|
+
if (data.operationId !== undefined && typeof data.operationId === "string") {
|
|
418
|
+
this.operationId = data.operationId as string;
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
export interface JetFireCalculationResponseSchemaData {
|
|
424
|
+
flameResult: Entities.FlameResult;
|
|
425
|
+
flameRecords: Entities.FlameRecord[];
|
|
426
|
+
resultCode: Enums.ResultCode;
|
|
427
|
+
messages: string[];
|
|
428
|
+
calculationElapsedTime: number;
|
|
429
|
+
operationId: string;
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
export class JetFireCalculationResponseSchema {
|
|
433
|
+
schema: Joi.ObjectSchema;
|
|
434
|
+
propertyTypes: Record<string, string>;
|
|
435
|
+
|
|
436
|
+
/**
|
|
437
|
+
* Schema for the JetFire calculation response.
|
|
438
|
+
*/
|
|
439
|
+
constructor() {
|
|
440
|
+
this.schema = Joi.object({
|
|
441
|
+
flameResult: new EntitySchemas.FlameResultSchema().schema,
|
|
442
|
+
flameRecords: Joi.array().items(new EntitySchemas.FlameRecordSchema().schema).allow(null),
|
|
443
|
+
resultCode: Joi.string().valid(...Object.values(Enums.ResultCode)),
|
|
444
|
+
messages: Joi.array().items(Joi.string()),
|
|
445
|
+
calculationElapsedTime: Joi.number().unsafe(),
|
|
446
|
+
operationId: Joi.string().uuid().allow(null),
|
|
447
|
+
}).unknown(true);
|
|
448
|
+
|
|
449
|
+
this.propertyTypes = {
|
|
450
|
+
flameResult: "Entities.FlameResult",
|
|
451
|
+
flameRecords: "Entities.FlameRecord[]",
|
|
452
|
+
};
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
validate(data: JetFireCalculationResponseSchemaData): JetFireCalculationResponse {
|
|
456
|
+
const { error, value } = this.schema.validate(data, { abortEarly: false });
|
|
457
|
+
if (error) {
|
|
458
|
+
throw new Error(`Validation error: ${error.details.map((x) => x.message).join(", ")}`);
|
|
459
|
+
}
|
|
460
|
+
return this.makeCalculationResponse(value);
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
makeCalculationResponse(data: JetFireCalculationResponseSchemaData): JetFireCalculationResponse {
|
|
464
|
+
return new JetFireCalculationResponse(
|
|
465
|
+
data.flameResult,
|
|
466
|
+
data.flameRecords,
|
|
467
|
+
data.resultCode,
|
|
468
|
+
data.messages,
|
|
469
|
+
data.calculationElapsedTime,
|
|
470
|
+
data.operationId
|
|
471
|
+
);
|
|
472
|
+
}
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
export interface ModifyFuelRateForJetFireCalculationRequestSchemaData {
|
|
476
|
+
dischargeRecords: Entities.DischargeRecord[];
|
|
477
|
+
dischargeRecordCount: number;
|
|
478
|
+
poolRecords: Entities.PoolRecord[];
|
|
479
|
+
poolRecordCount: number;
|
|
480
|
+
flammableParameters: Entities.FlammableParameters;
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
class ModifyFuelRateForJetFireCalculationRequest extends CalculationRequestBase {
|
|
484
|
+
dischargeRecords: Entities.DischargeRecord[];
|
|
485
|
+
dischargeRecordCount: number;
|
|
486
|
+
poolRecords: Entities.PoolRecord[];
|
|
487
|
+
poolRecordCount: number;
|
|
488
|
+
flammableParameters: Entities.FlammableParameters;
|
|
489
|
+
|
|
490
|
+
/**
|
|
491
|
+
* ModifyFuelRateForJetFire calculation request class.
|
|
492
|
+
*
|
|
493
|
+
* @param {Entities.DischargeRecord[]} dischargeRecords - Discharge records.
|
|
494
|
+
* @param {number} dischargeRecordCount - Number of discharge records.
|
|
495
|
+
* @param {Entities.PoolRecord[]} poolRecords - Pool records.
|
|
496
|
+
* @param {number} poolRecordCount - Number of pool records.
|
|
497
|
+
* @param {Entities.FlammableParameters} flammableParameters - Flammable parameters.
|
|
498
|
+
*/
|
|
499
|
+
constructor(
|
|
500
|
+
dischargeRecords: Entities.DischargeRecord[],
|
|
501
|
+
dischargeRecordCount: number,
|
|
502
|
+
poolRecords: Entities.PoolRecord[],
|
|
503
|
+
poolRecordCount: number,
|
|
504
|
+
flammableParameters: Entities.FlammableParameters
|
|
505
|
+
) {
|
|
506
|
+
super();
|
|
507
|
+
this.dischargeRecords = dischargeRecords;
|
|
508
|
+
this.dischargeRecordCount = dischargeRecordCount;
|
|
509
|
+
this.poolRecords = poolRecords;
|
|
510
|
+
this.poolRecordCount = poolRecordCount;
|
|
511
|
+
this.flammableParameters = flammableParameters;
|
|
512
|
+
}
|
|
513
|
+
}
|
|
514
|
+
|
|
515
|
+
export class ModifyFuelRateForJetFireCalculationRequestSchema {
|
|
516
|
+
schema: Joi.ObjectSchema;
|
|
517
|
+
propertyTypes: Record<string, string>;
|
|
518
|
+
|
|
519
|
+
/**
|
|
520
|
+
* Schema for the ModifyFuelRateForJetFire calculation request.
|
|
521
|
+
*/
|
|
522
|
+
constructor() {
|
|
523
|
+
this.schema = Joi.object({
|
|
524
|
+
dischargeRecords: Joi.array().items(new EntitySchemas.DischargeRecordSchema().schema).allow(null),
|
|
525
|
+
dischargeRecordCount: Joi.number().integer(),
|
|
526
|
+
poolRecords: Joi.array().items(new EntitySchemas.PoolRecordSchema().schema).allow(null),
|
|
527
|
+
poolRecordCount: Joi.number().integer(),
|
|
528
|
+
flammableParameters: new EntitySchemas.FlammableParametersSchema().schema,
|
|
529
|
+
}).unknown(true);
|
|
530
|
+
|
|
531
|
+
this.propertyTypes = {
|
|
532
|
+
dischargeRecords: "Entities.DischargeRecord[]",
|
|
533
|
+
dischargeRecordCount: "number",
|
|
534
|
+
poolRecords: "Entities.PoolRecord[]",
|
|
535
|
+
poolRecordCount: "number",
|
|
536
|
+
flammableParameters: "Entities.FlammableParameters",
|
|
537
|
+
};
|
|
538
|
+
}
|
|
539
|
+
|
|
540
|
+
validate(data: ModifyFuelRateForJetFireCalculationRequestSchemaData): ModifyFuelRateForJetFireCalculationRequest {
|
|
541
|
+
const { error, value } = this.schema.validate(data, { abortEarly: false });
|
|
542
|
+
if (error) {
|
|
543
|
+
throw new Error(`Validation error: ${error.details.map((x) => x.message).join(", ")}`);
|
|
544
|
+
}
|
|
545
|
+
return this.makeCalculationRequest(value);
|
|
546
|
+
}
|
|
547
|
+
|
|
548
|
+
makeCalculationRequest(data: ModifyFuelRateForJetFireCalculationRequestSchemaData): ModifyFuelRateForJetFireCalculationRequest {
|
|
549
|
+
return new ModifyFuelRateForJetFireCalculationRequest(
|
|
550
|
+
data.dischargeRecords,
|
|
551
|
+
data.dischargeRecordCount,
|
|
552
|
+
data.poolRecords,
|
|
553
|
+
data.poolRecordCount,
|
|
554
|
+
data.flammableParameters
|
|
555
|
+
);
|
|
556
|
+
}
|
|
557
|
+
}
|
|
558
|
+
|
|
559
|
+
export class ModifyFuelRateForJetFireCalculation extends CalculationBase {
|
|
560
|
+
dischargeRecords: Entities.DischargeRecord[];
|
|
561
|
+
dischargeRecordCount: number;
|
|
562
|
+
poolRecords: Entities.PoolRecord[];
|
|
563
|
+
poolRecordCount: number;
|
|
564
|
+
flammableParameters: Entities.FlammableParameters;
|
|
565
|
+
modDischargeRecords?: Entities.DischargeRecord[];
|
|
566
|
+
|
|
567
|
+
/**
|
|
568
|
+
* This method corrects the discharge records' mass flow prior to the jet fire model to account for the fraction of material that rains out in the case of delayed ignition. With delayed ignition it is assumed that the ignition happens after the pool has formed for
|
|
569
|
+
the cases of two-phase or liquid releases. As a result it is more accurate to account for the portion of mass that rains out and doesn't form
|
|
570
|
+
part of the jet fire. If we are modelling immediate ignition, the whole mass flow rate from the discharge calculation should be
|
|
571
|
+
taken into account. In cases where 33% or more of the discharged mass vaporises, experimental data on fireballs
|
|
572
|
+
(Hasegawa and Sato, 1977 and Roberts, 1982) found that the whole discharged mass should be the fuel mass used in fire models. CCPS later
|
|
573
|
+
adapted this to a rule set of 33%. Thus, this correction only applies for cases where more than 67% of the mass rains out.
|
|
574
|
+
*
|
|
575
|
+
* @param {Entities.DischargeRecord[]} dischargeRecords - Discharge records.
|
|
576
|
+
* @param {number} dischargeRecordCount - Number of discharge records.
|
|
577
|
+
* @param {Entities.PoolRecord[]} poolRecords - Pool records.
|
|
578
|
+
* @param {number} poolRecordCount - Number of pool records.
|
|
579
|
+
* @param {Entities.FlammableParameters} flammableParameters - Flammable parameters.
|
|
580
|
+
*/
|
|
581
|
+
constructor(
|
|
582
|
+
dischargeRecords: Entities.DischargeRecord[],
|
|
583
|
+
dischargeRecordCount: number,
|
|
584
|
+
poolRecords: Entities.PoolRecord[],
|
|
585
|
+
poolRecordCount: number,
|
|
586
|
+
flammableParameters: Entities.FlammableParameters
|
|
587
|
+
) {
|
|
588
|
+
super();
|
|
589
|
+
this.dischargeRecords = dischargeRecords;
|
|
590
|
+
this.dischargeRecordCount = dischargeRecordCount;
|
|
591
|
+
this.poolRecords = poolRecords;
|
|
592
|
+
this.poolRecordCount = poolRecordCount;
|
|
593
|
+
this.flammableParameters = flammableParameters;
|
|
594
|
+
}
|
|
595
|
+
|
|
596
|
+
async run() {
|
|
597
|
+
try {
|
|
598
|
+
const request = new ModifyFuelRateForJetFireCalculationRequest(
|
|
599
|
+
this.dischargeRecords,
|
|
600
|
+
this.dischargeRecordCount,
|
|
601
|
+
this.poolRecords,
|
|
602
|
+
this.poolRecordCount,
|
|
603
|
+
this.flammableParameters
|
|
604
|
+
);
|
|
605
|
+
|
|
606
|
+
const schema = new ModifyFuelRateForJetFireCalculationRequestSchema();
|
|
607
|
+
const validatedRequest = schema.validate(request);
|
|
608
|
+
|
|
609
|
+
const requestJson = JSON.stringify(validatedRequest);
|
|
610
|
+
const url = `${getAnalyticsApiTarget()}ModifyFuelRateForJetFire?clientId=${getClientAliasId()}`;
|
|
611
|
+
|
|
612
|
+
this.resultCode = Enums.ResultCode.UNEXPECTED_APPLICATION_ERROR;
|
|
613
|
+
|
|
614
|
+
const response = await this.postRequest(url, requestJson);
|
|
615
|
+
|
|
616
|
+
if (response.status >= 200 && response.status < 300) {
|
|
617
|
+
const schema = new ModifyFuelRateForJetFireCalculationResponseSchema();
|
|
618
|
+
const validatedResponse = schema.validate(response.data);
|
|
619
|
+
|
|
620
|
+
this.resultCode = validatedResponse.resultCode;
|
|
621
|
+
if (this.resultCode === Enums.ResultCode.SUCCESS) {
|
|
622
|
+
this.modDischargeRecords = validatedResponse.modDischargeRecords;
|
|
623
|
+
this.resultCode = validatedResponse.resultCode;
|
|
624
|
+
this.messages = validatedResponse.messages ?? [];
|
|
625
|
+
this.calculationElapsedTime = validatedResponse.calculationElapsedTime;
|
|
626
|
+
this.operationId = validatedResponse.operationId;
|
|
627
|
+
} else {
|
|
628
|
+
this.messages.push(...(validatedResponse.messages ?? []));
|
|
629
|
+
}
|
|
630
|
+
} else {
|
|
631
|
+
this.handleFailedResponse(response);
|
|
632
|
+
}
|
|
633
|
+
} catch (error) {
|
|
634
|
+
if (error instanceof Error) {
|
|
635
|
+
this.messages.push(`Error: ${error.message}`);
|
|
636
|
+
} else {
|
|
637
|
+
this.messages.push(`Unexpected error: ${JSON.stringify(error)}`);
|
|
638
|
+
}
|
|
639
|
+
console.error(error);
|
|
640
|
+
this.resultCode = Enums.ResultCode.UNEXPECTED_APPLICATION_ERROR;
|
|
641
|
+
}
|
|
642
|
+
|
|
643
|
+
return this.resultCode;
|
|
644
|
+
}
|
|
645
|
+
|
|
646
|
+
toString() {
|
|
647
|
+
const parts = ["* ModifyFuelRateForJetFire"];
|
|
648
|
+
|
|
649
|
+
parts.push("*** modDischargeRecords:");
|
|
650
|
+
parts.push(
|
|
651
|
+
this.modDischargeRecords && this.modDischargeRecords.length > 0
|
|
652
|
+
? this.modDischargeRecords.map((point) => `modDischargeRecordsElement: ${point}`).join("\n")
|
|
653
|
+
: "modDischargeRecords does not contain any elements"
|
|
654
|
+
);
|
|
655
|
+
parts.push(`resultCode: ${String(this.resultCode)}`);
|
|
656
|
+
parts.push("*** messages:");
|
|
657
|
+
parts.push(`messages: ${this.messages !== undefined ? this.messages : "(None)"}`);
|
|
658
|
+
parts.push(`calculationElapsedTime: ${this.calculationElapsedTime !== undefined ? this.calculationElapsedTime : "(None)"}`);
|
|
659
|
+
parts.push(`operationId: ${this.operationId !== undefined ? this.operationId : "(None)"}`);
|
|
660
|
+
|
|
661
|
+
return parts.join("\n");
|
|
662
|
+
}
|
|
663
|
+
}
|
|
664
|
+
|
|
665
|
+
export class ModifyFuelRateForJetFireCalculationResponse extends CalculationResponseBase {
|
|
666
|
+
modDischargeRecords: Entities.DischargeRecord[];
|
|
667
|
+
|
|
668
|
+
/**
|
|
669
|
+
* ModifyFuelRateForJetFire calculation response class.
|
|
670
|
+
*
|
|
671
|
+
* @param {Entities.DischargeRecord[]} modDischargeRecords - Modified discharge records.
|
|
672
|
+
*/
|
|
673
|
+
constructor(
|
|
674
|
+
modDischargeRecords: Entities.DischargeRecord[],
|
|
675
|
+
resultCode: Enums.ResultCode,
|
|
676
|
+
messages: string[],
|
|
677
|
+
calculationElapsedTime: number,
|
|
678
|
+
operationId: string
|
|
679
|
+
) {
|
|
680
|
+
super();
|
|
681
|
+
this.modDischargeRecords = modDischargeRecords;
|
|
682
|
+
this.resultCode = resultCode;
|
|
683
|
+
this.messages = messages;
|
|
684
|
+
this.calculationElapsedTime = calculationElapsedTime;
|
|
685
|
+
this.operationId = operationId;
|
|
686
|
+
}
|
|
687
|
+
|
|
688
|
+
initialiseFromDictionary(data: { [key: string]: unknown }) {
|
|
689
|
+
if (data.modDischargeRecords && Array.isArray(data.modDischargeRecords)) {
|
|
690
|
+
this.modDischargeRecords = data.modDischargeRecords.map(
|
|
691
|
+
(item) => {
|
|
692
|
+
const record = new Entities.DischargeRecord();
|
|
693
|
+
record.initialiseFromDictionary(item);
|
|
694
|
+
return record;
|
|
695
|
+
}
|
|
696
|
+
);
|
|
697
|
+
}
|
|
698
|
+
if (data.resultCode !== undefined && (typeof data.resultCode === "string" || typeof data.resultCode === "number")) {
|
|
699
|
+
this.resultCode = data.resultCode as Enums.ResultCode;
|
|
700
|
+
}
|
|
701
|
+
this.messages = this.messages ?? [];
|
|
702
|
+
if (data.messages && Array.isArray(data.messages)) {
|
|
703
|
+
this.messages.push(...data.messages);
|
|
704
|
+
}
|
|
705
|
+
if (data.calculationElapsedTime !== undefined && typeof data.calculationElapsedTime === "number") {
|
|
706
|
+
this.calculationElapsedTime = data.calculationElapsedTime as number;
|
|
707
|
+
}
|
|
708
|
+
if (data.operationId !== undefined && typeof data.operationId === "string") {
|
|
709
|
+
this.operationId = data.operationId as string;
|
|
710
|
+
}
|
|
711
|
+
}
|
|
712
|
+
}
|
|
713
|
+
|
|
714
|
+
export interface ModifyFuelRateForJetFireCalculationResponseSchemaData {
|
|
715
|
+
modDischargeRecords: Entities.DischargeRecord[];
|
|
716
|
+
resultCode: Enums.ResultCode;
|
|
717
|
+
messages: string[];
|
|
718
|
+
calculationElapsedTime: number;
|
|
719
|
+
operationId: string;
|
|
720
|
+
}
|
|
721
|
+
|
|
722
|
+
export class ModifyFuelRateForJetFireCalculationResponseSchema {
|
|
723
|
+
schema: Joi.ObjectSchema;
|
|
724
|
+
propertyTypes: Record<string, string>;
|
|
725
|
+
|
|
726
|
+
/**
|
|
727
|
+
* Schema for the ModifyFuelRateForJetFire calculation response.
|
|
728
|
+
*/
|
|
729
|
+
constructor() {
|
|
730
|
+
this.schema = Joi.object({
|
|
731
|
+
modDischargeRecords: Joi.array().items(new EntitySchemas.DischargeRecordSchema().schema).allow(null),
|
|
732
|
+
resultCode: Joi.string().valid(...Object.values(Enums.ResultCode)),
|
|
733
|
+
messages: Joi.array().items(Joi.string()),
|
|
734
|
+
calculationElapsedTime: Joi.number().unsafe(),
|
|
735
|
+
operationId: Joi.string().uuid().allow(null),
|
|
736
|
+
}).unknown(true);
|
|
737
|
+
|
|
738
|
+
this.propertyTypes = {
|
|
739
|
+
modDischargeRecords: "Entities.DischargeRecord[]",
|
|
740
|
+
};
|
|
741
|
+
}
|
|
742
|
+
|
|
743
|
+
validate(data: ModifyFuelRateForJetFireCalculationResponseSchemaData): ModifyFuelRateForJetFireCalculationResponse {
|
|
744
|
+
const { error, value } = this.schema.validate(data, { abortEarly: false });
|
|
745
|
+
if (error) {
|
|
746
|
+
throw new Error(`Validation error: ${error.details.map((x) => x.message).join(", ")}`);
|
|
747
|
+
}
|
|
748
|
+
return this.makeCalculationResponse(value);
|
|
749
|
+
}
|
|
750
|
+
|
|
751
|
+
makeCalculationResponse(data: ModifyFuelRateForJetFireCalculationResponseSchemaData): ModifyFuelRateForJetFireCalculationResponse {
|
|
752
|
+
return new ModifyFuelRateForJetFireCalculationResponse(
|
|
753
|
+
data.modDischargeRecords,
|
|
754
|
+
data.resultCode,
|
|
755
|
+
data.messages,
|
|
756
|
+
data.calculationElapsedTime,
|
|
757
|
+
data.operationId
|
|
758
|
+
);
|
|
759
|
+
}
|
|
760
|
+
}
|