Skip to content

Geometry Builders

Geometry utility functions for EnergyPlus surface manipulation. For creating building zones and surfaces, see Zoning.

Not in JavaScript yet

Building and transforming geometry is available in Python and is not in JavaScript today. A temporary gap, not a boundary. The port is tracked in idfkit-js#14.

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

Quick Start

from idfkit import new_document
from idfkit.geometry_builders import add_shading_block

doc = new_document()
add_shading_block(doc, "Neighbour", [(30, 0), (50, 0), (50, 20), (30, 20)], height=25)

print(len(doc["Shading:Site:Detailed"]))  # 5

Shading Blocks

add_shading_block creates Shading:Site:Detailed surfaces -- opaque boxes that cast shadows but have no thermal zones.

from idfkit import new_document
from idfkit.geometry_builders import add_shading_block

doc = new_document()

# Neighbouring building
add_shading_block(doc, "Neighbour", [(30, 0), (50, 0), (50, 20), (30, 20)], height=25)

# Elevated canopy
add_shading_block(doc, "Canopy", [(0, -3), (10, -3), (10, 0), (0, 0)], height=0.2, base_z=3)

Each call creates one wall surface per footprint edge plus a horizontal top cap.

GlobalGeometryRules Convention

All builder functions read the document's GlobalGeometryRules to determine the vertex ordering convention:

  • starting_vertex_position -- which corner is listed first for walls (UpperLeftCorner, LowerLeftCorner, etc.)
  • vertex_entry_direction -- winding direction (Counterclockwise or Clockwise)

new_document() pre-seeds GlobalGeometryRules with UpperLeftCorner / Counterclockwise defaults. If a model is missing GlobalGeometryRules (for example, some legacy inputs), the same EnergyPlus defaults are assumed.

This means you can safely add geometry to an existing model that uses a non-default convention without having to rewrite all existing surfaces:

from idfkit import load_idf, create_block

# Model uses Clockwise vertex convention
model = load_idf("existing_building.idf")

# New surfaces will automatically use Clockwise ordering
# to match the model's GlobalGeometryRules
create_block(model, "Addition", [(20, 0), (30, 0), (30, 10), (20, 10)], floor_to_floor=3)

Wall Vertex Order by Convention

For a wall between footprint vertices p1 and p2 (height z_bot to z_top), viewed from outside:

Starting Position Counterclockwise Clockwise
UpperLeftCorner UL LL LR UR UL UR LR LL
LowerLeftCorner LL LR UR UL LL UL UR LR
LowerRightCorner LR UR UL LL LR LL UL UR
UpperRightCorner UR UL LL LR UR LR LL UL

Where UL = (p1, z_top), LL = (p1, z_bot), LR = (p2, z_bot), UR = (p2, z_top).

Horizontal Surfaces

For floors and ceilings, the winding direction is adapted so that EnergyPlus computes the correct outward normal regardless of convention:

  • Floor: outward normal points down (toward ground)
  • Ceiling / Roof: outward normal points up (toward sky)

Utility Functions

set_default_constructions

Assigns a construction name to every opaque surface that lacks one. Walls and doors get construction_name. Roof, Floor and Ceiling surfaces get roof_construction, floor_construction and ceiling_construction, each falling back to construction_name. Windows, glass doors and tubular daylighting surfaces stay unset unless you pass window_construction; validate_document then reports them as missing a required field.

from idfkit.geometry_builders import set_default_constructions

count = set_default_constructions(
    doc,
    "Generic Wall",
    roof_construction="Generic Roof",
    window_construction="Generic Glazing",
)
print(f"Updated {count} surfaces")

The function only sets names. It does not create the Construction objects; validate_document reports one that does not exist.

bounding_box

Returns the 2D axis-aligned bounding box of all BuildingSurface:Detailed objects:

from idfkit.geometry_builders import bounding_box

bbox = bounding_box(doc)
if bbox:
    (min_x, min_y), (max_x, max_y) = bbox
    print(f"Footprint spans {max_x - min_x:.1f} x {max_y - min_y:.1f} m")

scale_building

Scales all surface vertices around an anchor point:

from idfkit.geometry_builders import scale_building
from idfkit.geometry import Vector3D

# Double the building in all directions
scale_building(doc, 2.0)

# Stretch only the X axis
scale_building(doc, (1.5, 1.0, 1.0))

# Scale around the building centroid
scale_building(doc, 0.5, anchor=Vector3D(15, 10, 0))

Horizontal Adjacency Detection

When building models with stacked blocks (e.g. setback towers), roof and floor surfaces at shared elevations need to be detected, split, and linked. The high-level link_blocks handles this automatically, but you can use the lower-level API for custom geometry workflows.

Detecting Adjacencies

detect_horizontal_adjacencies scans all BuildingSurface:Detailed surfaces for horizontal Roof/Floor pairs at the same z-elevation with Outdoors boundary condition, and computes their 2-D polygon intersection:

from idfkit.geometry_builders import detect_horizontal_adjacencies

adjacencies = detect_horizontal_adjacencies(doc)
for adj in adjacencies:
    print(f"Roof '{adj.roof_surface.name}' overlaps floor "
          f"'{adj.floor_surface.name}' at z={adj.z} "
          f"({adj.intersection_area:.1f} m²)")

Each HorizontalAdjacency record contains the roof surface, floor surface, z-elevation, 2-D intersection polygon, and intersection area.

Splitting Surfaces

split_horizontal_surface creates a new surface for a 2-D region within an existing horizontal surface. The original surface is shrunk to the remaining area:

from idfkit.geometry_builders import split_horizontal_surface

new_surface, remaining = split_horizontal_surface(doc, adj.roof_surface, adj.intersection)
# new_surface covers the intersection region
# remaining is the original surface, now covering only the exposed area

Linking Surfaces

link_horizontal_surfaces sets mutual Surface boundary conditions between a ceiling and floor:

from idfkit.geometry_builders import link_horizontal_surfaces

link_horizontal_surfaces(new_surface, adj.floor_surface)
# new_surface is now a Ceiling pointing at the floor, and vice versa

Full Example

from idfkit.geometry_builders import (
    detect_horizontal_adjacencies,
    link_horizontal_surfaces,
    split_horizontal_surface,
)

adjacencies = detect_horizontal_adjacencies(doc)
for adj in adjacencies:
    new_ceiling, _ = split_horizontal_surface(doc, adj.roof_surface, adj.intersection)
    link_horizontal_surfaces(new_ceiling, adj.floor_surface)

API Reference

Geometry utility functions for EnergyPlus surface manipulation.

Provides shading block creation, default construction assignment, bounding box queries, building scaling, horizontal adjacency detection, surface splitting, and GlobalGeometryRules vertex-ordering helpers.

For building zone and surface creation, see zoning which provides create_block and ZonedBlock.

WALL_ORDER = {('UpperLeftCorner', False): (0, 1, 2, 3), ('LowerLeftCorner', False): (1, 2, 3, 0), ('LowerRightCorner', False): (2, 3, 0, 1), ('UpperRightCorner', False): (3, 0, 1, 2), ('UpperLeftCorner', True): (0, 3, 2, 1), ('UpperRightCorner', True): (3, 2, 1, 0), ('LowerRightCorner', True): (2, 1, 0, 3), ('LowerLeftCorner', True): (1, 0, 3, 2)} module-attribute

logger = logging.getLogger(__name__) module-attribute

HorizontalAdjacency dataclass

A detected adjacency between a roof and floor surface at the same elevation.

Attributes:

Name Type Description
roof_surface IDFObject

The roof surface from the lower block.

floor_surface IDFObject

The floor surface from the upper block.

z float

The shared elevation in metres.

intersection list[tuple[float, float]]

2-D polygon of the overlapping area.

intersection_area float

Area of the overlap in square metres.

Source code in idfkit/geometry_builders.py
@dataclass(frozen=True)
class HorizontalAdjacency:
    """A detected adjacency between a roof and floor surface at the same elevation.

    Attributes:
        roof_surface: The roof surface from the lower block.
        floor_surface: The floor surface from the upper block.
        z: The shared elevation in metres.
        intersection: 2-D polygon of the overlapping area.
        intersection_area: Area of the overlap in square metres.
    """

    roof_surface: IDFObject
    floor_surface: IDFObject
    z: float
    intersection: list[tuple[float, float]]
    intersection_area: float

floor_surface instance-attribute

intersection instance-attribute

intersection_area instance-attribute

roof_surface instance-attribute

z instance-attribute

add_shading_block(doc, name, footprint, height, base_z=0.0)

Create Shading:Site:Detailed surfaces from a 2D footprint.

Creates one shading surface per footprint edge (walls) plus a horizontal top cap. No zones or thermal surfaces are created.

Parameters:

Name Type Description Default
doc AnyIDFDocument

The document to add objects to.

required
name str

Base name for shading surfaces.

required
footprint Sequence[tuple[float, float]]

2D footprint as (x, y) tuples. A clockwise footprint is reversed, so every wall faces outward and the top faces up.

required
height float

Height of the shading block in metres.

required
base_z float

Z-coordinate of the block base (default 0.0). Use this to create elevated shading surfaces such as canopies.

