Пример #1
0
	def trackProbe(self,eKin_in):
		""" Returns the Trajectory. The input energy is in MeV """
		part_probe = ParticleProbe(self.part_probe_init)
		part_probe.setKineticEnergy(eKin_in*1.0e+6)
		self.scenario.setProbe(part_probe)	
		self.scenario.run()	
		return 	self.scenario.getTrajectory()	
	def getModelEnergyOut(self,eKin_in,amp,phase,phase_shift):
		if(self.active_cav_wrapper == null): return 0.
		self.setModelAmpPhaseToActiveCav(amp,phase,phase_shift)
		part_probe = ParticleProbe(self.part_probe_init)
		part_probe.setKineticEnergy(eKin_in*1.0e+6)
		self.scenario.setProbe(part_probe)	
		self.scenario.resync()
		self.scenario.run()
		return self.scenario.getTrajectory().finalState().getKineticEnergy()/1.0e+6
	def calcForNewAmpsAndPhases(self):
		self.setRescaledModelCavityAmplitudes()
		cav_wrappers = self.scl_long_tuneup_controller.cav_wrappers
		for cav_wrapper in cav_wrappers:
			amp = cav_wrapper.rescaleBacket.designAmp
			phase = self.new_cav_amp_phase_dict[cav_wrapper][1]
			self.new_cav_amp_phase_dict[cav_wrapper] = [amp,phase]
		self.scenario.resync()
		#---set up phases : we should reproduce the rf gap avg. phases from the proxies
		max_limit_phase_diff = 0.01
		max_phase_diff = 1.0
		min_cav_amp = 0.5
		max_iter = 30
		it = 0
		while(max_phase_diff > max_limit_phase_diff):
			it += 1
			for cav_wrapper in cav_wrappers:
				 irfGap = self.cavToGapsDict[cav_wrapper][0]
				 phase = self.new_cav_amp_phase_dict[cav_wrapper][1]
				 irfGap.setPhase(phase*math.pi/180.)
			part_probe = ParticleProbe(self.part_probe_init)
			eKin_in = self.scl_long_tuneup_controller.cav_wrappers[0].eKin_in
			part_probe.setKineticEnergy(eKin_in*1.0e+6)
			self.scenario.setProbe(part_probe)	
			self.scenario.run()
			max_phase_diff = 0.0
			for cav_wrapper in cav_wrappers:
				phase_rf_gaps_avg = self.getAvgGapPhase(cav_wrapper)
				phase_diff = phase_rf_gaps_avg - cav_wrapper.rescaleBacket.avg_gap_phase
				#print "debug cav=",cav_wrapper.alias," phase_diff=",phase_diff," phase avg =",phase_rf_gaps_avg," design avg=",cav_wrapper.avg_gap_phase
				#print "debug ======= amp=",cav_wrapper.cav.getDfltCavAmp()," phase=",self.cavToGapsDict[cav_wrapper][0].getPhase()*180./math.pi
				if(cav_wrapper.rescaleBacket.designAmp > min_cav_amp):
					self.new_cav_amp_phase_dict[cav_wrapper][1] -= phase_diff/1.3
					phase_diff = math.fabs(phase_diff)
					if(max_phase_diff < phase_diff): max_phase_diff = phase_diff
			eKin_out = self.scenario.getTrajectory().finalState().getKineticEnergy()/1.0e+6	
			#print "debug eKin_out=",eKin_out
			if(it > max_iter): break	
		#---- update the cavities' new model phases
		for cav_wrapper in cav_wrappers:
			phase = self.new_cav_amp_phase_dict[cav_wrapper][1]
			cav_wrapper.rescaleBacket.designPhase = makePhaseNear(phase,0.)
		#print "debug iter=",it
		eKin_out = self.scenario.getTrajectory().finalState().getKineticEnergy()/1.0e+6
		cav_wrappers[len(cav_wrappers)-1].rescaleBacket.eKin_out = eKin_out 
		eKin_in = self.scenario.getTrajectory().initialState().getKineticEnergy()/1.0e+6
		cav_wrappers[0].rescaleBacket.eKin_in = eKin_in 
		scl_long_tuneup_rescale_controller = self.scl_long_tuneup_controller.scl_long_tuneup_rescale_controller
		scl_long_tuneup_operations_rescale_controller = scl_long_tuneup_rescale_controller.scl_long_tuneup_operations_rescale_controller		
		init_amp_phases_panel = scl_long_tuneup_operations_rescale_controller.init_amp_phases_panel
		init_amp_phases_panel.energy_text.setValue(eKin_out)	
		self.restoreInitAmpPhases()
		return eKin_out
	def calcForNewAmpsAndPhases(self):
		self.setRescaledModelCavityAmplitudes()
		cav_wrappers = self.scl_long_tuneup_controller.cav_wrappers
		for cav_wrapper in cav_wrappers:
			amp = cav_wrapper.rescaleBacket.designAmp
			phase = self.new_cav_amp_phase_dict[cav_wrapper][1]
			self.new_cav_amp_phase_dict[cav_wrapper] = [amp,phase]
		self.scenario.resync()
		#---set up phases : we should reproduce the rf gap avg. phases from the proxies
		max_limit_phase_diff = 0.01
		max_phase_diff = 1.0
		min_cav_amp = 0.5
		max_iter = 30
		it = 0
		while(max_phase_diff > max_limit_phase_diff):
			it += 1
			for cav_wrapper in cav_wrappers:
				 irfGap = self.cavToGapsDict[cav_wrapper][0]
				 phase = self.new_cav_amp_phase_dict[cav_wrapper][1]
				 irfGap.setPhase(phase*math.pi/180.)
			part_probe = ParticleProbe(self.part_probe_init)
			eKin_in = self.scl_long_tuneup_controller.cav_wrappers[0].eKin_in
			part_probe.setKineticEnergy(eKin_in*1.0e+6)
			self.scenario.setProbe(part_probe)	
			self.scenario.run()
			max_phase_diff = 0.0
			for cav_wrapper in cav_wrappers:
				phase_rf_gaps_avg = self.getAvgGapPhase(cav_wrapper)
				phase_diff = phase_rf_gaps_avg - cav_wrapper.rescaleBacket.avg_gap_phase
				#print "debug cav=",cav_wrapper.alias," phase_diff=",phase_diff," phase avg =",phase_rf_gaps_avg," design avg=",cav_wrapper.avg_gap_phase
				#print "debug ======= amp=",cav_wrapper.cav.getDfltCavAmp()," phase=",self.cavToGapsDict[cav_wrapper][0].getPhase()*180./math.pi
				if(cav_wrapper.rescaleBacket.designAmp > min_cav_amp):
					self.new_cav_amp_phase_dict[cav_wrapper][1] -= phase_diff/1.3
					phase_diff = math.fabs(phase_diff)
					if(max_phase_diff < phase_diff): max_phase_diff = phase_diff
			eKin_out = self.scenario.getTrajectory().finalState().getKineticEnergy()/1.0e+6	
			#print "debug eKin_out=",eKin_out
			if(it > max_iter): break	
		#---- update the cavities' new model phases
		for cav_wrapper in cav_wrappers:
			phase = self.new_cav_amp_phase_dict[cav_wrapper][1]
			cav_wrapper.rescaleBacket.designPhase = makePhaseNear(phase,0.)
		#print "debug iter=",it
		eKin_out = self.scenario.getTrajectory().finalState().getKineticEnergy()/1.0e+6
		scl_long_tuneup_rescale_controller = self.scl_long_tuneup_controller.scl_long_tuneup_rescale_controller
		init_amp_phases_panel = scl_long_tuneup_rescale_controller.init_amp_phases_panel
		init_amp_phases_panel.energy_text.setValue(eKin_out)	
		self.restoreInitAmpPhases()
		return eKin_out
