@abi-software/simulationvuer 2.0.0 → 2.0.2

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.
@@ -3,8 +3,8 @@
3
3
  <p v-if="!hasValidSimulationUiInfo && !showUserMessage" class="default error"><span class="error">Error:</span> an unknown or invalid model was provided.</p>
4
4
  <div class="main" v-if="hasValidSimulationUiInfo">
5
5
  <div class="main-left">
6
- <p class="default name">{{name}}</p>
7
- <el-divider></el-divider>
6
+ <p class="default name" v-if="libopencor === undefined">{{name}}</p>
7
+ <el-divider v-if="libopencor === undefined"></el-divider>
8
8
  <p class="default input-parameters">Input parameters</p>
9
9
  <div class="input scrollbar">
10
10
  <SimulationVuerInput v-for="(input, index) in simulationUiInfo.input"
@@ -19,16 +19,16 @@
19
19
  />
20
20
  </div>
21
21
  <div class="primary-button">
22
- <el-button type="primary" size="small" @click="startSimulation()" v-if="!this.libopencor">Run Simulation</el-button>
22
+ <el-button type="primary" size="small" @click="startSimulation()" v-if="libopencor === undefined">Run Simulation</el-button>
23
23
  </div>
24
24
  <div class="secondary-button" v-if="uuid">
25
25
  <el-button size="small" @click="runOnOsparc()">Run on oSPARC</el-button>
26
26
  </div>
27
27
  <div class="secondary-button">
28
- <el-button size="small" @click="viewDataset()" v-if="typeof this.id === 'number'">View Dataset</el-button>
28
+ <el-button size="small" @click="viewDataset()" v-if="libopencor === undefined">View Dataset</el-button>
29
29
  </div>
30
30
  <div class="secondary-button">
31
- <el-button size="small" @click="viewWorkspace()" v-if="typeof this.id !== 'number'">View Workspace</el-button>
31
+ <el-button size="small" @click="viewWorkspace()" v-if="libopencor !== undefined">View Workspace</el-button>
32
32
  </div>
33
33
  <p class="default note" v-if="uuid">Additional parameters are available on oSPARC</p>
34
34
  </div>
@@ -89,20 +89,12 @@ export default {
89
89
  type: String,
90
90
  },
91
91
  /**
92
- * The ID of the simulation-based dataset.
92
+ * The ID of the simulation-based dataset, if it is a number, or the path
93
+ * to a PMR file, if it is a string.
93
94
  */
94
95
  id: {
95
96
  required: true,
96
97
  },
97
- /**
98
- * The preferred solver to use for OpenCOR-based simulations. This property
99
- * is optional and defaults to "oSPARC". The only value that is currently
100
- * supported is "libOpenCOR". Any other value will default to "oSPARC".
101
- */
102
- preferredSolver: {
103
- type: String,
104
- default: OSPARC_SOLVER,
105
- },
106
98
  },
