The Open FUSION Toolkit 26.6
An open-source framework for fusion and plasma science and engineering
Loading...
Searching...
No Matches
PFile Class Reference

Detailed Description

Interface for Osborne p-file kinetic profiles.

Example usage:

pf = PFile("p123456.01234")
pf.ne # electron density array
pf.te # electron temperature array
pf.psinorm_for("ne") # psinorm grid for ne
"omgeb" in pf # check if profile exists

Public Member Functions

 __contains__ (self, key)
 __getitem__ (self, key)
 __init__ (self, filename)
 Initialize PFile by reading an Osborne p-file from disk.
 __iter__ (self)
 __len__ (self)
 __repr__ (self)
 compute_derivatives (self)
 Recompute d(data)/d(psinorm) for all profiles in place.
 compute_diamagnetic_rotations (self, psi, nI=None, TI=None)
 Compute diamagnetic rotation frequencies from kinetic profiles.
 compute_pressure (self)
 Compute total pressure from density and temperature profiles.
 compute_quasineutrality (self)
 Compute impurity density \(n_{z1}\) from quasi-neutrality.
 compute_rotation_decomposition (self, R=None, Bp=None, Bt=None, psi=None)
 Compute \(E\times B\) and \(V\times B\) rotation frequencies and derived quantities.
 compute_zeff (self)
 Compute the effective charge profile \(Z_{\mathrm{eff}}\).
 derivative_for (self, key)
 Return the derivative array for profile key.
 describe (self)
 Print a categorised summary of all profiles and derived quantities.
 from_bytes (cls, raw_bytes)
 Construct from in-memory bytes.
 new (cls)
 Create an empty PFile (no profiles loaded from disk).
 psinorm_for (self, key)
 Return the psinorm grid for profile key.
 remap (self, psinorm=None, key="ne")
 Return a new PFile with all profiles on a common grid.
 save (self, filename)
 Write the profiles to filename in p-file format.
 set_ion_species (self, N, Z, A)
 Set the ion species block.
 set_profile (self, key, psinorm, data, derivative=None, units=None)
 Add or replace a profile.
 to_bytes (self)
 Serialise to in-memory bytes (round-trips with from_bytes).
 units_for (self, key)
 Return the units string for profile key.

Public Attributes

 er = None
 Radial electric field \(E_r\) [kV/m].
 ion_species = None
 Ion species dict with 'N', 'Z', 'A' arrays, or None.
 keys = None
 Profile names in file order (list of str).
 kpol = None
 \(K_{\mathrm{POL}} = V_{\mathrm{POL}}/B_p\) [km/s/T]
 nb = None
 Fast ion density \(n_b\) [10 \(^{20}\)/m \(^3\)].
 ne = None
 Electron density \(n_e\) [10 \(^{20}\)/m \(^3\)].
 ni = None
 Ion density \(n_i\) [10 \(^{20}\)/m \(^3\)].
 omeg = None
 Toroidal rotation \(V_{\mathrm{TOR}}/R\) [kRad/s].
 omegp = None
 Poloidal rotation \(B_t V_{\mathrm{POL}}/(R B_p)\) [kRad/s].
 omgeb = None
 \(E\times B\) rotation frequency [kRad/s]
 omghb = None
 Hahm-Burrell \(E\times B\) shearing rate.
 omgpp = None
 Diamagnetic rotation term [kRad/s].
 omgvb = None
 \(V\times B\) rotation term [kRad/s]
 pb = None
 Fast ion pressure \(p_b\) [kPa].
 ptot = None
 Total pressure \(p_{\mathrm{tot}}\) [kPa].
 te = None
 Electron temperature \(T_e\) [keV].
 ti = None
 Ion temperature \(T_i\) [keV].

Protected Member Functions

 _get_data (self, key)
 _zz_doxygen_dummy (self)
 _zz_doxygen_dummy (self)

Protected Attributes

 _raw = _read_pfile(filename)

Constructor & Destructor Documentation

◆ __init__()

__init__ ( self,
filename )

Initialize PFile by reading an Osborne p-file from disk.

Parameters
filenamePath to the p-file

Member Function Documentation

