-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrunModel.mos
More file actions
94 lines (69 loc) · 6.47 KB
/
runModel.mos
File metadata and controls
94 lines (69 loc) · 6.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
//>> omc --showErrorMessages ModelicaScript/runModel.mos
//This script illustrates many of the common ModelicaScript commands through dampedPendulum.mo
// The model is located at /ModelicaStandardLibrary/mechanics/multibody/dampedPendulum/dampedPendulum.mo
// The model will be built and run in /temp/, all script run from the repository root '/'
//See https://www.openmodelica.org/doc/OpenModelicaUsersGuide/latest/scripting_api.html
print("\ncheckSettings:"); //print() is not documented but works, b/c ModelicaScript is a subset of Modelica?
//checkSettings(); //shows the environment and build settings
print("\nloadFile:_________________________________________________________________________________");
loadFile(fileName="ModelicaStandardLibrary/mechanics/multibody/dampedPendulum/dampedPendulum.mo"); //loads model from a file
print("\ncd:_______________________________________________________________________________________");
cd("temp/");
print("\ncheckModel:_______________________________________________________________________________");
//checkModel(dampedPendulum);
print("\ncheckModel->getErrorString:");
getErrorString(); //returns the current error message
print("\nlist:_____________________________________________________________________________________");
//list(dampedPendulum);//lists the contents of the given class, or all loaded classes if empty
print("\nlistVariables:____________________________________________________________________________");
//listVariables();//lists all variables active in the scripting environment, that is those created in this file but not those found in the model
print("\ninstantiateModel:_________________________________________________________________________");
//instantiateModel(dampedPendulum); //instantiates the class and returns the flattened code
print("\nbuildLabel:_______________________________________________________________________________");
//buildLabel(dampedPendulum, startTime=0.0, stopTime=1.0, numberOfIntervals=100, tolerance=1e-3, cflags="-v -d=failtrace,cgraphGraphVizFile");
buildLabel(dampedPendulum, startTime=0.0, stopTime=1.0, numberOfIntervals=100, tolerance=1e-3, cflags="-fPIC -d=failtrace,cgraphGraphVizFile");
print("\nbuildLabel->getMessagesString:");
getMessagesString();
print("\nbuildLabel->getErrorString:");
getErrorString();
//*
print("\nbuildModel:_______________________________________________________________________________");
//buildModel(dampedPendulum, startTime=0.0, stopTime=1.0, numberOfIntervals=100, tolerance=1e-3);
//buildModel(dampedPendulum, startTime=0.0, stopTime=1.0, numberOfIntervals=100, tolerance=1e-3, cflags="-d=failtrace,cgraphGraphVizFile");
//cflags = "-d=failtrace,cgraphGraphVizFile";
//buildModel(dampedPendulum, startTime=0.0, stopTime=1.0, numberOfIntervals=100, tolerance=1e-3, cflags=cflags);
//print("\nbuildModel->countMessages:");
//countMessages(); //returns the number of (messages, warnings, errors)
print("\nbuildModel->getMessagesString:");
getMessagesString(); //returns the current error message
print("\nbuildModel->getErrorString:");
getErrorString(); //returns the current error message
//print("\nclearMessages:");
//clearMessages(); //clears the error buffer
//*/
//setCFlags("-fPIC -d=backenddaeinfo,cgraph,cgraphGraphVizFile,cgraphGraphVizShow,checkSimplify,countOperations,daedumpgraphv,debugDifferentiation,debugDifferentiationVerbose,discreteinfo,dynload,execstat,gcProfiling,graphml,graphviz,graphvizDot,initialization");
//print("\nsetCFlags->getMessagesString:");
//getMessagesString();
//print("\nsetCFlags->getErrorString:");
//getErrorString();
print("\nsimulate:_________________________________________________________________________________");
//simulate options:
// see https://www.openmodelica.org/doc/OpenModelicaUsersGuide/latest/simulationflags.html
// -abortSlowSimulation : stop simulation if it chatters
// -alarm=nSeconds : stop simulation after n seconds. If the alarm stops the simulation results are still created but they are not through StopTime. StdOut log shows "Alarm clock"
// -lv=LOG_SIMULATION,LOG_STATS : additional logs to turn on
// -outputPath : location for output files
// -r=resultFileName : default is ModelName_res.format
// -steadyState : abort if simulation has reached steady state. See message "steady state reached at time = ___".
//simulate(dampedPendulum, outputFormat="csv", cflags="-v --debug=failtrace,-cgraphGraphVizFile,countOperations", simflags="-abortSlowSimulation -alarm=5 -lv=LOG_SIMULATION,LOG_STATS -steadyState");
simulate(dampedPendulum, outputFormat="csv", cflags="-d=backenddaeinfo,dynload,cgraph,cgraphGraphVizFile,cgraphGraphVizShow,checkSimplify,countOperations,daedumpgraphv,debugDifferentiation,debugDifferentiationVerbose,discreteinfo,dynload,execstat,gcProfiling,graphml,graphviz,graphvizDot,initialization", simflags="-abortSlowSimulation -alarm=5 -steadyState");
print("\nsimulate->getErrorString:");
getErrorString(); //returns the current error message
//plotAll();//eventually draws a qt window, too many vars to be useful..
// BSD 3-Clause License
// Copyright (c) [2020], [Mechanomy, LLC] All rights reserved.
// Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
// 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
// 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.