@abi-software/simulationvuer 1.0.0 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/simulationvuer.js +41025 -7741
- package/dist/simulationvuer.umd.cjs +96 -13
- package/dist/style.css +1 -1
- package/package.json +2 -1
- package/src/App.vue +24 -11
- package/src/components/SimulationVuer.vue +410 -128
- package/src/components/SimulationVuerInput.vue +1 -1
- package/src/components/common.js +54 -15
- package/src/components/json.js +68 -66
- package/src/components/libopencor.js +16 -0
- package/src/components/libopencor.wasm +0 -0
- package/src/main.js +10 -13
- package/src/components/ui.js +0 -85
package/src/components/common.js
CHANGED
|
@@ -1,31 +1,70 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
function doEvaluateValue(value, from, to) {
|
|
4
|
-
if (from !== undefined) {
|
|
5
|
-
let re = new RegExp(`\\b${ from }\\b`, 'g');
|
|
1
|
+
import { create, all } from "mathjs";
|
|
6
2
|
|
|
7
|
-
|
|
8
|
-
}
|
|
3
|
+
const math = create(all, {});
|
|
9
4
|
|
|
10
|
-
|
|
11
|
-
}
|
|
5
|
+
export const OPENCOR_SOLVER_NAME = "simcore/services/comp/opencor";
|
|
12
6
|
|
|
13
7
|
export function evaluateValue(parent, value) {
|
|
14
8
|
let index = -1;
|
|
9
|
+
const parser = new math.parser();
|
|
15
10
|
|
|
16
11
|
parent.simulationUiInfo.input.forEach((input) => {
|
|
17
12
|
++index;
|
|
18
13
|
|
|
19
|
-
|
|
14
|
+
parser.set(input.id, parent.$refs.simInput[index].vModel);
|
|
20
15
|
});
|
|
21
16
|
|
|
22
|
-
return
|
|
17
|
+
return parser.evaluate(value);
|
|
23
18
|
}
|
|
24
19
|
|
|
25
|
-
export function
|
|
26
|
-
|
|
27
|
-
|
|
20
|
+
export function updateUi(parent) {
|
|
21
|
+
// Show/hide and enable/disable all the elements.
|
|
22
|
+
|
|
23
|
+
parent.$nextTick(() => {
|
|
24
|
+
let index = -1;
|
|
25
|
+
|
|
26
|
+
parent.simulationUiInfo.input.forEach((input) => {
|
|
27
|
+
++index;
|
|
28
|
+
|
|
29
|
+
parent.$refs.simInput[index].visible = (input.visible === undefined) ? true : evaluateValue(parent, input.visible);
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
if (parent.libopencor !== undefined) {
|
|
33
|
+
parent.userMessage = "Rerunning the model...";
|
|
34
|
+
parent.showUserMessage = true;
|
|
35
|
+
|
|
36
|
+
parent.$nextTick(() => {
|
|
37
|
+
parent.runSimulation();
|
|
38
|
+
});
|
|
39
|
+
}
|
|
28
40
|
});
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export function finaliseUi(parent) {
|
|
44
|
+
// Finalise our UI, but only if we haven't already done so, we are mounted,
|
|
45
|
+
// and we have some valid simulation UI information.
|
|
46
|
+
|
|
47
|
+
if (!parent.hasFinalisedUi && parent.isMounted && parent.hasValidSimulationUiInfo) {
|
|
48
|
+
// Configure the PlotVuer's.
|
|
49
|
+
|
|
50
|
+
parent.$refs.output.classList.add("x" + parent.simulationUiInfo.output.plots.length);
|
|
51
|
+
|
|
52
|
+
// Initialise the simulation results.
|
|
29
53
|
|
|
30
|
-
|
|
54
|
+
let index = -1;
|
|
55
|
+
|
|
56
|
+
parent.simulationUiInfo.output.plots.forEach(() => {
|
|
57
|
+
parent.simulationResults[++index] = [{
|
|
58
|
+
x: [],
|
|
59
|
+
y: [],
|
|
60
|
+
type: "scatter",
|
|
61
|
+
}];
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
// Make sure that our UI is up to date.
|
|
65
|
+
|
|
66
|
+
updateUi(parent);
|
|
67
|
+
|
|
68
|
+
parent.hasFinalisedUi = true;
|
|
69
|
+
}
|
|
31
70
|
}
|
package/src/components/json.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { Validator } from "jsonschema";
|
|
2
2
|
import { OPENCOR_SOLVER_NAME } from "./common.js";
|
|
3
3
|
|
|
4
|
-
export function validJson(json) {
|
|
4
|
+
export function validJson(json, simulationInfoNeeded) {
|
|
5
5
|
// Check the JSON against our schema.
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
const validator = new Validator();
|
|
8
|
+
const schema = {
|
|
9
9
|
additionalProperties: false,
|
|
10
10
|
properties: {
|
|
11
11
|
input: {
|
|
@@ -214,14 +214,14 @@ export function validJson(json) {
|
|
|
214
214
|
type: "array",
|
|
215
215
|
},
|
|
216
216
|
},
|
|
217
|
-
required:
|
|
217
|
+
required: simulationInfoNeeded,
|
|
218
218
|
type: "object",
|
|
219
219
|
},
|
|
220
220
|
},
|
|
221
221
|
type: "object",
|
|
222
222
|
};
|
|
223
223
|
|
|
224
|
-
|
|
224
|
+
const result = validator.validate(json, schema, { nestedErrors: true });
|
|
225
225
|
|
|
226
226
|
if (!result.valid) {
|
|
227
227
|
console.warn(result.toString());
|
|
@@ -231,8 +231,8 @@ export function validJson(json) {
|
|
|
231
231
|
|
|
232
232
|
// Make sure that the input information makes sense.
|
|
233
233
|
|
|
234
|
-
|
|
235
|
-
|
|
234
|
+
const inputIdUsed = {};
|
|
235
|
+
const inputValid = json.input.every((input) => {
|
|
236
236
|
if (input.id !== undefined) {
|
|
237
237
|
if (input.id === "") {
|
|
238
238
|
console.warn("JSON: the input id must not be empty.");
|
|
@@ -240,7 +240,7 @@ export function validJson(json) {
|
|
|
240
240
|
return false;
|
|
241
241
|
}
|
|
242
242
|
|
|
243
|
-
if (inputIdUsed[input.id]) {
|
|
243
|
+
if (inputIdUsed[input.id] !== undefined) {
|
|
244
244
|
console.warn("JSON: the input id must be unique (" + input.id + " is used more than once).");
|
|
245
245
|
|
|
246
246
|
return false;
|
|
@@ -268,13 +268,13 @@ export function validJson(json) {
|
|
|
268
268
|
return false;
|
|
269
269
|
}
|
|
270
270
|
|
|
271
|
-
|
|
271
|
+
const values = input.possibleValues.map((value) => {
|
|
272
272
|
return value.value;
|
|
273
273
|
});
|
|
274
|
-
|
|
274
|
+
const valueUsed = {};
|
|
275
275
|
|
|
276
276
|
if (!values.every((value) => {
|
|
277
|
-
if (valueUsed[value]) {
|
|
277
|
+
if (valueUsed[value] !== undefined) {
|
|
278
278
|
console.warn("JSON: an input possible value must have a unique value (" + value + " is used more than once).");
|
|
279
279
|
|
|
280
280
|
return false;
|
|
@@ -307,7 +307,7 @@ export function validJson(json) {
|
|
|
307
307
|
return false;
|
|
308
308
|
}
|
|
309
309
|
|
|
310
|
-
|
|
310
|
+
const range = input.maximumValue - input.minimumValue;
|
|
311
311
|
|
|
312
312
|
if (input.stepValue !== undefined) {
|
|
313
313
|
if ((input.stepValue <= 0) || (input.stepValue > range)) {
|
|
@@ -347,8 +347,8 @@ export function validJson(json) {
|
|
|
347
347
|
|
|
348
348
|
// Make sure that the output information makes sense.
|
|
349
349
|
|
|
350
|
-
|
|
351
|
-
|
|
350
|
+
const outputIdUsed = {};
|
|
351
|
+
const outputDataValid = json.output.data.every((outputData) => {
|
|
352
352
|
if (outputData.id !== undefined) {
|
|
353
353
|
if (outputData.id === "") {
|
|
354
354
|
console.warn("JSON: the output data id must not be empty.");
|
|
@@ -356,7 +356,7 @@ export function validJson(json) {
|
|
|
356
356
|
return false;
|
|
357
357
|
}
|
|
358
358
|
|
|
359
|
-
if (outputIdUsed[outputData.id]) {
|
|
359
|
+
if (outputIdUsed[outputData.id] !== undefined) {
|
|
360
360
|
console.warn("JSON: the output data id must be unique (" + outputData.id + " is used more than once).");
|
|
361
361
|
|
|
362
362
|
return false;
|
|
@@ -378,7 +378,7 @@ export function validJson(json) {
|
|
|
378
378
|
return false;
|
|
379
379
|
}
|
|
380
380
|
|
|
381
|
-
|
|
381
|
+
const outputPlotsValid = json.output.plots.every((outputPlot) => {
|
|
382
382
|
if (outputPlot.xAxisTitle === "") {
|
|
383
383
|
console.warn("JSON: the output plot X axis title must not be empty.");
|
|
384
384
|
|
|
@@ -413,7 +413,7 @@ export function validJson(json) {
|
|
|
413
413
|
// Make sure that the parameters information makes sense.
|
|
414
414
|
|
|
415
415
|
if (json.parameters !== undefined) {
|
|
416
|
-
|
|
416
|
+
const parametersValid = json.parameters.every((parameter) => {
|
|
417
417
|
if (parameter.name === "") {
|
|
418
418
|
console.warn("JSON: the parameter name must not be empty.");
|
|
419
419
|
|
|
@@ -436,85 +436,87 @@ export function validJson(json) {
|
|
|
436
436
|
|
|
437
437
|
// Make sure that the simulation information makes sense.
|
|
438
438
|
|
|
439
|
-
|
|
439
|
+
if (simulationInfoNeeded) {
|
|
440
|
+
let needOpencorSettings = false;
|
|
440
441
|
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
442
|
+
if (!json.simulation.solvers.every((solver) => {
|
|
443
|
+
if (solver.if !== undefined) {
|
|
444
|
+
if (solver.if === "") {
|
|
445
|
+
console.warn("JSON: a simulation solver if must not be empty.");
|
|
445
446
|
|
|
446
|
-
|
|
447
|
+
return false;
|
|
448
|
+
}
|
|
447
449
|
}
|
|
448
|
-
}
|
|
449
450
|
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
451
|
+
if (solver.input !== undefined) {
|
|
452
|
+
if (solver.input.name === "") {
|
|
453
|
+
console.warn("JSON: a simulation solver input name must not be empty.");
|
|
453
454
|
|
|
454
|
-
|
|
455
|
+
return false;
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
if (solver.input.value === "") {
|
|
459
|
+
console.warn("JSON: a simulation solver input value must not be empty.");
|
|
460
|
+
|
|
461
|
+
return false;
|
|
462
|
+
}
|
|
455
463
|
}
|
|
456
464
|
|
|
457
|
-
if (solver.
|
|
458
|
-
console.warn("JSON: a simulation solver
|
|
465
|
+
if (solver.name === "") {
|
|
466
|
+
console.warn("JSON: a simulation solver name must not be empty.");
|
|
459
467
|
|
|
460
468
|
return false;
|
|
461
469
|
}
|
|
462
|
-
}
|
|
463
470
|
|
|
464
|
-
|
|
465
|
-
console.warn("JSON: a simulation solver name must not be empty.");
|
|
471
|
+
needOpencorSettings = needOpencorSettings || (solver.name === OPENCOR_SOLVER_NAME);
|
|
466
472
|
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
needOpencorSettings = needOpencorSettings || (solver.name === OPENCOR_SOLVER_NAME);
|
|
473
|
+
if (solver.version === "") {
|
|
474
|
+
console.warn("JSON: a simulation solver version must not be empty.");
|
|
471
475
|
|
|
472
|
-
|
|
473
|
-
|
|
476
|
+
return false;
|
|
477
|
+
}
|
|
474
478
|
|
|
479
|
+
return true;
|
|
480
|
+
})) {
|
|
475
481
|
return false;
|
|
476
482
|
}
|
|
477
483
|
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
return false;
|
|
481
|
-
}
|
|
484
|
+
if (needOpencorSettings && (json.simulation.opencor === undefined)) {
|
|
485
|
+
console.warn("JSON: the simulation solver for OpenCOR is specified so simulation OpenCOR settings must also be specified.");
|
|
482
486
|
|
|
483
|
-
|
|
484
|
-
|
|
487
|
+
return false;
|
|
488
|
+
}
|
|
485
489
|
|
|
486
|
-
|
|
487
|
-
|
|
490
|
+
if (json.simulation.opencor !== undefined) {
|
|
491
|
+
if (json.simulation.opencor.resource === "") {
|
|
492
|
+
console.warn("JSON: the simulation OpenCOR resource must not be empty.");
|
|
488
493
|
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
console.warn("JSON: the simulation OpenCOR resource must not be empty.");
|
|
494
|
+
return false;
|
|
495
|
+
}
|
|
492
496
|
|
|
493
|
-
|
|
494
|
-
|
|
497
|
+
if (json.simulation.opencor.endingPoint !== undefined) {
|
|
498
|
+
if (json.simulation.opencor.pointInterval !== undefined) {
|
|
499
|
+
if (json.simulation.opencor.endingPoint <= 0.0) {
|
|
500
|
+
console.warn("JSON: the simulation OpenCOR ending point (" + json.simulation.opencor.endingPoint + ") must be greater than zero.");
|
|
495
501
|
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
if (json.simulation.opencor.endingPoint <= 0.0) {
|
|
499
|
-
console.warn("JSON: the simulation OpenCOR ending point (" + json.simulation.opencor.endingPoint + ") must be greater than zero.");
|
|
502
|
+
return false;
|
|
503
|
+
}
|
|
500
504
|
|
|
501
|
-
|
|
502
|
-
|
|
505
|
+
if (json.simulation.opencor.pointInterval <= 0.0) {
|
|
506
|
+
console.warn("JSON: the simulation OpenCOR point interval (" + json.simulation.opencor.pointInterval + ") must be greater than zero.");
|
|
503
507
|
|
|
504
|
-
|
|
505
|
-
|
|
508
|
+
return false;
|
|
509
|
+
}
|
|
510
|
+
} else {
|
|
511
|
+
console.warn("JSON: a simulation OpenCOR ending point is specified so a simulation OpenCOR point interval must also be specified.");
|
|
506
512
|
|
|
507
513
|
return false;
|
|
508
514
|
}
|
|
509
|
-
} else {
|
|
510
|
-
console.warn("JSON: a simulation OpenCOR
|
|
515
|
+
} else if (json.simulation.opencor.pointInterval !== undefined) {
|
|
516
|
+
console.warn("JSON: a simulation OpenCOR point interval is specified so a simulation OpenCOR ending point must also be specified.");
|
|
511
517
|
|
|
512
518
|
return false;
|
|
513
519
|
}
|
|
514
|
-
} else if (json.simulation.opencor.pointInterval !== undefined) {
|
|
515
|
-
console.warn("JSON: a simulation OpenCOR point interval is specified so a simulation OpenCOR ending point must also be specified.");
|
|
516
|
-
|
|
517
|
-
return false;
|
|
518
520
|
}
|
|
519
521
|
}
|
|
520
522
|
|