SkillAgentSearch skills...

Epluspar

Conduct parametric analysis on EnergyPlus models in R

Install / Use

/learn @hongyuanjia/Epluspar
About this skill

Quality Score

0/100

Supported Platforms

Universal

README

<!-- README.md is generated from README.Rmd. Please edit that file -->

epluspar

Conduct sensitivity analysis and Bayesian calibration of EnergyPlus models.

Travis-CI Build
Status CRAN_Status_Badge

Installation

Currently, epluspar is not on CRAN. You can install the development version from GitHub.

install.packages("epluspar", repos = "https://hongyuanjia.r-universe.dev")
<!-- TOC GFM --> <!-- /TOC -->

Sensitivity Analysis

Basic workflow

The basic workflow is basically:

  1. Adding parameters for sensitivity analysis using $param() or $apply_measure().
  2. Check parameter sampled values and generated parametric models using $samples() and $models() respectively.
  3. Run EnergyPlus simulations in parallel using $run().
  4. Gather EnergyPlus simulated data using $report_data() or $tabular_data().
  5. Evaluate parameter sensitivity using $evaluate().

Examples

Create a SensitivityJob object:

# use an example file from EnergyPlus v8.8 for demonstration here
path_idf <- file.path(eplusr::eplus_config(8.8)$dir, "ExampleFiles", "5Zone_Transformer.idf")
path_epw <- file.path(eplusr::eplus_config(8.8)$dir, "WeatherData", "USA_CA_San.Francisco.Intl.AP.724940_TMY3.epw")

# create a `SensitivityJob` class which inheris from eplusr::ParametricJob class
sen <- sensi_job(path_idf, path_epw)
#> Adding an object in class 'Output:SQLite' and setting its 'Option Type' to 'SimpleAndTabular' in order to create SQLite output file.
#> Moving all objects in class 'Output:Meter:MeterFileOnly' to 'Output:Meter' in order to use csv for data extraction.

Set sensitivity parameters using $param() or $apply_measure().

  • Using $param()
<!-- end list -->
# set parameter using similar syntax to `Idf$set()` in eplusr
sen$param(
    # For adding a single object field as parameter
    # Syntax: Object = list(Field = c(Min, Max, Levels))
    `Supply Fan 1` = list(Fan_Total_Efficiency = c(0.1, 1.0, 5)),

    # For adding a class field as parameter
    Material := list(
        Thickness = c(min = 0.01, max = 0.08, levels = 5),
        Conductivity = c(min = 0.01, max = 0.6, levels = 6)
    ),

    # use `.names` to give names to each parameter
    .names = c("efficiency", "thickness", "conductivity"),

    # See `r` and `grid_jump` in `sensitivity::morris`
    .r = 8, .grid_jump = 1
)
  • Using $apply_measure()
<!-- end list -->
# first define a "measure"
my_actions <- function (idf, efficiency, thickness, conducitivy) {
    idf$set(
        `Supply Fan 1` = list(Fan_Total_Efficiency = efficiency),
        Material := list(Thickness = thickness, Conductivity = conducitivy)
    )

    idf
}

# then apply that measure with parameter space definitions as function arguments
sen$apply_measure(my_actions,
    efficiency = c(0.1, 1.0, 5),
    thickness = c(0.01, 0.08, 5),
    conducitivy = c(0.1, 0.6, 6),
    .r = 8, .grid_jump = 1
)
#> -- EnergPlus Sensitivity Analysis Job ------------------------------------
#> * Seed: 'C:\Users\hongy\AppData\Local\EnergyPlusV8-8-0\ExampleFiles\5...
#> * Weather: 'C:\Users\hongy\AppData\Local\EnergyPlusV8-8-0\WeatherData...
#> * EnergyPlus Version: '8.8.0'
#> * EnergyPlus Path: 'C:\Users\hongy\AppData\Local\EnergyPlusV8-8-0'
#> Applied Measure: 'my_actions'
#> Parameters [3]
#> [1]: 'efficiency' [0.1, 1] (lvl: 5)
#> [2]: 'thickness' [0.01, 0.08] (lvl: 5)
#> [3]: 'conducitivy' [0.1, 0.6] (lvl: 6)
#> Parametric Models [32]: 
#> [01]: 'Case01.idf'
#> [02]: 'Case02.idf'
#> [03]: 'Case03.idf'
#> [04]: 'Case04.idf'
#> [05]: 'Case05.idf'
#> [06]: 'Case06.idf'
#> [07]: 'Case07.idf'
#> [08]: 'Case08.idf'
#> [09]: 'Case09.idf'
....

Get samples

sen$samples()
#>      case efficiency thickness conducitivy
#>     <int>      <num>     <num>       <num>
#>  1:     1      0.325    0.0275         0.4
#>  2:     2      0.100    0.0275         0.4
#>  3:     3      0.100    0.0100         0.4
#>  4:     4      0.100    0.0100         0.3
#>  5:     5      0.100    0.0625         0.3
#>  6:     6      0.325    0.0625         0.3
#>  7:     7      0.325    0.0800         0.3
#>  8:     8      0.325    0.0800         0.4
#>  9:     9      0.100    0.0800         0.3
#> 10:    10      0.325    0.0800         0.3
#> 11:    11      0.325    0.0800         0.2
#> 12:    12      0.325    0.0625         0.2
#> 13:    13      0.100    0.0450         0.2
#> 14:    14      0.325    0.0450         0.2
#> 15:    15      0.325    0.0450         0.1
#> 16:    16      0.325    0.0625         0.1
#> 17:    17      0.550    0.0100         0.5
#> 18:    18      0.775    0.0100         0.5
....

