# Optimization

The goal of the Axisymetric optimization is to provide an maximum magnetic field at the center of the insert under constraints:

• total electric power

• maximal allowed temperature per helix

• maximal allowed stress per helix

for a given insert geometry.

The unknowns may either be:

• the current density distribution per helix: `OptHelix`,

• the maximum temperature distribution per helix: `OptAubert`

``OptAubert HL-31.dat``
 Each helix is splitted in a given number of sections $S_i$ along $z$ axis. The result of the optimization is the vector stem[{j_i}] (aka the current density $j_i$ value on the inner radius of all sections $S_i$) for `optaubert`. The stress in each section is approximated by the Hoop stress, namely $r j_{\theta}(r) \cdot b_z(r)$ for $r=r_i$ with $r_i$ the inner radius of section $S_i$.
 Both codes relies on SQP programming with `Nag`. For licensing issue, they can only be ran on `calcul10` server.

The input file corresponds to the header section of the `.d` magnet description file. The output is a `.d` file.

To build the actual 3D geometry, that shall reflect, this axisymetrical current density distribution, we use the following assumption:

• the nominal current is $I_o$,

• each element $S_i$ will be represented by an helix with a pitch $p$ and a number of turn $n$ such that the helix carries the same current as the element:

$n * I_o = \int_{S_i} \mathbf{j} \cdot \mathbf{n} \,d\Gamma$

The optimization result are then used to define the helical cut thet would be machined in each copper alloy tubes:

• CAD data may be obtained for Catia and/or Salome using:

``````opt2cad HL-31.d , (1)
opt2yml HL-31.d , (3)``````
 1 `opt2cad` generates files for CAD/CAM Helices 2 `addshape` generates files for CAD/CAM Helices with "bumps" on the helical cut shape path; this is optional. 3 `opt2yml` generates configuration files for building Helices with HiFiMagnet Salome plugin.
 To create the actual 3D CAD model of an helix (abusively: tube in which an helical cut has been machined by EDM technic), we still need some more information…​

## 1. Use `OptAubert`

``optaubert HL-31.dat``

Available options to control the optimization are:

``````--majorprint=INT                specify nag major print level (default is 10)
--minorprint=INT                specify nag major print level (default is 0)
--major_iteration_limit=INT     specify nag major iterations_limit (default is controlled by nag)
--minor_iteration_limit=INT     specify nag minor iterations_limit (default is controlled by nag)
--tolerance=DOUBLE              specify Optimaly tolerance (default is 1.0e-15)
--function_precision=DOUBLE     specify Function precision (default is 4.38e-15)
--feasibility=DOUBLE            specify nonlinear feasibility tolerance (default is 1.0e-15)
--check                         activate nag checks
--random                        initiliaze with random numbers
--init=STRING                   initialize solution from
--verbose                       activate verbose mode
--log                           activate nag logging mode
--recursive                     activate recursive mode``````

Other options are:

``````--gmsh                          activate gmsh output
--num_integ=INT                 specify num_integ size (default 100)
--num_eval=INT                  specify num_eval size (default 100)
--gsl-error-handler             deactivate gsl error handler (default is on)``````

## 2. Use `OptHelix`

``opthelix --stress --temp [--cooling] [--geom] HL-31.dat``

Available options are:

``````--majorprint=INT                specify nag major print level (default is 10)
--minorprint=INT                specify nag major print level (default is 0)
--major_iteration_limit=INT     specify nag major iterations_limit (default is controlled by nag)
--minor_iteration_limit=INT     specify nag minor iterations_limit (default is controlled by nag)
--tolerance=DOUBLE              specify Optimaly tolerance (default is 1.0e-15)
--feasibility=DOUBLE            specify nonlinear feasibility tolerance (default is 1.0e-15)
--geom                          activate geometry optimization
--check                         activate nag checks
--temp                          activate temperature constraints
--stress                        activate stress constraints
--random                        initiliaze with random numbers
--gmsh                          activate gmsh output
--init=STRING                   initialize solution from
--verbose                       activate verbose mode
--log                           activate nag logging mode
--recursive                     activate recursive mode
--cooling                       activate cooling modeling
--num_integ=INT                 specify num_integ size (default 100)
--num_eval=INT                  specify num_eval size (default 100)``````

To create files for CAD or CAM use `opt2cad`:

``opt2cad [-o format] HL-31.d``

Valid formats are:

• `LNCMI`: default value, for creating file for Lncmi CAM

• `CATIA`: for creating files for CATIA

• `SALOME`: for creating files for Salome

To add shapes on some helical cuts, you may use:

``add_shape --angle="60 90 120 120" --shape_angular_length=8 --shape=HL-31-995  --format=LNCMI --position="ALTERNATE" HL-31_H4``

In this example we had shape profile `HL-31-995` at various angles on `HL-31_H4` helical cut.

Definition of profile `HL-31-995`: `Shape_HL-31-995.dat`
``````#Shape : HL-31-995 pour H4
#N_i
20
#X_i F_i
-3.24	0
-3.05	0.04
-2.88	0.15
-2.78	0.31
-2.74	0.5
-2.74	1.3
-2.7	1.49
-2.59	1.65
-2.43	1.76
-2.24	1.8
2.24	1.8
2.43	1.76
2.59	1.65
2.7	1.49
2.74	1.3
2.74	0.5
2.78	0.31
2.88	0.15
3.05	0.04
3.24	0``````

This command will generate 2 files:

• `HL-31_H4_cut_with_shapes.iso`: CAM file for the EDM machining,

• `HL-31_H4_cut_with_shapes.xls`: CAD file for CATIA (the file needs to be converted to a real Excell file with the script `write_excel.py`)

## 4. Prepare Data for HiFiMagnet Salome

``opt2yml HL-31.d``

This command generates `.yaml` cfg files for Helices. These files are, somehow, incomplete. Some information has to be added to be complete, eg the dimension of the tube correspond to the actual helix.

 To add shapes on some helical cuts, you may use `add_shape` as above with additional option `--format=SALOME`. This will create the `HL-31_H4_cut_with_shapes_salome.dat` file for HiFiMagnet Salome plugin.