Optimizing with "coupled" variables

Moderators: cyao, michael_borland

Post Reply
Björklund
Posts: 84
Joined: 19 May 2016, 07:14

Optimizing with "coupled" variables

Post by Björklund » 06 Apr 2018, 03:00

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

michael_borland
Posts: 1959
Joined: 19 May 2008, 09:33
Location: Argonne National Laboratory
Contact:

Re: Optimizing with "coupled" variables

Post by michael_borland » 09 Apr 2018, 13:02

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

Björklund
Posts: 84
Joined: 19 May 2016, 07:14

Re: Optimizing with "coupled" variables

Post by Björklund » 12 Jun 2018, 08:50

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

Neeraj
Posts: 23
Joined: 24 May 2018, 10:42

Re: Optimizing with "coupled" variables

Post by Neeraj » 25 Jun 2018, 06:54

I am facing same the problem, too.
-Neeraj

michael_borland
Posts: 1959
Joined: 19 May 2008, 09:33
Location: Argonne National Laboratory
Contact:

Re: Optimizing with "coupled" variables

Post by michael_borland » 25 Jun 2018, 08:22

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

Björklund
Posts: 84
Joined: 19 May 2016, 07:14

Re: Optimizing with "coupled" variables

Post by Björklund » 26 Jun 2018, 10:13

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

michael_borland
Posts: 1959
Joined: 19 May 2008, 09:33
Location: Argonne National Laboratory
Contact:

Re: Optimizing with "coupled" variables

Post by michael_borland » 26 Jun 2018, 13:56

Jonas,

It appears that I.BC1_DMID3.L does not exist. Compare with the attached example.

--Michael
Attachments
2018-06-26.zip
(842 Bytes) Downloaded 292 times

Post Reply