0.0

Returns:

Type Description
list[IDFObject]

List of created Shading:Site:Detailed objects.

Raises:

Type Description
ValueError

If footprint has fewer than 3 vertices or no area, or height <= 0.

Source code in idfkit/geometry_builders.py
def add_shading_block(
    doc: AnyIDFDocument,
    name: str,
    footprint: Sequence[tuple[float, float]],
    height: float,
    base_z: float = 0.0,
) -> list[IDFObject]:
    """Create ``Shading:Site:Detailed`` surfaces from a 2D footprint.

    Creates one shading surface per footprint edge (walls) plus a
    horizontal top cap.  No zones or thermal surfaces are created.

    Args:
        doc: The document to add objects to.
        name: Base name for shading surfaces.
        footprint: 2D footprint as ``(x, y)`` tuples.  A clockwise
            footprint is reversed, so every wall faces outward and the
            top faces up.
        height: Height of the shading block in metres.
        base_z: Z-coordinate of the block base (default ``0.0``).
            Use this to create elevated shading surfaces such as canopies.

    Returns:
        List of created ``Shading:Site:Detailed`` objects.

    Raises:
        ValueError: If footprint has fewer than 3 vertices or no area, or
            height <= 0.
    """
    fp = counter_clockwise_footprint(footprint)
    if height <= 0:
        msg = f"Height must be positive, got {height}"
        raise ValueError(msg)

    svp, clockwise = get_geometry_convention(doc)
    wall_order = WALL_ORDER.get((svp, clockwise), (0, 1, 2, 3))

    z_bot = base_z
    z_top = base_z + height
    created: list[IDFObject] = []
    n = len(fp)

    # Walls
    for j in range(n):
        p1 = fp[j]
        p2 = fp[(j + 1) % n]
        wall_name = f"{name} Wall {j + 1}"
        corners = [
            Vector3D(p1[0], p1[1], z_top),  # UL
            Vector3D(p1[0], p1[1], z_bot),  # LL
            Vector3D(p2[0], p2[1], z_bot),  # LR
            Vector3D(p2[0], p2[1], z_top),  # UR
        ]
        poly = Polygon3D([corners[k] for k in wall_order])
        obj = doc["Shading:Site:Detailed"].add(wall_name, validate=False)
        set_surface_coords(obj, poly)
        created.append(obj)

    # Top cap — horizontal surface with normal pointing up
    cap_name = f"{name} Top"
    cap = doc["Shading:Site:Detailed"].add(cap_name, validate=False)
    set_surface_coords(cap, horizontal_poly(fp, z_top, reverse=clockwise))
    created.append(cap)

    return created

bounding_box(doc)

Return the 2D axis-aligned bounding box of all building surfaces.

Scans all BuildingSurface:Detailed vertices and returns the bounding envelope projected onto the XY plane.

Note

Only BuildingSurface:Detailed objects are considered. Fenestration and shading surfaces are excluded because they are either coplanar with (windows) or outside (shading) the thermal envelope.

Returns:

Type Description
tuple[tuple[float, float], tuple[float, float]] | None

((min_x, min_y), (max_x, max_y)) or None if no

tuple[tuple[float, float], tuple[float, float]] | None

surfaces with valid coordinates exist.

Source code in idfkit/geometry_builders.py
def bounding_box(doc: AnyIDFDocument) -> tuple[tuple[float, float], tuple[float, float]] | None:
    """Return the 2D axis-aligned bounding box of all building surfaces.

    Scans all ``BuildingSurface:Detailed`` vertices and returns the
    bounding envelope projected onto the XY plane.

    !!! note
        Only ``BuildingSurface:Detailed`` objects are considered.
        Fenestration and shading surfaces are excluded because they
        are either coplanar with (windows) or outside (shading) the
        thermal envelope.

    Returns:
        ``((min_x, min_y), (max_x, max_y))`` or ``None`` if no
        surfaces with valid coordinates exist.
    """
    min_x = float("inf")
    min_y = float("inf")
    max_x = float("-inf")
    max_y = float("-inf")
    found = False

    for srf in doc["BuildingSurface:Detailed"]:
        coords = get_surface_coords(srf)
        if coords is None:
            continue
        for v in coords.vertices:
            min_x = min(min_x, v.x)
            min_y = min(min_y, v.y)
            max_x = max(max_x, v.x)
            max_y = max(max_y, v.y)
            found = True

    if not found:
        return None
    return ((min_x, min_y), (max_x, max_y))

counter_clockwise_footprint(footprint, what='Footprint')

Return footprint in counter-clockwise order, reversing a clockwise one.

Extruding a footprint assumes counter-clockwise order seen from above: a clockwise one gives walls facing into the building, a floor facing up and a roof facing down, which EnergyPlus simulates (with warnings) as an inside-out zone of negative volume. The first vertex is kept first.

Parameters:

Name Type Description Default
footprint Sequence[tuple[float, float]]

2-D polygon as (x, y) tuples, in either order.

required
what str

How to name the polygon in an error message.

'Footprint'

Returns:

Type Description
list[tuple[float, float]]

The vertices in counter-clockwise order (a new list).

Raises:

Type Description
ValueError

If the polygon has fewer than 3 vertices or no area (all vertices on one line).

Examples:

>>> counter_clockwise_footprint([(0, 0), (0, 2), (3, 2), (3, 0)])
[(0, 0), (3, 0), (3, 2), (0, 2)]
Source code in idfkit/geometry_builders.py
def counter_clockwise_footprint(
    footprint: Sequence[tuple[float, float]], what: str = "Footprint"
) -> list[tuple[float, float]]:
    """Return *footprint* in counter-clockwise order, reversing a clockwise one.

    Extruding a footprint assumes counter-clockwise order seen from above:
    a clockwise one gives walls facing into the building, a floor facing up
    and a roof facing down, which EnergyPlus simulates (with warnings) as an
    inside-out zone of negative volume.  The first vertex is kept first.

    Args:
        footprint: 2-D polygon as ``(x, y)`` tuples, in either order.
        what: How to name the polygon in an error message.

    Returns:
        The vertices in counter-clockwise order (a new list).

    Raises:
        ValueError: If the polygon has fewer than 3 vertices or no area
            (all vertices on one line).

    Examples:
        >>> counter_clockwise_footprint([(0, 0), (0, 2), (3, 2), (3, 0)])
        [(0, 0), (3, 0), (3, 2), (0, 2)]
    """
    fp = list(footprint)
    if len(fp) < 3:
        msg = f"{what} must have at least 3 vertices, got {len(fp)}"
        raise ValueError(msg)
    area = polygon_area_2d(fp)
    if abs(area) < 1e-9:
        msg = f"{what} has zero area (its vertices lie on one line): {fp!r}"
        raise ValueError(msg)
    if area < 0:
        return [fp[0], *reversed(fp[1:])]
    return fp

detect_horizontal_adjacencies(doc)

Find roof/floor surface pairs at matching elevations.

Scans all BuildingSurface:Detailed surfaces for horizontal Roof surfaces with Outdoors boundary condition and horizontal Floor surfaces with Outdoors boundary condition at the same elevation.

For each overlapping pair the 2-D polygon intersection is computed.

Parameters:

Name Type Description Default
doc AnyIDFDocument

The document to scan.

required

Returns:

Type Description
list[HorizontalAdjacency]

List of HorizontalAdjacency records for each detected

list[HorizontalAdjacency]

overlap.

Source code in idfkit/geometry_builders.py
def detect_horizontal_adjacencies(
    doc: AnyIDFDocument,
) -> list[HorizontalAdjacency]:
    """Find roof/floor surface pairs at matching elevations.

    Scans all ``BuildingSurface:Detailed`` surfaces for horizontal Roof
    surfaces with ``Outdoors`` boundary condition and horizontal Floor
    surfaces with ``Outdoors`` boundary condition at the same elevation.

    For each overlapping pair the 2-D polygon intersection is computed.

    Args:
        doc: The document to scan.

    Returns:
        List of [HorizontalAdjacency][idfkit.geometry_builders.HorizontalAdjacency] records for each detected
        overlap.
    """
    roofs, floors = _collect_outdoor_horizontal_surfaces(doc)

    adjacencies: list[HorizontalAdjacency] = []
    for z_key, roof_list in roofs.items():
        floor_list = floors.get(z_key)
        if floor_list is None:
            continue
        for roof_srf, roof_fp in roof_list:
            for floor_srf, floor_fp in floor_list:
                inter = polygon_intersection_2d(roof_fp, floor_fp)
                if inter is None:
                    continue
                area = abs(polygon_area_2d(inter))
                if area < 0.01:
                    continue
                adjacencies.append(
                    HorizontalAdjacency(
                        roof_surface=roof_srf,
                        floor_surface=floor_srf,
                        z=z_key,
                        intersection=inter,
                        intersection_area=area,
                    )
                )
    return adjacencies

get_geometry_convention(doc)

Read the vertex ordering convention from GlobalGeometryRules.

Returns:

Type Description
str

(starting_vertex_position, clockwise) where clockwise is

bool

True when vertex_entry_direction is "Clockwise".

