Vlasov
The Vlasov-Poisson equation of electrons over a neutralizing background.
- Class:
VlasovEquationSystem - Import:
from skcomplex.systems.physics.fluids import VlasovEquationSystem - Field:
physics/fluids - Topics:
field,kinetic,phase space,plasma,pde - References:
- Bellomo et al. 2017
- Cheng and Knorr 1976
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.fluids import VlasovEquationSystem
trajectory = VlasovEquationSystem().prepare().simulate()
Parameters
The model parameters take these defaults, and set_params changes them.
| Parameter | Default |
|---|---|
positions |
32 |
velocities |
64 |
setup |
'landau' |
amplitude |
0.01 |
half_width |
6.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 | phase space |
| Laws | rate |
| Randomness | unknown |
| Domains | real |
| Structure | fixed |
Class
The source of the class shows how it builds its components from its model parameters.
class VlasovEquationSystem(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`.
Args:
positions:
The number of positions.
velocities:
The number of points of the velocity axis.
setup:
`'landau'` or `'two-stream'`.
amplitude:
The relative amplitude of the initial density wave.
half_width:
The half-width of the velocity axis.
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 semi-Lagrangian steps of 0.25.
backend:
The backend that evaluates the compiled functions, or `'auto'` for the one the system chooses.
Raises:
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
"""
field = 'physics/fluids'
topics = ('field', 'kinetic', 'phase space', 'plasma', 'pde')
references = ('Bellomo et al. 2017', 'Cheng and Knorr 1976')
until = 30.0
dt = 0.25
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
@staticmethod
def _get_poisson_drift(s: SimpleNamespace) -> list[Expression]:
"""Return the velocity along position and the potential force along velocity.
The potential is that of the density.
"""
density = moment(s.target.x, 0, axes=('v',))
return [coordinate('v'), -gradient(inverse_helmholtz(1 - density), 1)[0]]
def _prepare(self, context: Sequence[Observable] | None = None) -> None:
"""Set the system of electrons over a neutralizing background from the set-up.
Args:
context:
The observables to compile with the problem, or `None` for none.
Raises:
ValidationError:
The set-up is unknown.
"""
super()._prepare(context)
if self.setup not in SETUPS:
error_msg = f'Unknown set-up {self.setup!r} of the Vlasov equation. Use one of {", ".join(SETUPS)}.'
raise ValidationError(error_msg)
length = 4 * math.pi
space = PhaseSpace(
LatticeSpace((self.positions,), spacing=length / self.positions, discretization='finite-volume'),
[AxisSpec('v', self.velocities, -self.half_width, self.half_width)],
)
space.prepare()
x = np.arange(self.positions) * length / self.positions
v = space.coordinates_['v']
profile = np.exp(-(v**2) / 2) / np.sqrt(2 * np.pi)
if self.setup == 'two-stream':
profile = (np.exp(-2 * (v - 1.5) ** 2) + np.exp(-2 * (v + 1.5) ** 2)) * np.sqrt(2 / np.pi) / 2
gas = GasDensityElement('gas', x=np.outer(1.0 + self.amplitude * np.cos(0.5 * x), profile).ravel(), space=space)
self.system_ = System(
self.label,
elements=[gas],
interactions=[AdvectionInteraction('vlasov', target='gas', state='x', drift=self._get_poisson_drift)],
solver=SemiLagrangianSolver(0.25),
)
Components
The system uses these element and interaction classes, each with its nearest class of the core.
Elements:
GasDensityElement, fromElement
Interactions:
AdvectionInteraction, fromInteraction
class GasDensityElement(PhaseSpaceDensityElement):
"""Phase space density of a gas, drawn as its density along position.
Args:
label:
The label of the gas.
x:
The initial density, one nonnegative value per point or one for all.
space:
The phase space of the points, or `None` for one point.
Examples:
>>> from skcomplex.systems.physics.fluids._kinetic_equations import GasDensityElement
>>> GasDensityElement('gas', x=0.5).x
0.5
"""
visual = VisualSpec('image', {'moments': (0,)})
class AdvectionInteraction(Interaction):
"""Advection `du/dt + divergence(a u) = source(ns)` of a state `u` of a field by a drift.
Physics names it advection, the transport of a state by a flow or by the streaming of a phase-space density.
The drift field is `a(ns)`. The flux of the conservation law is the drift times the state, written in conservative
form, so the total of the state on a periodic field stays constant and, on a spectral field, the dealiasing of
products applies to it. The drift is one expression for a field of one dimension, or one per dimension, of the
states and parameters of the field, and may read other states than the one it carries, such as the flow of a fluid
derived from a streamfunction, or the drift of a probability density in a Fokker-Planck equation.
Args:
label:
The label of the interaction, unique among the components of its system.
target:
The path of the field whose state is carried.
state:
The name of the carried state of the field.
drift:
A function of the namespace that returns the drift, or one drift per dimension.
source:
A function of the namespace that returns the source, or `None` for none.
Raises:
ValidationError:
The state is not a name, or a function is not callable.
Examples:
>>> import numpy as np
>>> from skcomplex.core.components.elements import Element
>>> from skcomplex.core.components.spaces import LatticeSpace
>>> from skcomplex.core.systems import System
>>> from skcomplex.systems.physics.common.fields import AdvectionInteraction
>>> space = LatticeSpace((50,), spacing=0.1, boundary='periodic', discretization='finite-volume')
>>> values = {'u': np.exp(-((np.arange(50) - 25) / 5.0) ** 2)}
>>> tracer = Element('tracer', values=values, space=space)
>>> drift = AdvectionInteraction('drift', target='tracer', state='u', drift=lambda s: 1.0)
>>> trajectory = System(elements=[tracer], interactions=[drift]).prepare().simulate(until=1.0, dt=0.01)
>>> total = trajectory.get_values('tracer.u')[-1].sum()
>>> round(float(total), 6) == round(float(values['u'].sum()), 6)
True
"""
def __init__(
self,
label: str,
*,
target: Role,
state: str = 'u',
drift: Callable[[SimpleNamespace], object] | None = None,
source: Callable[[SimpleNamespace], object] | None = None,
) -> None:
super().__init__(label)
self.target = target
self.state = state
self.drift = drift
self.source = source
def _check_arguments(self) -> None:
"""Raise an error for an argument the interaction cannot take.
Raises:
ValidationError:
The state is not a name, the drift is not callable, or the source is neither callable nor `None`.
"""
super()._check_arguments()
if not isinstance(self.state, str) or not self.state.isidentifier():
error_msg = f'{type(self).__name__} {self.label!r} carries the state {self.state!r}, which is no name.'
raise ValidationError(error_msg)
if not callable(self.drift):
error_msg = f'The drift of {self.label!r} is {self.drift!r}. Give a function of the namespace.'
raise ValidationError(error_msg)
if self.source is not None and not callable(self.source):
error_msg = f'The source of {self.label!r} is {self.source!r}. Give a function of the namespace.'
raise ValidationError(error_msg)
def _prepare(self, context: SimpleNamespace) -> None:
"""Set the rate of the divergence of the flux `a u` and the rate of the source.
Args:
context:
The namespace of the field, the time `t`, and the parameters.
"""
super()._prepare(context)
u = getattr(context.target, self.state)
drift = cast('Callable[[SimpleNamespace], object]', self.drift)(context)
components = drift if isinstance(drift, FreeModuleElement | list | tuple) else [drift]
self.laws_ = [RateLaw(u, -divergence([SR(component) * u for component in components]))]
if self.source is not None:
self.laws_.append(RateLaw(u, self.source(context)))