Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
const y1 = Array.from(x, (x) => 0.29 * (A/20 - 0.37) * (x)**2) // Example transformation for the first line
const y2 = Array.from(x, (x) => 0.26 * (A/20 - 0.65)**0.5 * (x)**2) // Example transformation for the second line
source.data = { x, y1, y2 }
""",
""", # noqa: E501
)

te.js_on_change("value", callback)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@
ys2_mirror[i] = ys2[i];
}
source.change.emit();
""",
""", # noqa: E501
)

r0.js_on_change("value", callback)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
const y1 = Array.from(x, (x) => A * (1 - x**2)**B)
const y2 = Array.from(x, (x) => A / (1+B*x**2)**2) // Example transformation for the second line
source.data = { x, y1, y2 }
""",
""", # noqa: E501
)

n0.js_on_change("value", callback)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
source.data['y1'] = y1;
source.data['y2'] = y2;
source.change.emit();
""",
""", # noqa: E501
)

q95.js_on_change("value", callback)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@
ax.set_ylabel("Magnetic field at superconductor (T)")
ax.set_zlabel("$J_{\\text{crit}}$ (kA/mm²)")
ax.set_title(
"Western Superconducting Ltd. Nb\u2083Sn Critical Current Density Surface at Zero Strain"
"Western Superconducting Ltd. Nb\u2083Sn"
" Critical Current Density Surface at Zero Strain"
)
ax.view_init(elev=30, azim=45) # Rotate the plot around the z-axis by 45 degrees
fig.colorbar(surf, shrink=0.5, aspect=10)
Expand All @@ -52,7 +53,8 @@

