Generate,modify and save the xml file for co-simualtion between external program (R,python or C/C++) and EnergyPlus through the BCVTB

CosimR provides the minimum implementation for co-simulation between external program (R,python or C/C++) and EnergyPlus through the SystemCommand Acotr of BCVTB. CosimR can help you to generate(copy), modify and save a xml file, which will be used in the co-simulation. Meanwhile, CosimR also provides a simple function to run the co-simulation through command line of BCVTB.

Installation

You can install the development version of CosimR from Github by:

devtools::install_github('jywang2016/CosimR')

Features

Done:

  • Generate,modify and save BCVTB xml file.
  • Run BCVTB co-simuation based on command line.

Plan:

  • Generate variables.cfg automatically.
  • Check your IDF external interface with the corresponding parameters in xml file.

As for more diffcult operations, you need adjust your IDF and external scripts according to your needs.

Usage

The flowchart:


         Step1:Copy                    Step2:Modify         Step3:save/write            Step4: run
xml file =========>>> '.../CosimR.xml' =========>>>  xmlroot =========>>> '.../new.xml' =========>>> result
         copy_xml()                    modify_xml()           write_xml()               run_Cosim()

reproduce the schedule example

We need prepare some files for co-simulation. All files have been placed in the package. Therefore, just copy them to your target path.

Note: All the file.copy operations are not necessary for co-simulation if you already have your own idf, cfg, R or python script,and so on. These copy is just for the reproduction of schedule example which is provided in BCVTB.

library(CosimR)

Step1: Copy the xml

copy_xml(xmlpath = xmlpath)
## CosimR.xml is copied to D:/bcvtb/examples/CosimRtest successfully!

Step2: Modify the xml

## 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: Rscript 
## programArgs: "D:/bcvtb/examples/CosimRtest/R/Cosim.R $input $time $iteration" 
## workingDir: D:/bcvtb/examples/CosimRtest/R 
## simulationLog: D:/bcvtb/examples/CosimRtest/R/simulation.log
## ---------------- Modification End ----------------

The Cosim.R is also included in the CosimR package.

file.copy(from = system.file("extdata/Cosim.R", package = "CosimR"),
          to = paste0(xmlpath,'/R'),
          overwrite = TRUE)

Step3: write(save) your xml.file

## new.xml is written successfully!

Now, you can operate the new.xml by BCVTB.

Step4: run co-simulation (Optional)

## Co-simulation ends. You can check the results inD:/bcvtb/examples/CosimRtest

result

Results gif

Results gif

Speed

Run co-simulation for one-day in my windows 10 x64 system:

exe(compiled by C++, 5.X secs) >  python(10.x secs) > R(28.x secs).

Calling Rscript by SystemCommand spends much more time than python.

Author

Jiangyu Wang

School of Energy and Power Engineering, Huazhong University of Science and Technology