Skip to content

Fields

Field realizations shared by the physics packages.

The package holds advection by a drift, diffusion by a diffusivity, the one-particle density of kinetic theory, and the Monte Carlo sampling of lattice gauge fields.

AdvectionInteraction(label, *, target, state='u', drift=None, source=None)

Bases: 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.

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 whose state is carried.

required
state str

The name of the carried state of the field.

'u'
drift Callable[[SimpleNamespace], object] | None

A function of the namespace that returns the drift, or one drift per dimension.

None
source Callable[[SimpleNamespace], object] | None

A function of the namespace that returns the source, or None for none.

None

Raises:

Type Description
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
Source code in src/skcomplex/systems/physics/common/fields/_advection.py
69
70
71
72
73
74
75
76
77
78
79
80
81
82
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

DiffusivityInteraction(label, *, target, state='u', coefficient=1.0)

Bases: Interaction

Diffusion du/dt = D laplacian(u) of a state u of a field by a diffusivity D.

Physics names the coefficient a diffusivity, as the thermal diffusivity of heat conduction or the kinematic viscosity of the vorticity of a fluid. The diffusivity is uniform in space, a number or a function of the namespace that returns an expression of parameters and time. The rate is the Laplacian of the field, which its discretization evaluates, so the total of the state on a periodic field stays constant and a point mass spreads as the heat kernel.

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 whose state diffuses.

required
state str

The name of the state of the field that diffuses.

'u'
coefficient Callable[[SimpleNamespace], object] | float

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

1.0

Raises:

Type Description
ValidationError

The state is not a name, or the coefficient is neither callable nor a number.

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 DiffusivityInteraction
>>> space = LatticeSpace((40,), spacing=0.1, boundary='periodic')
>>> rod = Element('rod', values={'u': np.eye(40)[20]}, space=space)
>>> heat = DiffusivityInteraction('heat', target='rod', state='u', coefficient=0.1)
>>> trajectory = System(elements=[rod], interactions=[heat]).prepare().simulate(until=1.0, dt=0.01)
>>> round(float(trajectory.get_values('rod.u')[-1].sum()), 6)
1.0
Source code in src/skcomplex/systems/physics/common/fields/_diffusivity.py
58
59
60
61
62
63
64
65
66
67
68
69
def __init__(
    self,
    label: str,
    *,
    target: Role,
    state: str = 'u',
    coefficient: Callable[[SimpleNamespace], object] | float = 1.0,
) -> None:
    super().__init__(label)
    self.target = target
    self.state = state
    self.coefficient = coefficient

HolonomyScoreSpec(function, group, hits=1) dataclass

Bases: BaseSpec

Spec of an objective of a matrix group state on the edges of a cell complex.

The objective is a sum over the holonomies of faces. The objective is the sum over the faces of a class function of the holonomy of every face, the path-ordered product of the matrices of the edges around it. A class function, such as the real part of the trace, has the same value on every cyclic order of the product, so the local objective of an edge sums it over the holonomies of the faces around the edge that start at the edge.

Parameters:

Name Type Description Default
function Callable[..., object]

The function function(holonomies, **parameters) of an array of holonomies, matrices on the last two axes, and the parameters of the system that it names, which returns one number per holonomy.

required
group MatrixGroupSpec

The matrix group of the state.

required
hits int

The number of moves proposed per edge and sweep.

1

Raises:

Type Description
ValidationError

The function is not callable, the group is invalid, or the number of hits is not positive.

Examples:

>>> import numpy as np
>>> from skcomplex.core.components import MatrixGroupSpec
>>> from skcomplex.systems.physics.common.fields import HolonomyScoreSpec
>>> trace = lambda holonomies: -np.trace(holonomies, axis1=-2, axis2=-1).real
>>> HolonomyScoreSpec(trace, MatrixGroupSpec('SU', 2), hits=4).hits
4

PhaseSpaceDensityElement(label, *, x=0.0, space=None)

Bases: Element

Value x of the one-particle density of kinetic theory at every point of a phase space.

A gas is one member per position and velocity of a PhaseSpace, and streaming, collisions, and relaxation change it. The density is nonnegative.

Parameters:

Name Type Description Default
label str

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

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

The initial density, one nonnegative value per point or one for all.

0.0
space BaseSpace | None

The phase space of the points, or None for one point.

None

Examples:

>>> from skcomplex.core.components.spaces import AxisSpec, LatticeSpace, PhaseSpace
>>> from skcomplex.systems.physics.common.fields import PhaseSpaceDensityElement
>>> space = PhaseSpace(LatticeSpace(4), [AxisSpec('v', 8, -3.0, 3.0)])
>>> PhaseSpaceDensityElement('gas', x=0.2, space=space).space.prepare().size_
32
Source code in src/skcomplex/systems/physics/common/fields/_phase_space_density.py
39
40
41
42
43
44
45
46
47
def __init__(
    self,
    label: str,
    *,
    x: Annotated[object, RealSet.closed_open(0, oo)] = 0.0,
    space: BaseSpace | None = None,
) -> None:
    super().__init__(label, space=space)
    self.x = x

WilsonSamplingInteraction(label, *, target, beta=2.0, state='theta', group=None, move='rotate', width=1.5, rule='metropolis', schedule='colored', hits=1)

Bases: Interaction

Boltzmann weight of link variables under the local Wilson action of the plaquettes of a link.

For link angles the action is -beta sum_p cos(theta_p), where theta_p is the oriented sum of the link angles around the plaquette p. It is the objective of every link, which the MetropolisSolver of the system moves, such as MetropolisSolver(moves={'links.theta': 'rotate'}, schedule='colored', width=1.5) for U(1) or moves={'links.theta': 'random-value'} for Z_N. For the matrices of a group SU(N) the action is -(beta / N) sum_p Re tr U_p, where U_p is the path-ordered product of the link matrices around p, and the interaction sweeps the links itself: the move 'rotate' multiplies a link by a random matrix of the group near the identity of spread width, and 'random-value' draws a uniform matrix of the group, hits times per link.

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 group on the edges of a cell complex.

required
beta Annotated[float, closed_open(0, oo)]

The inverse coupling of the Wilson action.

2.0
state str

The name of the state that holds the link angles or matrices.

'theta'
group MatrixGroupSpec | None

The matrix group of the links, or None for link angles.

None
move str | Callable[..., object]

The move of matrix links, 'rotate' or 'random-value', or a function of the matrices and the random generator.

'rotate'
width float

The spread of a rotation of matrix links.

1.5
rule str

The acceptance of the moves of matrix links, 'metropolis' or 'glauber'.

'metropolis'
schedule str

The order of the moves of matrix links, 'colored' or 'random-sequential'.

'colored'
hits int

The number of moves proposed per matrix link and sweep.

1

Examples:

>>> from skcomplex.systems.physics.common.fields import WilsonSamplingInteraction
>>> WilsonSamplingInteraction('wilson', target='links', beta=2.0).beta
2.0
>>> from skcomplex.core.components import MatrixGroupSpec
>>> color = WilsonSamplingInteraction('wilson', target='links', state='U', group=MatrixGroupSpec('SU', 3))
>>> color.group.degree
3
Source code in src/skcomplex/systems/physics/common/fields/_wilson_sampling.py
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
def __init__(
    self,
    label: str,
    *,
    target: Role,
    beta: Annotated[float, RealSet.closed_open(0, oo)] = 2.0,
    state: str = 'theta',
    group: MatrixGroupSpec | None = None,
    move: str | Callable[..., object] = 'rotate',
    width: float = 1.5,
    rule: str = 'metropolis',
    schedule: str = 'colored',
    hits: int = 1,
) -> None:
    super().__init__(label)
    self.target = target
    self.beta = beta
    self.state = state
    self.group = group
    self.move = move
    self.width = width
    self.rule = rule
    self.schedule = schedule
    self.hits = hits