gbspy.pp module
- class gbspy.pp.Sim(path=None)
Bases:
object
The
Sim
class provides an interface for opening GBS results.Attributes of the simulation (mostly input parameters such as
nu
,dt
, etc.) are loaded in thesim.attribute
dictionnary.- Parameters
path (str, Path or path-like, optional) – Path to be opened as a GBS simulation. Can either be a single results file, or an entire directory containing many results files. If not provided, defaults to the current working directory.
Examples
This loads a simulation by visiting the folder where it is saved:
>>> %cd /path/containing/the/simulation >>> import gbspy >>> sim = gbspy.Sim() >>> sim.attribute['dt'] # show the timestep
- FIELD_LIST = {'SnD2_nD2cxD2': ('$n_{D}\nu_{cx,D_2^+-D}$', ('neutral_density', 'thetaD2', 'vo_cx_D_D2p'), <function Sim.<lambda>>), 'SnD2_nD2cxD2Dp': ('$n_{D_2}\nu_{cx,D_2-D^+}$', ('thetaD', 'neutralD2_density', 'vo_cx_D2Dp'), <function Sim.<lambda>>), 'SnD2_nD2pdiD2p': ('$n_{D_2^+}\nu_{di,D_2^+}$', ('theta', 'thetaD2', 'vo_di_D2p'), <function Sim.<lambda>>), 'Sne_iztot': ('$S_{iz,tot}$', ('ionsource', 'Sne_nnD2izD2', 'Sne_nD2pdiizD2p'), <function Sim.<lambda>>), 'Sne_nD2diizD2': ('$n_{D_2}\nu_{di-iz,D_2}$', ('theta', 'neutralD2_density', 'vo_di_iz_D2'), <function Sim.<lambda>>), 'Sne_nD2pdiizD2p': ('$n_{D_2^+}\nu_{di-iz,D_2^+}$', ('theta', 'thetaD2', 'vo_di_iz_D2p'), <function Sim.<lambda>>), 'Sne_nD2pdirecD2p': ('$n_{D_2^+}\nu_{di-rec,D_2^+}$', ('theta', 'thetaD2', 'vo_di_rec_D2p'), <function Sim.<lambda>>), 'Sne_nD2precD2p': ('$n_{D_2^+}\nu_{rec,D_2^+}$', ('theta', 'thetaD2', 'vo_rec_D2'), <function Sim.<lambda>>), 'Sne_nDprecDp': ('$n_{D^+}\nu_{rec,D^+}$', ('theta', 'thetaD', 'vo_rec'), <function Sim.<lambda>>), 'Sne_nnD2izD2': ('$n_{D_2}\nu_{iz,D_2}$', ('theta', 'neutralD2_density', 'vo_iz_D2'), <function Sim.<lambda>>), 'Sne_rectot': ('$S_{rec,tot}$', ('Sne_nDprecDp', 'Sne_nD2pdirecD2p'), <function Sim.<lambda>>), 'TD2': ('$ T_{D_2^+}$', ('tempD2',), <function Sim.<lambda>>), 'Te': ('$T_e$', ('temperature',), <function Sim.<lambda>>), 'Ti': ('$T_i$', ('temperaturi',), <function Sim.<lambda>>), 'gammaD2': ('$ \\Gamma_{D_2^+}$', ('thetaD2', 'vparD2'), <function Sim.<lambda>>), 'gammae': ('$ \\Gamma_{e}$', ('theta', 'vpare'), <function Sim.<lambda>>), 'gammai': ('$ \\Gamma_{i}$', ('theta', 'vpari'), <function Sim.<lambda>>), 'ionsource': ('$S_{iz}$', ('theta', 'neutral_density', 'vo_iz'), <function Sim.<lambda>>), 'n': ('$n$', ('theta',), <function Sim.<lambda>>), 'nD': ('$ n_{D^+}$', ('thetaD',), <function Sim.<lambda>>), 'nD2': ('$ n_{D_2^+}$', ('thetaD2',), <function Sim.<lambda>>), 'neutralD2_density': ('$n_{D_2}$', None, None), 'neutralD2_flux_R': ('$\\Gamma_{D_2,R}$', None, None), 'neutralD2_flux_Z': ('$\\Gamma_{D_2,Z}$', None, None), 'neutralD2_temperature': ('$T_{D_2}$', None, None), 'neutralD2_velocity': ('$v_{\\parallel D_2}$', None, None), 'neutral_density': ('$n_n$', None, None), 'neutral_flux_R': ('$\\Gamma_{n,R}$', None, None), 'neutral_flux_Z': ('$\\Gamma_{n,Z}$', None, None), 'neutral_flux_phi': ('$\\Gamma_{n,\\phi}$', None, None), 'neutral_temperature': ('$T_n$', None, None), 'neutral_velocity': ('$v_{\\parallel n}$', None, None), 'omega': ('$\\omega$', None, None), 'pD2': ('$p_{D_2^+}$', ('thetaD2', 'tempD2'), <function Sim.<lambda>>), 'pe': ('$p_e$', ('theta', 'temperature'), <function Sim.<lambda>>), 'pi': ('$p_i$', ('theta', 'temperaturi'), <function Sim.<lambda>>), 'pressurD2': ('$log(p_{D_2^+})$', ('thetaD2', 'tempD2'), <function Sim.<lambda>>), 'psi': ('$\\psi$', None, None), 'strmf': ('$\\phi$', None, None), 'tempD2': ('$\\log(T_{D_2^+})$', None, None), 'temperature': ('$\\log(T_e)$', None, None), 'temperaturi': ('$\\log(T_i)$', None, None), 'theta': ('$\\log(n)$', None, None), 'thetaD': ('$\\log(n_{D^+})$', None, None), 'thetaD2': ('$\\log(n_{D_2^+})$', None, None), 'vo_cx': ('$vo_{cx}$', None, None), 'vo_cx_D2': ('$vo_{cx,D_2}$', None, None), 'vo_cx_D2_Dp': ('$vo_{cx,D_2-D^+}$', None, None), 'vo_cx_D_D2p': ('$vo_{cx,D-D_2^+}$', None, None), 'vo_di_D2': ('$vo_{diss,D_2}$', None, None), 'vo_di_D2p': ('$vo_{diss,D_2^+}$', None, None), 'vo_di_iz_D2': ('$vo_{diss-iz,D_2}$', None, None), 'vo_di_iz_D2p': ('$vo_{diss-iz,D_2^+}$', None, None), 'vo_di_rec_D2p': ('$vo_{diss-rec,D_2^+}$', None, None), 'vo_en': ('$vo_{en}$', None, None), 'vo_en_D2': ('$vo_{en,D_2}$', None, None), 'vo_iz': ('$vo_{iz}$', None, None), 'vo_iz_D2': ('$vo_{iz,D_2}$', None, None), 'vo_rec': ('$vo_{rec}$', None, None), 'vo_rec_D2': ('$vo_{rec,D_2^+}$', None, None), 'vparD2': ('$v_{\\parallel D_2}$', None, None), 'vpare': ('$v_{\\parallel e}$', None, None), 'vpari': ('$v_{\\parallel i}$', None, None)}
- static add_field_id(name, latex='', loaded=None, func=None, overwrite=False)
Defines a loadable field from GBS.
- Parameters
name (str) – Keyword for the new field. Should be unique and not already defined unless
overwrite=True
.latex (str, optional) – LaTeX representation of the new field.
loaded (tuple of str, optional) – Tuple containing the GBS field names (datasets in the HDF5 results) required to compute the quantity.
func (callable, optional) – Function processing the loaded quantities.
overwrite (bool, optional) – If
True
, existing field names will be overwritten.
Examples
The following line could be used to add the electron pressure to the field list (it is already defined in the toolbox)
>>> Sim.add_field_id('pe', '$p_e$', ('theta', 'temperature',), ... lambda n, T: np.exp(n*T))
- find_ind(val, quant)
Find the index of a value in quant
- get_field(which_field, x1=None, x2=None, y1=None, y2=None, z1=None, z2=None, t1=None, t2=None)
Returns the requested simulation field as 4D array
- Parameters
which_field (str) – String identifying the field to load
x1 (float, optional) – The range of values to select in the radial direction. By default, all available points are loaded.
x2 (float, optional) – The range of values to select in the radial direction. By default, all available points are loaded.
y1 (float, optional) – The range of values to select in the vertical direction. By default, all available points are loaded.
y2 (float, optional) – The range of values to select in the vertical direction. By default, all available points are loaded.
z1 (float, optional) – The range of values to select in the toroidal direction. By default, all available points are loaded.
z2 (float, optional) – The range of values to select in the toroidal direction. By default, all available points are loaded.
- static get_field_id(key, what='latex')
Fetches information about a certain field name in GBS.
For example, calling
Sim.get_field_id('n', 'latex')
returns the string"$n$"
.
- load_equilibrium()
Loads the simulation’s magnetic equilibrium
Read the magnetic equilibrium from the result files into the simulation object. Note the most recent magnetic configuration is read. This method will not handle equilibria that vary from one restart to another. This function will replace
gbspy.utils.load_mag_field()
.