Skip to content

Drossel-Schwabl forest fire

The Drossel-Schwabl forest fire.

  • Class: ForestFireSystem
  • Import: from skcomplex.systems.physics.criticality import ForestFireSystem
  • Field: physics/criticality
  • Topics: lattice, fire, stochastic, power law
  • References:
    • Drossel and Schwabl 1992
    • Charbonneau 2017

Use this system

The block imports the class and simulates the system with its default parameters and its tuned run settings.

from skcomplex.systems.physics.criticality import ForestFireSystem

trajectory = ForestFireSystem().prepare().simulate()

Parameters

The model parameters take these defaults, and set_params changes them.

Parameter Default
shape (100, 100)
growth 0.05
lightning 0.0001
density 0.5
random_state 0
solver 'auto'
backend 'auto'

Tags

The system with its default parameters has these capability tags, which solvers and analyses check.

Tag Values
Time discrete
Space lattice
Laws update
Randomness deterministic
Domains real
Structure fixed

Class

The source of the class shows how it builds its components from its model parameters.

class ForestFireSystem(BaseSystem):
    """The Drossel-Schwabl forest fire.

    Slow growth and rare lightning give fires of every size.

    The system has the covers `forest.cover`.

    Args:
        shape:
            The number of rows and columns.

        growth:
            The probability that a tree grows on an empty site per step.

        lightning:
            The probability that lightning strikes a tree per step.

        density:
            The initial fraction of sites with a tree.

        random_state:
            The seed or generator of the initial forest.

        label:
            The label of the system, which names it when it is nested in another one.

        solver:
            The solver of the problem, or `'auto'` for the one the system chooses.

        backend:
            The backend that evaluates the compiled functions, or `'auto'` for the one the system chooses.

    Examples:
        >>> from skcomplex.systems.physics.criticality import ForestFireSystem
        >>> ForestFireSystem((10, 10)).prepare().system_.elements[0].growth
        0.05
    """

    field = 'physics/criticality'
    topics = ('lattice', 'fire', 'stochastic', 'power law')
    references = ('Drossel and Schwabl 1992', 'Charbonneau 2017')
    until = 500
    dt = 1

    def __init__(
        self,
        shape: Sequence[int] = (100, 100),
        *,
        growth: float = 0.05,
        lightning: float = 1e-4,
        density: float = 0.5,
        random_state: int | np.random.Generator | None = 0,
        label: str = 'system',
        solver: BaseSolver | str = 'auto',
        backend: BaseBackend | str = 'auto',
    ) -> None:
        super().__init__(label, solver=solver, backend=backend)
        self.shape = shape
        self.growth = growth
        self.lightning = lightning
        self.density = density
        self.random_state = random_state

    def _prepare(self, context: Sequence[Observable] | None = None) -> None:
        """Set the Drossel-Schwabl forest fire, where slow growth and rare lightning give fires of every size.

        Args:
            context:
                The observables to compile with the problem, or `None` for none.
        """
        super()._prepare(context)
        cover = (np.random.default_rng(self.random_state).random(tuple(self.shape)) < self.density).astype(float)
        forest = ForestElement(
            'forest',
            cover=cover.ravel(),
            growth=self.growth,
            lightning=self.lightning,
            space=LatticeSpace(tuple(self.shape)),
        )
        self.system_ = System(self.label, elements=[forest], interactions=[FireInteraction('fire', target='forest')])

Components

The system uses these element and interaction classes, each with its nearest class of the core.

Elements:

Interactions:

  • FireInteraction, from Interaction
class ForestElement(Element):
    """Sites of the Drossel-Schwabl forest fire.

    Every site is empty at 0, a tree at 1, or burning at 2.

    A `FireInteraction` grows trees on empty sites with probability `growth`, sets them on fire from a burning
    neighbour or from lightning with probability `lightning`, and empties burning sites.

    Args:
        label:
            The label of the site or the lattice of sites.

        cover:
            The initial cover, 0, 1, or 2, or one cover per site.

        growth:
            The probability that a tree grows on an empty site per step.

        lightning:
            The probability that lightning strikes a tree per step.

        space:
            The lattice or network of the sites, or `None` for one site.

    Examples:
        >>> from skcomplex.systems.physics.criticality import ForestElement
        >>> ForestElement('site').growth
        0.05
    """

    def __init__(
        self,
        label: str,
        *,
        cover: object = 0.0,
        growth: Annotated[float, RealSet.closed_open(0, oo)] = 0.05,
        lightning: Annotated[float, RealSet.closed_open(0, oo)] = 0.0001,
        space: BaseSpace | None = None,
    ) -> None:
        super().__init__(label, space=space)
        self.cover = cover
        self.growth = growth
        self.lightning = lightning

class FireInteraction(Interaction):
    """Stochastic rule of the Drossel-Schwabl forest fire.

    The cover is 0 for empty, 1 for a tree, and 2 for burning.

    Every step a tree catches fire from a burning neighbour or from lightning with the probability `lightning` of the
    site, a burning site becomes empty, and a tree grows on an empty site with the probability `growth` of the site.

    Args:
        label:
            The label of the interaction, unique among the components of its system.

        target:
            The path of the lattice or network of sites.

        neighborhood:
            The neighbours a fire spreads to, the von Neumann neighbourhood of a square lattice, the six neighbours of
            a triangular lattice, or the neighbours of a node, each with the site itself.

    Examples:
        >>> from skcomplex.systems.physics.criticality import FireInteraction
        >>> FireInteraction('fire', target='forest').neighborhood.metric
        'manhattan'
    """

    law_classes = (UpdateLaw,)

    def __init__(self, label: str, *, target: Role, neighborhood: BaseNeighborhood = NEAREST) -> None:
        super().__init__(label)
        self.target = target
        self.neighborhood = neighborhood

    @staticmethod
    def _burn(
        cover: Array,
        *around: Array,
        growth: float | Array,
        lightning: float | Array,
        random: Array,
        **kwargs: object,
    ) -> Array:
        """Return the covers after trees catch fire, fires burn out, and trees grow."""
        burning = np.any(np.stack(around) == BURNING, axis=0) if around else np.zeros(np.shape(cover), dtype=bool)
        ignites = burning | (random < lightning)
        tree = np.where(ignites, float(BURNING), 1.0)
        empty = np.where(random < growth, 1.0, 0.0)
        return np.where(cover == BURNING, 0.0, np.where(cover == 1, tree, empty))

    def _prepare(self, context: SimpleNamespace) -> None:
        """Set the rule of the covers of the target.

        Args:
            context:
                The namespace of the target and the time `t`.
        """
        super()._prepare(context)
        self.laws_ = [UpdateLaw(context.target.cover, self._burn, neighborhood=self.neighborhood, stochastic=True)]