This document show how to specify the path of python script and conduct co-simulation with EnergyPlus .
"""
This python script is the example of CosimR to show how to do co-simulation with EnergyPlus
Package: CosimR
Github: https://github.com/jywang2016/CosimR
Author: Jiangyu Wang
Date: 11th Dec, 2018
Email: jywang_2016@hust.edu.cn
Reference: schedule example in BCVTB
"""
import re
import sys
string = sys.argv[1]
time = sys.argv[2]
iter = sys.argv[3]
m = re.findall(r"\d+\.?\d*",string)
tout = float(m[0])
# input const -----------------------
dayStart = 6*3600
nightStart = 16*3600
TCNight = 30
TCRooLow = 22
TCRooHig = 26
TCOutLow = 20
TCOutHig = 24
THDay = 20
THNight = 16
# temp set logic ----------------------
time = int(float(time))
ToutDif = tout - TCOutLow
TSetCooOn = TCRooLow + ToutDif * (TCRooHig - TCRooLow)/(TCOutHig - TCOutLow)
TCDay = max(TCRooLow,min(TCRooHig,TSetCooOn))
if time % 86400 > dayStart and time % 86400 < nightStart:
THSetPoi = THDay
TCSetPoi = TCDay
else:
THSetPoi = THNight
TCSetPoi = TCNight
strs = [str(THSetPoi),str(TCSetPoi),' ']
sys.stdout.write(','.join(strs))
Suppose the python code Cosim.py
will be placed into the python
folder under the xmlpath = 'D:/bcvtb/examples/CosimRtest'
.
Step1: generate the .xml file
## CosimR.xml is copied to D:/bcvtb/examples/CosimRtest successfully!
Step2: modify the .xml file
file.copy(from = system.file("extdata/Cosim.py", package = "CosimR"),
to = paste0(xmlpath,'/python'),
overwrite = TRUE)
## [1] TRUE
xmlroot<- modify_xml(xmlpath = xmlpath,
timeStep = 15*60,
beginTime = 3*24*3600,
endTime = 4*24*3600,
extractLength = 2,
idf = paste0(xmlpath,'/SmOffPSZ.idf'),
epw = 'D:/bcvtb/examples/ePlusWeather/USA_IL_Chicago-OHare.Intl.AP.725300_TMY3.epw',
outname = 'eplusout',
programname = 'python',
programArgs = 'Cosim.py',
workingDir = paste0(xmlpath,'/python'),
cpp = FALSE)
## Part1: Cosim time set modify >>>>>>>>>
## timeStep: 900 beginTime: 259200 endTime: 345600
## Part2: ArrayExtract actor pram.args modify >>>>>>>>>
## extractLength: 2 outputArrayLength: 2
## Part3: EnergyPlus Simulator pram.args modify >>>>>>>>>
## energyplus command: " -w D:/bcvtb/examples/ePlusWeather/USA_IL_Chicago-OHare.Intl.AP.725300_TMY3.epw -p eplusout -s C -x -m -r D:/bcvtb/examples/CosimRtest/SmOffPSZ.idf "
## Part4: SystemCommand pram.args modify >>>>>>>>>
## programname: python
## programArgs: "D:/bcvtb/examples/CosimRtest/python/Cosim.py $input $time $iteration"
## workingDir: D:/bcvtb/examples/CosimRtest/python
## simulationLog: D:/bcvtb/examples/CosimRtest/python/simulation.log
## ---------------- Modification End ----------------
Step3: save the .xml file
## new.xml is written successfully!
Step4: run the .xml file