simulation_results module

Define a base object to store a multipactor simulation results.

exception ShapeMismatchError[source]

Bases: Exception

Raise error when population and time have different shapes.

exception MissingDataError[source]

Bases: Exception

Error raised when trying to access non-existing data.

class SimulationResults(id, e_acc, time, population, p_rms=None, plotter=None, trim_trailing=False, period=None, parameters=None, **kwargs)[source]

Bases: ABC

Store a single simulation results.

Parameters:
__init__(id, e_acc, time, population, p_rms=None, plotter=None, trim_trailing=False, period=None, parameters=None, **kwargs)[source]

Instantiate, post-process.

Parameters:
  • id (int) – Unique simulation identifier.

  • e_acc (float) – Accelerating field in \(\mathrm{V/m}\).

  • time (ndarray) – Time in \(\mathrm{ns}\).

  • population (ndarray) – Evolution of population with time. Same shape as time.

  • p_rms (float | None, default: None) – RMS power in \(\mathrm{W}\).

  • plotter (Plotter | None, default: None) – An object allowing to plot data.

  • trim_trailing (bool, default: False) – To remove the last simulation points, when the population is 0. Used with SPARK3D (CSV import) for consistency with CST.

  • period (float | None, default: None) – RF period in \(\mathrm{ns}\). Mandatory for exponential growth fits.

  • parameters (dict[str, float | bool | str] | None, default: None) – Additional information on the simulation. Typically, value of magnetic field, number of PIC cells, simulation flags…

__str__()[source]

Print info on current simulation.

Return type:

str

_check_consistent_shapes()[source]

Raise an error if time and population have diff shapes.

Return type:

None

_trim_trailing()[source]

Remove data for which population is null.

Return type:

None

property alpha: float

Return the exponential growth factor in \(\mathrm{ns^{-1}}\).

fit_alpha(fitting_periods, running_mean=False, log_fit=True, minimum_final_number_of_electrons=0, bounds=([1e-10, -10.0], [inf, 10.0]), initial_values=[0.0, 0.0], **kwargs)[source]

Fit exp growth factor.

Parameters:
  • fitting_periods (int) – Number of periods over which the exp growth is searched. Longer is better, but you do not want to start the fit before the exp growth starts.

  • running_mean (bool, default: False) – To tell if you want to average the number of particles over one period. It is recommended with CST, but does not bring anything for SPARK3D. The default is False.

  • log_fit (bool, default: True) – To perform the fit on exp_growth_log() rather than exp_growth(). The default is True, as it generally shows better convergence.

  • minimum_final_number_of_electrons (int, default: 0) – Under this final number of electrons, we do no bother finding the exp growth factor and set all fit parameters to NaN.

  • bounds (tuple[list[float], list[float]], default: ([1e-10, -10.0], [inf, 10.0])) – Upper bound and lower bound for the two variables: initial number of electrons, exp growth factor.

  • initial_values (list[float], optional) – Initial values for the two variables: initial number of electrons, exp growth factor.

Return type:

None

property modelled_population: ndarray

Define evolution of population, as modelled.

plot(x, y, plotter=None, label=None, grid=True, axes=None, **kwargs)[source]

Plot y vs x using plotter.plot() method.

Parameters:
  • x (Union[Literal['id', 'e_acc', 'p_rms', 'alpha'], Literal['time', 'population', 'modelled_population']]) – Name of properties to plot.

  • y (Union[Literal['id', 'e_acc', 'p_rms', 'alpha'], Literal['time', 'population', 'modelled_population']]) – Name of properties to plot.

  • plotter (Plotter | None, default: None) – Object to use for plot. If not provided, we use _plotter.

  • label (Union[str, Literal['auto'], None], default: None) – If provided, overrides the legend. Useful when several simulations are shown on the same plot. Use the magic keyword "auto" to legend with a short description of current object.

  • grid (bool, default: True) – If grid should be plotted. Default is True.

  • axes (Any | None, default: None) – Axes to re-use, if provided. The default is None (plot on new axis).

  • kwargs – Other keyword arguments passed to the Plotter.plot() method.

Returns:

Objects created by the Plotter.plot().

Return type:

Any

hist(*args, **kwargs)[source]
Return type:

Any

to_pandas(*args)[source]

Concatenate all attribute arrays which name is in args to a df.

Parameters:

args (Union[Literal['id', 'e_acc', 'p_rms', 'alpha'], Literal['time', 'population', 'modelled_population']]) – Name of arguments as saved in current objects. Example: "population", "time"

Returns:

Concatenates all desired data.

Return type:

pandas.DataFrame

Raises:
  • MissingDataError: – If a string in args does not correspond to any attribute in self (or if corresponding value is None).

  • ValueError: – If all the args are a single value (float/int/bool).

show()[source]

Show the plots that were produced.

Useful for the bash interface.

Return type:

None

_abc_impl = <_abc._abc_data object at 0x7e2c7019b9c0>
class SimulationResultsFactory(plotter=None, freq_ghz=None, stl_path=None, stl_alpha=None, *args, **kwargs)[source]

Bases: ABC

Easily create SimulationResults.

Parameters:
__init__(plotter=None, freq_ghz=None, stl_path=None, stl_alpha=None, *args, **kwargs)[source]

Instantiate object.

Parameters:
  • plotter (Plotter | None, default: None) – Object to create the plots.

  • freq_ghz (float | None, default: None) – RF frequency in \(\mathrm{GHz}\). Used to compute RF period, which is mandatory for exp growth fitting.

  • stl_path (str | Path | None, default: None) – Path to the STL file holding the 3D structure of the system. The default is None.

  • stl_alpha (float | None, default: None) – Transparency setting for the mesh.

_abc_impl = <_abc._abc_data object at 0x7e2c7019ba80>