Preprocessing API¶
Functions for expanding template and preprocessor objects before simulation.
EnergyPlus models may contain high-level template objects that must be expanded into their low-level equivalents before a simulation can run. Three preprocessors are supported:
| Function | Preprocessor | Objects handled |
|---|---|---|
expand_objects() |
ExpandObjects | HVACTemplate:* |
run_slab_preprocessor() |
Slab | GroundHeatTransfer:Slab:* |
run_basement_preprocessor() |
Basement | GroundHeatTransfer:Basement:* |
run_preprocessing() |
All of the above | Combined pipeline |
needs_ground_heat_preprocessing() |
— | Detection helper |
All functions return a new IDFDocument — the original model is never mutated.
If the model contains no objects for a given preprocessor, a copy is returned
immediately without invoking any external process.
Note
simulate() calls run_preprocessing() automatically when
expand_objects=True (the default) and the model contains ground
heat-transfer objects. Use the individual functions only when you need
to inspect or modify the preprocessed model before simulation.
expand_objects¶
idfkit.simulation.expand.expand_objects(model, *, energyplus=None, timeout=120.0)
¶
Run the EnergyPlus ExpandObjects preprocessor and return the expanded document.
ExpandObjects replaces HVACTemplate:* objects with their fully
specified low-level HVAC equivalents. The original model is not
mutated.
If the document contains no HVACTemplate:* objects a
copy is returned immediately without
invoking the preprocessor (no EnergyPlus installation required).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
IDFDocument
|
The EnergyPlus model to expand. |
required |
energyplus
|
EnergyPlusConfig | None
|
Pre-configured EnergyPlus installation. If |
None
|
timeout
|
float
|
Maximum time in seconds to wait for the preprocessor (default 120). |
120.0
|
Returns:
| Type | Description |
|---|---|
IDFDocument
|
A new IDFDocument containing the expanded |
IDFDocument
|
objects. |
Raises:
| Type | Description |
|---|---|
EnergyPlusNotFoundError
|
If no EnergyPlus installation (and therefore
no |
ExpandObjectsError
|
If the |
Source code in src/idfkit/simulation/expand.py
run_slab_preprocessor¶
idfkit.simulation.expand.run_slab_preprocessor(model, *, energyplus=None, weather=None, timeout=120.0)
¶
Run the Slab ground heat-transfer preprocessor and return the expanded document.
The workflow is:
ExpandObjectsextractsGroundHeatTransfer:Slab:*objects from the model intoGHTIn.idf.- The Slab preprocessor reads
GHTIn.idfand computes monthly ground surface temperatures, writingSLABSurfaceTemps.TXT. - The resulting temperature schedules are appended to the expanded IDF.
The original model is not mutated.
If the document contains no GroundHeatTransfer:Slab:* objects a
copy is returned immediately.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
IDFDocument
|
The EnergyPlus model containing |
required |
energyplus
|
EnergyPlusConfig | None
|
Pre-configured EnergyPlus installation. If |
None
|
weather
|
str | Path | None
|
Path to a weather file ( |
None
|
timeout
|
float
|
Maximum time in seconds for each subprocess invocation (default 120). |
120.0
|
Returns:
| Type | Description |
|---|---|
IDFDocument
|
A new IDFDocument with slab ground |
IDFDocument
|
temperatures appended. |
Raises:
| Type | Description |
|---|---|
EnergyPlusNotFoundError
|
If no EnergyPlus installation is found. |
ExpandObjectsError
|
If any preprocessor step fails. |
Source code in src/idfkit/simulation/expand.py
run_basement_preprocessor¶
idfkit.simulation.expand.run_basement_preprocessor(model, *, energyplus=None, weather=None, timeout=120.0)
¶
Run the Basement ground heat-transfer preprocessor and return the expanded document.
The workflow is:
ExpandObjectsextractsGroundHeatTransfer:Basement:*objects from the model intoBasementGHTIn.idf.- The Basement preprocessor reads
BasementGHTIn.idfand computes ground temperatures, writingEPObjects.TXT. - The resulting boundary conditions are appended to the expanded IDF.
The original model is not mutated.
If the document contains no GroundHeatTransfer:Basement:* objects a
copy is returned immediately.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
IDFDocument
|
The EnergyPlus model containing
|
required |
energyplus
|
EnergyPlusConfig | None
|
Pre-configured EnergyPlus installation. If |
None
|
weather
|
str | Path | None
|
Path to a weather file ( |
None
|
timeout
|
float
|
Maximum time in seconds for each subprocess invocation (default 120). |
120.0
|
Returns:
| Type | Description |
|---|---|
IDFDocument
|
A new IDFDocument with basement ground |
IDFDocument
|
temperatures appended. |
Raises:
| Type | Description |
|---|---|
EnergyPlusNotFoundError
|
If no EnergyPlus installation is found. |
ExpandObjectsError
|
If any preprocessor step fails. |
Source code in src/idfkit/simulation/expand.py
run_preprocessing¶
idfkit.simulation.expand.run_preprocessing(model, *, energyplus=None, weather=None, timeout=120.0)
¶
Run ExpandObjects and any required ground heat-transfer preprocessors.
This is a convenience function that runs all needed preprocessors in
a single call. It runs ExpandObjects once, then checks which
preprocessor input files were produced (GHTIn.idf and/or
BasementGHTIn.idf) and runs the corresponding Fortran solvers.
simulate calls this automatically
when the model contains ground heat-transfer objects and
expand_objects is True. Call it directly only when you need to
inspect or modify the preprocessed model before simulation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
IDFDocument
|
The EnergyPlus model to preprocess. |
required |
energyplus
|
EnergyPlusConfig | None
|
Pre-configured EnergyPlus installation. If |
None
|
weather
|
str | Path | None
|
Path to a weather file ( |
None
|
timeout
|
float
|
Maximum time in seconds for each subprocess invocation (default 120). |
120.0
|
Returns:
| Type | Description |
|---|---|
IDFDocument
|
A new IDFDocument with all |
IDFDocument
|
preprocessing applied. |
Raises:
| Type | Description |
|---|---|
EnergyPlusNotFoundError
|
If no EnergyPlus installation is found. |
ExpandObjectsError
|
If any preprocessor step fails. |
Source code in src/idfkit/simulation/expand.py
needs_ground_heat_preprocessing¶
idfkit.simulation.expand.needs_ground_heat_preprocessing(model)
¶
Return True if model contains ground heat-transfer objects.
Checks for GroundHeatTransfer:Slab:* and
GroundHeatTransfer:Basement:* objects that require the Slab or
Basement preprocessor before simulation.
This is used by simulate to decide whether to auto-run the preprocessing pipeline.
Source code in src/idfkit/simulation/expand.py
Error Handling¶
All three functions raise
ExpandObjectsError
on failure. The exception carries structured fields for programmatic access:
from idfkit.exceptions import ExpandObjectsError
try:
expanded = expand_objects(model)
except ExpandObjectsError as e:
print(e.preprocessor) # "ExpandObjects", "Slab", or "Basement"
print(e.exit_code) # Process exit code, or None for timeout/OS error
print(e.stderr) # Captured stderr (truncated to 500 chars)
Error modes¶
| Failure | preprocessor |
exit_code |
stderr |
|---|---|---|---|
| Executable not found | Name | None |
None |
| Process timeout | Name | None |
Partial output |
| OS error (permissions) | Name | None |
None |
| Process crash (SIGSEGV) | Name | 139 |
Signal info |
| Empty output (solver failure) | Name | 0 |
Solver output |
| Fatal PreprocessorMessage | Name | 0 |
Error message |
| Missing output file | Name | Exit code | Process stderr |