# Update layout for better visualization
fig_plotly.update_layout(
title="Western Superconducting Ltd. Nb\u2083Sn Critical Current Density Surface at Zero Strain",
title="Western Superconducting Ltd. Nb\u2083Sn"
" Critical Current Density Surface at Zero Strain",
scene={
"xaxis_title": "Temperature of superconductor (K)",
"yaxis_title": "Magnetic field strength at superconductor (T)",
Expand Down
18 changes: 13 additions & 5 deletions examples/introduction.ex.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,27 @@

# %% [markdown]
# <div class="alert alert-block alert-info">
# <b>NOTE</b> We run the examples in a temporary directory so all the inputs are copied there and the outputs contained there before the directory is removed when the example has finished running. This keeps the examples directory tidy and does not permanently modify any data files. The use of temporary directories is not needed for regular use of PROCESS.
# <b>NOTE</b> We run the examples in a temporary directory so all the inputs are copied
# there and the outputs contained there before the directory is removed when the example
# has finished running.
# This keeps the examples directory tidy and does not permanently modify any data files.
# The use of temporary directories is not needed for regular use of PROCESS.
# </div>

# %% [markdown]
# Process can be run from the command line with the `process` command or as a standard python package.
# Using process as a package allows for more complex scripting of a process run for different tasks.
# Process can be run from the command line with the `process` command or as a standard
# python package.
# Using process as a package allows for more complex scripting of a process run for
# different tasks.


# %% [markdown]
# ## Basic run of Process
# Run Process on an input file using the `SingleRun` class. This outputs an `MFILE.DAT` and an `OUT.DAT`.
# Run Process on an input file using the `SingleRun` class.
# This outputs an `MFILE.DAT` and an `OUT.DAT`.
#
# This is equivalent to running `process -i data/large_tokamak_IN.DAT` in the examples folder.
# This is equivalent to running `process -i data/large_tokamak_IN.DAT`
# in the examples folder.

# %%
# %load_ext autoreload
Expand Down
60 changes: 45 additions & 15 deletions examples/optimum_solutions_comparison.ex.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,43 @@
# # Optimum solutions comparison notebook
#
# %% [markdown]
# A Jupyter notebook to demonstrate how changing input parameters changes the optimum solution found by PROCESS.
# A Jupyter notebook to demonstrate how changing input parameters changes the optimum
# solution found by PROCESS.
#
# %% [markdown]
# <div class="alert alert-block alert-info">
# <b>NOTE</b> We run the examples in a temporary directory so all the inputs are copied there and the outputs contained there before the directory is removed when the example has finished running. This keeps the examples directory tidy and does not permanently modify any data files. The use of temporary directories is not needed for regular use of PROCESS.
# <b>NOTE</b> We run the examples in a temporary directory so all the inputs are copied
# there and the outputs contained there before the directory is removed when the example
# has finished running.
# This keeps the examples directory tidy and does not permanently modify any data files.
# The use of temporary directories is not needed for regular use of PROCESS.
# </div>

# %% [markdown]
# This notebook demonstrates how the optimum solution found by `PROCESS` changes as we vary input parameters. We will use the large tokamak example input file to do this. The figure of merit for this example is to minimise the major radius, `rmajor`.
# This notebook demonstrates how the optimum solution found by `PROCESS` changes
# as we vary input parameters.
# We will use the large tokamak example input file to do this.
# The figure of merit for this example is to minimise the major radius, `rmajor`.
#
# We use the functionality from `plot.solutions` and from `plot.summary` to demonstrate this.
# We use the functionality from `plot.solutions` and from `plot.summary`
# to demonstrate this.
#
# These tools plot the solution vectors (i.e. final values of optimisation parameters) for different runs of `PROCESS`. This allows visual comparisons of different solution points.
# These tools plot the solution vectors (i.e. final values of optimisation parameters)
# for different runs of `PROCESS`.
# This allows visual comparisons of different solution points.
#
# It can use different intra-solution optimisation parameter normalisations (e.g. initial value, parameter range) and inter-solution normalisations (e.g. normalise to a certain solution).
# It can use different intra-solution optimisation parameter normalisations
# (e.g. initial value, parameter range)
# and inter-solution normalisations (e.g. normalise to a certain solution).
#
# ### Known Limitations
#
# - The solution vectors (optimisation parameter values at the solution) currently plotted are normalised to the initial point (from the `IN.DAT`) of each solution: each element of the vector is the $x_{final}/x_{initial}$, the `xcmxxx` values in the `MFILE.DAT`. This allows all optimisation parameters to be plotted on the same axis, showing the relative changes from their initial values across multiple solutions.
# - The solution vectors (optimisation parameter values at the solution) currently
# plotted are normalised to the initial point (from the `IN.DAT`) of each solution:
# each element of the vector is the $x_{final}/x_{initial}$,
# the `xcmxxx` values in the `MFILE.DAT`.
# This allows all optimisation parameters to be plotted on the same axis,
# showing the relative changes from their initial values across multiple solutions.
# - Solutions being plotted together must also have the same optimisation parameters.
# - The solutions plotted in this example are fictitious.

Expand Down Expand Up @@ -90,7 +108,9 @@
# %% [markdown]
# # Plot single solution
#
# First we will look at the original large tokamak optimum solution. We will plot its solution, showing optimisation parameters normalised to their initial values.
# First we will look at the original large tokamak optimum solution.
# We will plot its solution, showing optimisation parameters normalised
# to their initial values.

# %%
large_tokamak_mfile = working_dir / "large_tokamak_MFILE.DAT"
Expand All @@ -109,11 +129,15 @@
# %% [markdown]
# # Comparing optimum solutions
#
# Now we will see the effect that varying an input parameter in the large tokamak input file has on the optimum solution found.
# Now we will see the effect that varying an input parameter in the large tokamak input
# file has on the optimum solution found.
#
# Here, the minimum allowable value for net electric power, `p_plant_electric_net_required_mw`, has been changed from 400MW to 200MW, and PROCESS has found a different optimum solution.
# Here, the minimum allowable value for net electric power,
# `p_plant_electric_net_required_mw`, has been changed from 400MW to 200MW,
# and PROCESS has found a different optimum solution.
#
# We can plot the two MFILEs together, showing normalised values of the optimisation parameters at the solution points, as well as the objective function values.
# We can plot the two MFILEs together, showing normalised values of the optimisation
# parameters at the solution points, as well as the objective function values.

# %%
large_tokamak_varied_min_net_electric_mfile = (
Expand Down Expand Up @@ -157,14 +181,19 @@
# %% [markdown]
# To have lower net electric, `PROCESS` has found a solution where:
# - the fusion power has dropped, therefore the neutron wall load has gone down
# - the toroidal field required has slightly dropped, therefore the case stress limits are lower as less current in the coils is needed
# - the toroidal field required has slightly dropped, therefore the case stress limits
# are lower as less current in the coils is needed

# %% [markdown]
# # Other solution comparison plots
#
# There are some other ways that you can compare solutions in `PROCESS`. We will demonstrate these for the same two MFILEs as above, but you can add in more MFILEs if you want.
# There are some other ways that you can compare solutions in `PROCESS`.
# We will demonstrate these for the same two MFILEs as above, but you can add in
# more MFILEs if you want.
#
# Here we refer to the original large tokamak file as `Large tokamak 1`, and the new solution obtained by varying `p_plant_electric_net_required_mw` as `Large tokamak 2`.
# Here we refer to the original large tokamak file as `Large tokamak 1`,
# and the new solution obtained by varying `p_plant_electric_net_required_mw`
# as `Large tokamak 2`.

# %% [markdown]
# ## Plot one solution normalised to another
Expand Down Expand Up @@ -204,7 +233,8 @@
# %% [markdown]
# ## Solutions normalised by range
#
# Use `nitvar` values instead; the solution optimisation parameters are normalised to the range of their upper and lower bounds.
# Use `nitvar` values instead; the solution optimisation parameters are normalised
# to the range of their upper and lower bounds.

# %%
fig6, df6 = plot_mfile_solutions(
Expand Down
13 changes: 9 additions & 4 deletions examples/scan.ex.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,21 @@
#
# ## Scan details
#
# The input file is a scan-enabled version of the large tokamak `IN.DAT`, as found in the `tests` directory. The scan-relevant values are:
# The input file is a scan-enabled version of the large tokamak `IN.DAT`,
# as found in the `tests` directory. The scan-relevant values are:
# ```
# nsweep = 17 * b_tf_inboard_max, maximum peak toroidal field (T) (constraint equation 25)
# nsweep = 17 * b_tf_inboard_max, maximum peak toroidal field (T)
# isweep = 6
# sweep = 10.5, 10.4, 10.3, 10.2, 10.1, 10.0
# ```
#
# - `nsweep`: integer denoting the variable to scan (see `scan_module` for options). Here `17` corresponds to `b_tf_inboard_max` being scanned
# - `nsweep`:
# integer denoting the variable to scan (see `scan_module` for options).
# Here `17` corresponds to `b_tf_inboard_max` being scanned
# - `isweep`: the number of scan points to run
# - `sweep`: array of values for the scanned variable to take; one for each run. Should be of length `isweep`
# - `sweep`:
# array of values for the scanned variable to take; one for each run.
# Should be of length `isweep`

# %% slideshow={"slide_type": "subslide"}
from process.core.repository import get_process_root
Expand Down
25 changes: 18 additions & 7 deletions examples/single_model_evaluation.ex.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@

# %% [markdown]
# # Evaluating a single PROCESS model
# When understanding or investigating an individual model within Process, it can be useful to run the model in isolation and plot some responses. This is done here to investigate the effect of tungsten impurity concentration on radiated power and power incident on the divertor.
# When understanding or investigating an individual model within Process,
# it can be useful to run the model in isolation and plot some responses.
# This is done here to investigate the effect of tungsten impurity concentration
# on radiated power and power incident on the divertor.

# %%
import matplotlib.pyplot as plt
Expand All @@ -33,7 +36,10 @@
print(f"p_plasma_separatrix_mw = {PhysicsData.p_plasma_separatrix_mw}")

# %% [markdown]
# In order to initialise all variables in Process with their values at a given point (design parameter vector), run an evaluation input file (one with no optimisation) to initialise values in all models. The "large tokamak" regression test solution is used here.
# In order to initialise all variables in Process with their values at a given point
# (design parameter vector), run an evaluation input file (one with no optimisation)
# to initialise values in all models.
# The "large tokamak" regression test solution is used here.

# %%
from process.core.repository import get_process_root
Expand All @@ -49,7 +55,8 @@
# Print initial values of interest
def print_values():
print(
f"W frac = {single_run.data.impurity_radiation.f_nd_impurity_electron_array[13]:.3e}"
"W frac = "
f"{single_run.data.impurity_radiation.f_nd_impurity_electron_array[13]:.3e}"
)
print(f"p_plasma_rad_mw = {single_run.data.physics.p_plasma_rad_mw:.3e}")
print(
Expand All @@ -60,18 +67,21 @@ def print_values():
print_values()

# %% [markdown]
# Now try increasing the tungsten impurity fraction to see if there's a change in the divertor power.
# Now try increasing the tungsten impurity fraction to see if there's a change in
# the divertor power.

# %%
single_run.data.impurity_radiation.f_nd_impurity_electron_array[13] = 5.0e-5
single_run.models.physics.run()
print_values()

# %% [markdown]
# With a higher W impurity fraction, the radiated power has increased and the power incident on the divertor has decreased.
# With a higher W impurity fraction, the radiated power has increased and
# the power incident on the divertor has decreased.
#
# ## Parameter study of W impurity
# Now investigate effect of varying W impurity on impurity radiation power, divertor power and constraint 15 (L-H threshold constraint).
# Now investigate effect of varying W impurity on impurity radiation power,
# divertor power and constraint 15 (L-H threshold constraint).

# %%
from process.core.solver.constraints import ConstraintManager
Expand Down Expand Up @@ -142,4 +152,5 @@ def run_impurities(w_imp_fracs):
# %% [markdown]
# The constraint becomes violated for W fraction values $> 6\times10^{-5}$.
#
# This can easily be modified to investigate behaviour of any model in Process in isolation, without running other models or optimising.
# This can easily be modified to investigate behaviour of
# any model in Process in isolation, without running other models or optimising.
47 changes: 34 additions & 13 deletions examples/vary_run_example.ex.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,29 +23,46 @@

# %% [markdown]
# <div class="alert alert-block alert-info">
# <b>NOTE</b> We run the examples in a temporary directory so all the inputs are copied there and the outputs contained there before the directory is removed when the example has finished running. This keeps the examples directory tidy and does not permanently modify any data files. The use of temporary directories is not needed for regular use of PROCESS.
# <b>NOTE</b> We run the examples in a temporary directory so all the inputs are copied
# there and the outputs contained there before the directory is removed when the example
# has finished running.
# This keeps the examples directory tidy and does not permanently modify any data files.
# The use of temporary directories is not needed for regular use of PROCESS.
# </div>

# %% [markdown]
# `VaryRun` is a tool which takes an input file that does not converge and varies the initial values of the
# iteration variables, within a tolerance, to find an initial point that converges, and creates
# a new input file using these values.
# `VaryRun` is a tool which takes an input file that does not converge and varies the
# initial values of the iteration variables, within a tolerance,
# to find an initial point that converges,
# and creates a new input file using these values.
#
# `VaryRun` requires a `.conf` file which specifies certain parameters needed for `VaryRun`.
# In this file, you specify the original input file, the maximum number of iterations to be performed, and a factor within which the iteration variables are changed.
# `VaryRun` requires a `.conf` file which specifies certain parameters needed for
# `VaryRun`.
# In this file, you specify the original input file,
# the maximum number of iterations to be performed,
# and a factor within which the iteration variables are changed.
#
# If `VaryRun` is able to find a new initial point within the maximum number of iterations, you can find this file in the same directory as your initial input file. This new file will now converge when you run `PROCESS`.
# If `VaryRun` is able to find a new initial point within the maximum number of
# iterations,
# you can find this file in the same directory as your initial input file.
# This new file will now converge when you run `PROCESS`.
# `VaryRun` will produce new, numbered sets of files for each iteration it performs.
# %% [markdown]
# # VaryRun setup
#
# VaryRun requires a `.conf` file in order to run. An example `.conf` file is displayed below.
# VaryRun requires a `.conf` file in order to run. An example `.conf` file is
# displayed below.
#
# - `WDIR` specifies the path to the working directory where `PROCESS` is being run, here is is `.` to run in the directory of the `.conf` file, which is in `examples/data`
# - `WDIR` specifies the path to the working directory where `PROCESS` is being run,
# here is is `.` to run in the directory of the `.conf` file,
# which is in `examples/data`
# - `ORIGINAL_IN_DAT` is providing the name of the original input file
# - `NITER` is specifying the maximum number of iterations to perform
# - `SEED` is specifying a random number generator. Here it is set to 5 so the results of running `VaryRun` on the original input file will always be the same
# - `FACTOR` is specifying a factor within which the iteration variables will change. Here it is set to 1.5, so this means the iteration variables can be varied within 50% of their initial values in the original input file
# - `SEED` is specifying a random number generator. Here it is set to 5 so the results of
# running `VaryRun` on the original input file will always be the same
# - `FACTOR` is specifying a factor within which the iteration variables will change.
# Here it is set to 1.5, so this means the iteration variables can be varied within
# 50% of their initial values in the original input file

# %% [markdown]
# ```ini
Expand All @@ -71,7 +88,10 @@
# %% [markdown]
# ## Run `VaryRun`
#
# Run `PROCESS` on an input file using the `VaryRun` class. The initial input file, `large_tokamak_varyrun_IN.DAT` does not converge. `VaryRun` will vary the initial values of the iteration variables to find an initial point that converges, and will create a new input file with these new values.
# Run `PROCESS` on an input file using the `VaryRun` class. The initial input file,
# `large_tokamak_varyrun_IN.DAT` does not converge. `VaryRun` will vary the
# initial values of the iteration variables to find an initial point that converges,
# and will create a new input file with these new values.

# %%
# %load_ext autoreload
Expand Down Expand Up @@ -131,7 +151,8 @@
# %%
import pandas as pd

# Use pandas to display the values of the iteration variables before and after running VaryRun
# Use pandas to display the values of the iteration variables before and after running
# VaryRun
df = pd.DataFrame({
"Iteration variable names": iteration_variable_names,
"Original values": original_iteration_variable_values,
Expand Down
Loading
Loading