simulation_results module
Define an object to store CST simulation results.
Note
As for now, it can only load data stored in a single file. For Position
Monitor exports (one file = one time step), see dedicated package
PositionMonitor.
Todo
Evaluate expressions such as param2 = 2 * param1
Todo
Allow to have P_rms instead of E_acc; E_acc does not make a lot of sense in a lot of cases.
- exception MissingFileError[source]
Bases:
ExceptionError raised when a mandatory CST file was not found.
- class CSTResults(id, e_acc, time, population, p_rms=None, plotter=None, trim_trailing=False, period=None, parameters=None, stl_alpha=None, particle_monitor=None, **kwargs)[source]
Bases:
SimulationResultsStore a single CST simulation results.
- Parameters:
- __init__(id, e_acc, time, population, p_rms=None, plotter=None, trim_trailing=False, period=None, parameters=None, stl_alpha=None, particle_monitor=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 astime.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 (CSVimport) 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…stl_path – Path to the
STLfile holding the 3D structure of the system. If given, we automatically load it.stl_alpha (
float|None, default:None) – Transparency for the 3D mesh.particle_monitor (
ParticleMonitor|None, default:None) – Stores all particle monitor data.
- hist(x, bins=200, hist_range=None, plotter=None, filter=None, **kwargs)[source]
Create a histogram.
- Parameters:
x (
Literal['emission_energy','collision_energy','collision_angle']) – Name of the data to plot.bins (
int, default:200) – Number of histogram bins.hist_range (
tuple[float,float] |None, default:None) – Lower and upper value for the histogram.plotter (
Plotter|None, default:None) – Object creating the plots.filter (
Union[Literal['seed','emitted','collision','no collision'],Callable[[Particle],bool],None], default:None) – To plot only some of the particles.
- Return type:
- plot_trajectories(emission_color=None, collision_color=None, lw=7, r=8, plotter=None, filter=None, **kwargs)[source]
Plot trajectories in 3D.
- Parameters:
emission_color (
str|None, default:None) – If provided, the first known position is colored with this color.collision_color (
str|None, default:None) – If provided, the last known position is colored with this color.collision_point – If provided and
collision_coloris notNone, we plot this point instead of the last ofpoints. This is useful when the extrapolated time is large, and actuel collision point may differ significantly from last position points.lw (
int, default:7) – Trajectory line width.r (
int, default:8) – Size of the emission/collision points.plotter (
Plotter|None, default:None) – An object allowing to plot data.filter (
Union[Literal['seed','emitted','collision','no collision'],Callable[[Particle],bool],None], default:None) – To select the particles to be plotted.
- Return type:
- _abc_impl = <_abc._abc_data object at 0x7e2c7019bc40>
- class CSTResultsFactory(*args, plotter=None, freq_ghz=None, e_acc_parameter=('E_acc', 'e_acc', 'accelerating_field'), e_acc_file_mv_m='E_acc in MV per m.txt', p_rms_file=None, stl_path=None, stl_alpha=None, **kwargs)[source]
Bases:
SimulationResultsFactoryDefine an object to easily instantiate
CSTResults.- Parameters:
- _parameters_file = 'Parameters.txt'
- _time_population_file = 'Particle vs. Time.txt'
- __init__(*args, plotter=None, freq_ghz=None, e_acc_parameter=('E_acc', 'e_acc', 'accelerating_field'), e_acc_file_mv_m='E_acc in MV per m.txt', p_rms_file=None, stl_path=None, stl_alpha=None, **kwargs)[source]
Instantiate object.
If necessary, override default
e_accfilename.- Parameters:
plotter (
Plotter|None, default:None) – Object to plot data.freq_ghz (
float|None, default:None) – RF frequency in GHz. Used to compute RF period, which is mandatory for exp growth fitting.e_acc_parameter (
Sequence[str], default:('E_acc', 'e_acc', 'accelerating_field')) – The possible names of the accelerating field inParameters.txt; we try all of them sequentially, and resort to taking it from a file if it was not successful. You can pass in an empty tuple to force the use of the file.e_acc_file_mv_m (
str, default:'E_acc in MV per m.txt') – Name of the file where the value of the accelerating field in \(\mathrm{MV/m}\) is written. This is a fallback, we prefer getting accelerating field from theParameters.txtfile.e_acc_file – Name of the file where the value of the RMS power in W is written. If not provided, we do not load RMS power.
stl_path (
Path|str|None, default:None) – Path to theSTLfile describing the geometry. Used byParticleMonitorto compute emission and collision angles, and realize 3D plots.stl_alpha (
float|None, default:None) – Transparency for the 3D mesh.
- from_simulation_folder(folderpath, delimiter='\\t', folder_particle_monitor=None, load_first_n_particles=None)[source]
Instantiate results from a
mmdd-xxxxxxxfolder.The expected structure is the following:
mmdd-xxxxxxx ├── 'Adimensional e.txt' ├── 'Adimensional h.txt' ├── 'E_acc in MV per m.txt' # Mandatory if E_acc not in :file:`Parameters.txt` ├── Parameters.txt # Mandatory ├── 'ParticleInfo [PIC]' │ ├── 'Emitted Secondaries.txt' │ └── 'Particle vs. Time.txt' # Mandatory ├── 'TD Number of mesh cells.txt' └── 'TD Total solver time.txt'
Non-mandatory files data will be loaded in the
parametersattribute.If you want to load particle monitor data, you must provide
folder_particle_monitorwhere all particle monitors are stored. Typical structure is:folder_particle_monitor ├──'position monitor 1_0.117175810039043.txt' ├──'position monitor 1_0.156234413385391.txt' ├──'position monitor 1_0.19529302418232.txt' ├──'position monitor 1_0.232905015349388.txt' ├──'position monitor 1_0.271963626146317.txt' ├──... └──'position monitor 1_7.81172066926956E-02.txt'
- Parameters:
folderpath (
Path) – Path to ammdd-xxxxxxxfolder, holding the results of a single simulation among a parametric simulation export.delimiter (
str, default:'\\t') – Delimiter between two columns.folder_particle_monitor (
str|Path|None, default:None) – Holds all the particle monitor files.load_first_n_particles (
int|None, default:None) – If provided, we only load theload_first_n_particlesfirst particles. Useful for debugging/speeding up.
- Returns:
results – Instantiated object.
- Return type:
- _abc_impl = <_abc._abc_data object at 0x7e2c7019bf40>
- _pop_e_acc(raw_results, folder)[source]
Pop the value of the accelerating field from
raw_results.First, we try to get it from the
Parameters.txtunder the names listed inself._e_acc_parameter. If was not found, we look into theself._e_acc_file_mv_mfile.
- from_simulation_folders(master_folder, delimiter='\\t')[source]
Load all
mmdd-xxxxxxxfolders inmaster_folder.Note
Loading of
ParticleMonitorfor multiple simulations is currently not supported.- Parameters:
- Return type: