Skip to content
Open
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
2 changes: 1 addition & 1 deletion documentation/source/cost-models/cost-models.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Two cost models are available, determined by the switch `cost_model`.

## 1990 cost model (`cost_model = 0`)

This combines methods[^1] used in the TETRA code [^2] and the Generomak[^3] scheme. The costs are split into accounting categories[^4]. The best references for the algorithms used are[^5], and source file `costs.f90` in the code itself. The majority of the costed items have a unit cost associated with them. These values scale with (for example) power output, volume, component mass etc., and many are available to be changed via the input file. All costs and their algorithms correspond to 1990 dollars.
This combines methods[^1] used in the TETRA code [^2] and the Generomak[^3] scheme. The costs are split into accounting categories[^4]. The best references for the algorithms used are[^5], and source file `costs.py` in the code itself. The majority of the costed items have a unit cost associated with them. These values scale with (for example) power output, volume, component mass etc., and many are available to be changed via the input file. All costs and their algorithms correspond to 1990 dollars.

The unit costs of the components of the fusion power core are relevant to "first-of-a-kind" items. That is to say, the items are assumed to be relatively expensive to build as they are effectively prototypes and specialised tools and machines have perhaps been made specially to create them. However, if a "production line" has been set up, and R & D progress has allowed more experience to be gained in constructing the power core components, the cost will be reduced as a result. Variable `fkind` may be used to multiply the raw unit costs of the fusion power core items (by a factor less than one) to simulate this cost reduction for an *N<sup>th</sup>*-of-a-kind device. In other systems studies of fusion power plants[^6], values for this multiplier have ranged from 0.5 to 0.8.

Expand Down
72 changes: 39 additions & 33 deletions documentation/source/development/add-vars.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,39 +5,28 @@ optimisation figure of merit and constraints to the `PROCESS` code.

**At all times the [`PROCESS` style guide](../development/standards.md) must be used.**

!!! note

As the code is quickly converging towards a wholly Python codebase the respective files may change in type from `.f90` to `.py`.

-----------------

## Add an input

To add a `PROCESS` input, please follow below:

1. Choose the most relevant module `XX` and add the variable in the `XX_variables` defined in `XX_variables.f90`.
1. Choose the most relevant module `XX` and add the variable in the `XX_variables` defined in `XX_variables.py`.

2. Add a description of the input variable below the declaration, using the FORD formatting described in the standards section specifying the units.
3. Specify a sensible default value in the `init_XX_variables()` function within the corresponding model `.py` main file
2. Add a description of the input variable below the declaration, using the formatting described in the standards section specifying the units.

3. Assign a sensible default initial value, and a type.

4. Add the parameter to the `INPUT_VARIABLES` dictionary in `input.py`.

Here is an example of the code to add:


Variable definition example in `tfcoil_variables.f90`:
```fortran
real(dp) :: rho_tf_joints
!! TF joints surfacic resistivity [ohm.m]
!! Feldmetal joints assumed.
```

Variable initialization example in `tf_coil.py`:
Variable definition and initial value setting example in `tfcoil_variables.py`:
```python
def init_tfcoil_variables():
...
tfv.rho_tf_joints = 2.5e-10
e_tf_coil_magnetic_stored: float = 0.0
"""Stored magnetic energy in a single TF coil (J)"""
```

Code example in the `input.py` file:
Expand All @@ -55,10 +44,10 @@ Code example in the `input.py` file:
To add a `PROCESS` iteration variable please follow the steps below, in addition to the instructions for adding an input variable:


1. The parameter `ipnvars` in module `numerics` of `numerics.f90` will normally be greater than the actual number of iteration variables, and does not need to be changed.
1. The parameter `ipnvars` in module `numerics` of `numerics.py` will normally be greater than the actual number of iteration variables, and does not need to be changed.
2. Append a new iteration number key to the end of the `ITERATION_VARIABLES` dictionary in `iteration_variables.py`. The associated variable is the corresponding key value.
3. Set the variable origin file and then the associated lower and upper bounds
4. Update the `lablxc` description in `numerics.f90`.
4. Update the `lablxc` description in `numerics.py`.

It should be noted that iteration variables must not be reset elsewhere in the
code. That is, they may only be assigned new values when originally
Expand Down Expand Up @@ -115,28 +104,45 @@ After following the instruction to add an input variable, you can make the varia


