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

export results in csv using OMPython

export results in csv using OMPython

omc = OMCSessionZMQ()
mod=ModelicaSystem("D:/FRND/Open_Modelica/_dev/Mar/" + "HP.mo","HP.Systems.SysHead")
#mod.buildModel()
mod.setParameters(["headl.UCfile=D:/FRND/Open_Modelica/_dev/Mar/Usecases/Stat_TA_Combi.txt"])
h = mod.getParameters()
r = h['headl.UCfile']
print(r)
e = mod.buildModel()
mod.simulate(resultfile="tmp.csv") #this returns mat format output in csv file.
But I want to have the CSV file output. Like how it gets exported from software. Also is there a way to save the parameter changed model .


Edited by: Thamizh - Dec-28-21 06:13:00

Re: export results in csv using OMPython

You can set "outputFormat" while calling simulate.

Here is a complete example:

Code:


>>> from OMPython import OMCSessionZMQ
>>> omc = OMCSessionZMQ()
>>> omc.sendExpression("getVersion()")
>>> omc.sendExpression("loadModel(Modelica)")
>>> omc.sendExpression("simulate(Modelica.Blocks.Examples.PID_Controller, outputFormat=\"csv\")")

Re: export results in csv using OMPython

Thanks for the answer.

But the answer which you shared is using OMCSession method. I'm looking for Modelica system model approach.
i.e. mod.simulate(); method. Because I'm setting new parameters to the declared variable.so after declaring the variable I want simulate the model and store the output in CSV file. So, Kindly show me how to save to output of Modelica system in CSV format or Show me how to set new parameters for declared variables in omc.sendExpression method that will be reallly helpful.Thanks.

Re: export results in csv using OMPython

I guess we would need to implement that functionality as I don't think we have it currently. Should be easy to add I think.

Re: export results in csv using OMPython

adrpo wrote:


I guess we would need to implement that functionality as I don't think we have it currently. Should be easy to add I think.

Hi, Can you help me on changing the parameters using omc.sendExpression(). That will be helpful

Re: export results in csv using OMPython

I answered your question here, with some more info:
https://stackoverflow.com/questions/705 … -interface

Basically this is what you want:

Code:


loadFile("HePackage.mo"); getErrorString();
list(HePackage.Systems.Syslam_Q5); getErrorString();
setElementModifierValue(HePackage.Systems.Syslam_Q5, hlam.UCfile, $Code(="C:/some/other/file.txt")); getErrorString();
setElementModifierValue(HePackage.Systems.Syslam_Q5, hlam.A_HS_mod1, $Code(=1.0)); getErrorString();
setElementModifierValue(HePackage.Systems.Syslam_Q5, hlam.CSize_flag, $Code(=true)); getErrorString();
setElementModifierValue(HePackage.Systems.Syslam_Q5, hlam.A_HS_mod2, $Code(=2.0)); getErrorString();
setElementModifierValue(HePackage.Systems.Syslam_Q5, hlam.A_HS_mod3, $Code(=3.0)); getErrorString();
setElementModifierValue(HePackage.Systems.Syslam_Q5, hlam.A_HS_mod4, $Code(=4.0)); getErrorString();
list(HePackage.Systems.Syslam_Q5); getErrorString();

There are 0 guests and 0 other users also viewing this topic
You are here: