Base System

The base system is the core of the comfit package. It is the base class for all the systems that can be simulated with comfit. It provides the basic structure for the simulation and the methods that are common to all systems.

class comfit.core.base_system.BaseSystem(dim, **kwargs)

Bases: BaseSystemInit, BaseSystemConf, BaseSystemEvolve, BaseSystemCalc, BaseSystemPlot, BaseSystemGet

The BaseSystem class is the base class for all systems in ComFiT

fft(field)

Perform a fast Fourier transform on a field.

Parameters

fieldnp.ndarray

The field to transform

Returns

np.ndarray

The transformed field

Note

The field is assumed to represent a field in the dimensions of the system. Thus, if the system is 2D and the field is 3D, it is assumed that the provided field is a collection of 2D fields which will be transformed individually.

ifft(field)

Perform an inverse fast Fourier transform on a field.

Parameters

fieldnp.ndarray

The field to transform

Returns

np.ndarray

The transformed field

Note

The field is assumed to represent a field in the dimensions of the system. Thus, if the system is 2D and the field is 3D, it is assumed that the provided field is a collection of 2D fields which will be transformed individually.

class comfit.core.base_system_init.BaseSystemInit(dim, **kwargs)

Bases: object

Initialization methods for the base system class.

__init__(dim, **kwargs)

Initialize the class with the given parameters.

Parameters

dimint

The dimension of the system. Must be 1, 2, or 3.

**kwargsdict

Additional keyword arguments, see https://comfitlib.com/ClassBaseSystem/

Returns

None

class comfit.core.base_system_evolve.BaseSystemEvolve

Bases: object

Evolution methods for the base system class

evolve_ETD2RK_loop(integrating_factors_f, nonlinear_evolution_function_f, field, field_f)

Evolves the given field using the ETD2RK scheme with a loop.

Return type:

tuple[ndarray, ndarray]

Parameters

integrating_factors_flist

A list of three integrating factors.

nonlinear_evolution_function_fcallable

A function that calculates the non-linear evolution of the field and returns the fourier transform.

fieldndarray

The initial field to be evolved.

field_fndarray

The Fourier transform of the initial field.

Returns

tuple

A tuple containing the evolved field and the predicted field in Fourier space.

evolve_ETD4RK_loop(integrating_factors_f, nonlinear_evolution_function_f, field, field_f)

Evolves the given field using the ETD4RK scheme with a loop.

Return type:

tuple[ndarray, ndarray]

Parameters

integrating_factors_flist

A list of five integrating factors.

nonlinear_evolution_function_fcallable

A function that calculates the non-linear evolution of the field.

fieldndarray

The initial field to be evolved.

field_fndarray

The Fourier transform of the initial field.

Returns

tuple

A tuple containing the evolved field and the predicted field in Fourier space.

class comfit.core.base_system_get.BaseSystemGet

Bases: object

Get methods for the base system class

get_anti_sym(omega, i, j)

Gets the i,j component of an anti-symmetric tensor saved in an array structure.

Return type:

ndarray

Parameters

omeganumpy.ndarray

The anti-symmetric tensor.

iint

The row index.

jint

The column index.

Returns

numpy.ndarray

The i,j component of the tensor.

get_sym(tensor, i, j)

Gets the i,j component of a symmetric tensor saved in an array structure.

Return type:

ndarray

Parameters

tensornumpy.ndarray

The symmetric tensor.

iint

The row index.

jint

The column index.

Returns

numpy.ndarray

The i,j component of the tensor.

get_sym_tl(tensor, i, j)

Gets the i,j component of a symmetric traceless tensor saved in an array structure.

Return type:

ndarray

Parameters

tensornumpy.ndarray

The symmetric traceless tensor.

iint

The row index.

jint

The column index.

Returns

numpy.ndarray

The i,j component of the tensor.

class comfit.core.base_system_plot.BaseSystemPlot

Bases: object

Plotting methods for the base system class

plot_angle_field(angle_field, **kwargs)

Plot an angle field.

Return type:

Tuple[Union[Figure, Figure], Any]

Parameters

angle_fieldnp.ndarray

Angle field to be plotted.

**kwargsAny

Keyword arguments for the plot. See https://comfitlib.com/ClassBaseSystem/ for a full list of keyword arguments.

Returns

Tuple[Union[go.Figure, plt.Figure], Any]

Tuple containing the figure (plotly or matplotlib) and the axes dictionary (plotly or matplotlib).

Note

plot_lib is a possible keyword argument. If not provided, the default plotting library (plotly or matplotlib) will be used. See the corresponding plot_angle_field_plotly or plot_angle_field_matplotlib function in the Auxiliary Plot Functions documentation for further details.

plot_angle_field_in_plane(angle_field, normal_vector=None, position=None, **kwargs)

Plot the angle field in a plane.

Return type:

Tuple[Union[Figure, Figure], Any]

Parameters

angle_fieldnp.ndarray

Angle field to be plotted.

normal_vectornp.ndarray, optional

Normal vector of the plane. If None, the normal vector will be calculated.

positionnp.ndarray, optional

Position of the plane. If None, the position will be calculated.

**kwargsAny

Keyword arguments for the plot. See https://comfitlib.com/ClassBaseSystem/ for a full list of keyword arguments.

Returns

Tuple[Union[go.Figure, plt.Figure], Any]

Tuple containing the figure (plotly or matplotlib) and the axes dictionary (plotly or matplotlib).

Note

plot_lib is a possible keyword argument. If not provided, the default plotting library (plotly or matplotlib) will be used. See the corresponding plot_angle_field_plotly or plot_angle_field_matplotlib function in the Auxiliary Plot Functions documentation for further details.

plot_complex_field(complex_field, **kwargs)

Plot a complex field.

Return type:

Tuple[Union[Figure, Figure], Any]

Parameters

complex_fieldnp.ndarray

Complex field to be plotted.

**kwargsAny

Keyword arguments for the plot. See https://comfitlib.com/ClassBaseSystem/ for a full list of keyword arguments.

Returns

Tuple[Union[go.Figure, plt.Figure], Any]

Tuple containing the figure (plotly or matplotlib) and the axes dictionary (plotly or matplotlib).

Note

plot_lib is a possible keyword argument. If not provided, the default plotting library (plotly or matplotlib) will be used. See the corresponding plot_complex_field_plotly or plot_complex_field_matplotlib function in the Auxiliary Plot Functions documentation for further details.

plot_complex_field_in_plane(complex_field, normal_vector=None, position=None, **kwargs)

Plot the complex field in a plane.

Return type:

Tuple[Union[Figure, Figure], Any]

Parameters

complex_fieldnp.ndarray

Complex field to be plotted.

normal_vectornp.ndarray, optional

Normal vector of the plane. If None, the normal vector will be calculated.

positionnp.ndarray, optional

Position of the plane. If None, the position will be calculated.

**kwargsAny

Keyword arguments for the plot. See https://comfitlib.com/ClassBaseSystem/ for a full list of keyword arguments.

Returns

Tuple[Union[go.Figure, plt.Figure], Any]

Tuple containing the figure (plotly or matplotlib) and the axes dictionary (plotly or matplotlib).

Note

plot_lib is a possible keyword argument. If not provided, the default plotting library (plotly or matplotlib) will be used. See the corresponding plot_complex_field_in_plane_plotly or plot_complex_field_in_plane_matplotlib function in the Auxiliary Plot Functions documentation for further details.

plot_field(field, **kwargs)

Plot a field.

Return type:

Tuple[Union[Figure, Figure], Any]

Parameters

fieldnp.ndarray

Field to be plotted.

**kwargsAny

Keyword arguments for the plot. See https://comfitlib.com/ClassBaseSystem/ for a full list of keyword arguments.

Returns

Tuple[Union[go.Figure, plt.Figure], Any]

Tuple containing the figure (plotly or matplotlib) and the axes dictionary (plotly or matplotlib).

