Setup BPMs, correctors and reference orbitΒΆ
For more general cases, genopt
provides interfaces to setup
BPMs, correctors, reference orbit and objective function type, etc.,
leaving more controls to the user side, to fulfill specific task.
Here is an exmaple to show how to use these capabilities.
import genopt
# lattice file
latfile = 'test_392.lat'
oc_ins = genopt.DakotaOC(lat_file=latfile)
# select BPMs
bpms = oc_ins.get_elem_by_type('bpm')
oc_ins.set_bpms(bpm=bpms)
# select correctors
hcors = oc_ins.get_all_cors(type='h')[0:40]
vcors = oc_ins.get_all_cors(type='v')[0:40]
oc_ins.set_cors(hcor=hcors, vcor=vcors)
# setup objective function type
oc_ins.ref_flag = "xy"
# setup reference orbit in x and y
bpms_size = len(oc_ins.bpms)
oc_ins.set_ref_x0(np.ones(bpms_size)*0.0)
oc_ins.set_ref_y0(np.ones(bpms_size)*0.0)
# run optimizaiton
oc_ins.simple_run(method='cg', mpi=True, np=4, iternum=30)
# get output
oc_ins.get_orbit(outfile='orbit.dat')
# plot
oc_ins.plot()
The highlighted code block is added for controlling all these abovementioned properties.
Warning
- BPMs and correctos are distinguished by the element index, which
could be get by proper method, e.g.
get_all_cors()
; - The array size of selected BPMs and reference orbit must be the same;
bpms
,hcors
,vcors
are properties ofDakotaOC
instance.
Warning
All elements could be treated as BPMs, see set_bpms()
, set pseudo_all=True
option will use all elements as monitors.
Note
Objective functions could be chosen from three types according to the value
of ref_flag
:
ref_flag="xy"
: \(\sum \Delta x^2 + \sum \Delta y^2\)ref_flag="x"
: \(\sum \Delta x^2\)ref_flag="y"
: \(\sum \Delta y^2\)
where \(\Delta x = x - x_0\), \(\Delta y = y - y_0\).