gbspy.utils module
This file contains useful functions to process the magnetic equilibrium and the grid.
- gbspy.utils.Ask_time(Ttime, ask_msg='', first_indx_time=0, give_default=0)
Ask for a specific time -> Default value is given in function of ‘give_default’ value, . give_default = 0 : no default value . give_default = 1 : first time by default . give_default = 2 : last time by default
- gbspy.utils.compute_psi_der(data)
Compute the derivatives of Psi
It is used only in old versions of GBS. This routine expects that the simulation has a loaded magnetic equilibrium flux function. The simulation object is modified in place (the input parameter is modified directly).
- Parameters
data (gbspy.pp.Sim) – Simulation object
- gbspy.utils.compute_source(gbssim)
Compute the density and temperature source
- Parameters
gbssim (gbspy.pp.Sim) – Simulation object
- Returns
Sn (np.ndarray) – A two dimensional array containing the density source in a poloidal plane.
St (np.ndarray) – A two dimensional array containing the temperature source in a poloidal plane.
- gbspy.utils.find_crash(sim, plane='yz', fields=['vpare', 'temperature'], z1=None, z2=None, t1=None)
Find nan or max and min values for fields and plot fields around the nan or min of last field
- Parameters
sim (simulation) –
plane ('xy', 'yz' or 'xz') –
fields (list of name of fields) –
t1 (time slice to check) –
- gbspy.utils.get_attribute_time(sim, which_attribute, t1=None, t2=None)
Read the attributes which_attribute in the results files between t1 and t2,
- Parameters
object (sim = Sim) –
list (which_attribute = str or) – name or list of names for the attributes
:param : name or list of names for the attributes
- Returns
attributes values for each time
- Return type
attrs = dict,
- gbspy.utils.get_lastslice_results(file_in)
- gbspy.utils.intersection(x1, y1, x2, y2)
- gbspy.utils.load_mag_field(data, filename=None)
Load magnetic field from the disk
This function attempts to identify which magnetic equilibrium was used in the simulation from the simulation’s attributes. It matches this set of parameters against one of the configurations shipped with gbspy and loads it in the simulation object. Note that the magnetic field is loaded in place (the input parameter is modified directly).
- Parameters
data (gbspy.pp.Sim) – Simulation object from which to identify the magnetic equilibrium.
filename (str, optional) – Name of the file that contains the desired equilibrium. This file should be packaged within the
"Equilibria"
directory of gbspy, for example"TCV.txt"
. IfNone
, an attempt will be made to guess which magnetic field to load automatically.
- gbspy.utils.make_init_data(x, y, gridp, profp)
- gbspy.utils.print_changed_attributes(sim, t1=None, t2=None)
Inspect simulation attributes and show when they change
This routine inspects a given simulation object and compares the attributes stored in each result file to monitor if they change. Each time an attribute is changed, a summary is printed.
- Parameters
sim (gbspy.pp.Sim) – The simulation object from which the attributes should be inspected.
t1 (float, optional) – Time at which to start monitoring changes. Default: the first time available.
t2 (float, optional) – Time at which to stop monitoring changes. Default: the last time available.
- gbspy.utils.restart_from_data(dir_out, basic_val, data_val, dset_in, attrs_root=None)
Create restart from input data
- Parameters
str (dir_out =) – output directory path
:param : output directory path :param basic_val = dict: all the values from the “Basic” group of a restart file :param : all the values from the “Basic” group of a restart file :param data_val = dict: all the values from the “data” group of a restart file :param : all the values from the “data” group of a restart file :param dset_in = dict: all the data sets as stored in a restart file,
use get_lastlice_results to get it from a results file
- :paramall the data sets as stored in a restart file,
use get_lastlice_results to get it from a results file
- Parameters
dict (attrs_root =) – attributes of the new restart file
optional – attributes of the new restart file
- gbspy.utils.restart_from_results(name_in, dir_out, dset_in=None)
Create restart getting info from results file and values from dset_in or from the last slice in results file name_in. NB: nz, nx, ny are taken from dset_in, with 2 ghost cells for x and y
- Parameters
str (name_in =) – name of the input results file
:param : name of the input results file :param dir_out = str: output directory path :param : output directory path :param dset_in = dict: all the data sets as stored in a results file
see function get_lastslice_results for an example
- Parameters
optional – all the data sets as stored in a results file see function get_lastslice_results for an example
- gbspy.utils.restart_from_scratch(dir_out, gridp, plasma_in)
Create restart from scratch and values as generated by make_init_data
- Parameters
str (dir_out =) – output directory path
:param : output directory path :param gridp = dict: description of the plasma grid
- keys {“nx”,”ny”,”nz”,”xmin”,
“xmax”,”ymin”,”ymax”}
- :paramdescription of the plasma grid
- keys {“nx”,”ny”,”nz”,”xmin”,
“xmax”,”ymin”,”ymax”}
- Parameters
dict (plasma_in =) –
parameters in a GBS input file keys {“lambda”,”miome”,”beta”,”initback_theta”,
”initback_tempe”,”initback_tempi”,”initback_omega”, “initback_vpare”,”initback_vpari”,”initback_psi”}
- :paramparameters in a GBS input file
- keys {“lambda”,”miome”,”beta”,”initback_theta”,
“initback_tempe”,”initback_tempi”,”initback_omega”, “initback_vpare”,”initback_vpari”,”initback_psi”}
- gbspy.utils.search_pos(x_value, x_array)
Search index position
- gbspy.utils.str2num(datum)
Convert string to interger or float
- gbspy.utils.vprofile(x, y, xmin, xmax, ymin, ymax)
- gbspy.utils.write_attrs(file, attributes)
- gbspy.utils.write_in_dset(file, dname, data)
- gbspy.utils.write_in_groups(file, group, data)