Integrations¶
Optional adapters for coupling TMHP to building-energy simulators and co-simulation masters. These modules are intentionally kept out of the top-level package import path so the core package remains usable without the adapter-specific runtimes.
For usage-first guides, model boundaries, and simulator wiring, see EnergyPlus Python Plugin and FMI FMU export.
Install the FMI dependencies with the integrations extra:
uv sync --extra integrations --locked
The EnergyPlus adapter is different: pyenergyplus is supplied by an
EnergyPlus installation and is not a PyPI dependency.
Interoperability contracts¶
FMI co-simulation is exposed through separate FMI 2.0 and FMI 3.0 adapters.
FMI 2.0 uses PythonFMU; FMI 3.0 uses PythonFMU3. The generated FMUs are
tool-coupling artifacts: Python, TMHP, CoolProp, NumPy, and SciPy must be
available in the importing environment. The FMU model descriptions are validated
with FMPy in tests. The XML declares units for power, temperature, DHW draw, and
COP so importers can perform basic unit checks. The slaves refuse a step with
unusable input values (non-finite values, negative DHW draw, outdoor humidity
outside 0 to 1.1 other than the start value -1) with a discard, and an illegal
step argument (non-finite time, step size not finite and positive) with
fmi3Error under FMI 3.0 and a discard under FMI 2.0. A refused step leaves
the model state and every output unchanged and, with debug logging on,
logs the reason; see
Invalid importer inputs.
EnergyPlus coupling uses the Python Plugin DataExchange API. The adapter first
resolves and validates all handles, then reads only finite boundary values
before calling analyze_steady(). Invalid boundary data is reported through
issue_severe(), the plant actuator is driven to a safe off state, and the
plugin returns a non-zero status instead of silently computing with bad data.
Compressor electricity is exposed with explicit plugin-global units:
tmhp_E_cmp_J receives timestep energy in joules by multiplying cycle power
in watts by EnergyPlus’s fractional-hour system_time_step(), while optional
tmhp_E_cmp_W receives the instantaneous cycle power. Older IDFs that
declare only tmhp_E_cmp are still accepted; that legacy global is treated as
a joule sink.
Adapter package¶
Building-energy-simulation co-simulation adapters.
Optional subpackage — each adapter needs an extra dependency that the core
tmhp package does not require, so this package is not imported by
tmhp/__init__.py; import tmhp stays usable without those deps and only
from tmhp.integrations... import ... pulls them in.
Adapters depend only on the public seams of the heat-pump models
(AirSourceHeatPumpBoiler.step() / .analyze_steady()), never on private
helpers:
tmhp.integrations.fmu— FMI 2.0 FMU wrappingstep()(the dynamic kernel; the FMU owns the storage-tank state). Needspythonfmu.tmhp.integrations.fmu3— FMI 3.0 Co-Simulation FMU wrapping the samestep()seam. Needspythonfmu3.tmhp.integrations.energyplus_plugin— EnergyPlus Python Plugin surrogating the ASHPB as aPlantComponent:UserDefinedthroughanalyze_steady()(the steady-state seam; EnergyPlus owns theWaterHeater:Mixedtank state). Runs inside EnergyPlus’s embedded CPython, so it needs the bundledpyenergyplus(not pip-installable).
- class tmhp.integrations.TmhpAshpbSlave(**kwargs)[source]¶
Bases:
Fmi2SlaveASHPB single-timestep co-simulation kernel (FMI 2.0).
- Parameters:
kwargs (
Any)
- author = 'BET Lab'¶
- description = 'tmhp ASHPB one-dt co-simulation kernel (FMI 2.0)'¶
- class tmhp.integrations.TmhpAshpbFmi3Slave(**kwargs)[source]¶
Bases:
Fmi3SlaveASHPB single-timestep co-simulation kernel (FMI 3.0).
- Parameters:
kwargs (
Any)
- author = 'BET Lab'¶
- description = 'TMHP ASHPB one-dt co-simulation kernel (FMI 3.0)'¶
- to_xml(model_options=None)[source]¶
Build a static FMI 3.0 model description for PythonFMU3.
- Parameters:
model_options (
dict[str,str] |None)- Return type:
Element
- class tmhp.integrations.TmhpPlantInit[source]¶
Bases:
EnergyPlusPluginOne-shot sizing actuators so the plant loop dispatches load to the ASHPB.
Bind to the
PlantComponent:UserDefinedinitialization program-calling manager (E+ runs it once before plant sizing).
- class tmhp.integrations.TmhpPlantSurrogate[source]¶
Bases:
EnergyPlusPluginPer-call ASHPB driver: read loop inlet + outdoor, solve, actuate.
Bind to the
PlantComponent:UserDefinedsimulation program-calling manager. Exposes compressor electricity through the plugin globaltmhp_E_cmp_J(declare it inPythonPlugin:Variablesand meter it as summed joules).tmhp_E_cmp_Wcan be declared for averaged power output.
FMI 2.0 co-simulation¶
FMI 2.0 co-simulation FMU wrapping the tmhp ASHPB step() kernel.
The slave advances AirSourceHeatPumpBoiler one communication
step at a time through the public step() seam, so any FMI master (fmpy,
OMSimulator, Dymola, …) can drive the refrigerant-cycle-resolved heat-pump
model as a co-simulation component.
Build (PythonFMU CLI or API):
pythonfmu build -f src/tmhp/integrations/fmu.py <project_folder>
# or: FmuBuilder.build_FMU(".../fmu.py", dest="out/")
Run:
import fmpy
fmpy.simulate_fmu("TmhpAshpbSlave.fmu", ...)
Lead track is FMI 2.0 (co-simulation only): tmhp exposes no continuous
state derivatives, and 2.0 co-sim is the most broadly importable flavour.
Boundary outputs are sanitized to avoid non-finite numeric values, while
converged and failure_reason preserve step-level diagnostics for the
importing master.
Note
Native-wheel caveat (CoolProp/numpy/scipy): the FMU is a tool-coupling
artifact, not a hermetic binary — the importing environment must provide
tmhp and its native dependencies for the chosen (OS, arch, Python-ABI).
No save-state/rollback at this scope (single-pass co-sim only).
- class tmhp.integrations.fmu.TmhpAshpbSlave(**kwargs)[source]¶
Bases:
Fmi2SlaveASHPB single-timestep co-simulation kernel (FMI 2.0).
- Parameters:
kwargs (
Any)
- author = 'BET Lab'¶
- description = 'tmhp ASHPB one-dt co-simulation kernel (FMI 2.0)'¶
FMI 3.0 co-simulation¶
FMI 3.0 co-simulation FMU wrapping the TMHP ASHPB step() kernel.
This adapter mirrors tmhp.integrations.fmu at the TMHP boundary but uses
pythonfmu3 and the FMI 3.0 Fmi3StepResult return contract. It targets
FMI 3.0 Co-Simulation only: the FMU owns the ASHPB dynamic state and advances it
once for each importer communication step.
Build:
pythonfmu3 build -f src/tmhp/integrations/fmu3.py .
The adapter intentionally does not expose FMI 3.0 clocks, Scheduled Execution, or array variables. Those features are useful for embedded controls and multi-rate models; TMHP’s current ASHPB FMU boundary is scalar Co-Simulation.
- class tmhp.integrations.fmu3.TmhpAshpbFmi3Slave(**kwargs)[source]¶
Bases:
Fmi3SlaveASHPB single-timestep co-simulation kernel (FMI 3.0).
- Parameters:
kwargs (
Any)
- author = 'BET Lab'¶
- description = 'TMHP ASHPB one-dt co-simulation kernel (FMI 3.0)'¶
- to_xml(model_options=None)[source]¶
Build a static FMI 3.0 model description for PythonFMU3.
- Parameters:
model_options (
dict[str,str] |None)- Return type:
Element
EnergyPlus Python Plugin¶
EnergyPlus Python Plugin adapter for the tmhp ASHPB.
Surrogates AirSourceHeatPumpBoiler inside EnergyPlus as a
PlantComponent:UserDefined device. Each plant-solver call hands the plugin
the loop inlet temperature, mass flow, specific heat, and load request, plus the
site outdoor drybulb temperature and relative humidity. The plugin solves the
refrigerant cycle with the public analyze_steady() seam and writes back the
outlet-temperature and mass-flow actuators, routing the system’s electricity
to a metered output.
Metered electricity and delivered heat (what crosses the EnergyPlus boundary)¶
The metered power is the system total E_tot of the solved cycle —
compressor plus outdoor-fan power (the plugin globals keep their historical
tmhp_E_cmp* names). The heat handed to the plant loop and the metered power
always belong to the same operating state:
q_loopheat put into the loop,
m_dot * cp * (T_out - T_in).E_meter = E_tot * q_loop / Q_cyclethe solved cycle runs a fraction
q_loop / Q_cycleof the timestep.
Two situations make q_loop smaller than the heat Q_cycle of the solved
(continuously running) cycle:
Minimum-speed clamp. Below its minimum compressor speed the machine cannot deliver the requested part load continuously. With the model’s default
Cd_cyclingthe cycle result is already the on/off mean of the minimum-speed machine (capacity_clamped == "min",runtime_fraction [-]below 1):Q_cycleequals the request andE_totincludes the cycling loss (E_cycling_loss [W]), so the duty fraction below is 1 and the loss is metered. Only a model built withCd_cycling=Nonereturns the continuous minimum-speed point (Q_cycle> request); the plugin then treats it as on/off cycling itself: the time-averaged heat equals the load request and the electricity is scaled by the same duty fraction, with no cycling-degradation penalty.PlantComponent:UserDefineddocuments theLoad Request for Plant Connection Nas the desired operating capacity for a connection in a load-meeting mode, and the loop outlet temperature isT_in + q / (m_dot cp): supplying the clampedQ_cycleinstead would overheat the loop and the storage tank relative to what EnergyPlus asked for.Outlet limit
TOUT_MAX. Heat that would push the outlet above the limit is not delivered, and the electricity that would have produced it is not metered.
Why analyze_steady (not step()): EnergyPlus owns the storage-tank state
through WaterHeater:Mixed and asks the component for a steady answer each
timestep (given the inlet/outdoor conditions and the loop load, what is the
leaving temperature and the electric input). The dynamic step() kernel — and
its tank model — is instead what the FMU adapter
(tmhp.integrations.fmu) wraps. The two BES adapters therefore ride on
different seams of the same model.
Runtime: EnergyPlus runs Python plugins in its embedded CPython, so
pyenergyplus is provided by the EnergyPlus install (not pip-installable) and
tmhp + native deps (CoolProp/numpy/scipy) must be built for that
interpreter’s ABI and pointed to via PythonPlugin:SearchPaths. Verify with an
import-only smoke plugin first — a wrong-ABI CoolProp wheel fails silently.
Configuration (environment variables, all optional):
|
refrigerant (default |
|
nominal HP capacity in W (default |
|
named parameter preset (default empty = model defaults) |
|
compressor displacement in cm³ (required with preset) |
|
rated outdoor fan flow in m³/s (required with preset) |
|
|
|
design loop volume flow in m³/s (default |
|
plugin global receiving timestep energy [J]
(default |
|
optional plugin global receiving power [W]
(default |
|
if set, append a per-call/tally log to this path |
IDF wiring (the “IDF wiring” section of
docs/source/integrations/energyplus-python.rst lists every object): one
PlantComponent:UserDefined named ASHPB_UserDefined with an init manager
bound to TmhpPlantInit and a simulation manager bound to
TmhpPlantSurrogate, a PythonPlugin:Variables global
tmhp_E_cmp_J for summed energy metering, and optionally tmhp_E_cmp_W for
averaged power reporting. The legacy global tmhp_E_cmp is still accepted as
an energy sink for older IDFs.
API strings (actuator component type "Plant Connection 1"; internal
variables "... for Plant Connection 1") are verified against EnergyPlus
24.2.0; reconfirm them for other releases.
- tmhp.integrations.energyplus_plugin.delivered_heat_and_power(res, *, q_request, t_in, m_dot, cp)[source]¶
Heat put into the loop [W] and the electricity metered for it [W].
q_requestis the load EnergyPlus asked for (capped at the nominal capacity). The solved cycle deliversQ_cycleatE_tot; the loop receivesmin(Q_cycle, q_request, m_dot * cp * (TOUT_MAX - t_in))and the machine is metered for the matching share of the timestep (see the module docstring).- Parameters:
res (
dict[str,Any])q_request (
float)t_in (
float)m_dot (
float)cp (
float)
- Return type:
tuple[float,float]
- class tmhp.integrations.energyplus_plugin.TmhpPlantInit[source]¶
Bases:
EnergyPlusPluginOne-shot sizing actuators so the plant loop dispatches load to the ASHPB.
Bind to the
PlantComponent:UserDefinedinitialization program-calling manager (E+ runs it once before plant sizing).
- class tmhp.integrations.energyplus_plugin.TmhpPlantSurrogate[source]¶
Bases:
EnergyPlusPluginPer-call ASHPB driver: read loop inlet + outdoor, solve, actuate.
Bind to the
PlantComponent:UserDefinedsimulation program-calling manager. Exposes compressor electricity through the plugin globaltmhp_E_cmp_J(declare it inPythonPlugin:Variablesand meter it as summed joules).tmhp_E_cmp_Wcan be declared for averaged power output.
Ground response from geolink¶
Optional. geolink is a separate package and is imported only when
geolink_gfunction() is called; see
Ground response.
Ground response from a borehole-to-borehole response matrix (geolink).
geolink (bet-lab/geolink) computes resolved ground responses that
pygfunction does not: groundwater advection (moving finite line source),
response at arbitrary observation points, depth-segmented responses. Its
response models share one contract:
response.response_matrix(field, soil, times) -> h[i, j, t] # K per W/m
the wall-temperature rise of borehole i for a unit load per metre on
borehole j. ResponseMatrixGFunction turns any object with that
method into the field g-function the tmhp models use, so the rest of the
chain (step-mean superposition, borehole resistance,
with_borehole_capacity()) is unchanged:
from tmhp.ground_coupling import AggregateGFunctionCoupler
from tmhp.integrations.geolink import geolink_gfunction
g = geolink_gfunction(x, y, H=150.0, r_b=0.08, k_s=2.0, alpha_s=1.25e-6,
t_max_s=10 * 8760 * 3600, groundwater_velocity=1e-7,
rho_s=2000.0, c_s=800.0)
model = GroundSourceHeatPumpBoiler(N_1=len(x), N_2=1, H_b=150.0,
ground_coupler=AggregateGFunctionCoupler(g))
geolink is not a dependency of tmhp and is imported only by
geolink_gfunction(); ResponseMatrixGFunction itself needs
nothing but the method above.
Two routes from geolink to a tmhp model¶
The g-function route (this module) reduces the response matrix to one
field g-function and leaves the superposition to tmhp. It is the default
choice. Every borehole carries the same load per metre; the first hour is
tabulated as in tmhp’s own g-functions (a line from g(0) = 0 to
g(1 h)); the table extends itself when a run outlasts t_max_s; and
the g-function can be wrapped by
with_borehole_capacity() before it is given to
the coupler.
The coupler route gives the model geolink’s own backend as
ground_coupler:
from geolink.coupling import NetworkGroundCoupler
coupler = NetworkGroundCoupler.from_rectangular(
N_1=2, N_2=2, B=6.0, H_b=150.0, D_b=1.0, r_b=0.08, k_s=2.0, alpha_s=1.25e-6)
model = GroundSourceHeatPumpBoiler(N_1=2, N_2=2, H_b=150.0, ground_coupler=coupler)
Use it when the boreholes do not share the heat in proportion to their
length (its weights), or when the response model itself should be
evaluated below one hour. It has no g-function to wrap, so the borehole is
the steady one (a resistance without heat capacity).
The coupler route needs geolink main 5cff1aa1 (2026-11-13,
bet-lab/geolink#578) or later. From that commit NetworkGroundCoupler
follows the contract of tmhp.ground_coupling: the load is per metre
of total borehole length (q_unit = Q / (N H)), the returned rise is the
mean over [t_n, t_n + dt], reset takes dt_s and
preview_wall_temperature_rise exists. Earlier versions divided the load
by the number of boreholes a second time and evaluated the response at the
start of each step: an N-borehole field returned 1/N of the rise and
the first loaded step returned zero.
On either route the total borehole length must be the same on both sides.
The model divides the field load by its own N_1 * N_2 * H_b; geolink
cannot see that number. A field of another total length
(NetworkGroundCoupler.total_length, or the H given to
geolink_gfunction()) is not detected and scales every rise by the
ratio of the two lengths: a 4 x 4 coupler under a 2 x 2 model returns four
times the rise the same heat causes in the 4 x 4 field. For boreholes of
different lengths H_b is their mean.
Checked with geolink 5cff1aa1 (2026-11-14). For 1 x 1, 2 x 2 and 4 x 4
fields (200 m, 6 m spacing, 20 W/m for a year, hourly and daily steps) the
coupler route gives 1.0001 to 1.0002 times the rise of tmhp’s 'UHTR'
g-function, and no step after the first differs by more than 0.002 K (of 7
to 11 K). A 24 h run of the boiler on a 2 x 2 field of 100 m boreholes
stays within 0.013 K of the 'UHTR' run on the coupler route and within
0.0003 K on the g-function route, for a swing of 0.65 K.
What remains different is the first hour. geolink evaluates the response
model there; a tmhp table draws the line from zero. With hourly steps the
first loaded step rises by 0.218 K on the coupler route and by 0.252 K on
the g-function route (20 W/m, k_s = 2 W/(m K), alpha_s = 1e-6 m2/s,
r_b = 0.08 m); with daily steps by 1.998 and 1.999 K.
- class tmhp.integrations.geolink.ResponseMatrixGFunction(response, field, soil, depths, t_max_s, *, points_per_decade=24.0)[source]¶
Bases:
objectField g-function
g(t)[m.K/W] from a response-matrix provider.Every borehole carries the same load per metre
q'(the field load over the total borehole length, as the tmhp models define it). The wall of boreholeithen rises byq' * sum_j h[i, j], and the field value is the length-weighted mean over the boreholes:g(t) = sum_i H_i sum_j h[i, j, t] / sum_i H_iwhich is the uniform-heat-flux g-function (pygfunction’s
'UHTR') for a finite-line-sourceh. Values are tabulated on a log-spaced grid from one hour to1.5 * t_max_swithg(0) = 0prepended, are interpolated linearly, and are recomputed when a later time is requested, liketmhp.g_function.GFunction.The provider is called once per decade of time, never with the whole grid. Until the fix of bet-lab/geolink#581, geolink’s groundwater model (
MFLSResponse) set its quadrature from the time span of one call: asked for the four to six decades of a table at once, its field response is up to 4e-5 m.K/W off for a 2 x 2 field and 2.5e-3 m.K/W (0.7 %) for a 10 x 10 field at a Darcy velocity of 1e-6 m/s; with decade calls 2e-5 and 1.3e-4 (150 m boreholes, 6 m spacing, against the same integral on a grid 500 times finer). The table then takes five to seven calls instead of one, 0.7 s -> 4 s for the 10 x 10 field. Conduction-only responses are the same either way to round-off.With the fix (bet-lab/geolink#583, checked on its branch at
69bbbf1d, 2026-11-14) the same fields are within 2e-10 m.K/W of that reference however the times are grouped, a table of the 10 x 10 field takes 0.14 s, and the split changes the values by 2e-11 at most. It is kept for earlier geolink versions and for other providers.- Parameters:
response (
Any) – Object withresponse_matrix(field, soil, times) -> h[i, j, t][K per W/m], receiver index first.field (
Any) – Passed through toresponse_matrixunchanged.soil (
Any) – Passed through toresponse_matrixunchanged.depths (
Any) – Active length of each borehole [m] (a scalar for equal lengths).t_max_s (
float) – Expected simulation length [s].points_per_decade (
float) – Node density of the grid (default 24, asGFunction).
- __init__(response, field, soil, depths, t_max_s, *, points_per_decade=24.0)[source]¶
- Parameters:
response (
Any)field (
Any)soil (
Any)depths (
Any)t_max_s (
float)points_per_decade (
float)
- tmhp.integrations.geolink.geolink_gfunction(x, y, H, *, r_b, k_s, alpha_s, t_max_s, D=0.0, groundwater_velocity=0.0, groundwater_direction=0.0, dispersivity=0.0, rho_s=None, c_s=None, response=None)[source]¶
Field g-function computed by
geolinkfor boreholes at(x, y).Without groundwater it is geolink’s native finite line source (boreholes may have different lengths). With
groundwater_velocityit is the moving finite line source of Molina-Giraldo et al. (2011), which needs equal lengths and the ground heat capacity.- Parameters:
x (
Any) – Borehole coordinates [m].y (
Any) – Borehole coordinates [m].H (
Any) – Active borehole length [m], one value or one per borehole.r_b (
float) – Borehole radius [m].k_s (
float) – Ground conductivity [W/(m K)] and diffusivity [m2/s].alpha_s (
float) – Ground conductivity [W/(m K)] and diffusivity [m2/s].t_max_s (
float) – Expected simulation length [s].D (
float) – Buried depth of the borehole heads [m].groundwater_velocity (
float) – Darcy velocity of the groundwater [m/s]; 0 (default) is pure conduction.groundwater_direction (
float) – Flow direction [rad], counter-clockwise from the x axis.dispersivity (
float) – Longitudinal thermal dispersivity [m] (isotropic in geolink).rho_s (
float|None) – Ground density [kg/m3] and specific heat [J/(kg K)]; required with groundwater flow (they set the thermal front velocity).c_s (
float|None) – Ground density [kg/m3] and specific heat [J/(kg K)]; required with groundwater flow (they set the thermal front velocity).response (
Any) – A geolink response model to use instead of the two above.
- Raises:
ImportError – If
geolinkis not installed.- Return type: