Skip to content

Commit b5a9745

Browse files
committed
Update documentation for constraints to remove f-values
1 parent 4741c15 commit b5a9745

5 files changed

Lines changed: 50 additions & 51 deletions

File tree

documentation/source/development/add-vars.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -142,13 +142,13 @@ After following the instruction to add an input variable, you can make the varia
142142

143143
## Add a constraint equation
144144

145-
Constraint equations are added to *PROCESS* in the `process/constraints.py` file. They are registered with the `ConstraintManager` whenever the application is run. Each equation has a unique name that is currently an integer, however upgrades to the input file format in the future will allow arbitrary hashable constraint names.
145+
Constraint equations are added to *PROCESS* in the `process/core/optimisation/constraints.py` file. They are registered with the `ConstraintManager` whenever the application is run. Each equation has a unique name that is currently an integer, however upgrades to the input file format in the future will allow arbitrary hashable constraint names.
146146

147147
A constraint is simply added by registering the constraint to the manager using a decorator.
148148

149149
```python
150150
@ConstraintManager.register_constraint(1234, "m", "=")
151-
def my_constraint_function(): ...
151+
def my_constraint_function(constraint_registration): ...
152152
```
153153
The arguments to the `register_constraint` function are:
154154

@@ -161,13 +161,13 @@ The arguments to the `register_constraint` function are:
161161

162162
- Normalised residual error
163163
- Constraint value
164-
- Constraint error
164+
- Constraint bound
165+
- Constraint residual
166+
167+
The recommended way to do this is using one of the functions `geq`, `leq`, or `eq` depending on whether the constraint is desired to be $v\geq b$, $v\leq b$, or $v=b$, respectively.
165168

166169
```python
167170
@ConstraintManager.register_constraint(1234, "m", "=")
168-
def my_constraint_function():
169-
normalised_residual = ...
170-
value = ...
171-
error = ...
172-
return ConstraintResult(normalised_residual, value, error)
171+
def my_constraint_function(constraint_registration):
172+
return geq(value, bound, constraint_registration)
173173
```

documentation/source/io/input-guide.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ If no input file name is given as the first argument to the code, it assumes an
3232
## Constraints
3333

3434
PROCESS permits a large number of constraint equations, all of which are formulated
35-
in the source file `constraint equations.f90`.
35+
in the source file `process/core/optimisation/constraints.py`.
3636

3737
In the input file constraint equations are specified as in the following example:
3838

documentation/source/solver/solver-guide.md

Lines changed: 37 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,40 @@
33

44
Any computer program naturally contains many equations. The built-in equation
55
solvers within PROCESS act on a special class, known as constraint equations,
6-
all of which are formulated in the source file `constraint equations.f90`. These
6+
all of which are formulated in the source file `process/core/optimisation/constraints.py`. These
77
can be split into two types:
88

9-
**Equality constraints (consistency equations)** -- that enforce consistency between the physics and
10-
engineering parameters in the various models
9+
**Equality constraints (consistency equations)** that enforce consistency between the physics and
10+
engineering parameters in the various models.
1111

