Skip to content

Simulated Weights

Simulated benefit weights: an ISO 13790 Annex C hourly thermal model ("5R1C") plus perturbation attribution, producing the hourly benefit / harm series consumed by benefit mode's simulated_weights_path. See Carving Modes for the user-level workflow and Tutorial 5 for a walkthrough.

urbansolarcarver.simulated_weights

Simulated benefit weights for benefit mode (ISO 13790 5R1C).

Implements the ISO 13790 Annex C simple hourly method ("5R1C": five thermal conductances and one heat capacity, as an electrical-circuit analogue of a single building zone) and derives, by perturbation, the marginal benefit and harm of solar gain at every hour of the year:

benefit[t] = -dQ_heating / dPhi_sol(t)   in [0, 1]
harm[t]    = +dQ_cooling / dPhi_sol(t)   in [0, 1]

Q_heating and Q_cooling are the annual demands [Wh] and Phi_sol(t) is the solar gain entering the zone in hour t [W]. The two series are written to a simulated_weights.json artifact that benefit mode can use in place of its balance-point Heaviside filter.

Provenance: this is an independent implementation written directly from the ISO 13790 Annex C equation set (not a fork or port of an existing simulator). It is cross-validated against ETH Zurich's RC_BuildingSimulator (MIT, https://github.com/architecture-building-systems/RC_BuildingSimulator; Jayathissa et al., Applied Energy 202, 2017) on three archetype scenarios (medium office, heavy masonry, light insulated) driven by the bundled Golden TMY3 EPW. The reference simulator's derived conductances are fed in directly, so the comparison tests the hourly recurrence: annual heating and cooling demands agree within 1 Wh (or a relative 1e-6), and hourly air and mass temperatures and demands agree at sampled hours. Reference data: tests/data/oracle_5r1c_reference.json; regression: tests/test_simulated_weights.py. The equations, the artifact, the coefficient provenance and the declared limitations: docs/simulated-weights.md.

This module is deliberately NumPy-only at import time (no torch, no ladybug) so it stays usable as a standalone generator; the EPW-facing helper imports Ladybug lazily.

ZoneParams(floor_area, h_tr_em, h_tr_w, h_tr_is, h_tr_ms, h_ve, c_m, a_m, a_t, t_set_heating=ARCHETYPE_DEFAULTS['t_set_heating'], t_set_cooling=ARCHETYPE_DEFAULTS['t_set_cooling']) dataclass

5R1C parameters: conductances (h_*) in W/K, c_m in J/K, areas (floor_area, a_m, a_t) in m², set-points in °C.

h_tr_em is exterior to mass, h_tr_w windows, h_tr_is air to internal surfaces, h_tr_ms surfaces to mass, h_ve ventilation: one value, or an (8760,) array of one value per hour when the ventilation follows a schedule.

Use :meth:from_archetype to derive them from physical archetype inputs per the standard; tests may also construct directly from known conductances (e.g. values from the reference simulator).

from_archetype(floor_area, volume, u_opaque, area_opaque, u_window, area_window, ach_vent, ach_infiltration, heat_recovery=ARCHETYPE_DEFAULTS['heat_recovery'], mass_class=None, t_set_heating=ARCHETYPE_DEFAULTS['t_set_heating'], t_set_cooling=ARCHETYPE_DEFAULTS['t_set_cooling'], mass_capacity_kj_m2k=None) classmethod

Derive the network from archetype inputs per ISO 13790.

  • A_tot = 4.5 · A_f; H_tr,is = 3.45 · A_tot
  • (A_m, C_m) from the Table-12 mass class, or, with mass_capacity_kj_m2k, C_m = capacity · 1000 · A_f and A_m of the class nearest in capacity (the lighter one on a tie)
  • H_tr,ms = 9.1 · A_m
  • H_tr,op = U_opaque · A_opaque; H_tr,w = U_window · A_window
  • H_tr,em = 1 / (1/H_tr,op − 1/H_tr,ms) (§12.2.2 serial split)
  • H_ve = 1200 · b_ek · V · ACH_tot/3600, with 1200 J/(m³K) the volumetric heat capacity of air and the heat-recovery adjustment b_ek = 1 − (ACH_vent/ACH_tot) · η_hr (Annex E).

Units: areas in m², volume in m³, U-values in W/(m²K), air change rates in 1/h, heat_recovery (η_hr) as a fraction 0-1, set-points in °C, mass_capacity_kj_m2k in kJ/(m²K) of floor. ach_vent is one value or 8760 hourly values (a ventilation schedule); then h_ve is hourly too, heat recovery applying to the ventilation part of each hour. mass_class defaults to the archetype default ("medium") when no capacity is given.

Raises ValueError for an unknown mass_class, for both mass_class and mass_capacity_kj_m2k, for a capacity that is not positive, when H_tr,op >= H_tr,ms (the serial split would be negative or infinite), for an ach_vent that is neither one value nor 8760, or when the total air change rate is not positive (in any hour).