107
99
  data: function() {
108
100
  // Retrieve some information about the dataset.
@@ -140,7 +132,6 @@ export default {
140
132
  perfectScollbarOptions: {
141
133
  suppressScrollX: true,
142
134
  },
143
- pmrBasedCombineArchive: false,
144
135
  showUserMessage: false,
145
136
  simulationResults: {},
146
137
  simulationResultsId: {},
@@ -216,27 +207,14 @@ export default {
216
207
  },
217
208
  /**
218
209
  * @vuese
219
- * Run the simulation using libOpenCOR.
210
+ * Run a PMR-based COMBINE archive using libOpenCOR.
220
211
  */
221
212
  runSimulation() {
222
213
  if (this.instance === undefined) {
223
- const fileNameOrUrl = this.pmrBasedCombineArchive ? PMR_URL + this.id : this.simulationUiInfo.simulation.opencor.resource;
224
- const document = new this.libopencor.SedDocument(toRaw(this.fileManager).file(fileNameOrUrl));
225
-
226
- // Customise the ending point and point interval of the simulation, if
227
- // needed.
228
-
229
- if ( !this.pmrBasedCombineArchive
230
- && (this.simulationUiInfo.simulation.opencor.endingPoint !== undefined)
231
- && (this.simulationUiInfo.simulation.opencor.pointInterval !== undefined)) {
232
- const simulation = document.simulations().get(0);
233
-
234
- simulation.setOutputEndTime(this.simulationUiInfo.simulation.opencor.endingPoint);
235
- simulation.setNumberOfSteps(this.simulationUiInfo.simulation.opencor.endingPoint / this.simulationUiInfo.simulation.opencor.pointInterval);
236
- }
237
-
238
214
  // Retrieve an instance of the model.
239
215
 
216
+ const document = new this.libopencor.SedDocument(toRaw(this.fileManager).file(PMR_URL + this.id));
217
+
240
218
  this.instance = document.instantiate();
241
219
 
242
220
  document.delete();
@@ -301,7 +279,7 @@ export default {
301
279
 
302
280
  // Make sure that the simulation UI information is valid.
303
281
 
304
- this.hasValidSimulationUiInfo = validJson(this.simulationUiInfo, !this.pmrBasedCombineArchive);
282
+ this.hasValidSimulationUiInfo = validJson(this.simulationUiInfo, this.libopencor === undefined);
305
283
 
306
284
  if (!this.hasValidSimulationUiInfo) {
307
285
  return;
@@ -310,7 +288,7 @@ export default {
310
288
  // Retrieve and keep track of the solver to be used for the simulation, if
311
289
  // needed.
312
290
 
313
- if (!this.pmrBasedCombineArchive) {
291
+ if (this.libopencor === undefined) {
314
292
  this.simulationUiInfo.simulation.solvers.forEach((solver) => {
315
293
  if ((solver.if === undefined) || evaluateValue(this, solver.if)) {
316
294
  this.solver = solver;
@@ -330,14 +308,14 @@ export default {
330
308
  // load libOpenCOR if we are dealing with an OpenCOR-based simulation and
331
309
  // we want to use libOpenCOR.
332
310
 
333
- if (this.pmrBasedCombineArchive) {
311
+ if (this.libopencor !== undefined) {
334
312
  this.userMessage = "Running the model...";
335
313
  this.showUserMessage = true;
336
314
 
337
315
  this.$nextTick(() => {
338
316
  this.runSimulation();
339
317
  });
340
- } else if (this.opencorBasedSimulation && (this.preferredSolver === LIBOPENCOR_SOLVER)) {
318
+ } else if (this.opencorBasedSimulation && (this.libopencor !== undefined)) {
341
319
  this.userMessage = "Retrieving and running the model...";
342
320
  this.showUserMessage = true;
343
321
 
@@ -583,6 +561,16 @@ export default {
583
561
  ];
584
562
  });
585
563
  },
564
+ /**
565
+ * @vuese
566
+ * Show an HTTP issue using the given `xmlhttp`.
567
+ * @arg `xmlhttp`
568
+ */
569
+ showHttpIssue(xmlhttp) {
570
+ this.isSimulationValid = false;
571
+ this.showUserMessage = false;
572
+ this.errorMessage = xmlhttp.statusText.toLowerCase() + " (<a href='https://httpstatuses.com/" + xmlhttp.status + "/' target='_blank'>" + xmlhttp.status + "</a>)";
573
+ },
586
574
  /**
587
575
  * @vuese
588
576
  * Check the progress of the simulation using the given `data`, a JSON object that contains the simulation job ID,
@@ -626,9 +614,7 @@ export default {
626
614
  this.errorMessage = response.description;
627
615
  }
628
616
  } else {
629
- this.isSimulationValid = false;
630
- this.showUserMessage = false;
631
- this.errorMessage = xmlhttp.statusText.toLowerCase() + " (<a href='https://httpstatuses.com/" + xmlhttp.status + "/' target='_blank'>" + xmlhttp.status + "</a>)";
617
+ this.showHttpIssue(xmlhttp);
632
618
  }
633
619
  }
634
620
  };
@@ -664,12 +650,10 @@ export default {
664
650
  this.checkSimulation(response.data);
665
651
  } else {
666
652
  this.showUserMessage = false;
667
- this.errorMessage = response.description;
653
+ this.errorMessage = response.description + "ASDASDASD";
668
654
  }
669
655
  } else {
670
- this.isSimulationValid = false;
671
- this.showUserMessage = false;
672
- this.errorMessage = xmlhttp.statusText.toLowerCase() + " (<a href='https://httpstatuses.com/" + xmlhttp.status + "/' target='_blank'>" + xmlhttp.status + "</a>)";
656
+ this.showHttpIssue(xmlhttp);
673
657
  }
674
658
  }
675
659
  };
@@ -704,7 +688,7 @@ export default {
704
688
  xmlhttp.send();
705
689
  });
706
690
  } else if (this.id !== 0) {
707
- this.userMessage = "Retrieving OMEX file...";
691
+ this.userMessage = "Retrieving COMBINE archive from PMR...";
708
692
  this.showUserMessage = true;
709
693
 
710
694
  // Retrieve the OMEX file, extract the simulation UI JSON file from it and
@@ -716,24 +700,27 @@ export default {
716
700
  xmlhttp.open("POST", this.apiLocation + "/pmr_file");
717
701
  xmlhttp.setRequestHeader("Content-type", "application/json");
718
702
  xmlhttp.onreadystatechange = () => {
719
- if ((xmlhttp.readyState === 4) && (xmlhttp.status === 200)) {
720
- libOpenCOR().then((libopencor) => {
721
- this.pmrBasedCombineArchive = true;
722
- this.libopencor = libopencor;
723
- this.fileManager = this.libopencor.FileManager.instance();
703
+ if (xmlhttp.readyState === 4) {
704
+ if (xmlhttp.status === 200) {
705
+ libOpenCOR().then((libopencor) => {
706
+ this.libopencor = libopencor;
707
+ this.fileManager = this.libopencor.FileManager.instance();
724
708
 
725
- const fileContents = Uint8Array.from(atob(xmlhttp.response), (c) => c.charCodeAt(0));
726
- const file = this.manageFile(PMR_URL + this.id, fileContents);
709
+ const fileContents = Uint8Array.from(atob(xmlhttp.response), (c) => c.charCodeAt(0));
710
+ const file = this.manageFile(PMR_URL + this.id, fileContents);
727
711
 
728
- const decoder = new TextDecoder();
729
- const simulationUiInfo = JSON.parse(decoder.decode(file.childFile("simulation.json").contents()));
712
+ const decoder = new TextDecoder();
713
+ const simulationUiInfo = JSON.parse(decoder.decode(file.childFile("simulation.json").contents()));
730
714
 
731
- this.showUserMessage = false;
715
+ this.showUserMessage = false;
732
716
 
733
- this.$nextTick(() => {
734
- this.buildSimulationUi(simulationUiInfo);
717
+ this.$nextTick(() => {
718
+ this.buildSimulationUi(simulationUiInfo);
719
+ });
735
720
  });
736
- });
721
+ } else {
722
+ this.showUserMessage = false;
723
+ }
737
724
  }
738
725
  };
739
726
  xmlhttp.send(JSON.stringify({path: this.id}));