4.4.5 pde.pdes.klein_gordon module

The Klein-Gordon equation.

class KleinGordonPDE(speed=1, mass=1, *, bc=None)[source]

Bases: PDEBase

The Klein-Gordon equation.

The mathematical definition, \(\partial_t^2 u = c^2 \nabla^2 u - \mu^2 u\), is implemented as two first-order equations,

\[\begin{split}\partial_t u &= v \\ \partial_t v &= c^2 \nabla^2 u - \mu^2 u\end{split}\]

where \(c\) sets the wave speed, \(\mu\) is the mass parameter, and \(v\) is an auxiliary field. Note that the class expects an initial condition specifying both fields, which can be created using the KleinGordonPDE.get_initial_condition() method. The result will also return two fields.

The Klein-Gordon equation describes relativistic scalar fields and reduces to the standard wave equation when \(\mu = 0\).

Parameters:
  • speed (float) – The speed \(c\) of the wave

  • mass (float) – The mass parameter \(\mu\)

  • bc (BoundariesData | None) – The boundary conditions applied to the field \(u\). Boundary conditions are generally given as a dictionary with one condition for each axis side. For periodic axes, only periodic boundary conditions are allowed (indicated by ‘periodic’ and ‘anti-periodic’). For non-periodic axes, different boundary conditions can be specified for the lower and upper end (using specific identifiers, like x- and y+). For instance, Dirichlet conditions enforcing a value NUM (specified by {‘value’: NUM}) and Neumann conditions enforcing the value DERIV for the derivative in the normal direction (specified by {‘derivative’: DERIV}) are supported. Note that the special value ‘auto_periodic_neumann’ imposes periodic boundary conditions for periodic axis and a vanishing derivative otherwise. More information can be found in the boundaries documentation.

default_bc = 'auto_periodic_neumann'

Default boundary condition used when no specific conditions are chosen.

evolution_rate(state, t=0)[source]

Evaluate the right hand side of the PDE.

Parameters:
Returns:

Fields describing the evolution rates of the PDE

Return type:

FieldCollection

explicit_time_dependence: bool | None = False

Flag indicating whether the right hand side of the PDE has an explicit time dependence.

Type:

bool

property expressions: dict[str, str]

the expressions of the right hand side of this PDE

Type:

dict

get_initial_condition(u, v=None)[source]

Create a suitable initial condition.

Parameters:
  • u (ScalarField) – The initial field amplitude on the grid

  • v (ScalarField, optional) – The initial rate of change. This is assumed to be zero if the value is omitted.

Returns:

The combined fields u and v, suitable for the simulation

Return type:

FieldCollection

make_evolution_rate(state, backend)[source]

Create a compiled function evaluating the right hand side of the PDE.

Parameters:
  • state (ScalarField) – An example for the state defining the grid and data types

  • backend (str or BackendBase) – The backend used for numerical operations

Returns:

A function with signature (state_data, t), which can be called with an instance of the state data and time to obtain the associated evolution rate.

Return type:

Callable[[TNativeArray, float], TNativeArray]