Page 1 of 1
Optimizing with "coupled" variables
Posted: 06 Apr 2018, 03:00
by Björklund
Hi!
So, I'd like to vary some quad positions on an overall fixed distance, i.e. vary the drift lengths between them while keeping the sum of the lengths constant. How would I implement this in elegant?
Best regards
Jonas
Re: Optimizing with "coupled" variables
Posted: 09 Apr 2018, 13:02
by michael_borland
Jonas,
You can use the optimization_covariable command for this purpose. E.g., suppose your beamline is
Code: Select all
D1: drift,l=1
Q1: quad,l=0.5
D2: drift,l=1
bl: line=(D1,Q1,D2)
and you want to move Q1 around while keeping the total length constant. You can use
Code: Select all
&optimization_variable name=D1, item=L, lower_limit=0, upper_limit=2, step_size=1e-3 &end
&optimization_covariable name=D2, item=L, equation="D1.L0 D2.L0 + D1.L -" &end
"D1.L0" and "D2.L0" stand for the original values of the lengths, whereas "D1.L" is the trial value.
--Michael
Re: Optimizing with "coupled" variables
Posted: 12 Jun 2018, 08:50
by Björklund
Hi!
So, I finally got around to trying this a little while ago. I have a case with more magnets and drifts (4 and 5, respectively), so I implemented the final drift as a co-variable similarly to what's described below. The problem is that I couldn't find a way to prevent this drift from getting negative values, the code just output a warning. How would I go about solving this?
Best regards
Jonas
Re: Optimizing with "coupled" variables
Posted: 25 Jun 2018, 06:54
by Neeraj
I am facing same the problem, too.
Re: Optimizing with "coupled" variables
Posted: 25 Jun 2018, 08:22
by michael_borland
Jonas,
You can add an optimization term using the length of D2. E.g.,
Code: Select all
&optimization_term term = "D2.L 0 1e-6 selt" &end
This will rise rapidly from 0 when D2.L is less than 0.
--Michael
Re: Optimizing with "coupled" variables
Posted: 26 Jun 2018, 10:13
by Björklund
Hi Michael,
I tried implementing it this way, but I get the error
Code: Select all
error: too few values on stack (popn)
Problem evaluating expression: I.BC1_DMID3.L 0 1e-6 selt
RPN expression errors prevent optimization
Do you know what causes this?
Best regards
Jonas
Re: Optimizing with "coupled" variables
Posted: 26 Jun 2018, 13:56
by michael_borland
Jonas,
It appears that I.BC1_DMID3.L does not exist. Compare with the attached example.
--Michael