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
Optimizing with "coupled" variables
Moderators: cyao, michael_borland
-
- Posts: 1959
- Joined: 19 May 2008, 09:33
- Location: Argonne National Laboratory
- Contact:
Re: Optimizing with "coupled" variables
Jonas,
You can use the optimization_covariable command for this purpose. E.g., suppose your beamline is
and you want to move Q1 around while keeping the total length constant. You can use
"D1.L0" and "D2.L0" stand for the original values of the lengths, whereas "D1.L" is the trial value.
--Michael
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)
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
--Michael
Re: Optimizing with "coupled" variables
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
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
-
- Posts: 1959
- Joined: 19 May 2008, 09:33
- Location: Argonne National Laboratory
- Contact:
Re: Optimizing with "coupled" variables
Jonas,
You can add an optimization term using the length of D2. E.g.,
This will rise rapidly from 0 when D2.L is less than 0.
--Michael
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
--Michael
Re: Optimizing with "coupled" variables
Hi Michael,
I tried implementing it this way, but I get the error
Do you know what causes this?
Best regards
Jonas
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
Best regards
Jonas
-
- Posts: 1959
- Joined: 19 May 2008, 09:33
- Location: Argonne National Laboratory
- Contact:
Re: Optimizing with "coupled" variables
Jonas,
It appears that I.BC1_DMID3.L does not exist. Compare with the attached example.
--Michael
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