Skip to content

Zoning

Automatic thermal zoning for EnergyPlus models. Splits a 2-D building footprint into thermal zones and creates all Zone, BuildingSurface:Detailed, and (optionally) Construction:AirBoundary objects needed for simulation.

Not in JavaScript yet

Generating zoned blocks from a footprint is available in Python and is not in JavaScript today. A temporary gap, not a boundary. The port is tracked in idfkit-js#16.

The full entry, including the vocabulary this capability owns, is on the capability parity page.

Quick Start

from idfkit import new_document, create_block, ZoningScheme
from idfkit.zoning import footprint_rectangle

doc = new_document()
create_block(
    doc,
    name="Office",
    footprint=footprint_rectangle(50, 30),
    floor_to_floor=3.5,
    num_stories=3,
    zoning=ZoningScheme.CORE_PERIMETER,
)

# 3 stories × 5 zones (4 perimeter + 1 core) = 15 zones
print(len(doc["Zone"]))  # 15

Zoning Schemes

create_block supports three zoning strategies via the zoning parameter:

Scheme Zones per floor Description
BY_STOREY 1 One zone per floor (default).
CORE_PERIMETER 5 Four orientation-based perimeter zones plus an interior core zone.
CUSTOM User-defined Caller supplies named zone polygons via custom_zones.

By Storey (default)

The simplest scheme — one thermal zone per floor:

from idfkit import new_document, create_block

doc = new_document()
create_block(
    doc,
    name="Warehouse",
    footprint=[(0, 0), (40, 0), (40, 20), (0, 20)],
    floor_to_floor=4.0,
    num_stories=2,
)

print(len(doc["Zone"]))  # 2

Core-Perimeter

Splits each floor into four perimeter zones (North, East, South, West) and one interior core zone. The perimeter depth defaults to 4.57 m (15 ft) per ASHRAE 90.1 Appendix G and the DOE prototype buildings.

from idfkit import new_document, create_block, ZoningScheme
from idfkit.zoning import footprint_rectangle

doc = new_document()
create_block(
    doc,
    name="Office",
    footprint=footprint_rectangle(50, 30),
    floor_to_floor=3.5,
    num_stories=3,
    zoning=ZoningScheme.CORE_PERIMETER,
)

# 3 stories × 5 zones = 15 zones
print(len(doc["Zone"]))  # 15

You can override the perimeter depth:

from idfkit import new_document, create_block, ZoningScheme
from idfkit.zoning import footprint_rectangle

doc = new_document()
create_block(
    doc,
    name="Office",
    footprint=footprint_rectangle(50, 30),
    floor_to_floor=3.5,
    num_stories=1,
    zoning=ZoningScheme.CORE_PERIMETER,
    perimeter_depth=3.0,  # 3 m instead of the default 4.57 m
)

Note

When the footprint is too small for the requested perimeter depth (i.e. the inradius is less than 0.5 m after insetting), zoning automatically falls back to a single zone per floor.

Custom Zoning

Supply your own named zone polygons per floor using custom_zones. Each entry is a (name, polygon) tuple:

from idfkit import ZoneFootprint, ZoningScheme, create_block, new_document

doc = new_document()
create_block(
    doc,
    name="Lab",
    footprint=[(0, 0), (30, 0), (30, 20), (0, 20)],
    floor_to_floor=3.5,
    num_stories=1,
    zoning=ZoningScheme.CUSTOM,
    custom_zones=[
        ZoneFootprint("Wet Lab", [(0, 0), (15, 0), (15, 20), (0, 20)]),
        ZoneFootprint("Dry Lab", [(15, 0), (30, 0), (30, 20), (15, 20)]),
    ],
)

print(len(doc["Zone"]))  # 2

Air Boundaries

Set air_boundary=True to apply Construction:AirBoundary to all inter-zone walls. This is useful for open-plan spaces where zone boundaries are notional rather than physical:

from idfkit import new_document, create_block, ZoningScheme
from idfkit.zoning import footprint_rectangle

doc = new_document()
create_block(
    doc,
    name="Open Office",
    footprint=footprint_rectangle(50, 30),
    floor_to_floor=3.5,
    num_stories=1,
    zoning=ZoningScheme.CORE_PERIMETER,
    air_boundary=True,
)

# A Construction:AirBoundary object is created automatically
print(len(doc["Construction:AirBoundary"]))  # 1

Multi-Story Boundary Conditions

For multi-story buildings, inter-story floors and ceilings are automatically linked with Surface boundary conditions:

Story Floor BC Ceiling BC
Ground floor (base_elevation=0) Ground Surface (story above)
Elevated ground floor (base_elevation>0) Outdoors Surface (story above)
Mid floors Surface (story below) Surface (story above)
Top floor Surface (story below) Outdoors (Roof)

Stacked Blocks (Setbacks)

Buildings with setbacks — where upper floors have a smaller footprint — are modelled as separate blocks stacked with base_elevation, then connected with link_blocks:

from idfkit import new_document, create_block, link_blocks
from idfkit.zoning import footprint_rectangle

doc = new_document()

# 5-story base
create_block(
    doc,
    name="Base",
    footprint=footprint_rectangle(50, 30),
    floor_to_floor=3.5,
    num_stories=5,
)

# 3-story tower with a setback, stacked on top of the base
create_block(
    doc,
    name="Tower",
    footprint=footprint_rectangle(40, 24),
    floor_to_floor=3.5,
    num_stories=3,
    base_elevation=17.5,  # 5 × 3.5 m
)

# Auto-detect and link roof/floor pairs at z=17.5
linked = link_blocks(doc)

link_blocks finds all roof and floor surfaces at shared elevations, splits roofs that partially overlap a floor, and sets mutual Surface boundary conditions between the new ceiling and floor. The original roof is shrunk to cover only the remaining exposed area.

To link only specific blocks by name, pass lower and upper:

linked = link_blocks(doc, lower="Base", upper="Tower")

For finer control, use the lower-level adjacency API directly.

Footprint Helpers

Pre-built footprint generators for common commercial building shapes. All return a list of (x, y) tuples in counter-clockwise order.

A footprint you write by hand may be in either order. create_block, ZonedBlock and add_shading_block reverse a clockwise footprint, so the block is never built inside-out, and raise ValueError for one with no area. counter_clockwise_footprint() does the same normalisation for your own code.

footprint_rectangle

from idfkit.zoning import footprint_rectangle

fp = footprint_rectangle(50, 30)
# [(0, 0), (50, 0), (50, 30), (0, 30)]

footprint_l_shape

┌────────┐
│  wing  │
│        │
├────────┴──────────┐
│      base         │
└───────────────────┘
from idfkit.zoning import footprint_l_shape

fp = footprint_l_shape(width=40, depth=10, wing_width=15, wing_depth=20)

footprint_u_shape

┌──────┐    ┌──────┐
│      │    │      │
│      └────┘      │
│                  │
└──────────────────┘
from idfkit.zoning import footprint_u_shape