`nsweep` comment example:
```fortran
```python
nsweep: int = None
"""Switch denoting quantity to scan:<UL>
<LI> 1 aspect
<LI> 2 pflux_div_heat_load_max_mw
<LI> 3 p_plant_electric_net_required_mw
<LI> 4 hfact
```

integer :: nsweep = 1
!! nsweep /1/ : switch denoting quantity to scan:<UL>
!! <LI> 1 aspect
!! <LI> 2 pflux_div_heat_load_max_mw
...
!! <LI> 54 GL_nbti upper critical field at 0 Kelvin
!! <LI> 55 `dr_shld_inboard` : Inboard neutron shield thickness </UL>
`nsweep_dict` example in `scans.py`
```python
nsweep_dict = {
1: "aspect",
2: "pflux_div_heat_load_max_mw",
3: "p_plant_electric_net_mw",
4: "hfact",
...
}
```

`SCAN_VARIABLES` case example:

`ScanVariables` case example:

```python
class ScanVariables(Enum):
aspect: ScanVariable("aspect", "Aspect_ratio", 1),
pflux_div_heat_load_max_mw: ScanVariable("pflux_div_heat_load_max_mw", "Div_heat_limit_(MW/m2)", 2),

...
Bc2_0K: ScanVariable("Bc2(0K)", "GL_NbTi Bc2(0K)", 54),
dr_shld_inboard : ScanVariable("dr_shld_inboard", "Inboard neutronic shield", 55),

aspect = ScanVariable("aspect", "Aspect_ratio", 1)
pflux_div_heat_load_max_mw = ScanVariable(
"pflux_div_heat_load_max_mw", "Div_heat_limit_(MW/m2)", 2
)
p_plant_electric_net_required_mw = ScanVariable(
"p_plant_electric_net_required_mw", "Net_electric_power_(MW)", 3
)
```



---------------

## Add a constraint equation
Expand Down
33 changes: 16 additions & 17 deletions documentation/source/development/standards.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ Switches should start with the `i_` prefix in their name, be of integer type and

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`
Refrain from declaring or typing known numerical constants directly in the code. Instead call the value from `constants.py`
If the constants doesn't exist then add it with a source link and uncertainty value.

---------------------
Expand Down Expand Up @@ -524,13 +524,13 @@ Try to keep names to a sensible length while also keeping the name explicit and

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:

```fortran
```python
res_plasma = 1.0
```

Another example would be pulse length

```fortran
```python
time_pulse_length = 7200.0
```

Expand All @@ -540,17 +540,17 @@ time_pulse_length = 7200.0

Inside PROCESS all variables should be in SI units unless otherwise stated. For example:

```fortran
! Fusion power [W]
p_fusion_total = 1000.0d6
```python
p_fusion_total = 1e6
"""Fusion power [W]"""
```

If a variable is not in SI units then its units should be put at the end of of the variable name.
Example:

```fortran
! Fusion power [MW]
p_fusion_total_mw = 1000.0d0
```python
p_fusion_total_mw = 1000.0
"""Fusion power [MW]"""
```

---------------------
Expand All @@ -559,22 +559,21 @@ p_fusion_total_mw = 1000.0d0

Coordinates should be defined as

```fortran
r_plasma_centre = 9.0d0
```python
r_plasma_centre = 9.0

z_plasma_centre = 0.0d0
z_plasma_centre = 0.0

theta_ =
theta_ = ...
```

For dimensions

```fortran
dr_cs =
```python
dr_cs = ...

dz_cs =
dz_cs = ...

dtheta_description =
```

---------------------
Expand Down
2 changes: 1 addition & 1 deletion documentation/source/fusion-devices/stellarator.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ ixc = 169 * Achievable Temperature of the ECRH at the ignition point

## Code specifics

The stellarator model is largely contained within source file `stellarator.f90`.
The stellarator model is largely contained within source file `stellarator.py`.

The model call is in the following order

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,8 @@ There are 4 key functions for calculating the fusion reaction for the plasma. Th
#### Detailed Steps
1. **Initialize Bosch-Hale Constants**: Initializes the Bosch-Hale constants for the required reaction using predefined reaction constants stored in the BoschHaleConstants dataclass.
2. **Calculate Fusion Reaction Rate**: Uses Simpson's rule to integrate the fusion reaction rate over the plasma profile.
3. **Calculate Fusion Power Density**: Compute the fusion power density produced by the given reaction. Using the reaction energy calculated and stored in `constants.f90`. The reactant density is given by $\mathtt{f\_deuterium, f\_tritium}$ or $\mathtt{f\_helium3}$ multiplied by the volume averaged ion density. For the D-D reactions the fusion reaction rate is scaled with the output of [`deuterium_branching()`](#deuterium-branching-fraction--deuterium_branching) to simulate the different branching ratios.
4. **Calculate Specific Fusion Power Densities**: Compute the fusion power density for alpha particles, neutrons and other charged particles, depending on the reaction. Energy branching fractions used are calculated and called from `constants.f90`.
3. **Calculate Fusion Power Density**: Compute the fusion power density produced by the given reaction. Using the reaction energy calculated and stored in `constants.py`. The reactant density is given by $\mathtt{f\_deuterium, f\_tritium}$ or $\mathtt{f\_helium3}$ multiplied by the volume averaged ion density. For the D-D reactions the fusion reaction rate is scaled with the output of [`deuterium_branching()`](#deuterium-branching-fraction--deuterium_branching) to simulate the different branching ratios.
4. **Calculate Specific Fusion Power Densities**: Compute the fusion power density for alpha particles, neutrons and other charged particles, depending on the reaction. Energy branching fractions used are calculated and called from `constants.py`.
5. **Calculate Fusion Rate Densities**: Compute the total fusion rate density and fusion rates just for the alpha particles, neutrons and other charged particles, depending on the reaction.
6. **Update Reaction Power Density**: Updates the object attribute for the specific reaction power density.
7. **Sum Fusion Rates**: Call the [`sum_fusion_rates()`](#sum-the-fusion-rates--sum_fusion_rates) function to add the reaction to the global plasma power balance.
Expand Down
2 changes: 1 addition & 1 deletion documentation/source/solver/solver-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ variable values that maximises or minimises a certain function of them,
known as the figure of merit.

Several possible figures of merit are available, all of which are in the
source file `evaluators.f90`.
source file `evaluators.py`.

Switch `minmax` is used to control which figure of merit is to be used. If the
figure of merit is to be minimised, `minmax` should be **positive**, and if a
Expand Down
3 changes: 1 addition & 2 deletions process/core/caller.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,8 +249,7 @@ def _call_models_once(self, xc: np.ndarray):
"""Call the physics and engineering models.