Note

plot_lib is a possible keyword argument. If not provided, the default plotting library (plotly or matplotlib) will be used. See the corresponding plot_field_plotly or plot_field_matplotlib function in the Auxiliary Plot Functions documentation for further details.

plot_field_in_plane(field, normal_vector=None, position=None, **kwargs)

Plot the field in a plane.

Return type:

Tuple[Union[Figure, Figure], Any]

Parameters

fieldnp.ndarray

Field to be plotted.

normal_vectornp.ndarray, optional

Normal vector of the plane. If None, the normal vector will be calculated.

positionnp.ndarray, optional

Position of the plane. If None, the position will be calculated.

**kwargsAny

Keyword arguments for the plot. See https://comfitlib.com/ClassBaseSystem/ for a full list of keyword arguments.

Returns

Tuple[Union[go.Figure, plt.Figure], Any]

Tuple containing the figure (plotly or matplotlib) and the axes dictionary (plotly or matplotlib).

Note

plot_lib is a possible keyword argument. If not provided, the default plotting library (plotly or matplotlib) will be used. See the corresponding plot_field_in_plane_plotly or plot_field_in_plane_matplotlib function in the Auxiliary Plot Functions documentation for further details.

plot_nodes(nodes, **kwargs)

Plot nodes.

Return type:

Tuple[Union[Figure, Figure], Any]

Parameters

nodesnp.ndarray

Nodes to be plotted.

**kwargsAny

Keyword arguments for the plot. See https://comfitlib.com/ClassBaseSystem/ for a full list of keyword arguments.

Returns

Tuple[Union[go.Figure, plt.Figure], Any]

Tuple containing the figure (plotly or matplotlib) and the axes dictionary (plotly or matplotlib).

Note

plot_lib is a possible keyword argument. If not provided, the default plotting library (plotly or matplotlib) will be used. See the corresponding plot_nodes_plotly or plot_nodes_matplotlib function in the Auxiliary Plot Functions documentation for further details.

plot_prepare(field, field_type, **kwargs)

Prepare axis and figure for plotting.

Return type:

Tuple[ndarray, Union[Figure, Figure], Any, Dict]

Parameters

fieldnp.ndarray

Field to be plotted.

field_typestr

Type of the field to be plotted.

Returns

Tuple[np.ndarray, Union[go.Figure, plt.Figure], Any, Dict]

Tuple containing the field, figure (plotly or matplotlib), axis (plotly or matplotlib) and keyword arguments for plotting.

plot_save(fig, counter=None, **kwargs)

Save a figure.

Return type:

None

Parameters

figUnion[plt.Figure, go.Figure]

Figure to be saved.

counterint, optional

Counter for the figure. If None, the figure will be saved as ‘plot.png’.

**kwargsAny

Optional arguments: ID, image_size_inches, dpi.

Returns

None

Save the figure.

plot_subplots(number_of_rows, number_of_columns, **kwargs)

Plot subplots.

Return type:

Tuple[Union[Figure, Figure], Any]

Parameters

number_of_rowsint

Number of rows in the subplot.

number_of_columnsint

Number of columns in the subplot.

Returns

Tuple[Union[go.Figure, plt.Figure], Any]

Tuple containing the figure (plotly or matplotlib) and the axes dictionary (plotly or matplotlib).

plot_vector_field(vector_field, **kwargs)

Plot a vector field.

Return type:

Tuple[Union[Figure, Figure], Any]

Parameters

vector_fieldnp.ndarray

Vector field to be plotted.

**kwargsAny

Keyword arguments for the plot. See https://comfitlib.com/ClassBaseSystem/ for a full list of keyword arguments.

Returns

Tuple[Union[go.Figure, plt.Figure], Any]

Tuple containing the figure (plotly or matplotlib) and the axes dictionary (plotly or matplotlib).

Note

plot_lib is a possible keyword argument. If not provided, the default plotting library (plotly or matplotlib) will be used. See the corresponding plot_vector_field_plotly or plot_vector_field_matplotlib function in the Auxiliary Plot Functions documentation for further details.