fp = footprint_u_shape(width=40, depth=30, courtyard_width=20, courtyard_depth=15)

footprint_t_shape

┌──────────────────────┐
│       top bar        │
└───┐              ┌───┘
    │    base      │
    └──────────────┘
from idfkit.zoning import footprint_t_shape

fp = footprint_t_shape(base_width=20, base_depth=15, top_width=40, top_depth=10)

footprint_h_shape

┌──────┐    ┌──────┐
│      └────┘      │
│     connector    │
│      ┌────┐      │
└──────┘    └──────┘
from idfkit.zoning import footprint_h_shape

fp = footprint_h_shape(width=40, depth=30, courtyard_width=20, courtyard_depth=10)

footprint_courtyard

┌──────────────────┐
│  ┌────────────┐  │
│  │  courtyard │  │
│  └────────────┘  │
└──────────────────┘
from idfkit.zoning import footprint_courtyard

fp = footprint_courtyard(outer_width=50, outer_depth=40, inner_width=30, inner_depth=20)

Using Footprint Helpers with create_block

All footprint helpers plug directly into create_block:

from idfkit import new_document, create_block, ZoningScheme
from idfkit.zoning import footprint_l_shape

doc = new_document()
create_block(
    doc,
    name="L-Wing",
    footprint=footprint_l_shape(40, 10, 15, 20),
    floor_to_floor=3.5,
    num_stories=2,
    zoning=ZoningScheme.CORE_PERIMETER,
)

ZonedBlock (Describe-then-Apply)

ZonedBlock is a frozen dataclass alternative that validates all parameters up front. Call build() to realise the geometry. This describe-then-apply pattern lets you inspect computed properties before committing to a document.

from idfkit import new_document, ZonedBlock, ZoningScheme
from idfkit.zoning import footprint_rectangle

block = ZonedBlock(
    name="Office",
    footprint=footprint_rectangle(50, 30),
    floor_to_floor=3.5,
    num_stories=3,
    zoning=ZoningScheme.CORE_PERIMETER,
)

print(f"Building height: {block.height} m")              # 10.5
print(f"Floor area: {block.floor_area} m²")               # 1500.0
print(f"Total floor area: {block.total_floor_area} m²")  # 4500.0

doc = new_document()
objects = block.build(doc)
print(len(objects))  # all created Zone + BuildingSurface:Detailed objects

API Reference

Automatic thermal zoning for EnergyPlus models.

Splits a 2-D building footprint into thermal zones using one of several standard schemes and creates all Zone, BuildingSurface:Detailed, and (optionally) Construction:AirBoundary objects needed for simulation.

Three zoning schemes are provided:

  • by_storey - one zone per floor.
  • core_perimeter - four orientation-based perimeter zones plus an interior core zone per floor. Perimeter depth defaults to 4.57 m (15 ft) per ASHRAE 90.1 Appendix G and the DOE prototype buildings.
  • custom - the caller supplies named polygons for each floor.

Footprint helpers for common commercial shapes (rectangle, L, U, T, H, courtyard) are included so users never have to compute vertices by hand.

Examples:

from idfkit import new_document
from idfkit.zoning import (
    ZoningScheme,
    create_block,
    footprint_rectangle,
)

doc = new_document()
zones = create_block(
    doc,
    name="Office",
    footprint=footprint_rectangle(50, 30),
    floor_to_floor=3.5,
    num_stories=3,
    zoning=ZoningScheme.CORE_PERIMETER,
    perimeter_depth=4.57,
)

ASHRAE_PERIMETER_DEPTH = 4.57 module-attribute

ZoneFootprint dataclass

Named 2-D polygon for one thermal zone on one floor.

Source code in idfkit/zoning.py
@dataclass(frozen=True)
class ZoneFootprint:
    """Named 2-D polygon for one thermal zone on one floor."""

    name_suffix: str  # e.g. "Core", "Perimeter_South"
    polygon: list[tuple[float, float]]

name_suffix instance-attribute

polygon instance-attribute

ZonedBlock dataclass

Describes a building block with a zoning strategy.

This is a pure data object. Call build() to realise the geometry in an IDFDocument.

Attributes:

Name Type Description
name str

Base name for zones and surfaces.

footprint Sequence[tuple[float, float]]

2-D footprint as (x, y) tuples, stored counter-clockwise (a clockwise one is reversed).

floor_to_floor float

Floor-to-floor height in metres.

num_stories int

Number of above-ground stories.

zoning ZoningScheme

Zoning strategy.

perimeter_depth float

Perimeter zone depth (metres), used only when zoning is CORE_PERIMETER.

custom_zones list[ZoneFootprint] | None

Per-floor named zone polygons, used only when zoning is CUSTOM.

air_boundary bool

Whether to use Construction:AirBoundary between inter-zone walls.

base_elevation float

Elevation of the ground floor in metres. Use this to stack blocks at different heights for setbacks.

Source code in idfkit/zoning.py
@dataclass(frozen=True)
class ZonedBlock:
    """Describes a building block with a zoning strategy.

    This is a pure data object.  Call `build()` to realise the
    geometry in an [IDFDocument][idfkit.document.IDFDocument].

    Attributes:
        name: Base name for zones and surfaces.
        footprint: 2-D footprint as ``(x, y)`` tuples, stored
            counter-clockwise (a clockwise one is reversed).
        floor_to_floor: Floor-to-floor height in metres.
        num_stories: Number of above-ground stories.
        zoning: Zoning strategy.
        perimeter_depth: Perimeter zone depth (metres), used only
            when ``zoning`` is ``CORE_PERIMETER``.
        custom_zones: Per-floor named zone polygons, used only when
            ``zoning`` is ``CUSTOM``.
        air_boundary: Whether to use ``Construction:AirBoundary``
            between inter-zone walls.
        base_elevation: Elevation of the ground floor in metres.
            Use this to stack blocks at different heights for setbacks.
    """

    name: str
    footprint: Sequence[tuple[float, float]]
    floor_to_floor: float
    num_stories: int = 1
    zoning: ZoningScheme = ZoningScheme.BY_STOREY
    perimeter_depth: float = ASHRAE_PERIMETER_DEPTH
    custom_zones: list[ZoneFootprint] | None = None
    air_boundary: bool = False
    base_elevation: float = 0.0

    def __post_init__(self) -> None:
        # A clockwise footprint would extrude into an inside-out block (walls facing in, floor
        # facing up, roof facing down), which EnergyPlus runs with only warnings; store it CCW.
        object.__setattr__(self, "footprint", counter_clockwise_footprint(self.footprint))
        if self.custom_zones:
            zones = [
                ZoneFootprint(z.name_suffix, counter_clockwise_footprint(z.polygon, f"Zone {z.name_suffix!r} polygon"))
                for z in self.custom_zones
            ]
            object.__setattr__(self, "custom_zones", zones)
        if self.floor_to_floor <= 0:
            msg = f"floor_to_floor must be positive, got {self.floor_to_floor}"
            raise ValueError(msg)
        if self.num_stories < 1:
            msg = f"num_stories must be >= 1, got {self.num_stories}"
            raise ValueError(msg)
        if self.perimeter_depth <= 0:
            msg = f"perimeter_depth must be positive, got {self.perimeter_depth}"
            raise ValueError(msg)
        if self.zoning == ZoningScheme.CUSTOM and not self.custom_zones:
            msg = "custom_zones is required when zoning is CUSTOM"
            raise ValueError(msg)
        if self.base_elevation < 0:
            msg = f"base_elevation must be >= 0, got {self.base_elevation}"
            raise ValueError(msg)

    @property
    def height(self) -> float:
        """Total building height in metres."""
        return self.floor_to_floor * self.num_stories

    @property
    def floor_area(self) -> float:
        """Single-floor footprint area in square metres."""
        return abs(_polygon_area_signed(list(self.footprint)))

    @property
    def total_floor_area(self) -> float:
        """Total floor area across all stories in square metres."""
        return self.floor_area * self.num_stories

    def build(self, doc: AnyIDFDocument) -> list[IDFObject]:
        """Realise the zoned geometry in the document.

        Returns:
            All created [IDFObject][idfkit.objects.IDFObject] instances.

        Raises:
            ValueError: If ``air_boundary`` is set and the document's
                EnergyPlus version has no ``Construction:AirBoundary``
                (versions before 9.2).  Nothing is added to the document.
        """
        # Check before creating any surface, so an unsupported version does
        # not leave the document holding a half-built block.
        # A schema-less document is judged by its version, as _apply_air_boundaries' as_version is.
        has_air_boundary = (
            "Construction:AirBoundary" in doc.schema if doc.schema is not None else doc.version >= (9, 2, 0)
        )
        if self.air_boundary and not has_air_boundary:
            version = version_string(doc.version)
            msg = (
                f"air_boundary=True needs Construction:AirBoundary, which EnergyPlus {version} does not have "
                "(it was added in 9.2); build the block without air_boundary or use a 9.2+ document"
            )
            raise ValueError(msg)

        fp = list(self.footprint)

        # Determine zone layout per floor
        if self.zoning == ZoningScheme.CORE_PERIMETER:
            zone_footprints = _split_core_perimeter(fp, self.perimeter_depth)
        elif self.zoning == ZoningScheme.CUSTOM:
            zone_footprints = self.custom_zones or [ZoneFootprint("Whole", fp)]
        else:  # BY_STOREY
            zone_footprints = [ZoneFootprint("Whole", fp)]

        # Build story specs
        story_specs: list[_StorySpec] = []
        for i in range(self.num_stories):
            z_bot = self.base_elevation + i * self.floor_to_floor
            z_top = self.base_elevation + (i + 1) * self.floor_to_floor
            story_specs.append(_StorySpec(i + 1, z_bot, z_top, zone_footprints))

        # Create surfaces for each story
        created: list[IDFObject] = []
        for spec in story_specs:
            created.extend(
                _build_story_surfaces(
                    doc,
                    self.name,
                    spec,
                    self.num_stories,
                    all_story_specs=story_specs,
                    air_boundary=self.air_boundary,
                )
            )
        return created

air_boundary = False class-attribute instance-attribute

base_elevation = 0.0 class-attribute instance-attribute

custom_zones = None class-attribute instance-attribute

floor_area property

Single-floor footprint area in square metres.

floor_to_floor instance-attribute

footprint instance-attribute

height property

Total building height in metres.

name instance-attribute

num_stories = 1 class-attribute instance-attribute

perimeter_depth = ASHRAE_PERIMETER_DEPTH class-attribute instance-attribute

total_floor_area property

Total floor area across all stories in square metres.

zoning = ZoningScheme.BY_STOREY class-attribute instance-attribute

build(doc)

Realise the zoned geometry in the document.

Returns:

Type Description
list[IDFObject]

All created IDFObject instances.

Raises:

Type Description
ValueError

If air_boundary is set and the document's EnergyPlus version has no Construction:AirBoundary (versions before 9.2). Nothing is added to the document.

Source code in idfkit/zoning.py
def build(self, doc: AnyIDFDocument) -> list[IDFObject]:
    """Realise the zoned geometry in the document.

    Returns:
        All created [IDFObject][idfkit.objects.IDFObject] instances.

    Raises:
        ValueError: If ``air_boundary`` is set and the document's
            EnergyPlus version has no ``Construction:AirBoundary``
            (versions before 9.2).  Nothing is added to the document.
    """
    # Check before creating any surface, so an unsupported version does
    # not leave the document holding a half-built block.
    # A schema-less document is judged by its version, as _apply_air_boundaries' as_version is.
    has_air_boundary = (
        "Construction:AirBoundary" in doc.schema if doc.schema is not None else doc.version >= (9, 2, 0)
    )
    if self.air_boundary and not has_air_boundary:
        version = version_string(doc.version)
        msg = (
            f"air_boundary=True needs Construction:AirBoundary, which EnergyPlus {version} does not have "
            "(it was added in 9.2); build the block without air_boundary or use a 9.2+ document"
        )
        raise ValueError(msg)

    fp = list(self.footprint)

    # Determine zone layout per floor
    if self.zoning == ZoningScheme.CORE_PERIMETER:
        zone_footprints = _split_core_perimeter(fp, self.perimeter_depth)
    elif self.zoning == ZoningScheme.CUSTOM:
        zone_footprints = self.custom_zones or [ZoneFootprint("Whole", fp)]
    else:  # BY_STOREY
        zone_footprints = [ZoneFootprint("Whole", fp)]

    # Build story specs
    story_specs: list[_StorySpec] = []
    for i in range(self.num_stories):
        z_bot = self.base_elevation + i * self.floor_to_floor
        z_top = self.base_elevation + (i + 1) * self.floor_to_floor
        story_specs.append(_StorySpec(i + 1, z_bot, z_top, zone_footprints))

    # Create surfaces for each story
    created: list[IDFObject] = []
    for spec in story_specs:
        created.extend(
            _build_story_surfaces(
                doc,
                self.name,
                spec,
                self.num_stories,
                all_story_specs=story_specs,
                air_boundary=self.air_boundary,
            )
        )
    return created

ZoningScheme

Bases: Enum

Thermal zoning strategy.

Attributes:

Name Type Description
BY_STOREY

One zone per floor.

CORE_PERIMETER

Core + 4 perimeter zones per floor.

CUSTOM

User-supplied zone polygons per floor.

Source code in idfkit/zoning.py
class ZoningScheme(enum.Enum):
    """Thermal zoning strategy.

    Attributes:
        BY_STOREY: One zone per floor.
        CORE_PERIMETER: Core + 4 perimeter zones per floor.
        CUSTOM: User-supplied zone polygons per floor.
    """

    BY_STOREY = "by_storey"
    CORE_PERIMETER = "core_perimeter"
    CUSTOM = "custom"