SimulationResult(q_heating_wh, q_cooling_wh, t_air, t_m, demand_w) dataclass

Annual outcome of :func:simulate (single trajectory).

FreeRunningResult(underheating_kh, overheating_kh, hours_below, hours_above, t_air, t_m, window_share) dataclass

Annual outcome of :func:simulate_free_running (single trajectory).

nearest_mass_class(capacity_kj_m2k)

The Table-12 class whose C_m per m² floor is nearest to the given capacity [kJ/(m²K)]; on a tie the lighter class.

simulate(p, t_out, phi_int, phi_sol, t_m_init=20.0)

Annual 5R1C simulation of a single zone (Wh demands, °C series).

t_out, phi_int and phi_sol are hourly arrays of length 8760: outdoor dry-bulb [°C], internal gains [W], transmitted solar gains [W]. t_m_init is the mass temperature at the start of the year [°C]. Raises ValueError if an array does not have shape (8760,).

attribute_solar_gains(p, t_out, phi_int, phi_sol, eps=1.0, t_m_init=20.0, progress=None)

Marginal hourly benefit/harm of solar gain by central-difference perturbation.

Returns (benefit, harm), each (8760,) in [0, 1]: the fraction of one extra watt-hour of solar gain at hour t that offsets heating demand / becomes cooling load over the year. eps is the perturbation size [W]; progress, when given, is called with the share of the year done (0 to 1); the other arguments are as in :func:simulate.

Values are marginal at this archetype's operating point. At hours where the control switches between heating, free-floating and cooling, the derivative is not defined and the central difference gives an average of the one-sided slopes. Out-of-range values up to 0.02 from such switching are clipped silently; larger ones are also clipped but trigger a warning.

window_conductance(volume, vent_ach)

The extra ventilation conductance [W/K] of windows opened fully: 1200 J/(m³K), the volumetric heat capacity of air, x the volume [m³] x vent_ach [1/h] / 3600.

loss_coefficient(p)

The zone's steady-state heat loss coefficient [W/K] with its windows closed: the windows, the opaque fabric (H_tr,em in series with H_tr,ms) and the ventilation (its mean over the year when it follows a schedule).

simulate_free_running(p, t_out, phi_int, phi_sol, h_open=0.0, vent_above=FREE_RUNNING_DEFAULTS['vent_above'], t_m_init=None)

Annual simulation of a free-running zone: no heating or cooling, windows opened as :func:_march_free describes, the comfort band from the zone's heating to its cooling set point. h_open [W/K] is the extra ventilation of the windows fully open (:func:window_conductance; 0, the default, keeps them closed). t_m_init is the mass temperature at the start of the year [°C]; None (the default) starts from a periodic steady state (:func:_periodic_start). The other arguments are as in :func:simulate; ValueError if an array does not have shape (8760,).

attribute_free_running(p, t_out, phi_int, phi_sol, h_open=0.0, vent_above=FREE_RUNNING_DEFAULTS['vent_above'], eps=10.0, t_m_init=None, progress=None)

Marginal hourly benefit/harm of solar gain in a free-running zone, by central-difference perturbation (eps [W] in one hour at a time).

Returns (benefit, harm), each (8760,) in [0, 1]: the degree-hours below the comfort band that one extra watt-hour of solar gain at hour t removes over the year, and the degree-hours above it that it adds, each times the zone's heat loss coefficient (:func:loss_coefficient). The product is a share of the watt-hour: in steady state, a watt-hour that all goes into warming a zone below the band removes 1/H degree-hours, which counts 1. Out-of-range values up to 0.02 are clipped silently, larger ones with a warning (as in :func:attribute_solar_gains). The other arguments are as in :func:simulate_free_running; progress as in :func:attribute_solar_gains.

transmitted_solar_from_epw(epw_path, windows, hourly_factors=None)

Hourly transmitted solar gain [W] for a set of windows.

windows: sequence of (azimuth_deg, area_m2, g_value) or (azimuth_deg, area_m2, g_value, altitude_deg); azimuth in Ladybug convention (0 = N, 90 = E, 180 = S, 270 = W); g_value is the glazing's total solar energy transmittance (0-1); altitude is that of the window's normal, 0 (the default) for a vertical window, 90 for a horizontal skylight. The irradiance on each window plane [W/m²] is that of Ladybug's Wea.directional_irradiance (isotropic sky, ground reflectance 0.2, no obstructions), with the sun placed once for all the windows (:func:_plane_irradiance); it is multiplied by area and g_value.

hourly_factors: optional per-window hourly transmission multipliers (one (8760,) array per window, e.g. shading coefficients); default 1.

Returns an (8760,) array of the summed gain over all windows [W].

sun_up_hours(epw_path)

