Page 1 of 1

Linking elements

Posted: 01 Aug 2008, 16:10
by mjoyce
Any time I alter MBX1E02.ANGLE, I want MBW1E0?.ANGLE = MBX1E02.ANGLE * -.5
I thought I had set up the link_elements and alter_elements commands correctly, but when I run DOG.ele and look at DOG.new, the angle for MBX1E02 has changed as expected, but the angles for MBW1E0? haven't changed. What Am I doing wrong? Thanks

DOG.ele
&run_setup
lattice="DOG.lte",
use_beamline="DOG",
p_central_mev=444.999706595186,
final="%s.fin"
parameters="%s.parms"
centroid="%s.cen"
sigma="%s.sig"
&end
&twiss_output
filename="%s.twi",
matched=0,radiation_integrals=1,
beta_x=1.353736269767569e+01, alpha_x=-8.175905502777217e-01,
beta_y=3.508702734979261e+01, alpha_y=6.216759265147694e-01
&end
&run_control n_steps=1
&end
&alter_elements
name=MBX1E02,
item = ANGLE,
value = 2
&end
&link_elements
target = MBW1E01,
item = ANGLE,
source = MBX1E02,
equation = ".5 *"
&end

&save_lattice
filename = "%s.new"
&end
&floor_coordinates
filename="%s.flr",
X0 = 8.059999999999999e+01,
Y0 = 1.999997326307599e+00,
Z0 = 1.521585078431476e+02,
theta0 = 0.00
&end
&bunched_beam
n_particles_per_bunch=1,
emit_x=6.2e-9, emit_y=6.2e-9,
beta_x=1.353736269767569e+01, alpha_x=-8.175905502777217e-01,
beta_y=3.508702734979261e+01, alpha_y=6.216759265147694e-01
sigma_dp=0,sigma_s=0,
distribution_type[0] = 3*"gaussian",
distribution_cutoff[0] = 3*3,
enforce_rms_values[0]=1,1,1
&end
&track
&end

DOG.lte
D121: DRIFT, L=0.4803
MBW1E01: SBEND, L=0.500137, ANGLE=-0.0405309085544383, K1=0 &
, TILT=-0 &
, E1=-0, HGAP=0, FINT=0.5, &
E2=-0.0405309085544383, EDGE_ORDER=1
D122: DRIFT, L=5.75472
MBX1E02: SBEND, L=1.00027, ANGLE=0.0810616425759514, K1=0 &
, TILT=-0 &
, E1=0.0405309085544383, HGAP=0, FINT=0.5, &
E2=0.0405309085544383, EDGE_ORDER=1
MBW1E03: SBEND, L=0.500137, ANGLE=-0.0405309085544383, K1=0 &
, TILT=-0 &
, E1=-0.0405309085544383, HGAP=0, FINT=0.5, &
E2=-0, EDGE_ORDER=1
D123: DRIFT, L=0.525003
DOG: LINE=(D121, MBW1E01, D122, MBX1E02, D122, MBW1E03, D123)

Re: Linking elements

Posted: 01 Aug 2008, 16:36
by michael_borland
Michele,

There are two issues here. One is an error in your input file, and another is the unclear nature of the link_elements command.

First, in the input file you have
&link_elements
target = MBW1E01,
item = ANGLE,
source = MBX1E02,
equation = ".5 *"
&end

This is not what you want. The equation should be "ANGLE .5 *". In this case, ANGLE refers to the ANGLE of the source element. You didn't get an error message because elegant puts the original value of the ANGLE for the target on the stack, for convenience.

Second, the link_elements command was designed originally for linking elements to other elements that have errors or variation imposed on them. That's why it is classified as a "setup" command (and has control over source position). It sets up a link to be enforced later, once a track command is given, for example. Like an error or variation, the changes due to link_elements won't appear in the lattice file when saved, since it is considered a perturbation, not a change of the lattice definition. However, they will appear in the parameter file.

There is a way to do what you want, by explicitly storing the angle in an rpn variable:
&alter_elements
name=MBX1E02,
item = ANGLE,
value = "(2 sto angle1)"
&end

&alter_elements
name=MBW1E01,
item = ANGLE
value = "(angle1 2 /)"
&end

I think this behavior of link_elements is counter-intuitive. I'll look into whether it can be readily improved.

--Michael

Re: Linking elements

Posted: 04 Aug 2008, 11:04
by mjoyce
Michael, once again thanks for your help. I tried the changes that you suggested, but I'm getting an error from elegant:
error scanning value (2 sto angle1) for namelist member value

Re: Linking elements

Posted: 04 Aug 2008, 12:46
by michael_borland
Michele,

I suspect you are using an old version. If so, try upgrading to the latest release.

--Michael