plot_vector_field_in_plane(vector_field, normal_vector=None, position=None, spacing=None, **kwargs)

Plot the vector field in a plane.

Return type:

Tuple[Union[Figure, Figure], Any]

Parameters

vector_fieldnp.ndarray

Vector field to be plotted.

normal_vectornp.ndarray, optional

Normal vector of the plane. If None, the normal vector will be calculated.

positionnp.ndarray, optional

Position of the plane. If None, the position will be calculated.

spacingfloat, optional

Spacing between the vectors.

**kwargsAny

Keyword arguments for the plot. See https://comfitlib.com/ClassBaseSystem/ for a full list of keyword arguments.

Returns

Tuple[Union[go.Figure, plt.Figure], Any]

Tuple containing the figure (plotly or matplotlib) and the axes dictionary (plotly or matplotlib).

Note

plot_lib is a possible keyword argument. If not provided, the default plotting library (plotly or matplotlib) will be used. See the plot_vector_field_both_plot_libs function in the Auxiliary Plot Functions documentation for further details.

show(fig)

Show a figure.

Return type:

None

Parameters

figUnion[plt.Figure, go.Figure]

Figure to be shown.

Returns

None

Show the figure.

class comfit.core.base_system_calc.BaseSystemCalc

Bases: object

Calculation method for the base system class

calc_Gaussian(position=None, width=None, top=None, value=None)

Calculate the Gaussian function.

Parameters

positionlist or array, optional

The center position of the Gaussian. If None, uses the middle of the grid.

widthfloat, optional

The width of the Gaussian. If None, uses the system’s a0 parameter.

topfloat, optional

The maximum value of the Gaussian function.

valuefloat, optional

The integrated value of the Gaussian function. If neither top nor value is provided, the function will be normalized to 1.

Returns

numpy.ndarray

The Gaussian function evaluated on the grid.

Notes

If top is provided, it scales the height of the Gaussian. If value is provided, it scales the integral of the Gaussian.

calc_Gaussian_filter_f(a0=None)

Calculate Gaussian filter in Fourier space.

This method computes a Gaussian filter in Fourier space using the formula: exp(-1/2 * a0^2 * k^2) where k^2 is the squared wavenumber.

Parameters

a0float, optional

Filter width parameter. If None, uses the instance’s a0 attribute.

Returns

numpy.ndarray

The Gaussian filter in Fourier space.

Notes

The filter is calculated using the squared wavenumber obtained from the calc_k2() method.

calc_advect_field(field, u, field_f=None, order=3)

Advects field according to the provided displacement field u.

Uses a Taylor expansion up to specified order to compute the advection.

Return type:

ndarray

Parameters

fieldnp.ndarray

The field to be advected.

unp.ndarray

Displacement field.

field_fnp.ndarray, optional

Fourier transform of the field. If None, it will be calculated.

orderint, default=3

Order of the Taylor expansion. Must be less than or equal to 3.

Returns

np.ndarray

The field after advection by u.

Raises

ValueError

If the order of the Taylor expansion is greater than 3.

calc_angle_field_single_vortex(position=None, charge=1)

Calculate the angle field due to a single vortex.

Return type:

ndarray

Parameters

positionlist, optional

The position of the vortex. Defaults to None.

chargeint, optional

The charge of the vortex. Defaults to 1.

Returns

numpy.ndarray

The angle field calculated for the vortex.

Raises

Exception

If the dimension of the system is not 2.

calc_angle_field_vortex_dipole(dipole_vector=None, dipole_position=None)

Calculates the angle field for a double vortex system.

Return type:

ndarray

Parameters

dipole_vectorlist or tuple, optional

The dipole vector. If None, defaults to [size_x/3, 0].

dipole_positionlist, optional

The position of the center of mass of the dipole. If None, defaults to the middle of the grid.

Returns

numpy.ndarray

The calculated angle field for the double vortex system.

Raises

Exception

If the dimension of the system is not 2.

calc_angle_field_vortex_ring(position=None, radius=None, normal_vector=[0, 0, 1])

Calculate the angle field for a vortex ring.

Return type:

ndarray

Parameters

positionlist, optional

The position of the vortex ring. If None, defaults to the middle of the grid.

radiusfloat, optional

The radius of the vortex ring. If None, defaults to 1/3 of the minimum system size.

normal_vectornumpy.ndarray, optional

The normal vector of the vortex ring. Defaults to [0, 0, 1].

Returns

numpy.ndarray

The calculated angle field for the vortex ring.

calc_defect_current_density(psi, dt_psi, psi_0=0)

Calculates the conserved current of the superfluid density.

Parameters

psinumpy.ndarray

The vector field that we find the density of.

dt_psinumpy.ndarray

The time derivative of psi.

psi_0float or numpy.ndarray, optional

The equilibrium state. Default is 0.

Returns

list of numpy.ndarray

Components of the conserved current.

calc_defect_density(psi, psi0=1)

Calculate the defect density of a given psi field.

Return type:

ndarray

Parameters

psilist of numpy.ndarray

A list of two psi fields.

psi0float, optional

The value of psi_0. Default is 1.

Returns

numpy.ndarray

The defect density of the psi field.

calc_defect_density_singular(psi, psi0=1)

Calculate the singular defect density for a given psi field.

Return type:

ndarray

Parameters

psinumpy.ndarray

The field psi.

psi0float, optional

The reference value of psi. Default is 1.

Returns

numpy.ndarray

The defect density for the given psi value.

calc_defect_nodes(defect_density, charge_tolerance=None, integration_radius=None)

Calculate the positions and charges of defect nodes based on the defect density.

Parameters

defect_densitynumpy.ndarray

The defect density field. A positive scalar field to be integrated.

charge_tolerancefloat, optional

The minimum charge value to consider as a defect. If None, uses default values based on dimension.

integration_radiusfloat, optional

The radius to use for integrating around potential defects. If None, uses default values based on dimension.

Returns

list

A list of dictionaries representing the defect nodes. Each dictionary contains: - ‘position_index’: The position index of the defect node in the defect density array. - ‘position’: The physical position of the defect node.

Raises

Exception

If the defect density is not a positive scalar field.

calc_defect_velocity_field(psi, dt_psi)

Calculate the velocity field of the defects in the psi field.

Return type:

list[ndarray, ndarray]

Parameters

psilist of numpy.ndarray

The psi field.

dt_psilist of numpy.ndarray

The time derivative of the psi field.

Returns

list of numpy.ndarray

The velocity field of the defects.

calc_delta_function(psi, psi0=1)

Calculate the delta function for a given wavefunction.

Parameters

psilist of numpy.ndarray

The wavefunction.

psi0float, optional

The width of the wavefunction. Default is 1.

Returns

numpy.ndarray

The value of the delta function.

calc_determinant_field(psi)

Calculate the determinant transformation of a given field.

The D-field used in the calculation of the topologicel defect density fields. See the ComFiT documentation for more information: https://comfitlib.com/TopologicalDefects/

Return type:

ndarray

Parameters

psilist of numpy.ndarray

A list of two psi fields.

Returns

numpy.ndarray

The determinant field.

calc_distance_squared_to_point(position)

Calculate the squared distance from each point in the grid to a specified position.

Return type:

ndarray

Parameters

positionUnion[float, list[float]]

The target position. Should be a single float for 1D systems or a list of floats for higher dimensions.

Returns

np.ndarray

An array of the same dimensionality as the system containing the squared distance from each grid point to the specified position. The shape matches the grid resolution.

Notes

This method accounts for periodic boundary conditions by calculating distances in each dimension considering the original position, and positions shifted by +/- the system size. It then takes the minimum of these distances to find the shortest path under periodicity.

calc_evolution_integrating_factors_ETD2RK(omega_f, tol=1e-05)

Calculates integrating factors for ETD2RK.