tuple[str, bool]

Defaults to ("UpperLeftCorner", False) if no rules exist.

Source code in idfkit/geometry_builders.py
def get_geometry_convention(doc: AnyIDFDocument) -> tuple[str, bool]:
    """Read the vertex ordering convention from ``GlobalGeometryRules``.

    Returns:
        ``(starting_vertex_position, clockwise)`` where *clockwise* is
        ``True`` when ``vertex_entry_direction`` is ``"Clockwise"``.
        Defaults to ``("UpperLeftCorner", False)`` if no rules exist.
    """
    geo_rules = doc["GlobalGeometryRules"]
    if not geo_rules:
        return ("UpperLeftCorner", False)
    rules = geo_rules.first()
    if rules is None:
        return ("UpperLeftCorner", False)
    svp = getattr(rules, "starting_vertex_position", None) or "UpperLeftCorner"
    ved = getattr(rules, "vertex_entry_direction", None) or "Counterclockwise"
    return (str(svp), str(ved).lower() == "clockwise")

horizontal_poly(footprint, z, *, reverse)

Build a horizontal polygon at height z.

When reverse is True the footprint is reversed, flipping the polygon normal. Used to produce floor and ceiling polygons in the correct winding for the active GlobalGeometryRules convention.

Source code in idfkit/geometry_builders.py
def horizontal_poly(footprint: list[tuple[float, float]], z: float, *, reverse: bool) -> Polygon3D:
    """Build a horizontal polygon at height *z*.

    When *reverse* is ``True`` the footprint is reversed, flipping the
    polygon normal.  Used to produce floor and ceiling polygons in the
    correct winding for the active ``GlobalGeometryRules`` convention.
    """
    pts = reversed(footprint) if reverse else footprint
    return Polygon3D([Vector3D(p[0], p[1], z) for p in pts])

Set mutual Surface boundary conditions between ceiling and floor.

Modifies both surfaces in-place:

  • The ceiling's surface_type is set to Ceiling.
  • Both surfaces get outside_boundary_condition = "Surface" pointing at each other, with sun/wind exposure set to NoSun / NoWind.

Parameters:

Name Type Description Default
ceiling IDFObject

The surface to designate as the ceiling.

required
floor IDFObject

The surface to designate as the floor.

required
Source code in idfkit/geometry_builders.py
def link_horizontal_surfaces(ceiling: IDFObject, floor: IDFObject) -> None:
    """Set mutual ``Surface`` boundary conditions between ceiling and floor.

    Modifies both surfaces in-place:

    * The ceiling's ``surface_type`` is set to ``Ceiling``.
    * Both surfaces get ``outside_boundary_condition = "Surface"``
      pointing at each other, with sun/wind exposure set to ``NoSun``
      / ``NoWind``.

    Args:
        ceiling: The surface to designate as the ceiling.
        floor: The surface to designate as the floor.
    """
    ceiling.surface_type = "Ceiling"
    ceiling.outside_boundary_condition = "Surface"
    ceiling.outside_boundary_condition_object = floor.name
    ceiling.sun_exposure = "NoSun"
    ceiling.wind_exposure = "NoWind"

    floor.outside_boundary_condition = "Surface"
    floor.outside_boundary_condition_object = ceiling.name
    floor.sun_exposure = "NoSun"
    floor.wind_exposure = "NoWind"

scale_building(doc, factor, anchor=None)

Scale all surface vertices around an anchor point.

Parameters:

Name Type Description Default
doc AnyIDFDocument

The document to modify in-place.

required
factor float | tuple[float, float, float]

Scale factor. A single float applies uniform scaling; a (fx, fy, fz) tuple scales each axis independently (e.g. (2.0, 1.0, 1.0) doubles X only).

required
anchor Vector3D | None

Point to scale around. If None, the origin (0, 0, 0) is used.

None
Source code in idfkit/geometry_builders.py
def scale_building(
    doc: AnyIDFDocument,
    factor: float | tuple[float, float, float],
    anchor: Vector3D | None = None,
) -> None:
    """Scale all surface vertices around an anchor point.

    Args:
        doc: The document to modify in-place.
        factor: Scale factor.  A single ``float`` applies uniform scaling;
            a ``(fx, fy, fz)`` tuple scales each axis independently
            (e.g. ``(2.0, 1.0, 1.0)`` doubles X only).
        anchor: Point to scale around.  If ``None``, the origin
            ``(0, 0, 0)`` is used.
    """
    if isinstance(factor, tuple):
        fx, fy, fz = factor
    else:
        fx = fy = fz = factor

    ax, ay, az = (anchor.x, anchor.y, anchor.z) if anchor else (0.0, 0.0, 0.0)

    for stype in VERTEX_SURFACE_TYPES:
        for srf in doc[stype]:
            coords = get_surface_coords(srf)
            if coords is None:
                continue
            new_vertices = [
                Vector3D(
                    ax + (v.x - ax) * fx,
                    ay + (v.y - ay) * fy,
                    az + (v.z - az) * fz,
                )
                for v in coords.vertices
            ]
            set_surface_coords(srf, Polygon3D(new_vertices))

