coconut_tools.pyTDM.core_td.COCONUT.coconut

Module for handling CFmesh files and injecting TDm/RBSL structures into the COCONUT model.

This module provides functions to: - read and parse corona.CFmesh files used in MHD simulations with COCONUT, - interpolate Cartesian magnetic fields (from VTK/VTU files) to the cell centers of a CFmesh grid, - generate a new CFmesh file with the injected magnetic structure, - convert Cartesian magnetic fields to spherical components (Br, Bθ, Bφ), - aggregate multiple .vtu files from parallel COCONUT simulations.

Main functions: - read_CFmesh: reads a CFmesh file and returns the magnetic field components in spherical coordinates. - read_vtu: merges .vtu files from a parallel run of COCONUT. - readstruct: extracts the internal structure and block indices from a CFmesh file.

This module is used to enable the injection of TDm or RBSL flux ropes as initial conditions in COCONUT-based simulations.

Functions

createdata(vtkfile)

Create the data file containing the magnetic field

read_CFmesh(path_file)

Read and extract magnetic field data from a COCONUT CFmesh file.

read_vtu(path_file, nb_proc)

Merge and clean multiple VTU files generated by COCONUT and compute magnetic field components in spherical coordinates.

readstruct(lines)

Find the structure of the CFmesh

restart_coolfluid(path, vtsfile, path_save, ...)

Create the CFmesh with the Tdm within

coconut_tools.pyTDM.core_td.COCONUT.coconut.createdata(vtkfile)[source]

Create the data file containing the magnetic field

Parameters:

vtkfile (str) – Magnetic field file

Returns:

coordinates and magnetic field components

Return type:

List (list(float,float,float,float,float,float)

Raises:

FileNotFoundError – if the Tdm file doesn’t exist

coconut_tools.pyTDM.core_td.COCONUT.coconut.read_CFmesh(path_file)[source]

Read and extract magnetic field data from a COCONUT CFmesh file.

This function computes the magnetic field components in spherical coordinates (radial, co-latitudinal, and longitudinal) at the center of each mesh cell.

Parameters:

path_file (str) – Path to the directory containing the ‘corona.CFmesh’ file.

Returns:

  • Unique cell centers (N x 3)

  • Radial magnetic field component br

  • Co-latitudinal magnetic field component bclt

  • Longitudinal magnetic field component blon

Return type:

Tuple[np.ndarray, np.ndarray, np.ndarray, np.ndarray]

Raises:

FileNotFoundError – If ‘corona.CFmesh’ does not exist in the given path.

coconut_tools.pyTDM.core_td.COCONUT.coconut.read_vtu(path_file, nb_proc)[source]

Merge and clean multiple VTU files generated by COCONUT and compute magnetic field components in spherical coordinates.

Parameters:
  • path_file (str) – Directory where the VTU files are located.

  • nb_proc (int) – Number of processors (and thus number of VTU files to read).

Returns:

  • Unique 3D coordinates of the points (shape: N x 3)

  • Radial component of B field (br)

  • Co-latitudinal component (bt)

  • Azimuthal component (bp)

Return type:

Tuple[np.ndarray, np.ndarray, np.ndarray, np.ndarray]

coconut_tools.pyTDM.core_td.COCONUT.coconut.readstruct(lines)[source]

Find the structure of the CFmesh

Parameters:

lines (list(str)) – contains the CFmesh lines

Returns:

where the node start idx1 (int): where the state start idx2 (int): where the elem start idx3 (int): where I don’t know what start nend (int): nbr of !end nbelements (int): nb of elements comment list(list(int,str)): all the non number lines and where there are

Return type:

idx0 (int)

coconut_tools.pyTDM.core_td.COCONUT.coconut.restart_coolfluid(path, vtsfile, path_save, alpha_0, theta_0, phi_0, d, a, R, name, method='rbf', save=False)[source]

Create the CFmesh with the Tdm within

Parameters:
  • path (str) – Where is the CFmesh file

  • vtsfile (str) – Where is the vtk file

  • path_save (str) – Where save the newCFmesh

  • method (str) – Which method we want to use for the interpolation

  • save (bool) – If true we save a vtk file with the TDm in the solar wind

  • alpha_0 (float)

  • theta_0 (float)

  • phi_0 (float)

  • d (float)

  • a (float)

  • R (float)

Return type:

None

Returns:

None

Raises:
  • FileNotFoundError – If the CFmesh doesn’t exist

  • NameError – If the interpolation method doesn’t exist