Skip to content

Commit

Permalink
Merge branch 'main' into 3385-update-the-plasma-composition-docs-to-i…
Browse files Browse the repository at this point in the history
…nclude-all-new-models
  • Loading branch information
chris-ashe committed Jan 8, 2025
2 parents 8f67f44 + 661027a commit 4619fa2
Show file tree
Hide file tree
Showing 176 changed files with 8,091 additions and 8,133 deletions.
15 changes: 0 additions & 15 deletions .flake8

This file was deleted.

12 changes: 5 additions & 7 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,12 @@ repos:
- id: check-docstring-first
- id: check-merge-conflict
- id: debug-statements
- repo: https://github.com/psf/black
rev: 22.3.0
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.8.0
hooks:
- id: black
- repo: https://github.com/PyCQA/flake8
rev: 4.0.1
hooks:
- id: flake8
- id: ruff
args: [--fix]
- id: ruff-format
- repo: https://github.com/jumanjihouse/pre-commit-hook-yamlfmt
rev: 0.2.3
hooks:
Expand Down
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ LIST(APPEND PROCESS_SRCS
stellarator_variables.f90
stellarator.f90
stellarator_configuration.f90
input.f90
)

PREPROCESS()
Expand Down
16 changes: 7 additions & 9 deletions documentation/proc-pages/development/ci-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,11 @@ Our GitHub actions Continuous Integration (CI) pipeline serves to ensure each br

| Name | Functionality |
| ---- | ------------- |
| docker | Checks if the `process-ci` Docker container is up-to-date and builds it if not. Only runs on the **main** branch. |
| make-py38 | Builds and archives the PROCESS build artefacts |
| unit-py38 | Installs PROCESS and runs the unit tests. The job will fail if any of the unit tests fail. |
| integration-py38 | Installs PROCESS and runs the integration tests. The job will fail if any of the integration tests fail. |
| regression-py38 | Installs PROCESS and runs the regression tests with a 0% and 5% tolerance, respectively. The job will fail if any of the regression tests fail. |
| large-tokamak-py38 | Installs PROCESS and runs the `large-tokamak` input file, archiving the output MFILE. Only runs on the **main** branch. |
| flake8 | Runs the flake8 Python linter and fails if any lint errors occur. |
| black | Runs the black Python formatter and fails if any formatting issues are detected. |
| tracking | Collects MFILEs for input files of interest and creates a dashboard of changes in key values over time (one datapoint for each commit on main). |
| make | Builds and archives the PROCESS build artefacts |
| unit-test | Installs PROCESS and runs the unit tests. The job will fail if any of the unit tests fail. |
| integration-test | Installs PROCESS and runs the integration tests. The job will fail if any of the integration tests fail. |
| regression-test | Installs PROCESS and runs the regression tests with a 0% and 5% tolerance, respectively. The job will fail if any of the regression tests fail. |
| run-tracking-inputs | Installs PROCESS and runs the regression test input files, archiving the output MFILEs. Only runs on the **main** branch. |
| tracking | Collects MFILEs for input files of interest and creates a dashboard of changes in key values over time (one datapoint for each commit on main). Only runs on the **main** branch. |
| pre-commit-quality-check | ensures the pushed code meets our standards as defined in `.pre-commit-config.yaml`. |
| docs | Builds and deploys the documentation onto GitHub pages. |
67 changes: 21 additions & 46 deletions documentation/proc-pages/development/pre-commit.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ the commit will not be made. On a failure, one of two things can happen:
1. Pre-commit plugins will rectify the mistakes made. This will happen with code formatters
(whose job it is to edit your files to the correct style). The files the plugins have changed
can then be `git add`ed again and the `git commit` command re-issued.
2. A pre-commit plugin will identify the mistake but will NOT fix it. This will happen with
`flake8` which is a linter and warns of code mistakes but does not correct them. You will need
2. A pre-commit plugin will identify the mistake but will NOT fix it. This could happen with
`ruff` which is a linter and warns of code mistakes but does not correct them. You will need
to fix these mistakes manually. Now, the changed files can be `git add`ed and the `git commit` command re-issued.

!!! Info "VSCode GUI users"
Expand Down Expand Up @@ -58,63 +58,44 @@ fixed and you will need to re-add the files that pre-commit has changed.

!!! example "Adding two files"
Consider that two files are being `git add`ed.
One of the files, `foo.py` has stylistic changes which **Black** objects to.
One of the files, `foo.py` has stylistic changes which **ruff** objects to.

```
> git add foo.py bar.py
> git commit -m "Adding foo and bar"
Trim Trailing Whitespace.................................................Passed
Check for merge conflicts................................................Passed
Debug Statements (Python)................................................Passed
black....................................................................Failed
- hook id: black
ruff.....................................................................Failed
- hook id: ruff-format
- exit code: 1
- files were modified by this hook

Fixing foo.py
Format YAML files....................................(no files to check)Skipped

> git add foo.py # since black has modified foo.py
> git add foo.py # since ruff has modified foo.py
> git commit -m "Adding foo and bar"
```

To avoid the need to re-add files a second time you could run `black .` which will do the
formatting (of Python code) that pre-commit would do.

!!! example "black won't fix all flake8 issues"
Flake8 (as has been stressed on this documentation) is a linter and not a formatter. This means
flake8 will never make any changes to your Python source code.

Consider the following file very simple file, `example.py`:

```python
from process.fortran import tfcoil_variables, fwbs_variables

def get_whttf():
return tfcoil_variables.whttf
```

Flake8 will return the following trace for this file:
```
example.py:1:47 F401 Module fwbs_variables imported but never used
```
because `fwbs_variables` is imported, but never used. However, this is not a style issue, it is
a semantic issue. Therefore, `black` will not fix this issue. It is up to the developer to
rectify this issue manually, `git add` the fixed file, and finally re-do the `git commit` command.

## Pre-commit and the `quality` CI stage
The Process continuous integration system (used to check Process builds and passes tests) also has
a `quality` stage. This is where several jobs will run to ensure the quality of your code. If all
your commits pass through pre-commit, then these jobs should not fail as your code will be of a high quality.

## Using black with VSCode
Although not required, the `black` VSCode extension will ensure that all the Python files you save
will be black-compliant and, as such, won't need to modified by pre-commit.

In VSCode, use `Ctrl+,` (`Command+,` for Mac users) to open the settings page. From here, use the
search bar to find **"Editor: Format On Save"** and tick the box. Next, search for
**"Python > Formatting: Provider"** and set it to `black`. Now, upon saving a Python file, the
black formatter will run over it.
## Using ruff with VSCode
Although not required, the `ruff` VSCode extension will ensure that all the Python files you save
will be ruff-compliant and, as such, won't need to modified by pre-commit.

Open or create the file `.vscode/settings.sh` and add/modify the following settings:
```json
{
"[python]": {
"editor.defaultFormatter": "charliermarsh.ruff",
"editor.formatOnSave": true
}
}
```

## What does pre-commit check for?

Expand All @@ -131,13 +112,7 @@ Pre-commit performs a few checks on each and every file you add, regardless of t

Because Process is becoming increasingly Pythonised, pre-commit performs many Python style checks.