set_default_constructions(doc, construction_name='Default Construction', *, roof_construction=None, floor_construction=None, ceiling_construction=None, window_construction=None)

Assign placeholder constructions to surfaces that lack one.

Sets a construction on every BuildingSurface:Detailed and every door FenestrationSurface:Detailed whose construction is empty. A building surface gets the construction for its surface type: roof_construction for Roof, floor_construction for Floor and ceiling_construction for Ceiling, each falling back to construction_name when not given; walls, doors and surfaces of any other type get construction_name. Windows, glass doors and tubular daylighting surfaces need a window construction, which EnergyPlus refuses an opaque one for, so they get window_construction when it is given and are left unset otherwise (validate_document then reports them as missing a required field).

Does not create the Construction objects — the caller is responsible for ensuring they exist; validate_document reports one that does not (E009).

Parameters:

Name Type Description Default
doc AnyIDFDocument

The document to modify.

required
construction_name str

Name of the opaque construction to assign to walls and doors, and to roofs, floors and ceilings that have no construction of their own below.

'Default Construction'
roof_construction str | None

Name of the construction for Roof surfaces. None uses construction_name.

None
floor_construction str | None

Name of the construction for Floor surfaces, interzone floors of upper storeys included, not only ground floors. None uses construction_name.

None
ceiling_construction str | None

Name of the construction for Ceiling surfaces. None uses construction_name. An interzone ceiling and the floor it faces should carry constructions whose layers are the reverse of each other.

None
window_construction str | None

Name of a window construction (one with a WindowMaterial layer) for glazed fenestration. None leaves glazed fenestration unassigned.

None

Returns:

Type Description
int

Number of surfaces updated.

Examples:

>>> from idfkit import create_block, new_document, set_wwr
>>> doc = new_document()
>>> _ = create_block(doc, "B", [(0, 0), (10, 0), (10, 10), (0, 10)], floor_to_floor=3)
>>> _ = set_wwr(doc, 0.3)
>>> set_default_constructions(
...     doc,
...     "Ext Wall",
...     roof_construction="Roof",
...     floor_construction="Slab",
...     window_construction="Glazing",
... )
10
>>> sorted({s.construction_name for s in doc["BuildingSurface:Detailed"]})
['Ext Wall', 'Roof', 'Slab']
Source code in idfkit/geometry_builders.py
def set_default_constructions(
    doc: AnyIDFDocument,
    construction_name: str = "Default Construction",
    *,
    roof_construction: str | None = None,
    floor_construction: str | None = None,
    ceiling_construction: str | None = None,
    window_construction: str | None = None,
) -> int:
    """Assign placeholder constructions to surfaces that lack one.

    Sets a construction on every ``BuildingSurface:Detailed`` and every door
    ``FenestrationSurface:Detailed`` whose construction is empty. A building surface gets the
    construction for its surface type: *roof_construction* for ``Roof``, *floor_construction* for
    ``Floor`` and *ceiling_construction* for ``Ceiling``, each falling back to *construction_name*
    when not given; walls, doors and surfaces of any other type get *construction_name*.
    Windows, glass doors and tubular daylighting surfaces need a window construction, which
    EnergyPlus refuses an opaque one for, so they get *window_construction* when it is given and
    are left unset otherwise (``validate_document`` then reports them as missing a required field).

    Does **not** create the ``Construction`` objects — the caller is responsible for ensuring
    they exist; ``validate_document`` reports one that does not (``E009``).

    Args:
        doc: The document to modify.
        construction_name: Name of the opaque construction to assign to walls and doors, and to
            roofs, floors and ceilings that have no construction of their own below.
        roof_construction: Name of the construction for ``Roof`` surfaces. ``None`` uses
            *construction_name*.
        floor_construction: Name of the construction for ``Floor`` surfaces, interzone floors of
            upper storeys included, not only ground floors. ``None`` uses *construction_name*.
        ceiling_construction: Name of the construction for ``Ceiling`` surfaces. ``None`` uses
            *construction_name*. An interzone ceiling and the floor it faces should carry
            constructions whose layers are the reverse of each other.
        window_construction: Name of a window construction (one with a ``WindowMaterial`` layer)
            for glazed fenestration. ``None`` leaves glazed fenestration unassigned.

    Returns:
        Number of surfaces updated.

    Examples:
        >>> from idfkit import create_block, new_document, set_wwr
        >>> doc = new_document()
        >>> _ = create_block(doc, "B", [(0, 0), (10, 0), (10, 10), (0, 10)], floor_to_floor=3)
        >>> _ = set_wwr(doc, 0.3)
        >>> set_default_constructions(
        ...     doc,
        ...     "Ext Wall",
        ...     roof_construction="Roof",
        ...     floor_construction="Slab",
        ...     window_construction="Glazing",
        ... )
        10
        >>> sorted({s.construction_name for s in doc["BuildingSurface:Detailed"]})
        ['Ext Wall', 'Roof', 'Slab']
    """
    by_surface_type = {
        "roof": roof_construction or construction_name,
        "floor": floor_construction or construction_name,
        "ceiling": ceiling_construction or construction_name,
    }
    count = 0
    for srf in doc["BuildingSurface:Detailed"]:
        if srf.get("Construction Name"):
            continue
        surface_type = srf.data.get("surface_type")
        key = surface_type.casefold() if isinstance(surface_type, str) else ""
        srf.construction_name = by_surface_type.get(key, construction_name)
        count += 1
    for srf in doc["FenestrationSurface:Detailed"]:
        if srf.get("Construction Name"):
            continue
        name = construction_name if is_fenestration_door(srf) else window_construction
        if name is not None:
            srf.construction_name = name
            count += 1
    return count

split_horizontal_surface(doc, surface, region)

Split a horizontal surface at a 2-D region boundary.

A new surface is created for the area inside the region. The original surface is shrunk to the area outside the region.

When the region sits strictly inside the surface, the outside area is a frame with a hole, which no single EnergyPlus surface can describe. The frame is then cut into hole-free pieces: the original surface keeps the largest, and each other piece is added to doc as a new surface named "<surface name> Remainder" (numbered when that name is taken). Use split_horizontal_surface_by_regions to get those extra surfaces back, or to split under several regions at once.

Parameters:

Name Type Description Default
doc AnyIDFDocument

The document containing the surface.

required
surface IDFObject

Horizontal surface to split (floor, ceiling, or roof).

required
region Sequence[tuple[float, float]]

2-D polygon defining the split region.

required

Returns:

Type Description
IDFObject

(new_region_surface, remaining_surface).

IDFObject | None

remaining_surface is None if the region covers the entire

tuple[IDFObject, IDFObject | None]

surface (i.e. no remaining area).

Source code in idfkit/geometry_builders.py
def split_horizontal_surface(
    doc: AnyIDFDocument,
    surface: IDFObject,
    region: Sequence[tuple[float, float]],
) -> tuple[IDFObject, IDFObject | None]:
    """Split a horizontal surface at a 2-D region boundary.

    A new surface is created for the area *inside* the region.  The
    original surface is shrunk to the area *outside* the region.

    When the region sits strictly inside the surface, the outside area is
    a frame with a hole, which no single EnergyPlus surface can describe.
    The frame is then cut into hole-free pieces: the original surface
    keeps the largest, and each other piece is added to *doc* as a new
    surface named ``"<surface name> Remainder"`` (numbered when that name
    is taken).  Use
    [split_horizontal_surface_by_regions][idfkit.geometry_builders.split_horizontal_surface_by_regions]
    to get those extra surfaces back, or to split under several regions
    at once.

    Args:
        doc: The document containing the surface.
        surface: Horizontal surface to split (floor, ceiling, or roof).
        region: 2-D polygon defining the split region.

    Returns:
        ``(new_region_surface, remaining_surface)``.
        *remaining_surface* is ``None`` if the region covers the entire
        surface (i.e. no remaining area).
    """
    region_surfaces, remaining = split_horizontal_surface_by_regions(doc, surface, [region])
    return region_surfaces[0], (remaining[0] if remaining else None)

split_horizontal_surface_by_regions(doc, surface, regions)

Split a horizontal surface under several non-overlapping 2-D regions at once.

One new surface is created per region, covering the part of the surface inside that region. The rest of the surface (the surface minus all regions together) is computed with polygon_difference_parts_2d, so it is always EnergyPlus-safe: no holes and no zero-width slits. The original surface takes the largest remaining piece. When more pieces remain, for example around a region sitting in the middle of the surface, each extra piece becomes a new surface named "<surface name> Remainder" (numbered when that name is taken) that copies the original's construction, zone, and boundary conditions.

