OMCompiler/Compiler/Util/SimulationResults.mo
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /* | ||
| 2 | * This file is part of OpenModelica. | ||
| 3 | * | ||
| 4 | * Copyright (c) 1998-2026, Open Source Modelica Consortium (OSMC), | ||
| 5 | * c/o Linköpings universitet, Department of Computer and Information Science, | ||
| 6 | * SE-58183 Linköping, Sweden. | ||
| 7 | * | ||
| 8 | * All rights reserved. | ||
| 9 | * | ||
| 10 | * THIS PROGRAM IS PROVIDED UNDER THE TERMS OF AGPL VERSION 3 LICENSE OR | ||
| 11 | * THIS OSMC PUBLIC LICENSE (OSMC-PL) VERSION 1.8. | ||
| 12 | * ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS PROGRAM CONSTITUTES | ||
| 13 | * RECIPIENT'S ACCEPTANCE OF THE OSMC PUBLIC LICENSE OR THE GNU AGPL | ||
| 14 | * VERSION 3, ACCORDING TO RECIPIENTS CHOICE. | ||
| 15 | * | ||
| 16 | * The OpenModelica software and the OSMC (Open Source Modelica Consortium) | ||
| 17 | * Public License (OSMC-PL) are obtained from OSMC, either from the above | ||
| 18 | * address, from the URLs: | ||
| 19 | * http://www.openmodelica.org or | ||
| 20 | * https://github.com/OpenModelica/ or | ||
| 21 | * http://www.ida.liu.se/projects/OpenModelica, | ||
| 22 | * and in the OpenModelica distribution. | ||
| 23 | * | ||
| 24 | * GNU AGPL version 3 is obtained from: | ||
| 25 | * https://www.gnu.org/licenses/licenses.html#GPL | ||
| 26 | * | ||
| 27 | * This program is distributed WITHOUT ANY WARRANTY; without | ||
| 28 | * even the implied warranty of MERCHANTABILITY or FITNESS | ||
| 29 | * FOR A PARTICULAR PURPOSE, EXCEPT AS EXPRESSLY SET FORTH | ||
| 30 | * IN THE BY RECIPIENT SELECTED SUBSIDIARY LICENSE CONDITIONS OF OSMC-PL. | ||
| 31 | * | ||
| 32 | * See the full OSMC Public License conditions for more details. | ||
| 33 | * | ||
| 34 | */ | ||
| 35 | |||
| 36 | encapsulated package SimulationResults | ||
| 37 | " file: SimulationResults.mo | ||
| 38 | package: SimulationResults | ||
| 39 | description: Read simulation results into the Values.Value structure. | ||
| 40 | |||
| 41 | |||
| 42 | " | ||
| 43 | |||
| 44 | import Values; | ||
| 45 | |||
| 46 | protected | ||
| 47 | |||
| 48 | import List; | ||
| 49 | import ValuesMake; | ||
| 50 | |||
| 51 | ✗ | public function val | |
| 52 | input String filename; | ||
| 53 | input String varname; | ||
| 54 | input Real timeStamp; | ||
| 55 | output Real val; | ||
| 56 | external "C" val=SimulationResults_val(filename,varname,timeStamp); | ||
| 57 | end val; | ||
| 58 | |||
| 59 | 2510 | public function readVariables | |
| 60 | input String filename; | ||
| 61 | input Boolean readParameters = true; | ||
| 62 | input Boolean openmodelicaStyle = false; | ||
| 63 | output list<String> vars; | ||
| 64 | |||
| 65 | external "C" vars=SimulationResults_readVariables(filename, readParameters, openmodelicaStyle) annotation(Library = "omcruntime"); | ||
| 66 | end readVariables; | ||
| 67 | |||
| 68 | public function readDataset | ||
| 69 | input String filename; | ||
| 70 | input list<String> vars; | ||
| 71 | input Integer dimsize; | ||
| 72 | output Values.Value val; | ||
| 73 | protected | ||
| 74 | list<list<Real>> rvals; | ||
| 75 | list<list<Values.Value>> vals; | ||
| 76 | list<Values.Value> rows; | ||
| 77 | 104 | function readDataset_work | |
| 78 | input String filename; | ||
| 79 | input list<String> vars; | ||
| 80 | input Integer dimsize; | ||
| 81 | output list<list<Real>> outMatrix; | ||
| 82 | |||
| 83 | external "C" outMatrix=SimulationResults_readDataset(filename,vars,dimsize) annotation(Library = "omcruntime"); | ||
| 84 | end readDataset_work; | ||
| 85 | algorithm | ||
| 86 | rvals := readDataset_work(filename,vars,dimsize); | ||
| 87 | 52 | vals := List.mapListReverse(rvals, ValuesMake.makeReal); | |
| 88 | 52 | rows := List.mapReverse(vals, ValuesMake.makeArray); | |
| 89 | 52 | val := ValuesMake.makeArray(rows); | |
| 90 | end readDataset; | ||
| 91 | |||
| 92 | ✗ | public function readSimulationResultSize | |
| 93 | input String filename; | ||
| 94 | output Integer size; | ||
| 95 | |||
| 96 | external "C" size=SimulationResults_readSimulationResultSize(filename) annotation(Library = "omcruntime"); | ||
| 97 | end readSimulationResultSize; | ||
| 98 | |||
| 99 | 39 | public function close | |
| 100 | external "C" SimulationResults_close() annotation(Library = "omcruntime"); | ||
| 101 | end close; | ||
| 102 | |||
| 103 | 1199 | public function cmpSimulationResults | |
| 104 | input Boolean runningTestsuite; | ||
| 105 | input String filename; | ||
| 106 | input String reffilename; | ||
| 107 | input String logfilename; | ||
| 108 | input Real refTol; | ||
| 109 | input Real absTol; | ||
| 110 | input list<String> vars; | ||
| 111 | output list<String> res; | ||
| 112 | external "C" res=SimulationResults_cmpSimulationResults(runningTestsuite,filename,reffilename,logfilename,refTol,absTol,vars) annotation(Library = "omcruntime"); | ||
| 113 | end cmpSimulationResults; | ||
| 114 | |||
| 115 | 183 | public function deltaSimulationResults | |
| 116 | input String filename; | ||
| 117 | input String reffilename; | ||
| 118 | input String method; | ||
| 119 | input list<String> vars; | ||
| 120 | output Real res; | ||
| 121 | external "C" res=SimulationResults_deltaSimulationResults(filename,reffilename,method,vars) annotation(Library = "omcruntime"); | ||
| 122 | end deltaSimulationResults; | ||
| 123 | |||
| 124 | 12 | public function diffSimulationResults | |
| 125 | input Boolean runningTestsuite; | ||
| 126 | input String filename; | ||
| 127 | input String reffilename; | ||
| 128 | input String prefix; | ||
| 129 | input Real refTol; | ||
| 130 | input Real relTolDiffMaxMin; | ||
| 131 | input Real rangeDelta; | ||
| 132 | input list<String> vars; | ||
| 133 | input Boolean keepEqualResults; | ||
| 134 | output Boolean success; | ||
| 135 | output list<String> res; | ||
| 136 | external "C" res=SimulationResults_diffSimulationResults(runningTestsuite,filename,reffilename,prefix,refTol,relTolDiffMaxMin,rangeDelta,vars,keepEqualResults,success) annotation(Library = "omcruntime"); | ||
| 137 | end diffSimulationResults; | ||
| 138 | |||
| 139 | 238 | public function diffSimulationResultsHtml | |
| 140 | input Boolean runningTestsuite; | ||
| 141 | input String filename; | ||
| 142 | input String reffilename; | ||
| 143 | input Real refTol; | ||
| 144 | input Real relTolDiffMaxMin; | ||
| 145 | input Real rangeDelta; | ||
| 146 | input String var; | ||
| 147 | output String html; | ||
| 148 | external "C" html=SimulationResults_diffSimulationResultsHtml(runningTestsuite,var,filename,reffilename,refTol,relTolDiffMaxMin,rangeDelta) annotation(Library = "omcruntime"); | ||
| 149 | end diffSimulationResultsHtml; | ||
| 150 | |||
| 151 | ✗ | public function filterSimulationResults | |
| 152 | input String inFile; | ||
| 153 | input String outFile; | ||
| 154 | input list<String> vars; | ||
| 155 | input Integer numberOfIntervals; | ||
| 156 | input Boolean removeDescription; | ||
| 157 | input Boolean hintReadAllVars "Read a whole mat-file into memory. May crash OMC if you have too little virtual memory."; | ||
| 158 | output Boolean result; | ||
| 159 | external "C" result=SimulationResults_filterSimulationResults(inFile,outFile,vars,numberOfIntervals,removeDescription,hintReadAllVars) annotation(Library = "omcruntime"); | ||
| 160 | end filterSimulationResults; | ||
| 161 | |||
| 162 | annotation(__OpenModelica_Interface="script_util"); | ||
| 163 | end SimulationResults; | ||
| 164 |