Skip to content

Fluids

Fluid dynamics systems.

The package covers flows, convection cells, turbulence, shocks, shallow water, wave trains, and kinetic gases.

BGKEquationSystem(positions=100, velocities=32, *, knudsen=0.01, half_width=6.0, label='system', solver='auto', backend='auto')

Bases: BaseSystem

The BGK equation of the Sod shock tube over one position and one velocity axis.

The density relaxes at every position towards the maximum-entropy density with its density, momentum, and energy, and the gas starts from the two states of the shock tube of Sod on either side of the middle of a unit interval. As the Knudsen number falls the density moment tends to the Euler solution with the adiabatic index 3 of one velocity dimension. The system has the density gas.x.

Parameters:

Name Type Description Default
positions int

The number of positions.

100
velocities int

The number of points of the velocity axis.

32
knudsen float

The Knudsen number, the relaxation time.

0.01
half_width float

The half-width of the velocity axis.

6.0
label str

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

'system'
solver BaseSolver | str

The solver of the problem, or 'auto' for the steps the system chooses.

'auto'
backend BaseBackend | str

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

'auto'

Examples:

>>> from skcomplex.systems.physics.fluids import BGKEquationSystem
>>> BGKEquationSystem(8, 16).prepare().system_.elements[0].space.prepare().size_
128
Source code in src/skcomplex/systems/physics/fluids/_kinetic_equations.py
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
def __init__(
    self,
    positions: int = 100,
    velocities: int = 32,
    *,
    knudsen: float = 1e-2,
    half_width: float = 6.0,
    label: str = 'system',
    solver: BaseSolver | str = 'auto',
    backend: BaseBackend | str = 'auto',
) -> None:
    super().__init__(label, solver=solver, backend=backend)
    self.positions = positions
    self.velocities = velocities
    self.knudsen = knudsen
    self.half_width = half_width

BenardMarangoniSystem(shape=(64, 64), *, length=16 * math.pi, r=0.1, g=1.0, random_state=0, label='system', solver='auto', backend='auto')

Bases: BaseSystem

The order-parameter equation of Bénard-Marangoni convection.

The convection forms hexagonal cells.

The field u is the vertical velocity at mid-depth of a heated layer whose open surface has a surface tension that falls with temperature. It follows u_t = r u - (1 + laplacian)^2 u + g u^2 - u^3, the Swift-Hohenberg equation of convection with the quadratic term that the thermocapillary surface adds by breaking the symmetry between rising and sinking fluid. With g > 0 and small r > 0, the cells are hexagons of rising fluid with a wavenumber near 1, and with g = 0, the layer of a fixed surface, they are rolls. The system has the field layer.u.

Parameters:

Name Type Description Default
shape Sequence[int]

The number of sites along every axis of the periodic lattice.

(64, 64)
length float

The side of the domain.

16 * pi
r float

The distance above onset.

0.1
g float

The strength of the quadratic term of the thermocapillary surface.

1.0
random_state int | Generator | None

The seed or generator of the small random initial field.

0
label str

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

'system'
solver BaseSolver | str

The solver of the problem, or 'auto' for exponential steps of 0.5.

'auto'
backend BaseBackend | str

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

'auto'

Examples:

