| ParametricJob | R Documentation |
ParametricJob class provides a prototype of conducting parametric analysis
of EnergyPlus simulations.
param_job() takes an IDF and EPW as input and returns a ParametricJob.
For details on ParametricJob, please see ParametricJob class.
param_job(idf, epw)
idf |
A path to EnergyPlus IDF or IMF file or an |
epw |
A path to EnergyPlus EPW file or an |
Basically, it is a collection of multiple EplusJob objects. However, the
model is first parsed and the Idf object is stored internally, instead of
storing only the path of Idf like in EplusJob class. Also, an object in
Output:SQLite with Option Type value of SimpleAndTabular will be
automatically created if it does not exists, like Idf class does.
A ParametricJob object.
eplusr::EplusGroupJob -> ParametricJob
eplusr::EplusGroupJob$errors()eplusr::EplusGroupJob$kill()eplusr::EplusGroupJob$list_files()eplusr::EplusGroupJob$list_table()eplusr::EplusGroupJob$locate_output()eplusr::EplusGroupJob$output_dir()eplusr::EplusGroupJob$read_mdd()eplusr::EplusGroupJob$read_rdd()eplusr::EplusGroupJob$read_table()eplusr::EplusGroupJob$report_data()eplusr::EplusGroupJob$report_data_dict()eplusr::EplusGroupJob$status()eplusr::EplusGroupJob$tabular_data()new()Create a ParametricJob object
ParametricJob$new(idf, epw)
idfPath to EnergyPlus IDF file or an Idf object.
epwPath to EnergyPlus EPW file or an Epw object. epw can
also be NULL which will force design-day-only simulation
when $run() method is called. Note this needs at least one
Sizing:DesignDay object exists in the Idf.
A ParametricJob object.
\dontrun{
if (is_avail_eplus("8.8")) {
path_idf <- path_eplus_example("8.8", "5Zone_Transformer.idf")
path_epw <- path_eplus_weather("8.8", "USA_CA_San.Francisco.Intl.AP.724940_TMY3.epw")
# create from an IDF and an EPW
param <- param_job(path_idf, path_epw)
param <- ParametricJob$new(path_idf, path_epw)
# create from an Idf and an Epw object
param_job(read_idf(path_idf), read_epw(path_epw))
}
}
version()Get the version of seed IDF
ParametricJob$version()
$version() returns the version of input seed Idf object.
A base::numeric_version() object.
\dontrun{
param$version()
}
seed()Get the seed Idf object
ParametricJob$seed()
$seed() returns the parsed input seed Idf object.
\dontrun{
param$seed()
}
weather()Get the Epw object
ParametricJob$weather()
$weather() returns the input Epw object. If no Epw is provided
when creating the ParametricJob object, NULL is returned.
\dontrun{
param$weather()
}
param()Set parameters for parametric simulations
ParametricJob$param(..., .names = NULL, .cross = FALSE)
...Lists of paramter definitions. Please see above on the syntax.
.namesA character vector of the parameter names. If NULL,
the parameter will be named in format param_X, where
X is the index of parameter. Default: NULL.
.crossIf TRUE, all combinations of parameter values will be
used to create models. If FALSE, each parameter should have
the same length of values. Default: FALSE.
$param() takes parameter definitions in list format, which is
similar to Idf$set() except that each field is not assigned
with a single value, but a vector of any length, indicating the
levels of each parameter.
Similar like the way of modifying object field values in Idf$set(), there are 3 different ways of defining a parameter in epluspar:
object = list(field = c(value1, value2, ...)): Where object is
a valid object ID or name. Note object ID should be denoted with
two periods .., e.g. ..10 indicates the object with ID 10, It
will set that specific field in that object as one parameter.
.(object, object) := list(field = c(value1, value2, ...)):
Simimar like above, but note the use of .() in the left hand
side. You can put multiple object ID or names in .(). It will
set the field of all specified objects as one parameter.
class := list(field = c(value1, value2, ...)): Note the use of
:= instead of =. The main difference is that, unlike =, the
left hand side of := should be a valid class name in current
Idf. It will set that field of all objects in specified
class as one parameter.
For example, the code block below defines 3 parameters:
Field Fan Total Efficiency in object named Supply Fan 1 in class
Fan:VariableVolume class, with 10 levels being 0.1 to 1.0 with a
0.1 step.
Field Thickness in all objects in class Material, with 10
levels being 0.01 to 0.1 m with a 0.1 m step.
Field Conductivity in all objects in class Material, with 10
levels being 0.1 to 1.0 W/m-K with a 0.1 W/m-K step.
param$param(
`Supply Fan 1` = list(Fan_Total_Efficiency = seq(0.1, 1.0, 0.1)),
Material := list(
Thickness = seq(0.01, 0.1, 0.1),
Conductivity = seq(0.1, 1.0, 0.1)
)
)
The modified ParametricJob object invisibly.
\dontrun{
param$param(
Material := .(
Thickness = seq(0.1, 1, length.out = 3),
Conductivity = seq(0.1, 0.6, length.out = 3)
),
"Supply Fan 1" = .(fan_total_efficiency = c(0.1, 0.5, 0.8))
)
# specify parameter values
param$param(
Material := .(
Thickness = seq(0.1, 1, length.out = 3),
Conductivity = seq(0.1, 0.6, length.out = 3)
),
"Supply Fan 1" = list(fan_total_efficiency = c(0.1, 0.5, 0.8)),
.names = c("thickness", "conduct", "fan_eff")
)
# each parameter should have the same length of values
try(
param$param(
Material := list(Thickness = c(0.1, 0.2)),
"Supply Fan 1" = list(fan_total_efficiency = c(0.1, 0.5, 0.8))
)
)
# use all combinations of parameters
param$param(
Material := list(
Thickness = seq(0.1, 1, length.out = 3),
Conductivity = seq(0.1, 0.6, length.out = 3)
),
"Supply Fan 1" = list(fan_total_efficiency = c(0.1, 0.5, 0.8)),
.cross = TRUE
)
}
apply_measure()Create parametric models
ParametricJob$apply_measure(measure, ..., .names = NULL)
measureA function that takes an Idf and other arguments as
input and returns an Idf object as output.
...Arguments except first Idf argument that are passed
to that measure.
.namesA character vector of the names of parametric Idfs.
If NULL, the new Idfs will be named in format
measure_name + number.
$apply_measure() allows to apply a measure to an Idf and creates
parametric models for analysis. Basically, a measure is just a
function that takes an Idf object and other arguements as input, and
returns a modified Idf object as output. Use ... to supply
different arguments, except for the first Idf argument, to that
measure. Under the hook, base::mapply() is used to create multiple
Idfs according to the input values.
The modified ParametricJob object itself, invisibly.
\dontrun{
# create a measure to change the orientation of the building
rotate_building <- function(idf, degree = 0L) {
if (!idf$is_valid_class("Building")) {
stop("Input model does not have a Building object")
}
if (degree > 360 || degree < -360 ) {
stop("Input degree should in range [-360, 360]")
}
cur <- idf$Building$North_Axis
new <- cur + degree
if (new > 360) {
new <- new %% 360
warning("Calculated new north axis is greater than 360. ",
"Final north axis will be ", new
)
} else if (new < -360) {
new <- new %% -360
warning("Calculated new north axis is smaller than -360. ",
"Final north axis will be ", new
)
}
idf$Building$North_Axis <- new
idf
}
# apply measure
# this will create 12 models
param$apply_measure(rotate_building, degree = seq(30, 360, 30))
# apply measure with new names specified
param$apply_measure(rotate_building, degree = seq(30, 360, 30),
.names = paste0("rotate_", seq(30, 360, 30))
)
}
models()Get created parametric Idf objects
ParametricJob$models(names = NULL)
namesA character vector of new names for parametric models.
If a single string, it will be used as a prefix and all models
will be named in pattern names_X, where X is the model
index. If NULL, existing parametric models are directly
returned. Default: NULL.
$models() returns a list of parametric models generated using input
Idf object and
$apply_measure()
method. Model names are assigned in the same way as the .names
arugment in
$apply_measure().
If no measure has been applied, NULL is returned. Note that it is
not recommended to conduct any extra modification on those models
directly, after they were created using
$apply_measure(),
as this may lead to an un-reproducible process. A warning message
will be issued if any of those models has been modified when running
simulations.
\dontrun{
param$models()
}
cases()Get a summary of parametric models and parameters
ParametricJob$cases()
$cases() returns a data.table giving a
summary of parametric models and parameter values.
The returned data.table has the following columns:
index: Integer type. The indices of parameter models
case: Character type. The names of parameter models
Parameters: Type depends on the parameter values. Each parameter
stands in a separate column. For parametric models created using
ParametricJob$param(), the column names will be the same as what
you specified in .names. For the case of
ParametricJob$apply_measure(), this will be the argument names of
the measure functions.
If no parametric models have been created, NULL is
returned. Otherwise, a data.table.
\dontrun{
param$cases()
}
save()Save parametric models
ParametricJob$save(dir = NULL, separate = TRUE, copy_external = FALSE)
dirThe parent output directory for models to be saved. If
NULL, the directory of the seed model will be used. Default:
NULL.
separateIf TRUE, all models are saved in a separate folder
with each model's name under specified directory. If FALSE,
all models are saved in the specified directory. Default:
TRUE.
copy_externalOnly applicable when separate is TRUE. If
TRUE, the external files that every Idf object depends on
will also be copied into the saving directory. The values of
file paths in the Idf will be changed automatically.
$save() saves all parametric models in specified folder. An error
will be issued if no measure has been applied.
A data.table::data.table() with two columns:
model: The path of saved parametric model files.
weather: The path of saved weather files.
\dontrun{
# save all parametric models with each model in a separate folder
param$save(tempdir())
# save all parametric models with all models in the same folder
param$save(tempdir(), separate = FALSE)
}
run()Run parametric simulations
ParametricJob$run( dir = NULL, wait = TRUE, force = FALSE, copy_external = FALSE, echo = wait, separate = TRUE, readvars = TRUE )
dirThe parent output directory for specified simulations.
Outputs of each simulation are placed in a separate folder
under the parent directory. If NULL, the directory of the
seed model will be used. Default: NULL.
waitIf TRUE, R will hang on and wait all EnergyPlus
simulations finish. If FALSE, all EnergyPlus simulations are
run in the background. Default: TRUE.
forceOnly applicable when the last simulation runs with
wait equals to FALSE and is still running. If TRUE,
current running job is forced to stop and a new one will
start. Default: FALSE.
copy_externalIf TRUE, the external files that current Idf
object depends on will also be copied into the simulation
output directory. The values of file paths in the Idf will be
changed automatically. Currently, only Schedule:File class
is supported. This ensures that the output directory will
have all files needed for the model to run. Default is
FALSE.
echoOnly applicable when wait is TRUE. Whether to
simulation status. Default: same as wait.
separateIf TRUE, all models are saved in a separate folder
with each model's name under dir when simulation. If FALSE,
all models are saved in dir when simulation. Default:
TRUE.
readvarsIf TRUE, the ReadVarESO post-processor will run
to generate CSV files from the ESO output. Since those CSV
files are never used when extracting simulation data in eplusr,
setting it to FALSE can speed up the simulation if there are
hundreds of output variables or meters. Default: TRUE.
$run() runs all parametric simulations in parallel. The number of
parallel EnergyPlus process can be controlled by
eplusr_option("num_parallel"). If wait is FALSE, then the job
will be run in the background. You can get updated job status by just
printing the ParametricJob object.
The ParametricJob object itself, invisibly.
\dontrun{
# run parametric simulations
param$run(wait = TRUE, echo = FALSE)
# run in background
param$run(wait = FALSE)
# get detailed job status by printing
print(param)
}
print()Print ParametricJob object
ParametricJob$print()
$print() shows the core information of this ParametricJob,
including the path of IDFs and EPWs and also the simulation job
status.
$print() is quite useful to get the simulation status, especially
when wait is FALSE in $run(). The job status will be updated
and printed whenever $print() is called.
The ParametricJob object itself, invisibly.
\dontrun{
param$print()
Sys.sleep(10)
param$print()
}
Hongyuan Jia
eplus_job() for creating an EnergyPlus single simulation job.
## ------------------------------------------------
## Method `ParametricJob$new`
## ------------------------------------------------
## Not run:
if (is_avail_eplus("8.8")) {
path_idf <- path_eplus_example("8.8", "5Zone_Transformer.idf")
path_epw <- path_eplus_weather("8.8", "USA_CA_San.Francisco.Intl.AP.724940_TMY3.epw")
# create from an IDF and an EPW
param <- param_job(path_idf, path_epw)
param <- ParametricJob$new(path_idf, path_epw)
# create from an Idf and an Epw object
param_job(read_idf(path_idf), read_epw(path_epw))
}
## End(Not run)
## ------------------------------------------------
## Method `ParametricJob$version`
## ------------------------------------------------
## Not run:
param$version()
## End(Not run)
## ------------------------------------------------
## Method `ParametricJob$seed`
## ------------------------------------------------
## Not run:
param$seed()
## End(Not run)
## ------------------------------------------------
## Method `ParametricJob$weather`
## ------------------------------------------------
## Not run:
param$weather()
## End(Not run)
## ------------------------------------------------
## Method `ParametricJob$param`
## ------------------------------------------------
## Not run:
param$param(
Material := .(
Thickness = seq(0.1, 1, length.out = 3),
Conductivity = seq(0.1, 0.6, length.out = 3)
),
"Supply Fan 1" = .(fan_total_efficiency = c(0.1, 0.5, 0.8))
)
# specify parameter values
param$param(
Material := .(
Thickness = seq(0.1, 1, length.out = 3),
Conductivity = seq(0.1, 0.6, length.out = 3)
),
"Supply Fan 1" = list(fan_total_efficiency = c(0.1, 0.5, 0.8)),
.names = c("thickness", "conduct", "fan_eff")
)
# each parameter should have the same length of values
try(
param$param(
Material := list(Thickness = c(0.1, 0.2)),
"Supply Fan 1" = list(fan_total_efficiency = c(0.1, 0.5, 0.8))
)
)
# use all combinations of parameters
param$param(
Material := list(
Thickness = seq(0.1, 1, length.out = 3),
Conductivity = seq(0.1, 0.6, length.out = 3)
),
"Supply Fan 1" = list(fan_total_efficiency = c(0.1, 0.5, 0.8)),
.cross = TRUE
)
## End(Not run)
## ------------------------------------------------
## Method `ParametricJob$apply_measure`
## ------------------------------------------------
## Not run:
# create a measure to change the orientation of the building
rotate_building <- function(idf, degree = 0L) {
if (!idf$is_valid_class("Building")) {
stop("Input model does not have a Building object")
}
if (degree > 360 || degree < -360 ) {
stop("Input degree should in range [-360, 360]")
}
cur <- idf$Building$North_Axis
new <- cur + degree
if (new > 360) {
new <- new %% 360
warning("Calculated new north axis is greater than 360. ",
"Final north axis will be ", new
)
} else if (new < -360) {
new <- new %% -360
warning("Calculated new north axis is smaller than -360. ",
"Final north axis will be ", new
)
}
idf$Building$North_Axis <- new
idf
}
# apply measure
# this will create 12 models
param$apply_measure(rotate_building, degree = seq(30, 360, 30))
# apply measure with new names specified
param$apply_measure(rotate_building, degree = seq(30, 360, 30),
.names = paste0("rotate_", seq(30, 360, 30))
)
## End(Not run)
## ------------------------------------------------
## Method `ParametricJob$models`
## ------------------------------------------------
## Not run:
param$models()
## End(Not run)
## ------------------------------------------------
## Method `ParametricJob$cases`
## ------------------------------------------------
## Not run:
param$cases()
## End(Not run)
## ------------------------------------------------
## Method `ParametricJob$save`
## ------------------------------------------------
## Not run:
# save all parametric models with each model in a separate folder
param$save(tempdir())
# save all parametric models with all models in the same folder
param$save(tempdir(), separate = FALSE)
## End(Not run)
## ------------------------------------------------
## Method `ParametricJob$run`
## ------------------------------------------------
## Not run:
# run parametric simulations
param$run(wait = TRUE, echo = FALSE)
# run in background
param$run(wait = FALSE)
# get detailed job status by printing
print(param)
## End(Not run)
## ------------------------------------------------
## Method `ParametricJob$print`
## ------------------------------------------------
## Not run:
param$print()
Sys.sleep(10)
param$print()
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.