coconut_tools.pyTDM.core_td.COCONUT.utils

Utility functions for numerical derivatives and vector field rotation.

This module provides helper tools commonly used in MHD or plasma simulations, including: - nufd1: construction of first-order derivative operators on non-uniform grids using finite differences. - ComputeRot: computation of the curl (∇×F) of a vector field in Cartesian or spherical geometry.

These functions were developed by Antoine Strugarek (CEA) and are intended for post-processing or analysis of vector fields, such as magnetic fields in flux rope models.

Functions:
  • nufd1(x): returns a sparse matrix (scipy COO format) representing the first-order derivative operator.

  • ComputeRot(x1, x2, x3, var1, var2, var3, geom=’cartesian’): computes the curl of a 3D vector field in either Cartesian or spherical coordinates, with support for 2.5D geometries.

Functions

ComputeRot(x1, x2, x3, var1, var2, var3[, geom])

Compute the curl (∇×F) of a vector field in Cartesian or spherical coordinates.

nufd1(x)

Build a finite-difference matrix for first-order derivatives on a non-uniform grid.

coconut_tools.pyTDM.core_td.COCONUT.utils.ComputeRot(x1, x2, x3, var1, var2, var3, geom='cartesian')[source]

Compute the curl (∇×F) of a vector field in Cartesian or spherical coordinates.

Parameters:
  • x1 (array-like) – Grid points in the first dimension (r or x).

  • x2 (array-like) – Grid points in the second dimension (θ or y).

  • x3 (array-like) – Grid points in the third dimension (φ or z).

  • var1 (ndarray) – First component of the vector field (F₁).

  • var2 (ndarray) – Second component of the vector field (F₂).

  • var3 (ndarray) – Third component of the vector field (F₃).

  • geom (str) – Geometry type. ‘cartesian’ or ‘spherical’.

Returns:

Components [∇×F]_1, [∇×F]_2, [∇×F]_3 of the curl of the vector field.

Return type:

list of ndarray

Notes

  • The implementation supports 3D and 2.5D geometries.

  • For spherical geometry, x1, x2, and x3 must represent [r, θ, φ] respectively.

  • This function was developed by Antoine Strugarek (CEA).

coconut_tools.pyTDM.core_td.COCONUT.utils.nufd1(x)[source]

Build a finite-difference matrix for first-order derivatives on a non-uniform grid.

This function returns a second-order accurate sparse matrix that approximates the first derivative operator ∂/∂x on a given 1D grid, even if the grid spacing is non-uniform.

Parameters:

x (array-like) – 1D array of coordinates (assumed to be ordered).

Returns:

Sparse matrix of shape (n, n) representing the derivative operator.

Return type:

scipy.sparse.coo_matrix

Notes

This function was developed by Antoine Strugarek (CEA).