@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,3320 @@
|
|
|
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 ConvertCompositionMassToMoleCalculationRequestSchemaData {
|
|
151
|
+
mixture: Entities.Material;
|
|
152
|
+
compositionMass: number[];
|
|
153
|
+
compositionMassCount: number;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
class ConvertCompositionMassToMoleCalculationRequest extends CalculationRequestBase {
|
|
157
|
+
mixture: Entities.Material;
|
|
158
|
+
compositionMass: number[];
|
|
159
|
+
compositionMassCount: number;
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* ConvertCompositionMassToMole calculation request class.
|
|
163
|
+
*
|
|
164
|
+
* @param {Entities.Material} mixture - A Material entity with two or more Material Components to have composition converted.
|
|
165
|
+
* @param {number[]} compositionMass - Array of mass fractions.
|
|
166
|
+
* @param {number} compositionMassCount - Number of components in mixture.
|
|
167
|
+
*/
|
|
168
|
+
constructor(
|
|
169
|
+
mixture: Entities.Material,
|
|
170
|
+
compositionMass: number[],
|
|
171
|
+
compositionMassCount: number
|
|
172
|
+
) {
|
|
173
|
+
super();
|
|
174
|
+
this.mixture = mixture;
|
|
175
|
+
this.compositionMass = compositionMass;
|
|
176
|
+
this.compositionMassCount = compositionMassCount;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
export class ConvertCompositionMassToMoleCalculationRequestSchema {
|
|
181
|
+
schema: Joi.ObjectSchema;
|
|
182
|
+
propertyTypes: Record<string, string>;
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* Schema for the ConvertCompositionMassToMole calculation request.
|
|
186
|
+
*/
|
|
187
|
+
constructor() {
|
|
188
|
+
this.schema = Joi.object({
|
|
189
|
+
mixture: new EntitySchemas.MaterialSchema().schema,
|
|
190
|
+
compositionMass: Joi.array().items(Joi.number().unsafe()).allow(null),
|
|
191
|
+
compositionMassCount: Joi.number().integer(),
|
|
192
|
+
}).unknown(true);
|
|
193
|
+
|
|
194
|
+
this.propertyTypes = {
|
|
195
|
+
mixture: "Entities.Material",
|
|
196
|
+
compositionMass: "number[]",
|
|
197
|
+
compositionMassCount: "number",
|
|
198
|
+
};
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
validate(data: ConvertCompositionMassToMoleCalculationRequestSchemaData): ConvertCompositionMassToMoleCalculationRequest {
|
|
202
|
+
const { error, value } = this.schema.validate(data, { abortEarly: false });
|
|
203
|
+
if (error) {
|
|
204
|
+
throw new Error(`Validation error: ${error.details.map((x) => x.message).join(", ")}`);
|
|
205
|
+
}
|
|
206
|
+
return this.makeCalculationRequest(value);
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
makeCalculationRequest(data: ConvertCompositionMassToMoleCalculationRequestSchemaData): ConvertCompositionMassToMoleCalculationRequest {
|
|
210
|
+
return new ConvertCompositionMassToMoleCalculationRequest(
|
|
211
|
+
data.mixture,
|
|
212
|
+
data.compositionMass,
|
|
213
|
+
data.compositionMassCount
|
|
214
|
+
);
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
export class ConvertCompositionMassToMoleCalculation extends CalculationBase {
|
|
219
|
+
mixture: Entities.Material;
|
|
220
|
+
compositionMass: number[];
|
|
221
|
+
compositionMassCount: number;
|
|
222
|
+
compositionMole?: number[];
|
|
223
|
+
|
|
224
|
+
/**
|
|
225
|
+
* Converts mixture composition from mass to mole basis.
|
|
226
|
+
*
|
|
227
|
+
* @param {Entities.Material} mixture - A Material entity with two or more Material Components to have composition converted.
|
|
228
|
+
* @param {number[]} compositionMass - Array of mass fractions.
|
|
229
|
+
* @param {number} compositionMassCount - Number of components in mixture.
|
|
230
|
+
*/
|
|
231
|
+
constructor(
|
|
232
|
+
mixture: Entities.Material,
|
|
233
|
+
compositionMass: number[],
|
|
234
|
+
compositionMassCount: number
|
|
235
|
+
) {
|
|
236
|
+
super();
|
|
237
|
+
this.mixture = mixture;
|
|
238
|
+
this.compositionMass = compositionMass;
|
|
239
|
+
this.compositionMassCount = compositionMassCount;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
async run() {
|
|
243
|
+
try {
|
|
244
|
+
const request = new ConvertCompositionMassToMoleCalculationRequest(
|
|
245
|
+
this.mixture,
|
|
246
|
+
this.compositionMass,
|
|
247
|
+
this.compositionMassCount
|
|
248
|
+
);
|
|
249
|
+
|
|
250
|
+
const schema = new ConvertCompositionMassToMoleCalculationRequestSchema();
|
|
251
|
+
const validatedRequest = schema.validate(request);
|
|
252
|
+
|
|
253
|
+
const requestJson = JSON.stringify(validatedRequest);
|
|
254
|
+
const url = `${getAnalyticsApiTarget()}utilities/convertcompositionmasstomole?clientId=${getClientAliasId()}`;
|
|
255
|
+
|
|
256
|
+
this.resultCode = Enums.ResultCode.UNEXPECTED_APPLICATION_ERROR;
|
|
257
|
+
|
|
258
|
+
const response = await this.postRequest(url, requestJson);
|
|
259
|
+
|
|
260
|
+
if (response.status >= 200 && response.status < 300) {
|
|
261
|
+
const schema = new ConvertCompositionMassToMoleCalculationResponseSchema();
|
|
262
|
+
const validatedResponse = schema.validate(response.data);
|
|
263
|
+
|
|
264
|
+
this.resultCode = validatedResponse.resultCode;
|
|
265
|
+
if (this.resultCode === Enums.ResultCode.SUCCESS) {
|
|
266
|
+
this.compositionMole = validatedResponse.compositionMole;
|
|
267
|
+
this.resultCode = validatedResponse.resultCode;
|
|
268
|
+
this.messages = validatedResponse.messages ?? [];
|
|
269
|
+
this.calculationElapsedTime = validatedResponse.calculationElapsedTime;
|
|
270
|
+
this.operationId = validatedResponse.operationId;
|
|
271
|
+
} else {
|
|
272
|
+
this.messages.push(...(validatedResponse.messages ?? []));
|
|
273
|
+
}
|
|
274
|
+
} else {
|
|
275
|
+
this.handleFailedResponse(response);
|
|
276
|
+
}
|
|
277
|
+
} catch (error) {
|
|
278
|
+
if (error instanceof Error) {
|
|
279
|
+
this.messages.push(`Error: ${error.message}`);
|
|
280
|
+
} else {
|
|
281
|
+
this.messages.push(`Unexpected error: ${JSON.stringify(error)}`);
|
|
282
|
+
}
|
|
283
|
+
console.error(error);
|
|
284
|
+
this.resultCode = Enums.ResultCode.UNEXPECTED_APPLICATION_ERROR;
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
return this.resultCode;
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
toString() {
|
|
291
|
+
const parts = ["* ConvertCompositionMassToMole"];
|
|
292
|
+
|
|
293
|
+
parts.push("*** compositionMole:");
|
|
294
|
+
parts.push(
|
|
295
|
+
this.compositionMole && this.compositionMole.length > 0
|
|
296
|
+
? this.compositionMole.map((point) => `compositionMoleElement: ${point}`).join("\n")
|
|
297
|
+
: "compositionMole does not contain any elements"
|
|
298
|
+
);
|
|
299
|
+
parts.push(`resultCode: ${String(this.resultCode)}`);
|
|
300
|
+
parts.push("*** messages:");
|
|
301
|
+
parts.push(`messages: ${this.messages !== undefined ? this.messages : "(None)"}`);
|
|
302
|
+
parts.push(`calculationElapsedTime: ${this.calculationElapsedTime !== undefined ? this.calculationElapsedTime : "(None)"}`);
|
|
303
|
+
parts.push(`operationId: ${this.operationId !== undefined ? this.operationId : "(None)"}`);
|
|
304
|
+
|
|
305
|
+
return parts.join("\n");
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
export class ConvertCompositionMassToMoleCalculationResponse extends CalculationResponseBase {
|
|
310
|
+
compositionMole: number[];
|
|
311
|
+
|
|
312
|
+
/**
|
|
313
|
+
* ConvertCompositionMassToMole calculation response class.
|
|
314
|
+
*
|
|
315
|
+
* @param {number[]} compositionMole - Array of mole fractions.
|
|
316
|
+
*/
|
|
317
|
+
constructor(
|
|
318
|
+
compositionMole: number[],
|
|
319
|
+
resultCode: Enums.ResultCode,
|
|
320
|
+
messages: string[],
|
|
321
|
+
calculationElapsedTime: number,
|
|
322
|
+
operationId: string
|
|
323
|
+
) {
|
|
324
|
+
super();
|
|
325
|
+
this.compositionMole = compositionMole;
|
|
326
|
+
this.resultCode = resultCode;
|
|
327
|
+
this.messages = messages;
|
|
328
|
+
this.calculationElapsedTime = calculationElapsedTime;
|
|
329
|
+
this.operationId = operationId;
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
initialiseFromDictionary(data: { [key: string]: unknown }) {
|
|
333
|
+
if (data.compositionMole && Array.isArray(data.compositionMole)) {
|
|
334
|
+
this.compositionMole = data.compositionMole.map((item) => parseFloat(item));
|
|
335
|
+
}
|
|
336
|
+
if (data.resultCode !== undefined && (typeof data.resultCode === "string" || typeof data.resultCode === "number")) {
|
|
337
|
+
this.resultCode = data.resultCode as Enums.ResultCode;
|
|
338
|
+
}
|
|
339
|
+
this.messages = this.messages ?? [];
|
|
340
|
+
if (data.messages && Array.isArray(data.messages)) {
|
|
341
|
+
this.messages.push(...data.messages);
|
|
342
|
+
}
|
|
343
|
+
if (data.calculationElapsedTime !== undefined && typeof data.calculationElapsedTime === "number") {
|
|
344
|
+
this.calculationElapsedTime = data.calculationElapsedTime as number;
|
|
345
|
+
}
|
|
346
|
+
if (data.operationId !== undefined && typeof data.operationId === "string") {
|
|
347
|
+
this.operationId = data.operationId as string;
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
export interface ConvertCompositionMassToMoleCalculationResponseSchemaData {
|
|
353
|
+
compositionMole: number[];
|
|
354
|
+
resultCode: Enums.ResultCode;
|
|
355
|
+
messages: string[];
|
|
356
|
+
calculationElapsedTime: number;
|
|
357
|
+
operationId: string;
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
export class ConvertCompositionMassToMoleCalculationResponseSchema {
|
|
361
|
+
schema: Joi.ObjectSchema;
|
|
362
|
+
propertyTypes: Record<string, string>;
|
|
363
|
+
|
|
364
|
+
/**
|
|
365
|
+
* Schema for the ConvertCompositionMassToMole calculation response.
|
|
366
|
+
*/
|
|
367
|
+
constructor() {
|
|
368
|
+
this.schema = Joi.object({
|
|
369
|
+
compositionMole: Joi.array().items(Joi.number().unsafe()).allow(null),
|
|
370
|
+
resultCode: Joi.string().valid(...Object.values(Enums.ResultCode)),
|
|
371
|
+
messages: Joi.array().items(Joi.string()),
|
|
372
|
+
calculationElapsedTime: Joi.number().unsafe(),
|
|
373
|
+
operationId: Joi.string().uuid().allow(null),
|
|
374
|
+
}).unknown(true);
|
|
375
|
+
|
|
376
|
+
this.propertyTypes = {
|
|
377
|
+
compositionMole: "number[]",
|
|
378
|
+
};
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
validate(data: ConvertCompositionMassToMoleCalculationResponseSchemaData): ConvertCompositionMassToMoleCalculationResponse {
|
|
382
|
+
const { error, value } = this.schema.validate(data, { abortEarly: false });
|
|
383
|
+
if (error) {
|
|
384
|
+
throw new Error(`Validation error: ${error.details.map((x) => x.message).join(", ")}`);
|
|
385
|
+
}
|
|
386
|
+
return this.makeCalculationResponse(value);
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
makeCalculationResponse(data: ConvertCompositionMassToMoleCalculationResponseSchemaData): ConvertCompositionMassToMoleCalculationResponse {
|
|
390
|
+
return new ConvertCompositionMassToMoleCalculationResponse(
|
|
391
|
+
data.compositionMole,
|
|
392
|
+
data.resultCode,
|
|
393
|
+
data.messages,
|
|
394
|
+
data.calculationElapsedTime,
|
|
395
|
+
data.operationId
|
|
396
|
+
);
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
export interface ConvertCompositionMoleToMassCalculationRequestSchemaData {
|
|
401
|
+
mixture: Entities.Material;
|
|
402
|
+
compositionMoles: number[];
|
|
403
|
+
compositionMolesCount: number;
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
class ConvertCompositionMoleToMassCalculationRequest extends CalculationRequestBase {
|
|
407
|
+
mixture: Entities.Material;
|
|
408
|
+
compositionMoles: number[];
|
|
409
|
+
compositionMolesCount: number;
|
|
410
|
+
|
|
411
|
+
/**
|
|
412
|
+
* ConvertCompositionMoleToMass calculation request class.
|
|
413
|
+
*
|
|
414
|
+
* @param {Entities.Material} mixture - A Material entity with two or more Material Components to have composition converted.
|
|
415
|
+
* @param {number[]} compositionMoles - Array of mole fractions.
|
|
416
|
+
* @param {number} compositionMolesCount - Number of components in mixture.
|
|
417
|
+
*/
|
|
418
|
+
constructor(
|
|
419
|
+
mixture: Entities.Material,
|
|
420
|
+
compositionMoles: number[],
|
|
421
|
+
compositionMolesCount: number
|
|
422
|
+
) {
|
|
423
|
+
super();
|
|
424
|
+
this.mixture = mixture;
|
|
425
|
+
this.compositionMoles = compositionMoles;
|
|
426
|
+
this.compositionMolesCount = compositionMolesCount;
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
export class ConvertCompositionMoleToMassCalculationRequestSchema {
|
|
431
|
+
schema: Joi.ObjectSchema;
|
|
432
|
+
propertyTypes: Record<string, string>;
|
|
433
|
+
|
|
434
|
+
/**
|
|
435
|
+
* Schema for the ConvertCompositionMoleToMass calculation request.
|
|
436
|
+
*/
|
|
437
|
+
constructor() {
|
|
438
|
+
this.schema = Joi.object({
|
|
439
|
+
mixture: new EntitySchemas.MaterialSchema().schema,
|
|
440
|
+
compositionMoles: Joi.array().items(Joi.number().unsafe()).allow(null),
|
|
441
|
+
compositionMolesCount: Joi.number().integer(),
|
|
442
|
+
}).unknown(true);
|
|
443
|
+
|
|
444
|
+
this.propertyTypes = {
|
|
445
|
+
mixture: "Entities.Material",
|
|
446
|
+
compositionMoles: "number[]",
|
|
447
|
+
compositionMolesCount: "number",
|
|
448
|
+
};
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
validate(data: ConvertCompositionMoleToMassCalculationRequestSchemaData): ConvertCompositionMoleToMassCalculationRequest {
|
|
452
|
+
const { error, value } = this.schema.validate(data, { abortEarly: false });
|
|
453
|
+
if (error) {
|
|
454
|
+
throw new Error(`Validation error: ${error.details.map((x) => x.message).join(", ")}`);
|
|
455
|
+
}
|
|
456
|
+
return this.makeCalculationRequest(value);
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
makeCalculationRequest(data: ConvertCompositionMoleToMassCalculationRequestSchemaData): ConvertCompositionMoleToMassCalculationRequest {
|
|
460
|
+
return new ConvertCompositionMoleToMassCalculationRequest(
|
|
461
|
+
data.mixture,
|
|
462
|
+
data.compositionMoles,
|
|
463
|
+
data.compositionMolesCount
|
|
464
|
+
);
|
|
465
|
+
}
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
export class ConvertCompositionMoleToMassCalculation extends CalculationBase {
|
|
469
|
+
mixture: Entities.Material;
|
|
470
|
+
compositionMoles: number[];
|
|
471
|
+
compositionMolesCount: number;
|
|
472
|
+
compositionMass?: number[];
|
|
473
|
+
|
|
474
|
+
/**
|
|
475
|
+
* Converts mixture composition from mole to mass basis.
|
|
476
|
+
*
|
|
477
|
+
* @param {Entities.Material} mixture - A Material entity with two or more Material Components to have composition converted.
|
|
478
|
+
* @param {number[]} compositionMoles - Array of mole fractions.
|
|
479
|
+
* @param {number} compositionMolesCount - Number of components in mixture.
|
|
480
|
+
*/
|
|
481
|
+
constructor(
|
|
482
|
+
mixture: Entities.Material,
|
|
483
|
+
compositionMoles: number[],
|
|
484
|
+
compositionMolesCount: number
|
|
485
|
+
) {
|
|
486
|
+
super();
|
|
487
|
+
this.mixture = mixture;
|
|
488
|
+
this.compositionMoles = compositionMoles;
|
|
489
|
+
this.compositionMolesCount = compositionMolesCount;
|
|
490
|
+
}
|
|
491
|
+
|
|
492
|
+
async run() {
|
|
493
|
+
try {
|
|
494
|
+
const request = new ConvertCompositionMoleToMassCalculationRequest(
|
|
495
|
+
this.mixture,
|
|
496
|
+
this.compositionMoles,
|
|
497
|
+
this.compositionMolesCount
|
|
498
|
+
);
|
|
499
|
+
|
|
500
|
+
const schema = new ConvertCompositionMoleToMassCalculationRequestSchema();
|
|
501
|
+
const validatedRequest = schema.validate(request);
|
|
502
|
+
|
|
503
|
+
const requestJson = JSON.stringify(validatedRequest);
|
|
504
|
+
const url = `${getAnalyticsApiTarget()}utilities/convertcompositionmoletomass?clientId=${getClientAliasId()}`;
|
|
505
|
+
|
|
506
|
+
this.resultCode = Enums.ResultCode.UNEXPECTED_APPLICATION_ERROR;
|
|
507
|
+
|
|
508
|
+
const response = await this.postRequest(url, requestJson);
|
|
509
|
+
|
|
510
|
+
if (response.status >= 200 && response.status < 300) {
|
|
511
|
+
const schema = new ConvertCompositionMoleToMassCalculationResponseSchema();
|
|
512
|
+
const validatedResponse = schema.validate(response.data);
|
|
513
|
+
|
|
514
|
+
this.resultCode = validatedResponse.resultCode;
|
|
515
|
+
if (this.resultCode === Enums.ResultCode.SUCCESS) {
|
|
516
|
+
this.compositionMass = validatedResponse.compositionMass;
|
|
517
|
+
this.resultCode = validatedResponse.resultCode;
|
|
518
|
+
this.messages = validatedResponse.messages ?? [];
|
|
519
|
+
this.calculationElapsedTime = validatedResponse.calculationElapsedTime;
|
|
520
|
+
this.operationId = validatedResponse.operationId;
|
|
521
|
+
} else {
|
|
522
|
+
this.messages.push(...(validatedResponse.messages ?? []));
|
|
523
|
+
}
|
|
524
|
+
} else {
|
|
525
|
+
this.handleFailedResponse(response);
|
|
526
|
+
}
|
|
527
|
+
} catch (error) {
|
|
528
|
+
if (error instanceof Error) {
|
|
529
|
+
this.messages.push(`Error: ${error.message}`);
|
|
530
|
+
} else {
|
|
531
|
+
this.messages.push(`Unexpected error: ${JSON.stringify(error)}`);
|
|
532
|
+
}
|
|
533
|
+
console.error(error);
|
|
534
|
+
this.resultCode = Enums.ResultCode.UNEXPECTED_APPLICATION_ERROR;
|
|
535
|
+
}
|
|
536
|
+
|
|
537
|
+
return this.resultCode;
|
|
538
|
+
}
|
|
539
|
+
|
|
540
|
+
toString() {
|
|
541
|
+
const parts = ["* ConvertCompositionMoleToMass"];
|
|
542
|
+
|
|
543
|
+
parts.push("*** compositionMass:");
|
|
544
|
+
parts.push(
|
|
545
|
+
this.compositionMass && this.compositionMass.length > 0
|
|
546
|
+
? this.compositionMass.map((point) => `compositionMassElement: ${point}`).join("\n")
|
|
547
|
+
: "compositionMass does not contain any elements"
|
|
548
|
+
);
|
|
549
|
+
parts.push(`resultCode: ${String(this.resultCode)}`);
|
|
550
|
+
parts.push("*** messages:");
|
|
551
|
+
parts.push(`messages: ${this.messages !== undefined ? this.messages : "(None)"}`);
|
|
552
|
+
parts.push(`calculationElapsedTime: ${this.calculationElapsedTime !== undefined ? this.calculationElapsedTime : "(None)"}`);
|
|
553
|
+
parts.push(`operationId: ${this.operationId !== undefined ? this.operationId : "(None)"}`);
|
|
554
|
+
|
|
555
|
+
return parts.join("\n");
|
|
556
|
+
}
|
|
557
|
+
}
|
|
558
|
+
|
|
559
|
+
export class ConvertCompositionMoleToMassCalculationResponse extends CalculationResponseBase {
|
|
560
|
+
compositionMass: number[];
|
|
561
|
+
|
|
562
|
+
/**
|
|
563
|
+
* ConvertCompositionMoleToMass calculation response class.
|
|
564
|
+
*
|
|
565
|
+
* @param {number[]} compositionMass - Array of mass fractions.
|
|
566
|
+
*/
|
|
567
|
+
constructor(
|
|
568
|
+
compositionMass: number[],
|
|
569
|
+
resultCode: Enums.ResultCode,
|
|
570
|
+
messages: string[],
|
|
571
|
+
calculationElapsedTime: number,
|
|
572
|
+
operationId: string
|
|
573
|
+
) {
|
|
574
|
+
super();
|
|
575
|
+
this.compositionMass = compositionMass;
|
|
576
|
+
this.resultCode = resultCode;
|
|
577
|
+
this.messages = messages;
|
|
578
|
+
this.calculationElapsedTime = calculationElapsedTime;
|
|
579
|
+
this.operationId = operationId;
|
|
580
|
+
}
|
|
581
|
+
|
|
582
|
+
initialiseFromDictionary(data: { [key: string]: unknown }) {
|
|
583
|
+
if (data.compositionMass && Array.isArray(data.compositionMass)) {
|
|
584
|
+
this.compositionMass = data.compositionMass.map((item) => parseFloat(item));
|
|
585
|
+
}
|
|
586
|
+
if (data.resultCode !== undefined && (typeof data.resultCode === "string" || typeof data.resultCode === "number")) {
|
|
587
|
+
this.resultCode = data.resultCode as Enums.ResultCode;
|
|
588
|
+
}
|
|
589
|
+
this.messages = this.messages ?? [];
|
|
590
|
+
if (data.messages && Array.isArray(data.messages)) {
|
|
591
|
+
this.messages.push(...data.messages);
|
|
592
|
+
}
|
|
593
|
+
if (data.calculationElapsedTime !== undefined && typeof data.calculationElapsedTime === "number") {
|
|
594
|
+
this.calculationElapsedTime = data.calculationElapsedTime as number;
|
|
595
|
+
}
|
|
596
|
+
if (data.operationId !== undefined && typeof data.operationId === "string") {
|
|
597
|
+
this.operationId = data.operationId as string;
|
|
598
|
+
}
|
|
599
|
+
}
|
|
600
|
+
}
|
|
601
|
+
|
|
602
|
+
export interface ConvertCompositionMoleToMassCalculationResponseSchemaData {
|
|
603
|
+
compositionMass: number[];
|
|
604
|
+
resultCode: Enums.ResultCode;
|
|
605
|
+
messages: string[];
|
|
606
|
+
calculationElapsedTime: number;
|
|
607
|
+
operationId: string;
|
|
608
|
+
}
|
|
609
|
+
|
|
610
|
+
export class ConvertCompositionMoleToMassCalculationResponseSchema {
|
|
611
|
+
schema: Joi.ObjectSchema;
|
|
612
|
+
propertyTypes: Record<string, string>;
|
|
613
|
+
|
|
614
|
+
/**
|
|
615
|
+
* Schema for the ConvertCompositionMoleToMass calculation response.
|
|
616
|
+
*/
|
|
617
|
+
constructor() {
|
|
618
|
+
this.schema = Joi.object({
|
|
619
|
+
compositionMass: Joi.array().items(Joi.number().unsafe()).allow(null),
|
|
620
|
+
resultCode: Joi.string().valid(...Object.values(Enums.ResultCode)),
|
|
621
|
+
messages: Joi.array().items(Joi.string()),
|
|
622
|
+
calculationElapsedTime: Joi.number().unsafe(),
|
|
623
|
+
operationId: Joi.string().uuid().allow(null),
|
|
624
|
+
}).unknown(true);
|
|
625
|
+
|
|
626
|
+
this.propertyTypes = {
|
|
627
|
+
compositionMass: "number[]",
|
|
628
|
+
};
|
|
629
|
+
}
|
|
630
|
+
|
|
631
|
+
validate(data: ConvertCompositionMoleToMassCalculationResponseSchemaData): ConvertCompositionMoleToMassCalculationResponse {
|
|
632
|
+
const { error, value } = this.schema.validate(data, { abortEarly: false });
|
|
633
|
+
if (error) {
|
|
634
|
+
throw new Error(`Validation error: ${error.details.map((x) => x.message).join(", ")}`);
|
|
635
|
+
}
|
|
636
|
+
return this.makeCalculationResponse(value);
|
|
637
|
+
}
|
|
638
|
+
|
|
639
|
+
makeCalculationResponse(data: ConvertCompositionMoleToMassCalculationResponseSchemaData): ConvertCompositionMoleToMassCalculationResponse {
|
|
640
|
+
return new ConvertCompositionMoleToMassCalculationResponse(
|
|
641
|
+
data.compositionMass,
|
|
642
|
+
data.resultCode,
|
|
643
|
+
data.messages,
|
|
644
|
+
data.calculationElapsedTime,
|
|
645
|
+
data.operationId
|
|
646
|
+
);
|
|
647
|
+
}
|
|
648
|
+
}
|
|
649
|
+
|
|
650
|
+
export interface GetMassFromVesselCalculationRequestSchemaData {
|
|
651
|
+
vessel: Entities.Vessel;
|
|
652
|
+
}
|
|
653
|
+
|
|
654
|
+
class GetMassFromVesselCalculationRequest extends CalculationRequestBase {
|
|
655
|
+
vessel: Entities.Vessel;
|
|
656
|
+
|
|
657
|
+
/**
|
|
658
|
+
* GetMassFromVessel calculation request class.
|
|
659
|
+
*
|
|
660
|
+
* @param {Entities.Vessel} vessel - A Vessel entity.
|
|
661
|
+
*/
|
|
662
|
+
constructor(
|
|
663
|
+
vessel: Entities.Vessel
|
|
664
|
+
) {
|
|
665
|
+
super();
|
|
666
|
+
this.vessel = vessel;
|
|
667
|
+
}
|
|
668
|
+
}
|
|
669
|
+
|
|
670
|
+
export class GetMassFromVesselCalculationRequestSchema {
|
|
671
|
+
schema: Joi.ObjectSchema;
|
|
672
|
+
propertyTypes: Record<string, string>;
|
|
673
|
+
|
|
674
|
+
/**
|
|
675
|
+
* Schema for the GetMassFromVessel calculation request.
|
|
676
|
+
*/
|
|
677
|
+
constructor() {
|
|
678
|
+
this.schema = Joi.object({
|
|
679
|
+
vessel: new EntitySchemas.VesselSchema().schema,
|
|
680
|
+
}).unknown(true);
|
|
681
|
+
|
|
682
|
+
this.propertyTypes = {
|
|
683
|
+
vessel: "Entities.Vessel",
|
|
684
|
+
};
|
|
685
|
+
}
|
|
686
|
+
|
|
687
|
+
validate(data: GetMassFromVesselCalculationRequestSchemaData): GetMassFromVesselCalculationRequest {
|
|
688
|
+
const { error, value } = this.schema.validate(data, { abortEarly: false });
|
|
689
|
+
if (error) {
|
|
690
|
+
throw new Error(`Validation error: ${error.details.map((x) => x.message).join(", ")}`);
|
|
691
|
+
}
|
|
692
|
+
return this.makeCalculationRequest(value);
|
|
693
|
+
}
|
|
694
|
+
|
|
695
|
+
makeCalculationRequest(data: GetMassFromVesselCalculationRequestSchemaData): GetMassFromVesselCalculationRequest {
|
|
696
|
+
return new GetMassFromVesselCalculationRequest(
|
|
697
|
+
data.vessel
|
|
698
|
+
);
|
|
699
|
+
}
|
|
700
|
+
}
|
|
701
|
+
|
|
702
|
+
export class GetMassFromVesselCalculation extends CalculationBase {
|
|
703
|
+
vessel: Entities.Vessel;
|
|
704
|
+
massInventory?: number;
|
|
705
|
+
|
|
706
|
+
/**
|
|
707
|
+
* Calculates the mass in a vessel.
|
|
708
|
+
*
|
|
709
|
+
* @param {Entities.Vessel} vessel - A Vessel entity.
|
|
710
|
+
*/
|
|
711
|
+
constructor(
|
|
712
|
+
vessel: Entities.Vessel
|
|
713
|
+
) {
|
|
714
|
+
super();
|
|
715
|
+
this.vessel = vessel;
|
|
716
|
+
}
|
|
717
|
+
|
|
718
|
+
async run() {
|
|
719
|
+
try {
|
|
720
|
+
const request = new GetMassFromVesselCalculationRequest(
|
|
721
|
+
this.vessel
|
|
722
|
+
);
|
|
723
|
+
|
|
724
|
+
const schema = new GetMassFromVesselCalculationRequestSchema();
|
|
725
|
+
const validatedRequest = schema.validate(request);
|
|
726
|
+
|
|
727
|
+
const requestJson = JSON.stringify(validatedRequest);
|
|
728
|
+
const url = `${getAnalyticsApiTarget()}utilities/getmassfromvessel?clientId=${getClientAliasId()}`;
|
|
729
|
+
|
|
730
|
+
this.resultCode = Enums.ResultCode.UNEXPECTED_APPLICATION_ERROR;
|
|
731
|
+
|
|
732
|
+
const response = await this.postRequest(url, requestJson);
|
|
733
|
+
|
|
734
|
+
if (response.status >= 200 && response.status < 300) {
|
|
735
|
+
const schema = new GetMassFromVesselCalculationResponseSchema();
|
|
736
|
+
const validatedResponse = schema.validate(response.data);
|
|
737
|
+
|
|
738
|
+
this.resultCode = validatedResponse.resultCode;
|
|
739
|
+
if (this.resultCode === Enums.ResultCode.SUCCESS) {
|
|
740
|
+
this.massInventory = validatedResponse.massInventory;
|
|
741
|
+
this.resultCode = validatedResponse.resultCode;
|
|
742
|
+
this.messages = validatedResponse.messages ?? [];
|
|
743
|
+
this.calculationElapsedTime = validatedResponse.calculationElapsedTime;
|
|
744
|
+
this.operationId = validatedResponse.operationId;
|
|
745
|
+
} else {
|
|
746
|
+
this.messages.push(...(validatedResponse.messages ?? []));
|
|
747
|
+
}
|
|
748
|
+
} else {
|
|
749
|
+
this.handleFailedResponse(response);
|
|
750
|
+
}
|
|
751
|
+
} catch (error) {
|
|
752
|
+
if (error instanceof Error) {
|
|
753
|
+
this.messages.push(`Error: ${error.message}`);
|
|
754
|
+
} else {
|
|
755
|
+
this.messages.push(`Unexpected error: ${JSON.stringify(error)}`);
|
|
756
|
+
}
|
|
757
|
+
console.error(error);
|
|
758
|
+
this.resultCode = Enums.ResultCode.UNEXPECTED_APPLICATION_ERROR;
|
|
759
|
+
}
|
|
760
|
+
|
|
761
|
+
return this.resultCode;
|
|
762
|
+
}
|
|
763
|
+
|
|
764
|
+
toString() {
|
|
765
|
+
const parts = ["* GetMassFromVessel"];
|
|
766
|
+
|
|
767
|
+
parts.push(`massInventory: ${String(this.massInventory)}`);
|
|
768
|
+
parts.push(`resultCode: ${String(this.resultCode)}`);
|
|
769
|
+
parts.push("*** messages:");
|
|
770
|
+
parts.push(`messages: ${this.messages !== undefined ? this.messages : "(None)"}`);
|
|
771
|
+
parts.push(`calculationElapsedTime: ${this.calculationElapsedTime !== undefined ? this.calculationElapsedTime : "(None)"}`);
|
|
772
|
+
parts.push(`operationId: ${this.operationId !== undefined ? this.operationId : "(None)"}`);
|
|
773
|
+
|
|
774
|
+
return parts.join("\n");
|
|
775
|
+
}
|
|
776
|
+
}
|
|
777
|
+
|
|
778
|
+
export class GetMassFromVesselCalculationResponse extends CalculationResponseBase {
|
|
779
|
+
massInventory: number;
|
|
780
|
+
|
|
781
|
+
/**
|
|
782
|
+
* GetMassFromVessel calculation response class.
|
|
783
|
+
*
|
|
784
|
+
* @param {number} massInventory - Mass inventory in the vessel (kg).
|
|
785
|
+
*/
|
|
786
|
+
constructor(
|
|
787
|
+
massInventory: number,
|
|
788
|
+
resultCode: Enums.ResultCode,
|
|
789
|
+
messages: string[],
|
|
790
|
+
calculationElapsedTime: number,
|
|
791
|
+
operationId: string
|
|
792
|
+
) {
|
|
793
|
+
super();
|
|
794
|
+
this.massInventory = massInventory;
|
|
795
|
+
this.resultCode = resultCode;
|
|
796
|
+
this.messages = messages;
|
|
797
|
+
this.calculationElapsedTime = calculationElapsedTime;
|
|
798
|
+
this.operationId = operationId;
|
|
799
|
+
}
|
|
800
|
+
|
|
801
|
+
initialiseFromDictionary(data: { [key: string]: unknown }) {
|
|
802
|
+
if (data.massInventory !== undefined && typeof data.massInventory === "number") {
|
|
803
|
+
this.massInventory = data.massInventory as number;
|
|
804
|
+
}
|
|
805
|
+
if (data.resultCode !== undefined && (typeof data.resultCode === "string" || typeof data.resultCode === "number")) {
|
|
806
|
+
this.resultCode = data.resultCode as Enums.ResultCode;
|
|
807
|
+
}
|
|
808
|
+
this.messages = this.messages ?? [];
|
|
809
|
+
if (data.messages && Array.isArray(data.messages)) {
|
|
810
|
+
this.messages.push(...data.messages);
|
|
811
|
+
}
|
|
812
|
+
if (data.calculationElapsedTime !== undefined && typeof data.calculationElapsedTime === "number") {
|
|
813
|
+
this.calculationElapsedTime = data.calculationElapsedTime as number;
|
|
814
|
+
}
|
|
815
|
+
if (data.operationId !== undefined && typeof data.operationId === "string") {
|
|
816
|
+
this.operationId = data.operationId as string;
|
|
817
|
+
}
|
|
818
|
+
}
|
|
819
|
+
}
|
|
820
|
+
|
|
821
|
+
export interface GetMassFromVesselCalculationResponseSchemaData {
|
|
822
|
+
massInventory: number;
|
|
823
|
+
resultCode: Enums.ResultCode;
|
|
824
|
+
messages: string[];
|
|
825
|
+
calculationElapsedTime: number;
|
|
826
|
+
operationId: string;
|
|
827
|
+
}
|
|
828
|
+
|
|
829
|
+
export class GetMassFromVesselCalculationResponseSchema {
|
|
830
|
+
schema: Joi.ObjectSchema;
|
|
831
|
+
propertyTypes: Record<string, string>;
|
|
832
|
+
|
|
833
|
+
/**
|
|
834
|
+
* Schema for the GetMassFromVessel calculation response.
|
|
835
|
+
*/
|
|
836
|
+
constructor() {
|
|
837
|
+
this.schema = Joi.object({
|
|
838
|
+
massInventory: Joi.number().unsafe(),
|
|
839
|
+
resultCode: Joi.string().valid(...Object.values(Enums.ResultCode)),
|
|
840
|
+
messages: Joi.array().items(Joi.string()),
|
|
841
|
+
calculationElapsedTime: Joi.number().unsafe(),
|
|
842
|
+
operationId: Joi.string().uuid().allow(null),
|
|
843
|
+
}).unknown(true);
|
|
844
|
+
|
|
845
|
+
this.propertyTypes = {
|
|
846
|
+
massInventory: "number",
|
|
847
|
+
};
|
|
848
|
+
}
|
|
849
|
+
|
|
850
|
+
validate(data: GetMassFromVesselCalculationResponseSchemaData): GetMassFromVesselCalculationResponse {
|
|
851
|
+
const { error, value } = this.schema.validate(data, { abortEarly: false });
|
|
852
|
+
if (error) {
|
|
853
|
+
throw new Error(`Validation error: ${error.details.map((x) => x.message).join(", ")}`);
|
|
854
|
+
}
|
|
855
|
+
return this.makeCalculationResponse(value);
|
|
856
|
+
}
|
|
857
|
+
|
|
858
|
+
makeCalculationResponse(data: GetMassFromVesselCalculationResponseSchemaData): GetMassFromVesselCalculationResponse {
|
|
859
|
+
return new GetMassFromVesselCalculationResponse(
|
|
860
|
+
data.massInventory,
|
|
861
|
+
data.resultCode,
|
|
862
|
+
data.messages,
|
|
863
|
+
data.calculationElapsedTime,
|
|
864
|
+
data.operationId
|
|
865
|
+
);
|
|
866
|
+
}
|
|
867
|
+
}
|
|
868
|
+
|
|
869
|
+
export interface LoadMassInventoryVesselForLeakScenarioCalculationRequestSchemaData {
|
|
870
|
+
material: Entities.Material;
|
|
871
|
+
mass: number;
|
|
872
|
+
pressure: number;
|
|
873
|
+
temperature: number;
|
|
874
|
+
holeSize: number;
|
|
875
|
+
releaseElevation: number;
|
|
876
|
+
releaseAngle: number;
|
|
877
|
+
}
|
|
878
|
+
|
|
879
|
+
class LoadMassInventoryVesselForLeakScenarioCalculationRequest extends CalculationRequestBase {
|
|
880
|
+
material: Entities.Material;
|
|
881
|
+
mass: number;
|
|
882
|
+
pressure: number;
|
|
883
|
+
temperature: number;
|
|
884
|
+
holeSize: number;
|
|
885
|
+
releaseElevation: number;
|
|
886
|
+
releaseAngle: number;
|
|
887
|
+
|
|
888
|
+
/**
|
|
889
|
+
* LoadMassInventoryVesselForLeakScenario calculation request class.
|
|
890
|
+
*
|
|
891
|
+
* @param {Entities.Material} material - A Material entity.
|
|
892
|
+
* @param {number} mass - Total vessel mass inventory.
|
|
893
|
+
* @param {number} pressure - Absolute pressure of the fluid.
|
|
894
|
+
* @param {number} temperature - Temperature of the fluid.
|
|
895
|
+
* @param {number} holeSize - The diameter of the equivalent circular orifice with the same area as the area of the leak.
|
|
896
|
+
* @param {number} releaseElevation - Elevation of the release above ground level.
|
|
897
|
+
* @param {number} releaseAngle - Angle of release above a horizontal plane.
|
|
898
|
+
*/
|
|
899
|
+
constructor(
|
|
900
|
+
material: Entities.Material,
|
|
901
|
+
mass: number,
|
|
902
|
+
pressure: number,
|
|
903
|
+
temperature: number,
|
|
904
|
+
holeSize: number,
|
|
905
|
+
releaseElevation: number,
|
|
906
|
+
releaseAngle: number
|
|
907
|
+
) {
|
|
908
|
+
super();
|
|
909
|
+
this.material = material;
|
|
910
|
+
this.mass = mass;
|
|
911
|
+
this.pressure = pressure;
|
|
912
|
+
this.temperature = temperature;
|
|
913
|
+
this.holeSize = holeSize;
|
|
914
|
+
this.releaseElevation = releaseElevation;
|
|
915
|
+
this.releaseAngle = releaseAngle;
|
|
916
|
+
}
|
|
917
|
+
}
|
|
918
|
+
|
|
919
|
+
export class LoadMassInventoryVesselForLeakScenarioCalculationRequestSchema {
|
|
920
|
+
schema: Joi.ObjectSchema;
|
|
921
|
+
propertyTypes: Record<string, string>;
|
|
922
|
+
|
|
923
|
+
/**
|
|
924
|
+
* Schema for the LoadMassInventoryVesselForLeakScenario calculation request.
|
|
925
|
+
*/
|
|
926
|
+
constructor() {
|
|
927
|
+
this.schema = Joi.object({
|
|
928
|
+
material: new EntitySchemas.MaterialSchema().schema,
|
|
929
|
+
mass: Joi.number().unsafe(),
|
|
930
|
+
pressure: Joi.number().unsafe(),
|
|
931
|
+
temperature: Joi.number().unsafe(),
|
|
932
|
+
holeSize: Joi.number().unsafe(),
|
|
933
|
+
releaseElevation: Joi.number().unsafe(),
|
|
934
|
+
releaseAngle: Joi.number().unsafe(),
|
|
935
|
+
}).unknown(true);
|
|
936
|
+
|
|
937
|
+
this.propertyTypes = {
|
|
938
|
+
material: "Entities.Material",
|
|
939
|
+
mass: "number",
|
|
940
|
+
pressure: "number",
|
|
941
|
+
temperature: "number",
|
|
942
|
+
holeSize: "number",
|
|
943
|
+
releaseElevation: "number",
|
|
944
|
+
releaseAngle: "number",
|
|
945
|
+
};
|
|
946
|
+
}
|
|
947
|
+
|
|
948
|
+
validate(data: LoadMassInventoryVesselForLeakScenarioCalculationRequestSchemaData): LoadMassInventoryVesselForLeakScenarioCalculationRequest {
|
|
949
|
+
const { error, value } = this.schema.validate(data, { abortEarly: false });
|
|
950
|
+
if (error) {
|
|
951
|
+
throw new Error(`Validation error: ${error.details.map((x) => x.message).join(", ")}`);
|
|
952
|
+
}
|
|
953
|
+
return this.makeCalculationRequest(value);
|
|
954
|
+
}
|
|
955
|
+
|
|
956
|
+
makeCalculationRequest(data: LoadMassInventoryVesselForLeakScenarioCalculationRequestSchemaData): LoadMassInventoryVesselForLeakScenarioCalculationRequest {
|
|
957
|
+
return new LoadMassInventoryVesselForLeakScenarioCalculationRequest(
|
|
958
|
+
data.material,
|
|
959
|
+
data.mass,
|
|
960
|
+
data.pressure,
|
|
961
|
+
data.temperature,
|
|
962
|
+
data.holeSize,
|
|
963
|
+
data.releaseElevation,
|
|
964
|
+
data.releaseAngle
|
|
965
|
+
);
|
|
966
|
+
}
|
|
967
|
+
}
|
|
968
|
+
|
|
969
|
+
export class LoadMassInventoryVesselForLeakScenarioCalculation extends CalculationBase {
|
|
970
|
+
material: Entities.Material;
|
|
971
|
+
mass: number;
|
|
972
|
+
pressure: number;
|
|
973
|
+
temperature: number;
|
|
974
|
+
holeSize: number;
|
|
975
|
+
releaseElevation: number;
|
|
976
|
+
releaseAngle: number;
|
|
977
|
+
vessel?: Entities.Vessel;
|
|
978
|
+
leak?: Entities.Leak;
|
|
979
|
+
|
|
980
|
+
/**
|
|
981
|
+
* Sets up a vessel and a leak scenario from a mass inventory, pressure, temperature and hole size specifications.
|
|
982
|
+
*
|
|
983
|
+
* @param {Entities.Material} material - A Material entity.
|
|
984
|
+
* @param {number} mass - Total vessel mass inventory.
|
|
985
|
+
* @param {number} pressure - Absolute pressure of the fluid.
|
|
986
|
+
* @param {number} temperature - Temperature of the fluid.
|
|
987
|
+
* @param {number} holeSize - The diameter of the equivalent circular orifice with the same area as the area of the leak.
|
|
988
|
+
* @param {number} releaseElevation - Elevation of the release above ground level.
|
|
989
|
+
* @param {number} releaseAngle - Angle of release above a horizontal plane.
|
|
990
|
+
*/
|
|
991
|
+
constructor(
|
|
992
|
+
material: Entities.Material,
|
|
993
|
+
mass: number,
|
|
994
|
+
pressure: number,
|
|
995
|
+
temperature: number,
|
|
996
|
+
holeSize: number,
|
|
997
|
+
releaseElevation: number,
|
|
998
|
+
releaseAngle: number
|
|
999
|
+
) {
|
|
1000
|
+
super();
|
|
1001
|
+
this.material = material;
|
|
1002
|
+
this.mass = mass;
|
|
1003
|
+
this.pressure = pressure;
|
|
1004
|
+
this.temperature = temperature;
|
|
1005
|
+
this.holeSize = holeSize;
|
|
1006
|
+
this.releaseElevation = releaseElevation;
|
|
1007
|
+
this.releaseAngle = releaseAngle;
|
|
1008
|
+
}
|
|
1009
|
+
|
|
1010
|
+
async run() {
|
|
1011
|
+
try {
|
|
1012
|
+
const request = new LoadMassInventoryVesselForLeakScenarioCalculationRequest(
|
|
1013
|
+
this.material,
|
|
1014
|
+
this.mass,
|
|
1015
|
+
this.pressure,
|
|
1016
|
+
this.temperature,
|
|
1017
|
+
this.holeSize,
|
|
1018
|
+
this.releaseElevation,
|
|
1019
|
+
this.releaseAngle
|
|
1020
|
+
);
|
|
1021
|
+
|
|
1022
|
+
const schema = new LoadMassInventoryVesselForLeakScenarioCalculationRequestSchema();
|
|
1023
|
+
const validatedRequest = schema.validate(request);
|
|
1024
|
+
|
|
1025
|
+
const requestJson = JSON.stringify(validatedRequest);
|
|
1026
|
+
const url = `${getAnalyticsApiTarget()}utilities/loadmassinventoryvesselforleakscenario?clientId=${getClientAliasId()}`;
|
|
1027
|
+
|
|
1028
|
+
this.resultCode = Enums.ResultCode.UNEXPECTED_APPLICATION_ERROR;
|
|
1029
|
+
|
|
1030
|
+
const response = await this.postRequest(url, requestJson);
|
|
1031
|
+
|
|
1032
|
+
if (response.status >= 200 && response.status < 300) {
|
|
1033
|
+
const schema = new LoadMassInventoryVesselForLeakScenarioCalculationResponseSchema();
|
|
1034
|
+
const validatedResponse = schema.validate(response.data);
|
|
1035
|
+
|
|
1036
|
+
this.resultCode = validatedResponse.resultCode;
|
|
1037
|
+
if (this.resultCode === Enums.ResultCode.SUCCESS) {
|
|
1038
|
+
this.vessel = validatedResponse.vessel;
|
|
1039
|
+
this.leak = validatedResponse.leak;
|
|
1040
|
+
this.resultCode = validatedResponse.resultCode;
|
|
1041
|
+
this.messages = validatedResponse.messages ?? [];
|
|
1042
|
+
this.calculationElapsedTime = validatedResponse.calculationElapsedTime;
|
|
1043
|
+
this.operationId = validatedResponse.operationId;
|
|
1044
|
+
} else {
|
|
1045
|
+
this.messages.push(...(validatedResponse.messages ?? []));
|
|
1046
|
+
}
|
|
1047
|
+
} else {
|
|
1048
|
+
this.handleFailedResponse(response);
|
|
1049
|
+
}
|
|
1050
|
+
} catch (error) {
|
|
1051
|
+
if (error instanceof Error) {
|
|
1052
|
+
this.messages.push(`Error: ${error.message}`);
|
|
1053
|
+
} else {
|
|
1054
|
+
this.messages.push(`Unexpected error: ${JSON.stringify(error)}`);
|
|
1055
|
+
}
|
|
1056
|
+
console.error(error);
|
|
1057
|
+
this.resultCode = Enums.ResultCode.UNEXPECTED_APPLICATION_ERROR;
|
|
1058
|
+
}
|
|
1059
|
+
|
|
1060
|
+
return this.resultCode;
|
|
1061
|
+
}
|
|
1062
|
+
|
|
1063
|
+
toString() {
|
|
1064
|
+
const parts = ["* LoadMassInventoryVesselForLeakScenario"];
|
|
1065
|
+
|
|
1066
|
+
parts.push(`vessel: ${String(this.vessel)}`);
|
|
1067
|
+
parts.push(`leak: ${String(this.leak)}`);
|
|
1068
|
+
parts.push(`resultCode: ${String(this.resultCode)}`);
|
|
1069
|
+
parts.push("*** messages:");
|
|
1070
|
+
parts.push(`messages: ${this.messages !== undefined ? this.messages : "(None)"}`);
|
|
1071
|
+
parts.push(`calculationElapsedTime: ${this.calculationElapsedTime !== undefined ? this.calculationElapsedTime : "(None)"}`);
|
|
1072
|
+
parts.push(`operationId: ${this.operationId !== undefined ? this.operationId : "(None)"}`);
|
|
1073
|
+
|
|
1074
|
+
return parts.join("\n");
|
|
1075
|
+
}
|
|
1076
|
+
}
|
|
1077
|
+
|
|
1078
|
+
export class LoadMassInventoryVesselForLeakScenarioCalculationResponse extends CalculationResponseBase {
|
|
1079
|
+
vessel: Entities.Vessel;
|
|
1080
|
+
leak: Entities.Leak;
|
|
1081
|
+
|
|
1082
|
+
/**
|
|
1083
|
+
* LoadMassInventoryVesselForLeakScenario calculation response class.
|
|
1084
|
+
*
|
|
1085
|
+
* @param {Entities.Vessel} vessel - A Vessel entity.
|
|
1086
|
+
* @param {Entities.Leak} leak - A Leak entity.
|
|
1087
|
+
*/
|
|
1088
|
+
constructor(
|
|
1089
|
+
vessel: Entities.Vessel,
|
|
1090
|
+
leak: Entities.Leak,
|
|
1091
|
+
resultCode: Enums.ResultCode,
|
|
1092
|
+
messages: string[],
|
|
1093
|
+
calculationElapsedTime: number,
|
|
1094
|
+
operationId: string
|
|
1095
|
+
) {
|
|
1096
|
+
super();
|
|
1097
|
+
this.vessel = vessel;
|
|
1098
|
+
this.leak = leak;
|
|
1099
|
+
this.resultCode = resultCode;
|
|
1100
|
+
this.messages = messages;
|
|
1101
|
+
this.calculationElapsedTime = calculationElapsedTime;
|
|
1102
|
+
this.operationId = operationId;
|
|
1103
|
+
}
|
|
1104
|
+
|
|
1105
|
+
initialiseFromDictionary(data: { [key: string]: unknown }) {
|
|
1106
|
+
if (data.vessel) {
|
|
1107
|
+
this.vessel = new Entities.Vessel();
|
|
1108
|
+
this.vessel.initialiseFromDictionary(data.vessel as { [key: string]: unknown });
|
|
1109
|
+
}
|
|
1110
|
+
if (data.leak) {
|
|
1111
|
+
this.leak = new Entities.Leak();
|
|
1112
|
+
this.leak.initialiseFromDictionary(data.leak as { [key: string]: unknown });
|
|
1113
|
+
}
|
|
1114
|
+
if (data.resultCode !== undefined && (typeof data.resultCode === "string" || typeof data.resultCode === "number")) {
|
|
1115
|
+
this.resultCode = data.resultCode as Enums.ResultCode;
|
|
1116
|
+
}
|
|
1117
|
+
this.messages = this.messages ?? [];
|
|
1118
|
+
if (data.messages && Array.isArray(data.messages)) {
|
|
1119
|
+
this.messages.push(...data.messages);
|
|
1120
|
+
}
|
|
1121
|
+
if (data.calculationElapsedTime !== undefined && typeof data.calculationElapsedTime === "number") {
|
|
1122
|
+
this.calculationElapsedTime = data.calculationElapsedTime as number;
|
|
1123
|
+
}
|
|
1124
|
+
if (data.operationId !== undefined && typeof data.operationId === "string") {
|
|
1125
|
+
this.operationId = data.operationId as string;
|
|
1126
|
+
}
|
|
1127
|
+
}
|
|
1128
|
+
}
|
|
1129
|
+
|
|
1130
|
+
export interface LoadMassInventoryVesselForLeakScenarioCalculationResponseSchemaData {
|
|
1131
|
+
vessel: Entities.Vessel;
|
|
1132
|
+
leak: Entities.Leak;
|
|
1133
|
+
resultCode: Enums.ResultCode;
|
|
1134
|
+
messages: string[];
|
|
1135
|
+
calculationElapsedTime: number;
|
|
1136
|
+
operationId: string;
|
|
1137
|
+
}
|
|
1138
|
+
|
|
1139
|
+
export class LoadMassInventoryVesselForLeakScenarioCalculationResponseSchema {
|
|
1140
|
+
schema: Joi.ObjectSchema;
|
|
1141
|
+
propertyTypes: Record<string, string>;
|
|
1142
|
+
|
|
1143
|
+
/**
|
|
1144
|
+
* Schema for the LoadMassInventoryVesselForLeakScenario calculation response.
|
|
1145
|
+
*/
|
|
1146
|
+
constructor() {
|
|
1147
|
+
this.schema = Joi.object({
|
|
1148
|
+
vessel: new EntitySchemas.VesselSchema().schema,
|
|
1149
|
+
leak: new EntitySchemas.LeakSchema().schema,
|
|
1150
|
+
resultCode: Joi.string().valid(...Object.values(Enums.ResultCode)),
|
|
1151
|
+
messages: Joi.array().items(Joi.string()),
|
|
1152
|
+
calculationElapsedTime: Joi.number().unsafe(),
|
|
1153
|
+
operationId: Joi.string().uuid().allow(null),
|
|
1154
|
+
}).unknown(true);
|
|
1155
|
+
|
|
1156
|
+
this.propertyTypes = {
|
|
1157
|
+
vessel: "Entities.Vessel",
|
|
1158
|
+
leak: "Entities.Leak",
|
|
1159
|
+
};
|
|
1160
|
+
}
|
|
1161
|
+
|
|
1162
|
+
validate(data: LoadMassInventoryVesselForLeakScenarioCalculationResponseSchemaData): LoadMassInventoryVesselForLeakScenarioCalculationResponse {
|
|
1163
|
+
const { error, value } = this.schema.validate(data, { abortEarly: false });
|
|
1164
|
+
if (error) {
|
|
1165
|
+
throw new Error(`Validation error: ${error.details.map((x) => x.message).join(", ")}`);
|
|
1166
|
+
}
|
|
1167
|
+
return this.makeCalculationResponse(value);
|
|
1168
|
+
}
|
|
1169
|
+
|
|
1170
|
+
makeCalculationResponse(data: LoadMassInventoryVesselForLeakScenarioCalculationResponseSchemaData): LoadMassInventoryVesselForLeakScenarioCalculationResponse {
|
|
1171
|
+
return new LoadMassInventoryVesselForLeakScenarioCalculationResponse(
|
|
1172
|
+
data.vessel,
|
|
1173
|
+
data.leak,
|
|
1174
|
+
data.resultCode,
|
|
1175
|
+
data.messages,
|
|
1176
|
+
data.calculationElapsedTime,
|
|
1177
|
+
data.operationId
|
|
1178
|
+
);
|
|
1179
|
+
}
|
|
1180
|
+
}
|
|
1181
|
+
|
|
1182
|
+
export interface LoadMassInventoryVesselForLineRuptureScenarioCalculationRequestSchemaData {
|
|
1183
|
+
material: Entities.Material;
|
|
1184
|
+
mass: number;
|
|
1185
|
+
pressure: number;
|
|
1186
|
+
temperature: number;
|
|
1187
|
+
pipeDiameter: number;
|
|
1188
|
+
pipeLength: number;
|
|
1189
|
+
releaseElevation: number;
|
|
1190
|
+
releaseAngle: number;
|
|
1191
|
+
}
|
|
1192
|
+
|
|
1193
|
+
class LoadMassInventoryVesselForLineRuptureScenarioCalculationRequest extends CalculationRequestBase {
|
|
1194
|
+
material: Entities.Material;
|
|
1195
|
+
mass: number;
|
|
1196
|
+
pressure: number;
|
|
1197
|
+
temperature: number;
|
|
1198
|
+
pipeDiameter: number;
|
|
1199
|
+
pipeLength: number;
|
|
1200
|
+
releaseElevation: number;
|
|
1201
|
+
releaseAngle: number;
|
|
1202
|
+
|
|
1203
|
+
/**
|
|
1204
|
+
* LoadMassInventoryVesselForLineRuptureScenario calculation request class.
|
|
1205
|
+
*
|
|
1206
|
+
* @param {Entities.Material} material - A Material entity.
|
|
1207
|
+
* @param {number} mass - Total vessel mass inventory.
|
|
1208
|
+
* @param {number} pressure - Absolute pressure of the fluid.
|
|
1209
|
+
* @param {number} temperature - Temperature of the fluid.
|
|
1210
|
+
* @param {number} pipeDiameter - Internal diameter of the pipe.
|
|
1211
|
+
* @param {number} pipeLength - length of the pipe.
|
|
1212
|
+
* @param {number} releaseElevation - Elevation of the release above ground level.
|
|
1213
|
+
* @param {number} releaseAngle - Angle of release above a horizontal plane.
|
|
1214
|
+
*/
|
|
1215
|
+
constructor(
|
|
1216
|
+
material: Entities.Material,
|
|
1217
|
+
mass: number,
|
|
1218
|
+
pressure: number,
|
|
1219
|
+
temperature: number,
|
|
1220
|
+
pipeDiameter: number,
|
|
1221
|
+
pipeLength: number,
|
|
1222
|
+
releaseElevation: number,
|
|
1223
|
+
releaseAngle: number
|
|
1224
|
+
) {
|
|
1225
|
+
super();
|
|
1226
|
+
this.material = material;
|
|
1227
|
+
this.mass = mass;
|
|
1228
|
+
this.pressure = pressure;
|
|
1229
|
+
this.temperature = temperature;
|
|
1230
|
+
this.pipeDiameter = pipeDiameter;
|
|
1231
|
+
this.pipeLength = pipeLength;
|
|
1232
|
+
this.releaseElevation = releaseElevation;
|
|
1233
|
+
this.releaseAngle = releaseAngle;
|
|
1234
|
+
}
|
|
1235
|
+
}
|
|
1236
|
+
|
|
1237
|
+
export class LoadMassInventoryVesselForLineRuptureScenarioCalculationRequestSchema {
|
|
1238
|
+
schema: Joi.ObjectSchema;
|
|
1239
|
+
propertyTypes: Record<string, string>;
|
|
1240
|
+
|
|
1241
|
+
/**
|
|
1242
|
+
* Schema for the LoadMassInventoryVesselForLineRuptureScenario calculation request.
|
|
1243
|
+
*/
|
|
1244
|
+
constructor() {
|
|
1245
|
+
this.schema = Joi.object({
|
|
1246
|
+
material: new EntitySchemas.MaterialSchema().schema,
|
|
1247
|
+
mass: Joi.number().unsafe(),
|
|
1248
|
+
pressure: Joi.number().unsafe(),
|
|
1249
|
+
temperature: Joi.number().unsafe(),
|
|
1250
|
+
pipeDiameter: Joi.number().unsafe(),
|
|
1251
|
+
pipeLength: Joi.number().unsafe(),
|
|
1252
|
+
releaseElevation: Joi.number().unsafe(),
|
|
1253
|
+
releaseAngle: Joi.number().unsafe(),
|
|
1254
|
+
}).unknown(true);
|
|
1255
|
+
|
|
1256
|
+
this.propertyTypes = {
|
|
1257
|
+
material: "Entities.Material",
|
|
1258
|
+
mass: "number",
|
|
1259
|
+
pressure: "number",
|
|
1260
|
+
temperature: "number",
|
|
1261
|
+
pipeDiameter: "number",
|
|
1262
|
+
pipeLength: "number",
|
|
1263
|
+
releaseElevation: "number",
|
|
1264
|
+
releaseAngle: "number",
|
|
1265
|
+
};
|
|
1266
|
+
}
|
|
1267
|
+
|
|
1268
|
+
validate(data: LoadMassInventoryVesselForLineRuptureScenarioCalculationRequestSchemaData): LoadMassInventoryVesselForLineRuptureScenarioCalculationRequest {
|
|
1269
|
+
const { error, value } = this.schema.validate(data, { abortEarly: false });
|
|
1270
|
+
if (error) {
|
|
1271
|
+
throw new Error(`Validation error: ${error.details.map((x) => x.message).join(", ")}`);
|
|
1272
|
+
}
|
|
1273
|
+
return this.makeCalculationRequest(value);
|
|
1274
|
+
}
|
|
1275
|
+
|
|
1276
|
+
makeCalculationRequest(data: LoadMassInventoryVesselForLineRuptureScenarioCalculationRequestSchemaData): LoadMassInventoryVesselForLineRuptureScenarioCalculationRequest {
|
|
1277
|
+
return new LoadMassInventoryVesselForLineRuptureScenarioCalculationRequest(
|
|
1278
|
+
data.material,
|
|
1279
|
+
data.mass,
|
|
1280
|
+
data.pressure,
|
|
1281
|
+
data.temperature,
|
|
1282
|
+
data.pipeDiameter,
|
|
1283
|
+
data.pipeLength,
|
|
1284
|
+
data.releaseElevation,
|
|
1285
|
+
data.releaseAngle
|
|
1286
|
+
);
|
|
1287
|
+
}
|
|
1288
|
+
}
|
|
1289
|
+
|
|
1290
|
+
export class LoadMassInventoryVesselForLineRuptureScenarioCalculation extends CalculationBase {
|
|
1291
|
+
material: Entities.Material;
|
|
1292
|
+
mass: number;
|
|
1293
|
+
pressure: number;
|
|
1294
|
+
temperature: number;
|
|
1295
|
+
pipeDiameter: number;
|
|
1296
|
+
pipeLength: number;
|
|
1297
|
+
releaseElevation: number;
|
|
1298
|
+
releaseAngle: number;
|
|
1299
|
+
vessel?: Entities.Vessel;
|
|
1300
|
+
lineRupture?: Entities.LineRupture;
|
|
1301
|
+
|
|
1302
|
+
/**
|
|
1303
|
+
* Sets up a vessel and a line rupture scenario from a mass inventory, pressure, temperature pipe diameter and length specifications.
|
|
1304
|
+
*
|
|
1305
|
+
* @param {Entities.Material} material - A Material entity.
|
|
1306
|
+
* @param {number} mass - Total vessel mass inventory.
|
|
1307
|
+
* @param {number} pressure - Absolute pressure of the fluid.
|
|
1308
|
+
* @param {number} temperature - Temperature of the fluid.
|
|
1309
|
+
* @param {number} pipeDiameter - Internal diameter of the pipe.
|
|
1310
|
+
* @param {number} pipeLength - length of the pipe.
|
|
1311
|
+
* @param {number} releaseElevation - Elevation of the release above ground level.
|
|
1312
|
+
* @param {number} releaseAngle - Angle of release above a horizontal plane.
|
|
1313
|
+
*/
|
|
1314
|
+
constructor(
|
|
1315
|
+
material: Entities.Material,
|
|
1316
|
+
mass: number,
|
|
1317
|
+
pressure: number,
|
|
1318
|
+
temperature: number,
|
|
1319
|
+
pipeDiameter: number,
|
|
1320
|
+
pipeLength: number,
|
|
1321
|
+
releaseElevation: number,
|
|
1322
|
+
releaseAngle: number
|
|
1323
|
+
) {
|
|
1324
|
+
super();
|
|
1325
|
+
this.material = material;
|
|
1326
|
+
this.mass = mass;
|
|
1327
|
+
this.pressure = pressure;
|
|
1328
|
+
this.temperature = temperature;
|
|
1329
|
+
this.pipeDiameter = pipeDiameter;
|
|
1330
|
+
this.pipeLength = pipeLength;
|
|
1331
|
+
this.releaseElevation = releaseElevation;
|
|
1332
|
+
this.releaseAngle = releaseAngle;
|
|
1333
|
+
}
|
|
1334
|
+
|
|
1335
|
+
async run() {
|
|
1336
|
+
try {
|
|
1337
|
+
const request = new LoadMassInventoryVesselForLineRuptureScenarioCalculationRequest(
|
|
1338
|
+
this.material,
|
|
1339
|
+
this.mass,
|
|
1340
|
+
this.pressure,
|
|
1341
|
+
this.temperature,
|
|
1342
|
+
this.pipeDiameter,
|
|
1343
|
+
this.pipeLength,
|
|
1344
|
+
this.releaseElevation,
|
|
1345
|
+
this.releaseAngle
|
|
1346
|
+
);
|
|
1347
|
+
|
|
1348
|
+
const schema = new LoadMassInventoryVesselForLineRuptureScenarioCalculationRequestSchema();
|
|
1349
|
+
const validatedRequest = schema.validate(request);
|
|
1350
|
+
|
|
1351
|
+
const requestJson = JSON.stringify(validatedRequest);
|
|
1352
|
+
const url = `${getAnalyticsApiTarget()}utilities/loadmassinventoryvesselforlinerupturescenario?clientId=${getClientAliasId()}`;
|
|
1353
|
+
|
|
1354
|
+
this.resultCode = Enums.ResultCode.UNEXPECTED_APPLICATION_ERROR;
|
|
1355
|
+
|
|
1356
|
+
const response = await this.postRequest(url, requestJson);
|
|
1357
|
+
|
|
1358
|
+
if (response.status >= 200 && response.status < 300) {
|
|
1359
|
+
const schema = new LoadMassInventoryVesselForLineRuptureScenarioCalculationResponseSchema();
|
|
1360
|
+
const validatedResponse = schema.validate(response.data);
|
|
1361
|
+
|
|
1362
|
+
this.resultCode = validatedResponse.resultCode;
|
|
1363
|
+
if (this.resultCode === Enums.ResultCode.SUCCESS) {
|
|
1364
|
+
this.vessel = validatedResponse.vessel;
|
|
1365
|
+
this.lineRupture = validatedResponse.lineRupture;
|
|
1366
|
+
this.resultCode = validatedResponse.resultCode;
|
|
1367
|
+
this.messages = validatedResponse.messages ?? [];
|
|
1368
|
+
this.calculationElapsedTime = validatedResponse.calculationElapsedTime;
|
|
1369
|
+
this.operationId = validatedResponse.operationId;
|
|
1370
|
+
} else {
|
|
1371
|
+
this.messages.push(...(validatedResponse.messages ?? []));
|
|
1372
|
+
}
|
|
1373
|
+
} else {
|
|
1374
|
+
this.handleFailedResponse(response);
|
|
1375
|
+
}
|
|
1376
|
+
} catch (error) {
|
|
1377
|
+
if (error instanceof Error) {
|
|
1378
|
+
this.messages.push(`Error: ${error.message}`);
|
|
1379
|
+
} else {
|
|
1380
|
+
this.messages.push(`Unexpected error: ${JSON.stringify(error)}`);
|
|
1381
|
+
}
|
|
1382
|
+
console.error(error);
|
|
1383
|
+
this.resultCode = Enums.ResultCode.UNEXPECTED_APPLICATION_ERROR;
|
|
1384
|
+
}
|
|
1385
|
+
|
|
1386
|
+
return this.resultCode;
|
|
1387
|
+
}
|
|
1388
|
+
|
|
1389
|
+
toString() {
|
|
1390
|
+
const parts = ["* LoadMassInventoryVesselForLineRuptureScenario"];
|
|
1391
|
+
|
|
1392
|
+
parts.push(`vessel: ${String(this.vessel)}`);
|
|
1393
|
+
parts.push(`lineRupture: ${String(this.lineRupture)}`);
|
|
1394
|
+
parts.push(`resultCode: ${String(this.resultCode)}`);
|
|
1395
|
+
parts.push("*** messages:");
|
|
1396
|
+
parts.push(`messages: ${this.messages !== undefined ? this.messages : "(None)"}`);
|
|
1397
|
+
parts.push(`calculationElapsedTime: ${this.calculationElapsedTime !== undefined ? this.calculationElapsedTime : "(None)"}`);
|
|
1398
|
+
parts.push(`operationId: ${this.operationId !== undefined ? this.operationId : "(None)"}`);
|
|
1399
|
+
|
|
1400
|
+
return parts.join("\n");
|
|
1401
|
+
}
|
|
1402
|
+
}
|
|
1403
|
+
|
|
1404
|
+
export class LoadMassInventoryVesselForLineRuptureScenarioCalculationResponse extends CalculationResponseBase {
|
|
1405
|
+
vessel: Entities.Vessel;
|
|
1406
|
+
lineRupture: Entities.LineRupture;
|
|
1407
|
+
|
|
1408
|
+
/**
|
|
1409
|
+
* LoadMassInventoryVesselForLineRuptureScenario calculation response class.
|
|
1410
|
+
*
|
|
1411
|
+
* @param {Entities.Vessel} vessel - A Vessel entity.
|
|
1412
|
+
* @param {Entities.LineRupture} lineRupture - A Line Rupture entity.
|
|
1413
|
+
*/
|
|
1414
|
+
constructor(
|
|
1415
|
+
vessel: Entities.Vessel,
|
|
1416
|
+
lineRupture: Entities.LineRupture,
|
|
1417
|
+
resultCode: Enums.ResultCode,
|
|
1418
|
+
messages: string[],
|
|
1419
|
+
calculationElapsedTime: number,
|
|
1420
|
+
operationId: string
|
|
1421
|
+
) {
|
|
1422
|
+
super();
|
|
1423
|
+
this.vessel = vessel;
|
|
1424
|
+
this.lineRupture = lineRupture;
|
|
1425
|
+
this.resultCode = resultCode;
|
|
1426
|
+
this.messages = messages;
|
|
1427
|
+
this.calculationElapsedTime = calculationElapsedTime;
|
|
1428
|
+
this.operationId = operationId;
|
|
1429
|
+
}
|
|
1430
|
+
|
|
1431
|
+
initialiseFromDictionary(data: { [key: string]: unknown }) {
|
|
1432
|
+
if (data.vessel) {
|
|
1433
|
+
this.vessel = new Entities.Vessel();
|
|
1434
|
+
this.vessel.initialiseFromDictionary(data.vessel as { [key: string]: unknown });
|
|
1435
|
+
}
|
|
1436
|
+
if (data.lineRupture) {
|
|
1437
|
+
this.lineRupture = new Entities.LineRupture();
|
|
1438
|
+
this.lineRupture.initialiseFromDictionary(data.lineRupture as { [key: string]: unknown });
|
|
1439
|
+
}
|
|
1440
|
+
if (data.resultCode !== undefined && (typeof data.resultCode === "string" || typeof data.resultCode === "number")) {
|
|
1441
|
+
this.resultCode = data.resultCode as Enums.ResultCode;
|
|
1442
|
+
}
|
|
1443
|
+
this.messages = this.messages ?? [];
|
|
1444
|
+
if (data.messages && Array.isArray(data.messages)) {
|
|
1445
|
+
this.messages.push(...data.messages);
|
|
1446
|
+
}
|
|
1447
|
+
if (data.calculationElapsedTime !== undefined && typeof data.calculationElapsedTime === "number") {
|
|
1448
|
+
this.calculationElapsedTime = data.calculationElapsedTime as number;
|
|
1449
|
+
}
|
|
1450
|
+
if (data.operationId !== undefined && typeof data.operationId === "string") {
|
|
1451
|
+
this.operationId = data.operationId as string;
|
|
1452
|
+
}
|
|
1453
|
+
}
|
|
1454
|
+
}
|
|
1455
|
+
|
|
1456
|
+
export interface LoadMassInventoryVesselForLineRuptureScenarioCalculationResponseSchemaData {
|
|
1457
|
+
vessel: Entities.Vessel;
|
|
1458
|
+
lineRupture: Entities.LineRupture;
|
|
1459
|
+
resultCode: Enums.ResultCode;
|
|
1460
|
+
messages: string[];
|
|
1461
|
+
calculationElapsedTime: number;
|
|
1462
|
+
operationId: string;
|
|
1463
|
+
}
|
|
1464
|
+
|
|
1465
|
+
export class LoadMassInventoryVesselForLineRuptureScenarioCalculationResponseSchema {
|
|
1466
|
+
schema: Joi.ObjectSchema;
|
|
1467
|
+
propertyTypes: Record<string, string>;
|
|
1468
|
+
|
|
1469
|
+
/**
|
|
1470
|
+
* Schema for the LoadMassInventoryVesselForLineRuptureScenario calculation response.
|
|
1471
|
+
*/
|
|
1472
|
+
constructor() {
|
|
1473
|
+
this.schema = Joi.object({
|
|
1474
|
+
vessel: new EntitySchemas.VesselSchema().schema,
|
|
1475
|
+
lineRupture: new EntitySchemas.LineRuptureSchema().schema,
|
|
1476
|
+
resultCode: Joi.string().valid(...Object.values(Enums.ResultCode)),
|
|
1477
|
+
messages: Joi.array().items(Joi.string()),
|
|
1478
|
+
calculationElapsedTime: Joi.number().unsafe(),
|
|
1479
|
+
operationId: Joi.string().uuid().allow(null),
|
|
1480
|
+
}).unknown(true);
|
|
1481
|
+
|
|
1482
|
+
this.propertyTypes = {
|
|
1483
|
+
vessel: "Entities.Vessel",
|
|
1484
|
+
lineRupture: "Entities.LineRupture",
|
|
1485
|
+
};
|
|
1486
|
+
}
|
|
1487
|
+
|
|
1488
|
+
validate(data: LoadMassInventoryVesselForLineRuptureScenarioCalculationResponseSchemaData): LoadMassInventoryVesselForLineRuptureScenarioCalculationResponse {
|
|
1489
|
+
const { error, value } = this.schema.validate(data, { abortEarly: false });
|
|
1490
|
+
if (error) {
|
|
1491
|
+
throw new Error(`Validation error: ${error.details.map((x) => x.message).join(", ")}`);
|
|
1492
|
+
}
|
|
1493
|
+
return this.makeCalculationResponse(value);
|
|
1494
|
+
}
|
|
1495
|
+
|
|
1496
|
+
makeCalculationResponse(data: LoadMassInventoryVesselForLineRuptureScenarioCalculationResponseSchemaData): LoadMassInventoryVesselForLineRuptureScenarioCalculationResponse {
|
|
1497
|
+
return new LoadMassInventoryVesselForLineRuptureScenarioCalculationResponse(
|
|
1498
|
+
data.vessel,
|
|
1499
|
+
data.lineRupture,
|
|
1500
|
+
data.resultCode,
|
|
1501
|
+
data.messages,
|
|
1502
|
+
data.calculationElapsedTime,
|
|
1503
|
+
data.operationId
|
|
1504
|
+
);
|
|
1505
|
+
}
|
|
1506
|
+
}
|
|
1507
|
+
|
|
1508
|
+
export interface LoadMassInventoryVesselForReliefValveScenarioCalculationRequestSchemaData {
|
|
1509
|
+
material: Entities.Material;
|
|
1510
|
+
mass: number;
|
|
1511
|
+
pressure: number;
|
|
1512
|
+
temperature: number;
|
|
1513
|
+
constrictionSize: number;
|
|
1514
|
+
pipeDiameter: number;
|
|
1515
|
+
pipeLength: number;
|
|
1516
|
+
releaseElevation: number;
|
|
1517
|
+
releaseAngle: number;
|
|
1518
|
+
}
|
|
1519
|
+
|
|
1520
|
+
class LoadMassInventoryVesselForReliefValveScenarioCalculationRequest extends CalculationRequestBase {
|
|
1521
|
+
material: Entities.Material;
|
|
1522
|
+
mass: number;
|
|
1523
|
+
pressure: number;
|
|
1524
|
+
temperature: number;
|
|
1525
|
+
constrictionSize: number;
|
|
1526
|
+
pipeDiameter: number;
|
|
1527
|
+
pipeLength: number;
|
|
1528
|
+
releaseElevation: number;
|
|
1529
|
+
releaseAngle: number;
|
|
1530
|
+
|
|
1531
|
+
/**
|
|
1532
|
+
* LoadMassInventoryVesselForReliefValveScenario calculation request class.
|
|
1533
|
+
*
|
|
1534
|
+
* @param {Entities.Material} material - A Material entity.
|
|
1535
|
+
* @param {number} mass - Total vessel mass inventory.
|
|
1536
|
+
* @param {number} pressure - Absolute pressure of the fluid.
|
|
1537
|
+
* @param {number} temperature - Tmperature of the fluid.
|
|
1538
|
+
* @param {number} constrictionSize - Constriction diameter at the upstream end of the pipe.
|
|
1539
|
+
* @param {number} pipeDiameter - Internal diameter of the pipe.
|
|
1540
|
+
* @param {number} pipeLength - Length of the pipe.
|
|
1541
|
+
* @param {number} releaseElevation - Elevation of the release above ground level.
|
|
1542
|
+
* @param {number} releaseAngle - Angle of release above a horizontal plane.
|
|
1543
|
+
*/
|
|
1544
|
+
constructor(
|
|
1545
|
+
material: Entities.Material,
|
|
1546
|
+
mass: number,
|
|
1547
|
+
pressure: number,
|
|
1548
|
+
temperature: number,
|
|
1549
|
+
constrictionSize: number,
|
|
1550
|
+
pipeDiameter: number,
|
|
1551
|
+
pipeLength: number,
|
|
1552
|
+
releaseElevation: number,
|
|
1553
|
+
releaseAngle: number
|
|
1554
|
+
) {
|
|
1555
|
+
super();
|
|
1556
|
+
this.material = material;
|
|
1557
|
+
this.mass = mass;
|
|
1558
|
+
this.pressure = pressure;
|
|
1559
|
+
this.temperature = temperature;
|
|
1560
|
+
this.constrictionSize = constrictionSize;
|
|
1561
|
+
this.pipeDiameter = pipeDiameter;
|
|
1562
|
+
this.pipeLength = pipeLength;
|
|
1563
|
+
this.releaseElevation = releaseElevation;
|
|
1564
|
+
this.releaseAngle = releaseAngle;
|
|
1565
|
+
}
|
|
1566
|
+
}
|
|
1567
|
+
|
|
1568
|
+
export class LoadMassInventoryVesselForReliefValveScenarioCalculationRequestSchema {
|
|
1569
|
+
schema: Joi.ObjectSchema;
|
|
1570
|
+
propertyTypes: Record<string, string>;
|
|
1571
|
+
|
|
1572
|
+
/**
|
|
1573
|
+
* Schema for the LoadMassInventoryVesselForReliefValveScenario calculation request.
|
|
1574
|
+
*/
|
|
1575
|
+
constructor() {
|
|
1576
|
+
this.schema = Joi.object({
|
|
1577
|
+
material: new EntitySchemas.MaterialSchema().schema,
|
|
1578
|
+
mass: Joi.number().unsafe(),
|
|
1579
|
+
pressure: Joi.number().unsafe(),
|
|
1580
|
+
temperature: Joi.number().unsafe(),
|
|
1581
|
+
constrictionSize: Joi.number().unsafe(),
|
|
1582
|
+
pipeDiameter: Joi.number().unsafe(),
|
|
1583
|
+
pipeLength: Joi.number().unsafe(),
|
|
1584
|
+
releaseElevation: Joi.number().unsafe(),
|
|
1585
|
+
releaseAngle: Joi.number().unsafe(),
|
|
1586
|
+
}).unknown(true);
|
|
1587
|
+
|
|
1588
|
+
this.propertyTypes = {
|
|
1589
|
+
material: "Entities.Material",
|
|
1590
|
+
mass: "number",
|
|
1591
|
+
pressure: "number",
|
|
1592
|
+
temperature: "number",
|
|
1593
|
+
constrictionSize: "number",
|
|
1594
|
+
pipeDiameter: "number",
|
|
1595
|
+
pipeLength: "number",
|
|
1596
|
+
releaseElevation: "number",
|
|
1597
|
+
releaseAngle: "number",
|
|
1598
|
+
};
|
|
1599
|
+
}
|
|
1600
|
+
|
|
1601
|
+
validate(data: LoadMassInventoryVesselForReliefValveScenarioCalculationRequestSchemaData): LoadMassInventoryVesselForReliefValveScenarioCalculationRequest {
|
|
1602
|
+
const { error, value } = this.schema.validate(data, { abortEarly: false });
|
|
1603
|
+
if (error) {
|
|
1604
|
+
throw new Error(`Validation error: ${error.details.map((x) => x.message).join(", ")}`);
|
|
1605
|
+
}
|
|
1606
|
+
return this.makeCalculationRequest(value);
|
|
1607
|
+
}
|
|
1608
|
+
|
|
1609
|
+
makeCalculationRequest(data: LoadMassInventoryVesselForReliefValveScenarioCalculationRequestSchemaData): LoadMassInventoryVesselForReliefValveScenarioCalculationRequest {
|
|
1610
|
+
return new LoadMassInventoryVesselForReliefValveScenarioCalculationRequest(
|
|
1611
|
+
data.material,
|
|
1612
|
+
data.mass,
|
|
1613
|
+
data.pressure,
|
|
1614
|
+
data.temperature,
|
|
1615
|
+
data.constrictionSize,
|
|
1616
|
+
data.pipeDiameter,
|
|
1617
|
+
data.pipeLength,
|
|
1618
|
+
data.releaseElevation,
|
|
1619
|
+
data.releaseAngle
|
|
1620
|
+
);
|
|
1621
|
+
}
|
|
1622
|
+
}
|
|
1623
|
+
|
|
1624
|
+
export class LoadMassInventoryVesselForReliefValveScenarioCalculation extends CalculationBase {
|
|
1625
|
+
material: Entities.Material;
|
|
1626
|
+
mass: number;
|
|
1627
|
+
pressure: number;
|
|
1628
|
+
temperature: number;
|
|
1629
|
+
constrictionSize: number;
|
|
1630
|
+
pipeDiameter: number;
|
|
1631
|
+
pipeLength: number;
|
|
1632
|
+
releaseElevation: number;
|
|
1633
|
+
releaseAngle: number;
|
|
1634
|
+
vessel?: Entities.Vessel;
|
|
1635
|
+
reliefValve?: Entities.ReliefValve;
|
|
1636
|
+
|
|
1637
|
+
/**
|
|
1638
|
+
* Sets up a vessel and a relief valve scenario from a mass inventory, pressure, temperature pipe diameter, length and constriction size specifications.
|
|
1639
|
+
*
|
|
1640
|
+
* @param {Entities.Material} material - A Material entity.
|
|
1641
|
+
* @param {number} mass - Total vessel mass inventory.
|
|
1642
|
+
* @param {number} pressure - Absolute pressure of the fluid.
|
|
1643
|
+
* @param {number} temperature - Tmperature of the fluid.
|
|
1644
|
+
* @param {number} constrictionSize - Constriction diameter at the upstream end of the pipe.
|
|
1645
|
+
* @param {number} pipeDiameter - Internal diameter of the pipe.
|
|
1646
|
+
* @param {number} pipeLength - Length of the pipe.
|
|
1647
|
+
* @param {number} releaseElevation - Elevation of the release above ground level.
|
|
1648
|
+
* @param {number} releaseAngle - Angle of release above a horizontal plane.
|
|
1649
|
+
*/
|
|
1650
|
+
constructor(
|
|
1651
|
+
material: Entities.Material,
|
|
1652
|
+
mass: number,
|
|
1653
|
+
pressure: number,
|
|
1654
|
+
temperature: number,
|
|
1655
|
+
constrictionSize: number,
|
|
1656
|
+
pipeDiameter: number,
|
|
1657
|
+
pipeLength: number,
|
|
1658
|
+
releaseElevation: number,
|
|
1659
|
+
releaseAngle: number
|
|
1660
|
+
) {
|
|
1661
|
+
super();
|
|
1662
|
+
this.material = material;
|
|
1663
|
+
this.mass = mass;
|
|
1664
|
+
this.pressure = pressure;
|
|
1665
|
+
this.temperature = temperature;
|
|
1666
|
+
this.constrictionSize = constrictionSize;
|
|
1667
|
+
this.pipeDiameter = pipeDiameter;
|
|
1668
|
+
this.pipeLength = pipeLength;
|
|
1669
|
+
this.releaseElevation = releaseElevation;
|
|
1670
|
+
this.releaseAngle = releaseAngle;
|
|
1671
|
+
}
|
|
1672
|
+
|
|
1673
|
+
async run() {
|
|
1674
|
+
try {
|
|
1675
|
+
const request = new LoadMassInventoryVesselForReliefValveScenarioCalculationRequest(
|
|
1676
|
+
this.material,
|
|
1677
|
+
this.mass,
|
|
1678
|
+
this.pressure,
|
|
1679
|
+
this.temperature,
|
|
1680
|
+
this.constrictionSize,
|
|
1681
|
+
this.pipeDiameter,
|
|
1682
|
+
this.pipeLength,
|
|
1683
|
+
this.releaseElevation,
|
|
1684
|
+
this.releaseAngle
|
|
1685
|
+
);
|
|
1686
|
+
|
|
1687
|
+
const schema = new LoadMassInventoryVesselForReliefValveScenarioCalculationRequestSchema();
|
|
1688
|
+
const validatedRequest = schema.validate(request);
|
|
1689
|
+
|
|
1690
|
+
const requestJson = JSON.stringify(validatedRequest);
|
|
1691
|
+
const url = `${getAnalyticsApiTarget()}utilities/loadmassinventoryvesselforreliefvalvescenario?clientId=${getClientAliasId()}`;
|
|
1692
|
+
|
|
1693
|
+
this.resultCode = Enums.ResultCode.UNEXPECTED_APPLICATION_ERROR;
|
|
1694
|
+
|
|
1695
|
+
const response = await this.postRequest(url, requestJson);
|
|
1696
|
+
|
|
1697
|
+
if (response.status >= 200 && response.status < 300) {
|
|
1698
|
+
const schema = new LoadMassInventoryVesselForReliefValveScenarioCalculationResponseSchema();
|
|
1699
|
+
const validatedResponse = schema.validate(response.data);
|
|
1700
|
+
|
|
1701
|
+
this.resultCode = validatedResponse.resultCode;
|
|
1702
|
+
if (this.resultCode === Enums.ResultCode.SUCCESS) {
|
|
1703
|
+
this.vessel = validatedResponse.vessel;
|
|
1704
|
+
this.reliefValve = validatedResponse.reliefValve;
|
|
1705
|
+
this.resultCode = validatedResponse.resultCode;
|
|
1706
|
+
this.messages = validatedResponse.messages ?? [];
|
|
1707
|
+
this.calculationElapsedTime = validatedResponse.calculationElapsedTime;
|
|
1708
|
+
this.operationId = validatedResponse.operationId;
|
|
1709
|
+
} else {
|
|
1710
|
+
this.messages.push(...(validatedResponse.messages ?? []));
|
|
1711
|
+
}
|
|
1712
|
+
} else {
|
|
1713
|
+
this.handleFailedResponse(response);
|
|
1714
|
+
}
|
|
1715
|
+
} catch (error) {
|
|
1716
|
+
if (error instanceof Error) {
|
|
1717
|
+
this.messages.push(`Error: ${error.message}`);
|
|
1718
|
+
} else {
|
|
1719
|
+
this.messages.push(`Unexpected error: ${JSON.stringify(error)}`);
|
|
1720
|
+
}
|
|
1721
|
+
console.error(error);
|
|
1722
|
+
this.resultCode = Enums.ResultCode.UNEXPECTED_APPLICATION_ERROR;
|
|
1723
|
+
}
|
|
1724
|
+
|
|
1725
|
+
return this.resultCode;
|
|
1726
|
+
}
|
|
1727
|
+
|
|
1728
|
+
toString() {
|
|
1729
|
+
const parts = ["* LoadMassInventoryVesselForReliefValveScenario"];
|
|
1730
|
+
|
|
1731
|
+
parts.push(`vessel: ${String(this.vessel)}`);
|
|
1732
|
+
parts.push(`reliefValve: ${String(this.reliefValve)}`);
|
|
1733
|
+
parts.push(`resultCode: ${String(this.resultCode)}`);
|
|
1734
|
+
parts.push("*** messages:");
|
|
1735
|
+
parts.push(`messages: ${this.messages !== undefined ? this.messages : "(None)"}`);
|
|
1736
|
+
parts.push(`calculationElapsedTime: ${this.calculationElapsedTime !== undefined ? this.calculationElapsedTime : "(None)"}`);
|
|
1737
|
+
parts.push(`operationId: ${this.operationId !== undefined ? this.operationId : "(None)"}`);
|
|
1738
|
+
|
|
1739
|
+
return parts.join("\n");
|
|
1740
|
+
}
|
|
1741
|
+
}
|
|
1742
|
+
|
|
1743
|
+
export class LoadMassInventoryVesselForReliefValveScenarioCalculationResponse extends CalculationResponseBase {
|
|
1744
|
+
vessel: Entities.Vessel;
|
|
1745
|
+
reliefValve: Entities.ReliefValve;
|
|
1746
|
+
|
|
1747
|
+
/**
|
|
1748
|
+
* LoadMassInventoryVesselForReliefValveScenario calculation response class.
|
|
1749
|
+
*
|
|
1750
|
+
* @param {Entities.Vessel} vessel - A Vessel entity.
|
|
1751
|
+
* @param {Entities.ReliefValve} reliefValve - A Relief Valve entity.
|
|
1752
|
+
*/
|
|
1753
|
+
constructor(
|
|
1754
|
+
vessel: Entities.Vessel,
|
|
1755
|
+
reliefValve: Entities.ReliefValve,
|
|
1756
|
+
resultCode: Enums.ResultCode,
|
|
1757
|
+
messages: string[],
|
|
1758
|
+
calculationElapsedTime: number,
|
|
1759
|
+
operationId: string
|
|
1760
|
+
) {
|
|
1761
|
+
super();
|
|
1762
|
+
this.vessel = vessel;
|
|
1763
|
+
this.reliefValve = reliefValve;
|
|
1764
|
+
this.resultCode = resultCode;
|
|
1765
|
+
this.messages = messages;
|
|
1766
|
+
this.calculationElapsedTime = calculationElapsedTime;
|
|
1767
|
+
this.operationId = operationId;
|
|
1768
|
+
}
|
|
1769
|
+
|
|
1770
|
+
initialiseFromDictionary(data: { [key: string]: unknown }) {
|
|
1771
|
+
if (data.vessel) {
|
|
1772
|
+
this.vessel = new Entities.Vessel();
|
|
1773
|
+
this.vessel.initialiseFromDictionary(data.vessel as { [key: string]: unknown });
|
|
1774
|
+
}
|
|
1775
|
+
if (data.reliefValve) {
|
|
1776
|
+
this.reliefValve = new Entities.ReliefValve();
|
|
1777
|
+
this.reliefValve.initialiseFromDictionary(data.reliefValve as { [key: string]: unknown });
|
|
1778
|
+
}
|
|
1779
|
+
if (data.resultCode !== undefined && (typeof data.resultCode === "string" || typeof data.resultCode === "number")) {
|
|
1780
|
+
this.resultCode = data.resultCode as Enums.ResultCode;
|
|
1781
|
+
}
|
|
1782
|
+
this.messages = this.messages ?? [];
|
|
1783
|
+
if (data.messages && Array.isArray(data.messages)) {
|
|
1784
|
+
this.messages.push(...data.messages);
|
|
1785
|
+
}
|
|
1786
|
+
if (data.calculationElapsedTime !== undefined && typeof data.calculationElapsedTime === "number") {
|
|
1787
|
+
this.calculationElapsedTime = data.calculationElapsedTime as number;
|
|
1788
|
+
}
|
|
1789
|
+
if (data.operationId !== undefined && typeof data.operationId === "string") {
|
|
1790
|
+
this.operationId = data.operationId as string;
|
|
1791
|
+
}
|
|
1792
|
+
}
|
|
1793
|
+
}
|
|
1794
|
+
|
|
1795
|
+
export interface LoadMassInventoryVesselForReliefValveScenarioCalculationResponseSchemaData {
|
|
1796
|
+
vessel: Entities.Vessel;
|
|
1797
|
+
reliefValve: Entities.ReliefValve;
|
|
1798
|
+
resultCode: Enums.ResultCode;
|
|
1799
|
+
messages: string[];
|
|
1800
|
+
calculationElapsedTime: number;
|
|
1801
|
+
operationId: string;
|
|
1802
|
+
}
|
|
1803
|
+
|
|
1804
|
+
export class LoadMassInventoryVesselForReliefValveScenarioCalculationResponseSchema {
|
|
1805
|
+
schema: Joi.ObjectSchema;
|
|
1806
|
+
propertyTypes: Record<string, string>;
|
|
1807
|
+
|
|
1808
|
+
/**
|
|
1809
|
+
* Schema for the LoadMassInventoryVesselForReliefValveScenario calculation response.
|
|
1810
|
+
*/
|
|
1811
|
+
constructor() {
|
|
1812
|
+
this.schema = Joi.object({
|
|
1813
|
+
vessel: new EntitySchemas.VesselSchema().schema,
|
|
1814
|
+
reliefValve: new EntitySchemas.ReliefValveSchema().schema,
|
|
1815
|
+
resultCode: Joi.string().valid(...Object.values(Enums.ResultCode)),
|
|
1816
|
+
messages: Joi.array().items(Joi.string()),
|
|
1817
|
+
calculationElapsedTime: Joi.number().unsafe(),
|
|
1818
|
+
operationId: Joi.string().uuid().allow(null),
|
|
1819
|
+
}).unknown(true);
|
|
1820
|
+
|
|
1821
|
+
this.propertyTypes = {
|
|
1822
|
+
vessel: "Entities.Vessel",
|
|
1823
|
+
reliefValve: "Entities.ReliefValve",
|
|
1824
|
+
};
|
|
1825
|
+
}
|
|
1826
|
+
|
|
1827
|
+
validate(data: LoadMassInventoryVesselForReliefValveScenarioCalculationResponseSchemaData): LoadMassInventoryVesselForReliefValveScenarioCalculationResponse {
|
|
1828
|
+
const { error, value } = this.schema.validate(data, { abortEarly: false });
|
|
1829
|
+
if (error) {
|
|
1830
|
+
throw new Error(`Validation error: ${error.details.map((x) => x.message).join(", ")}`);
|
|
1831
|
+
}
|
|
1832
|
+
return this.makeCalculationResponse(value);
|
|
1833
|
+
}
|
|
1834
|
+
|
|
1835
|
+
makeCalculationResponse(data: LoadMassInventoryVesselForReliefValveScenarioCalculationResponseSchemaData): LoadMassInventoryVesselForReliefValveScenarioCalculationResponse {
|
|
1836
|
+
return new LoadMassInventoryVesselForReliefValveScenarioCalculationResponse(
|
|
1837
|
+
data.vessel,
|
|
1838
|
+
data.reliefValve,
|
|
1839
|
+
data.resultCode,
|
|
1840
|
+
data.messages,
|
|
1841
|
+
data.calculationElapsedTime,
|
|
1842
|
+
data.operationId
|
|
1843
|
+
);
|
|
1844
|
+
}
|
|
1845
|
+
}
|
|
1846
|
+
|
|
1847
|
+
export interface ReliefValveMinTemperatureCalculationRequestSchemaData {
|
|
1848
|
+
material: Entities.Material;
|
|
1849
|
+
pressure: number;
|
|
1850
|
+
}
|
|
1851
|
+
|
|
1852
|
+
class ReliefValveMinTemperatureCalculationRequest extends CalculationRequestBase {
|
|
1853
|
+
material: Entities.Material;
|
|
1854
|
+
pressure: number;
|
|
1855
|
+
|
|
1856
|
+
/**
|
|
1857
|
+
* ReliefValveMinTemperature calculation request class.
|
|
1858
|
+
*
|
|
1859
|
+
* @param {Entities.Material} material - A Material entity.
|
|
1860
|
+
* @param {number} pressure - Input pressure (absolute) at which to evaluate bubble point temperature.
|
|
1861
|
+
*/
|
|
1862
|
+
constructor(
|
|
1863
|
+
material: Entities.Material,
|
|
1864
|
+
pressure: number
|
|
1865
|
+
) {
|
|
1866
|
+
super();
|
|
1867
|
+
this.material = material;
|
|
1868
|
+
this.pressure = pressure;
|
|
1869
|
+
}
|
|
1870
|
+
}
|
|
1871
|
+
|
|
1872
|
+
export class ReliefValveMinTemperatureCalculationRequestSchema {
|
|
1873
|
+
schema: Joi.ObjectSchema;
|
|
1874
|
+
propertyTypes: Record<string, string>;
|
|
1875
|
+
|
|
1876
|
+
/**
|
|
1877
|
+
* Schema for the ReliefValveMinTemperature calculation request.
|
|
1878
|
+
*/
|
|
1879
|
+
constructor() {
|
|
1880
|
+
this.schema = Joi.object({
|
|
1881
|
+
material: new EntitySchemas.MaterialSchema().schema,
|
|
1882
|
+
pressure: Joi.number().unsafe(),
|
|
1883
|
+
}).unknown(true);
|
|
1884
|
+
|
|
1885
|
+
this.propertyTypes = {
|
|
1886
|
+
material: "Entities.Material",
|
|
1887
|
+
pressure: "number",
|
|
1888
|
+
};
|
|
1889
|
+
}
|
|
1890
|
+
|
|
1891
|
+
validate(data: ReliefValveMinTemperatureCalculationRequestSchemaData): ReliefValveMinTemperatureCalculationRequest {
|
|
1892
|
+
const { error, value } = this.schema.validate(data, { abortEarly: false });
|
|
1893
|
+
if (error) {
|
|
1894
|
+
throw new Error(`Validation error: ${error.details.map((x) => x.message).join(", ")}`);
|
|
1895
|
+
}
|
|
1896
|
+
return this.makeCalculationRequest(value);
|
|
1897
|
+
}
|
|
1898
|
+
|
|
1899
|
+
makeCalculationRequest(data: ReliefValveMinTemperatureCalculationRequestSchemaData): ReliefValveMinTemperatureCalculationRequest {
|
|
1900
|
+
return new ReliefValveMinTemperatureCalculationRequest(
|
|
1901
|
+
data.material,
|
|
1902
|
+
data.pressure
|
|
1903
|
+
);
|
|
1904
|
+
}
|
|
1905
|
+
}
|
|
1906
|
+
|
|
1907
|
+
export class ReliefValveMinTemperatureCalculation extends CalculationBase {
|
|
1908
|
+
material: Entities.Material;
|
|
1909
|
+
pressure: number;
|
|
1910
|
+
minTemperature?: number;
|
|
1911
|
+
|
|
1912
|
+
/**
|
|
1913
|
+
* The Relief Valve scenario does not allow fluid conditions to be liquid. As such, his method calculates the lower limit for the input temperature to ensure vapour or two-phase fluid state.
|
|
1914
|
+
*
|
|
1915
|
+
* @param {Entities.Material} material - A Material entity.
|
|
1916
|
+
* @param {number} pressure - Input pressure (absolute) at which to evaluate bubble point temperature.
|
|
1917
|
+
*/
|
|
1918
|
+
constructor(
|
|
1919
|
+
material: Entities.Material,
|
|
1920
|
+
pressure: number
|
|
1921
|
+
) {
|
|
1922
|
+
super();
|
|
1923
|
+
this.material = material;
|
|
1924
|
+
this.pressure = pressure;
|
|
1925
|
+
}
|
|
1926
|
+
|
|
1927
|
+
async run() {
|
|
1928
|
+
try {
|
|
1929
|
+
const request = new ReliefValveMinTemperatureCalculationRequest(
|
|
1930
|
+
this.material,
|
|
1931
|
+
this.pressure
|
|
1932
|
+
);
|
|
1933
|
+
|
|
1934
|
+
const schema = new ReliefValveMinTemperatureCalculationRequestSchema();
|
|
1935
|
+
const validatedRequest = schema.validate(request);
|
|
1936
|
+
|
|
1937
|
+
const requestJson = JSON.stringify(validatedRequest);
|
|
1938
|
+
const url = `${getAnalyticsApiTarget()}utilities/reliefvalvemintemperature?clientId=${getClientAliasId()}`;
|
|
1939
|
+
|
|
1940
|
+
this.resultCode = Enums.ResultCode.UNEXPECTED_APPLICATION_ERROR;
|
|
1941
|
+
|
|
1942
|
+
const response = await this.postRequest(url, requestJson);
|
|
1943
|
+
|
|
1944
|
+
if (response.status >= 200 && response.status < 300) {
|
|
1945
|
+
const schema = new ReliefValveMinTemperatureCalculationResponseSchema();
|
|
1946
|
+
const validatedResponse = schema.validate(response.data);
|
|
1947
|
+
|
|
1948
|
+
this.resultCode = validatedResponse.resultCode;
|
|
1949
|
+
if (this.resultCode === Enums.ResultCode.SUCCESS) {
|
|
1950
|
+
this.minTemperature = validatedResponse.minTemperature;
|
|
1951
|
+
this.resultCode = validatedResponse.resultCode;
|
|
1952
|
+
this.messages = validatedResponse.messages ?? [];
|
|
1953
|
+
this.calculationElapsedTime = validatedResponse.calculationElapsedTime;
|
|
1954
|
+
this.operationId = validatedResponse.operationId;
|
|
1955
|
+
} else {
|
|
1956
|
+
this.messages.push(...(validatedResponse.messages ?? []));
|
|
1957
|
+
}
|
|
1958
|
+
} else {
|
|
1959
|
+
this.handleFailedResponse(response);
|
|
1960
|
+
}
|
|
1961
|
+
} catch (error) {
|
|
1962
|
+
if (error instanceof Error) {
|
|
1963
|
+
this.messages.push(`Error: ${error.message}`);
|
|
1964
|
+
} else {
|
|
1965
|
+
this.messages.push(`Unexpected error: ${JSON.stringify(error)}`);
|
|
1966
|
+
}
|
|
1967
|
+
console.error(error);
|
|
1968
|
+
this.resultCode = Enums.ResultCode.UNEXPECTED_APPLICATION_ERROR;
|
|
1969
|
+
}
|
|
1970
|
+
|
|
1971
|
+
return this.resultCode;
|
|
1972
|
+
}
|
|
1973
|
+
|
|
1974
|
+
toString() {
|
|
1975
|
+
const parts = ["* ReliefValveMinTemperature"];
|
|
1976
|
+
|
|
1977
|
+
parts.push(`minTemperature: ${String(this.minTemperature)}`);
|
|
1978
|
+
parts.push(`resultCode: ${String(this.resultCode)}`);
|
|
1979
|
+
parts.push("*** messages:");
|
|
1980
|
+
parts.push(`messages: ${this.messages !== undefined ? this.messages : "(None)"}`);
|
|
1981
|
+
parts.push(`calculationElapsedTime: ${this.calculationElapsedTime !== undefined ? this.calculationElapsedTime : "(None)"}`);
|
|
1982
|
+
parts.push(`operationId: ${this.operationId !== undefined ? this.operationId : "(None)"}`);
|
|
1983
|
+
|
|
1984
|
+
return parts.join("\n");
|
|
1985
|
+
}
|
|
1986
|
+
}
|
|
1987
|
+
|
|
1988
|
+
export class ReliefValveMinTemperatureCalculationResponse extends CalculationResponseBase {
|
|
1989
|
+
minTemperature: number;
|
|
1990
|
+
|
|
1991
|
+
/**
|
|
1992
|
+
* ReliefValveMinTemperature calculation response class.
|
|
1993
|
+
*
|
|
1994
|
+
* @param {number} minTemperature - Calculated lower temperature limit for relief valve scenario.
|
|
1995
|
+
*/
|
|
1996
|
+
constructor(
|
|
1997
|
+
minTemperature: number,
|
|
1998
|
+
resultCode: Enums.ResultCode,
|
|
1999
|
+
messages: string[],
|
|
2000
|
+
calculationElapsedTime: number,
|
|
2001
|
+
operationId: string
|
|
2002
|
+
) {
|
|
2003
|
+
super();
|
|
2004
|
+
this.minTemperature = minTemperature;
|
|
2005
|
+
this.resultCode = resultCode;
|
|
2006
|
+
this.messages = messages;
|
|
2007
|
+
this.calculationElapsedTime = calculationElapsedTime;
|
|
2008
|
+
this.operationId = operationId;
|
|
2009
|
+
}
|
|
2010
|
+
|
|
2011
|
+
initialiseFromDictionary(data: { [key: string]: unknown }) {
|
|
2012
|
+
if (data.minTemperature !== undefined && typeof data.minTemperature === "number") {
|
|
2013
|
+
this.minTemperature = data.minTemperature as number;
|
|
2014
|
+
}
|
|
2015
|
+
if (data.resultCode !== undefined && (typeof data.resultCode === "string" || typeof data.resultCode === "number")) {
|
|
2016
|
+
this.resultCode = data.resultCode as Enums.ResultCode;
|
|
2017
|
+
}
|
|
2018
|
+
this.messages = this.messages ?? [];
|
|
2019
|
+
if (data.messages && Array.isArray(data.messages)) {
|
|
2020
|
+
this.messages.push(...data.messages);
|
|
2021
|
+
}
|
|
2022
|
+
if (data.calculationElapsedTime !== undefined && typeof data.calculationElapsedTime === "number") {
|
|
2023
|
+
this.calculationElapsedTime = data.calculationElapsedTime as number;
|
|
2024
|
+
}
|
|
2025
|
+
if (data.operationId !== undefined && typeof data.operationId === "string") {
|
|
2026
|
+
this.operationId = data.operationId as string;
|
|
2027
|
+
}
|
|
2028
|
+
}
|
|
2029
|
+
}
|
|
2030
|
+
|
|
2031
|
+
export interface ReliefValveMinTemperatureCalculationResponseSchemaData {
|
|
2032
|
+
minTemperature: number;
|
|
2033
|
+
resultCode: Enums.ResultCode;
|
|
2034
|
+
messages: string[];
|
|
2035
|
+
calculationElapsedTime: number;
|
|
2036
|
+
operationId: string;
|
|
2037
|
+
}
|
|
2038
|
+
|
|
2039
|
+
export class ReliefValveMinTemperatureCalculationResponseSchema {
|
|
2040
|
+
schema: Joi.ObjectSchema;
|
|
2041
|
+
propertyTypes: Record<string, string>;
|
|
2042
|
+
|
|
2043
|
+
/**
|
|
2044
|
+
* Schema for the ReliefValveMinTemperature calculation response.
|
|
2045
|
+
*/
|
|
2046
|
+
constructor() {
|
|
2047
|
+
this.schema = Joi.object({
|
|
2048
|
+
minTemperature: Joi.number().unsafe(),
|
|
2049
|
+
resultCode: Joi.string().valid(...Object.values(Enums.ResultCode)),
|
|
2050
|
+
messages: Joi.array().items(Joi.string()),
|
|
2051
|
+
calculationElapsedTime: Joi.number().unsafe(),
|
|
2052
|
+
operationId: Joi.string().uuid().allow(null),
|
|
2053
|
+
}).unknown(true);
|
|
2054
|
+
|
|
2055
|
+
this.propertyTypes = {
|
|
2056
|
+
minTemperature: "number",
|
|
2057
|
+
};
|
|
2058
|
+
}
|
|
2059
|
+
|
|
2060
|
+
validate(data: ReliefValveMinTemperatureCalculationResponseSchemaData): ReliefValveMinTemperatureCalculationResponse {
|
|
2061
|
+
const { error, value } = this.schema.validate(data, { abortEarly: false });
|
|
2062
|
+
if (error) {
|
|
2063
|
+
throw new Error(`Validation error: ${error.details.map((x) => x.message).join(", ")}`);
|
|
2064
|
+
}
|
|
2065
|
+
return this.makeCalculationResponse(value);
|
|
2066
|
+
}
|
|
2067
|
+
|
|
2068
|
+
makeCalculationResponse(data: ReliefValveMinTemperatureCalculationResponseSchemaData): ReliefValveMinTemperatureCalculationResponse {
|
|
2069
|
+
return new ReliefValveMinTemperatureCalculationResponse(
|
|
2070
|
+
data.minTemperature,
|
|
2071
|
+
data.resultCode,
|
|
2072
|
+
data.messages,
|
|
2073
|
+
data.calculationElapsedTime,
|
|
2074
|
+
data.operationId
|
|
2075
|
+
);
|
|
2076
|
+
}
|
|
2077
|
+
}
|
|
2078
|
+
|
|
2079
|
+
export interface SetMixingLayerHeightCalculationRequestSchemaData {
|
|
2080
|
+
weather: Entities.Weather;
|
|
2081
|
+
}
|
|
2082
|
+
|
|
2083
|
+
class SetMixingLayerHeightCalculationRequest extends CalculationRequestBase {
|
|
2084
|
+
weather: Entities.Weather;
|
|
2085
|
+
|
|
2086
|
+
/**
|
|
2087
|
+
* SetMixingLayerHeight calculation request class.
|
|
2088
|
+
*
|
|
2089
|
+
* @param {Entities.Weather} weather - A Weather entity.
|
|
2090
|
+
*/
|
|
2091
|
+
constructor(
|
|
2092
|
+
weather: Entities.Weather
|
|
2093
|
+
) {
|
|
2094
|
+
super();
|
|
2095
|
+
this.weather = weather;
|
|
2096
|
+
}
|
|
2097
|
+
}
|
|
2098
|
+
|
|
2099
|
+
export class SetMixingLayerHeightCalculationRequestSchema {
|
|
2100
|
+
schema: Joi.ObjectSchema;
|
|
2101
|
+
propertyTypes: Record<string, string>;
|
|
2102
|
+
|
|
2103
|
+
/**
|
|
2104
|
+
* Schema for the SetMixingLayerHeight calculation request.
|
|
2105
|
+
*/
|
|
2106
|
+
constructor() {
|
|
2107
|
+
this.schema = Joi.object({
|
|
2108
|
+
weather: new EntitySchemas.WeatherSchema().schema,
|
|
2109
|
+
}).unknown(true);
|
|
2110
|
+
|
|
2111
|
+
this.propertyTypes = {
|
|
2112
|
+
weather: "Entities.Weather",
|
|
2113
|
+
};
|
|
2114
|
+
}
|
|
2115
|
+
|
|
2116
|
+
validate(data: SetMixingLayerHeightCalculationRequestSchemaData): SetMixingLayerHeightCalculationRequest {
|
|
2117
|
+
const { error, value } = this.schema.validate(data, { abortEarly: false });
|
|
2118
|
+
if (error) {
|
|
2119
|
+
throw new Error(`Validation error: ${error.details.map((x) => x.message).join(", ")}`);
|
|
2120
|
+
}
|
|
2121
|
+
return this.makeCalculationRequest(value);
|
|
2122
|
+
}
|
|
2123
|
+
|
|
2124
|
+
makeCalculationRequest(data: SetMixingLayerHeightCalculationRequestSchemaData): SetMixingLayerHeightCalculationRequest {
|
|
2125
|
+
return new SetMixingLayerHeightCalculationRequest(
|
|
2126
|
+
data.weather
|
|
2127
|
+
);
|
|
2128
|
+
}
|
|
2129
|
+
}
|
|
2130
|
+
|
|
2131
|
+
export class SetMixingLayerHeightCalculation extends CalculationBase {
|
|
2132
|
+
weather: Entities.Weather;
|
|
2133
|
+
updatedWeather?: Entities.Weather;
|
|
2134
|
+
|
|
2135
|
+
/**
|
|
2136
|
+
* Updates the mixing layer height in a weather according to the stability class,.
|
|
2137
|
+
*
|
|
2138
|
+
* @param {Entities.Weather} weather - A Weather entity.
|
|
2139
|
+
*/
|
|
2140
|
+
constructor(
|
|
2141
|
+
weather: Entities.Weather
|
|
2142
|
+
) {
|
|
2143
|
+
super();
|
|
2144
|
+
this.weather = weather;
|
|
2145
|
+
}
|
|
2146
|
+
|
|
2147
|
+
async run() {
|
|
2148
|
+
try {
|
|
2149
|
+
const request = new SetMixingLayerHeightCalculationRequest(
|
|
2150
|
+
this.weather
|
|
2151
|
+
);
|
|
2152
|
+
|
|
2153
|
+
const schema = new SetMixingLayerHeightCalculationRequestSchema();
|
|
2154
|
+
const validatedRequest = schema.validate(request);
|
|
2155
|
+
|
|
2156
|
+
const requestJson = JSON.stringify(validatedRequest);
|
|
2157
|
+
const url = `${getAnalyticsApiTarget()}utilities/SetMixingLayerHeight?clientId=${getClientAliasId()}`;
|
|
2158
|
+
|
|
2159
|
+
this.resultCode = Enums.ResultCode.UNEXPECTED_APPLICATION_ERROR;
|
|
2160
|
+
|
|
2161
|
+
const response = await this.postRequest(url, requestJson);
|
|
2162
|
+
|
|
2163
|
+
if (response.status >= 200 && response.status < 300) {
|
|
2164
|
+
const schema = new SetMixingLayerHeightCalculationResponseSchema();
|
|
2165
|
+
const validatedResponse = schema.validate(response.data);
|
|
2166
|
+
|
|
2167
|
+
this.resultCode = validatedResponse.resultCode;
|
|
2168
|
+
if (this.resultCode === Enums.ResultCode.SUCCESS) {
|
|
2169
|
+
this.updatedWeather = validatedResponse.updatedWeather;
|
|
2170
|
+
this.resultCode = validatedResponse.resultCode;
|
|
2171
|
+
this.messages = validatedResponse.messages ?? [];
|
|
2172
|
+
this.calculationElapsedTime = validatedResponse.calculationElapsedTime;
|
|
2173
|
+
this.operationId = validatedResponse.operationId;
|
|
2174
|
+
} else {
|
|
2175
|
+
this.messages.push(...(validatedResponse.messages ?? []));
|
|
2176
|
+
}
|
|
2177
|
+
} else {
|
|
2178
|
+
this.handleFailedResponse(response);
|
|
2179
|
+
}
|
|
2180
|
+
} catch (error) {
|
|
2181
|
+
if (error instanceof Error) {
|
|
2182
|
+
this.messages.push(`Error: ${error.message}`);
|
|
2183
|
+
} else {
|
|
2184
|
+
this.messages.push(`Unexpected error: ${JSON.stringify(error)}`);
|
|
2185
|
+
}
|
|
2186
|
+
console.error(error);
|
|
2187
|
+
this.resultCode = Enums.ResultCode.UNEXPECTED_APPLICATION_ERROR;
|
|
2188
|
+
}
|
|
2189
|
+
|
|
2190
|
+
return this.resultCode;
|
|
2191
|
+
}
|
|
2192
|
+
|
|
2193
|
+
toString() {
|
|
2194
|
+
const parts = ["* SetMixingLayerHeight"];
|
|
2195
|
+
|
|
2196
|
+
parts.push(`updatedWeather: ${String(this.updatedWeather)}`);
|
|
2197
|
+
parts.push(`resultCode: ${String(this.resultCode)}`);
|
|
2198
|
+
parts.push("*** messages:");
|
|
2199
|
+
parts.push(`messages: ${this.messages !== undefined ? this.messages : "(None)"}`);
|
|
2200
|
+
parts.push(`calculationElapsedTime: ${this.calculationElapsedTime !== undefined ? this.calculationElapsedTime : "(None)"}`);
|
|
2201
|
+
parts.push(`operationId: ${this.operationId !== undefined ? this.operationId : "(None)"}`);
|
|
2202
|
+
|
|
2203
|
+
return parts.join("\n");
|
|
2204
|
+
}
|
|
2205
|
+
}
|
|
2206
|
+
|
|
2207
|
+
export class SetMixingLayerHeightCalculationResponse extends CalculationResponseBase {
|
|
2208
|
+
updatedWeather: Entities.Weather;
|
|
2209
|
+
|
|
2210
|
+
/**
|
|
2211
|
+
* SetMixingLayerHeight calculation response class.
|
|
2212
|
+
*
|
|
2213
|
+
* @param {Entities.Weather} updatedWeather - Updated Weather entity.
|
|
2214
|
+
*/
|
|
2215
|
+
constructor(
|
|
2216
|
+
updatedWeather: Entities.Weather,
|
|
2217
|
+
resultCode: Enums.ResultCode,
|
|
2218
|
+
messages: string[],
|
|
2219
|
+
calculationElapsedTime: number,
|
|
2220
|
+
operationId: string
|
|
2221
|
+
) {
|
|
2222
|
+
super();
|
|
2223
|
+
this.updatedWeather = updatedWeather;
|
|
2224
|
+
this.resultCode = resultCode;
|
|
2225
|
+
this.messages = messages;
|
|
2226
|
+
this.calculationElapsedTime = calculationElapsedTime;
|
|
2227
|
+
this.operationId = operationId;
|
|
2228
|
+
}
|
|
2229
|
+
|
|
2230
|
+
initialiseFromDictionary(data: { [key: string]: unknown }) {
|
|
2231
|
+
if (data.updatedWeather) {
|
|
2232
|
+
this.updatedWeather = new Entities.Weather();
|
|
2233
|
+
this.updatedWeather.initialiseFromDictionary(data.updatedWeather as { [key: string]: unknown });
|
|
2234
|
+
}
|
|
2235
|
+
if (data.resultCode !== undefined && (typeof data.resultCode === "string" || typeof data.resultCode === "number")) {
|
|
2236
|
+
this.resultCode = data.resultCode as Enums.ResultCode;
|
|
2237
|
+
}
|
|
2238
|
+
this.messages = this.messages ?? [];
|
|
2239
|
+
if (data.messages && Array.isArray(data.messages)) {
|
|
2240
|
+
this.messages.push(...data.messages);
|
|
2241
|
+
}
|
|
2242
|
+
if (data.calculationElapsedTime !== undefined && typeof data.calculationElapsedTime === "number") {
|
|
2243
|
+
this.calculationElapsedTime = data.calculationElapsedTime as number;
|
|
2244
|
+
}
|
|
2245
|
+
if (data.operationId !== undefined && typeof data.operationId === "string") {
|
|
2246
|
+
this.operationId = data.operationId as string;
|
|
2247
|
+
}
|
|
2248
|
+
}
|
|
2249
|
+
}
|
|
2250
|
+
|
|
2251
|
+
export interface SetMixingLayerHeightCalculationResponseSchemaData {
|
|
2252
|
+
updatedWeather: Entities.Weather;
|
|
2253
|
+
resultCode: Enums.ResultCode;
|
|
2254
|
+
messages: string[];
|
|
2255
|
+
calculationElapsedTime: number;
|
|
2256
|
+
operationId: string;
|
|
2257
|
+
}
|
|
2258
|
+
|
|
2259
|
+
export class SetMixingLayerHeightCalculationResponseSchema {
|
|
2260
|
+
schema: Joi.ObjectSchema;
|
|
2261
|
+
propertyTypes: Record<string, string>;
|
|
2262
|
+
|
|
2263
|
+
/**
|
|
2264
|
+
* Schema for the SetMixingLayerHeight calculation response.
|
|
2265
|
+
*/
|
|
2266
|
+
constructor() {
|
|
2267
|
+
this.schema = Joi.object({
|
|
2268
|
+
updatedWeather: new EntitySchemas.WeatherSchema().schema,
|
|
2269
|
+
resultCode: Joi.string().valid(...Object.values(Enums.ResultCode)),
|
|
2270
|
+
messages: Joi.array().items(Joi.string()),
|
|
2271
|
+
calculationElapsedTime: Joi.number().unsafe(),
|
|
2272
|
+
operationId: Joi.string().uuid().allow(null),
|
|
2273
|
+
}).unknown(true);
|
|
2274
|
+
|
|
2275
|
+
this.propertyTypes = {
|
|
2276
|
+
updatedWeather: "Entities.Weather",
|
|
2277
|
+
};
|
|
2278
|
+
}
|
|
2279
|
+
|
|
2280
|
+
validate(data: SetMixingLayerHeightCalculationResponseSchemaData): SetMixingLayerHeightCalculationResponse {
|
|
2281
|
+
const { error, value } = this.schema.validate(data, { abortEarly: false });
|
|
2282
|
+
if (error) {
|
|
2283
|
+
throw new Error(`Validation error: ${error.details.map((x) => x.message).join(", ")}`);
|
|
2284
|
+
}
|
|
2285
|
+
return this.makeCalculationResponse(value);
|
|
2286
|
+
}
|
|
2287
|
+
|
|
2288
|
+
makeCalculationResponse(data: SetMixingLayerHeightCalculationResponseSchemaData): SetMixingLayerHeightCalculationResponse {
|
|
2289
|
+
return new SetMixingLayerHeightCalculationResponse(
|
|
2290
|
+
data.updatedWeather,
|
|
2291
|
+
data.resultCode,
|
|
2292
|
+
data.messages,
|
|
2293
|
+
data.calculationElapsedTime,
|
|
2294
|
+
data.operationId
|
|
2295
|
+
);
|
|
2296
|
+
}
|
|
2297
|
+
}
|
|
2298
|
+
|
|
2299
|
+
export interface SetPhaseToReleaseForLeakScenarioCalculationRequestSchemaData {
|
|
2300
|
+
phaseToRelease: Enums.Phase;
|
|
2301
|
+
releaseElevation: number;
|
|
2302
|
+
vessel: Entities.Vessel;
|
|
2303
|
+
}
|
|
2304
|
+
|
|
2305
|
+
class SetPhaseToReleaseForLeakScenarioCalculationRequest extends CalculationRequestBase {
|
|
2306
|
+
phaseToRelease: Enums.Phase;
|
|
2307
|
+
releaseElevation: number;
|
|
2308
|
+
vessel: Entities.Vessel;
|
|
2309
|
+
|
|
2310
|
+
/**
|
|
2311
|
+
* SetPhaseToReleaseForLeakScenario calculation request class.
|
|
2312
|
+
*
|
|
2313
|
+
* @param {Enums.Phase} phaseToRelease - Requested fluid phase to release.
|
|
2314
|
+
* @param {number} releaseElevation - Release point elevation above ground.
|
|
2315
|
+
* @param {Entities.Vessel} vessel - A Vessel entity.
|
|
2316
|
+
*/
|
|
2317
|
+
constructor(
|
|
2318
|
+
phaseToRelease: Enums.Phase,
|
|
2319
|
+
releaseElevation: number,
|
|
2320
|
+
vessel: Entities.Vessel
|
|
2321
|
+
) {
|
|
2322
|
+
super();
|
|
2323
|
+
this.phaseToRelease = phaseToRelease;
|
|
2324
|
+
this.releaseElevation = releaseElevation;
|
|
2325
|
+
this.vessel = vessel;
|
|
2326
|
+
}
|
|
2327
|
+
}
|
|
2328
|
+
|
|
2329
|
+
export class SetPhaseToReleaseForLeakScenarioCalculationRequestSchema {
|
|
2330
|
+
schema: Joi.ObjectSchema;
|
|
2331
|
+
propertyTypes: Record<string, string>;
|
|
2332
|
+
|
|
2333
|
+
/**
|
|
2334
|
+
* Schema for the SetPhaseToReleaseForLeakScenario calculation request.
|
|
2335
|
+
*/
|
|
2336
|
+
constructor() {
|
|
2337
|
+
this.schema = Joi.object({
|
|
2338
|
+
phaseToRelease: Joi.string().valid(...Object.values(Enums.Phase)),
|
|
2339
|
+
releaseElevation: Joi.number().unsafe(),
|
|
2340
|
+
vessel: new EntitySchemas.VesselSchema().schema,
|
|
2341
|
+
}).unknown(true);
|
|
2342
|
+
|
|
2343
|
+
this.propertyTypes = {
|
|
2344
|
+
phaseToRelease: "Enums.Phase",
|
|
2345
|
+
releaseElevation: "number",
|
|
2346
|
+
vessel: "Entities.Vessel",
|
|
2347
|
+
};
|
|
2348
|
+
}
|
|
2349
|
+
|
|
2350
|
+
validate(data: SetPhaseToReleaseForLeakScenarioCalculationRequestSchemaData): SetPhaseToReleaseForLeakScenarioCalculationRequest {
|
|
2351
|
+
const { error, value } = this.schema.validate(data, { abortEarly: false });
|
|
2352
|
+
if (error) {
|
|
2353
|
+
throw new Error(`Validation error: ${error.details.map((x) => x.message).join(", ")}`);
|
|
2354
|
+
}
|
|
2355
|
+
return this.makeCalculationRequest(value);
|
|
2356
|
+
}
|
|
2357
|
+
|
|
2358
|
+
makeCalculationRequest(data: SetPhaseToReleaseForLeakScenarioCalculationRequestSchemaData): SetPhaseToReleaseForLeakScenarioCalculationRequest {
|
|
2359
|
+
return new SetPhaseToReleaseForLeakScenarioCalculationRequest(
|
|
2360
|
+
data.phaseToRelease,
|
|
2361
|
+
data.releaseElevation,
|
|
2362
|
+
data.vessel
|
|
2363
|
+
);
|
|
2364
|
+
}
|
|
2365
|
+
}
|
|
2366
|
+
|
|
2367
|
+
export class SetPhaseToReleaseForLeakScenarioCalculation extends CalculationBase {
|
|
2368
|
+
phaseToRelease: Enums.Phase;
|
|
2369
|
+
releaseElevation: number;
|
|
2370
|
+
vessel: Entities.Vessel;
|
|
2371
|
+
zCoordUpdated?: number;
|
|
2372
|
+
holeHeightFractionUpdated?: number;
|
|
2373
|
+
|
|
2374
|
+
/**
|
|
2375
|
+
* Calculates the hole height fraction and vessel z coordinate to release the requested phase (vapour or liquid).
|
|
2376
|
+
*
|
|
2377
|
+
* @param {Enums.Phase} phaseToRelease - Requested fluid phase to release.
|
|
2378
|
+
* @param {number} releaseElevation - Release point elevation above ground.
|
|
2379
|
+
* @param {Entities.Vessel} vessel - A Vessel entity.
|
|
2380
|
+
*/
|
|
2381
|
+
constructor(
|
|
2382
|
+
phaseToRelease: Enums.Phase,
|
|
2383
|
+
releaseElevation: number,
|
|
2384
|
+
vessel: Entities.Vessel
|
|
2385
|
+
) {
|
|
2386
|
+
super();
|
|
2387
|
+
this.phaseToRelease = phaseToRelease;
|
|
2388
|
+
this.releaseElevation = releaseElevation;
|
|
2389
|
+
this.vessel = vessel;
|
|
2390
|
+
}
|
|
2391
|
+
|
|
2392
|
+
async run() {
|
|
2393
|
+
try {
|
|
2394
|
+
const request = new SetPhaseToReleaseForLeakScenarioCalculationRequest(
|
|
2395
|
+
this.phaseToRelease,
|
|
2396
|
+
this.releaseElevation,
|
|
2397
|
+
this.vessel
|
|
2398
|
+
);
|
|
2399
|
+
|
|
2400
|
+
const schema = new SetPhaseToReleaseForLeakScenarioCalculationRequestSchema();
|
|
2401
|
+
const validatedRequest = schema.validate(request);
|
|
2402
|
+
|
|
2403
|
+
const requestJson = JSON.stringify(validatedRequest);
|
|
2404
|
+
const url = `${getAnalyticsApiTarget()}utilities/setphasetoreleaseforleakscenario?clientId=${getClientAliasId()}`;
|
|
2405
|
+
|
|
2406
|
+
this.resultCode = Enums.ResultCode.UNEXPECTED_APPLICATION_ERROR;
|
|
2407
|
+
|
|
2408
|
+
const response = await this.postRequest(url, requestJson);
|
|
2409
|
+
|
|
2410
|
+
if (response.status >= 200 && response.status < 300) {
|
|
2411
|
+
const schema = new SetPhaseToReleaseForLeakScenarioCalculationResponseSchema();
|
|
2412
|
+
const validatedResponse = schema.validate(response.data);
|
|
2413
|
+
|
|
2414
|
+
this.resultCode = validatedResponse.resultCode;
|
|
2415
|
+
if (this.resultCode === Enums.ResultCode.SUCCESS) {
|
|
2416
|
+
this.zCoordUpdated = validatedResponse.zCoordUpdated;
|
|
2417
|
+
this.holeHeightFractionUpdated = validatedResponse.holeHeightFractionUpdated;
|
|
2418
|
+
this.resultCode = validatedResponse.resultCode;
|
|
2419
|
+
this.messages = validatedResponse.messages ?? [];
|
|
2420
|
+
this.calculationElapsedTime = validatedResponse.calculationElapsedTime;
|
|
2421
|
+
this.operationId = validatedResponse.operationId;
|
|
2422
|
+
} else {
|
|
2423
|
+
this.messages.push(...(validatedResponse.messages ?? []));
|
|
2424
|
+
}
|
|
2425
|
+
} else {
|
|
2426
|
+
this.handleFailedResponse(response);
|
|
2427
|
+
}
|
|
2428
|
+
} catch (error) {
|
|
2429
|
+
if (error instanceof Error) {
|
|
2430
|
+
this.messages.push(`Error: ${error.message}`);
|
|
2431
|
+
} else {
|
|
2432
|
+
this.messages.push(`Unexpected error: ${JSON.stringify(error)}`);
|
|
2433
|
+
}
|
|
2434
|
+
console.error(error);
|
|
2435
|
+
this.resultCode = Enums.ResultCode.UNEXPECTED_APPLICATION_ERROR;
|
|
2436
|
+
}
|
|
2437
|
+
|
|
2438
|
+
return this.resultCode;
|
|
2439
|
+
}
|
|
2440
|
+
|
|
2441
|
+
toString() {
|
|
2442
|
+
const parts = ["* SetPhaseToReleaseForLeakScenario"];
|
|
2443
|
+
|
|
2444
|
+
parts.push(`zCoordUpdated: ${String(this.zCoordUpdated)}`);
|
|
2445
|
+
parts.push(`holeHeightFractionUpdated: ${String(this.holeHeightFractionUpdated)}`);
|
|
2446
|
+
parts.push(`resultCode: ${String(this.resultCode)}`);
|
|
2447
|
+
parts.push("*** messages:");
|
|
2448
|
+
parts.push(`messages: ${this.messages !== undefined ? this.messages : "(None)"}`);
|
|
2449
|
+
parts.push(`calculationElapsedTime: ${this.calculationElapsedTime !== undefined ? this.calculationElapsedTime : "(None)"}`);
|
|
2450
|
+
parts.push(`operationId: ${this.operationId !== undefined ? this.operationId : "(None)"}`);
|
|
2451
|
+
|
|
2452
|
+
return parts.join("\n");
|
|
2453
|
+
}
|
|
2454
|
+
}
|
|
2455
|
+
|
|
2456
|
+
export class SetPhaseToReleaseForLeakScenarioCalculationResponse extends CalculationResponseBase {
|
|
2457
|
+
zCoordUpdated: number;
|
|
2458
|
+
holeHeightFractionUpdated: number;
|
|
2459
|
+
|
|
2460
|
+
/**
|
|
2461
|
+
* SetPhaseToReleaseForLeakScenario calculation response class.
|
|
2462
|
+
*
|
|
2463
|
+
* @param {number} zCoordUpdated - Updated z-coordinate of vessel to accommodate requested phase to release.
|
|
2464
|
+
* @param {number} holeHeightFractionUpdated - Updated hole height fraction to accommodate requested phase to release.
|
|
2465
|
+
*/
|
|
2466
|
+
constructor(
|
|
2467
|
+
zCoordUpdated: number,
|
|
2468
|
+
holeHeightFractionUpdated: number,
|
|
2469
|
+
resultCode: Enums.ResultCode,
|
|
2470
|
+
messages: string[],
|
|
2471
|
+
calculationElapsedTime: number,
|
|
2472
|
+
operationId: string
|
|
2473
|
+
) {
|
|
2474
|
+
super();
|
|
2475
|
+
this.zCoordUpdated = zCoordUpdated;
|
|
2476
|
+
this.holeHeightFractionUpdated = holeHeightFractionUpdated;
|
|
2477
|
+
this.resultCode = resultCode;
|
|
2478
|
+
this.messages = messages;
|
|
2479
|
+
this.calculationElapsedTime = calculationElapsedTime;
|
|
2480
|
+
this.operationId = operationId;
|
|
2481
|
+
}
|
|
2482
|
+
|
|
2483
|
+
initialiseFromDictionary(data: { [key: string]: unknown }) {
|
|
2484
|
+
if (data.zCoordUpdated !== undefined && typeof data.zCoordUpdated === "number") {
|
|
2485
|
+
this.zCoordUpdated = data.zCoordUpdated as number;
|
|
2486
|
+
}
|
|
2487
|
+
if (data.holeHeightFractionUpdated !== undefined && typeof data.holeHeightFractionUpdated === "number") {
|
|
2488
|
+
this.holeHeightFractionUpdated = data.holeHeightFractionUpdated as number;
|
|
2489
|
+
}
|
|
2490
|
+
if (data.resultCode !== undefined && (typeof data.resultCode === "string" || typeof data.resultCode === "number")) {
|
|
2491
|
+
this.resultCode = data.resultCode as Enums.ResultCode;
|
|
2492
|
+
}
|
|
2493
|
+
this.messages = this.messages ?? [];
|
|
2494
|
+
if (data.messages && Array.isArray(data.messages)) {
|
|
2495
|
+
this.messages.push(...data.messages);
|
|
2496
|
+
}
|
|
2497
|
+
if (data.calculationElapsedTime !== undefined && typeof data.calculationElapsedTime === "number") {
|
|
2498
|
+
this.calculationElapsedTime = data.calculationElapsedTime as number;
|
|
2499
|
+
}
|
|
2500
|
+
if (data.operationId !== undefined && typeof data.operationId === "string") {
|
|
2501
|
+
this.operationId = data.operationId as string;
|
|
2502
|
+
}
|
|
2503
|
+
}
|
|
2504
|
+
}
|
|
2505
|
+
|
|
2506
|
+
export interface SetPhaseToReleaseForLeakScenarioCalculationResponseSchemaData {
|
|
2507
|
+
zCoordUpdated: number;
|
|
2508
|
+
holeHeightFractionUpdated: number;
|
|
2509
|
+
resultCode: Enums.ResultCode;
|
|
2510
|
+
messages: string[];
|
|
2511
|
+
calculationElapsedTime: number;
|
|
2512
|
+
operationId: string;
|
|
2513
|
+
}
|
|
2514
|
+
|
|
2515
|
+
export class SetPhaseToReleaseForLeakScenarioCalculationResponseSchema {
|
|
2516
|
+
schema: Joi.ObjectSchema;
|
|
2517
|
+
propertyTypes: Record<string, string>;
|
|
2518
|
+
|
|
2519
|
+
/**
|
|
2520
|
+
* Schema for the SetPhaseToReleaseForLeakScenario calculation response.
|
|
2521
|
+
*/
|
|
2522
|
+
constructor() {
|
|
2523
|
+
this.schema = Joi.object({
|
|
2524
|
+
zCoordUpdated: Joi.number().unsafe(),
|
|
2525
|
+
holeHeightFractionUpdated: Joi.number().unsafe(),
|
|
2526
|
+
resultCode: Joi.string().valid(...Object.values(Enums.ResultCode)),
|
|
2527
|
+
messages: Joi.array().items(Joi.string()),
|
|
2528
|
+
calculationElapsedTime: Joi.number().unsafe(),
|
|
2529
|
+
operationId: Joi.string().uuid().allow(null),
|
|
2530
|
+
}).unknown(true);
|
|
2531
|
+
|
|
2532
|
+
this.propertyTypes = {
|
|
2533
|
+
zCoordUpdated: "number",
|
|
2534
|
+
holeHeightFractionUpdated: "number",
|
|
2535
|
+
};
|
|
2536
|
+
}
|
|
2537
|
+
|
|
2538
|
+
validate(data: SetPhaseToReleaseForLeakScenarioCalculationResponseSchemaData): SetPhaseToReleaseForLeakScenarioCalculationResponse {
|
|
2539
|
+
const { error, value } = this.schema.validate(data, { abortEarly: false });
|
|
2540
|
+
if (error) {
|
|
2541
|
+
throw new Error(`Validation error: ${error.details.map((x) => x.message).join(", ")}`);
|
|
2542
|
+
}
|
|
2543
|
+
return this.makeCalculationResponse(value);
|
|
2544
|
+
}
|
|
2545
|
+
|
|
2546
|
+
makeCalculationResponse(data: SetPhaseToReleaseForLeakScenarioCalculationResponseSchemaData): SetPhaseToReleaseForLeakScenarioCalculationResponse {
|
|
2547
|
+
return new SetPhaseToReleaseForLeakScenarioCalculationResponse(
|
|
2548
|
+
data.zCoordUpdated,
|
|
2549
|
+
data.holeHeightFractionUpdated,
|
|
2550
|
+
data.resultCode,
|
|
2551
|
+
data.messages,
|
|
2552
|
+
data.calculationElapsedTime,
|
|
2553
|
+
data.operationId
|
|
2554
|
+
);
|
|
2555
|
+
}
|
|
2556
|
+
}
|
|
2557
|
+
|
|
2558
|
+
export interface SetPhaseToReleaseForLineRuptureScenarioCalculationRequestSchemaData {
|
|
2559
|
+
phaseToRelease: Enums.Phase;
|
|
2560
|
+
releaseElevation: number;
|
|
2561
|
+
vessel: Entities.Vessel;
|
|
2562
|
+
}
|
|
2563
|
+
|
|
2564
|
+
class SetPhaseToReleaseForLineRuptureScenarioCalculationRequest extends CalculationRequestBase {
|
|
2565
|
+
phaseToRelease: Enums.Phase;
|
|
2566
|
+
releaseElevation: number;
|
|
2567
|
+
vessel: Entities.Vessel;
|
|
2568
|
+
|
|
2569
|
+
/**
|
|
2570
|
+
* SetPhaseToReleaseForLineRuptureScenario calculation request class.
|
|
2571
|
+
*
|
|
2572
|
+
* @param {Enums.Phase} phaseToRelease - Requested fluid phase to release.
|
|
2573
|
+
* @param {number} releaseElevation - Release point elevation above ground.
|
|
2574
|
+
* @param {Entities.Vessel} vessel - A Vessel entity.
|
|
2575
|
+
*/
|
|
2576
|
+
constructor(
|
|
2577
|
+
phaseToRelease: Enums.Phase,
|
|
2578
|
+
releaseElevation: number,
|
|
2579
|
+
vessel: Entities.Vessel
|
|
2580
|
+
) {
|
|
2581
|
+
super();
|
|
2582
|
+
this.phaseToRelease = phaseToRelease;
|
|
2583
|
+
this.releaseElevation = releaseElevation;
|
|
2584
|
+
this.vessel = vessel;
|
|
2585
|
+
}
|
|
2586
|
+
}
|
|
2587
|
+
|
|
2588
|
+
export class SetPhaseToReleaseForLineRuptureScenarioCalculationRequestSchema {
|
|
2589
|
+
schema: Joi.ObjectSchema;
|
|
2590
|
+
propertyTypes: Record<string, string>;
|
|
2591
|
+
|
|
2592
|
+
/**
|
|
2593
|
+
* Schema for the SetPhaseToReleaseForLineRuptureScenario calculation request.
|
|
2594
|
+
*/
|
|
2595
|
+
constructor() {
|
|
2596
|
+
this.schema = Joi.object({
|
|
2597
|
+
phaseToRelease: Joi.string().valid(...Object.values(Enums.Phase)),
|
|
2598
|
+
releaseElevation: Joi.number().unsafe(),
|
|
2599
|
+
vessel: new EntitySchemas.VesselSchema().schema,
|
|
2600
|
+
}).unknown(true);
|
|
2601
|
+
|
|
2602
|
+
this.propertyTypes = {
|
|
2603
|
+
phaseToRelease: "Enums.Phase",
|
|
2604
|
+
releaseElevation: "number",
|
|
2605
|
+
vessel: "Entities.Vessel",
|
|
2606
|
+
};
|
|
2607
|
+
}
|
|
2608
|
+
|
|
2609
|
+
validate(data: SetPhaseToReleaseForLineRuptureScenarioCalculationRequestSchemaData): SetPhaseToReleaseForLineRuptureScenarioCalculationRequest {
|
|
2610
|
+
const { error, value } = this.schema.validate(data, { abortEarly: false });
|
|
2611
|
+
if (error) {
|
|
2612
|
+
throw new Error(`Validation error: ${error.details.map((x) => x.message).join(", ")}`);
|
|
2613
|
+
}
|
|
2614
|
+
return this.makeCalculationRequest(value);
|
|
2615
|
+
}
|
|
2616
|
+
|
|
2617
|
+
makeCalculationRequest(data: SetPhaseToReleaseForLineRuptureScenarioCalculationRequestSchemaData): SetPhaseToReleaseForLineRuptureScenarioCalculationRequest {
|
|
2618
|
+
return new SetPhaseToReleaseForLineRuptureScenarioCalculationRequest(
|
|
2619
|
+
data.phaseToRelease,
|
|
2620
|
+
data.releaseElevation,
|
|
2621
|
+
data.vessel
|
|
2622
|
+
);
|
|
2623
|
+
}
|
|
2624
|
+
}
|
|
2625
|
+
|
|
2626
|
+
export class SetPhaseToReleaseForLineRuptureScenarioCalculation extends CalculationBase {
|
|
2627
|
+
phaseToRelease: Enums.Phase;
|
|
2628
|
+
releaseElevation: number;
|
|
2629
|
+
vessel: Entities.Vessel;
|
|
2630
|
+
zCoordUpdated?: number;
|
|
2631
|
+
pipeHeightFractionUpdated?: number;
|
|
2632
|
+
|
|
2633
|
+
/**
|
|
2634
|
+
* Calculates the pipe height fraction and vessel z coordinate to release the requested phase (vapour or liquid).
|
|
2635
|
+
*
|
|
2636
|
+
* @param {Enums.Phase} phaseToRelease - Requested fluid phase to release.
|
|
2637
|
+
* @param {number} releaseElevation - Release point elevation above ground.
|
|
2638
|
+
* @param {Entities.Vessel} vessel - A Vessel entity.
|
|
2639
|
+
*/
|
|
2640
|
+
constructor(
|
|
2641
|
+
phaseToRelease: Enums.Phase,
|
|
2642
|
+
releaseElevation: number,
|
|
2643
|
+
vessel: Entities.Vessel
|
|
2644
|
+
) {
|
|
2645
|
+
super();
|
|
2646
|
+
this.phaseToRelease = phaseToRelease;
|
|
2647
|
+
this.releaseElevation = releaseElevation;
|
|
2648
|
+
this.vessel = vessel;
|
|
2649
|
+
}
|
|
2650
|
+
|
|
2651
|
+
async run() {
|
|
2652
|
+
try {
|
|
2653
|
+
const request = new SetPhaseToReleaseForLineRuptureScenarioCalculationRequest(
|
|
2654
|
+
this.phaseToRelease,
|
|
2655
|
+
this.releaseElevation,
|
|
2656
|
+
this.vessel
|
|
2657
|
+
);
|
|
2658
|
+
|
|
2659
|
+
const schema = new SetPhaseToReleaseForLineRuptureScenarioCalculationRequestSchema();
|
|
2660
|
+
const validatedRequest = schema.validate(request);
|
|
2661
|
+
|
|
2662
|
+
const requestJson = JSON.stringify(validatedRequest);
|
|
2663
|
+
const url = `${getAnalyticsApiTarget()}utilities/setphasetoreleaseforlinerupturescenario?clientId=${getClientAliasId()}`;
|
|
2664
|
+
|
|
2665
|
+
this.resultCode = Enums.ResultCode.UNEXPECTED_APPLICATION_ERROR;
|
|
2666
|
+
|
|
2667
|
+
const response = await this.postRequest(url, requestJson);
|
|
2668
|
+
|
|
2669
|
+
if (response.status >= 200 && response.status < 300) {
|
|
2670
|
+
const schema = new SetPhaseToReleaseForLineRuptureScenarioCalculationResponseSchema();
|
|
2671
|
+
const validatedResponse = schema.validate(response.data);
|
|
2672
|
+
|
|
2673
|
+
this.resultCode = validatedResponse.resultCode;
|
|
2674
|
+
if (this.resultCode === Enums.ResultCode.SUCCESS) {
|
|
2675
|
+
this.zCoordUpdated = validatedResponse.zCoordUpdated;
|
|
2676
|
+
this.pipeHeightFractionUpdated = validatedResponse.pipeHeightFractionUpdated;
|
|
2677
|
+
this.resultCode = validatedResponse.resultCode;
|
|
2678
|
+
this.messages = validatedResponse.messages ?? [];
|
|
2679
|
+
this.calculationElapsedTime = validatedResponse.calculationElapsedTime;
|
|
2680
|
+
this.operationId = validatedResponse.operationId;
|
|
2681
|
+
} else {
|
|
2682
|
+
this.messages.push(...(validatedResponse.messages ?? []));
|
|
2683
|
+
}
|
|
2684
|
+
} else {
|
|
2685
|
+
this.handleFailedResponse(response);
|
|
2686
|
+
}
|
|
2687
|
+
} catch (error) {
|
|
2688
|
+
if (error instanceof Error) {
|
|
2689
|
+
this.messages.push(`Error: ${error.message}`);
|
|
2690
|
+
} else {
|
|
2691
|
+
this.messages.push(`Unexpected error: ${JSON.stringify(error)}`);
|
|
2692
|
+
}
|
|
2693
|
+
console.error(error);
|
|
2694
|
+
this.resultCode = Enums.ResultCode.UNEXPECTED_APPLICATION_ERROR;
|
|
2695
|
+
}
|
|
2696
|
+
|
|
2697
|
+
return this.resultCode;
|
|
2698
|
+
}
|
|
2699
|
+
|
|
2700
|
+
toString() {
|
|
2701
|
+
const parts = ["* SetPhaseToReleaseForLineRuptureScenario"];
|
|
2702
|
+
|
|
2703
|
+
parts.push(`zCoordUpdated: ${String(this.zCoordUpdated)}`);
|
|
2704
|
+
parts.push(`pipeHeightFractionUpdated: ${String(this.pipeHeightFractionUpdated)}`);
|
|
2705
|
+
parts.push(`resultCode: ${String(this.resultCode)}`);
|
|
2706
|
+
parts.push("*** messages:");
|
|
2707
|
+
parts.push(`messages: ${this.messages !== undefined ? this.messages : "(None)"}`);
|
|
2708
|
+
parts.push(`calculationElapsedTime: ${this.calculationElapsedTime !== undefined ? this.calculationElapsedTime : "(None)"}`);
|
|
2709
|
+
parts.push(`operationId: ${this.operationId !== undefined ? this.operationId : "(None)"}`);
|
|
2710
|
+
|
|
2711
|
+
return parts.join("\n");
|
|
2712
|
+
}
|
|
2713
|
+
}
|
|
2714
|
+
|
|
2715
|
+
export class SetPhaseToReleaseForLineRuptureScenarioCalculationResponse extends CalculationResponseBase {
|
|
2716
|
+
zCoordUpdated: number;
|
|
2717
|
+
pipeHeightFractionUpdated: number;
|
|
2718
|
+
|
|
2719
|
+
/**
|
|
2720
|
+
* SetPhaseToReleaseForLineRuptureScenario calculation response class.
|
|
2721
|
+
*
|
|
2722
|
+
* @param {number} zCoordUpdated - Updated z-coordinate of vessel to accommodate requested phase to release.
|
|
2723
|
+
* @param {number} pipeHeightFractionUpdated - Updated pipe height fraction to accommodate requested phase to release.
|
|
2724
|
+
*/
|
|
2725
|
+
constructor(
|
|
2726
|
+
zCoordUpdated: number,
|
|
2727
|
+
pipeHeightFractionUpdated: number,
|
|
2728
|
+
resultCode: Enums.ResultCode,
|
|
2729
|
+
messages: string[],
|
|
2730
|
+
calculationElapsedTime: number,
|
|
2731
|
+
operationId: string
|
|
2732
|
+
) {
|
|
2733
|
+
super();
|
|
2734
|
+
this.zCoordUpdated = zCoordUpdated;
|
|
2735
|
+
this.pipeHeightFractionUpdated = pipeHeightFractionUpdated;
|
|
2736
|
+
this.resultCode = resultCode;
|
|
2737
|
+
this.messages = messages;
|
|
2738
|
+
this.calculationElapsedTime = calculationElapsedTime;
|
|
2739
|
+
this.operationId = operationId;
|
|
2740
|
+
}
|
|
2741
|
+
|
|
2742
|
+
initialiseFromDictionary(data: { [key: string]: unknown }) {
|
|
2743
|
+
if (data.zCoordUpdated !== undefined && typeof data.zCoordUpdated === "number") {
|
|
2744
|
+
this.zCoordUpdated = data.zCoordUpdated as number;
|
|
2745
|
+
}
|
|
2746
|
+
if (data.pipeHeightFractionUpdated !== undefined && typeof data.pipeHeightFractionUpdated === "number") {
|
|
2747
|
+
this.pipeHeightFractionUpdated = data.pipeHeightFractionUpdated as number;
|
|
2748
|
+
}
|
|
2749
|
+
if (data.resultCode !== undefined && (typeof data.resultCode === "string" || typeof data.resultCode === "number")) {
|
|
2750
|
+
this.resultCode = data.resultCode as Enums.ResultCode;
|
|
2751
|
+
}
|
|
2752
|
+
this.messages = this.messages ?? [];
|
|
2753
|
+
if (data.messages && Array.isArray(data.messages)) {
|
|
2754
|
+
this.messages.push(...data.messages);
|
|
2755
|
+
}
|
|
2756
|
+
if (data.calculationElapsedTime !== undefined && typeof data.calculationElapsedTime === "number") {
|
|
2757
|
+
this.calculationElapsedTime = data.calculationElapsedTime as number;
|
|
2758
|
+
}
|
|
2759
|
+
if (data.operationId !== undefined && typeof data.operationId === "string") {
|
|
2760
|
+
this.operationId = data.operationId as string;
|
|
2761
|
+
}
|
|
2762
|
+
}
|
|
2763
|
+
}
|
|
2764
|
+
|
|
2765
|
+
export interface SetPhaseToReleaseForLineRuptureScenarioCalculationResponseSchemaData {
|
|
2766
|
+
zCoordUpdated: number;
|
|
2767
|
+
pipeHeightFractionUpdated: number;
|
|
2768
|
+
resultCode: Enums.ResultCode;
|
|
2769
|
+
messages: string[];
|
|
2770
|
+
calculationElapsedTime: number;
|
|
2771
|
+
operationId: string;
|
|
2772
|
+
}
|
|
2773
|
+
|
|
2774
|
+
export class SetPhaseToReleaseForLineRuptureScenarioCalculationResponseSchema {
|
|
2775
|
+
schema: Joi.ObjectSchema;
|
|
2776
|
+
propertyTypes: Record<string, string>;
|
|
2777
|
+
|
|
2778
|
+
/**
|
|
2779
|
+
* Schema for the SetPhaseToReleaseForLineRuptureScenario calculation response.
|
|
2780
|
+
*/
|
|
2781
|
+
constructor() {
|
|
2782
|
+
this.schema = Joi.object({
|
|
2783
|
+
zCoordUpdated: Joi.number().unsafe(),
|
|
2784
|
+
pipeHeightFractionUpdated: Joi.number().unsafe(),
|
|
2785
|
+
resultCode: Joi.string().valid(...Object.values(Enums.ResultCode)),
|
|
2786
|
+
messages: Joi.array().items(Joi.string()),
|
|
2787
|
+
calculationElapsedTime: Joi.number().unsafe(),
|
|
2788
|
+
operationId: Joi.string().uuid().allow(null),
|
|
2789
|
+
}).unknown(true);
|
|
2790
|
+
|
|
2791
|
+
this.propertyTypes = {
|
|
2792
|
+
zCoordUpdated: "number",
|
|
2793
|
+
pipeHeightFractionUpdated: "number",
|
|
2794
|
+
};
|
|
2795
|
+
}
|
|
2796
|
+
|
|
2797
|
+
validate(data: SetPhaseToReleaseForLineRuptureScenarioCalculationResponseSchemaData): SetPhaseToReleaseForLineRuptureScenarioCalculationResponse {
|
|
2798
|
+
const { error, value } = this.schema.validate(data, { abortEarly: false });
|
|
2799
|
+
if (error) {
|
|
2800
|
+
throw new Error(`Validation error: ${error.details.map((x) => x.message).join(", ")}`);
|
|
2801
|
+
}
|
|
2802
|
+
return this.makeCalculationResponse(value);
|
|
2803
|
+
}
|
|
2804
|
+
|
|
2805
|
+
makeCalculationResponse(data: SetPhaseToReleaseForLineRuptureScenarioCalculationResponseSchemaData): SetPhaseToReleaseForLineRuptureScenarioCalculationResponse {
|
|
2806
|
+
return new SetPhaseToReleaseForLineRuptureScenarioCalculationResponse(
|
|
2807
|
+
data.zCoordUpdated,
|
|
2808
|
+
data.pipeHeightFractionUpdated,
|
|
2809
|
+
data.resultCode,
|
|
2810
|
+
data.messages,
|
|
2811
|
+
data.calculationElapsedTime,
|
|
2812
|
+
data.operationId
|
|
2813
|
+
);
|
|
2814
|
+
}
|
|
2815
|
+
}
|
|
2816
|
+
|
|
2817
|
+
export interface SetPhaseToReleaseForReliefValveScenarioCalculationRequestSchemaData {
|
|
2818
|
+
phaseToRelease: Enums.Phase;
|
|
2819
|
+
releaseElevation: number;
|
|
2820
|
+
vessel: Entities.Vessel;
|
|
2821
|
+
}
|
|
2822
|
+
|
|
2823
|
+
class SetPhaseToReleaseForReliefValveScenarioCalculationRequest extends CalculationRequestBase {
|
|
2824
|
+
phaseToRelease: Enums.Phase;
|
|
2825
|
+
releaseElevation: number;
|
|
2826
|
+
vessel: Entities.Vessel;
|
|
2827
|
+
|
|
2828
|
+
/**
|
|
2829
|
+
* SetPhaseToReleaseForReliefValveScenario calculation request class.
|
|
2830
|
+
*
|
|
2831
|
+
* @param {Enums.Phase} phaseToRelease - Requested fluid phase to release.
|
|
2832
|
+
* @param {number} releaseElevation - Release point elevation above ground.
|
|
2833
|
+
* @param {Entities.Vessel} vessel - A Vessel entity.
|
|
2834
|
+
*/
|
|
2835
|
+
constructor(
|
|
2836
|
+
phaseToRelease: Enums.Phase,
|
|
2837
|
+
releaseElevation: number,
|
|
2838
|
+
vessel: Entities.Vessel
|
|
2839
|
+
) {
|
|
2840
|
+
super();
|
|
2841
|
+
this.phaseToRelease = phaseToRelease;
|
|
2842
|
+
this.releaseElevation = releaseElevation;
|
|
2843
|
+
this.vessel = vessel;
|
|
2844
|
+
}
|
|
2845
|
+
}
|
|
2846
|
+
|
|
2847
|
+
export class SetPhaseToReleaseForReliefValveScenarioCalculationRequestSchema {
|
|
2848
|
+
schema: Joi.ObjectSchema;
|
|
2849
|
+
propertyTypes: Record<string, string>;
|
|
2850
|
+
|
|
2851
|
+
/**
|
|
2852
|
+
* Schema for the SetPhaseToReleaseForReliefValveScenario calculation request.
|
|
2853
|
+
*/
|
|
2854
|
+
constructor() {
|
|
2855
|
+
this.schema = Joi.object({
|
|
2856
|
+
phaseToRelease: Joi.string().valid(...Object.values(Enums.Phase)),
|
|
2857
|
+
releaseElevation: Joi.number().unsafe(),
|
|
2858
|
+
vessel: new EntitySchemas.VesselSchema().schema,
|
|
2859
|
+
}).unknown(true);
|
|
2860
|
+
|
|
2861
|
+
this.propertyTypes = {
|
|
2862
|
+
phaseToRelease: "Enums.Phase",
|
|
2863
|
+
releaseElevation: "number",
|
|
2864
|
+
vessel: "Entities.Vessel",
|
|
2865
|
+
};
|
|
2866
|
+
}
|
|
2867
|
+
|
|
2868
|
+
validate(data: SetPhaseToReleaseForReliefValveScenarioCalculationRequestSchemaData): SetPhaseToReleaseForReliefValveScenarioCalculationRequest {
|
|
2869
|
+
const { error, value } = this.schema.validate(data, { abortEarly: false });
|
|
2870
|
+
if (error) {
|
|
2871
|
+
throw new Error(`Validation error: ${error.details.map((x) => x.message).join(", ")}`);
|
|
2872
|
+
}
|
|
2873
|
+
return this.makeCalculationRequest(value);
|
|
2874
|
+
}
|
|
2875
|
+
|
|
2876
|
+
makeCalculationRequest(data: SetPhaseToReleaseForReliefValveScenarioCalculationRequestSchemaData): SetPhaseToReleaseForReliefValveScenarioCalculationRequest {
|
|
2877
|
+
return new SetPhaseToReleaseForReliefValveScenarioCalculationRequest(
|
|
2878
|
+
data.phaseToRelease,
|
|
2879
|
+
data.releaseElevation,
|
|
2880
|
+
data.vessel
|
|
2881
|
+
);
|
|
2882
|
+
}
|
|
2883
|
+
}
|
|
2884
|
+
|
|
2885
|
+
export class SetPhaseToReleaseForReliefValveScenarioCalculation extends CalculationBase {
|
|
2886
|
+
phaseToRelease: Enums.Phase;
|
|
2887
|
+
releaseElevation: number;
|
|
2888
|
+
vessel: Entities.Vessel;
|
|
2889
|
+
zCoordUpdated?: number;
|
|
2890
|
+
pipeHeightFractionUpdated?: number;
|
|
2891
|
+
|
|
2892
|
+
/**
|
|
2893
|
+
* Calculates the pipe height fraction and vessel z coordinate to release the requested phase.
|
|
2894
|
+
*
|
|
2895
|
+
* @param {Enums.Phase} phaseToRelease - Requested fluid phase to release.
|
|
2896
|
+
* @param {number} releaseElevation - Release point elevation above ground.
|
|
2897
|
+
* @param {Entities.Vessel} vessel - A Vessel entity.
|
|
2898
|
+
*/
|
|
2899
|
+
constructor(
|
|
2900
|
+
phaseToRelease: Enums.Phase,
|
|
2901
|
+
releaseElevation: number,
|
|
2902
|
+
vessel: Entities.Vessel
|
|
2903
|
+
) {
|
|
2904
|
+
super();
|
|
2905
|
+
this.phaseToRelease = phaseToRelease;
|
|
2906
|
+
this.releaseElevation = releaseElevation;
|
|
2907
|
+
this.vessel = vessel;
|
|
2908
|
+
}
|
|
2909
|
+
|
|
2910
|
+
async run() {
|
|
2911
|
+
try {
|
|
2912
|
+
const request = new SetPhaseToReleaseForReliefValveScenarioCalculationRequest(
|
|
2913
|
+
this.phaseToRelease,
|
|
2914
|
+
this.releaseElevation,
|
|
2915
|
+
this.vessel
|
|
2916
|
+
);
|
|
2917
|
+
|
|
2918
|
+
const schema = new SetPhaseToReleaseForReliefValveScenarioCalculationRequestSchema();
|
|
2919
|
+
const validatedRequest = schema.validate(request);
|
|
2920
|
+
|
|
2921
|
+
const requestJson = JSON.stringify(validatedRequest);
|
|
2922
|
+
const url = `${getAnalyticsApiTarget()}utilities/setphasetoreleaseforreliefvalvescenario?clientId=${getClientAliasId()}`;
|
|
2923
|
+
|
|
2924
|
+
this.resultCode = Enums.ResultCode.UNEXPECTED_APPLICATION_ERROR;
|
|
2925
|
+
|
|
2926
|
+
const response = await this.postRequest(url, requestJson);
|
|
2927
|
+
|
|
2928
|
+
if (response.status >= 200 && response.status < 300) {
|
|
2929
|
+
const schema = new SetPhaseToReleaseForReliefValveScenarioCalculationResponseSchema();
|
|
2930
|
+
const validatedResponse = schema.validate(response.data);
|
|
2931
|
+
|
|
2932
|
+
this.resultCode = validatedResponse.resultCode;
|
|
2933
|
+
if (this.resultCode === Enums.ResultCode.SUCCESS) {
|
|
2934
|
+
this.zCoordUpdated = validatedResponse.zCoordUpdated;
|
|
2935
|
+
this.pipeHeightFractionUpdated = validatedResponse.pipeHeightFractionUpdated;
|
|
2936
|
+
this.resultCode = validatedResponse.resultCode;
|
|
2937
|
+
this.messages = validatedResponse.messages ?? [];
|
|
2938
|
+
this.calculationElapsedTime = validatedResponse.calculationElapsedTime;
|
|
2939
|
+
this.operationId = validatedResponse.operationId;
|
|
2940
|
+
} else {
|
|
2941
|
+
this.messages.push(...(validatedResponse.messages ?? []));
|
|
2942
|
+
}
|
|
2943
|
+
} else {
|
|
2944
|
+
this.handleFailedResponse(response);
|
|
2945
|
+
}
|
|
2946
|
+
} catch (error) {
|
|
2947
|
+
if (error instanceof Error) {
|
|
2948
|
+
this.messages.push(`Error: ${error.message}`);
|
|
2949
|
+
} else {
|
|
2950
|
+
this.messages.push(`Unexpected error: ${JSON.stringify(error)}`);
|
|
2951
|
+
}
|
|
2952
|
+
console.error(error);
|
|
2953
|
+
this.resultCode = Enums.ResultCode.UNEXPECTED_APPLICATION_ERROR;
|
|
2954
|
+
}
|
|
2955
|
+
|
|
2956
|
+
return this.resultCode;
|
|
2957
|
+
}
|
|
2958
|
+
|
|
2959
|
+
toString() {
|
|
2960
|
+
const parts = ["* SetPhaseToReleaseForReliefValveScenario"];
|
|
2961
|
+
|
|
2962
|
+
parts.push(`zCoordUpdated: ${String(this.zCoordUpdated)}`);
|
|
2963
|
+
parts.push(`pipeHeightFractionUpdated: ${String(this.pipeHeightFractionUpdated)}`);
|
|
2964
|
+
parts.push(`resultCode: ${String(this.resultCode)}`);
|
|
2965
|
+
parts.push("*** messages:");
|
|
2966
|
+
parts.push(`messages: ${this.messages !== undefined ? this.messages : "(None)"}`);
|
|
2967
|
+
parts.push(`calculationElapsedTime: ${this.calculationElapsedTime !== undefined ? this.calculationElapsedTime : "(None)"}`);
|
|
2968
|
+
parts.push(`operationId: ${this.operationId !== undefined ? this.operationId : "(None)"}`);
|
|
2969
|
+
|
|
2970
|
+
return parts.join("\n");
|
|
2971
|
+
}
|
|
2972
|
+
}
|
|
2973
|
+
|
|
2974
|
+
export class SetPhaseToReleaseForReliefValveScenarioCalculationResponse extends CalculationResponseBase {
|
|
2975
|
+
zCoordUpdated: number;
|
|
2976
|
+
pipeHeightFractionUpdated: number;
|
|
2977
|
+
|
|
2978
|
+
/**
|
|
2979
|
+
* SetPhaseToReleaseForReliefValveScenario calculation response class.
|
|
2980
|
+
*
|
|
2981
|
+
* @param {number} zCoordUpdated - Updated z-coordinate of vessel to accommodate requested phase to release.
|
|
2982
|
+
* @param {number} pipeHeightFractionUpdated - Updated pipe height fraction to accommodate requested phase to release.
|
|
2983
|
+
*/
|
|
2984
|
+
constructor(
|
|
2985
|
+
zCoordUpdated: number,
|
|
2986
|
+
pipeHeightFractionUpdated: number,
|
|
2987
|
+
resultCode: Enums.ResultCode,
|
|
2988
|
+
messages: string[],
|
|
2989
|
+
calculationElapsedTime: number,
|
|
2990
|
+
operationId: string
|
|
2991
|
+
) {
|
|
2992
|
+
super();
|
|
2993
|
+
this.zCoordUpdated = zCoordUpdated;
|
|
2994
|
+
this.pipeHeightFractionUpdated = pipeHeightFractionUpdated;
|
|
2995
|
+
this.resultCode = resultCode;
|
|
2996
|
+
this.messages = messages;
|
|
2997
|
+
this.calculationElapsedTime = calculationElapsedTime;
|
|
2998
|
+
this.operationId = operationId;
|
|
2999
|
+
}
|
|
3000
|
+
|
|
3001
|
+
initialiseFromDictionary(data: { [key: string]: unknown }) {
|
|
3002
|
+
if (data.zCoordUpdated !== undefined && typeof data.zCoordUpdated === "number") {
|
|
3003
|
+
this.zCoordUpdated = data.zCoordUpdated as number;
|
|
3004
|
+
}
|
|
3005
|
+
if (data.pipeHeightFractionUpdated !== undefined && typeof data.pipeHeightFractionUpdated === "number") {
|
|
3006
|
+
this.pipeHeightFractionUpdated = data.pipeHeightFractionUpdated as number;
|
|
3007
|
+
}
|
|
3008
|
+
if (data.resultCode !== undefined && (typeof data.resultCode === "string" || typeof data.resultCode === "number")) {
|
|
3009
|
+
this.resultCode = data.resultCode as Enums.ResultCode;
|
|
3010
|
+
}
|
|
3011
|
+
this.messages = this.messages ?? [];
|
|
3012
|
+
if (data.messages && Array.isArray(data.messages)) {
|
|
3013
|
+
this.messages.push(...data.messages);
|
|
3014
|
+
}
|
|
3015
|
+
if (data.calculationElapsedTime !== undefined && typeof data.calculationElapsedTime === "number") {
|
|
3016
|
+
this.calculationElapsedTime = data.calculationElapsedTime as number;
|
|
3017
|
+
}
|
|
3018
|
+
if (data.operationId !== undefined && typeof data.operationId === "string") {
|
|
3019
|
+
this.operationId = data.operationId as string;
|
|
3020
|
+
}
|
|
3021
|
+
}
|
|
3022
|
+
}
|
|
3023
|
+
|
|
3024
|
+
export interface SetPhaseToReleaseForReliefValveScenarioCalculationResponseSchemaData {
|
|
3025
|
+
zCoordUpdated: number;
|
|
3026
|
+
pipeHeightFractionUpdated: number;
|
|
3027
|
+
resultCode: Enums.ResultCode;
|
|
3028
|
+
messages: string[];
|
|
3029
|
+
calculationElapsedTime: number;
|
|
3030
|
+
operationId: string;
|
|
3031
|
+
}
|
|
3032
|
+
|
|
3033
|
+
export class SetPhaseToReleaseForReliefValveScenarioCalculationResponseSchema {
|
|
3034
|
+
schema: Joi.ObjectSchema;
|
|
3035
|
+
propertyTypes: Record<string, string>;
|
|
3036
|
+
|
|
3037
|
+
/**
|
|
3038
|
+
* Schema for the SetPhaseToReleaseForReliefValveScenario calculation response.
|
|
3039
|
+
*/
|
|
3040
|
+
constructor() {
|
|
3041
|
+
this.schema = Joi.object({
|
|
3042
|
+
zCoordUpdated: Joi.number().unsafe(),
|
|
3043
|
+
pipeHeightFractionUpdated: Joi.number().unsafe(),
|
|
3044
|
+
resultCode: Joi.string().valid(...Object.values(Enums.ResultCode)),
|
|
3045
|
+
messages: Joi.array().items(Joi.string()),
|
|
3046
|
+
calculationElapsedTime: Joi.number().unsafe(),
|
|
3047
|
+
operationId: Joi.string().uuid().allow(null),
|
|
3048
|
+
}).unknown(true);
|
|
3049
|
+
|
|
3050
|
+
this.propertyTypes = {
|
|
3051
|
+
zCoordUpdated: "number",
|
|
3052
|
+
pipeHeightFractionUpdated: "number",
|
|
3053
|
+
};
|
|
3054
|
+
}
|
|
3055
|
+
|
|
3056
|
+
validate(data: SetPhaseToReleaseForReliefValveScenarioCalculationResponseSchemaData): SetPhaseToReleaseForReliefValveScenarioCalculationResponse {
|
|
3057
|
+
const { error, value } = this.schema.validate(data, { abortEarly: false });
|
|
3058
|
+
if (error) {
|
|
3059
|
+
throw new Error(`Validation error: ${error.details.map((x) => x.message).join(", ")}`);
|
|
3060
|
+
}
|
|
3061
|
+
return this.makeCalculationResponse(value);
|
|
3062
|
+
}
|
|
3063
|
+
|
|
3064
|
+
makeCalculationResponse(data: SetPhaseToReleaseForReliefValveScenarioCalculationResponseSchemaData): SetPhaseToReleaseForReliefValveScenarioCalculationResponse {
|
|
3065
|
+
return new SetPhaseToReleaseForReliefValveScenarioCalculationResponse(
|
|
3066
|
+
data.zCoordUpdated,
|
|
3067
|
+
data.pipeHeightFractionUpdated,
|
|
3068
|
+
data.resultCode,
|
|
3069
|
+
data.messages,
|
|
3070
|
+
data.calculationElapsedTime,
|
|
3071
|
+
data.operationId
|
|
3072
|
+
);
|
|
3073
|
+
}
|
|
3074
|
+
}
|
|
3075
|
+
|
|
3076
|
+
export interface SetReleaseElevationForScenarioCalculationRequestSchemaData {
|
|
3077
|
+
releaseElevation: number;
|
|
3078
|
+
releaseHeightFraction: number;
|
|
3079
|
+
vessel: Entities.Vessel;
|
|
3080
|
+
}
|
|
3081
|
+
|
|
3082
|
+
class SetReleaseElevationForScenarioCalculationRequest extends CalculationRequestBase {
|
|
3083
|
+
releaseElevation: number;
|
|
3084
|
+
releaseHeightFraction: number;
|
|
3085
|
+
vessel: Entities.Vessel;
|
|
3086
|
+
|
|
3087
|
+
/**
|
|
3088
|
+
* SetReleaseElevationForScenario calculation request class.
|
|
3089
|
+
*
|
|
3090
|
+
* @param {number} releaseElevation - Release point elevation above ground.
|
|
3091
|
+
* @param {number} releaseHeightFraction - Release height fraction of the total vessel height.
|
|
3092
|
+
* @param {Entities.Vessel} vessel - A Vessel entity.
|
|
3093
|
+
*/
|
|
3094
|
+
constructor(
|
|
3095
|
+
releaseElevation: number,
|
|
3096
|
+
releaseHeightFraction: number,
|
|
3097
|
+
vessel: Entities.Vessel
|
|
3098
|
+
) {
|
|
3099
|
+
super();
|
|
3100
|
+
this.releaseElevation = releaseElevation;
|
|
3101
|
+
this.releaseHeightFraction = releaseHeightFraction;
|
|
3102
|
+
this.vessel = vessel;
|
|
3103
|
+
}
|
|
3104
|
+
}
|
|
3105
|
+
|
|
3106
|
+
export class SetReleaseElevationForScenarioCalculationRequestSchema {
|
|
3107
|
+
schema: Joi.ObjectSchema;
|
|
3108
|
+
propertyTypes: Record<string, string>;
|
|
3109
|
+
|
|
3110
|
+
/**
|
|
3111
|
+
* Schema for the SetReleaseElevationForScenario calculation request.
|
|
3112
|
+
*/
|
|
3113
|
+
constructor() {
|
|
3114
|
+
this.schema = Joi.object({
|
|
3115
|
+
releaseElevation: Joi.number().unsafe(),
|
|
3116
|
+
releaseHeightFraction: Joi.number().unsafe(),
|
|
3117
|
+
vessel: new EntitySchemas.VesselSchema().schema,
|
|
3118
|
+
}).unknown(true);
|
|
3119
|
+
|
|
3120
|
+
this.propertyTypes = {
|
|
3121
|
+
releaseElevation: "number",
|
|
3122
|
+
releaseHeightFraction: "number",
|
|
3123
|
+
vessel: "Entities.Vessel",
|
|
3124
|
+
};
|
|
3125
|
+
}
|
|
3126
|
+
|
|
3127
|
+
validate(data: SetReleaseElevationForScenarioCalculationRequestSchemaData): SetReleaseElevationForScenarioCalculationRequest {
|
|
3128
|
+
const { error, value } = this.schema.validate(data, { abortEarly: false });
|
|
3129
|
+
if (error) {
|
|
3130
|
+
throw new Error(`Validation error: ${error.details.map((x) => x.message).join(", ")}`);
|
|
3131
|
+
}
|
|
3132
|
+
return this.makeCalculationRequest(value);
|
|
3133
|
+
}
|
|
3134
|
+
|
|
3135
|
+
makeCalculationRequest(data: SetReleaseElevationForScenarioCalculationRequestSchemaData): SetReleaseElevationForScenarioCalculationRequest {
|
|
3136
|
+
return new SetReleaseElevationForScenarioCalculationRequest(
|
|
3137
|
+
data.releaseElevation,
|
|
3138
|
+
data.releaseHeightFraction,
|
|
3139
|
+
data.vessel
|
|
3140
|
+
);
|
|
3141
|
+
}
|
|
3142
|
+
}
|
|
3143
|
+
|
|
3144
|
+
export class SetReleaseElevationForScenarioCalculation extends CalculationBase {
|
|
3145
|
+
releaseElevation: number;
|
|
3146
|
+
releaseHeightFraction: number;
|
|
3147
|
+
vessel: Entities.Vessel;
|
|
3148
|
+
updatedVessel?: Entities.Vessel;
|
|
3149
|
+
|
|
3150
|
+
/**
|
|
3151
|
+
* Calculates the vessel z coordinate to release at the requested elevation. The release elevation is the point above the ground from where the dispersion and downstream models start. This method sets the vessel defined by its dimensions and shape to be elevated at a particular height such as to guarantee that the discharge result height is at the requested elevation.
|
|
3152
|
+
*
|
|
3153
|
+
* @param {number} releaseElevation - Release point elevation above ground.
|
|
3154
|
+
* @param {number} releaseHeightFraction - Release height fraction of the total vessel height.
|
|
3155
|
+
* @param {Entities.Vessel} vessel - A Vessel entity.
|
|
3156
|
+
*/
|
|
3157
|
+
constructor(
|
|
3158
|
+
releaseElevation: number,
|
|
3159
|
+
releaseHeightFraction: number,
|
|
3160
|
+
vessel: Entities.Vessel
|
|
3161
|
+
) {
|
|
3162
|
+
super();
|
|
3163
|
+
this.releaseElevation = releaseElevation;
|
|
3164
|
+
this.releaseHeightFraction = releaseHeightFraction;
|
|
3165
|
+
this.vessel = vessel;
|
|
3166
|
+
}
|
|
3167
|
+
|
|
3168
|
+
async run() {
|
|
3169
|
+
try {
|
|
3170
|
+
const request = new SetReleaseElevationForScenarioCalculationRequest(
|
|
3171
|
+
this.releaseElevation,
|
|
3172
|
+
this.releaseHeightFraction,
|
|
3173
|
+
this.vessel
|
|
3174
|
+
);
|
|
3175
|
+
|
|
3176
|
+
const schema = new SetReleaseElevationForScenarioCalculationRequestSchema();
|
|
3177
|
+
const validatedRequest = schema.validate(request);
|
|
3178
|
+
|
|
3179
|
+
const requestJson = JSON.stringify(validatedRequest);
|
|
3180
|
+
const url = `${getAnalyticsApiTarget()}utilities/SetReleaseElevationForScenario?clientId=${getClientAliasId()}`;
|
|
3181
|
+
|
|
3182
|
+
this.resultCode = Enums.ResultCode.UNEXPECTED_APPLICATION_ERROR;
|
|
3183
|
+
|
|
3184
|
+
const response = await this.postRequest(url, requestJson);
|
|
3185
|
+
|
|
3186
|
+
if (response.status >= 200 && response.status < 300) {
|
|
3187
|
+
const schema = new SetReleaseElevationForScenarioCalculationResponseSchema();
|
|
3188
|
+
const validatedResponse = schema.validate(response.data);
|
|
3189
|
+
|
|
3190
|
+
this.resultCode = validatedResponse.resultCode;
|
|
3191
|
+
if (this.resultCode === Enums.ResultCode.SUCCESS) {
|
|
3192
|
+
this.updatedVessel = validatedResponse.updatedVessel;
|
|
3193
|
+
this.resultCode = validatedResponse.resultCode;
|
|
3194
|
+
this.messages = validatedResponse.messages ?? [];
|
|
3195
|
+
this.calculationElapsedTime = validatedResponse.calculationElapsedTime;
|
|
3196
|
+
this.operationId = validatedResponse.operationId;
|
|
3197
|
+
} else {
|
|
3198
|
+
this.messages.push(...(validatedResponse.messages ?? []));
|
|
3199
|
+
}
|
|
3200
|
+
} else {
|
|
3201
|
+
this.handleFailedResponse(response);
|
|
3202
|
+
}
|
|
3203
|
+
} catch (error) {
|
|
3204
|
+
if (error instanceof Error) {
|
|
3205
|
+
this.messages.push(`Error: ${error.message}`);
|
|
3206
|
+
} else {
|
|
3207
|
+
this.messages.push(`Unexpected error: ${JSON.stringify(error)}`);
|
|
3208
|
+
}
|
|
3209
|
+
console.error(error);
|
|
3210
|
+
this.resultCode = Enums.ResultCode.UNEXPECTED_APPLICATION_ERROR;
|
|
3211
|
+
}
|
|
3212
|
+
|
|
3213
|
+
return this.resultCode;
|
|
3214
|
+
}
|
|
3215
|
+
|
|
3216
|
+
toString() {
|
|
3217
|
+
const parts = ["* SetReleaseElevationForScenario"];
|
|
3218
|
+
|
|
3219
|
+
parts.push(`updatedVessel: ${String(this.updatedVessel)}`);
|
|
3220
|
+
parts.push(`resultCode: ${String(this.resultCode)}`);
|
|
3221
|
+
parts.push("*** messages:");
|
|
3222
|
+
parts.push(`messages: ${this.messages !== undefined ? this.messages : "(None)"}`);
|
|
3223
|
+
parts.push(`calculationElapsedTime: ${this.calculationElapsedTime !== undefined ? this.calculationElapsedTime : "(None)"}`);
|
|
3224
|
+
parts.push(`operationId: ${this.operationId !== undefined ? this.operationId : "(None)"}`);
|
|
3225
|
+
|
|
3226
|
+
return parts.join("\n");
|
|
3227
|
+
}
|
|
3228
|
+
}
|
|
3229
|
+
|
|
3230
|
+
export class SetReleaseElevationForScenarioCalculationResponse extends CalculationResponseBase {
|
|
3231
|
+
updatedVessel: Entities.Vessel;
|
|
3232
|
+
|
|
3233
|
+
/**
|
|
3234
|
+
* SetReleaseElevationForScenario calculation response class.
|
|
3235
|
+
*
|
|
3236
|
+
* @param {Entities.Vessel} updatedVessel - Updated Vessel entity with modified z coordinate.
|
|
3237
|
+
*/
|
|
3238
|
+
constructor(
|
|
3239
|
+
updatedVessel: Entities.Vessel,
|
|
3240
|
+
resultCode: Enums.ResultCode,
|
|
3241
|
+
messages: string[],
|
|
3242
|
+
calculationElapsedTime: number,
|
|
3243
|
+
operationId: string
|
|
3244
|
+
) {
|
|
3245
|
+
super();
|
|
3246
|
+
this.updatedVessel = updatedVessel;
|
|
3247
|
+
this.resultCode = resultCode;
|
|
3248
|
+
this.messages = messages;
|
|
3249
|
+
this.calculationElapsedTime = calculationElapsedTime;
|
|
3250
|
+
this.operationId = operationId;
|
|
3251
|
+
}
|
|
3252
|
+
|
|
3253
|
+
initialiseFromDictionary(data: { [key: string]: unknown }) {
|
|
3254
|
+
if (data.updatedVessel) {
|
|
3255
|
+
this.updatedVessel = new Entities.Vessel();
|
|
3256
|
+
this.updatedVessel.initialiseFromDictionary(data.updatedVessel as { [key: string]: unknown });
|
|
3257
|
+
}
|
|
3258
|
+
if (data.resultCode !== undefined && (typeof data.resultCode === "string" || typeof data.resultCode === "number")) {
|
|
3259
|
+
this.resultCode = data.resultCode as Enums.ResultCode;
|
|
3260
|
+
}
|
|
3261
|
+
this.messages = this.messages ?? [];
|
|
3262
|
+
if (data.messages && Array.isArray(data.messages)) {
|
|
3263
|
+
this.messages.push(...data.messages);
|
|
3264
|
+
}
|
|
3265
|
+
if (data.calculationElapsedTime !== undefined && typeof data.calculationElapsedTime === "number") {
|
|
3266
|
+
this.calculationElapsedTime = data.calculationElapsedTime as number;
|
|
3267
|
+
}
|
|
3268
|
+
if (data.operationId !== undefined && typeof data.operationId === "string") {
|
|
3269
|
+
this.operationId = data.operationId as string;
|
|
3270
|
+
}
|
|
3271
|
+
}
|
|
3272
|
+
}
|
|
3273
|
+
|
|
3274
|
+
export interface SetReleaseElevationForScenarioCalculationResponseSchemaData {
|
|
3275
|
+
updatedVessel: Entities.Vessel;
|
|
3276
|
+
resultCode: Enums.ResultCode;
|
|
3277
|
+
messages: string[];
|
|
3278
|
+
calculationElapsedTime: number;
|
|
3279
|
+
operationId: string;
|
|
3280
|
+
}
|
|
3281
|
+
|
|
3282
|
+
export class SetReleaseElevationForScenarioCalculationResponseSchema {
|
|
3283
|
+
schema: Joi.ObjectSchema;
|
|
3284
|
+
propertyTypes: Record<string, string>;
|
|
3285
|
+
|
|
3286
|
+
/**
|
|
3287
|
+
* Schema for the SetReleaseElevationForScenario calculation response.
|
|
3288
|
+
*/
|
|
3289
|
+
constructor() {
|
|
3290
|
+
this.schema = Joi.object({
|
|
3291
|
+
updatedVessel: new EntitySchemas.VesselSchema().schema,
|
|
3292
|
+
resultCode: Joi.string().valid(...Object.values(Enums.ResultCode)),
|
|
3293
|
+
messages: Joi.array().items(Joi.string()),
|
|
3294
|
+
calculationElapsedTime: Joi.number().unsafe(),
|
|
3295
|
+
operationId: Joi.string().uuid().allow(null),
|
|
3296
|
+
}).unknown(true);
|
|
3297
|
+
|
|
3298
|
+
this.propertyTypes = {
|
|
3299
|
+
updatedVessel: "Entities.Vessel",
|
|
3300
|
+
};
|
|
3301
|
+
}
|
|
3302
|
+
|
|
3303
|
+
validate(data: SetReleaseElevationForScenarioCalculationResponseSchemaData): SetReleaseElevationForScenarioCalculationResponse {
|
|
3304
|
+
const { error, value } = this.schema.validate(data, { abortEarly: false });
|
|
3305
|
+
if (error) {
|
|
3306
|
+
throw new Error(`Validation error: ${error.details.map((x) => x.message).join(", ")}`);
|
|
3307
|
+
}
|
|
3308
|
+
return this.makeCalculationResponse(value);
|
|
3309
|
+
}
|
|
3310
|
+
|
|
3311
|
+
makeCalculationResponse(data: SetReleaseElevationForScenarioCalculationResponseSchemaData): SetReleaseElevationForScenarioCalculationResponse {
|
|
3312
|
+
return new SetReleaseElevationForScenarioCalculationResponse(
|
|
3313
|
+
data.updatedVessel,
|
|
3314
|
+
data.resultCode,
|
|
3315
|
+
data.messages,
|
|
3316
|
+
data.calculationElapsedTime,
|
|
3317
|
+
data.operationId
|
|
3318
|
+
);
|
|
3319
|
+
}
|
|
3320
|
+
}
|