This method is the principal caller of all the physics and
engineering models. Some are Fortran subroutines within modules, others
will be methods on Python model objects.
engineering models.

Parameters
----------
Expand Down
13 changes: 3 additions & 10 deletions process/core/input.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class InputVariable:
"""A variable to be parsed from the input file."""

module: Any
"""The Fortran module that this variable should be set on."""
"""The module that this variable should be set on."""
type: type
"""The expected type of the variable"""
range: tuple[NumberType, NumberType] | None = None
Expand Down Expand Up @@ -1156,7 +1156,6 @@ def parse_input_file(data_structure_obj: DataStructure):
continue

# matches (variable name, array index, value)
# NOTE: array index is Fortran-based hence starts at 1.
line_match = re.match(
r"([a-zA-Z0-9_]+)(?:\(([0-9]+)\))?[ ]*=[ ]*([ +\-a-zA-Z0-9.,]+).*",
stripped_line,
Expand Down Expand Up @@ -1342,12 +1341,9 @@ def set_scalar_variable(name: str, value: ValidInputTypes, config: InputVariable
"""
current_value = getattr(config.module, name, ...)

# use ... sentinel because None is probably a valid return from Fortran
Comment thread
chris-ashe marked this conversation as resolved.
# and definately will be when moving to a Python data structure
# use ... sentinel because None is a valid initial/default value for variables
if current_value is ...:
error_msg = (
f"Fortran module '{config.module}' does not have a variable '{name}'."
)
error_msg = f"Module '{config.module}' does not have a variable '{name}'."
raise ProcessValueError(error_msg)

setattr(config.module, name, value)
Expand All @@ -1356,9 +1352,6 @@ def set_scalar_variable(name: str, value: ValidInputTypes, config: InputVariable
def set_array_variable(name: str, value: str, array_index: int, config: InputVariable):
"""Set an array variable in the `config.module`.

The way PROCESS input files are structured, each element of the array is provided on one line
so this function just needs to set the `value` at `array_index` (-1) because of Fortran-based indexing.

Parameters
----------
name :
Expand Down
17 changes: 5 additions & 12 deletions process/core/io/data_structure_dicts.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ def publish(self):


class SourceDictionary(Dictionary):
# Dictionary created from Fortran source
def __init__(self, name, dict_creator_func):
Dictionary.__init__(self, name)
# Function that creates the dict
Expand Down Expand Up @@ -221,11 +220,8 @@ def remove_comments(line):

def dict_var_type():
"""Function to return a dictionary mapping variable name to variable type
eg. 'real_variable' or 'int_array'. Looks in input.f90 at the process
functions that read in variables from IN.DAT.

Example of line we are looking for:
call parse_real_variable('BETA', beta, 0.0D0, 1.0D0, &
eg. 'real_variable' or 'int_array'. Iterates over INPUT_VARIABLES to build
the mapping using the type and array properties of each variable config.

Example dictionary entry:
DICT_VAR_TYPE['beta'] = 'real_variable'
Expand All @@ -244,12 +240,9 @@ def dict_var_type():

def dict_input_bounds():
"""Returns a dictionary matching variable names to dictionary containing
upper and lower bounds that PROCESS checks variable lies between when
reading IN.DAT. Looks in input.f90 for parse_real_variable and
parse_int_variable.

Example of a line we are looking for:
call parse_real_variable('BETA', beta, 0.0D0, 1.0D0, &
upper and lower bounds. Bounds are derived from the INPUT_VARIABLES config
objects, using either the explicit range property or min/max of choices
for numeric types.

Example dictionary entry:
DICT_INPUT_BOUNDS['beta'] = {'lb' : 0.0, 'ub' : 1.0}
Expand Down
Loading
Loading