How forefireapi/forefire works
Purpose and Deliverables
ForeFire is a C++ wildfire-spread simulation engine and embeddable library. It simulates fire-front propagation over geospatial, fuel, weather, and terrain inputs; supports fire–atmosphere coupling; and writes formats such as NetCDF, KML, and GeoJSON. The primary build graph is defined in CMakeLists.txt; the core library API starts at src/CLibForeFire.h.
Execution and Integration Entry Points
The main interactive/script interpreter is app/forefire/ForeFire.cpp, with line editing in app/forefire/AdvancedLineEditor.cpp. It accepts .ff command scripts and interactive commands, and can expose an HTTP command server via src/HttpCommandServer.hpp.
Embedders use the C/C++ facade src/CLibForeFire.cpp. Python wraps this core through bindings/python/src/pyforefire/_pyforefire.cpp and provides a CLI in bindings/python/src/pyforefire/_cli.py; Java bindings are under bindings/java/JLibForeFire.cpp.
Simulation Orchestration
src/Simulator.cpp is the runtime coordinator: it advances simulation time and drives domain, events, data, and models. src/FireDomain.cpp owns the spatial/time simulation domain and its configured layers. src/SimulationParameters.cpp holds runtime parameters.
Control flow is command-driven: parsed commands mutate/configure the simulator and domain, trigger ignition or model actions, then invoke stepping/output. Relevant paths: src/Command.cpp, src/EventCommand.cpp, src/FFEvent.cpp.
Fire Geometry and Evolution
The propagating state is represented as fire fronts composed of nodes and points. src/FireFront.cpp manages a front, src/FireNode.cpp models evolving front nodes, and src/FFPoint.cpp / src/FFVector.cpp supply spatial primitives. src/BurningMap.cpp provides gridded burn-state representation.
The simulator queries local conditions, computes spread, advances node/front geometry, and updates burned-state/output layers.
Data-Layer Boundary
src/DataBroker.cpp mediates named data and model layers configured by scripts. The abstract layer contract is src/DataLayer.h; concrete layers cover fuel, weather, terrain-like gradients, time-varying fields, and NetCDF-backed data: src/FuelDataLayer.h, src/WeatherDataLayer.h, src/NCXYZTDataLayer.h.
This separates model logic from data sources and permits external raster/NetCDF datasets to drive simulations.
Spread and Flux Model Plugins
src/PropagationModel.cpp defines the rate-of-spread model boundary. Alternative physical and empirical implementations live in src/propagation/, including src/propagation/Rothermel.cpp, src/propagation/Balbi2020.cpp, and src/propagation/ANNPropagationModel.cpp.
Heat, vapor, spotting, and related fire-atmosphere source terms are abstracted by src/FluxModel.cpp and implementations in src/flux/, such as src/flux/BurnupHeatFluxModel.cpp and src/flux/SpottingFluxBasicModel.cpp.
Parallel and External Runtime Context
The CMake build can enable MPI for parallel execution and MesoNH fire–atmosphere coupling; parallel coordination is concentrated in src/ParallelData.cpp and src/ParallelException.cpp. NetCDF is a material data/output dependency, including for coupled scenarios. Python wheels intentionally disable MPI and bundle NetCDF.
Deployment paths include Dockerfile, CMake-built native binaries/libraries, and Python packaging via pyproject.toml. Coupled-MesoNH installation guidance and case workflow assets are in docs/mnh/coupledMNHInstall.md and tools/3nestFFCASE/.
Main entry points: Simulator.cpp Simulator · ForeFire.cpp ForeFire interpreter · CLibForeFire.cpp C/C++ facade · CMakeLists.txt CMake build
Components 20
Entry Points
- ForeFire interpreter · Executes interactive commands and .ff scripts.
app/forefire/ForeFire.cpp - Line editor
app/forefire/AdvancedLineEditor.cpp - HTTP command server
src/HttpCommandServer.hpp - C/C++ facade
src/CLibForeFire.cpp - Python extension
bindings/python/src/pyforefire/_pyforefire.cpp - Python CLI
bindings/python/src/pyforefire/_cli.py - Java binding
bindings/java/JLibForeFire.cpp
Simulation Core
- Command & event flow · Parses commands and creates simulation events.
src/Command.cpp - Simulator · Advances time and coordinates domain, events, data, and models.
src/Simulator.cpp - Fire domain · Owns configured simulation layers and spatial state.
src/FireDomain.cpp - Fire fronts · Fronts and nodes represent propagating fire perimeter state.
src/FireFront.cpp - Burning map
src/BurningMap.cpp
Models & Data
- Data broker · Resolves named data and model layers configured by scripts.
src/DataBroker.cpp - Data layers · Abstract fuel, weather, terrain, temporal, and NetCDF inputs.
src/DataLayer.h - Propagation models · Selects rate-of-spread implementations such as Rothermel or Balbi.
src/PropagationModel.cpp - Flux models · Provides heat, vapor, and spotting source terms.
src/FluxModel.cpp
Runtime & Delivery
- CMake build · Builds native binaries, library, and optional MPI/coupling features.
CMakeLists.txt - Parallel runtime · Optional parallel execution and coupled-runtime coordination.
src/ParallelData.cpp - NetCDF datasets & output · Material raster/coupled input and simulation output dependency.
src/NCXYZTDataLayer.h - MesoNH coupling · Optional fire–atmosphere coupled execution.
docs/mnh/coupledMNHInstall.md
Connections 23
- CMake build → ForeFire interpreter: builds
- CMake build → C/C++ facade: builds
- CMake build → Parallel runtime: enables optionally
- ForeFire interpreter → Line editor: uses
- ForeFire interpreter → Command & event flow: submits commands
- ForeFire interpreter → HTTP command server: may expose
- HTTP command server → Command & event flow: accepts commands
- C/C++ facade → Simulator: embeds
- Python extension → C/C++ facade: wraps
- Python CLI → Python extension: invokes
- Java binding → C/C++ facade: wraps
- Command & event flow → Simulator: configures and triggers
- Simulator → Fire domain: advances
- Simulator → Data broker: queries layers
- Simulator → Propagation models: computes spread
- Simulator → Flux models: computes source terms
- Fire domain → Fire fronts: owns evolving fronts
- Fire fronts → Burning map: updates burned state
- Data broker → Data layers: resolves
- Data layers → NetCDF datasets & output: reads
- Simulator → Parallel runtime: coordinates optionally
- Flux models → MesoNH coupling: supports coupling
- NetCDF datasets & output → MesoNH coupling: exchanges coupled data