astronomix.initial_condition_generation.magnetic_field_from_vector_potential#
Construct divergence-free magnetic fields from a vector potential.
Initialising the magnetic field from a vector potential A and taking a
discrete curl guarantees div(B) = 0 to machine precision under the matching
discrete divergence operator. The correct discretisation of that curl depends
on the solver topology, so this module branches on the solver mode: staggered
edge-centered differences for the constrained-transport finite-difference
scheme, and a central-difference curl for the cell-centered finite-volume
scheme.
Module Contents#
Functions#
Calculate the cell-centered and face-centered magnetic fields from a given vector potential function, correctly applying discrete curl operations depending on the solver mode (FINITE_DIFFERENCE or FINITE_VOLUME) to ensure a divergence-free magnetic field. |
API#
- astronomix.initial_condition_generation.magnetic_field_from_vector_potential.setup_magnetic_fields_from_vector_potential(config: astronomix.option_classes.simulation_config.SimulationConfig, vector_potential_func: Callable, *args, **kwargs) Tuple[jax.numpy.ndarray, jax.numpy.ndarray, jax.numpy.ndarray, jax.numpy.ndarray, jax.numpy.ndarray, jax.numpy.ndarray][source]#
Calculate the cell-centered and face-centered magnetic fields from a given vector potential function, correctly applying discrete curl operations depending on the solver mode (FINITE_DIFFERENCE or FINITE_VOLUME) to ensure a divergence-free magnetic field.
Note: Uniform background fields cannot be correctly generated from a periodic vector potential. Add background fields to the returned arrays after calling.
- Args:
config: The simulation configuration object. vector_potential_func: A callable
f(X, Y, Z, *args, **kwargs)thatreturns a tuple
(A_x, A_y, A_z)evaluated at the given coordinates.- Returns:
B_x, B_y, B_z: Cell-centered magnetic field components. bxb, byb, bzb: Face-centered (interface) magnetic field components.