Thermal API¶
The simses.thermal module provides two environment models — a simple ambient coupling and a physics-based container with walls + HVAC + solar — wired through the ThermalComponent structural protocol. For the thermal network, protocol contract, and the HVAC strategy/hardware split, see the Thermal Models concept page.
Thermal component protocol¶
Structural contract that any registerable node (battery, non-battery storage, custom component) must satisfy: state.T, state.heat, thermal_capacity, thermal_resistance.
simses.thermal.protocol.ThermalComponent
¶
Bases: Protocol
Protocol for objects that can be registered as thermal nodes.
Satisfying this protocol does not require explicit inheritance — any object with these attributes qualifies (structural subtyping).
Attributes:
| Name | Type | Description |
|---|---|---|
state |
ThermalComponentState
|
Mutable state object exposing |
thermal_capacity |
float
|
Thermal capacity in J/K. |
thermal_resistance |
float
|
Thermal resistance to the thermal environment in K/W. |
Source code in src/simses/thermal/protocol.py
Ambient thermal model¶
Zero-dimensional environment: each registered component is an independent node coupled to a single ambient temperature. Use when the thermal environment can be treated as a uniform external temperature (bench tests, climate-controlled rooms, first-order sanity checks).
simses.thermal.ambient.AmbientThermalModel
¶
Zero-dimensional room thermal model with constant ambient temperature.
Models heat exchange between registered components and a constant-temperature environment. Each component is an independent thermal node with its own temperature, thermal capacity, and thermal resistance.
Per-component ODE (forward Euler integration)::
dT_i / dt = Q_heat_i / C_th_i + (T_ambient - T_i) / (R_th_i * C_th_i)
Components are registered via :meth:add_component and must provide:
state.T-- current temperature in °C (read/written)state.heat-- total heat generation in W (read)thermal_capacity-- thermal capacity in J/K (read)thermal_resistance-- thermal resistance in K/W (read)
Source code in src/simses/thermal/ambient.py
T_ambient
property
writable
¶
External ambient temperature in °C (convenience accessor for state.T_ambient).
__init__(T_ambient, components=None)
¶
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
T_ambient
|
float
|
Ambient temperature in °C. May be overwritten at any
time via the |
required |
components
|
list | None
|
Initial list of :class: |
None
|
Source code in src/simses/thermal/ambient.py
add_component(component)
¶
Register a component as a thermal node.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
component
|
ThermalComponent
|
Any object satisfying the :class: |
required |
step(dt)
¶
Advance every registered component's temperature by one timestep.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dt
|
float
|
Timestep in seconds. |
required |
Source code in src/simses/thermal/ambient.py
simses.thermal.ambient.AmbientThermalState
dataclass
¶
Mutable state of a :class:AmbientThermalModel.
Attributes:
| Name | Type | Description |
|---|---|---|
T_ambient |
float
|
External ambient temperature in °C. |
Source code in src/simses/thermal/ambient.py
Container thermal model¶
Physics-based BESS container with five coupled thermal nodes (batteries, internal air, three wall layers), HVAC injection at the air node, and optional solar heat on the outer wall. Use when wall conduction, air thermal mass, HVAC sizing, or diurnal external cycles matter.
simses.thermal.container.ContainerThermalModel
¶
Physics-based container thermal model with three-layer walls and HVAC.
Five coupled thermal nodes (forward Euler): - Battery nodes (one per registered component) - Internal air - Inner wall layer - Mid wall layer - Outer wall layer
The outer wall is coupled to the ambient temperature (updatable via
:attr:T_ambient). Observable outputs are stored in :attr:state
after each :meth:step.
Components are registered via :meth:add_component and must satisfy
the :class:~simses.thermal.protocol.ThermalComponent protocol:
state.T-- current temperature in °C (read/written)state.heat-- total heat generation in W (read)thermal_capacity-- thermal capacity in J/K (read)thermal_resistance-- thermal resistance to internal air in K/W (read)
Source code in src/simses/thermal/container.py
276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 | |
T_ambient
property
writable
¶
External ambient temperature in °C (convenience accessor for state.T_ambient).
Q_solar
property
writable
¶
Solar irradiance heat load on the outer wall in W.
__init__(properties, T_ambient, T_initial, hvac, tms)
¶
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
properties
|
ContainerProperties
|
Container geometry and wall-layer parameters. |
required |
T_ambient
|
float
|
Initial external ambient temperature in °C. |
required |
T_initial
|
float
|
Initial temperature for all internal nodes in °C. |
required |
hvac
|
HvacModel
|
HVAC hardware model mapping thermal demand to electrical consumption. |
required |
tms
|
ThermalManagementStrategy
|
Thermal-management strategy producing the thermal-power demand from the reference temperature. |
required |
Source code in src/simses/thermal/container.py
add_component(component)
¶
Register a component as a thermal node.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
component
|
ThermalComponent
|
Any object satisfying the :class: |
required |
step(dt)
¶
Advance all thermal nodes by one timestep.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dt
|
float
|
Timestep in seconds. |
required |
Source code in src/simses/thermal/container.py
simses.thermal.container.ContainerThermalState
dataclass
¶
Mutable state of a :class:ContainerThermalModel.
Attributes:
| Name | Type | Description |
|---|---|---|
T_air |
float
|
Internal air temperature in °C. |
T_in |
float
|
Inner wall layer temperature in °C. |
T_mid |
float
|
Middle wall layer temperature in °C. |
T_out |
float
|
Outer wall layer temperature in °C. |
T_ambient |
float
|
External ambient temperature in °C. |
Q_solar |
float
|
Solar irradiance heat load on the outer wall in W (default 0). |
power_th |
float
|
HVAC thermal power delivered to the air in W (positive = heating, negative = cooling, 0 = idle). |
power_el |
float
|
HVAC electrical power consumption in W (always ≥ 0). |
Source code in src/simses/thermal/container.py
simses.thermal.container.ContainerProperties
dataclass
¶
Geometry and thermal properties of a container.
Internal dimensions are used to derive surface area and internal volume. Convection coefficients apply at inner and outer surfaces.
Attributes:
| Name | Type | Description |
|---|---|---|
length |
float
|
Internal length in m. |
width |
float
|
Internal width in m. |
height |
float
|
Internal height in m. |
h_inner |
float
|
Inner surface convection coefficient in W/m²K. |
h_outer |
float
|
Outer surface convection coefficient in W/m²K. |
inner |
ContainerLayer
|
Innermost wall layer (e.g. aluminium). |
mid |
ContainerLayer
|
Middle wall layer (e.g. insulation). |
outer |
ContainerLayer
|
Outermost wall layer (e.g. steel). |
vol_air |
float
|
Factor of volume of the container occupied by air in % (default: 1.0) |
A_surface |
float
|
Total surface area in m² (derived). |
V_internal |
float
|
Internal volume in m³ (derived). |
Source code in src/simses/thermal/container.py
simses.thermal.container.ContainerLayer
dataclass
¶
Physical properties of a single wall layer.
Attributes:
| Name | Type | Description |
|---|---|---|
thickness |
float
|
Layer thickness in m. |
conductivity |
float
|
Thermal conductivity in W/mK. |
density |
float
|
Material density in kg/m³. |
specific_heat |
float
|
Specific heat capacity in J/kgK. |
Source code in src/simses/thermal/container.py
HVAC¶
Hardware-side Protocol converting a thermal-power demand into the corresponding electrical draw. The shipped constant-COP implementation is a reasonable default; swap it for a detailed chiller model by implementing the same two-method interface.
simses.thermal.container.HvacModel
¶
Bases: Protocol
Protocol for HVAC hardware models.
The sole responsibility is to convert a thermal power demand into the corresponding electrical consumption. The model is stateless — no results are stored internally; the caller (the thermal model) is responsible for recording them in its state.
Source code in src/simses/thermal/container.py
electrical_consumption(Q_thermal)
¶
Return the electrical power required to deliver Q_thermal.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Q_thermal
|
float
|
Thermal power in W (positive = heating, negative = cooling, 0 = idle). |
required |
Returns:
| Type | Description |
|---|---|
float
|
Electrical power draw in W (always ≥ 0). |
Source code in src/simses/thermal/container.py
simses.thermal.container.ConstantCopHvac
¶
HVAC hardware model with fixed coefficients of performance.
Electrical consumption is proportional to the thermal demand:
heating (Q_thermal > 0): P_el = Q_thermal / cop_heating cooling (Q_thermal < 0): P_el = |Q_thermal| / cop_cooling
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cop_cooling
|
float
|
COP for cooling mode (default 3.0). |
3.0
|
cop_heating
|
float
|
COP for heating mode (default 2.5). |
2.5
|
Source code in src/simses/thermal/container.py
electrical_consumption(Q_thermal)
¶
Return the electrical power required to deliver Q_thermal.
Source code in src/simses/thermal/container.py
Thermal management strategies¶
The "brain" side of the HVAC: decides how much heating/cooling the container needs per step. Use ThermostatStrategy for simple hysteresis control, or ExternalThermalManagement as a pass-through when an external controller (MPC, optimisation, co-simulation) computes the demand upstream.
simses.thermal.container.ThermalManagementStrategy
¶
Bases: Protocol
Protocol for thermostat control strategies.
Used by :class:ContainerThermalModel. control() returns the
requested thermal power based on a reference temperature derived from
the registered storage components.
Source code in src/simses/thermal/container.py
control(T_ref, dt)
¶
Advance the strategy and return the requested thermal power.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
T_ref
|
float
|
Reference temperature in °C — the maximum temperature across all registered storage components. |
required |
dt
|
float
|
Timestep in seconds. |
required |
Returns:
| Type | Description |
|---|---|
float
|
|
Source code in src/simses/thermal/container.py
simses.thermal.container.ThermostatStrategy
¶
Hysteresis thermostat control strategy.
Decides when to heat or cool based on setpoint and dead-band. The
requested thermal power (±max_power) is passed to an :class:HvacModel
to obtain the corresponding electrical consumption. No power values are
stored in the strategy itself.
State machine transitions
IDLE → HEATING if T_air < T_setpoint - threshold IDLE → COOLING if T_air > T_setpoint + threshold HEATING → IDLE if T_air >= T_setpoint COOLING → IDLE if T_air <= T_setpoint
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
T_setpoint
|
float
|
Target internal air temperature in °C. |
required |
max_power
|
float
|
Maximum thermal output requested from the HVAC unit in W. |
required |
threshold
|
float
|
Half-width of the dead-band in K (default 5.0). |
5.0
|
Source code in src/simses/thermal/container.py
mode
property
¶
Current thermostat operating mode.
control(T_ref, dt)
¶
Advance the state machine and return the requested thermal power.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
T_ref
|
float
|
Reference temperature in °C (max battery temperature). |
required |
dt
|
float
|
Timestep in seconds (unused but required by protocol). |
required |
Returns:
| Type | Description |
|---|---|
float
|
|
Source code in src/simses/thermal/container.py
simses.thermal.container.ThermostatMode
¶
Bases: Enum
Operating mode of a :class:ThermostatStrategy.
Source code in src/simses/thermal/container.py
IDLE = 'idle'
class-attribute
instance-attribute
¶
Neither heating nor cooling; HVAC draws no power.
HEATING = 'heating'
class-attribute
instance-attribute
¶
HVAC is adding heat to the internal air node.
COOLING = 'cooling'
class-attribute
instance-attribute
¶
HVAC is removing heat from the internal air node.
simses.thermal.container.ExternalThermalManagement
¶
Pass-through thermal management strategy for external controllers.
Instead of computing HVAC power internally, this strategy returns a
value set externally via the :attr:Q_hvac property. Use this when
an external controller (e.g. MPC) decides the thermal power.
Example::
tms = ExternalThermalManagement()
container = ContainerThermalModel(..., tms=tms)
# In the simulation loop:
tms.Q_hvac = mpc_computed_power
container.step(dt=1.0)
Source code in src/simses/thermal/container.py
Solar heat load¶
Vectorised pre-computation of absorbed solar power on a container's outer walls. Takes a GHI time series, solar-position + Reindl decomposition + per-face geometry, and returns a per-timestep power series to feed ContainerThermalModel.Q_solar.
simses.thermal.solar.SolarConfig
dataclass
¶
Solar and surface parameters for solar heat-load pre-computation.
Attributes:
| Name | Type | Description |
|---|---|---|
latitude |
float
|
Site latitude in degrees N (negative = Southern hemisphere). |
longitude |
float
|
Site longitude in degrees E (negative = West). |
azimuth |
float
|
Container orientation — compass bearing that the North face of the container points toward, in degrees clockwise from true North. 0 = North face points North (standard alignment), 90 = rotated 90° clockwise (North face now points East). |
absorptivity |
float
|
Outer surface absorptivity coefficient (0–1). Typical painted steel ≈ 0.6. Default: 0.6. |
albedo |
float
|
Ground reflectance (0–1). Default: 0.2. |
Source code in src/simses/thermal/solar.py
simses.thermal.solar.solar_heat_load(ghi, container, config)
¶
Pre-compute absorbed solar heat load on a container for a full timeseries.
The calculation is vectorised: a single call processes an entire year (or
any length) of GHI data at once. The returned series can be indexed during
the simulation loop and assigned to
:attr:~simses.thermal.ContainerThermalModel.Q_solar.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ghi
|
Series
|
Global horizontal irradiance [W/m²]. Must carry a
timezone-aware :class: |
required |
container
|
ContainerProperties
|
Container geometry — |
required |
config
|
SolarConfig
|
Site location, container orientation, and surface properties. |
required |
Returns:
| Type | Description |
|---|---|
Series
|
Absorbed solar power [W] with the same index as ghi. All values are |
Series
|
≥ 0; night-time and below-horizon rows are zero. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If ghi is not a :class: |
Example::
import pandas as pd
from simses.thermal import ContainerLayer, ContainerProperties
from simses.thermal.solar import SolarConfig, solar_heat_load
df = pd.read_csv("munich_ghi_2024.csv", index_col=0, parse_dates=True)
df.index = df.index.tz_localize("Europe/Berlin")
ghi = df["ghi_wm2"] # select one column → pd.Series
props = ContainerProperties(
length=6.06, width=2.44, height=2.59,
h_inner=5.0, h_outer=15.0,
inner=ContainerLayer(0.001, 200, 2700, 900),
mid=ContainerLayer(0.06, 0.04, 30, 1000),
outer=ContainerLayer(0.002, 50, 7800, 500),
)
config = SolarConfig(latitude=48.14, longitude=11.58, azimuth=0.0)
q_solar = solar_heat_load(ghi.squeeze(), props, config)
Source code in src/simses/thermal/solar.py
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 | |