Swift-Hohenberg
The Swift-Hohenberg equation u_t = r u - (1 + laplacian)^2 u - u^3.
- Class:
SwiftHohenbergSystem - Import:
from skcomplex.systems.physics.pattern_formation import SwiftHohenbergSystem - Field:
physics/pattern_formation - Topics:
field,rolls,convection,spectral,pde - References:
- Swift and Hohenberg 1977
- Cross and Hohenberg 1993
- Datseris and Parlitz 2022
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.pattern_formation import SwiftHohenbergSystem
trajectory = SwiftHohenbergSystem().prepare().simulate()
Parameters
The model parameters take these defaults, and set_params changes them.
| Parameter | Default |
|---|---|
shape |
(64, 64) |
length |
50.26548245743669 |
r |
0.3 |
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 | continuous |
| Space | lattice |
| Laws | rate |
| Randomness | deterministic |
| Domains | real |
| Structure | fixed |
Class
The source of the class shows how it builds its components from its model parameters.
class SwiftHohenbergSystem(BaseSystem):
"""The Swift-Hohenberg equation `u_t = r u - (1 + laplacian)^2 u - u^3`.
The equation forms rolls of length 2 pi.
Above onset, `r > 0`, small noise grows into rolls whose wavenumber is near 1, the fastest growing one. The system
has the field `cells.u`.
Args:
shape:
The number of sites along every axis of the periodic lattice.
length:
The side of the domain.
r:
The distance above onset.
random_state:
The seed or generator of the noise.
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 exponential steps of 0.5.
backend:
The backend that evaluates the compiled functions, or `'auto'` for the one the system chooses.
Examples:
>>> from skcomplex.systems.physics.pattern_formation import SwiftHohenbergSystem
>>> SwiftHohenbergSystem((8, 8), r=0.1).prepare().system_.interactions[0].r
0.1
"""
field = 'physics/pattern_formation'
topics = ('field', 'rolls', 'convection', 'spectral', 'pde')
references = ('Swift and Hohenberg 1977', 'Cross and Hohenberg 1993', 'Datseris and Parlitz 2022')
until = 200.0
dt = 5.0
def __init__(
self,
shape: Sequence[int] = (64, 64),
*,
length: float = 16 * math.pi,
r: float = 0.3,
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.length = length
self.r = r
self.random_state = random_state
def _prepare(self, context: Sequence[Observable] | None = None) -> None:
"""Set the system of the Swift-Hohenberg equation from small noise.
Args:
context:
The observables to compile with the problem, or `None` for none.
"""
super()._prepare(context)
shape = tuple(self.shape)
u = ComplexGinzburgLandauSystem._get_noise(shape, 0.01, self.random_state)
space = LatticeSpace(shape, spacing=self.length / shape[0], discretization='spectral')
self.system_ = System(
self.label,
elements=[PatternFieldElement('cells', u=u.ravel(), space=space)],
interactions=[SwiftHohenbergEnergyInteraction('energy', target='cells', r=self.r)],
solver=ETDRK4Solver(dt=0.5),
)
Components
The system uses these element and interaction classes, each with its nearest class of the core.
Elements:
PatternFieldElement, fromElement
Interactions:
SwiftHohenbergEnergyInteraction, fromInteraction, through the shared recipeGradientInteraction
class PatternFieldElement(Element):
"""Sites of a real field `u` whose patterns a free energy selects.
Args:
label:
The label of the field.
u:
The initial value of the field, one value per site or one for all.
space:
The lattice of the sites, or `None` for one site.
Examples:
>>> from skcomplex.systems.physics.pattern_formation import PatternFieldElement
>>> PatternFieldElement('site', u=0.1).u
0.1
"""
def __init__(self, label: str, *, u: object = 0.0, space: BaseSpace | None = None) -> None:
super().__init__(label, space=space)
self.u = u
class SwiftHohenbergEnergyInteraction(GradientInteraction):
"""Gradient flow of a field in the Swift-Hohenberg free energy.
The flow is `u_t = r u - (1 + laplacian)^2 u + g u^2 - u^3`.
The free energy is `F = integral -r u^2 / 2 + ((1 + laplacian) u)^2 / 2 - g u^3 / 3 + u^4 / 4`. Above onset,
`r > 0`, the modes of wavenumber near 1 grow into rolls, or into hexagons for a large enough quadratic term `g`.
Args:
label:
The label of the interaction, unique among the components of its system.
target:
The path of the field.
state:
The name of the state of the field.
r:
The distance above onset.
g:
The strength of the quadratic term, which breaks the symmetry `u -> -u`.
Examples:
>>> from types import SimpleNamespace
>>> from sage.all__sagemath_symbolics import var
>>> from skcomplex.systems.physics.pattern_formation._patterns import SwiftHohenbergEnergyInteraction
>>> energy = SwiftHohenbergEnergyInteraction('energy', target='cells')
>>> namespace = SimpleNamespace(target=SimpleNamespace(u=var('u')), r=var('r'), g=0)
>>> [law.value for law in energy.prepare(namespace).laws_]
[-u^3 + r*u - u - 2*laplacian(u) - laplacian(laplacian(u))]
"""
def __init__(
self,
label: str,
*,
target: Role,
state: str = 'u',
r: float = 0.3,
g: float = 0.0,
) -> None:
super().__init__(label, target=target, states=state, variational=True)
self.state = state
self.r = r
self.g = g
def _get_potential(self, namespace: SimpleNamespace) -> Expression:
"""Return the Swift-Hohenberg free energy density.
The density is `-r u^2 / 2 + (u + laplacian(u))^2 / 2 - g u^3 / 3 + u^4 / 4`.
Args:
namespace:
The namespace of the symbols the density can use.
Returns:
density:
The density of the free energy.
"""
u = getattr(namespace.target, self.state)
return -namespace.r * u**2 / 2 + (u + laplacian(u)) ** 2 / 2 - namespace.g * u**3 / 3 + u**4 / 4