◆ __contains__()

__contains__ ( self,
key )

◆ __getitem__()

__getitem__ ( self,
key )

◆ __iter__()

__iter__ ( self)

◆ __len__()

__len__ ( self)

◆ __repr__()

__repr__ ( self)

◆ _get_data()

_get_data ( self,
key )
protected

◆ _zz_doxygen_dummy() [1/2]

_zz_doxygen_dummy ( self)
protected

◆ _zz_doxygen_dummy() [2/2]

_zz_doxygen_dummy ( self)
protected

◆ compute_derivatives()

compute_derivatives ( self)

Recompute d(data)/d(psinorm) for all profiles in place.

◆ compute_diamagnetic_rotations()

compute_diamagnetic_rotations ( self,
psi,
nI = None,
TI = None )

Compute diamagnetic rotation frequencies from kinetic profiles.

For species \(s\): \(\omega_{\mathrm{dia},s} = \frac{1}{n_s Z_s e}\frac{d(n_s T_s)}{d\psi}\). In p-file units (n in 10 \(^{20}\)/m \(^3\), T in keV, \(\psi\) in Wb) this gives results in kRad/s. Sets omgpp, ommpp, omepp profiles.

Parameters
psiPoloidal flux in SI (Weber), same length as the profile grids
nIImpurity density [10 \(^{20}\)/m \(^3\)]; if None, uses nz1 from the p-file when present, otherwise defaults to zero
TIImpurity temperature [keV]; if None, uses ti

◆ compute_pressure()

compute_pressure ( self)

Compute total pressure from density and temperature profiles.

Uses \(p_{\mathrm{tot}} = c_{NT}\,(n_e T_e + (n_i + n_{z1}) T_i) + p_b\) with \(c_{NT}\) converting from (10 \(^{20}\)/m \(^3\) \(\cdot\) keV) to kPa. Requires ne, te, ni, ti on the same psinorm grid. nz1 and pb default to zero if absent. Stores the result as ptot.

◆ compute_quasineutrality()

compute_quasineutrality ( self)

Compute impurity density \(n_{z1}\) from quasi-neutrality.

\(n_{z1} = (n_e - n_i - n_b) / Z_{\mathrm{imp}}\). Requires ne, ni on the same grid and an "N Z A" block with at least one impurity species. nb defaults to zero if absent. Stores the result as nz1.

◆ compute_rotation_decomposition()

compute_rotation_decomposition ( self,
R = None,
Bp = None,
Bt = None,
psi = None )

Compute \(E\times B\) and \(V\times B\) rotation frequencies and derived quantities.

From the diamagnetic terms (omgpp, ommpp, omepp) and the impurity \(V\times B\) rotation omgvb, computes: omgeb = omgvb + omgpp, ommvb = omgeb - ommpp, omevb = omgeb - omepp. If equilibrium data are provided, also computes er = omgeb * R * Bp and the Hahm-Burrell shearing rate omghb.

Parameters
RMidplane major radius [m] on the profile psinorm grid
BpPoloidal field [T] on the profile psinorm grid
BtToroidal field [T] on the profile psinorm grid
psiPoloidal flux in SI (Weber)

◆ compute_zeff()

compute_zeff ( self)

Compute the effective charge profile \(Z_{\mathrm{eff}}\).

\(Z_{\mathrm{eff}} = (n_i Z_{\mathrm{main}}^2 + n_{z1} Z_{\mathrm{imp}}^2 + n_b Z_{\mathrm{beam}}^2)/n_e\). Charge states are read from the "N Z A" block using the OMFIT convention: impurities first, then main ion, beam ion last. Species-count-specific handling:

  • 1 species: treated as the impurity (main = beam = main ion hydrogen, \(Z=1\)).
  • 2 species: impurity + main ion (no separate beam; beam \(n_b\) defaults to zero so its charge state is irrelevant).
  • 3+ species: impurity(ies) first, main ion at [-2], beam at [-1].
Returns
Tuple (psinorm, zeff) of 1-D ndarrays

◆ derivative_for()

derivative_for ( self,
key )

Return the derivative array for profile key.