BY_STOREY = 'by_storey' class-attribute instance-attribute

CORE_PERIMETER = 'core_perimeter' class-attribute instance-attribute

CUSTOM = 'custom' class-attribute instance-attribute

create_block(doc, name, footprint, floor_to_floor, num_stories=1, *, zoning=ZoningScheme.BY_STOREY, perimeter_depth=ASHRAE_PERIMETER_DEPTH, custom_zones=None, air_boundary=False, base_elevation=0.0)

Create a fully-zoned building block in one call.

This is the primary entry point for the zoning module. It combines footprint definition, zoning strategy, and multi-story extrusion into a single function call.

For setback buildings, create multiple blocks at different elevations and link them with link_blocks.

Parameters:

Name Type Description Default
doc AnyIDFDocument

The document to add objects to.

required
name str

Base name for zones and surfaces (e.g. "Office").

required
footprint Sequence[tuple[float, float]]

2-D footprint as (x, y) tuples. Counter-clockwise is expected; a clockwise footprint is reversed, so the block is never built inside-out.

required
floor_to_floor float

Floor-to-floor height in metres.

required
num_stories int

Number of above-ground stories.

1
zoning ZoningScheme

Zoning strategy (default: one zone per floor).

BY_STOREY
perimeter_depth float

Depth of perimeter zones in metres. Only used when zoning is CORE_PERIMETER. Defaults to 4.57 m (ASHRAE 90.1 / DOE prototypes).

ASHRAE_PERIMETER_DEPTH
custom_zones list[ZoneFootprint] | None

Named zone polygons, required when zoning is CUSTOM.

None
air_boundary bool

If True, apply Construction:AirBoundary to all inter-zone walls (for open-plan spaces).

False
base_elevation float

Elevation of the ground floor in metres. Defaults to 0. When > 0, the ground-floor boundary condition is Outdoors instead of Ground.

0.0

Returns:

Type Description
list[IDFObject]

All created IDFObject instances.

Raises:

Type Description
ValueError

If air_boundary is True and the document's EnergyPlus version is older than 9.2, which has no Construction:AirBoundary, or if the footprint has fewer than 3 vertices or no area.

Examples:

Core-perimeter zoning for a 3-story office:

```python
from idfkit import new_document
from idfkit.zoning import (
    ZoningScheme,
    create_block,
    footprint_rectangle,
)

doc = new_document()
create_block(
    doc,
    name="Office",
    footprint=footprint_rectangle(50, 30),
    floor_to_floor=3.5,
    num_stories=3,
    zoning=ZoningScheme.CORE_PERIMETER,
)
```
Source code in idfkit/zoning.py
def create_block(
    doc: AnyIDFDocument,
    name: str,
    footprint: Sequence[tuple[float, float]],
    floor_to_floor: float,
    num_stories: int = 1,
    *,
    zoning: ZoningScheme = ZoningScheme.BY_STOREY,
    perimeter_depth: float = ASHRAE_PERIMETER_DEPTH,
    custom_zones: list[ZoneFootprint] | None = None,
    air_boundary: bool = False,
    base_elevation: float = 0.0,
) -> list[IDFObject]:
    """Create a fully-zoned building block in one call.

    This is the primary entry point for the zoning module.  It combines
    footprint definition, zoning strategy, and multi-story extrusion into
    a single function call.

    For setback buildings, create multiple blocks at different elevations
    and link them with [link_blocks][idfkit.zoning.link_blocks].

    Args:
        doc: The document to add objects to.
        name: Base name for zones and surfaces (e.g. ``"Office"``).
        footprint: 2-D footprint as ``(x, y)`` tuples.  Counter-clockwise
            is expected; a clockwise footprint is reversed, so the block is
            never built inside-out.
        floor_to_floor: Floor-to-floor height in metres.
        num_stories: Number of above-ground stories.
        zoning: Zoning strategy (default: one zone per floor).
        perimeter_depth: Depth of perimeter zones in metres.
            Only used when ``zoning`` is ``CORE_PERIMETER``.
            Defaults to 4.57 m (ASHRAE 90.1 / DOE prototypes).
        custom_zones: Named zone polygons, required when ``zoning``
            is ``CUSTOM``.
        air_boundary: If ``True``, apply ``Construction:AirBoundary``
            to all inter-zone walls (for open-plan spaces).
        base_elevation: Elevation of the ground floor in metres.
            Defaults to 0.  When > 0, the ground-floor boundary
            condition is ``Outdoors`` instead of ``Ground``.

    Returns:
        All created [IDFObject][idfkit.objects.IDFObject] instances.

    Raises:
        ValueError: If ``air_boundary`` is ``True`` and the document's
            EnergyPlus version is older than 9.2, which has no
            ``Construction:AirBoundary``, or if the footprint has fewer
            than 3 vertices or no area.

    Examples:
        Core-perimeter zoning for a 3-story office:

            ```python
            from idfkit import new_document
            from idfkit.zoning import (
                ZoningScheme,
                create_block,
                footprint_rectangle,
            )

            doc = new_document()
            create_block(
                doc,
                name="Office",
                footprint=footprint_rectangle(50, 30),
                floor_to_floor=3.5,
                num_stories=3,
                zoning=ZoningScheme.CORE_PERIMETER,
            )
            ```
    """
    block = ZonedBlock(
        name=name,
        footprint=footprint,
        floor_to_floor=floor_to_floor,
        num_stories=num_stories,
        zoning=zoning,
        perimeter_depth=perimeter_depth,
        custom_zones=custom_zones,
        air_boundary=air_boundary,
        base_elevation=base_elevation,
    )
    return block.build(doc)

create_courtyard_block(doc, name, outer, courtyards, floor_to_floor, num_stories=1, *, air_boundary=False, base_elevation=0.0)

Create a block with one or more courtyards cut out of its footprint.

