Site percolation
Site percolation probed by a fire lit along the top row.
- Class:
SitePercolationSystem - Import:
from skcomplex.systems.physics.statistical_mechanics import SitePercolationSystem - Field:
physics/statistical_mechanics - Topics:
lattice,percolation,phase transition,fire - References:
- Broadbent and Hammersley 1957
- Stauffer and Aharony 1994
- 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.statistical_mechanics import SitePercolationSystem
trajectory = SitePercolationSystem().prepare().simulate()
Parameters
The model parameters take these defaults, and set_params changes them.
| Parameter | Default |
|---|---|
shape |
(64, 64) |
p |
0.6 |
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 SitePercolationSystem(BaseSystem):
"""Site percolation probed by a fire lit along the top row.
The fire spans the lattice above `p_c = 0.5927`.
Sites are occupied with probability `p`, and the fire burns the clusters connected to the top row, one layer of
sites per step. The system has the covers `lattice.cover`.
Args:
shape:
The number of rows and columns.
p:
The occupation probability.
random_state:
The seed or generator of the occupations.
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.statistical_mechanics import SitePercolationSystem
>>> trajectory = SitePercolationSystem((10, 10)).prepare().simulate(until=1)
>>> trajectory.get_values('lattice.cover').shape
(2, 100)
"""
field = 'physics/statistical_mechanics'
topics = ('lattice', 'percolation', 'phase transition', 'fire')
references = ('Broadbent and Hammersley 1957', 'Stauffer and Aharony 1994', 'Charbonneau 2017')
until = 200
dt = 1
def __init__(
self,
shape: Sequence[int] = (64, 64),
*,
p: float = 0.6,
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.p = p
self.random_state = random_state
def _prepare(self, context: Sequence[Observable] | None = None) -> None:
"""Set the occupied sites with the fire lit along the top row.
Args:
context:
The observables to compile with the problem, or `None` for none.
"""
super()._prepare(context)
shape = tuple(self.shape)
cover = (np.random.default_rng(self.random_state).random(shape) < self.p).astype(float)
cover[0] *= BURNING
sites = PercolationSiteElement('lattice', cover=cover.ravel(), space=LatticeSpace(shape, boundary='fixed'))
fire = FireSpreadInteraction('fire', target='lattice')
self.system_ = System(self.label, elements=[sites], interactions=[fire])
Components
The system uses these element and interaction classes, each with its nearest class of the core.
Elements:
PercolationSiteElement, fromElement
Interactions:
FireSpreadInteraction, fromInteraction
class PercolationSiteElement(Element):
"""Sites of a percolation lattice.
Every site is empty at 0, occupied at 1, burning at 2, or burnt at 3.
Args:
label:
The label of the site or the lattice of sites.
cover:
The initial cover, 0, 1, 2, or 3, or one cover per site.
space:
The lattice of the sites, or `None` for one site.
Examples:
>>> from skcomplex.systems.physics.statistical_mechanics import PercolationSiteElement
>>> PercolationSiteElement('site').cover
0.0
"""
def __init__(self, label: str, *, cover: object = 0.0, space: BaseSpace | None = None) -> None:
super().__init__(label, space=space)
self.cover = cover
class FireSpreadInteraction(Interaction):
"""Fire on a percolation lattice.
Fire spreads from burning sites to their occupied neighbours and burns out in one step, so a fire lit along one
edge burns exactly the clusters that touch that edge.
Args:
label:
The label of the interaction.
target:
The path of the sites, whose value `cover` is 0, 1, 2, or 3.
Examples:
>>> from skcomplex.systems.physics.statistical_mechanics import FireSpreadInteraction
>>> FireSpreadInteraction('fire', target='lattice').target
'lattice'
"""
law_classes = (UpdateLaw,)
def __init__(self, label: str, *, target: Role) -> None:
super().__init__(label)
self.target = target
@staticmethod
def _burn(cover: Array, *around: Array, **kwargs: object) -> Array:
"""Return the next cover of a site.
The site burns out, catches fire from a burning neighbour, or stays.
"""
catches = (cover == 1) & np.any(np.stack(around) == BURNING, axis=0)
return np.where(cover == BURNING, BURNT, np.where(catches, BURNING, cover))
def _prepare(self, context: SimpleNamespace) -> None:
"""Set the spread and the burning out of the fire.
Args:
context:
The namespace of the target, the time `t`, and the parameters.
"""
super()._prepare(context)
self.laws_ = [UpdateLaw(context.target.cover, self._burn, neighborhood=NEAREST, label=self.label)]