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
  • Index
  • » Users
  • » Thamizh
  • » Profile



Feb-09-22 08:06:52
i'm creating a .mos script with python for the modelica model

package HePackage

package Systems

model Syslam_Q5
  HePackage.Components.Hlam hlam(
         A_HS_mod1 =0.0786
         A_HS_mod2 = {0.0914,3.01,3.01,3.01,1.38,1.38,1.62,1.62,1.62}
         A_HS_mod3 = {0.0223,3.01,3.01,3.01,1.38,1.38,1.62,1.62,1.62}
         A_HS_mod4 = {0.0245,3.01,3.01,3.01,1.38,1.38,1.62,1.62,1.62});
end Syslam_Q5;

end Systems;

package Components
model Hlam
   parameter String UCfile = "";
   parameter Real A_HS_mod1 = 1.0
   parameter Real A_HS_mod2 = {1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,0.0}
   parameter Real A_HS_mod3 = {1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,0.0}
   parameter Real A_HS_mod4 = {0.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0}
   parameter Boolean CSize_flag = false;
end Hlam;
end Components;

end HePackage;

while creating .mos file for this modelica model with python i'm able to do it for single value.
but when I do it for multiple values i'm getting error as "failed to build model package".
File : modifiers.mos

loadFile(""); getErrorString();
list(HePackage.Systems.Syslam_Q5); 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,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0})); getErrorString(); #This cause failure during model building
setElementModifierValue(HePackage.Systems.Syslam_Q5, hlam.A_HS_mod3, $Code(={3.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0})); getErrorString(); #This cause failure during model building
setElementModifierValue(HePackage.Systems.Syslam_Q5, hlam.A_HS_mod4, $Code(={4.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0})); getErrorString(); #This cause failure during model building
list(HePackage.Systems.Syslam_Q5); getErrorString();

How to create a .mos file which takes input multiple values for sngle variable ?

Dec-29-21 06:31:23
I'm using OMPython to test modelica model, Is there a way to save results in Csv format

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

Dec-28-21 13:29:19
I'm using OMPython to test modelica model, Is there a way to save results in Csv format

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 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.

Dec-28-21 09:06:32
How to change parameters of a modelica model in Python CLI interface

I want to edit modelica model parameters in Python CLI interface, But don't know how to find the correct method to make it.

Modelica model code :

model Syslam_Q5
  HePackage.Components.Hlam hlam(
         A_HS_mod1 = 0.0786,
         A_HS_mod2 = 0.0914,
         A_HS_mod3 = 0.0223,
         A_HS_mod4 = 0.0245)

Python code :

from OMPython import OMCSessionZMQ
omc = OMCSessionZMQ()
cmds = [
    #'removeElementModifiers(HePackage.Systems.Syslam_Q5, "component", false)',
    'setElementModifierValue(HePackage.Systems.Syslam_Q5, HePackage.Components.Hlam, hlam.UCfile = C:/Users/Pikachu/Docs/i_v2/H100.txt)',
    #'setParameterValue(HePackage.Systems.Syslam_Q5, hlam.UCfile, $Code(=C:/Users/Pikachu/Docs/i_v2/H100.txt))',
    'saveModel("", Example)',
for cmd in cmds:
    answer = omc.sendExpression(cmd)
    print(cmd, ':', answer)

In a folder i have around 10 text files, I want to run the modelica model for all the text files.
How to do that with Python interface.

Dec-28-21 05:26:35
I'm using OMPython to test modelica model, Is there a way to save results in Csv format

omc = OMCSessionZMQ()
mod=ModelicaSystem("D:/FRND/Open_Modelica/_dev/Mar/" + "","HP.Systems.SysHead")
h = mod.getParameters()
r = h['headl.UCfile']
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 .

Dec-27-21 07:07:57
I'm using OMPYthon interface to run and test my modelica model.I want to run the model for...

Using OMPython interface I'm able to edit the parameters of the modelica model using setParameters option.
But now after changing the parameters i want to save the model. How to do that in OMPython. Also I want save the results in .CSV format not in .MAT format.

omc = OMCSessionZMQ()
mod=ModelicaSystem("D:/FRND/Open_Modelica/_dev/Mar/" + "","HP.Systems.SysHeadl")
#after setting this parameter, Have to save the model.
h = mod.getParameters()
r = h['headlamp.UCfile']
mod.simulate(resultfile="tmout.csv") #this CSV file also contains the mat file output in csv format. But I want to have it like how it got exported in csv file via Openmodelica software

Oct-21-21 04:50:48
I'm trying to pass reference variable inside setParameters function but its throwing error.
Category: Programming

I'm using OMPython to connect with OMEdit. when I'm trying to change the parameters of modelica model using setParameters method, I'm facing bit difficulty with it.
if i use setParameters("Values = 10"), its working. But if i declare the value first with a reference variable , like k = 10 and then passing the reference value to setParameters("Values = k") its not working. Its directly taking k as value for setParameters. But i want to pass only the value of K to setParameters. How to make it?

Sep-27-21 03:25:52
Trying to setup a dynamic Simulation model
Category: Programming

I'm pretty new to modelica , I'm trying to setup and simulate a headlamp module with OpenModelica Connector. Trying to setup it as dynamic module. so It requires some datas for calculation, those were stored in SQL and Excel database. I tried to import datas from Excel using ExternData. But its not handy, Is there a way to import Data's from SQL using some queries or is there any other ways to import datas from Excel ? Open Modelica connector supports python Interface. So if I fetch the needed data from SQL database using Python and pass it to Open Modelica connector as a parameter will it work? or If i fetch the data from excel as dataframe, will I be still able to pass the data to OpenModelica connector as parameter? Explored Externdata library but its not handy or in other words I'm not getting comfort with it.  Thanks.

  • Index
  • » Users
  • » Thamizh
  • » Profile
You are here: