Ticket #3028: plant.mos

File plant.mos, 2.2 KB (added by Ravi Saripalli <ravi.saripalli@…>, 10 years ago)
Line 
1echo(false) ;
2if (loadFile("plant.mo"))then
3 print("Plant Model Loaded\n");
4else
5 print("Plant Model failed\n");
6 exit(0) ;
7end if;
8/************ Cleanup Work **********/
9print("Cleaning Up Work Area\n") ;
10system("rm work/*");
11cd("./work"); // Do all the dirty work here
12print(getSettings());
13
14/********* Flatten and Run Plant ******/
15print("Simulation has begun\n");
16
17/* if you don't set timeStep it is calculated as (stopTime-startTime)/count
18 which can be bad news fi you set too large a stopTime this really
19 caught me off gaurd, lost few weeks of effor */
20
21tEnd := 10;
22iniStepSize := 0.05 ;
23count := 100 ; // floor(tEnd / iniStepSize) ;
24setDebugFlags("infoXmlOperations,failtrace");
25flags := "" ; // "-lv=LOG_NLS" ;
26echo(true);
27status := simulate(plant, startTime=0, outputFormat="mat",
28 stopTime=tEnd, tolerance=1e-6, stepSize=iniStepSize,
29 numberOfIntervals=count, simflags=flags) ;
30echo(false);
31
32/* Error Handling stuff */
33getErrorMessage();
34writeFile("tmpfile",status.messages);
35system("grep \"Simulation execution failed\" tmpfile | wc -l > tmpfile");
36getErrorMessage();
37success := Modelica.Utilities.Strings.isEqual(readFile("tmpfile"),"0",false);
38getErrorMessage();
39
40if (false) then
41 print("simulation failed ... bailing out\n");
42 exit(0) ;
43else
44 print("simulation done\n");
45 sVars := readSimulationResultVars("plant_res.mat");
46 print("No. of Plant Variables = " + String(size(sVars,1)) + "\n");
47end if;
48
49
50print("Plotting\n");
51
52plot({mv, sp, pv},
53 curveWidth=2, externalWindow=true, title = "PI controller)");
54 system("sleep 1s");
55
56/***********************************************************/
57/* Useful String Manipulation Functions */
58/* These exist in Modelica.Utilities.Strings ..
59 but just an illustration of using external calls */
60/***********************************************************/
61loadString("
62 function strlen
63 input String str;
64 output Integer len;
65 external \"C\" len=ModelicaStrings_length(str);
66 end strlen;
67 function substr
68 input String str;
69 input Integer i1,i2;
70 output String out;
71 external \"C\" out=ModelicaStrings_substring(str,i1,i2);
72 end substr;
73");
74/***********************************************************/
75