PROCESS uses ruff to enforce code formatting and detect common code mistakes/smells. Unless there is a justifiable reason, the ruff linter should not be ignored or overridden.
You can check if your code meets the ruff standards by running:
ruff checkandruff format(the later may modify your source code, this is completely safe)pre-commit run --all-files
!!! Info "ruff automatic fixes"
Many problems that ruff can detect it can also safely fix. Simply run ruff check --fix and it will try and automatically fix the mistakes, rewritting your source code.
!!! quote "The Zen of Python"
*“Explicit is better than implicit.”*
*"Readability counts."*
Use a lowercase word or words. Separate words by underscores(_) to improve readability.
Switches should start with the i_ prefix in their name, be of integer type and should be indexed from 0.
Use an uppercase single letter, word, or words. Separate words with underscores to improve readability.
Refrain from declaring or typing known numerical constants directly in the code. Instead call the value from constants.f90
If the constants doesn't exist then add it with a source link and uncertainty value.
!!! note
Variable names are slowly being converted to their new verbose form as development progresses. Therefore you may come across variables that do not match the style mentioned below.
Use a lowercase single letter, word, or words. Separate words with underscores to improve readability.
If converting between units it may be required to have some capital letters at the end of the variable name to differentiate between different orders of magnitude, m and M etc.
The agreed upon style is to name the variables by the following scheme:
Having the units at the end of the name is only necessary when the variable is not in SI/standard units.
For example, a variable can look like:
Which represents:
So for above; a is the data type representing area, tf is the system representing the TF coils and wp is the secondary description or system. This variable thus represents the cross-sectional area of the TF coil winding pack.
It may also be useful to use several data type prefixes to greater greater clarity.
For example, a variable can look like:
In system designation it means this:
This means the variable represents the fraction of the TF coil area taken up by the winding pack.
!!! note "Naming conventions with limit variables"
For naming variables which represent either upper or lower limits the words `_max` and `_min` should be used in the variable name. Though if a variable represents the highest of a measured value then the variable name should use the word `_peak`.
Below are a few shorthand designations for different systems that should be used in variable names
- Toroidal field coils:
_tf_ - Poloidal field coils:
_pf_ - Vacuum Vessel:
_vv_ - First wall:
_fw_ - Divertor:
_div_ - Blanket:
_blkt_ - Shield:
_shld_ - Central Solenoid:
_cs_ - Heating & Current Drive:
_hcd_- Electron cyclotron current drive:
_eccd_ - Ion cyclotron current drive:
_iccd_ - Electron Bernstein Wave:
_ebw_ - Neutral Beam:
_nb_
- Electron cyclotron current drive:
- Centre post:
_cp_Should only be used for ST's - Vacuum pumping systems:
_vac_ - The fusion power plant as a whole:
_plant_
If the variables are physics variables and do not belong to a system then:
var = <physics variable>_<description>
The data types of different variables can be seen below:
-
Radial positions should start with the
r_prefix -
Radial thicknesses should start with the
dr_prefix -
Vertical positions should start with the
z_prefix -
Vertical thicknesses should start with the
dz_prefix
- Integer countable items should start with the
n_prefix
Example, the total number of TF coils: n_tf_coils
- Number density items should start with the
nd_prefix
- Areas should start with the
a_prefix
Example, the area of the TF winding pack: a_tf_wp
- Volumes should start with the
vol_prefix
- Lengths should start with the
len_prefix
- Radii should start with the
radius_prefix
- Diameters should start with the
dia_prefix
- Circumferences should start with the
circ_prefix
- Velocities should start with the
vel_prefix
- Masses should start with the
m_prefix
- Molecule flow rates should start with the
molflow_prefix
This should be used for units of
This unit is normally used for fuelling or vacuum pumping models
- Volume flow rates should start with the
volflow_prefix
This should be used for units of
This unit is normally used for fuelling or vacuum pumping models
- Outgassing rates should start with the
outgrat_prefix
This should be used for units of
This is normally used for vacuum systems and outgassing from its surfaces.
- Mass flow rates should start with the
mflow_prefix
This should be used for units of
- Mass fluxes should start with the
mflux_prefix
This should be used for units of
- Reynolds numbers should start with the
reynolds_prefix
- Darcy Friction Factors for fluid flow numbers should start with the
darcy_frict_prefix
- Pressures should start with the
pres_prefix - Pressure changes or drops should start with the
dpres_prefix
- Densities should start with the
den_prefix
- Voltages should start with the
v_prefix
- Resistances should start with the
res_prefix
- Impedances should start with the
imp_prefix
- Resistivity variables should start with the
rho_prefix
- Residual resistance ratios should start with the
rrr_prefix
- Currents should start with the
c_prefix
- Inductances should start with the
ind_prefix
- Electric charges should start with the
charge_prefix
- Electric charge numbers should start with the
n_charge_prefix.
- Current densities should start with the
j_prefix
- Powers should start with the
p_prefix
- Power densities should start with the
pden_prefix
- Power fluxes should start with the
pflux_prefix
- Energies should start with the
e_prefix
- Fluences should start with the
flu_prefix
- Temperatures should start with the
temp_prefix
- Times should start with the
t_prefix - Time intervals should start with the
dt_prefix
- Magnetic field strengths should start with the
b_prefix
-
Magnetic fluxes can start with the
web_prefix representing Webers. -
Since magnetic flux units are more commonly used in inductive current drive it may be more appropriate to use the
vs_prefix instead representing a$\text{Vs}$ .
- Frequencies should start with the
freq_
- Angles should start with the
deg_orrad_depending on the units used
- Solid angles should start with the
ster_prefix. Short for steradians.
- Lifetimes of components should start with the
life_prefix.
The default units for lifetimes is in years.
The unit declaration _fpy can be used to specify that it is the full-power year lifetime.
- Viscosities should start with the
visc_prefix.
- Stresses should start with the
stress_prefix followed by the type of stress, for examplestress_shear_. Normal stresses are assumed in thestress_only case.
-
Strains due to normal stresses should start with the
strain_prefix. -
Strains due to shear stresses should start with the
strain_shear_prefix.
- The Young's modulus of materials should start with the
youngmod_prefix.
- Poisons ratios for material under stress should start with the
f_poisson_
- Forces should start with the
forc_prefix.
- Torques should start with the
torq_prefix
Absolute current drive efficiencies (eta_cd prefix.
Normalized current drive efficiecnies using major radius and volume averaged electron temperature start with the eta_cd_norm prefix
The above is concurrent with that of general efficiencies given below.
- Fusion rates should start with the
fusrat_prefix.
This should be used for units of reactions per second.
- Fusion rate densities should start with the
fusden_prefix.
This should be used for units of reactions per cubic metre, per second (
If a variable is intended to demonstrate a fraction of a value or distribution etc. Then it should start with the f_ prefix.
Similar to this is variables representing efficiencies.
If a variable is intended to represent an engineering efficiency then it should start with the eta_ prefix to represent
Variables used within constraint equations to scale iteration variables (f-values) should start with the f prefix without an underscore before the next word.
Try to keep names to a sensible length while also keeping the name explicit and descriptive.
The physical type of the variable should form the first part of the variable name, e.g. for plasma resistance the variable should be named:
res_plasma = 1.0Another example would be pulse length
time_pulse_length = 7200.0Inside PROCESS all variables should be in SI units unless otherwise stated. For example:
! Fusion power [W]
p_fusion_total = 1000.0d6If a variable is not in SI units then its units should be put at the end of of the variable name. Example:
! Fusion power [MW]
p_fusion_total_mw = 1000.0d0Coordinates should be defined as
r_plasma_centre = 9.0d0
z_plasma_centre = 0.0d0
theta_ = For dimensions
dr_cs =
dz_cs =
dtheta_description =Loop variables that use I, j etc. should use
ii
jj
kk
mm| Variable name | Description | Units |
|---|---|---|
c_plasma |
Plasma current | A |
c_plasma_MA |
Plasma current | MA |
b_t_onaxis |
Toroidal field on-axis | T |
b_t_max |
Max toroidal field | T |
nd_electron_vol |
Volume average electron density | m-3 |
temp_electron_vol_eV |
Volume avgerage electron temperature | eV |
m_steel |
Mass of steel | kg |
m_steel_tonne |
Mass of steel | tonne |
e_neutron_eV |
Energy of neutron | eV |
e_neutron_MeV |
Energy of neutron | MeV |
v_tf_dump |
TF dump voltage | V |
t_plant_life |
Plant lifetime | s |
t_plant_life_yrs |
Plant lifetime | years |
dr_tf_inboard_leg |
TF coil inboard leg radial thickness | m |
dr_blanket_inboard |
Inboard blanket thickness | m |
vel_coolant |
TF centrepost coolant velocity | m/s |
vol_plasma |
Plasma volume | m3 |
a_plasma |
Plasma area | m2 |
rad_div_target |
Divertor target angle | radians |
deg_div_target |
Divertor target angle | deg |
s_shear_tf |
TF shear stress | Pa |
| `` |
Please see issue #940 to discuss new conventions.
It is greatly encouraged and recommended to include type hints for all inputs and outputs in Python. Please follow the guidelines set out in PEP-484.
The docstring style is that of the Sphinx type. Though there are some additions for Notes and References in order to give mathematical reasoning and sources to some functions.
If writing in new Python functions please use the docstring template below.
def function_name(param1, param2):
"""
Brief description of what the function does.
Detailed description of the function. This can include information about the algorithm,
any important notes, and other relevant details.
:param type param1: Description of the first parameter.
:param type param2: Description of the second parameter.
:returns: Description of the return value.
:rtype: return_type
:raises ExceptionType: Description of the exception raised (if any).
:notes:
- Additional notes about the function.
- Any important considerations or caveats.
:references:
- Reference 1: Description of the reference.
- Reference 2: Description of the reference.
"""If writing in new Python classes please use the docstring template below.
class ExampleClass:
"""
Brief description of the class.
Detailed description of the class. This can include information about the purpose
of the class, how it should be used, and any other relevant details.
Attributes:
attribute1 (type): Description of attribute1.
attribute2 (type): Description of attribute2.
attribute3 (type): Description of attribute3.
Methods:
method1(param1, param2): Description of method1.
method2(param1, param2): Description of method2.
"""
def __init__(self, attribute1, attribute2, attribute3):
"""
Initializes the ExampleClass with the given attributes.
:param type attribute1: Description of attribute1.
:param type attribute2: Description of attribute2.
:param type attribute3: Description of attribute3.
"""
self.attribute1 = attribute1
self.attribute2 = attribute2
self.attribute3 = attribute3-
Comments that contradict the code are worse than no comments
-
Comments should be complete sentences. The first word should be capitalized, unless it is an identifier that begins with a lower case letter.
-
Use inline comments sparingly.
-
Comments above apply to code below.