Opened 5 years ago
Last modified 5 years ago
#5890 reopened defect
buildModel() fails with 'ModelicaSystem' object has no attribute 'buildModel'
Reported by: | Michael Wetter | Owned by: | Alachew Mengist |
---|---|---|---|
Priority: | high | Milestone: | Future |
Component: | OMPython | Version: | v1.16.0-dev |
Keywords: | Cc: |
Description
Hi
I like to use a Modelica block, set its parameters and simulate it while assigning its inputs from a csv file. Running the commands below, which are from https://www.openmodelica.org/doc/OpenModelicaUsersGuide/latest/ompython.html#enhanced-ompython-features, gives the shown error.
>>> from OMPython import OMCSessionZMQ >>> omc = OMCSessionZMQ() 2020-03-12 15:58:29,708 - OMPython - INFO - OMC Server is up and running at file:////tmp/openmodelica.mwetter.port.b2a371262e6c4fb182a2e58d04ac0dee pid=49441 >>> model_path=omc.sendExpression("getInstallationDirectoryPath()") + "/share/doc/omc/testmodels/" >>> from OMPython import ModelicaSystem >>> mod=ModelicaSystem(model_path + "BouncingBall.mo","BouncingBall") 2020-03-12 15:59:14,981 - OMPython - INFO - OMC Server is up and running at file:////tmp/openmodelica.mwetter.port.f6bfd8fa2b0044b5a13ab273c9613b4c pid=49446 >>> mod.buildModel() Traceback (most recent call last): File "<stdin>", line 1, in <module> AttributeError: 'ModelicaSystem' object has no attribute 'buildModel'
Is such a functionality still supported? If not, is there a way to realize this in omc? I tried
import shutil import os from OMPython import OMCSessionZMQ model="Buildings.Controls.OBC.ASHRAE.G36_PR1.AHUs.SingleZone.VAV.SetPoints.Supply" parameters="(yHeaMax=0.7, yMin=0.3, TSupSetMax=303.15, TSupSetMin=289.15)" omc = OMCSessionZMQ() omc.sendExpression("loadModel(Buildings)") omc.sendExpression("simulate({}, startTime=0, stopTime=3600, simflags=\"-csvInput reference_input.csv\", outputFormat=\"csv\")".format(model))
with reference_input.csv
time, uHea, uCoo, TZonSet, TZon, TOut, uFan 0, 1, 1, 293.15, 293.15, 283.15, 0 3600, 1, 1, 293.15, 293.15, 283.15, 0
but uHea
is always zero. Adding a terminating comma as proposed in https://openmodelica.org/forum/default-topic/2627-csvinput-usage-and-input-file-format#p8935 won't help.
Moreover, I have not found a documentation for how to set parameters in the block Supply
, hence the attempt with ModelicaSystem
which appears to provide this functionality
Attachments (3)
Change History (9)
by , 5 years ago
Attachment: | reference_input.csv added |
---|
by , 5 years ago
Attachment: | simulateCDL.py added |
---|
by , 5 years ago
Attachment: | simulateCDL.sh added |
---|
comment:1 by , 5 years ago
comment:2 by , 5 years ago
How did you installed OMPython? Install it with:
python -m pip install -U https://github.com/OpenModelica/OMPython/archive/master.zip
and you will have mod.buildModel()
method.
I will check the other stuff now.
comment:3 by , 5 years ago
I must have had an old version of OMPython installed. I don't recall having it installed with pip, so it may have come from a deb package.
Running your pip
command solves the problem and the example now works with version
$ python3 -m pip freeze | grep OM OMPython==3.1.2
Thanks.
comment:4 by , 5 years ago
Resolution: | → worksforme |
---|---|
Status: | new → closed |
comment:5 by , 5 years ago
Resolution: | worksforme |
---|---|
Status: | closed → reopened |
comment:6 by , 5 years ago
Don't close this yet as the reading of reference_input.csv
doesn't work properly it seems, uHea
is zero during simulation and should be one. Strangely the other ones are fine as far as I could tell so it seems like a weird bug.
Also, I will open some ticket for some other usability issues:
- make it possible to use several override flags as the user cannot use it because OMPython does already
- support outputFormat for OMPython simulation command
Do you have an estimate for when this will be corrected? Please advise so I can plan implementing a possible work-around.