FieldAnalyzer#
- class zeroheliumkit.fem.fieldreader.FieldAnalyzer(coupling_constants: CouplingConstants)[source]#
Bases:
objectA class for analyzing and plotting field data extracted from FEM simulations. This class provides methods to: - Load and store field data as attributes. - Calculate potential distributions from coupling constants and voltages. - Plot 2D and 1D potential and electric field distributions.
- Parameters:
coupling_constants (CouplingConstants) – The coupling constants used for field analysis.
Methods
Calculates the potential distribution based on the coupling constants and voltages.
get_data([slice])Returns the potential distribution.
get_gradient(grad_axis[, slice])Returns the gradient of the potential data.
plot1D_data(slice[, ax, scale, add_offset])Plots the 1D potential distribution along a specified slice in the XY plane.
plot1D_gradient(grad_axis, slice[, ax, ...])Plots the 1D gradient of the potential distribution along a specified slice in the XY plane.
plot2D_data([ax, num_levels, zero_line])Plots the 2D potential distribution based on the coupling constants and voltages.
plot2D_gradient(grad_axis[, ax, num_levels])Plots the 2D gradient distribution based on the coupling constants and voltages.
plot2D_vectorfield([ax, step])Plots the 2D electric field distribution as a vector field.
print_voltages()set_voltages(voltages)Sets the voltages for the electrodes.
update()Updates the potential distribution based on the current voltages.
Attributes
couplingsnamesvoltagespotential- set_voltages(voltages: dict) None[source]#
Sets the voltages for the electrodes.
- Parameters:
voltages (dict) – A dictionary containing the voltages.
- accumulate_arrays() None[source]#
Calculates the potential distribution based on the coupling constants and voltages.
- get_data(slice: tuple = None) ndarray[source]#
Returns the potential distribution. If a slice is provided, returns the potential along that slice.
- Parameters:
slice (tuple, optional) – A tuple specifying the slice of data to use. Defaults to None -> In this case, the full 2D array is returned.
- get_gradient(grad_axis: str, slice: tuple = None) ndarray[source]#
Returns the gradient of the potential data.
- Parameters:
grad_axis (str) – The axis along which to compute the gradient. Must be either ‘x’ or ‘y’.
slice (tuple, optional) – A tuple specifying the slice of data to use. Defaults to None -> In this case, the full 2D array is used.
- Raises:
ValueError – If grad_axis is not ‘x’ or ‘y’.
- Returns:
The gradient of the potential data.
- Return type:
np.ndarray
- plot2D_data(ax=None, num_levels: int = 17, zero_line: float | int = None, **kwargs)[source]#
Plots the 2D potential distribution based on the coupling constants and voltages.
- Parameters:
ax (optional) – The matplotlib axes object to plot on. If not provided, a new figure and axes will be created.
num_levels (int, optional) – The number of contour levels to use. Defaults to 17.
zero_line (optional) – The value at which to draw a dashed line. If True, the zero line will be drawn at 0. If None, no zero line will be drawn.
**kwargs – Additional keyword arguments to pass to the contourf function. See documentation <https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.contourf.html>`_.
- plot2D_gradient(grad_axis: str, ax=None, num_levels: int = 17, **kwargs)[source]#
Plots the 2D gradient distribution based on the coupling constants and voltages.
- Parameters:
grad_axis (str) – The axis along which to compute the gradient. Must be either ‘x’ or ‘y’.
ax (optional) – The matplotlib axes object to plot on. Defaults to None.
num_levels (int, optional) – The number of contour levels to use. Defaults to 17.
**kwargs – Additional keyword arguments to pass to the contourf function. See documentation <https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.contourf.html>`_.
- Raises:
ValueError – If grad_axis is not ‘x’ or ‘y’.
- plot2D_vectorfield(ax=None, step: int = 5, **kwargs)[source]#
Plots the 2D electric field distribution as a vector field.
- Parameters:
ax (optional) – The matplotlib axes object to plot on. Defaults to None. If not provided, a new figure and axes will be created.
**kwargs – Additional keyword arguments to pass to the matplotlib quiver function. See documentation <https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.quiver.html>`_.
- plot1D_data(slice: tuple, ax=None, scale=1, add_offset=0, **kwargs)[source]#
Plots the 1D potential distribution along a specified slice in the XY plane.
- Parameters:
slice (tuple) – A tuple specifying the slice of data to use. Must be of the form (‘x’ or ‘y’, value).
scale (float, optional) – A scaling factor to apply to the potential data. Defaults to 1e3.
add_offset (float, optional) – An offset to add to the potential data after scaling. Defaults to 0.
ax (optional) – The matplotlib axes object to plot on. If not provided, a new figure and axes will be created.
**kwargs – Additional keyword arguments to pass to the plot function.
- plot1D_gradient(grad_axis: str, slice: tuple, ax=None, scale=1, add_offset=0, **kwargs)[source]#
Plots the 1D gradient of the potential distribution along a specified slice in the XY plane.
- Parameters:
grad_axis (str) – The axis along which to compute the gradient. Must be either ‘x’ or ‘y’.
slice (tuple) – A tuple specifying the slice of data to use. Must be of the form (‘x’ or ‘y’, value).
scale (float, optional) – A scaling factor to apply to the gradient data. Defaults to 1e3.
add_offset (float, optional) – An offset to add to the gradient data after scaling. Defaults to 0.
ax (optional) – The matplotlib axes object to plot on. If not provided, a new figure and axes will be created.
**kwargs – Additional keyword arguments to pass to the plot function.