Return type:

list

Parameters

omega_fnumpy.ndarray

The value of omega_f in Fourier space.

tolfloat, optional

Tolerance for when to expand the integrating factors that divide by omega. Default is 10^-5.

Returns

list

The list of integrating factors for the ETD2RK method.

calc_evolution_integrating_factors_ETD4RK(omega_f, tol=1e-05)

Calculate the evolution integrating factors using the ETDRK4 method.

Return type:

list

Parameters

omega_fnumpy.ndarray

The value of omega_f in Fourier space.

tolfloat, optional

Tolerance for when to expand the integrating factors that divide by omega. Default is 10^-5.

Returns

list

The list of integrating factors for the ETD4RK method.

calc_integrate_field(field, region=None)

Calculates the integrated field value within a specified region.

Return type:

float

Parameters

fieldnumpy.ndarray

The field array to integrate.

regionOptional[int], default=None

If provided, specifies the region to integrate over. If None, integrates over the entire field.

Returns

float

The integrated field value within the region.

Raises

Exception

If the dimension of the field is not compatible.

calc_integrating_factors_f_and_solver(omega_f, method)

Calculates the integrating factors and the solver for the evolution equation.

Return type:

tuple

Parameters

omega_fnumpy.ndarray

The value of omega_f in Fourier space.

method{‘ETD2RK’, ‘ETD4RK’}

The method used for evolution.

Returns

tuple

A tuple containing: integrating_factors_f : list (The integrating factors for the selected method), solver : function (The corresponding solver function for the evolution equation).

Raises

Exception

If the specified method is not implemented.

calc_k2()

Calculates the squared wavenumber.

Parameters

None

Returns

numpy.ndarray

The squared wavenumber.

calc_region_ball(position, radius)

Calculate a boolean array indicating whether a point is within a ball of a given radius.

Return type:

ndarray

Parameters

positionlist[float]

The position of the ball

radiusfloat

The radius of the ball

Returns

numpy.ndarray

A boolean array indicating whether a point is within the ball.

Raises

Exception

If the dimension of the system is not 3.

calc_region_cylinder(position, radius, normal_vector, height)

Calculates a boolean array indicating whether a point is within a cylinder of a given radius and height.

Return type:

ndarray

Parameters

positionlist[float]

The position of the cylinder

radiusfloat

The radius of the cylinder

normal_vectornp.ndarray

The normal vector of the cylinder

heightfloat

The height of the cylinder

Returns

np.ndarray

A boolean array indicating whether a point is within the cylinder.

Raises

Exception

If the dimension of the system is not 3.

calc_region_disk(position, radius)

Calculates a boolean array indicating whether a point is within a disk of a given radius.

Return type:

ndarray

Parameters

positionlist[float]

The position of the disk

radiusfloat

The radius of the disk

Returns

numpy.ndarray

A boolean array indicating whether a point is within the disk.

Raises

Exception

If the dimension of the system is not 2.

calc_region_interval(a, b)

Calculate a boolean array indicating whether a point is within an interval.

Return type:

ndarray

Parameters

afloat

The lower bound of the interval.

bfloat

The upper bound of the interval.

Returns

numpy.ndarray

A boolean array indicating whether a point is within the interval.

Raises

Exception

If the lower bound is greater than the upper bound or if the dimension of the system is not 1.

calc_wavenums(x)

Calculates the wavenumbers corresponding to the input position vectors given by x.

Return type:

ndarray

Parameters

xnumpy.ndarray

1D array of x-positions.

Returns

numpy.ndarray

1D array of wavenumbers with all the modes for the given x-array, assuming periodicity from x[0] to x[0] over n intervals.

Examples

>>> x = np.array([-10, -5, 0, 5, 10])
>>> k = instance_of_BaseSystem.calc_wavenums(self, x)
>>> print(k)
[ 0.          0.25132741  0.50265482 -0.50265482 -0.25132741]
class comfit.core.base_system_conf.BaseSystemConf

Bases: object

Configuration methods for the base system class