Пример #5
0
	def __init__(self,main_loop_controller):
		self.main_loop_controller = main_loop_controller
		cav_wrappers = self.main_loop_controller.cav_wrappers	
		self.accSeq = self.main_loop_controller.accSeq
		self.part_tracker = AlgorithmFactory.createParticleTracker(self.accSeq)
		self.part_tracker.setRfGapPhaseCalculation(true)
		self.part_probe_init = ProbeFactory.createParticleProbe(self.accSeq,self.part_tracker)
		self.scenario = Scenario.newScenarioFor(self.accSeq)
		self.scenario.setSynchronizationMode(Scenario.SYNC_MODE_DESIGN)
		self.scenario.resync()
		part_probe = ParticleProbe(self.part_probe_init)
		part_probe.setKineticEnergy(self.part_probe_init.getKineticEnergy())
		self.scenario.setProbe(part_probe)	
		self.scenario.run()	
		#-------------------------------------------------
		# The cavToGapsDict is needed for reference to the irfGap to set phase and do not use  scenario.resync()
		rfGaps = self.accSeq.getAllNodesWithQualifier(AndTypeQualifier().and((OrTypeQualifier()).or(RfGap.s_strType)))	
		self.cavToGapsDict = {}
		self.cavEnergyInOutDict = {}		
		for cav_wrapper in cav_wrappers:
			self.cavToGapsDict[cav_wrapper] = []
			for rfGap in rfGaps:
				if(rfGap.getParent().getId() == cav_wrapper.cav.getId()):
					irfGaps = self.scenario.elementsMappedTo(rfGap)
					self.cavToGapsDict[cav_wrapper].append(irfGaps[0])
		for cav_wrapper_ind in range(len(cav_wrappers)):
			cav_wrapper = cav_wrappers[cav_wrapper_ind]
			irfGaps = self.cavToGapsDict[cav_wrapper]
			nGaps = len(irfGaps)
			state_in = self.scenario.getTrajectory().statesForElement(irfGaps[0].getId()).get(0)
			if(cav_wrapper_ind > 0):
				irfGaps_0 = self.cavToGapsDict[cav_wrappers[cav_wrapper_ind-1]]
				irfGap_0 = irfGaps_0[len(irfGaps_0)-1]
				state_in = self.scenario.getTrajectory().statesForElement(irfGap_0.getId()).get(0)
			state_out = self.scenario.getTrajectory().statesForElement(irfGaps[nGaps-1].getId()).get(0)
			#print "debug cav=",cav_wrapper.alias," eKin_in=",state_in.getKineticEnergy()/1.0e+6," eKin_out=",state_out.getKineticEnergy()/1.0e+6
			self.cavEnergyInOutDict[cav_wrapper] = (state_in.getKineticEnergy()/1.0e+6,state_out.getKineticEnergy()/1.0e+6)
		# cav_wrappers_param_dict[cav_wrapper] = (cavAmp,phase)
		self.cav_wrappers_param_dict = {}
		self.cav_amp_phase_dict = {}
		for cav_wrapper in cav_wrappers:
			amp = cav_wrapper.cav.getDfltCavAmp()
			phase = cav_wrapper.cav.getDfltCavPhase()
			self.cav_amp_phase_dict[cav_wrapper] = (amp,phase)
		#----------------------------------------------------------------
		self.active_cav_wrapper = null
		self.gap_first = null
		self.gap_last = null	
		self.gap_list = null
	def fillOutEneregyVsPhase(self,eKin_in,amp,phase_shift,phase_arr):
		self.scan_gd.removeAllPoints()
		if(self.active_cav_wrapper == null): return
		self.active_cav_wrapper.cav.updateDesignAmp(amp)
		self.scenario.resync()
		irfGap = self.cavToGapsDict[self.active_cav_wrapper][0]	
		for phase in phase_arr:
			part_probe = ParticleProbe(self.part_probe_init)
			part_probe.setKineticEnergy(eKin_in*1.0e+6)
			self.scenario.setProbe(part_probe)		
			#self.active_cav_wrapper.cav.updateDesignPhase(phase-phase_shift)
			#self.scenario.resync()
			irfGap.setPhase((phase-phase_shift)*math.pi/180.)
			self.scenario.run()
			eKin_out = self.scenario.getTrajectory().finalState().getKineticEnergy()/1.0e+6
			self.scan_gd.addPoint(phase,eKin_out)
		return self.scan_gd
	def initTrackingModelAndArrivalTimes(self):
		# It fills out the arrival time for the our base case 
		# It also returns the energy
		self.setAnalysisModelCavityAmplitudes()		
		part_probe = ParticleProbe(self.part_probe_init)
		eKin_in = self.scl_long_tuneup_controller.cav_wrappers[0].eKin_in
		part_probe.setKineticEnergy(eKin_in*1.0e+6)
		self.scenario.setProbe(part_probe)	
		self.scenario.resync()
		self.scenario.run()
		cav_wrappers = self.scl_long_tuneup_controller.cav_wrappers
		for cav_wrapper in cav_wrappers:
			if(self.cavToGapsDict.has_key(cav_wrapper)):
				irfGap = self.cavToGapsDict[cav_wrapper][0]
				state = self.scenario.getTrajectory().stateForElement(irfGap.getId())
				cav_wrapper.rescaleBacket.arrivalTime = state.getTime()
				self.new_cav_amp_phase_dict[cav_wrapper][1] = cav_wrapper.designPhase
		self.modelArrivalTimesIsReady = true
		self.restoreInitAmpPhases()
		return self.scenario.getTrajectory().finalState().getKineticEnergy()/1.0e+6
	def initTrackingModelAndArrivalTimes(self):
		# It fills out the arrival time for the our base case 
		# It also returns the energy
		self.setAnalysisModelCavityAmplitudes()		
		part_probe = ParticleProbe(self.part_probe_init)
		eKin_in = self.scl_long_tuneup_controller.cav_wrappers[0].eKin_in
		part_probe.setKineticEnergy(eKin_in*1.0e+6)
		self.scenario.setProbe(part_probe)	
		self.scenario.resync()
		self.scenario.run()
		cav_wrappers = self.scl_long_tuneup_controller.cav_wrappers
		for cav_wrapper in cav_wrappers:
			if(self.cavToGapsDict.has_key(cav_wrapper)):
				irfGap = self.cavToGapsDict[cav_wrapper][0]
				state = self.scenario.getTrajectory().stateForElement(irfGap.getId())
				cav_wrapper.rescaleBacket.arrivalTime = state.getTime()
				self.new_cav_amp_phase_dict[cav_wrapper][1] = cav_wrapper.designPhase
		self.modelArrivalTimesIsReady = true
		self.restoreInitAmpPhases()
		return self.scenario.getTrajectory().finalState().getKineticEnergy()/1.0e+6
