discretisedfield.tools.topological_charge#

discretisedfield.tools.topological_charge(field, /, method='continuous', absolute=False)#

Topological charge.

This function computes topological charge for a vector field of three dimensions (i.e. nvdim=3). There are two possible methods, which can be chosen using method parameter. For details on method, please refer to topological_charge_density(). Absolute topological charge given as integral over the absolute values of the topological charge density can be computed by passing absolute=True.

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

Parameters:
  • 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.

  • absolute (bool, optional) – If True the absolute topological charge is computed. Defaults to False.

Returns:

Topological charge.

Return type:

float

Raises:

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

Example

1. Compute the topological charge of a spatially constant vector field (zero value is expected).

>>> 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(f.sel('z'), method='continuous')
0.0
>>> dft.topological_charge(f.sel('z'), method='continuous',
...                                      absolute=True)
0.0
>>> dft.topological_charge(f.sel('z'), method='berg-luescher')
0.0
>>> dft.topological_charge(f.sel('z'), method='berg-luescher',
...                                      absolute=True)
0.0
  1. Attempt to compute the topological charge of a scalar field.

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

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

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