Parameters
keyProfile name
Returns
1-D ndarray of d(data)/dpsinorm, or None if not present

◆ describe()

describe ( self)

Print a categorised summary of all profiles and derived quantities.

Groups profiles by physics category (kinetic, rotation, impurity, etc.), showing grid length, data range, units, and whether a descriptive label from PFILE_DESCRIPTIONS is known. The ion species block is also printed if present. Access any profile as pf.ne, pf.te, etc. (for common named profiles), or generically via pf['key'] / pf._get_data('key').

◆ from_bytes()

from_bytes ( cls,
raw_bytes )

Construct from in-memory bytes.

Parameters
raw_bytesRaw p-file content
Returns
New PFile instance

◆ new()

new ( cls)

Create an empty PFile (no profiles loaded from disk).

Returns
New empty PFile instance

◆ psinorm_for()

psinorm_for ( self,
key )

Return the psinorm grid for profile key.

Parameters
keyProfile name
Returns
1-D ndarray of psinorm values, or None if not present

◆ remap()

remap ( self,
psinorm = None,
key = "ne" )

Return a new PFile with all profiles on a common grid.

Parameters
psinormTarget grid. If None, use the grid from key. If int, use np.linspace(0, 1, psinorm). If array-like, use as given.
keyProfile whose grid to use when psinorm is None
Returns
New PFile instance with interpolated profiles on the common grid

◆ save()

save ( self,
filename )

Write the profiles to filename in p-file format.

Parameters
filenameOutput path for the p-file

◆ set_ion_species()

set_ion_species ( self,
N,
Z,
A )

Set the ion species block.

Parameters
NAtomic number for each species
ZCharge state for each species
AMass number for each species

◆ set_profile()

set_profile ( self,
key,
psinorm,
data,
derivative = None,
units = None )

Add or replace a profile.

Parameters
keyProfile name (e.g. "ne", "te")
psinormNormalised poloidal flux grid
dataProfile values on psinorm
derivativeDerivative d(data)/d(psinorm); if None, computed via np.gradient
unitsUnit label; if None, looked up from PFILE_UNITS

◆ to_bytes()

to_bytes ( self)

Serialise to in-memory bytes (round-trips with from_bytes).

Returns
Raw p-file content as bytes

◆ units_for()

units_for ( self,
key )

Return the units string for profile key.

Parameters
keyProfile name
Returns
Units string, or None if the key is not a profile

Member Data Documentation

◆ _raw

_raw = _read_pfile(filename)
protected

◆ er

er = None

Radial electric field \(E_r\) [kV/m].

◆ ion_species

ion_species = None

Ion species dict with 'N', 'Z', 'A' arrays, or None.

◆ keys

keys = None

Profile names in file order (list of str).

◆ kpol

kpol = None

\(K_{\mathrm{POL}} = V_{\mathrm{POL}}/B_p\) [km/s/T]

◆ nb

nb = None

Fast ion density \(n_b\) [10 \(^{20}\)/m \(^3\)].

◆ ne

ne = None

Electron density \(n_e\) [10 \(^{20}\)/m \(^3\)].

◆ ni

ni = None

Ion density \(n_i\) [10 \(^{20}\)/m \(^3\)].

◆ omeg

omeg = None

Toroidal rotation \(V_{\mathrm{TOR}}/R\) [kRad/s].

◆ omegp

omegp = None

Poloidal rotation \(B_t V_{\mathrm{POL}}/(R B_p)\) [kRad/s].

◆ omgeb

omgeb = None

\(E\times B\) rotation frequency [kRad/s]

◆ omghb

omghb = None

Hahm-Burrell \(E\times B\) shearing rate.

◆ omgpp

omgpp = None

Diamagnetic rotation term [kRad/s].

◆ omgvb

omgvb = None

\(V\times B\) rotation term [kRad/s]

◆ pb

pb = None

Fast ion pressure \(p_b\) [kPa].

◆ ptot

ptot = None

Total pressure \(p_{\mathrm{tot}}\) [kPa].

◆ te

te = None

Electron temperature \(T_e\) [keV].

◆ ti

ti = None

Ion temperature \(T_i\) [keV].


The documentation for this class was generated from the following file: