python中Eppy的使用(Eppy Tutorial)
写在前面的话,在网页上搜了两天,似乎没有太多关于Eppy的使用,所以在研究过程中就做下笔记,与大家分享
Energy Plus软件安装链接:https://energyplus.net/downloads
注意:安装过程中不能断网,不然会出现 “下载失败-需要授权” ,出现的话重新下载即可
Eppy
Eppy is a scripting language for E+ idf files, and E+ output files. Eppy is written in the programming language Python.As a result it takes full advantage of the rich data structure and idioms that are avaliable in python.
eppy是energyplus idf文件和energyplus输出文件的脚本语言。eppy是用python编程语言编写的。因此,它充分利用了python中可用的丰富的数据结构和习惯用法。
●安装eppy包
pip install eppy
●配置运行环境
import sys
pathnameto_eppy = 'c:/EnergyPlusV22-2-0' #这里填写你自己安装软件的位置
sys.path.append(pathnameto_eppy)
●导入需要用到的库
from eppy import modeleditor
from eppy.modeleditor import IDF
导入模型的.idd(固定框架,参数)和.idf(模型数据)文件
👇
学习过EnergyPlus课程小伙伴应该记得这个页面,Eppy主要是用来处理.idf文件的,idf文件就是输入的模型数据
●指定文件路径
#根据自己实际的文件路径填写
#.idd文件跟随软件版本号,为固定文件
#.idf是输入的模型数据文件,选择你要计算的建筑模型文件
iddfile = "c:/EnergyPlusV22-2-0/PreProcess/IDFVersionUpdater/V22-2-0-Energy+.idd"
fname1 = "c:/EnergyPlusV22-2-0/ExampleFiles/ZoneCoupledGroundHTSlabInGrade.idf"
IDF.setiddname(iddfile)
idf1 = IDF(fname1)
●查看模型数据(与用记事本打开ZoneCoupledGroundHTSlabInGrade.idf看到的内容一致)
#函数 .printidf()
idf1.printidf()
●查看其中某个类型数据(建筑,材料,位置等)
#函数 .idfobjects['']
idf1.idfobjects['BUILDING']
#
building = idf1.idfobjects['BUILDING'][0]
building.Name
●可直接对BUILDING中的NAME进行更改
building.Name = "house"
print(building.Name)
但需要执行 idf1.save() 才会对修改进行保存,
执行 idf1.saveas(‘something.idf’) 对文件进行另存为
建筑名称已被修改
添加参数
以Materials为例,
使用函数 .idfobjects[“Materials”] 读取.idf文件中Materials的信息,
使用函数.newidfobject(“MATERIAL”)添加新的Materials 材料信息,
在新增时调用了.addobject函数输入所有默认值,并将其他值留空,Out [7]看到的样子.
materials = idf1.idfobjects["MATERIAL"]
len(materials)
idf1.newidfobject("MATERIAL")
len(materials)
填入Materials的参数
materials[-1].Name = 'Peanut Butter'
materials[-1].Roughness = 'MediumSmooth'
materials[-1].Thickness = 0.03
materials[-1].Conductivity = 0.16
materials[-1].Density = 600
materials[-1].Specific_Heat = 1500
print(materials[-1])
☆与python中的增删改一样.可以使用append(),remove(),**pop()**对参数进行修改
eppy 中的几何函数
● 表面方位角 surface azimuth
● 表面倾斜 surface tilt
● 表面积 surface area
[直接有函数计算,无需自己手动计算]
from eppy import modeleditor
from eppy.modeleditor import IDF
iddfile = "c:/EnergyPlusV22-2-0/PreProcess/IDFVersionUpdater/V22-2-0-Energy+.idd"
try:
IDF.setiddname(iddfile)
except modeleditor.IDDAlreadySetError as e:
pass
fname1 = "c:/EnergyPlusV22-2-0/ExampleFiles/5ZoneSupRetPlenRAB.idf" #此处更换了.idf文件
idf1 = IDF(fname1)
surfaces = idf1.idfobjects['BUILDINGSURFACE:DETAILED']
asurface = surfaces[0]
asurface
print("surface azimuth =", asurface.azimuth, "degrees")
print("surface tilt =", asurface.tilt, "degrees")
print("surface area =", asurface.area, "m2")
纯属个人学习笔记,共享学习,有误请指教,谢谢~
本文参考:https://eppy.readthedocs.io/en/latest/Main_Tutorial.html