(8760,) array of 0 and 1: 1 for the hours with the sun above the horizon at the weather file's site.

The sun is placed as :func:transmitted_solar_from_epw places it: by a Ladybug Sunpath at the middle of each hour (the Wea's datetimes).

write_simulated_weights(path, benefit, harm, meta)

Write the simulated_weights.json artifact and return its path.

The schema is described in docs/simulated-weights.md. Values are rounded to 6 decimals. Raises ValueError if a series is not 8760 finite values in [0, 1].

read_simulated_weights(path)

Read and validate a simulated_weights.json artifact.

Returns (benefit, harm, meta): two (8760,) float64 arrays and the metadata dict (a file that also holds rooms per facade direction gives the averaged room's). Raises ValueError if the file cannot be read or parsed, has an unsupported schema_version, or holds invalid series.

expand_shoebox(archetype)

Expand the shoebox geometry shorthand into explicit archetype areas.

Instead of floor_area / volume / area_opaque / area_window / windows, an archetype may describe a rectangular single-zone box:

  • width: east-west dimension (m)
  • length: north-south dimension (m)
  • height: storey height (m)
  • wwr: window-to-wall ratio per facade in [0, 1), keyed by cardinal name (north / east / south / west); omitted sides get no window
  • g_value: glazing solar transmittance for all windows (default 0.6)
  • orientation: degrees to rotate the box clockwise from north (optional, default 0)
  • roof_exposed (default true) and floor_exposed (default false): whether the roof and the floor lose heat to the outside; a roof or floor that is not exposed is adiabatic (a storey between others, or a slab whose ground loss is left out)
  • the opaque U values: either u_opaque, one U for the walls and the exposed roof and floor, or u_wall with u_roof (needed when the roof is exposed) and u_floor (needed when the floor is exposed)

Derived: floor area = width x length; volume = floor area x height; per-facade window areas = wwr x facade area; area_opaque = opaque walls + the exposed roof and floor; area_window = sum of windows. With u_wall, u_opaque is the area-weighted U of that opaque area, so H_tr,op = u_wall x opaque walls + u_roof x roof (if exposed) + u_floor x floor (if exposed). Archetypes without any of the shoebox keys above are returned as an unchanged copy.

Raises ValueError if the shoebox keys are incomplete, mixed with explicit-area keys, non-positive, or define no window; for both u_opaque and u_wall, for u_roof/u_floor without u_wall, for a missing U of an exposed roof or floor, or for an exposure that is not true or false.

generate_simulated_weights(epw_path, archetype, out_path, internal_gains_w_m2=None, eps=1.0, progress=None)

Run the full 5R1C weights pipeline: EPW + archetype → artifact.

archetype holds the :meth:ZoneParams.from_archetype keyword arguments plus windows: a list of [azimuth_deg, area_m2, g_value] or [azimuth_deg, area_m2, g_value, altitude_deg] (or the shoebox geometry shorthand, see :func:expand_shoebox). Optional keys: shading_permanent, shading_hot and hot_months or shading_hot_period (transmission multipliers, see :func:_shading_factors) and the internal-gain keys below. ach_vent may be 8760 hourly values (see :meth:ZoneParams.from_archetype).

operation (one of OPERATIONS, default "conditioned") says how the zone is run. Conditioned: ideal heating and cooling to the set points, the weights by :func:attribute_solar_gains. Free running: no heating or cooling, the comfort band from t_set_heating to t_set_cooling, windows opened for natural ventilation by the keys vent_above [°C] and vent_ach [1/h] (FREE_RUNNING_DEFAULTS; free running only), the weights by :func:attribute_free_running.

Internal gains are either a single flat value [W/m²], a 24-value daily occupancy profile [W/m² per hour of day], tiled over the year, or 8760 hourly values from 1 January 0:00. They may come from the internal_gains_w_m2 / internal_gains_profile_w_m2 archetype keys, or be passed as the internal_gains_w_m2 argument (which takes precedence). Default 5.0.

eps is the solar-gain perturbation [W] used by :func:attribute_solar_gains. progress, when given, is called with the share of the calculation done (0 to 1, rising, by the measured time of each step), about 20 times, and with 1 once the artifact is written. Writes the JSON artifact to out_path and, if matplotlib is installed, a heatmap PNG of the series next to it with the same name; returns the artifact path. The artifact's meta also holds the zone's annual heating and cooling demand per m² of floor (heating_kwh_m2, cooling_kwh_m2, in kWh/m²), from :func:simulate with the same gains, and sun_up, 8760 values of 0 or 1 marking the hours with the sun above the horizon (:func:sun_up_hours). Free running, it holds operation and, in place of the demands, the zone's degree-hours below and above the band (underheating_kh, overheating_kh, in K·h), its hours outside it (hours_below, hours_above), the band (comfort_band_c) and the loss coefficient the weights are scaled by (loss_coefficient_w_k), from :func:simulate_free_running.