discretisedfield.tools.topological_charge_density(field, /, method='continuous')#

Topological charge density.

This method computes the topological charge density for a vector field having three value components (i.e. nvdim=3). Two different methods are available and can be selected using method:

  1. Continuous method for calculation of the topological charge density in xy-plane:

    \[q = \frac{1}{4\pi} \mathbf{n} \cdot \left(\frac{\partial \mathbf{n}}{\partial x} \times \frac{\partial \mathbf{n}}{\partial y} \right),\]

    where \(\mathbf{n}\) is the orientation field.

  2. Berg-Luescher method. Details can be found in:

    1. B. Berg and M. Luescher. Definition and statistical distributions of a topological number in the lattice O(3) sigma-model. Nuclear Physics B 190 (2), 412-424 (1981).

    2. J.-V. Kim and J. Mulkers. On quantifying the topological charge in micromagnetics using a lattice-based approach. IOP SciNotes 1, 025211 (2020).

Topological charge is defined on two-dimensional geometries only. Therefore, the field must be “sliced” using the discretisedfield.Field.sel method. If the field is not three-dimensional or the field is not sliced, ValueError is raised.

  • field (discretisedfield.Field) – Vector field.

  • method (str, optional) – Method how the topological charge is computed. It can be continuous or berg-luescher. Defaults to continuous.


Topological charge density scalar field.

Return type:



ValueError – If the field is not three-dimensional or the field is not sliced.


  1. Compute topological charge density of a spatially constant vector field.

>>> import discretisedfield as df
>>> import discretisedfield.tools as dft
>>> p1 = (0, 0, 0)
>>> p2 = (10, 10, 10)
>>> cell = (2, 2, 2)
>>> mesh = df.Mesh(p1=p1, p2=p2, cell=cell)
>>> f = df.Field(mesh, nvdim=3, value=(1, 1, -1))
>>> dft.topological_charge_density(f.sel('z'))
>>> dft.topological_charge_density(f.sel('z'), method='berg-luescher')
  1. An attempt to compute the topological charge density of a scalar field.

>>> f = df.Field(mesh, nvdim=1, value=12)
>>> dft.topological_charge_density(f.sel('z'))
Traceback (most recent call last):
ValueError: ...

3. Attempt to compute the topological charge density of a vector field, which is not sliced.

>>> f = df.Field(mesh, nvdim=3, value=(1, 2, 3))
>>> dft.topological_charge_density(f)
Traceback (most recent call last):
ValueError: ...