>>> from skcomplex.systems.physics.fluids import BenardMarangoniSystem
>>> BenardMarangoniSystem((8, 8), g=0.5).prepare().system_.interactions[0].g
0.5
Source code in src/skcomplex/systems/physics/fluids/_marangoni.py
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
def __init__(
    self,
    shape: Sequence[int] = (64, 64),
    *,
    length: float = 16 * math.pi,
    r: float = 0.1,
    g: float = 1.0,
    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.g = g
    self.random_state = random_state

BhatnagarGrossKrookInteraction(label, *, target, state='x', axes=('v',), time=1.0)

Bases: RelaxationTimeInteraction

Relaxation of Bhatnagar, Gross, and Krook of a density.

The density relaxes towards the maximum-entropy density with its moments.

Parameters:

Name Type Description Default
label str

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

required
target Role

The path of the field on a phase space.

required
state str

The name of the state of the density.

'x'
axes Sequence[str]

The names of the velocity axes.

('v',)
time Callable[[SimpleNamespace], object] | float

A function of the namespace that returns the relaxation time, or a positive number.

1.0

Examples:

>>> from skcomplex.systems.physics.fluids import BhatnagarGrossKrookInteraction
>>> BhatnagarGrossKrookInteraction('bgk', target='gas', axes=('v',), time=0.1).axes
('v',)
Source code in src/skcomplex/systems/physics/fluids/_kinetic_equations.py
200
201
202
203
204
205
206
207
208
209
210
def __init__(
    self,
    label: str,
    *,
    target: Role,
    state: str = 'x',
    axes: Sequence[str] = ('v',),
    time: Callable[[SimpleNamespace], object] | float = 1.0,
) -> None:
    super().__init__(label, target=target, state=state, goal=0.0, time=time)
    self.axes = axes

BoltzmannEquationSystem(positions=8, velocities=12, *, knudsen=1.0, half_width=6.0, label='system', solver='auto', backend='auto')

Bases: BaseSystem

The Boltzmann equation of Maxwell molecules.

The equation is over one position and two velocity axes.

Free streaming moves a density wave along the periodic position axis, and binary collisions redistribute the density over the velocities at every position, by the fast spectral method. The system has the density gas.x.

Parameters:

Name Type Description Default
positions int

The number of positions.

8
velocities int

The number of points of each velocity axis.

12
knudsen float

The Knudsen number, the inverse of the collision frequency.

1.0
half_width float

The half-width of each velocity axis.

6.0
label str

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

'system'
solver BaseSolver | str

The solver of the problem, or 'auto' for the steps the system chooses.

'auto'
backend BaseBackend | str

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

'auto'

Examples:

>>> from skcomplex.systems.physics.fluids import BoltzmannEquationSystem
>>> BoltzmannEquationSystem(4, 8).prepare().system_.elements[0].space.prepare().size_
256
Source code in src/skcomplex/systems/physics/fluids/_kinetic_equations.py
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
def __init__(
    self,
    positions: int = 8,
    velocities: int = 12,
    *,
    knudsen: float = 1.0,
    half_width: float = 6.0,
    label: str = 'system',
    solver: BaseSolver | str = 'auto',
    backend: BaseBackend | str = 'auto',
) -> None:
    super().__init__(label, solver=solver, backend=backend)
    self.positions = positions
    self.velocities = velocities
    self.knudsen = knudsen
    self.half_width = half_width

BoussinesqElement(label, *, omega=0.0, theta=0.0, Ra=1000.0, Pr=1.0, space=None)

Bases: Element

Sites of Boussinesq convection, with the vorticity omega and the temperature departure theta.

The units are those of the thermal diffusion time.

The temperature theta is the departure from the linear profile between a hot bottom and a cold top, so dtheta/dt + u . grad(theta) = w + laplacian(theta) and domega/dt + u . grad(omega) = Pr laplacian(omega) + Ra Pr dtheta/dx. The advections, the diffusions, and the buoyancy are interactions of the system, which read the Rayleigh number Ra and the Prandtl number Pr of the layer.

Parameters:

Name Type Description Default
label str

The label of the layer.

required
omega object

The initial vorticity, one value per site or one for all.

0.0
theta object

The initial temperature departure, one value per site or one for all.

0.0
Ra Annotated[float, closed_open(0, oo)]

The Rayleigh number.

1000.0
Pr Annotated[float, open(0, oo)]

The Prandtl number.

1.0
space BaseSpace | None

The lattice of the sites, or None for one site.

None

Examples:

>>> from skcomplex.systems.physics.fluids import BoussinesqElement
>>> BoussinesqElement('site').Ra
1000.0
Source code in src/skcomplex/systems/physics/fluids/_flows.py
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
def __init__(
    self,
    label: str,
    *,
    omega: object = 0.0,
    theta: object = 0.0,
    Ra: Annotated[float, RealSet.closed_open(0, oo)] = 1000.0,
    Pr: Annotated[float, RealSet.open(0, oo)] = 1.0,
    space: BaseSpace | None = None,
) -> None:
    super().__init__(label, space=space)
    self.omega = omega
    self.theta = theta
    self.Ra = Ra
    self.Pr = Pr

BurgersElement(label, *, u=0.0, space=None)

Bases: Element

Cells of a field u carried by the Burgers equation.

The equation is du/dt + d(u^2 / 2)/dx = 0.

Parameters:

Name Type Description Default
label str

The label of the line.

required
u object

The initial value, one value per cell or one for all.

0.0
space BaseSpace | None

The lattice of the cells, or None for one cell.

None

Examples:

>>> from skcomplex.systems.physics.fluids import BurgersElement
>>> BurgersElement('site', u=1.5).u
1.5
Source code in src/skcomplex/systems/physics/fluids/_flows.py
105
106
107
def __init__(self, label: str, *, u: object = 0.0, space: BaseSpace | None = None) -> None:
    super().__init__(label, space=space)
    self.u = u

BurgersSystem(n=200, *, mean=1.5, amplitude=1.0, label='system', solver='auto', backend='auto')

Bases: BaseSystem

The inviscid Burgers equation on a periodic interval of length 2 pi.

Its sine steepens into a shock.

The cells hold averages updated by MUSCL reconstruction with a minmod limiter and Rusanov fluxes, so the total is conserved and the shock forms no new extrema. The shock forms at time 1 / amplitude. The system has the velocity line.u.

Parameters:

Name Type Description Default
n int

The number of cells.

200
mean float

The mean of the initial wave.

1.5
amplitude float

The amplitude of the initial wave.

1.0
label str

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

'system'
solver BaseSolver | str

The solver of the problem, or 'auto' for strong stability preserving Runge-Kutta steps.

'auto'
backend BaseBackend | str

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

'auto'

Examples:

>>> from skcomplex.systems.physics.fluids import BurgersSystem
>>> BurgersSystem(16).prepare().system_.elements[0].space.prepare().size_
16
Source code in src/skcomplex/systems/physics/fluids/_flows.py
665
666
667
668
669
670
671
672
673
674
675
676
677
678
def __init__(
    self,
    n: int = 200,
    *,
    mean: float = 1.5,
    amplitude: float = 1.0,
    label: str = 'system',
    solver: BaseSolver | str = 'auto',
    backend: BaseBackend | str = 'auto',
) -> None:
    super().__init__(label, solver=solver, backend=backend)
    self.n = n
    self.mean = mean
    self.amplitude = amplitude

CarlemanGasElement(label, *, f_plus=1.0, f_minus=1.0, c=1.0, kappa=1.0, space=None)

Bases: Element

Cells of the Carleman discrete-velocity gas.

The densities f_plus and f_minus move at the speeds c and -c.

Collisions turn two particles of one velocity into two of the other at the rate kappa, so df_plus/dt + c df_plus/dx = kappa (f_minus^2 - f_plus^2) and the opposite for f_minus, which conserves the mass and relaxes to the equilibrium f_plus = f_minus.

Parameters:

Name Type Description Default
label str

The label of the gas.

required
f_plus Annotated[object, closed_open(0, oo)]

The initial density of right-moving particles, one value per cell or one for all.

1.0
f_minus Annotated[object, closed_open(0, oo)]

The initial density of left-moving particles, one value per cell or one for all.

1.0
c Annotated[float, open(0, oo)]

The particle speed.

1.0
kappa Annotated[float, closed_open(0, oo)]

The collision rate.

1.0
space BaseSpace | None

The lattice of the cells, or None for one cell.

None

Examples:

>>> from skcomplex.systems.physics.fluids import CarlemanGasElement
>>> CarlemanGasElement('site').kappa
1.0
Source code in src/skcomplex/systems/physics/fluids/_kinetics.py
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
def __init__(
    self,
    label: str,
    *,
    f_plus: Annotated[object, RealSet.closed_open(0, oo)] = 1.0,
    f_minus: Annotated[object, RealSet.closed_open(0, oo)] = 1.0,
    c: Annotated[float, RealSet.open(0, oo)] = 1.0,
    kappa: Annotated[float, RealSet.closed_open(0, oo)] = 1.0,
    space: BaseSpace | None = None,
) -> None:
    super().__init__(label, space=space)
    self.f_plus = f_plus
    self.f_minus = f_minus
    self.c = c
    self.kappa = kappa

DecayingTurbulenceSystem(shape=(64, 64), *, nu=0.001, modes=6, random_state=0, label='system', solver='auto', backend='auto')

Bases: BaseSystem

Decaying two-dimensional turbulence from a random vorticity field.

The field lies on a periodic square of side 2 pi.

Energy flows to large scales and enstrophy to small scales, where viscosity removes it, so vortices merge while the enstrophy decays faster than the energy. The system has the vorticity flow.omega.

Parameters:

Name Type Description Default
shape Sequence[int]

The number of sites along both axes.

(64, 64)
nu float

The kinematic viscosity.

0.001
modes int

The largest wavenumber of the initial vorticity.

6
random_state int | Generator | None

The seed or generator of the initial vorticity.

0
label str

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

'system'
solver BaseSolver | str

The solver of the problem, or 'auto' for exponential steps of 0.05.

'auto'
backend BaseBackend | str

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

'auto'

Examples:

>>> from skcomplex.systems.physics.fluids import DecayingTurbulenceSystem
>>> DecayingTurbulenceSystem((16, 16)).prepare().system_.elements[0].space.prepare().size_
256
Source code in src/skcomplex/systems/physics/fluids/_flows.py
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
def __init__(
    self,
    shape: Sequence[int] = (64, 64),
    *,
    nu: float = 1e-3,
    modes: int = 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.nu = nu
    self.modes = modes
    self.random_state = random_state

DiscreteVelocityBoltzmannSystem(n=200, *, c=1.0, kappa=1.0, length=10.0, label='system', solver='auto', backend='auto')

Bases: BaseSystem

The Carleman discrete-velocity Boltzmann equation on a periodic line.

The gas starts from a pulse of right movers.

A pulse of right-moving particles on a uniform background splits into two moving pulses while collisions relax every site towards equal densities, and the total mass stays constant. The system has the densities gas.f_plus and gas.f_minus.

Parameters:

Name Type Description Default
n int

The number of cells.

200
c float

The particle speed.

1.0
kappa float

The collision rate.

1.0
length float

The length of the line.

10.0
label str

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

'system'
solver BaseSolver | str

The solver of the problem, or 'auto' for strong stability preserving Runge-Kutta steps.

'auto'
backend BaseBackend | str

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

'auto'

Examples:

>>> from skcomplex.systems.physics.fluids import DiscreteVelocityBoltzmannSystem
>>> DiscreteVelocityBoltzmannSystem(16).prepare().system_.elements[0].space.prepare().size_
16
Source code in src/skcomplex/systems/physics/fluids/_kinetics.py
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
def __init__(
    self,
    n: int = 200,
    *,
    c: float = 1.0,
    kappa: float = 1.0,
    length: float = 10.0,
    label: str = 'system',
    solver: BaseSolver | str = 'auto',
    backend: BaseBackend | str = 'auto',
) -> None:
    super().__init__(label, solver=solver, backend=backend)
    self.n = n
    self.c = c
    self.kappa = kappa
    self.length = length

EnskogSystem(positions=8, velocities=12, *, knudsen=1.0, diameter=0.2, half_width=6.0, label='system', solver='auto', backend='auto')

Bases: BaseSystem

The local Enskog equation.

It is the Boltzmann equation with the contact value of the pair correlation of disks.

The collision frequency is multiplied at every position by Henderson's contact value (1 - 7 c / 16) / (1 - c)^2 of the area fraction c = pi n d^2 / 4, with n the density moment and d the diameter of the disks. The collision partners sit at one position, so the shift of one diameter of the full Enskog collision is left out. The system has the density gas.x.

Parameters:

Name Type Description Default
positions int

The number of positions.

8
velocities int

The number of points of each velocity axis.

12
knudsen float

The Knudsen number, the inverse of the collision frequency of the dilute gas.

1.0
diameter float

The diameter of the disks.

0.2
half_width float

The half-width of each velocity axis.

6.0
label str

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

'system'
solver BaseSolver | str

The solver of the problem, or 'auto' for the steps the system chooses.

'auto'
backend BaseBackend | str

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

'auto'

Examples:

>>> from skcomplex.systems.physics.fluids import EnskogSystem
>>> EnskogSystem(4, 8).prepare().system_.elements[0].space.prepare().size_
256
Source code in src/skcomplex/systems/physics/fluids/_kinetic_equations.py
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
def __init__(
    self,
    positions: int = 8,
    velocities: int = 12,
    *,
    knudsen: float = 1.0,
    diameter: float = 0.2,
    half_width: float = 6.0,
    label: str = 'system',
    solver: BaseSolver | str = 'auto',
    backend: BaseBackend | str = 'auto',
) -> None:
    super().__init__(label, solver=solver, backend=backend)
    self.positions = positions
    self.velocities = velocities
    self.knudsen = knudsen
    self.diameter = diameter
    self.half_width = half_width

FHPLatticeGasSystem(shape=(64, 64), *, density=0.2, bump=0.6, radius=None, random_state=0, label='system', solver='auto', backend='auto')

Bases: BaseSystem

The FHP-I lattice gas on a periodic triangular lattice.

A dense disc spreads into the gas.

Every channel of every site is occupied at random with probability density, or bump inside a disc at the centre of the lattice, so the excess density spreads as a sound wave and then diffuses. The system has the channels gas.n0 to gas.n5 and the particle numbers gas.density.

Parameters:

Name Type Description Default
shape Sequence[int]

The number of rows and columns of the triangular lattice.

(64, 64)
density float

The occupation probability of a channel outside the disc.

0.2
bump float

The occupation probability of a channel inside the disc.

0.6
radius float | None

The radius of the disc in lattice spacings, or None for a sixth of the smaller side.

None
random_state int | Generator | None

The seed or generator of the initial occupations.

0
label str

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

'system'
solver BaseSolver | str

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

'auto'
backend BaseBackend | str

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

'auto'

Examples:

>>> from skcomplex.systems.physics.fluids import FHPLatticeGasSystem
>>> trajectory = FHPLatticeGasSystem((8, 8)).prepare().simulate(until=2, random_state=0)
>>> trajectory.get_values('gas.density').shape
(3, 64)
Source code in src/skcomplex/systems/physics/fluids/_lattice_gases.py
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
def __init__(
    self,
    shape: Sequence[int] = (64, 64),
    *,
    density: float = 0.2,
    bump: float = 0.6,
    radius: float | None = None,
    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.density = density
    self.bump = bump
    self.radius = radius
    self.random_state = random_state

FHPSiteElement(label, *, n0=0.0, n1=0.0, n2=0.0, n3=0.0, n4=0.0, n5=0.0, density=0.0, space=None)

Bases: Element

Sites of the FHP-I lattice gas.

Every site has one boolean channel per direction of the triangular lattice, and the number density of its particles.

Parameters:

Name Type Description Default
label str

The label of the site or the lattice of sites.

required
n0 object

The initial occupation of the channel at 0 degrees.

0.0
n1 object

The initial occupation of the channel at 60 degrees.

0.0
n2 object

The initial occupation of the channel at 120 degrees.

0.0
n3 object

The initial occupation of the channel at 180 degrees.

0.0
n4 object

The initial occupation of the channel at 240 degrees.

0.0
n5 object

The initial occupation of the channel at 300 degrees.

0.0
density object

The initial number of particles at the site.

0.0
space BaseSpace | None

The lattice of the sites, or None for one site.

None

Examples:

>>> from skcomplex.systems.physics.fluids import FHPSiteElement
>>> FHPSiteElement('site').n0
0.0
Source code in src/skcomplex/systems/physics/fluids/_lattice_gases.py
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
def __init__(
    self,
    label: str,
    *,
    n0: object = 0.0,
    n1: object = 0.0,
    n2: object = 0.0,
    n3: object = 0.0,
    n4: object = 0.0,
    n5: object = 0.0,
    density: object = 0.0,
    space: BaseSpace | None = None,
) -> None:
    super().__init__(label, space=space)
    self.n0 = n0
    self.n1 = n1
    self.n2 = n2
    self.n3 = n3
    self.n4 = n4
    self.n5 = n5
    self.density = density

HPPLatticeGasSystem(shape=(64, 64), *, density=0.2, bump=0.6, radius=None, full=False, random_state=0, label='system', solver='auto', backend='auto')

Bases: BaseSystem

The HPP lattice gas on a periodic square lattice.

Its particles move along four directions and collide.

Every site holds up to four particles, one per direction. Every step the particles first collide, where a site with exactly two particles of opposite directions turns them by a quarter turn and every other site keeps its particles, and then every particle moves one site along its direction. The rules are deterministic and reversible, and they conserve the number of particles and the momentum, and also the momentum along every row and every column, a spurious invariant that keeps the HPP gas from isotropic hydrodynamics. Every channel is occupied at random with probability density, or bump inside a disc at the centre. With full, as in Problem 4.3 of Lindgren, the particles start only in full cells, which hold all four directions, placed at random with probability density. The system has the channels gas.n0 to gas.n3 and the particle numbers gas.density.

Parameters:

Name Type Description Default
shape Sequence[int]

The number of rows and columns.

(64, 64)
density float

The occupation probability of a channel outside the disc, or of a full cell with full.

0.2
bump float

The occupation probability of a channel inside the disc, unused with full.

0.6
radius float | None

The radius of the disc in lattice spacings, or None for a sixth of the smaller side.

None
full bool

Whether the particles start in full cells only.

False
random_state int | Generator | None

The seed or generator of the initial occupations.

0
label str

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

'system'
solver BaseSolver | str

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

'auto'
backend BaseBackend | str

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

'auto'

Examples:

>>> from skcomplex.systems.physics.fluids import HPPLatticeGasSystem
>>> trajectory = HPPLatticeGasSystem((8, 8)).prepare().simulate(until=2)
>>> trajectory.get_values('gas.density').shape
(3, 64)
Source code in src/skcomplex/systems/physics/fluids/_lattice_gases.py
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
def __init__(
    self,
    shape: Sequence[int] = (64, 64),
    *,
    density: float = 0.2,
    bump: float = 0.6,
    radius: float | None = None,
    full: bool = False,
    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.density = density
    self.bump = bump
    self.radius = radius
    self.full = full
    self.random_state = random_state

HPPSiteElement(label, *, n0=0.0, n1=0.0, n2=0.0, n3=0.0, density=0.0, space=None)

Bases: Element

Sites of the HPP lattice gas.

Every site has one boolean channel per direction of the square lattice, and the number density of its particles.

Parameters:

Name Type Description Default
label str

The label of the site or the lattice of sites.

required
n0 object

The initial occupation of the channel along the columns, towards higher column indices.

0.0
n1 object

The initial occupation of the channel along the rows, towards higher row indices.

0.0
n2 object

The initial occupation of the channel along the columns, towards lower column indices.

0.0
n3 object

The initial occupation of the channel along the rows, towards lower row indices.

0.0
density object

The initial number of particles at the site.

0.0
space BaseSpace | None

The lattice of the sites, or None for one site.

None

Examples:

>>> from skcomplex.systems.physics.fluids import HPPSiteElement
>>> HPPSiteElement('site').n0
0.0
Source code in src/skcomplex/systems/physics/fluids/_lattice_gases.py
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
def __init__(
    self,
    label: str,
    *,
    n0: object = 0.0,
    n1: object = 0.0,
    n2: object = 0.0,
    n3: object = 0.0,
    density: object = 0.0,
    space: BaseSpace | None = None,
) -> None:
    super().__init__(label, space=space)
    self.n0 = n0
    self.n1 = n1
    self.n2 = n2
    self.n3 = n3
    self.density = density

KuramotoSivashinskyElement(label, *, u=0.0, space=None)

Bases: Element

Sites of a flame front or a thin film.

The field follows du/dt = -d(u^2 / 2)/dx - laplacian(u) - laplacian(laplacian(u)).

The conservation of the flux u^2 / 2 and the rate of the linear operator are interactions of the system.

Parameters:

Name Type Description Default
label str

The label of the front.

required
u object

The initial height of the front, one value per site or one for all.

0.0
space BaseSpace | None

The lattice of the sites, or None for one site.

None

Examples:

>>> from skcomplex.systems.physics.fluids import KuramotoSivashinskyElement
>>> KuramotoSivashinskyElement('site', u=0.5).u
0.5
Source code in src/skcomplex/systems/physics/fluids/_flows.py
133
134
135
def __init__(self, label: str, *, u: object = 0.0, space: BaseSpace | None = None) -> None:
    super().__init__(label, space=space)
    self.u = u

KuramotoSivashinskySystem(modes=128, *, length=32 * math.pi, label='system', solver='auto', backend='auto')

Bases: BaseSystem

The Kuramoto-Sivashinsky equation u_t = -u u_x - u_xx - u_xxxx.

The equation is spatiotemporally chaotic.

The field is spectral on a periodic line, started from cos(x / 16) (1 + sin(x / 16)) as in Kassam and Trefethen, and the stiff fourth derivative suits exponential time differencing.

The derivative of the nonlinear term u²/2 is dealiased by the two-thirds rule: it keeps only the wavenumbers below a third of 2 π modes / length, 2.67 for the defaults, so the spectrum drops to round-off from q = 2.69 on. The cut costs little, since the modes there decay at the rate q⁴ - q² above 45, and with the defaults the power at the last kept mode is five decades below the peak near q = 0.6. More modes on the same length move the cut up in proportion. The system has the field line.u.

Parameters:

Name Type Description Default
modes int

The number of sites, and of Fourier modes.

128
length float

The length of the line.

32 * pi
label str

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

'system'
solver BaseSolver | str

The solver of the problem, or 'auto' for exponential steps of 0.25.

'auto'
backend BaseBackend | str

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

'auto'

Examples:

>>> from skcomplex.systems.physics.fluids import KuramotoSivashinskySystem
>>> KuramotoSivashinskySystem(32).prepare().system_.elements[0].space.discretization
'spectral'
Source code in src/skcomplex/systems/physics/fluids/_flows.py
271
272
273
274
275
276
277
278
279
280
281
282
def __init__(
    self,
    modes: int = 128,
    *,
    length: float = 32 * math.pi,
    label: str = 'system',
    solver: BaseSolver | str = 'auto',
    backend: BaseBackend | str = 'auto',
) -> None:
    super().__init__(label, solver=solver, backend=backend)
    self.modes = modes
    self.length = length

LatticeGasCollisionInteraction(label, *, target, geometry='square')

Bases: Interaction

Collisions of the particles at every site of a lattice gas.

On the square lattice of the HPP gas, a site with exactly two particles of opposite directions turns them by a quarter turn. On the triangular lattice of the FHP-I gas, head-on pairs turn by a sixth of a turn to either side with equal probability, and symmetric triples turn by a sixth of a turn. Every other site keeps its particles, so collisions conserve the number of particles and their momentum at every site.

Parameters:

Name Type Description Default
label str

The label of the interaction.

required
target Role

The path of the sites, whose channels are n0, n1, and so on.

required
geometry str

The lattice of the gas, 'square' for HPP or 'triangular' for FHP-I.

'square'

Raises:

Type Description
ValidationError

The geometry is not 'square' or 'triangular'.

Examples:

>>> from skcomplex.systems.physics.fluids import LatticeGasCollisionInteraction
>>> LatticeGasCollisionInteraction('collision', target='gas', geometry='triangular').geometry
'triangular'
Source code in src/skcomplex/systems/physics/fluids/_lattice_gases.py
215
216
217
218
def __init__(self, label: str, *, target: Role, geometry: str = 'square') -> None:
    super().__init__(label)
    self.target = target
    self.geometry = geometry

LatticeGasPropagationInteraction(label, *, target, geometry='square')

Bases: Interaction

Propagation of every particle of a lattice gas to the neighbouring site along its direction.

Parameters:

Name Type Description Default
label str

The label of the interaction.

required
target Role

The path of the sites, whose channels are n0, n1, and so on.

required
geometry str

The lattice of the gas, 'square' for HPP or 'triangular' for FHP-I.

'square'

Raises:

Type Description
ValidationError

The geometry is not 'square' or 'triangular'.

Examples:

>>> from skcomplex.systems.physics.fluids import LatticeGasPropagationInteraction
>>> LatticeGasPropagationInteraction('propagation', target='gas').geometry
'square'
Source code in src/skcomplex/systems/physics/fluids/_lattice_gases.py
299
300
301
302
def __init__(self, label: str, *, target: Role, geometry: str = 'square') -> None:
    super().__init__(label)
    self.target = target
    self.geometry = geometry

MarangoniLayerElement(label, *, u=0.0, space=None)

Bases: Element

Sites of a convecting layer with a free surface, with the order parameter u.

Parameters:

Name Type Description Default
label str

The label of the layer.

required
u object

The initial order parameter, one value per site or one for all.

0.0
space BaseSpace | None

The lattice of the sites, or None for one site.

None

Examples:

>>> from skcomplex.systems.physics.fluids import MarangoniLayerElement
>>> MarangoniLayerElement('site', u=0.5).u
0.5
Source code in src/skcomplex/systems/physics/fluids/_marangoni.py
46
47
48
def __init__(self, label: str, *, u: object = 0.0, space: BaseSpace | None = None) -> None:
    super().__init__(label, space=space)
    self.u = u

ParticleCountInteraction(label, *, target, channels=SQUARE_CHANNELS)

Bases: Interaction

Count of the particles at every site, the sum of its channels.

Parameters:

Name Type Description Default
label str

The label of the interaction.

required
target Role

The path of the sites, whose value density holds the count.

required
channels Sequence[str]

The names of the channels of a site.

SQUARE_CHANNELS

Examples:

>>> from skcomplex.systems.physics.fluids import ParticleCountInteraction
>>> ParticleCountInteraction('count', target='gas', channels=('n0', 'n1')).channels
('n0', 'n1')
Source code in src/skcomplex/systems/physics/fluids/_lattice_gases.py
368
369
370
371
def __init__(self, label: str, *, target: Role, channels: Sequence[str] = SQUARE_CHANNELS) -> None:
    super().__init__(label)
    self.target = target
    self.channels = channels

RayleighBenardSystem(Ra=1000.0, *, Pr=1.0, shape=(32, 32), amplitude=0.001, label='system', solver='auto', backend='auto')

Bases: BaseSystem

Rayleigh-Bénard convection between free-slip walls.

The convection starts from a small perturbation of the critical mode.

The layer has height 1 and width 2 sqrt(2), the wavelength of the critical mode, and convection sets in above Ra = 27 pi^4 / 4, about 657.5. The lattice holds twice the layer's height with odd states, which gives the free-slip walls. The default step ETDRK4Solver(dt=0.005) is stable up to about Ra = 4000, and faster convection needs a smaller step, such as ETDRK4Solver(dt=0.0025) at Ra = 5000. The system has the vorticity flow.omega and the temperature departure flow.theta.

Parameters:

Name Type Description Default
Ra float

The Rayleigh number.

1000.0
Pr float

The Prandtl number.

1.0
shape Sequence[int]

The number of sites along the width and twice the height.

(32, 32)
amplitude float

The amplitude of the initial temperature perturbation.

0.001
label str

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

'system'
solver BaseSolver | str

The solver of the problem, or 'auto' for exponential steps of 0.005.

'auto'
backend BaseBackend | str

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

'auto'

Examples:

>>> from skcomplex.systems.physics.fluids import RayleighBenardSystem
>>> RayleighBenardSystem(500.0).prepare().system_.elements[0].Ra
500.0
Source code in src/skcomplex/systems/physics/fluids/_flows.py
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
def __init__(
    self,
    Ra: float = 1000.0,
    *,
    Pr: float = 1.0,
    shape: Sequence[int] = (32, 32),
    amplitude: float = 1e-3,
    label: str = 'system',
    solver: BaseSolver | str = 'auto',
    backend: BaseBackend | str = 'auto',
) -> None:
    super().__init__(label, solver=solver, backend=backend)
    self.Ra = Ra
    self.Pr = Pr
    self.shape = shape
    self.amplitude = amplitude

RelaxationTimeInteraction(label, *, target, state='x', goal=0.0, time=1.0, noise=None)

Bases: Interaction

Relaxation of a state towards a goal over a relaxation time.

The state follows x' = (goal - x) / time, with the noise noise dW when one is given. With a constant goal and time this is the Ornstein-Uhlenbeck process, whose stationary variance is noise**2 time / 2. It is Newton cooling, a belief adapting to news, or the BGK collision term of a gas. The goal, the time, and the noise are numbers or functions of the namespace of the interaction, and a goal that is a number applies to every component of a vector state.

Parameters:

Name Type Description Default
label str

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

required
target Role

The path of the element or group whose state relaxes.

required
state str

The name of the state of the target that relaxes.

'x'
goal Callable[[SimpleNamespace], object] | float

A function of the namespace that returns the goal, or a number.

0.0
time Callable[[SimpleNamespace], object] | float

A function of the namespace that returns the relaxation time, or a positive number.

1.0
noise Callable[[SimpleNamespace], object] | float | None

A function of the namespace that returns the amplitude of the noise, a number, or None for no noise.

None

Raises:

Type Description
ValidationError

A goal, a time, or a noise is neither callable nor a number.

Examples:

>>> from skcomplex.core.components.elements import Element
>>> from skcomplex.core.systems import System
>>> from skcomplex.systems.physics.fluids import RelaxationTimeInteraction
>>> relaxation = RelaxationTimeInteraction('relaxation', target='stock', goal=10.0, time=0.5)
>>> system = System(elements=[Element('stock', values={'x': 0.0})], interactions=[relaxation]).prepare()
>>> round(float(system.simulate(until=5.0, dt=0.01).get_values('stock.x')[-1]), 3)
10.0
Source code in src/skcomplex/systems/physics/fluids/_kinetic_equations.py
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
def __init__(
    self,
    label: str,
    *,
    target: Role,
    state: str = 'x',
    goal: Callable[[SimpleNamespace], object] | float = 0.0,
    time: Callable[[SimpleNamespace], object] | float = 1.0,
    noise: Callable[[SimpleNamespace], object] | float | None = None,
) -> None:
    super().__init__(label)
    self.target = target
    self.state = state
    self.goal = goal
    self.time = time
    self.noise = noise

ShallowWaterElement(label, *, h=1.0, q=0.0, g=9.81, space=None)

Bases: Element

Cells of a channel of shallow water.

Every cell has the depth h and the discharge q per unit width.

The mass h and the momentum q are conserved by two conservation laws, with the fluxes q and q^2 / h + g h^2 / 2, which form one hyperbolic system.

Parameters:

Name Type Description Default
label str

The label of the channel.

required
h object

The initial depth, one value per cell or one for all.

1.0
q object

The initial discharge, one value per cell or one for all.

0.0
g float

The gravitational acceleration.

9.81
space BaseSpace | None

The lattice of the cells, or None for one cell.

None

Examples:

>>> from skcomplex.systems.physics.fluids import ShallowWaterElement
>>> ShallowWaterElement('site', h=2.0).h
2.0
Source code in src/skcomplex/systems/physics/fluids/_flows.py
168
169
170
171
172
173
174
175
176
177
178
179
180
def __init__(
    self,
    label: str,
    *,
    h: object = 1.0,
    q: object = 0.0,
    g: float = 9.81,
    space: BaseSpace | None = None,
) -> None:
    super().__init__(label, space=space)
    self.h = h
    self.q = q
    self.g = g

ShallowWaterSystem(n=400, *, length=10.0, upstream=2.0, downstream=1.0, g=9.81, label='system', solver='auto', backend='auto')

Bases: BaseSystem

The shallow-water dam break.

Still water at two depths was separated at the middle by a removed dam.

A shock runs downstream and a rarefaction upstream, with the depth and the discharge conserved by finite volumes and open edges. The system has the depth channel.h and the discharge channel.q.

Parameters:

Name Type Description Default
n int

The number of cells.

400
length float

The length of the channel.

10.0
upstream float

The depth upstream of the dam.

2.0
downstream float

The depth downstream of the dam.

1.0
g float

The gravitational acceleration.

9.81
label str

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

'system'
solver BaseSolver | str

The solver of the problem, or 'auto' for strong stability preserving Runge-Kutta steps.

'auto'
backend BaseBackend | str

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

'auto'

Examples:

>>> from skcomplex.systems.physics.fluids import ShallowWaterSystem
>>> float(ShallowWaterSystem(10).prepare().system_.elements[0].h[0])
2.0
Source code in src/skcomplex/systems/physics/fluids/_flows.py
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
def __init__(
    self,
    n: int = 400,
    *,
    length: float = 10.0,
    upstream: float = 2.0,
    downstream: float = 1.0,
    g: float = 9.81,
    label: str = 'system',
    solver: BaseSolver | str = 'auto',
    backend: BaseBackend | str = 'auto',
) -> None:
    super().__init__(label, solver=solver, backend=backend)
    self.n = n
    self.length = length
    self.upstream = upstream
    self.downstream = downstream
    self.g = g

ThermocapillaryInteraction(label, *, target, r=0.1, g=1.0)

Bases: GradientInteraction

Relaxation of the order parameter of a convecting layer whose free surface breaks the up-down symmetry.

The order parameter u of the target follows u_t = r u - (1 + laplacian)^2 u + g u^2 - u^3, the gradient flow of the density -(r - 1) u^2 / 2 - g u^3 / 3 + u^4 / 4 + u laplacian(u) + laplacian(u)^2 / 2.

Parameters:

Name Type Description Default
label str

The label of the interaction.

required
target Role

The path of the layer.

required
r float

The distance from the onset of convection.

0.1
g float

The strength of the quadratic term that the free surface adds.

1.0

Examples:

>>> from skcomplex.systems.physics.fluids import ThermocapillaryInteraction
>>> ThermocapillaryInteraction('relaxation', target='layer', g=0.5).g
0.5
Source code in src/skcomplex/systems/physics/fluids/_marangoni.py
76
77
78
79
80
81
82
83
84
85
86
def __init__(
    self,
    label: str,
    *,
    target: Role,
    r: float = 0.1,
    g: float = 1.0,
) -> None:
    super().__init__(label, target=target, states='u', variational=True)
    self.r = r
    self.g = g

VlasovEquationSystem(positions=32, velocities=64, *, setup='landau', amplitude=0.01, half_width=6.0, label='system', solver='auto', backend='auto')

Bases: BaseSystem

The Vlasov-Poisson equation of electrons over a neutralizing background.

The position axis is periodic.

The electric field is solved from the density moment at every step. The set-up 'landau' starts from a Maxwellian with a density wave of wave number 0.5, whose electric energy decays at twice the Landau damping rate 0.1533. The set-up 'two-stream' starts from two beams of temperature 0.25 at the velocities -1.5 and 1.5, which are unstable at the wave number 0.5. The system has the density gas.x.

Parameters:

Name Type Description Default
positions int

The number of positions.

32
velocities int

The number of points of the velocity axis.

64
setup str

'landau' or 'two-stream'.

'landau'
amplitude float

The relative amplitude of the initial density wave.

0.01
half_width float

The half-width of the velocity axis.

6.0
label str

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

'system'
solver BaseSolver | str

The solver of the problem, or 'auto' for semi-Lagrangian steps of 0.25.

'auto'
backend BaseBackend | str

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

'auto'

Raises:

Type Description
ValidationError

The set-up is unknown.

Examples:

>>> from skcomplex.systems.physics.fluids import VlasovEquationSystem
>>> VlasovEquationSystem(8, 16).prepare().system_.elements[0].space.prepare().size_
128
Source code in src/skcomplex/systems/physics/fluids/_kinetic_equations.py
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
def __init__(
    self,
    positions: int = 32,
    velocities: int = 64,
    *,
    setup: str = 'landau',
    amplitude: float = 0.01,
    half_width: float = 6.0,
    label: str = 'system',
    solver: BaseSolver | str = 'auto',
    backend: BaseBackend | str = 'auto',
) -> None:
    super().__init__(label, solver=solver, backend=backend)
    self.positions = positions
    self.velocities = velocities
    self.setup = setup
    self.amplitude = amplitude
    self.half_width = half_width

VorticityElement(label, *, omega=0.0, nu=0.001, f=0.0, space=None)

Bases: Element

Sites of the vorticity of an incompressible two-dimensional flow.

The vorticity follows domega/dt + u . grad(omega) = nu laplacian(omega) + f.

The velocity comes from the streamfunction, the solution of a Poisson equation, so the flow is divergence free, and the advection is written in conservative form so that dealiasing applies to it. The advection, the viscosity, and the forcing are interactions of the system, which read the viscosity nu and the forcing f of the flow.

Parameters:

Name Type Description Default
label str

The label of the flow.

required
omega object

The initial vorticity, one value per site or one for all.

0.0
nu Annotated[float, closed_open(0, oo)]

The kinematic viscosity.

0.001
f object

The forcing of the vorticity, one value per site or one for all.

0.0
space BaseSpace | None

The lattice of the sites, or None for one site.

None

Examples:

>>> from skcomplex.systems.physics.fluids import VorticityElement
>>> VorticityElement('site').nu
0.001
Source code in src/skcomplex/systems/physics/fluids/_flows.py
214
215
216
217
218
219
220
221
222
223
224
225
226
def __init__(
    self,
    label: str,
    *,
    omega: object = 0.0,
    nu: Annotated[float, RealSet.closed_open(0, oo)] = 0.001,
    f: object = 0.0,
    space: BaseSpace | None = None,
) -> None:
    super().__init__(label, space=space)
    self.omega = omega
    self.nu = nu
    self.f = f

WaveBreakingSystem(n=200, *, k0=1.0, amplitude=0.5, g=1.0, label='system', solver='auto', backend='auto')

Bases: BaseSystem

The kinematic wave equation of deep-water wave trains.

The interval is periodic of length 2 pi.

The wave number starts as k0 (1 + amplitude sin x) and steepens into a jump, a break of the wavelength, at the time 1 / max(-C'(k0(x)) k0'(x)) of the first crossing of characteristics. Finite volumes conserve the total number of waves. The system has the wave number train.k.

Parameters:

Name Type Description Default
n int

The number of cells.

200
k0 float

The mean initial wave number.

1.0
amplitude float

The relative amplitude of the initial modulation, below 1.

0.5
g float

The gravitational acceleration.

1.0
label str

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

'system'
solver BaseSolver | str

The solver of the problem, or 'auto' for strong stability preserving Runge-Kutta steps.

'auto'
backend BaseBackend | str

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

'auto'

Examples:

>>> from skcomplex.systems.physics.fluids import WaveBreakingSystem
>>> WaveBreakingSystem(16).prepare().system_.elements[0].space.prepare().size_
16
Source code in src/skcomplex/systems/physics/fluids/_kinetics.py
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
def __init__(
    self,
    n: int = 200,
    *,
    k0: float = 1.0,
    amplitude: float = 0.5,
    g: float = 1.0,
    label: str = 'system',
    solver: BaseSolver | str = 'auto',
    backend: BaseBackend | str = 'auto',
) -> None:
    super().__init__(label, solver=solver, backend=backend)
    self.n = n
    self.k0 = k0
    self.amplitude = amplitude
    self.g = g

WaveNumberElement(label, *, k=1.0, g=1.0, space=None)

Bases: Element

Cells of the local wave number of deep-water waves.

The wave number is conserved as dk/dt + d omega(k)/dx = 0 with omega = sqrt(g k).

The wave number travels at the group speed C(k) = sqrt(g / k) / 2, which falls as the waves shorten, so long waves catch up with short ones and the wave number steepens until it breaks.

Parameters:

Name Type Description Default
label str

The label of the wave train.

required
k Annotated[object, open(0, oo)]

The initial wave number, one value per cell or one for all.

1.0
g Annotated[float, open(0, oo)]

The gravitational acceleration.

1.0
space BaseSpace | None

The lattice of the cells, or None for one cell.

None

Examples:

>>> from skcomplex.systems.physics.fluids import WaveNumberElement
>>> WaveNumberElement('site').g
1.0
Source code in src/skcomplex/systems/physics/fluids/_kinetics.py
107
108
109
110
111
112
113
114
115
116
117
def __init__(
    self,
    label: str,
    *,
    k: Annotated[object, RealSet.open(0, oo)] = 1.0,
    g: Annotated[float, RealSet.open(0, oo)] = 1.0,
    space: BaseSpace | None = None,
) -> None:
    super().__init__(label, space=space)
    self.k = k
    self.g = g

incompressible_flow(shape=(64, 64), size=(2 * math.pi, 2 * math.pi), *, nu=0.001, forcing=None, buoyancy=None, walls=False, vorticity=None, temperature=None, solver='auto', label='system')

Return incompressible two-dimensional flow in vorticity-streamfunction form.

The flow is on a periodic spectral lattice.

Parameters:

Name Type Description Default
shape Sequence[int]

The number of sites along both axes.

(64, 64)
size Sequence[float]

The lengths of the domain along both axes.

(2 * pi, 2 * pi)
nu float

The kinematic viscosity, unused with buoyancy, whose viscosity is the Prandtl number.

0.001
forcing ArrayLike | None

The forcing of the vorticity at every site, or None.

None
buoyancy Mapping[str, float] | None

The Rayleigh number Ra and the Prandtl number Pr of Boussinesq convection with a temperature field, or None for a flow without temperature.

None
walls bool

Whether the second axis is twice the height of a layer between free-slip walls in its middle and at its ends, the vorticity and temperature being odd about them.

False
vorticity ArrayLike | None

The initial vorticity, or None for rest.

None
temperature ArrayLike | None

The initial temperature departure of convection, or None for zero.

None
solver BaseSolver | str

The solver of the flow, or 'auto' for the one the system chooses.

'auto'
label str

The label of the system.

'system'

Returns:

Name Type Description
system System

The flow, with the vorticity flow.omega and, with buoyancy, the temperature flow.theta.

Examples:

>>> from skcomplex.systems.physics.fluids import incompressible_flow
>>> type(incompressible_flow((16, 16), buoyancy={'Ra': 800.0, 'Pr': 1.0}).elements[0]).__name__
'BoussinesqElement'
Source code in src/skcomplex/systems/physics/fluids/_flows.py
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
def incompressible_flow(
    shape: Sequence[int] = (64, 64),
    size: Sequence[float] = (2 * math.pi, 2 * math.pi),
    *,
    nu: float = 1e-3,
    forcing: npt.ArrayLike | None = None,
    buoyancy: Mapping[str, float] | None = None,
    walls: bool = False,
    vorticity: npt.ArrayLike | None = None,
    temperature: npt.ArrayLike | None = None,
    solver: BaseSolver | str = 'auto',
    label: str = 'system',
) -> System:
    """Return incompressible two-dimensional flow in vorticity-streamfunction form.

    The flow is on a periodic spectral lattice.

    Args:
        shape:
            The number of sites along both axes.

        size:
            The lengths of the domain along both axes.

        nu:
            The kinematic viscosity, unused with buoyancy, whose viscosity is the Prandtl number.

        forcing:
            The forcing of the vorticity at every site, or `None`.

        buoyancy:
            The Rayleigh number `Ra` and the Prandtl number `Pr` of Boussinesq convection with a temperature field,
            or `None` for a flow without temperature.

        walls:
            Whether the second axis is twice the height of a layer between free-slip walls in its middle and at its
            ends, the vorticity and temperature being odd about them.

        vorticity:
            The initial vorticity, or `None` for rest.

        temperature:
            The initial temperature departure of convection, or `None` for zero.

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

        label:
            The label of the system.

    Returns:
        system:
            The flow, with the vorticity `flow.omega` and, with buoyancy, the temperature `flow.theta`.

    Examples:
        >>> from skcomplex.systems.physics.fluids import incompressible_flow
        >>> type(incompressible_flow((16, 16), buoyancy={'Ra': 800.0, 'Pr': 1.0}).elements[0]).__name__
        'BoussinesqElement'
    """
    shape = tuple(int(item) for item in shape)
    states = ['omega'] if buoyancy is None else ['omega', 'theta']
    space = LatticeSpace(
        shape,
        spacing=tuple(length / count for length, count in zip(size, shape, strict=True)),
        discretization='spectral',
        symmetry=dict.fromkeys(states, (None, 'odd')) if walls else None,
    )
    omega = 0.0 if vorticity is None else np.asarray(vorticity, dtype=float).ravel()
    flow: Element
    if buoyancy is None:
        f = 0.0 if forcing is None else np.asarray(forcing, dtype=float).ravel()
        flow = VorticityElement('flow', omega=omega, nu=nu, f=f, space=space)
    else:
        theta = 0.0 if temperature is None else np.asarray(temperature, dtype=float).ravel()
        Ra, Pr = (float(buoyancy[name]) for name in ('Ra', 'Pr'))
        flow = BoussinesqElement('flow', omega=omega, theta=theta, Ra=Ra, Pr=Pr, space=space)
    interactions = _get_flow_interactions(buoyancy is not None)
    return System(label, elements=[flow], interactions=interactions, solver=solver)