Simulation¶
The Simulation class is the main entry point for creating FDS simulations with PyFDS.
Overview¶
Simulation provides a Pythonic interface for building FDS input files. It manages all namelist groups and provides methods for adding simulation components.
from pyfds import Simulation
# Create a new simulation
sim = Simulation(chid='my_fire', title='My Fire Simulation')
# Add components
sim.add(Time(t_end=600.0))
sim.add(Mesh(ijk=Grid3D.of(50, 50, 25), xb=Bounds3D.of(0, 5, 0, 5, 0, 2.5)))
sim.add(Surface(id='FIRE', hrrpua=1000.0))
sim.add(Obstruction(xb=Bounds3D.of(2, 3, 2, 3, 0, 0.1), surf_id='FIRE'))
# Write FDS file
sim.write('my_fire.fds')
Class Reference¶
Simulation
¶
Main class for building FDS simulations.
This class mirrors the structure of an FDS input file, which consists
of namelist groups like MESH, SURF, MATL, etc. All components are added
using the unified add() method.
| PARAMETER | DESCRIPTION |
|---|---|
chid
|
Case identifier (filename prefix for all output files). Must be 50 characters or less, no spaces or periods (FDS requirement).
TYPE:
|
title
|
Descriptive title for the simulation (256 characters max).
TYPE:
|
eager_validation
|
If True, validate cross-references when items are added. If False (default), validation only occurs at write time.
TYPE:
|
| ATTRIBUTE | DESCRIPTION |
|---|---|
meshes |
Read-only view of registered meshes
TYPE:
|
surfaces |
Read-only view of registered surfaces
TYPE:
|
materials |
Read-only view of registered materials
TYPE:
|
obstructions |
Read-only view of registered obstructions
TYPE:
|
vents |
Read-only view of registered vents
TYPE:
|
holes |
Read-only view of registered holes
TYPE:
|
devices |
Read-only view of registered devices
TYPE:
|
props |
Read-only view of registered properties
TYPE:
|
ctrls |
Read-only view of registered controls
TYPE:
|
species |
Read-only view of registered species
TYPE:
|
reactions |
Read-only view of registered reactions
TYPE:
|
ramps |
Read-only view of registered ramps
TYPE:
|
mults |
Read-only view of registered multipliers
TYPE:
|
inits |
Read-only view of registered initial conditions
TYPE:
|
Examples:
Create a basic room fire simulation:
>>> from pyfds import Simulation
>>> from pyfds.core.geometry import Bounds3D, Grid3D
>>> from pyfds.core.namelists import Time, Mesh, Surface, Obstruction
>>>
>>> sim = Simulation(chid='room_fire', title='Simple Room Fire')
>>> sim.add(
... Time(t_end=600.0),
... Mesh(ijk=Grid3D.of(50, 50, 25), xb=Bounds3D.of(0, 5, 0, 5, 0, 2.5)),
... Surface(id='FIRE', hrrpua=1000.0, color='RED'),
... Obstruction(xb=Bounds3D.of(2, 3, 2, 3, 0, 0.1), surf_id='FIRE')
... )
>>> sim.write('room_fire.fds')
Notes
This class uses a unified registry system to ensure all IDs are unique across the entire simulation, matching FDS behavior. Validation is performed automatically before writing or running simulations.
Initialize a new FDS simulation.
Source code in src/pyfds/core/simulation.py
Functions¶
set_misc
¶
Set MISC parameters for the simulation.
Can be called with a Misc object or with keyword arguments to create one.
| PARAMETER | DESCRIPTION |
|---|---|
misc
|
Misc object to set (if None, kwargs are used to create one)
TYPE:
|
**kwargs
|
Keyword arguments to pass to Misc constructor
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Simulation
|
Self for method chaining |
Examples:
Notes
Only one MISC namelist is allowed per simulation. Calling this method multiple times will raise an error.
Source code in src/pyfds/core/simulation.py
validate
¶
Validate the simulation configuration.
| RETURNS | DESCRIPTION |
|---|---|
List[str]
|
List of validation warnings (empty if no issues) |
Examples:
>>> sim = Simulation('test')
>>> warnings = sim.validate()
>>> if warnings:
... for w in warnings:
... print(f"Warning: {w}")
Source code in src/pyfds/core/simulation.py
to_fds
¶
Generate the complete FDS input file content.
| RETURNS | DESCRIPTION |
|---|---|
str
|
FDS input file content |
Examples:
>>> sim = Simulation('test')
>>> sim.add(Time(t_end=100.0))
>>> sim.add(Mesh(ijk=Grid3D.of(10, 10, 10), xb=Bounds3D.of(0, 1, 0, 1, 0, 1)))
>>> content = sim.to_fds()
Source code in src/pyfds/core/simulation.py
533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 | |
write
¶
Write the FDS input file to disk.
| PARAMETER | DESCRIPTION |
|---|---|
filename
|
Path to output file (should have .fds extension)
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Path
|
Path to the written file |
Examples:
>>> sim = Simulation('test')
>>> sim.add(Time(t_end=100.0))
>>> sim.add(Mesh(ijk=Grid3D.of(10, 10, 10), xb=Bounds3D.of(0, 1, 0, 1, 0, 1)))
>>> sim.write('test.fds')
Source code in src/pyfds/core/simulation.py
run
¶
Write FDS file and execute simulation.
This is a convenience method that combines write() and execution in a single call. The FDS file is written to a temporary location or specified output directory, then executed.
| PARAMETER | DESCRIPTION |
|---|---|
config
|
Execution configuration (default: RunConfig())
TYPE:
|
**kwargs
|
Additional keyword arguments passed to RunConfig()
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Results or Job
|
Results object if wait=True, Job object if wait=False |
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If validation fails and strict=True |
ExecutionError
|
If FDS execution fails |
FDSNotFoundError
|
If FDS executable cannot be found |
Examples:
>>> sim = Simulation('test')
>>> sim.add(Time(t_end=100.0))
>>> sim.add(Mesh(ijk=Grid3D.of(10, 10, 10), xb=Bounds3D.of(0, 1, 0, 1, 0, 1)))
>>> results = sim.run(n_threads=4)
>>> print(f"Peak HRR: {results.hrr['HRR'].max()}")
>>> # Non-blocking execution
>>> job = sim.run(wait=False, monitor=True)
>>> while job.is_running():
... print(f"Progress: {job.progress}%")
... time.sleep(5)
>>> results = job.get_results()
Source code in src/pyfds/core/simulation.py
734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 | |
Quick Reference¶
Creating a Simulation¶
# Basic creation
sim = Simulation(chid='test')
# With title
sim = Simulation(chid='test', title='My Test Simulation')
Time Configuration¶
# Simple
sim.add(Time(t_end=600.0))
# With start time and time step
sim.add(Time(t_end=600.0, t_begin=0.0, dt=0.1))
Domain Setup¶
# Single mesh
sim.add(Mesh(ijk=Grid3D.of(50, 50, 25), xb=Bounds3D.of(0, 5, 0, 5, 0, 2.5)))
# Multiple meshes
sim.add(Mesh(ijk=Grid3D.of(50, 50, 25), xb=Bounds3D.of(0, 5, 0, 5, 0, 2.5), id='MESH1'))
sim.add(Mesh(ijk=Grid3D.of(30, 30, 15), xb=Bounds3D.of(5, 8, 0, 3, 0, 1.5), id='MESH2'))
Surfaces¶
# Fire surface
sim.add(Surface(id='BURNER', hrrpua=1000.0, color='RED'))
# Material surface
sim.add(Surface(id='WALL', matl_id='CONCRETE', thickness=0.2))
# Boundary condition
sim.add(Surface(id='INLET', vel=1.0, tmp_front=25.0))
Geometry¶
# Obstruction
sim.add(Obstruction(
xb=Bounds3D.of(0, 0.2, 0, 5, 0, 2.5),
surf_id='WALL'
)
# Vent
sim.add(Vent(
xb=Bounds3D.of(4, 4, 0, 2, 0, 2),
surf_id='OPEN'
)
# Circular vent
sim.add(Vent(
xb=Bounds3D.of(-2, 2, -2, 2, 0, 0),
surf_id='BURNER',
xyz=Point3D.of(0, 0, 0),
radius=1.0
)
Devices¶
# Point measurement
sim.add(Device(
id='TEMP_1',
quantity='TEMPERATURE',
xyz=Point3D.of(2.5, 2.5, 2.4)
)
# Area measurement
sim.add(Device(
id='HF_FLOOR',
quantity='HEAT FLUX',
xb=Bounds3D.of(0, 5, 0, 5, 0, 0)
)
Advanced Features¶
# Material definition
sim.add(Material(
id='WOOD',
conductivity=0.12,
specific_heat=1.0,
density=500.0
)
# Time-varying property
sim.add(Ramp(
id='FIRE_GROWTH',
t=[0, 100, 200, 300],
f=[0, 0.5, 1.0, 1.0]
)
# Control logic
sim.add(Control(
id='ACTIVATION',
input_id='TEMP_1',
setpoint=100.0
)
# Initial condition
sim.add(Init(
xb=Bounds3D.of(0, 5, 0, 5, 2.0, 2.5),
temperature=200.0
)
Validation and Output¶
# Validate before writing
warnings = sim.validate()
for w in warnings:
print(f"Warning: {w}")
# Write FDS file
sim.write('simulation.fds')
# Get FDS content as string
fds_content = sim.to_fds()
print(fds_content)
Execution¶
# Blocking execution
results = sim.run(n_threads=4)
# Non-blocking execution
job = sim.run(wait=False, monitor=True)
# With MPI
results = sim.run(n_mpi=4, n_threads=2)
Method Chaining¶
All configuration methods return self for chaining:
sim = (Simulation(chid='test')
.add(Time(t_end=600.0))
.add(Mesh(ijk=Grid3D.of(50, 50, 25), xb=Bounds3D.of(0, 5, 0, 5, 0, 2.5)))
.add(Surface(id='FIRE', hrrpua=1000.0))
.add(Obstruction(xb=Bounds3D.of(2, 3, 2, 3, 0, 0.1), surf_id='FIRE')))
sim.write('test.fds')
See Also¶
- Validation - Validation functionality
- Namelist Classes - Individual namelist documentation
- User Guide - Comprehensive usage guide