Archived OpenModelica forums. Posting is disabled.

Alternative forums include GitHub discussions or StackOverflow (make sure to read the Stack Overflow rules; you need to have well-formed questions)


Forgot password? | Forgot username? | Register

OMPython

OMPython

Hi,
I am freshly install OMPython. My OS is win7.
I have simple code such as below.

Code:


from OMPython import OMCSession
OMPython = OMCSession()

print OMPython.execute('loadModel(Modelica)')
print OMPython.execute  ('loadFile(\"C:/loop/test.mo\")')
result = OMPython.execute('simulate(test)')
OMPython.execute("plot(meter.v)")
print result

I have 3 question.
1) I read print result file ..... 'resultFile': '"C:/loop/test.mat"'}  but, there is no test.mat file in c:/loop folder.

2) How can get result file as csv file not mat?

3)If simulation stop time 100 then, how can i get specific time result on screen like meter.v (time =33) ?

Thanks

Oki 

Re: OMPython

Hi,

1. the file is generated in the current directory, not in c:/loop.
use cd("c:/loop") before running simulate if you want the files there.

2. Use: simulate(Model, outputFormat="csv") to generate a comma separated values file.

3. Use val(meter.v, 33) to get the value of meter.v at time 33

See also:
https://build.openmodelica.org/Document … pting.html
and the user's guide.

Cheers,
Adrian Pop/

Re: OMPython

Thank you Adrian,
I think val() only working with .mat result.  For .csv not implemented yet.

Oki

Re: OMPython

Adrian,
Also i am looking for OMShell it is very usable.
Does OMShell have   for next / while wend  type of controls?

Oki

Re: OMPython

Yes, but you need to write it on a single line, for example:

j:=0; for i in 1:3 loop j:=j+i; end for; j

Re: OMPython

Thank you sjoelund,

So, i want to compare two different parameters inside loop.
I try something like this but it is not working,

for i in 1007:1016 loop i:=i+1; val(Meter1.v,i)-val(Meter2.v) ; end for;

Is there any  documents explain more control about   for, loop, if, while, wend e.t.c.

Oki

Re: OMPython

Hi again,
I found pdf file. But,

for i in 1:18 loop val(Meter.v,i); end for

this code suppose to be  print val(Meter.v,i) value but not,

What's wrong this code?

Oki




There are 0 guests and 0 other users also viewing this topic