Splitting under every region in one call matters when the regions are adjacent, such as the floors of a core-and-perimeter tower standing on a podium roof. Their union is subtracted in one step, so the remainder is cut only where it has to be.

Parameters:

Name Type Description Default
doc AnyIDFDocument

The document containing the surface.

required
surface IDFObject

Horizontal surface to split (floor, ceiling, or roof).

required
regions Sequence[Sequence[tuple[float, float]]]

2-D polygons to split at. Each must overlap the surface and be convex or have a convex overlap with it.

required

Returns:

Type Description
list[IDFObject]

(region_surfaces, remaining_surfaces). region_surfaces

list[IDFObject]

holds one surface per region, in order. remaining_surfaces

tuple[list[IDFObject], list[IDFObject]]

starts with the original surface, followed by any extra remainder

tuple[list[IDFObject], list[IDFObject]]

pieces. It is empty when the regions cover the whole surface; the

tuple[list[IDFObject], list[IDFObject]]

original surface is then left unchanged.

Raises:

Type Description
ValueError

If the surface has no coordinates or a region does not overlap it.

Source code in idfkit/geometry_builders.py
def split_horizontal_surface_by_regions(
    doc: AnyIDFDocument,
    surface: IDFObject,
    regions: Sequence[Sequence[tuple[float, float]]],
) -> tuple[list[IDFObject], list[IDFObject]]:
    """Split a horizontal surface under several non-overlapping 2-D regions at once.

    One new surface is created per region, covering the part of the
    surface inside that region.  The rest of the surface (the surface
    minus all regions together) is computed with
    [polygon_difference_parts_2d][idfkit.geometry.polygon_difference_parts_2d],
    so it is always EnergyPlus-safe: no holes and no zero-width slits.  The
    original surface takes the largest remaining piece.  When more pieces
    remain, for example around a region sitting in the middle of the
    surface, each extra piece becomes a new surface named
    ``"<surface name> Remainder"`` (numbered when that name is taken) that
    copies the original's construction, zone, and boundary conditions.

    Splitting under every region in one call matters when the regions are
    adjacent, such as the floors of a core-and-perimeter tower standing on
    a podium roof.  Their union is subtracted in one step, so the remainder
    is cut only where it has to be.

    Args:
        doc: The document containing the surface.
        surface: Horizontal surface to split (floor, ceiling, or roof).
        regions: 2-D polygons to split at.  Each must overlap the surface
            and be convex or have a convex overlap with it.

    Returns:
        ``(region_surfaces, remaining_surfaces)``.  *region_surfaces*
        holds one surface per region, in order.  *remaining_surfaces*
        starts with the original surface, followed by any extra remainder
        pieces.  It is empty when the regions cover the whole surface; the
        original surface is then left unchanged.

    Raises:
        ValueError: If the surface has no coordinates or a region does not
            overlap it.
    """
    result = _extract_horizontal_footprint(surface)
    if result is None:
        msg = f"Surface '{surface.name}' has no coordinates"
        raise ValueError(msg)
    z, footprint = result
    _, clockwise = get_geometry_convention(doc)

    inters: list[list[tuple[float, float]]] = []
    for region in regions:
        inter = polygon_intersection_2d(footprint, list(region))
        if inter is None:
            msg = f"Region does not overlap surface '{surface.name}'"
            raise ValueError(msg)
        inters.append(inter)

    # Determine surface type for winding
    st = (getattr(surface, "surface_type", "") or "").upper()
    # For roofs/ceilings, winding is clockwise; for floors, not clockwise
    reverse = clockwise if st in ("ROOF", "CEILING") else not clockwise

    region_surfaces = [
        _add_horizontal_like(doc, surface, f"{surface.name} Split", inter, z, reverse=reverse) for inter in inters
    ]

    pieces = [p for p in polygon_difference_parts_2d(footprint, *inters) if abs(polygon_area_2d(p)) >= 0.01]
    if not pieces:
        return region_surfaces, []

    # Update original surface geometry to the largest remaining piece
    set_surface_coords(surface, horizontal_poly(pieces[0], z, reverse=reverse))
    remaining = [surface]
    remaining.extend(
        _add_horizontal_like(doc, surface, f"{surface.name} Remainder", piece, z, reverse=reverse)
        for piece in pieces[1:]
    )
    return region_surfaces, remaining

See Also

  • Zoning -- create_block, link_blocks, core-perimeter zoning, footprint helpers, and multi-zone building generation
  • Geometry -- Lower-level 3D primitives, coordinate transforms, and surface intersection
  • Visualization -- 3D rendering of building geometry
  • Thermal -- R/U-value calculations for constructions