* [`black`](https://black.readthedocs.io/en/stable/) has already been discussed on this page. It is
an industry-standard Python code formatter that enforces a "one-way is right" style. This ensures
all of our Python is of the same, black-correct, style. **This plugin will automatically fix any mistakes it finds**.
* [`flake8`](https://flake8.pycqa.org/en/latest/) is the linter of choice on Process. A linter
checks common errors in code. Flake8, for instance, can check for `import` statements that are
unused or variables that are declared but never used. Black, a formatter, will not remove these
"mistakes" as it will never change the semantic meaning of code. **This plugin will NOT automatically fix any mistakes it finds**.
* [`ruff`](https://github.com/astral-sh/ruff) formats and lints code. It will identify formatting and stylistic errors in Python code. **This plugin will automatically fix any mistakes it finds**.
* `check-docstring-first` will check that a function/class docstring comes before any of the body
(ie the docstring must be at the top). **This plugin will NOT automatically fix any mistakes it finds**.
* `debug-statements` will check that debug statements (those using the built-in `pdb` module)
Expand All @@ -146,4 +121,4 @@ Because Process is becoming increasingly Pythonised, pre-commit performs many Py
### Other checks

* [`yamlfmt`](https://github.com/jumanjihouse/pre-commit-hook-yamlfmt) formats YAML code (similar
to what `black` does for Python code). **This plugin will automatically fix any mistakes it finds**.
to what `ruff` does for Python code). **This plugin will automatically fix any mistakes it finds**.
8 changes: 4 additions & 4 deletions documentation/proc-pages/physics-models/error.txt
Original file line number Diff line number Diff line change
Expand Up @@ -994,18 +994,18 @@ is derived directly from the energy confinement scaling law.
\texttt{iradloss\ =\ 0} -- Total power lost is scaling power plus
radiation

\texttt{pscaling\ +\ pradpv\ =\ f_alpha_plasma*alpha_power_density\ +\ charged_power_density\ +\ pohmpv\ +\ pinjmw/plasma_volume}
\texttt{pscaling\ +\ pradpv\ =\ f_alpha_plasma*alpha_power_density\ +\ charged_power_density\ +\ pden_plasma_ohmic_mw\ +\ pinjmw/plasma_volume}

\texttt{iradloss\ =\ 1} -- Total power lost is scaling power plus core
radiation only

\texttt{pscaling\ +\ pcoreradpv\ =\ f_alpha_plasma*alpha_power_density\ +\ charged_power_density\ +\ pohmpv\ +\ pinjmw/plasma_volume}
\texttt{pscaling\ +\ pcoreradpv\ =\ f_alpha_plasma*alpha_power_density\ +\ charged_power_density\ +\ pden_plasma_ohmic_mw\ +\ pinjmw/plasma_volume}

\texttt{iradloss\ =\ 2} -- Total power lost is scaling power only, with
no additional allowance for radiation. This is not recommended for power
plant models.

\texttt{pscaling\ =\ f_alpha_plasma*alpha_power_density\ +\ charged_power_density\ +\ pohmpv\ +\ pinjmw/plasma_volume}
\texttt{pscaling\ =\ f_alpha_plasma*alpha_power_density\ +\ charged_power_density\ +\ pden_plasma_ohmic_mw\ +\ pinjmw/plasma_volume}

\subsection{Plasma Core Power Balance}\label{plasma-core-power-balance}

Expand Down Expand Up @@ -1365,7 +1365,7 @@ Effects}\label{neo-classical-correction-effects}

Switch \texttt{ires} controls whether neo-classical (trapped particle)
effects are included in the calculation of the plasma resistance and
ohmic heating power in routine \texttt{pohm}, which is called by routine
ohmic heating power in routine \texttt{plasma_ohmic_heating}, which is called by routine
\texttt{physics}. If \texttt{ires\ =\ 1}, these effects are included.
Note that the scaling used is only valid for aspect ratios between 2.5
and 4, and it is possible for the plasma resistance to be wrongly
Expand Down
6 changes: 3 additions & 3 deletions documentation/proc-pages/physics-models/plasma_confinement.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,17 +78,17 @@ derived directly from the energy confinement scaling law.

`iradloss = 0` -- Total power lost is scaling power plus radiation:

`pscaling + pradpv = f_alpha_plasma*alpha_power_density_total + charged_power_density + pohmpv + pinjmw/plasma_volume`
`pscaling + pradpv = f_alpha_plasma*alpha_power_density_total + charged_power_density + pden_plasma_ohmic_mw + pinjmw/plasma_volume`


`iradloss = 1` -- Total power lost is scaling power plus radiation from a region defined as the "core":

`pscaling + pcoreradpv = f_alpha_plasma*alpha_power_density_total + charged_power_density + pohmpv + pinjmw/plasma_volume`
`pscaling + pcoreradpv = f_alpha_plasma*alpha_power_density_total + charged_power_density + pden_plasma_ohmic_mw + pinjmw/plasma_volume`

`iradloss = 2` -- Total power lost is scaling power only, with no additional
allowance for radiation. This is not recommended for power plant models.

`pscaling = f_alpha_plasma*alpha_power_density_total + charged_power_density + pohmpv + pinjmw/plasma_volume`
`pscaling = f_alpha_plasma*alpha_power_density_total + charged_power_density + pden_plasma_ohmic_mw + pinjmw/plasma_volume`

## L-H Power Threshold Scalings

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Resistive Plasma Heating

The ohmic component of the plasma heating is given by that from the ITER 1989 Physics Design Guidelines[^1]

Using the resistive loop voltage for a reference profile of parabolic shape with:

$$
\alpha_n \approx 0.5, \alpha_T \approx 1.0, \alpha_J \approx 1.5
$$


$$
\Omega_{\text{plasma}} \approx 2.15 \times 10^{-3} Z_{\text{eff}}\langle \gamma_{\text{NC}} \rangle \frac{R_0}{\kappa a^2} \frac{1}{T_{10}^{1.5}}
$$

The neoclassical (avergae) resisitivity enhancement factor $\left(\langle \gamma_{\text{NC}} \rangle \right)$ is given by an empirical fit:

$$
\langle \gamma_{\text{NC}} \rangle = 4.3 -0.6A
$$

where $A$ is valid in the range of 2.5 - 4.0.


[^1]: N.A. Uckan and ITER Physics Group, 'ITER Physics Design Guidelines: 1989',
2 changes: 1 addition & 1 deletion documentation/proc-pages/physics-models/plasma_overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ More detail is given in [^1], but this webpage is more up to date.

Neo-classical trapped particle effects are
included in the calculation of the plasma resistance and ohmic heating power in
subroutine `pohm`, which is called by routine `physics`. The scaling used is only valid for aspect
subroutine `plasma_ohmic_heating()`, which is called by routine `physics`. The scaling used is only valid for aspect
ratios between 2.5 and 4, and it is possible for the plasma resistance to be
incorrect or even negative if the aspect ratio is outside this range. An error is reported if the
calculated plasma resistance is negative.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import numpy as np
import matplotlib.pyplot as plt
import numpy as np

plt.style.use("ggplot")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
from bokeh.models import ColumnDataSource
from bokeh.plotting import figure, output_file, save


x = np.linspace(1.0, 5, 500)
y = 3.12 + 3.5 * (1 / x) ** 1.7
source = ColumnDataSource(data=dict(x=x, y=y))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
from bokeh.models import ColumnDataSource
from bokeh.plotting import figure, output_file, save


x = np.linspace(1.0, 5, 500)
y = 2.7 * (1 + 5 * (1 / x) ** 3.5)
source = ColumnDataSource(data=dict(x=x, y=y))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from bokeh.models import ColumnDataSource, CustomJS, Slider
from bokeh.plotting import figure, output_file, save


x = np.linspace(0, 1, 500)
y = 5.0 * (1 - x**2) ** 2.0

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from bokeh.models import ColumnDataSource, CustomJS, Slider
from bokeh.plotting import figure, output_file, save


T0 = Slider(start=0.1, end=10, value=10.0, step=0.1, title="Plasma centre value | T0")
alpha = Slider(
start=0.01, end=10, value=2.0, step=0.01, title="Profile Index | alphan"
Expand Down
8 changes: 4 additions & 4 deletions documentation/proc-pages/scripts/sort_vardes.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
"""
Script to tidy up vardes.md for the GitLab Page
Script to tidy up vardes.md for the GitLab Page
J. Morris
10/08/19
UKAEA
J. Morris
10/08/19
UKAEA
"""

Expand Down
1 change: 1 addition & 0 deletions examples/csv_output.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
],
"source": [
"from pathlib import Path\n",
"\n",
"from process.io import mfile_to_csv\n",
"\n",
"# Project directory for example result file and default .json list;\n",
Expand Down
8 changes: 4 additions & 4 deletions examples/data/csv_output_large_tokamak_MFILE.DAT
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@
Fraction_of_power_incident_on_the_lower_outer_target____________________ (fLO)_________________________ 5.9000E-01 OP
Power_incident_on_the_lower_inner_target_(MW)___________________________ (pLImw)_______________________ 1.2724E+01 OP
Power_incident_on_the_lower_outer_target_(MW)___________________________ (pLOmw)_______________________ 1.8311E+01 OP
Ohmic_heating_power_(MW)________________________________________________ (pohmmw)______________________ 6.6172E-01 OP
Ohmic_heating_power_(MW)________________________________________________ (p_plasma_ohmic_mw)______________________ 6.6172E-01 OP
Fraction_of_alpha_power_deposited_in_plasma_____________________________ (falpha)______________________ 9.5000E-01
Fraction_of_alpha_power_to_electrons____________________________________ (falpe)_______________________ 7.2139E-01
Fraction_of_alpha_power_to_ions_________________________________________ (falpi)_______________________ 2.7861E-01
Expand Down Expand Up @@ -522,7 +522,7 @@
Diamagnetic_fraction_(enforced)_________________________________________ (diaipf.)_____________________ 0.0000E+00
Pfirsch-Schlueter_fraction_(enforced)___________________________________ (ps_current_fraction.)______________________ 0.0000E+00
Loop_voltage_during_burn_(V)____________________________________________ (vburn)_______________________ 3.9627E-02 OP
Plasma_resistance_(ohm)_________________________________________________ (rplas)_______________________ 4.0562E-09 OP
Plasma_resistance_(ohm)_________________________________________________ (res_plasma)_______________________ 4.0562E-09 OP
Resistive_diffusion_time_(s)____________________________________________ (res_time)____________________ 3.0010E+03 OP
Plasma_inductance_(H)___________________________________________________ (rlp)_________________________ 1.3992E-05 OP
Coefficient_for_sawtooth_effects_on_burn_V-s_requirement________________ (csawth)______________________ 1.0000E+00
Expand Down Expand Up @@ -1141,13 +1141,13 @@
Total_(MW)______________________________________________________________ ______________________________ 3.7935E+02
Alpha_power_deposited_in_plasma_(MW)____________________________________ (falpha*palpmw)_______________ 3.0224E+02
Power_from_charged_products_of_DD_and/or_D-He3_fusion_(MW)______________ (pchargemw.)__________________ 1.2322E+00
Ohmic_heating_(MW)______________________________________________________ (pohmmw.)_____________________ 6.6172E-01
Ohmic_heating_(MW)______________________________________________________ (p_plasma_ohmic_mw.)_____________________ 6.6172E-01
Injected_power_deposited_in_plasma_(MW)_________________________________ (pinjmw)______________________ 7.5213E+01
Total_(MW)______________________________________________________________ ______________________________ 3.7935E+02
Fusion_power_(MW)_______________________________________________________ (powfmw)______________________ 1.5926E+03
Power_from_energy_multiplication_in_blanket_and_shield_(MW)_____________ (emultmw)_____________________ 3.0312E+02
Injected_power_(MW)_____________________________________________________ (pinjmw.)_____________________ 7.5213E+01
Ohmic_power_(MW)________________________________________________________ (pohmmw.)_____________________ 6.6172E-01
Ohmic_power_(MW)________________________________________________________ (p_plasma_ohmic_mw.)_____________________ 6.6172E-01
Power_deposited_in_primary_coolant_by_pump_(MW)_________________________ (htpmw_mech)__________________ 1.6306E+02
Total_(MW)______________________________________________________________ ______________________________ 2.1347E+03
Heat_extracted_from_first_wall_and_blanket_(MW)_________________________ (pthermfw_blkt)_______________ 1.8043E+03
Expand Down
Loading

0 comments on commit 4619fa2

Please sign in to comment.