12-
**Inequality constraints (limit equations)** -- that enforce various parameters to lie within their allowed
13-
limits. The `neqns` constraint equations that the user chooses for a given run are
14-
activated by including the equation numbers in the first `neqns` elements of
15-
array `icc`.
12+
**Inequality constraints (limit equations)** that enforce a value be greater/less than or equal to some bound (limit).
13+
14+
A PROCESS input file will, for example, define which constraint equations are being used as follows:
15+
16+
```
17+
...
18+
neqns = 3
19+
20+
* Equalities
21+
icc = 1 * Beta
22+
icc = 2 * Global power balance
23+
icc = 11 * Radial build
24+
25+
* Inequalities
26+
icc = 9 * Fusion power upper limit
27+
icc = 5 * Density upper limit
28+
icc = 24 * Beta upper limit
29+
icc = 15 * LH power threshold limit
30+
...
31+
```
32+
33+
Here each `icc=n` statement tells PROCESS to activate a constraint with the name `n`. A list of the constraints and
34+
their corresponding names can be found [here](../../source/reference/process/data_structure/numerics/#process.data_structure.numerics.lablcc).
35+
36+
The `neqns = 3` statement is telling PROCESS to treat the first `3` equations as equality constraints, and the rest as inequality constraints. Therefore, it is imperative that all equality constraints are stated before any inequality constraints.
37+
38+
39+
In both types of equations, an optimiser/solver uses the normalised residuals $c_i$ of the constraints (and sometimes its gradient, depending on the solver/optimiser) to guide the solution towards one that satisfies all of the constraints.
1640

1741
## Consistency Equations
1842

@@ -30,59 +54,34 @@ $$
3054
c_i = 1 - \frac{g}{h}
3155
$$
3256

33-
The equation solvers VMCON and HYBRD need the constraint equations $c_i$ to be given in
34-
the form shown, since they adjust the iteration variables so as to obtain $c_i = 0$,
35-
thereby ensuring that $g = h$.
57+
The optimiser/solver will attempt to find a solution that produces $c_i = 0$ for all equality constraints.
3658

3759
## Limit Equations
3860

3961
The limit equations are inequalities that ensure that various physics or engineering
4062
limits are not exceeded.
4163

42-
The f-values are used as follows. In general, limit equations have the form
43-
44-
$$
45-
\mathrm{calculated\ quantity} = f \times \mathrm{maximum\ allowable\ value}
46-
$$
47-
48-
where $f$ is the `f-value`. In optimisation mode, all iteration variables have prescribed
49-
lower and upper bounds. If $f$ is chosen to be an iteration variable and is given a
50-
lower bound of zero and an upper bound of one, then the limit equation does indeed
51-
constrain the calculated quantity to lie between zero and its maximum allowable value,
52-
as required.
53-
5464
As with the consistency equations, the general form of the limit equations is
5565

5666
$$
57-
c_i = 1 - f.\frac{h_{max}}{h}
67+
c_i = 1 - \frac{h_{max}}{h}
5868
$$
5969

60-
where $h_{max}$ is the maximum allowed value of the quantity $h$. Sometimes, the limit
61-
equation and `f-value` are used to ensure that quantity $h$ is larger than its minimum
62-
value $h_{min}$. In this case, $0 ≤ f ≤ 1$ (as before), but the equation takes the form
70+
where $h_{max}$ is the maximum allowed value of the quantity $h$, or
6371

6472
$$
6573
c_i = 1 - f.\frac{h}{h_{min}}
6674
$$
6775

68-
By fixing the `f-value` (i.e. not including it in the `ixc` array), the limit equations
69-
can be used as equality constraints.
76+
where $h_{min}$ is the minimum allowed value of the quantity $h$.
7077

7178
For example, to set the net electric power to a certain value, the following
7279
should be carried out:
7380

7481
1. Activate `constraint 16` (net electric power lower limit) by including it in the `icc` array
7582
2. Set `p_plant_electric_net_required_mw` to the required net electric power.
7683

77-
Limit equations are not restricted to optimisation mode. In non-optimisation mode, the iteration
78-
variables are not bounded, but the `f-values` can still be used to provide information about
79-
how calculated values compare with limiting values, without having to change the characteristics
80-
of the device being benchmarked to find a solution.
81-
82-
It is for this reason that all the constraint equations used in PROCESS are formulated as equalities,
83-
despite the fact that equation solver VMCON can solve for inequalities as well. The use of `f-values`
84-
precludes this need, and allows the non-optimising equation solver HYBRD to use the same constraint
85-
equations.
84+
The optimiser/solver will attempt to find a solution that produces $c_i \geq 0$ for all inequality constraints.
8685

8786
## Iteration Variables
8887

@@ -111,7 +110,7 @@ Switch `ioptimz` should be set to 1 for optimisation mode.
111110

112111
If `ioptimz = 0`, a non-optimisation pass is performed first. Occasionally this provides a feasible set of initial conditions that aids convergence of the optimiser, but it is recommended to use `ioptimz = 1`.
113112

114-
Enable all the relevant consistency equations, and it is advisable to enable the corresponding iterations variables. A number of limit equations (inequality constraints) can also be activated. For limit equations, the corresponding f-value must be selected as an iteration variable. In optimisation more, the number of iteration variables is unlimited.
113+
Enable all the relevant consistency equations, and it is advisable to enable the corresponding iterations variables. A number of limit equations (inequality constraints) can also be activated. In optimisation more, the number of iteration variables is unlimited.
115114

116115
It may still be difficult, if not impossible, to reconcile the fusion power and the net electric power with the required values. This may well be due to the power conversion efficiency values being used.
117116

process/scan.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ def _missing_(cls, var):
7676
"f_c_plasma_bootstrap_max", "Bootstrap_fraction", 12
7777
)
7878
boundu10 = ScanVariable("boundu(10)", "H_factor_upper_bound", 13)
79-
fiooic = ScanVariable("fiooic", "TFC_Iop_/_Icrit_f-value", 14)
79+
fiooic = ScanVariable("fiooic", "TFC_Iop_/_Icrit_margin", 14)
8080
rmajor = ScanVariable("rmajor", "Plasma_major_radius_(m)", 16)
8181
b_tf_inboard_max = ScanVariable("b_tf_inboard_max", "Max_toroidal_field_(T)", 17)
8282
eta_cd_norm_hcd_primary_max = ScanVariable(

tests/regression/input_files/low_aspect_ratio_DEMO.IN.DAT

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ nd_plasma_electrons_vol_avg = 6.88360041658364314e+19
186186
*ixc = 9
187187
fdene = 1.2
188188
*boundu(9) = 1.2
189-
* DESCRIPTION: f-value for density limit (used to set max greenwald fraction)
189+
* DESCRIPTION: margin for density limit (used to set max greenwald fraction)
190190
* JUSTIFICATION: Used with icc=5 to enforce density limit
191191

192192
*ixc = 11 * pheat
@@ -242,7 +242,7 @@ f_c_plasma_non_inductive = 4.92677875380845121e-01
242242
* JUSTIFICATION: We have a pulsed reactor so this can vary
243243

244244
fiooic = 1.0
245-
* DESCRIPTION: f-value for TF coil operating current / critical current density ratio
245+
* DESCRIPTION: margin for TF coil operating current / critical current density ratio
246246
* JUSTIFICATION: Constraint equation 33 is used
247247

248248
ixc = 56 * tdmptf
@@ -282,7 +282,7 @@ dr_shld_vv_gap_inboard = 0.02
282282
f_h_mode_margin = 1.1
283283
*boundl(103) = 1.1
284284
*boundu(103) = 1.2
285-
* DESCRIPTION: f-value for L-H Power Threshold (now used to set lower bound)
285+
* DESCRIPTION: margin for L-H Power Threshold (now used to set lower bound)
286286
* JUSTIFICATION: Used with icc=15 to enforce H-mode
287287

288288
ixc = 109

0 commit comments

Comments
 (0)