EnergyPlus surfaces cannot have holes, so the footprint outer minus courtyards is split into hole-free pieces with polygon_difference_parts_2d and each piece becomes one zone per story, named "<name> Part <k>" ("<name> Story <n> Part <k>" for several stories), largest piece first. The pieces are built as CUSTOM zones of a single block, so the walls along the cuts between pieces are interior walls (Surface boundary, paired with the neighbouring piece's wall) rather than exterior walls, and the courtyard facades are exterior walls. The pieces come from one planar overlay, so wherever two of them touch they carry the same vertices, which is what the reversed-edge wall pairing needs. No surface has repeated or coincident vertices.

Parameters:

Name Type Description Default
doc AnyIDFDocument

The document to add objects to.

required
name str

Base name for zones and surfaces.

required
outer Sequence[tuple[float, float]]

Outer 2-D footprint as (x, y) tuples (CCW).

required
courtyards Sequence[Sequence[tuple[float, float]]]

Polygons to cut out of outer. They may touch or cross the outer boundary, which leaves a notch instead of a hole.

required
floor_to_floor float

Floor-to-floor height in metres.

required
num_stories int

Number of above-ground stories.

1
air_boundary bool

If True, apply Construction:AirBoundary to the walls between pieces, so the ring behaves as one open space.

False
base_elevation float

Elevation of the ground floor in metres.

0.0

Returns:

Type Description
list[IDFObject]

All created IDFObject instances.

Raises:

Type Description
ValueError

If outer or a courtyard has fewer than three vertices (for example a single polygon passed as courtyards instead of a list of polygons), or if the courtyards cover the whole footprint, or if air_boundary is True and the document's EnergyPlus version is older than 9.2, which has no Construction:AirBoundary.

Examples:

A 50 x 40 m block around a centred 20 x 10 m courtyard:

```python
from idfkit import new_document
from idfkit.zoning import create_courtyard_block, footprint_rectangle

doc = new_document()
create_courtyard_block(
    doc,
    "Office",
    footprint_rectangle(50, 40),
    [footprint_rectangle(20, 10, origin=(15, 15))],
    floor_to_floor=3.5,
    num_stories=2,
)
```
Source code in idfkit/zoning.py
def create_courtyard_block(
    doc: AnyIDFDocument,
    name: str,
    outer: Sequence[tuple[float, float]],
    courtyards: Sequence[Sequence[tuple[float, float]]],
    floor_to_floor: float,
    num_stories: int = 1,
    *,
    air_boundary: bool = False,
    base_elevation: float = 0.0,
) -> list[IDFObject]:
    """Create a block with one or more courtyards cut out of its footprint.

    EnergyPlus surfaces cannot have holes, so the footprint ``outer`` minus
    ``courtyards`` is split into hole-free pieces with
    [polygon_difference_parts_2d][idfkit.geometry.polygon_difference_parts_2d]
    and each piece becomes one zone per story, named
    ``"<name> Part <k>"`` (``"<name> Story <n> Part <k>"`` for several
    stories), largest piece first.  The pieces are built as ``CUSTOM``
    zones of a single block, so the walls along the cuts between pieces
    are interior walls (``Surface`` boundary, paired with the neighbouring
    piece's wall) rather than exterior walls, and the courtyard facades are
    exterior walls.  The pieces come from one planar overlay, so wherever
    two of them touch they carry the same vertices, which is what the
    reversed-edge wall pairing needs.  No surface has repeated or
    coincident vertices.

    Args:
        doc: The document to add objects to.
        name: Base name for zones and surfaces.
        outer: Outer 2-D footprint as ``(x, y)`` tuples (CCW).
        courtyards: Polygons to cut out of *outer*.  They may touch or
            cross the outer boundary, which leaves a notch instead of a hole.
        floor_to_floor: Floor-to-floor height in metres.
        num_stories: Number of above-ground stories.
        air_boundary: If ``True``, apply ``Construction:AirBoundary`` to
            the walls between pieces, so the ring behaves as one open space.
        base_elevation: Elevation of the ground floor in metres.

    Returns:
        All created [IDFObject][idfkit.objects.IDFObject] instances.

    Raises:
        ValueError: If *outer* or a courtyard has fewer than three
            vertices (for example a single polygon passed as
            *courtyards* instead of a list of polygons), or if the
            courtyards cover the whole footprint, or if ``air_boundary``
            is ``True`` and the document's EnergyPlus version is older
            than 9.2, which has no ``Construction:AirBoundary``.

    Examples:
        A 50 x 40 m block around a centred 20 x 10 m courtyard:

            ```python
            from idfkit import new_document
            from idfkit.zoning import create_courtyard_block, footprint_rectangle

            doc = new_document()
            create_courtyard_block(
                doc,
                "Office",
                footprint_rectangle(50, 40),
                [footprint_rectangle(20, 10, origin=(15, 15))],
                floor_to_floor=3.5,
                num_stories=2,
            )
            ```
    """
    if len(outer) < 3:
        msg = f"create_courtyard_block: outer must have at least 3 vertices, got {len(outer)}"
        raise ValueError(msg)
    for k, courtyard in enumerate(courtyards):
        # A single polygon passed instead of a list of polygons unpacks into
        # (x, y) points here; each would subtract nothing and the block would
        # silently be built without its courtyard.
        if len(courtyard) < 3 or any(len(p) != 2 for p in courtyard):
            msg = (
                f"create_courtyard_block: courtyards[{k}] is not a polygon of at least 3 (x, y) vertices; "
                "pass a list of polygons, e.g. [footprint_rectangle(...)]"
            )
            raise ValueError(msg)
    parts = polygon_difference_parts_2d(outer, *courtyards)
    if not parts:
        msg = "create_courtyard_block: the courtyards cover the whole footprint"
        raise ValueError(msg)
    block = ZonedBlock(
        name=name,
        footprint=outer,
        floor_to_floor=floor_to_floor,
        num_stories=num_stories,
        zoning=ZoningScheme.CUSTOM,
        custom_zones=[ZoneFootprint(f"Part {k + 1}", part) for k, part in enumerate(parts)],
        air_boundary=air_boundary,
        base_elevation=base_elevation,
    )
    return block.build(doc)

footprint_courtyard(outer_width, outer_depth, inner_width, inner_depth, origin=(0.0, 0.0))

Return a courtyard (donut) footprint as a single slit polygon.

Deprecated

Use footprint_courtyard_parts for hole-free pieces, or create_courtyard_block to build the block directly. This function emits a DeprecationWarning and will be removed in a future release.

The polygon traces the outer boundary counter-clockwise, steps into the courtyard through a zero-width slit from the left edge, traces the courtyard clockwise, and returns along the slit. The area is right, but the slit vertex appears twice and the slit is traversed in both directions, so create_block turns it into two overlapping, opposite-facing exterior walls and a self-touching floor and roof, which EnergyPlus rejects. EnergyPlus surfaces cannot have holes, so a courtyard has to be split into several simple pieces.

```text
┌──────────────────┐
│  ┌────────────┐  │
│  │  courtyard │  │
│  └────────────┘  │
└──────────────────┘
```

Parameters:

Name Type Description Default
outer_width float

Outer bounding box width (X).

required
outer_depth float

Outer bounding box depth (Y).

required
inner_width float

Courtyard width (X), must be < outer_width.

required
inner_depth float

Courtyard depth (Y), must be < outer_depth.

required
origin tuple[float, float]

(x, y) of the lower-left corner.

(0.0, 0.0)
Source code in idfkit/zoning.py
def footprint_courtyard(
    outer_width: float,
    outer_depth: float,
    inner_width: float,
    inner_depth: float,
    origin: tuple[float, float] = (0.0, 0.0),
) -> list[tuple[float, float]]:
    """Return a courtyard (donut) footprint as a single slit polygon.

    !!! warning "Deprecated"
        Use [footprint_courtyard_parts][idfkit.zoning.footprint_courtyard_parts]
        for hole-free pieces, or
        [create_courtyard_block][idfkit.zoning.create_courtyard_block] to build
        the block directly.  This function emits a ``DeprecationWarning`` and
        will be removed in a future release.

    The polygon traces the outer boundary counter-clockwise, steps into
    the courtyard through a zero-width slit from the left edge, traces the
    courtyard clockwise, and returns along the slit.  The area is right,
    but the slit vertex appears twice and the slit is traversed in both
    directions, so [create_block][idfkit.zoning.create_block] turns it into
    two overlapping, opposite-facing exterior walls and a self-touching
    floor and roof, which EnergyPlus rejects.  EnergyPlus surfaces cannot
    have holes, so a courtyard has to be split into several simple pieces.

        ```text
        ┌──────────────────┐
        │  ┌────────────┐  │
        │  │  courtyard │  │
        │  └────────────┘  │
        └──────────────────┘
        ```

    Args:
        outer_width: Outer bounding box width (X).
        outer_depth: Outer bounding box depth (Y).
        inner_width: Courtyard width (X), must be < *outer_width*.
        inner_depth: Courtyard depth (Y), must be < *outer_depth*.
        origin: ``(x, y)`` of the lower-left corner.
    """
    warnings.warn(
        "footprint_courtyard() returns a slit polygon that create_block() turns into overlapping walls; "
        "use idfkit.zoning.footprint_courtyard_parts() or idfkit.zoning.create_courtyard_block() instead",
        DeprecationWarning,
        stacklevel=2,
    )
    _check_courtyard_dims(outer_width, outer_depth, inner_width, inner_depth)
    x, y = origin
    ix0, iy0 = _courtyard_inner_origin(outer_width, outer_depth, inner_width, inner_depth, origin)
    ix1 = ix0 + inner_width
    iy1 = iy0 + inner_depth
    return [
        # Outer rectangle (CCW)
        (x, y),
        (x + outer_width, y),
        (x + outer_width, y + outer_depth),
        (x, y + outer_depth),
        # Slit down to inner (from outer top-left back down to inner)
        (x, iy0),  # slit entry
        # Inner rectangle (CW to cut a hole)
        (ix0, iy0),
        (ix0, iy1),
        (ix1, iy1),
        (ix1, iy0),
        # Slit back out
        (x, iy0),  # slit exit (same point, degenerate edge)
    ]

footprint_courtyard_parts(outer_width, outer_depth, inner_width, inner_depth, origin=(0.0, 0.0))

Return a centred-courtyard footprint as hole-free pieces.

EnergyPlus surfaces cannot have holes, so the ring around the courtyard is cut by a vertical line through the courtyard's centre into two U-shaped halves. The pieces are simple, counter-clockwise, free of repeated or coincident vertices, and do not overlap; their areas add up to outer_width * outer_depth - inner_width * inner_depth. The two cut edges are shared exactly, so passing the pieces as CUSTOM zones of one block (which create_courtyard_block does) makes them interior walls.

```text
┌─────────┬─────────┐
│  ┌──────┴──────┐  │
│  │  courtyard  │  │
│  └──────┬──────┘  │
└─────────┴─────────┘
```

Parameters:

Name Type Description Default
outer_width float

Outer bounding box width (X).

required
outer_depth float

Outer bounding box depth (Y).

required
inner_width float

Courtyard width (X), must be < outer_width.

required
inner_depth float

Courtyard depth (Y), must be < outer_depth.

required
origin tuple[float, float]

(x, y) of the lower-left corner.

(0.0, 0.0)

Returns:

Type Description
list[list[tuple[float, float]]]

The pieces, largest first.

Examples:

>>> from idfkit.geometry import polygon_area_2d
>>> parts = footprint_courtyard_parts(50, 40, 20, 10)
>>> parts[0]
[(0.0, 0.0), (25.0, 0.0), (25.0, 15.0), (15.0, 15.0), (15.0, 25.0), (25.0, 25.0), (25.0, 40.0), (0.0, 40.0)]
>>> sum(polygon_area_2d(p) for p in parts)
1800.0
Source code in idfkit/zoning.py
def footprint_courtyard_parts(
    outer_width: float,
    outer_depth: float,
    inner_width: float,
    inner_depth: float,
    origin: tuple[float, float] = (0.0, 0.0),
) -> list[list[tuple[float, float]]]:
    """Return a centred-courtyard footprint as hole-free pieces.

    EnergyPlus surfaces cannot have holes, so the ring around the
    courtyard is cut by a vertical line through the courtyard's centre
    into two U-shaped halves.  The pieces are simple, counter-clockwise,
    free of repeated or coincident vertices, and do not overlap; their
    areas add up to ``outer_width * outer_depth - inner_width * inner_depth``.
    The two cut edges are shared exactly, so passing the pieces as
    ``CUSTOM`` zones of one block (which
    [create_courtyard_block][idfkit.zoning.create_courtyard_block] does)
    makes them interior walls.

        ```text
        ┌─────────┬─────────┐
        │  ┌──────┴──────┐  │
        │  │  courtyard  │  │
        │  └──────┬──────┘  │
        └─────────┴─────────┘
        ```

    Args:
        outer_width: Outer bounding box width (X).
        outer_depth: Outer bounding box depth (Y).
        inner_width: Courtyard width (X), must be < *outer_width*.
        inner_depth: Courtyard depth (Y), must be < *outer_depth*.
        origin: ``(x, y)`` of the lower-left corner.

    Returns:
        The pieces, largest first.

    Examples:
        >>> from idfkit.geometry import polygon_area_2d
        >>> parts = footprint_courtyard_parts(50, 40, 20, 10)
        >>> parts[0]
        [(0.0, 0.0), (25.0, 0.0), (25.0, 15.0), (15.0, 15.0), (15.0, 25.0), (25.0, 25.0), (25.0, 40.0), (0.0, 40.0)]
        >>> sum(polygon_area_2d(p) for p in parts)
        1800.0
    """
    for label, value in (("inner_width", inner_width), ("inner_depth", inner_depth)):
        if value <= 0:
            msg = f"{label} ({value}) must be > 0"
            raise ValueError(msg)
    _check_courtyard_dims(outer_width, outer_depth, inner_width, inner_depth)
    outer = footprint_rectangle(outer_width, outer_depth, origin)
    inner_origin = _courtyard_inner_origin(outer_width, outer_depth, inner_width, inner_depth, origin)
    inner = footprint_rectangle(inner_width, inner_depth, inner_origin)
    return [[(float(px), float(py)) for px, py in part] for part in polygon_difference_parts_2d(outer, inner)]

footprint_h_shape(width, depth, courtyard_width, courtyard_depth, origin=(0.0, 0.0))

Return an H-shaped footprint (counter-clockwise).

Two symmetrical courtyards are cut from the left and right sides of the bounding rectangle.

```text
┌──────┐    ┌──────┐
│      └────┘      │
│     connector    │
│      ┌────┐      │
└──────┘    └──────┘
```

Parameters:

Name Type Description Default
width float

Overall width (X).

required
depth float

Overall depth (Y).

required
courtyard_width float

Width of each courtyard notch (X).

required
courtyard_depth float

Depth of each courtyard notch (Y).

required
origin tuple[float, float]

(x, y) of the lower-left corner.

(0.0, 0.0)
Source code in idfkit/zoning.py
def footprint_h_shape(
    width: float,
    depth: float,
    courtyard_width: float,
    courtyard_depth: float,
    origin: tuple[float, float] = (0.0, 0.0),
) -> list[tuple[float, float]]:
    """Return an H-shaped footprint (counter-clockwise).

    Two symmetrical courtyards are cut from the left and right sides of
    the bounding rectangle.

        ```text
        ┌──────┐    ┌──────┐
        │      └────┘      │
        │     connector    │
        │      ┌────┐      │
        └──────┘    └──────┘
        ```

    Args:
        width: Overall width (X).
        depth: Overall depth (Y).
        courtyard_width: Width of each courtyard notch (X).
        courtyard_depth: Depth of each courtyard notch (Y).
        origin: ``(x, y)`` of the lower-left corner.
    """
    if courtyard_width >= width:
        msg = f"courtyard_width ({courtyard_width}) must be < width ({width})"
        raise ValueError(msg)
    if 2 * courtyard_depth >= depth:
        msg = f"2 * courtyard_depth ({2 * courtyard_depth}) must be < depth ({depth})"
        raise ValueError(msg)
    x, y = origin
    w2 = (width - courtyard_width) / 2
    cy_bot_top = y + courtyard_depth
    cy_top_bot = y + depth - courtyard_depth
    cx_left = x + w2
    cx_right = x + w2 + courtyard_width
    return [
        (x, y),
        (cx_left, y),
        (cx_left, cy_bot_top),
        (cx_right, cy_bot_top),
        (cx_right, y),
        (x + width, y),
        (x + width, y + depth),
        (cx_right, y + depth),
        (cx_right, cy_top_bot),
        (cx_left, cy_top_bot),
        (cx_left, y + depth),
        (x, y + depth),
    ]

footprint_l_shape(width, depth, wing_width, wing_depth, origin=(0.0, 0.0))

Return an L-shaped footprint (counter-clockwise).

The base rectangle runs from the origin along width (X) and depth (Y). A shorter wing extends upward from the left side with dimensions wing_width x wing_depth.

```text
┌────────┐
│  wing  │
│        │
├────────┴──────────┐
│      base         │
└───────────────────┘
```

Parameters:

Name Type Description Default
width float

Base width (X).

required
depth float

Base depth (Y).

required
wing_width float

Wing width (X), must be <= width.

required
wing_depth float

Wing depth (Y), added above the base.

required
origin tuple[float, float]

(x, y) of the lower-left corner.

(0.0, 0.0)
Source code in idfkit/zoning.py
def footprint_l_shape(
    width: float,
    depth: float,
    wing_width: float,
    wing_depth: float,
    origin: tuple[float, float] = (0.0, 0.0),
) -> list[tuple[float, float]]:
    """Return an L-shaped footprint (counter-clockwise).

    The *base* rectangle runs from the origin along ``width`` (X) and
    ``depth`` (Y).  A shorter wing extends upward from the left side
    with dimensions ``wing_width`` x ``wing_depth``.

        ```text
        ┌────────┐
        │  wing  │
        │        │
        ├────────┴──────────┐
        │      base         │
        └───────────────────┘
        ```

    Args:
        width: Base width (X).
        depth: Base depth (Y).
        wing_width: Wing width (X), must be <= *width*.
        wing_depth: Wing depth (Y), added above the base.
        origin: ``(x, y)`` of the lower-left corner.
    """
    if wing_width > width:
        msg = f"wing_width ({wing_width}) must be <= width ({width})"
        raise ValueError(msg)
    x, y = origin
    return [
        (x, y),
        (x + width, y),
        (x + width, y + depth),
        (x + wing_width, y + depth),
        (x + wing_width, y + depth + wing_depth),
        (x, y + depth + wing_depth),
    ]

footprint_rectangle(width, depth, origin=(0.0, 0.0))

Return a rectangular footprint (counter-clockwise).

Parameters:

Name Type Description Default
width float

Dimension along the X axis (metres).

required
depth float

Dimension along the Y axis (metres).

required
origin tuple[float, float]

(x, y) of the lower-left corner.

(0.0, 0.0)
Source code in idfkit/zoning.py
def footprint_rectangle(
    width: float,
    depth: float,
    origin: tuple[float, float] = (0.0, 0.0),
) -> list[tuple[float, float]]:
    """Return a rectangular footprint (counter-clockwise).

    Args:
        width: Dimension along the X axis (metres).
        depth: Dimension along the Y axis (metres).
        origin: ``(x, y)`` of the lower-left corner.
    """
    x, y = origin
    return [(x, y), (x + width, y), (x + width, y + depth), (x, y + depth)]

footprint_t_shape(base_width, base_depth, top_width, top_depth, origin=(0.0, 0.0))

Return a T-shaped footprint (counter-clockwise).

A narrower base rectangle is centred below a wider top bar.

```text
┌──────────────────────┐
│       top bar        │
└───┐              ┌───┘
    │    base      │
    └──────────────┘
```

Parameters:

Name Type Description Default
base_width float

Width of the stem (X).

required
base_depth float

Depth of the stem (Y).

required
top_width float

Width of the top bar (X), must be >= base_width.

required
top_depth float

Depth of the top bar (Y).

required
origin tuple[float, float]

(x, y) of the lower-left corner of the stem.

(0.0, 0.0)
Source code in idfkit/zoning.py
def footprint_t_shape(
    base_width: float,
    base_depth: float,
    top_width: float,
    top_depth: float,
    origin: tuple[float, float] = (0.0, 0.0),
) -> list[tuple[float, float]]:
    """Return a T-shaped footprint (counter-clockwise).

    A narrower base rectangle is centred below a wider top bar.

        ```text
        ┌──────────────────────┐
        │       top bar        │
        └───┐              ┌───┘
            │    base      │
            └──────────────┘
        ```

    Args:
        base_width: Width of the stem (X).
        base_depth: Depth of the stem (Y).
        top_width: Width of the top bar (X), must be >= *base_width*.
        top_depth: Depth of the top bar (Y).
        origin: ``(x, y)`` of the lower-left corner of the stem.
    """
    if top_width < base_width:
        msg = f"top_width ({top_width}) must be >= base_width ({base_width})"
        raise ValueError(msg)
    x, y = origin
    overhang = (top_width - base_width) / 2
    return [
        (x, y),
        (x + base_width, y),
        (x + base_width, y + base_depth),
        (x + base_width + overhang, y + base_depth),
        (x + base_width + overhang, y + base_depth + top_depth),
        (x - overhang, y + base_depth + top_depth),
        (x - overhang, y + base_depth),
        (x, y + base_depth),
    ]

footprint_u_shape(width, depth, courtyard_width, courtyard_depth, origin=(0.0, 0.0))

Return a U-shaped footprint (counter-clockwise).

The overall bounding box is width x depth. A rectangular courtyard is cut from the top centre of the footprint.

```text
┌──────┐    ┌──────┐
│      │    │      │
│      └────┘      │
│                  │
└──────────────────┘
```

Parameters:

Name Type Description Default
width float

Overall width (X).

required
depth float

Overall depth (Y).

required
courtyard_width float

Width of the courtyard opening (X).

required
courtyard_depth float

Depth of the courtyard from the top edge (Y).

required
origin tuple[float, float]

(x, y) of the lower-left corner.

(0.0, 0.0)
Source code in idfkit/zoning.py
def footprint_u_shape(
    width: float,
    depth: float,
    courtyard_width: float,
    courtyard_depth: float,
    origin: tuple[float, float] = (0.0, 0.0),
) -> list[tuple[float, float]]:
    """Return a U-shaped footprint (counter-clockwise).

    The overall bounding box is ``width`` x ``depth``.  A rectangular
    courtyard is cut from the top centre of the footprint.

        ```text
        ┌──────┐    ┌──────┐
        │      │    │      │
        │      └────┘      │
        │                  │
        └──────────────────┘
        ```

    Args:
        width: Overall width (X).
        depth: Overall depth (Y).
        courtyard_width: Width of the courtyard opening (X).
        courtyard_depth: Depth of the courtyard from the top edge (Y).
        origin: ``(x, y)`` of the lower-left corner.
    """
    if courtyard_width >= width:
        msg = f"courtyard_width ({courtyard_width}) must be < width ({width})"
        raise ValueError(msg)
    if courtyard_depth >= depth:
        msg = f"courtyard_depth ({courtyard_depth}) must be < depth ({depth})"
        raise ValueError(msg)
    x, y = origin
    cx_left = x + (width - courtyard_width) / 2
    cx_right = cx_left + courtyard_width
    cy_bottom = y + depth - courtyard_depth
    return [
        (x, y),
        (x + width, y),
        (x + width, y + depth),
        (cx_right, y + depth),
        (cx_right, cy_bottom),
        (cx_left, cy_bottom),
        (cx_left, y + depth),
        (x, y + depth),
    ]
link_blocks(doc: AnyIDFDocument) -> list[IDFObject]
link_blocks(
    doc: AnyIDFDocument, lower: str, upper: str
) -> list[IDFObject]

Link stacked building blocks at shared elevations.

Detects roof and floor surfaces at matching elevations, splits surfaces where the footprints differ, and sets Surface boundary conditions between the resulting ceiling/floor pairs.

Can be called in two ways:

  • link_blocks(doc) — auto-detect all stacked blocks.
  • link_blocks(doc, "Base", "Tower") — link only the named blocks (surfaces whose zone name starts with the given prefix).

Uses the lower-level detect_horizontal_adjacencies, split_horizontal_surface_by_regions, and link_horizontal_surfaces functions.

Parameters:

Name Type Description Default
doc AnyIDFDocument

The document containing the blocks.

required
lower str | None

Optional name prefix for the lower block.

None
upper str | None

Optional name prefix for the upper block.

None

Returns:

Type Description
list[IDFObject]

All created or modified surface objects.

Examples:

Setback building with a podium and tower:

```python
from idfkit import new_document
from idfkit.zoning import create_block, link_blocks, footprint_rectangle

doc = new_document()
create_block(doc, "Base", footprint_rectangle(50, 30), 3.5, num_stories=5)
create_block(doc, "Tower", footprint_rectangle(40, 24), 3.5, num_stories=3, base_elevation=17.5)
linked = link_blocks(doc)
```
Source code in idfkit/zoning.py
def link_blocks(
    doc: AnyIDFDocument,
    lower: str | None = None,
    upper: str | None = None,
) -> list[IDFObject]:
    """Link stacked building blocks at shared elevations.

    Detects roof and floor surfaces at matching elevations, splits
    surfaces where the footprints differ, and sets ``Surface`` boundary
    conditions between the resulting ceiling/floor pairs.

    Can be called in two ways:

    * ``link_blocks(doc)`` — auto-detect all stacked blocks.
    * ``link_blocks(doc, "Base", "Tower")`` — link only the named
      blocks (surfaces whose zone name starts with the given prefix).

    Uses the lower-level [detect_horizontal_adjacencies][idfkit.geometry_builders.detect_horizontal_adjacencies],
    [split_horizontal_surface_by_regions][idfkit.geometry_builders.split_horizontal_surface_by_regions], and
    [link_horizontal_surfaces][idfkit.geometry_builders.link_horizontal_surfaces] functions.

    Args:
        doc: The document containing the blocks.
        lower: Optional name prefix for the lower block.
        upper: Optional name prefix for the upper block.

    Returns:
        All created or modified surface objects.

    Examples:
        Setback building with a podium and tower:

            ```python
            from idfkit import new_document
            from idfkit.zoning import create_block, link_blocks, footprint_rectangle

            doc = new_document()
            create_block(doc, "Base", footprint_rectangle(50, 30), 3.5, num_stories=5)
            create_block(doc, "Tower", footprint_rectangle(40, 24), 3.5, num_stories=3, base_elevation=17.5)
            linked = link_blocks(doc)
            ```
    """
    if (lower is None) != (upper is None):
        msg = "lower and upper must both be provided or both omitted"
        raise ValueError(msg)

    adjacencies = detect_horizontal_adjacencies(doc)

    # Filter by block name prefix if specified
    if lower is not None and upper is not None:
        adjacencies = [
            adj
            for adj in adjacencies
            if (getattr(adj.roof_surface, "zone_name", "") or "").startswith(lower)
            and (getattr(adj.floor_surface, "zone_name", "") or "").startswith(upper)
        ]

    if not adjacencies:
        return []

    # Group the adjacencies by roof surface so each roof is split under all
    # of its overlapping floors in one step.  Splitting one region at a time
    # would cut the remainder around the first region before the others are
    # known, and a later region could then straddle two remainder pieces.
    by_roof: dict[int, list[HorizontalAdjacency]] = {}
    for adj in adjacencies:
        by_roof.setdefault(id(adj.roof_surface), []).append(adj)

    modified: list[IDFObject] = []
    for group in by_roof.values():
        roof = group[0].roof_surface
        ceilings, remaining = split_horizontal_surface_by_regions(doc, roof, [adj.intersection for adj in group])
        for new_ceiling, adj in zip(ceilings, group, strict=True):
            # Link the new ceiling to the floor surface
            link_horizontal_surfaces(new_ceiling, adj.floor_surface)
            modified.append(new_ceiling)
            modified.append(adj.floor_surface)
        modified.extend(remaining)

    return modified

See Also

  • Geometry Builders -- Shading blocks, horizontal adjacency detection, surface splitting, and utility functions
  • Geometry -- Lower-level 3D primitives, coordinate transforms, and surface intersection
  • Visualization -- 3D rendering of building geometry