Registry System¶
registry
¶
Unified registry for all FDS simulation components.
Classes¶
Registry
¶
Bases: Generic[T]
Type-safe registry for FDS namelist objects.
Unlike WeakValueDictionary, this uses strong references to ensure objects are not garbage collected unexpectedly.
Source code in src/pyfds/core/registry.py
Functions¶
add
¶
Add an item to the registry.
Source code in src/pyfds/core/registry.py
get
¶
remove
¶
contains
¶
list_ids
¶
list_items
¶
SimulationRegistry
¶
Centralized registry for all simulation components.
All IDs must be unique across ALL namelist types (FDS requirement). This mirrors FDS behavior where IDs like 'INERT' could refer to a SURF, MATL, or other component depending on context.
Source code in src/pyfds/core/registry.py
Functions¶
register
¶
Register any item to appropriate registry.
Source code in src/pyfds/core/registry.py
147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 | |
get_by_id
¶
Get any item by ID from any registry.
Source code in src/pyfds/core/registry.py
clear
¶
Clear all registries and singletons.
Source code in src/pyfds/core/registry.py
all_namelists
¶
Get all namelists in FDS output order.
Source code in src/pyfds/core/registry.py
registry_view
¶
Read-only views into Registry collections.
This module provides RegistryView, a typed read-only interface for accessing registry contents without exposing mutation operations.
Classes¶
RegistryView
¶
Bases: Generic[T]
Read-only typed view into a Registry.
Provides dictionary-like read access to registry contents without exposing mutation operations. This ensures that namelists can only be added through the Simulation.add() method.
| PARAMETER | DESCRIPTION |
|---|---|
registry
|
The underlying registry to wrap
TYPE:
|
Examples:
>>> sim = Simulation(chid="test")
>>> sim.add(Mesh(id="mesh1", ...))
>>>
>>> # Access via view
>>> mesh = sim.meshes["mesh1"] # Get by ID
>>> len(sim.meshes) # Count items
>>> "mesh1" in sim.meshes # Check existence
>>> for m in sim.meshes: # Iterate
... print(m.id)
Source code in src/pyfds/core/registry_view.py
Functions¶
__getitem__
¶
Get an item by its ID or index.
| PARAMETER | DESCRIPTION |
|---|---|
key
|
The unique identifier of the item, or an integer index
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
T
|
The item with the given ID or at the given index |
| RAISES | DESCRIPTION |
|---|---|
UnknownIdError
|
If a string ID does not exist in the registry |
IndexError
|
If an integer index is out of range |
Source code in src/pyfds/core/registry_view.py
__contains__
¶
Check if an ID or item exists in the registry.
| PARAMETER | DESCRIPTION |
|---|---|
item
|
The ID to check, or an item to check for membership
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
bool
|
True if the ID/item exists |
Source code in src/pyfds/core/registry_view.py
__iter__
¶
Iterate over all items in the registry.
| YIELDS | DESCRIPTION |
|---|---|
T
|
Each item in the registry |
__len__
¶
Return the number of items in the registry.
| RETURNS | DESCRIPTION |
|---|---|
int
|
Count of registered items |
__bool__
¶
Return True if registry contains items.
| RETURNS | DESCRIPTION |
|---|---|
bool
|
True if not empty |
ids
¶
Get all registered IDs.
| RETURNS | DESCRIPTION |
|---|---|
list[str]
|
List of all IDs in the registry |
all
¶
Get all registered items.
| RETURNS | DESCRIPTION |
|---|---|
list[T]
|
List of all items in the registry |
get
¶
Get an item by ID with optional default.
| PARAMETER | DESCRIPTION |
|---|---|
item_id
|
The ID to look up
TYPE:
|
default
|
Value to return if ID not found
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
T or None
|
The item if found, otherwise default |
Source code in src/pyfds/core/registry_view.py
Overview¶
The registry system manages namelist objects and their IDs within a simulation. It provides centralized object storage, ID validation, and type-safe retrieval.
Core Components¶
Registry¶
Generic registry for managing objects of a specific type with ID-based lookup.
from pyfds.core.registry import Registry
from pyfds import Surface
# Create a registry for surfaces
registry = Registry[Surface]()
# Add objects
surface = Surface(id="FIRE", hrrpua=1000)
registry.add(surface)
# Retrieve by ID
fire_surface = registry.get("FIRE")
# Check existence
if registry.contains("FIRE"):
print("Surface exists")
# Get all objects
all_surfaces = registry.get_all()
Type Parameters:
T: The type of object stored in the registry
Key Methods:
add(obj): Add an object to the registryget(id): Retrieve an object by IDcontains(id): Check if an ID existsget_all(): Get all registered objectsclear(): Remove all objects
SimulationRegistry¶
Main registry system for a simulation, managing all namelist types.
from pyfds import Simulation
sim = Simulation(chid="test")
# Registry is accessed internally
# Add objects to simulation
sim.add(Surface(id="FIRE", hrrpua=1000))
sim.add(Mesh(id="MAIN", ijk=(50, 50, 25), xb=(0, 10, 0, 10, 0, 5)))
# The registry manages these objects and enforces ID uniqueness
The SimulationRegistry maintains separate registries for each namelist type:
- Surfaces
- Materials
- Meshes
- Devices
- Reactions
- Species
- And all other namelist types
RegistryView¶
Read-only view of a registry, providing safe access without modification.
from pyfds import Simulation
sim = Simulation(chid="test")
sim.add(Surface(id="FIRE", hrrpua=1000))
sim.add(Surface(id="WALL", color="GRAY"))
# Get read-only view of surfaces
surfaces_view = sim.surfaces # Returns RegistryView
# Read operations work
fire = surfaces_view.get("FIRE")
all_surfaces = surfaces_view.get_all()
exists = surfaces_view.contains("FIRE")
# But cannot modify through view
# surfaces_view.add(...) # Not available
ID Management¶
Duplicate ID Detection¶
from pyfds import Simulation, Surface
from pyfds.exceptions import DuplicateIdError
sim = Simulation(chid="test")
sim.add(Surface(id="FIRE", hrrpua=1000))
try:
# This will raise an error
sim.add(Surface(id="FIRE", hrrpua=2000))
except DuplicateIdError as e:
print(f"Cannot add duplicate: {e}")
ID Resolution¶
from pyfds import Simulation, Obstruction
from pyfds.exceptions import UnknownIdError
sim = Simulation(chid="test")
try:
# Reference to undefined surface
sim.add(Obstruction(xb=(0, 1, 0, 1, 0, 1), surf_id="UNKNOWN"))
sim.write("test.fds") # Validation catches this
except UnknownIdError as e:
print(f"Unknown surface ID: {e}")
Type-Safe Access¶
The registry system is fully typed for IDE support:
from pyfds import Simulation, Surface
sim = Simulation(chid="test")
sim.add(Surface(id="FIRE", hrrpua=1000))
# Type-safe retrieval
surface: Surface = sim.surfaces.get("FIRE")
# IDE knows the type and provides autocomplete
print(surface.hrrpua) # IDE suggests 'hrrpua' attribute
Common Patterns¶
Checking for Existence¶
sim = Simulation(chid="test")
# Check before adding
if not sim.surfaces.contains("FIRE"):
sim.add(Surface(id="FIRE", hrrpua=1000))
Retrieving All Objects¶
sim = Simulation(chid="test")
# ... add multiple surfaces ...
# Get all surfaces
for surface in sim.surfaces.get_all():
print(f"Surface {surface.id}: {surface.hrrpua} kW/m²")
Conditional Object Creation¶
sim = Simulation(chid="test")
# Add default surface if not present
if not sim.surfaces.contains("INERT"):
sim.add(Surface(id="INERT", color="GRAY"))
Getting Object Count¶
sim = Simulation(chid="test")
# ... add objects ...
# Check registry sizes
surface_count = len(sim.surfaces.get_all())
mesh_count = len(sim.meshes.get_all())
print(f"Simulation has {surface_count} surfaces and {mesh_count} meshes")
Advanced Usage¶
Programmatic Object Creation¶
from pyfds import Simulation, Device
from pyfds.core.geometry import Point3D
sim = Simulation(chid="test")
# Create devices programmatically
for i in range(10):
for j in range(10):
device = Device(
id=f"TEMP_{i}_{j}",
quantity="TEMPERATURE",
xyz=Point3D.of(i * 1.0, j * 1.0, 2.4)
)
sim.add(device)
# Registry ensures all IDs are unique
print(f"Created {len(sim.devices.get_all())} devices")
Bulk Operations¶
sim = Simulation(chid="test")
# ... add multiple materials ...
# Process all materials
for material in sim.materials.get_all():
if material.density and material.density < 100:
print(f"Warning: {material.id} has low density")
Cross-Reference Validation¶
sim = Simulation(chid="test")
# Add surfaces and obstructions
sim.add(Surface(id="FIRE", hrrpua=1000))
sim.add(Obstruction(xb=(2, 3, 2, 3, 0, 0.1), surf_id="FIRE"))
# Registry enables validation
# Can check if all surf_id references are valid
for obst in sim.obstructions.get_all():
if obst.surf_id and not sim.surfaces.contains(obst.surf_id):
print(f"Warning: {obst.id} references unknown surface {obst.surf_id}")
Implementation Details¶
Registry Properties¶
Each namelist type has a corresponding registry accessed via properties on the Simulation class:
sim.surfaces # Registry[Surface]
sim.materials # Registry[Material]
sim.meshes # Registry[Mesh]
sim.obstructions # Registry[Obstruction]
sim.vents # Registry[Vent]
sim.devices # Registry[Device]
sim.reactions # Registry[Reaction]
sim.species # Registry[Species]
# ... and more
ID Uniqueness Scope¶
IDs must be unique within their type:
sim = Simulation(chid="test")
# This is OK - different types can have same ID
sim.add(Surface(id="FIRE", hrrpua=1000))
sim.add(Device(id="FIRE", quantity="TEMPERATURE", xyz=(5, 5, 2)))
# This is NOT OK - same type, duplicate ID
sim.add(Surface(id="FIRE", color="RED")) # Raises DuplicateIdError
See Also¶
- Simulation - Main simulation class that uses registries
- Exceptions - DuplicateIdError and UnknownIdError
- Validation - Cross-reference validation