Пример #9
0
	def __init__(self,mebt_main_orbit_diff_cntrl):
		self.mebt_main_orbit_diff_cntrl = mebt_main_orbit_diff_cntrl	
		self.accSeq = self.mebt_main_orbit_diff_cntrl.accSeq
		self.scenario = Scenario.newScenarioFor(self.accSeq)
		self.scenario.setSynchronizationMode(Scenario.SYNC_MODE_DESIGN)
		self.scenario.unsetStartNode()
		self.scenario.unsetStopNode()			
		self.part_tracker = AlgorithmFactory.createParticleTracker(self.accSeq)
		self.part_tracker.setRfGapPhaseCalculation(true)
		self.part_probe_init = ProbeFactory.createParticleProbe(self.accSeq,self.part_tracker)
		self.scenario.resync()
		part_probe = ParticleProbe(self.part_probe_init)
		self.scenario.setProbe(part_probe)
		self.scenario.run()
		self.traj = self.scenario.getTrajectory()	
Пример #10
0
	def runModel(self):
		quad_wrappers = self.mebt_main_orbit_diff_cntrl.quad_wrappers
		for quad_wrapper in quad_wrappers:
			quad_wrapper.magnet.setDfltField(quad_wrapper.field)
		dc_wrappers = self.mebt_main_orbit_diff_cntrl.dc_wrappers
		for dc_wrapper in dc_wrappers:
			dc_wrapper.magnet.setDfltField(dc_wrapper.field)
		#"""
		self.scenario = Scenario.newScenarioFor(self.accSeq)
		self.scenario.setSynchronizationMode(Scenario.SYNC_MODE_DESIGN)
		self.scenario.unsetStartNode()
		self.scenario.unsetStopNode()			
		#"""	
		self.scenario.resync()
		part_probe = ParticleProbe(self.part_probe_init)
		self.scenario.setProbe(part_probe)
		self.scenario.run()
		self.traj = self.scenario.getTrajectory()