为Python添加dymola库
Dymola中集成了Python接口,在 <你的安装路径>\Modelica\Library\python_interface下,有一个Python库文件dymola.egg,很遗憾不能通过pip安装,只能手动添加环境变量,推荐使用最常用的窗口形式添加,具体见下列步骤
在Python中直接调用Dymola引擎进行计算
import os
# Import dymola package
from dymola.dymola_interface import DymolaInterface
# Start the interface
dymola = DymolaInterface()
# Location of your local library clone, my library name is DES
dir_DES ="D:/Distributed Energy Systems"
# Location where to store the results
dir_result ="D:/Distributed Energy Systems/DES_result"
# Open Library
dymola.openModel(path=os.path.join(dir_DES, 'DES.mo'))
# Translate any model you'd like to simulate
dymola.translateModel('DES.CCHPPlants.PlantTemplates.EngineSystemTemplates.EngineTwoAC_mixedTank')
# Simulate the model
output = dymola.simulateExtendedModel(
problem='DES.CCHPPlants.PlantTemplates.EngineSystemTemplates.EngineTwoAC_mixedTank',
startTime=0.0,
stopTime=10000,
outputInterval=500,
method="Dassl",
tolerance=0.0001,
resultFile=os.path.join(dir_result, 'demo_results'),
finalNames=['ICE-MIXEDTANK' ],
)
dymola.close()
软件版本 Python3.5,Dymola2019