Run simulations and calculate statistic indicators

# run simulations in temporary directory
sen$run(dir = tempdir(), echo = FALSE)
#> ── EnergPlus Parametric Simulation Job ─────────────────────────────────────────
#> * Seed: '/home/hongyuanjia/.local/EnergyPlus-8-8-0/ExampleFiles/5Zone_Trans...
#> * Weather: '/home/hongyuanjia/.local/EnergyPlus-8-8-0/WeatherData/USA_CA_Sa...
#> -- EnergPlus Sensitivity Analysis Job ------------------------------------
#> * Seed: 'C:\Users\hongy\AppData\Local\EnergyPlusV8-8-0\ExampleFiles\5...
#> * Weather: 'C:\Users\hongy\AppData\Local\EnergyPlusV8-8-0\WeatherData...
#> * EnergyPlus Version: '8.8.0'
#> * EnergyPlus Path: 'C:\Users\hongy\AppData\Local\EnergyPlusV8-8-0'
#> Applied Measure: 'my_actions'
#> Parameters [3]
#> [1]: 'efficiency' [0.1, 1] (lvl: 5)
#> [2]: 'thickness' [0.01, 0.08] (lvl: 5)
#> [3]: 'conducitivy' [0.1, 0.6] (lvl: 6)
#> Parametric Models [32]: 
#> [01]: 'Case01.idf' <-- SUCCEEDED
#> [02]: 'Case02.idf' <-- SUCCEEDED
#> [03]: 'Case03.idf' <-- SUCCEEDED
#> [04]: 'Case04.idf' <-- SUCCEEDED
#> [05]: 'Case05.idf' <-- SUCCEEDED
#> [06]: 'Case06.idf' <-- SUCCEEDED
#> [07]: 'Case07.idf' <-- SUCCEEDED
#> [08]: 'Case08.idf' <-- SUCCEEDED
#> [09]: 'Case09.idf' <-- SUCCEEDED
....

# extract output
# here is just am example
eng <- sen$tabular_data(table_name = "site and source energy",
    column_name = "energy per total building area",
    row_name = "total site energy")[, as.numeric(value)]

# calculate sensitivity
(result <- sen$evaluate(eng))
#> 
#> Call:
#> sensitivity::morris(model = NULL, factors = l$param$param_name,     r = .r, design = list(type = "oat", levels = l$param$levels,         grid.jump = .grid_jump), binf = l$param$min, bsup = l$param$max,     scale = .scale)
#> 
#> Model runs: 32 
#>                   mu mu.star      sigma
#> efficiency  -0.88000 0.88000 0.80796040
#> thickness   -0.51000 0.51000 0.36893670
#> conducitivy  0.16875 0.16875 0.09613049

# extract data
attr(result, "data")
#>    index        name       mu mu.star      sigma
#>    <int>      <char>    <num>   <num>      <num>
#> 1:     1  efficiency -0.88000 0.88000 0.80796040
#> 2:     2   thickness -0.51000 0.51000 0.36893670
#> 3:     3 conducitivy  0.16875 0.16875 0.09613049

Plot

# plot
plot(result)

<!-- -->

Bayesian Calibration

Basic workflow

  1. Setting input and output variables using $input() and $output() respectively. Input variables should be variables listed in RDD while output variables should be variables listed in RDD and MDD.
  2. Adding parameters to calibrate using $param() or $apply_measure().
  3. Check parameter sampled values and generated parametric models using $samples() and $models() respectively.
  4. Run EnergyPlus simulations in parallel using $eplus_run().
  5. Gather simulated data of input and output parameters using $data_sim().
  6. Specify field measured data of input and output parameters using $data_field().
  7. Specify field measured data of input and output parameters using $data_field().
  8. Specify input data for Stan for Bayesian calibration using $data_bc().
  9. Run bayesian calibration and get predictions using stan using $stan_run().

Examples

Create a BayesCalibJob object:

# use an example file from EnergyPlus v8.8 for demonstration here
path_idf <- file.path(eplusr::eplus_config(8.8)$dir, "ExampleFiles", "RefBldgLargeOfficeNew2004_Chicago.idf")
path_epw <- file.path(eplusr::eplus_config(8.8)$dir, "WeatherData", "USA_CA_San.Francisco.Intl.AP.724940_TMY3.epw")

# create a `SensitivityJob` class which inherits from eplusr::ParametricJob class
bc <- bayes_job(path_idf, path_epw)

Get RDD and MDD

$read_rdd() and $read_mdd() can be used to get RDD and MDD for current seed model.

(rdd <- bc$read_rdd())
#> Initializing RDD...
#> Initializing RDD... [SUCCESSFUL]
#> == EnergyPlus Report Data Dictionary File ================================
#>   * EnergyPlus version: 8.8.0 (7c3bbe4830)
#>   * Simulation started: 2020-09-10 18:55:00
#> 
#
View on GitHub
GitHub Stars9
CategoryDevelopment
Updated1y ago
Forks0

Languages

R

Security Score

60/100

Audited on Jul 25, 2024

No findings