コード例 #1
0
    def addTrMatrxGenNodes(self,
                           accLattice,
                           node_or_nodes,
                           place=MarkerLinacNode.ENTRANCE):
        """
		Adds the LinacTrMatrixGenNode to the nodes as child nodes.
		"""
        nodes = []
        if (type(node_or_nodes) in [tuple, list]):
            for node in node_or_nodes:
                nodes.append(node)
        else:
            nodes.append(node_or_nodes)
        #-----------------------------
        for node in nodes:
            trMatrxGenNode = LinacTrMatrixGenNode(self,
                                                  node.getName() + ":trMatrx")
            node.addChildNode(trMatrxGenNode, place)
        #----- set up the position of the TrMatrix nodes
        actions = AccActionsContainer()

        def accNodeExitAction(paramsDict):
            """
			Nonbound function. Sets the position of the TrMatrix nodes.
			"""
            node = paramsDict["node"]
            if (isinstance(node, LinacTrMatrixGenNode)):
                pos = paramsDict["path_length"]
                node.setPosition(pos)

        actions.addAction(accNodeExitAction, AccNode.EXIT)
        accLattice.trackActions(actions)
        self.init()
        return self.trMatrxNodes
コード例 #2
0
	def getChromaticitiesXY(self):
		"""
		Calculates chromaticities for X,Y planes for the whole ring
		"""
		(tuneX,tmp0,tmp1) = self.getRingTwissDataX()
		(tuneY,tmp0,tmp1) = self.getRingTwissDataY()
		tuneX = tuneX[1][-1]
		tuneY = tuneY[1][-1]
		self.matrixGenerator.initBunchChromCoeff(self.bunch)
		#track bunch through the TEAPOT nodes
		def twissAction(paramsDict):
			node = paramsDict["node"]
			if(isinstance(node, BaseTEAPOT) == True and isinstance(node,RingRFTEAPOT) == False): 
				node.track(paramsDict)
		
		accContainer = AccActionsContainer()
		accContainer.addAction(twissAction,AccActionsContainer.BODY)
		paramsDict = {}
		paramsDict["bunch"] = self.bunch
		self.teapot_lattice.trackActions(accContainer,paramsDict)	
		
		res_coeff = self.matrixGenerator.calcChromCoeff(self.bunch)
		(coeff_x_dE,coeff_xp_dE,coeff_y_dE,coeff_yp_dE) = res_coeff
		momentum = self.bunch.getSyncParticle().momentum()
		mass = self.bunch.getSyncParticle().mass()
		Ekin = self.bunch.getSyncParticle().kinEnergy()
		chromX = - (momentum/(2*math.sin(2*math.pi*tuneX)))*(coeff_x_dE+coeff_xp_dE)
		chromX = (momentum/(mass+Ekin))*chromX
		chromY = - (momentum/(2*math.sin(2*math.pi*tuneY)))*(coeff_y_dE+coeff_yp_dE)
		chromY = (momentum/(mass+Ekin))*chromY
		return (chromX/(2*math.pi),chromY/(2*math.pi))
コード例 #3
0
    def trackDesignBunch(self,
                         bunch_in,
                         paramsDict=None,
                         actionContainer=None,
                         index_start=-1,
                         index_stop=-1):
        """
		This will track the design bunch through the linac and set up RF Cavities times of
		arrivals.
		"""
        if (actionContainer == None):
            actionContainer = AccActionsContainer("Design Bunch Tracking")
        if (paramsDict == None): paramsDict = {}
        bunch = Bunch()
        bunch_in.copyEmptyBunchTo(bunch)
        bunch.getSyncParticle().time(0.)
        paramsDict["bunch"] = bunch

        def trackDesign(localParamsDict):
            node = localParamsDict["node"]
            node.trackDesign(localParamsDict)

        actionContainer.addAction(trackDesign, AccActionsContainer.BODY)
        self.trackActions(actionContainer, paramsDict, index_start, index_stop)
        actionContainer.removeAction(trackDesign, AccActionsContainer.BODY)
        return bunch
コード例 #4
0
def getResultsDict():
	bunch = Bunch()
	bunch_init.copyEmptyBunchTo(bunch)

	#set up design
	accLattice.trackDesignBunch(bunch)

	#track through the lattice START SCL with 95.610 
	rf_gaps_eKin_phases_dict = {}
	paramsDict = {"test_pos":95.605984,"count":0,"rf_gap_dict":rf_gaps_eKin_phases_dict}
	actionContainer = AccActionsContainer("Bunch Tracking")
	
	def action_exit(paramsDict):
		node = paramsDict["node"]
		length = node.getLength()
		pos = paramsDict["test_pos"] + length
		paramsDict["test_pos"] = pos	
		if(isinstance(paramsDict["parentNode"],AccLattice)):
			if(isinstance(node,BaseRF_Gap)):
				bunch_inner = paramsDict["bunch"]
				eKin_out = bunch_inner.getSyncParticle().kinEnergy()*1.0e+3
				phase = makePhaseNear(node.getGapPhase()*180./math.pi-180.,0.)
				rf_gaps_eKin_phases_dict = paramsDict["rf_gap_dict"]
				rf_gaps_eKin_phases_dict[node] = [eKin_out,phase]
				#print "debug eKin out=",eKin_out
	actionContainer.addAction(action_exit, AccActionsContainer.EXIT)
	accLattice.trackBunch(bunch, paramsDict = paramsDict, actionContainer = actionContainer)
	return rf_gaps_eKin_phases_dict
コード例 #5
0
def getNodeForNameFromWholeLattice(accLattice, name):
    """
	Returns the accelerator node or an array of nodes with the same name.
	This function could be replaced later by the method in the AccLattice class.
	"""

    paramsDict = {}
    actions = AccActionsContainer()
    nodes = []

    def accNodeExitAction(paramsDict):
        """
		Non-bound function. Finds the node in the lattice
		with the specified name.
		positions. This is a closure (well, maybe not
		exactly). It uses external objects.
		"""
        node = paramsDict["node"]
        if (node.getName() == name):
            nodes.append(node)

    actions.addAction(accNodeExitAction, AccNode.EXIT)
    accLattice.trackActions(actions, paramsDict)
    if (len(nodes) == 1):
        return nodes[0]
    elif (len(nodes) == 0):
        return None
    else:
        return nodes
コード例 #6
0
    def __init__(self, teapot_lattice, bunch, name=None):
        MATRIX_Lattice.__init__(self, name)
        if (isinstance(teapot_lattice, TEAPOT_Lattice) != True):
            orbitFinalize(
                "Constructor orbit.teapot.TEAPOT_MATRIX_Lattice needs  the TEAPOT_Lattice instance."
            )
        #memorize the TEAPOT LATTICE
        if (name == None):
            name = teapot_lattice.getName()
        self.setName(name)
        self.teapot_lattice = teapot_lattice
        self.bunch = Bunch()
        self.lost_bunch = Bunch()
        bunch.copyEmptyBunchTo(self.bunch)
        bunch.copyEmptyBunchTo(self.lost_bunch)
        self.matrixGenerator = MatrixGenerator()

        #----------make MATRIX lattice from TEAPOT
        def twissAction(paramsDict):
            node = paramsDict["node"]
            bunch = paramsDict["bunch"]
            active_index = node.getActivePartIndex()
            n_parts = node.getnParts()
            length = node.getLength(active_index)
            if (isinstance(node, BaseTEAPOT) == True
                    and isinstance(node, RingRFTEAPOT) == False):
                self.matrixGenerator.initBunch(bunch)
                node.track(paramsDict)
                #bunch is ready
                matrixNode = BaseMATRIX(node.getName() + "_" +
                                        str(active_index))
                matrixNode.addParam("matrix_parent_node", node)
                matrixNode.addParam("matrix_parent_node_type", node.getType())
                matrixNode.addParam("matrix_parent_node_n_nodes", n_parts)
                matrixNode.addParam("matrix_parent_node_active_index",
                                    active_index)
                matrixNode.setLength(length)
                self.matrixGenerator.calculateMatrix(bunch,
                                                     matrixNode.getMatrix())
                #print "============= name=",matrixNode.getName(),
                #print " type=",matrixNode.getParam("matrix_parent_node_type"),
                #print " L=",matrixNode.getLength()
                self.addNode(matrixNode)
            if (isinstance(node, RingRFTEAPOT) == True):
                rf_node = RingRFTEAPOT(node.getName())
                rf_node.setParamsDict(node.getParamsDict().copy())
                self.addNode(rf_node)

        accContainer = AccActionsContainer()
        accContainer.addAction(twissAction, AccActionsContainer.BODY)
        paramsDict = {}
        paramsDict["bunch"] = self.bunch
        paramsDict["lostbunch"] = self.lost_bunch
        paramsDict["position"] = 0.
        paramsDict["useCharge"] = self.teapot_lattice.getUseRealCharge()
        self.teapot_lattice.trackActions(accContainer, paramsDict)
        self.makeOneTurnMatrix()
        self.initialize()
コード例 #7
0
 def getTransportMatrixArray(self, teapot_lattice):
     accContainer = AccActionsContainer()
     accContainer.addAction(self._twissAction, AccActionsContainer.BODY)
     paramsDict = {}
     paramsDict["bunch"] = self.b
     paramsDict["position"] = 0.
     self.matrixArr = []
     self.index = 0
     teapot_lattice.trackActions(accContainer, paramsDict)
     return self.matrixArr
コード例 #8
0
	def getTransportMatrixArray(self,teapot_lattice):
		accContainer = AccActionsContainer()
		accContainer.addAction(self._twissAction,AccActionsContainer.BODY)
		paramsDict = {}
		paramsDict["bunch"] = self.b
		paramsDict["position"] = 0.
		self.matrixArr = []
		self.index = 0
		teapot_lattice.trackActions(accContainer,paramsDict)
		return self.matrixArr
コード例 #9
0
	def __init__(self, teapot_lattice, bunch, name = None):
		MATRIX_Lattice.__init__(self,name)
		if(isinstance(teapot_lattice,TEAPOT_Lattice) != True):
			orbitFinalize("Constructor orbit.teapot.TEAPOT_MATRIX_Lattice needs  the TEAPOT_Lattice instance.")
		#memorize the TEAPOT LATTICE
		if(name == None):
			name = teapot_lattice.getName()
		self.setName(name)
		self.teapot_lattice = teapot_lattice
		self.bunch = Bunch()
		self.lost_bunch = Bunch()
		bunch.copyEmptyBunchTo(self.bunch)
		bunch.copyEmptyBunchTo(self.lost_bunch)
		self.matrixGenerator = MatrixGenerator()
		#----------make MATRIX lattice from TEAPOT		
		def twissAction(paramsDict):
			node = paramsDict["node"]
			bunch = paramsDict["bunch"]
			active_index = node.getActivePartIndex()
			n_parts = node.getnParts()
			length = node.getLength(active_index)
			if(isinstance(node,BaseTEAPOT) == True and isinstance(node,RingRFTEAPOT) == False): 
				self.matrixGenerator.initBunch(bunch)
				node.track(paramsDict)
				#bunch is ready
				matrixNode = BaseMATRIX(node.getName()+"_"+str(active_index))
				matrixNode.addParam("matrix_parent_node",node)
				matrixNode.addParam("matrix_parent_node_type",node.getType())
				matrixNode.addParam("matrix_parent_node_n_nodes",n_parts)
				matrixNode.addParam("matrix_parent_node_active_index",active_index)
				matrixNode.setLength(length)
				self.matrixGenerator.calculateMatrix(bunch,matrixNode.getMatrix())
				#print "============= name=",matrixNode.getName(),
				#print " type=",matrixNode.getParam("matrix_parent_node_type"),			
				#print " L=",matrixNode.getLength()	
				self.addNode(matrixNode)		
			if(isinstance(node,RingRFTEAPOT) == True):
				rf_node = RingRFTEAPOT(node.getName())
				rf_node.setParamsDict(node.getParamsDict().copy())
				self.addNode(rf_node)
				
		accContainer = AccActionsContainer()
		accContainer.addAction(twissAction,AccActionsContainer.BODY)
		paramsDict = {}
		paramsDict["bunch"] = self.bunch
		paramsDict["lostbunch"] = self.lost_bunch
		paramsDict["position"] = 0.
		paramsDict["useCharge"] = self.teapot_lattice.getUseRealCharge()
		self.teapot_lattice.trackActions(accContainer,paramsDict)		
		self.makeOneTurnMatrix()
		self.initialize()		
コード例 #10
0
	def trackDesignBunch(self, bunch, paramsDict = {}, actionContainer = None):
		"""
		It tracks the bunch through the AccNodeBunchTracker instance.
		"""
		if(actionContainer == None): actionContainer = AccActionsContainer("Design Bunch Tracking")
		paramsDict["bunch"] = bunch
		
		def trackDesign(paramsDict):
			node = paramsDict["node"]
			node.trackDesign(paramsDict)
			
		actionContainer.addAction(trackDesign, AccActionsContainer.BODY)
		self.trackActions(actionContainer,paramsDict)
		actionContainer.removeAction(trackDesign, AccActionsContainer.BODY)				
コード例 #11
0
	def trackBunch(self, bunch, paramsDict = {}, actionContainer = None):
		"""
		It tracks the bunch through the lattice.
		"""
		if(actionContainer == None): actionContainer = AccActionsContainer("Bunch Tracking")
		paramsDict["bunch"] = bunch
		
		def track(paramsDict):
			node = paramsDict["node"]
			node.track(paramsDict)
			
		actionContainer.addAction(track, AccActionsContainer.BODY)
		self.trackActions(actionContainer,paramsDict)
		actionContainer.removeAction(track, AccActionsContainer.BODY)
コード例 #12
0
    def trackBunch(self, bunch, paramsDict={}, actionContainer=None):
        """
		It tracks the bunch through the lattice.
		"""
        if (actionContainer == None):
            actionContainer = AccActionsContainer("Bunch Tracking")
        paramsDict["bunch"] = bunch

        def track(paramsDict):
            node = paramsDict["node"]
            node.track(paramsDict)

        actionContainer.addAction(track, AccActionsContainer.BODY)
        self.trackActions(actionContainer, paramsDict)
        actionContainer.removeAction(track, AccActionsContainer.BODY)
コード例 #13
0
	def trackBunch(self, bunch, paramsDict = None, actionContainer = None, index_start = -1, index_stop = -1):
		"""
		It tracks the bunch through the lattice.
		"""
		if(actionContainer == None): actionContainer = AccActionsContainer("Bunch Tracking")
		if(paramsDict == None): paramsDict = {}			
		paramsDict["bunch"] = bunch
		bunch.getSyncParticle().time(0.)
		
		def track(paramsDict):
			node = paramsDict["node"]
			node.track(paramsDict)
			
		actionContainer.addAction(track, AccActionsContainer.BODY)
		self.trackActions(actionContainer,paramsDict,index_start,index_stop)
		actionContainer.removeAction(track, AccActionsContainer.BODY)
コード例 #14
0
	def initialize(self):
		"""
		Method. Initializes the lattice and child node structures.
		"""
		res_dict = {}
		for node in self.__children:
			if(res_dict.has_key(node)):
				msg = "The AccLattice class instance should not have duplicate nodes!"
				msg = msg + os.linesep
				msg = msg + "Method initialize():"
				msg = msg + os.linesep
				msg = msg + "Name of node=" + node.getName()
				msg = msg + os.linesep
				msg = msg + "Type of node=" + node.getType()
				msg = msg + os.linesep
				orbitFinalize(msg)
			else:
				res_dict[node] = None
			node.initialize()
		del res_dict

		paramsDict = {}
		actions = AccActionsContainer()
		d = [0.]
		posn = {}

		def accNodeExitAction(paramsDict):
			"""
			Nonbound function. Sets lattice length and node
			positions. This is a closure (well, maybe not
			exactly). It uses external objects.
			"""
			node = paramsDict["node"]
			parentNode = paramsDict["parentNode"]
			if(isinstance(parentNode, AccLattice)):
				posBefore = d[0]
				d[0] += node.getLength()
				posAfter = d[0]
				posn[node]=(posBefore, posAfter)
			
		actions.addAction(accNodeExitAction, AccNode.EXIT)
		self.trackActions(actions, paramsDict)
		self.__length = d[0]
		self.__childPositions = posn
		self.__isInitialized = True
コード例 #15
0
ファイル: AccLattice.py プロジェクト: luxiaohan/py-orbit-code
	def initialize(self):
		"""
		Method. Initializes the lattice and child node structures.
		"""
		res_dict = {}
		for node in self.__children:
			if(res_dict.has_key(node)):
				msg = "The AccLattice class instance should not have duplicate nodes!"
				msg = msg + os.linesep
				msg = msg + "Method initialize():"
				msg = msg + os.linesep
				msg = msg + "Name of node=" + node.getName()
				msg = msg + os.linesep
				msg = msg + "Type of node=" + node.getType()
				msg = msg + os.linesep
				orbitFinalize(msg)
			else:
				res_dict[node] = None
			node.initialize()
		del res_dict

		paramsDict = {}
		actions = AccActionsContainer()
		d = [0.]
		posn = {}

		def accNodeExitAction(paramsDict):
			"""
			Nonbound function. Sets lattice length and node
			positions. This is a closure (well, maybe not
			exactly). It uses external objects.
			"""
			node = paramsDict["node"]
			parentNode = paramsDict["parentNode"]
			if(isinstance(parentNode, AccLattice)):
				posBefore = d[0]
				d[0] += node.getLength()
				posAfter = d[0]
				posn[node]=(posBefore, posAfter)
			
		actions.addAction(accNodeExitAction, AccNode.EXIT)
		self.trackActions(actions, paramsDict)
		self.__length = d[0]
		self.__childPositions = posn
		self.__isInitialized = True
コード例 #16
0
	def trackDesignBunch(self, bunch_in, paramsDict = None, actionContainer = None, index_start = -1, index_stop = -1):
		"""
		This will track the design bunch through the linac and set up RF Cavities times of
		arrivals.
		"""
		if(actionContainer == None): actionContainer = AccActionsContainer("Design Bunch Tracking")
		if(paramsDict == None): paramsDict = {}		
		bunch = Bunch()
		bunch_in.copyEmptyBunchTo(bunch)
		bunch.getSyncParticle().time(0.)	
		paramsDict["bunch"] = bunch
		
		def trackDesign(localParamsDict):
			node = localParamsDict["node"]
			node.trackDesign(localParamsDict)
			
		actionContainer.addAction(trackDesign, AccActionsContainer.BODY)
		self.trackActions(actionContainer,paramsDict,index_start,index_stop)
		actionContainer.removeAction(trackDesign, AccActionsContainer.BODY)
コード例 #17
0
    def trackBunch(self,
                   bunch,
                   paramsDict={},
                   actionContainer=None,
                   index_start=-1,
                   index_stop=-1):
        """
		It tracks the bunch through the lattice. Indexes index_start and index_stop are inclusive.
		"""
        if (actionContainer == None):
            actionContainer = AccActionsContainer("Bunch Tracking")
        paramsDict["bunch"] = bunch
        paramsDict["useCharge"] = self.useCharge

        def track(paramsDict):
            node = paramsDict["node"]
            node.track(paramsDict)

        actionContainer.addAction(track, AccActionsContainer.BODY)
        self.trackActions(actionContainer, paramsDict, index_start, index_stop)
        actionContainer.removeAction(track, AccActionsContainer.BODY)
コード例 #18
0
def getNodePosDictForWholeLattice(accLattice):
    """
	Returns the dict[node] = (posStart,posEnd) for all nodes (not only for the firts level).
	This function could be replaced later by the method in the AccLattice class.
	"""
    paramsDict = {}
    actions = AccActionsContainer()
    posStartDict = {}
    posStopDict = {}

    def accNodeEntranceAction(paramsDict):
        """
		Non-bound function. Sets node's end positions. 
		This is a closure (well, maybe not exactly). .
		"""
        node = paramsDict["node"]
        pos = paramsDict["path_length"]
        posStartDict[node] = pos

    def accNodeExitAction(paramsDict):
        """
		Non-bound function. Sets node's end positions. 
		This is a closure (well, maybe not exactly). .
		"""
        node = paramsDict["node"]
        pos = paramsDict["path_length"]
        posStopDict[node] = pos

    actions.addAction(accNodeEntranceAction, AccNode.ENTRANCE)
    actions.addAction(accNodeExitAction, AccNode.EXIT)
    accLattice.trackActions(actions, paramsDict)

    posStartStopDict = {}
    for key in posStartDict:
        pos_start = posStartDict[key]
        pos_end = posStopDict[key]
        posStartStopDict[key] = (pos_start, pos_end)

    return posStartStopDict
コード例 #19
0
    def trackBunch(self,
                   bunch,
                   paramsDict=None,
                   actionContainer=None,
                   index_start=-1,
                   index_stop=-1):
        """
		It tracks the bunch through the lattice.
		"""
        if (actionContainer == None):
            actionContainer = AccActionsContainer("Bunch Tracking")
        if (paramsDict == None): paramsDict = {}
        paramsDict["bunch"] = bunch
        bunch.getSyncParticle().time(0.)

        def track(paramsDict):
            node = paramsDict["node"]
            node.track(paramsDict)

        actionContainer.addAction(track, AccActionsContainer.BODY)
        self.trackActions(actionContainer, paramsDict, index_start, index_stop)
        actionContainer.removeAction(track, AccActionsContainer.BODY)
コード例 #20
0
def getAllNodesInLattice(accLattice):
    """
	Returns the array with all nodes on all levels (even sub-child).
	"""

    nodes = []
    paramsDict = {}
    actions = AccActionsContainer()

    def accNodeEntranceAction(paramsDict):
        """
		Non-bound function. Add the node to the nodes array
		at the entrance inside the node.
		This is a closure (well, maybe not
		exactly). It uses external objects.
		"""
        node = paramsDict["node"]
        nodes.append(node)

    actions.addAction(accNodeEntranceAction, AccNode.ENTRANCE)
    accLattice.trackActions(actions, paramsDict)
    return nodes
コード例 #21
0
def getAllMagnetsInLattice(accLattice):
    """
	Returns the array with all magnets including magnets on all levels (e.g correctors)
	"""

    magnets = []
    paramsDict = {}
    actions = AccActionsContainer()

    def accNodeExitAction(paramsDict):
        """
		Non-bound function. Finds the node in the lattice
		with the specified name.
		positions. This is a closure (well, maybe not
		exactly). It uses external objects.
		"""
        node = paramsDict["node"]
        if (isinstance(node, LinacMagnetNode)):
            magnets.append(node)

    actions.addAction(accNodeExitAction, AccNode.EXIT)
    accLattice.trackActions(actions, paramsDict)
    return magnets
コード例 #22
0
    def getChromaticitiesXY(self):
        """
		Calculates chromaticities for X,Y planes for the whole ring
		"""
        (tuneX, tmp0, tmp1) = self.getRingTwissDataX()
        (tuneY, tmp0, tmp1) = self.getRingTwissDataY()
        tuneX = tuneX[1][-1]
        tuneY = tuneY[1][-1]
        self.matrixGenerator.initBunchChromCoeff(self.bunch)

        #track bunch through the TEAPOT nodes
        def twissAction(paramsDict):
            node = paramsDict["node"]
            if (isinstance(node, BaseTEAPOT) == True
                    and isinstance(node, RingRFTEAPOT) == False):
                node.track(paramsDict)

        accContainer = AccActionsContainer()
        accContainer.addAction(twissAction, AccActionsContainer.BODY)
        paramsDict = {}
        paramsDict["bunch"] = self.bunch
        self.teapot_lattice.trackActions(accContainer, paramsDict)

        res_coeff = self.matrixGenerator.calcChromCoeff(self.bunch)
        (coeff_x_dE, coeff_xp_dE, coeff_y_dE, coeff_yp_dE) = res_coeff
        momentum = self.bunch.getSyncParticle().momentum()
        mass = self.bunch.getSyncParticle().mass()
        Ekin = self.bunch.getSyncParticle().kinEnergy()
        chromX = -(momentum /
                   (2 * math.sin(2 * math.pi * tuneX))) * (coeff_x_dE +
                                                           coeff_xp_dE)
        chromX = (momentum / (mass + Ekin)) * chromX
        chromY = -(momentum /
                   (2 * math.sin(2 * math.pi * tuneY))) * (coeff_y_dE +
                                                           coeff_yp_dE)
        chromY = (momentum / (mass + Ekin)) * chromY
        return (chromX / (2 * math.pi), chromY / (2 * math.pi))
コード例 #23
0
ファイル: teapot.py プロジェクト: yunluo0921/py-orbit
    def initialize(self):
        AccLattice.initialize(self)
        #set up ring length for RF nodes
        ringRF_Node = RingRFTEAPOT()
        bunchwrap_Node = BunchWrapTEAPOT()
        for node in self.getNodes():
            if (node.getType() == ringRF_Node.getType()):
                node.getParamsDict()["ring_length"] = self.getLength()

        paramsDict = {}
        actions = AccActionsContainer()

        def accSetWrapLengthAction(paramsDict):
            """
			Nonbound function. Sets lattice length for wrapper nodes
			"""
            node = paramsDict["node"]
            bunchwrap_node = BunchWrapTEAPOT()
            if (node.getType() == bunchwrap_Node.getType()):
                node.getParamsDict()["ring_length"] = self.getLength()

        actions.addAction(accSetWrapLengthAction, AccNode.EXIT)
        self.trackActions(actions, paramsDict)
        actions.removeAction(accSetWrapLengthAction, AccNode.EXIT)
コード例 #24
0
ファイル: teapot.py プロジェクト: luxiaohan/py-orbit-code
	def initialize(self):
		AccLattice.initialize(self)
		#set up ring length for RF nodes
		ringRF_Node = RingRFTEAPOT()
		bunchwrap_Node = BunchWrapTEAPOT()
		for node in self.getNodes():
			if(node.getType() == ringRF_Node.getType()):
				node.getParamsDict()["ring_length"] = self.getLength()
			
		paramsDict = {}
		actions = AccActionsContainer()

		def accSetWrapLengthAction(paramsDict):
			"""
			Nonbound function. Sets lattice length for wrapper nodes
			"""
			node = paramsDict["node"]
			bunchwrap_node = BunchWrapTEAPOT()
			if(node.getType() == bunchwrap_Node.getType()):
				node.getParamsDict()["ring_length"] = self.getLength()

		actions.addAction(accSetWrapLengthAction, AccNode.EXIT)
		self.trackActions(actions, paramsDict)
		actions.removeAction(accSetWrapLengthAction, AccNode.EXIT)
コード例 #25
0
def getResultsDict():
    bunch = Bunch()
    bunch_init.copyEmptyBunchTo(bunch)

    #set up design
    accLattice.trackDesignBunch(bunch)

    #track through the lattice START SCL with 95.610
    rf_gaps_eKin_phases_dict = {}
    paramsDict = {
        "test_pos": 95.605984,
        "count": 0,
        "rf_gap_dict": rf_gaps_eKin_phases_dict
    }
    actionContainer = AccActionsContainer("Bunch Tracking")

    def action_exit(paramsDict):
        node = paramsDict["node"]
        length = node.getLength()
        pos = paramsDict["test_pos"] + length
        paramsDict["test_pos"] = pos
        if (isinstance(paramsDict["parentNode"], AccLattice)):
            if (isinstance(node, BaseRF_Gap)):
                bunch_inner = paramsDict["bunch"]
                eKin_out = bunch_inner.getSyncParticle().kinEnergy() * 1.0e+3
                phase = makePhaseNear(
                    node.getGapPhase() * 180. / math.pi - 180., 0.)
                rf_gaps_eKin_phases_dict = paramsDict["rf_gap_dict"]
                rf_gaps_eKin_phases_dict[node] = [eKin_out, phase]
                #print "debug eKin out=",eKin_out

    actionContainer.addAction(action_exit, AccActionsContainer.EXIT)
    accLattice.trackBunch(bunch,
                          paramsDict=paramsDict,
                          actionContainer=actionContainer)
    return rf_gaps_eKin_phases_dict
コード例 #26
0
def funcExit(paramsDict):
    node = paramsDict["node"]
    if (paramsDict.has_key("print") and paramsDict["print"] == True):
        print Blanks(
            nLevel[0]), "EXIT  level=", nLevel[0], " node=", node.getName()
    nLevel[0] -= 1


def funcTrack(paramsDict):
    node = paramsDict["node"]
    if (paramsDict.has_key("print") and paramsDict["print"] == True):
        print Blanks(nLevel[0]), "BODY TRACK through node =", node.getName(
        ), " level=", nLevel[0]


acts.addAction(funcEntrance, AccActionsContainer.ENTRANCE)
acts.addAction(funcTrack, AccActionsContainer.BODY)
acts.addAction(funcExit, AccActionsContainer.EXIT)

lattice.initialize()

print "Total length=", lattice.getLength()

nodes = lattice.getNodes()
for node in nodes:
    print "node=", node.getName(
    ), " s start,stop = %4.3f %4.3f " % lattice.getNodePositionsDict()[node]

d = {"print": True}

lattice.trackActions(acts, d)
コード例 #27
0
    x = bunch.x(0) * 1000.
    y = bunch.y(0) * 1000.
    xp = bunch.xp(0) * 1000.
    yp = bunch.yp(0) * 1000.
    st = " %35s  %4.5f " % (node.getName(), pos + pos_start)
    st += "   %6.4f  %6.4f  %6.4f  %6.4f" % (x, xp, y, yp)
    file_out.write(st + "\n")
    file_out.flush()
    print st


def action_exit(paramsDict):
    action_entrance(paramsDict)


actionContainer.addAction(action_entrance, AccActionsContainer.ENTRANCE)
actionContainer.addAction(action_exit, AccActionsContainer.EXIT)

time_start = time.clock()

accLattice.trackBunch(bunch_init,
                      paramsDict=paramsDict,
                      actionContainer=actionContainer)

time_exec = time.clock() - time_start
print "time[sec]=", time_exec

file_out.close()

trajCorrection = TrajectoryCorrection(accLattice)
"""
コード例 #28
0
def TrackingBunch(accLattice, bunch, print_info=False):

    #set up design
    accLattice.trackDesignBunch(bunch)

    #track through the lattice
    paramsDict = {"old_pos": -1., "count": 0, "pos_step": 0.01}
    actionContainer = AccActionsContainer("Bunch Tracking")

    pos_start = 0.

    twiss_analysis = BunchTwissAnalysis()

    results_arr = []

    def action_entrance(paramsDict):
        node = paramsDict["node"]
        bunch = paramsDict["bunch"]
        pos = paramsDict["path_length"]
        if (paramsDict["old_pos"] == pos): return
        if (paramsDict["old_pos"] + paramsDict["pos_step"] > pos): return
        paramsDict["old_pos"] = pos
        paramsDict["count"] += 1
        gamma = bunch.getSyncParticle().gamma()
        beta = bunch.getSyncParticle().beta()
        twiss_analysis.analyzeBunch(bunch)
        x_rms = math.sqrt(
            twiss_analysis.getTwiss(0)[1] *
            twiss_analysis.getTwiss(0)[3]) * 1000.
        y_rms = math.sqrt(
            twiss_analysis.getTwiss(1)[1] *
            twiss_analysis.getTwiss(1)[3]) * 1000.
        z_rms = math.sqrt(
            twiss_analysis.getTwiss(2)[1] *
            twiss_analysis.getTwiss(2)[3]) * 1000.
        z_to_phase_coeff = bunch_gen.getZtoPhaseCoeff(bunch)
        z_rms_deg = z_to_phase_coeff * z_rms / 1000.0
        nParts = bunch.getSizeGlobal()
        (alphaX, betaX, emittX) = (twiss_analysis.getTwiss(0)[0],
                                   twiss_analysis.getTwiss(0)[1],
                                   twiss_analysis.getTwiss(0)[3] * 1.0e+6)
        (alphaY, betaY, emittY) = (twiss_analysis.getTwiss(1)[0],
                                   twiss_analysis.getTwiss(1)[1],
                                   twiss_analysis.getTwiss(1)[3] * 1.0e+6)
        (alphaZ, betaZ, emittZ) = (twiss_analysis.getTwiss(2)[0],
                                   twiss_analysis.getTwiss(2)[1],
                                   twiss_analysis.getTwiss(2)[3] * 1.0e+6)
        norm_emittX = emittX * gamma * beta
        norm_emittY = emittY * gamma * beta
        #---- phi_de_emittZ will be in [pi*deg*MeV]
        phi_de_emittZ = z_to_phase_coeff * emittZ
        eKin = bunch.getSyncParticle().kinEnergy() * 1.0e+3
        s_prt = " %5d  %35s  %4.5f " % (paramsDict["count"], node.getName(),
                                        pos + pos_start)
        s_prt += "  %5.3f  %5.3f   %5.3f " % (x_rms, y_rms, z_rms_deg)
        s_prt += "  %10.6f   %8d " % (eKin, nParts)
        if (print_info): print s_prt
        twiss_arr = [(alphaX, betaX, emittX, norm_emittX),
                     (alphaY, betaY, emittY, norm_emittY),
                     (alphaZ, betaZ, emittZ, phi_de_emittZ)]
        rms_arr = [x_rms, y_rms, z_rms_deg]
        results_arr.append(
            [node.getName(), pos, rms_arr, twiss_arr, eKin, nParts])

    def action_exit(paramsDict):
        action_entrance(paramsDict)

    actionContainer.addAction(action_entrance, AccActionsContainer.ENTRANCE)
    actionContainer.addAction(action_exit, AccActionsContainer.EXIT)

    accLattice.trackBunch(bunch,
                          paramsDict=paramsDict,
                          actionContainer=actionContainer)

    return results_arr
コード例 #29
0
    z_to_phase_coeff = bunch_generator.getZtoPhaseCoeff(bunch)
    z_rms_deg = z_to_phase_coeff * z_rms / 1000.0
    nParts = bunch.getSizeGlobal()
    x_avg = twiss_analysis.getAverage(0) * 1000.
    y_avg = twiss_analysis.getAverage(2) * 1000.
    z_deg_avg = twiss_analysis.getAverage(4) * z_to_phase_coeff
    dE_avg = twiss_analysis.getAverage(5) * 1.0e+3
    eKin = bunch.getSyncParticle().kinEnergy() * 1.0e+3
    s = " %20s  %4.5f " % (node.getName(), pos + pos_start)
    s += "   %8.2f  %8.2f  %8.5f   " % (x_avg, y_avg, dE_avg)
    s += "   %8.2f  %8.2f  %8.6f " % (x_rms, y_rms, dE_rms)
    s += "   %8.2f  %8.6f    " % (x_z_corr, x_dE_corr)
    s += "   %8.2f  %8.6f    " % (y_z_corr, y_dE_corr)
    s += "     %6.3f   %8d " % (eKin, nParts)
    print s


actionContainer.addAction(actions_all, AccActionsContainer.ENTRANCE)
actionContainer.addAction(actions_all, AccActionsContainer.BODY)
actionContainer.addAction(actions_all, AccActionsContainer.EXIT)

accLattice.trackBunch(bunch,
                      paramsDict=paramsDict,
                      actionContainer=actionContainer)

#--------------------------------------------------------------------------
# You can see the shift of average coordinates in the quad_1
#--------------------------------------------------------------------------

print "Done."
コード例 #30
0
                    sx = math.sqrt(sx/bunch.getSize())
                    sy = math.sqrt(sy/bunch.getSize())
                    sz = math.sqrt(sz/bunch.getSize())

                    return sx,sy,sz

                sx, sy, sz = get_rms()

                file_out.write(str(pos)+"\t"+str(sx)+"\t"+str(sy)+"\t"+str(sz)+"\t"+str(eKin) +"\n")

                length = node.getLength()
                pos = paramsDict["test_pos"] + length
                paramsDict["test_pos"] = pos


    
    actionContainer.addAction(action_entrance, AccActionsContainer.ENTRANCE)      
    
    accLattice.trackDesignBunch(b, paramsDict = paramsDict)

    accLattice.trackBunch(b, paramsDict = paramsDict, actionContainer = actionContainer)
    
    #accLattice.trackBunch(b, paramsDict = paramsDict)

    #b.dumpBunch("bunch_ls_out.txt")   


    file_out.close()

    sys.exit() 
コード例 #31
0
    if(paramsDict.has_key("print") and paramsDict["print"] == True):
			print Blanks(nLevel[0]),"ENTER level=",nLevel[0]," node=",node.getName()
			nElems[0] += 1

def funcExit(paramsDict):
    node = paramsDict["node"]
    if(paramsDict.has_key("print") and paramsDict["print"] == True):
        print Blanks(nLevel[0]),"EXIT  level=",nLevel[0]," node=",node.getName()
    nLevel[0] -= 1

def funcTrack(paramsDict):
    node = paramsDict["node"]
    if(paramsDict.has_key("print") and paramsDict["print"] == True):
        print Blanks(nLevel[0]),"BODY TRACK through node =",node.getName()," level=",nLevel[0]

acts.addAction(funcEntrance,AccActionsContainer.ENTRANCE)
acts.addAction(funcTrack,AccActionsContainer.BODY)
acts.addAction(funcExit,AccActionsContainer.EXIT)

lattice.initialize()

print "Total length=",lattice.getLength()

nodes = lattice.getNodes()
for node in nodes:
	print "node=",node.getName()," s start,stop = %4.3f %4.3f "%lattice.getNodePositionsDict()[node]


d = {"print":True}

lattice.trackActions(acts,d)
コード例 #32
0
print "   N           node           position           kinEnergy[MeV]      "


def test_action(paramsDict):
    node = paramsDict["node"]
    length = node.getLength()
    pos = paramsDict["test_pos"] + length
    paramsDict["test_pos"] = pos
    bunch = paramsDict["bunch"]
    eKin = bunch.getSyncParticle().kinEnergy() * 1.0e+3
    if (node.getName().find(":Rg") >= 0):
        paramsDict["count"] += 1
        s = " %5d     %35s     %4.5f     %5.3f  " % (paramsDict["count"],
                                                     node.getName(),
                                                     (pos - length / 2), eKin)
        #outF.write(s+"\n")
        print s


actionContainer.addAction(test_action, AccActionsContainer.EXIT)

accLattice.trackDesignBunch(b,
                            paramsDict=paramsDict,
                            actionContainer=actionContainer)

outF.close()

accLattice.trackBunch(b,
                      paramsDict=paramsDict,
                      actionContainer=actionContainer)
コード例 #33
0
#///////////////////////////////////////////////////////////

print "==============BEFORE============================"
b.dumpBunch()
print "=========================================="


#=====track action ============
def bodyAction(paramsDict):
    node = paramsDict["node"]
    node.track(paramsDict)


accContainer = AccActionsContainer()
accContainer.addAction(bodyAction, AccActionsContainer.BODY)

paramsDict = {}
paramsDict["bunch"] = b

lattice.trackActions(accContainer, paramsDict)
print "=============AFTER============================="
b.dumpBunch()
print "=========================================="

print "lattice length=", lattice.getLength()
print "beta=", b.getSyncParticle().beta()
print "TEAPOT time[sec]=", b.getSyncParticle().time()
print "SIMPLE time[sec]=", lattice.getLength() / (b.getSyncParticle().beta() *
                                                  2.99792458e+8)
print "Stop."
コード例 #34
0
print "RFVoltage = ", RFVoltage
print "RFPhase = ", RFPhase
#///////////////////////////////////////////////////////////

print "==============BEFORE============================"
b.dumpBunch()
print "=========================================="

#=====track action ============
def bodyAction(paramsDict):
	node = paramsDict["node"]
	node.track(paramsDict)


accContainer = AccActionsContainer()
accContainer.addAction(bodyAction,AccActionsContainer.BODY)

paramsDict = {}
paramsDict["bunch"] = b

lattice.trackActions(accContainer,paramsDict)
print "=============AFTER============================="
b.dumpBunch()
print "=========================================="

print "lattice length=",lattice.getLength()
print "beta=",b.getSyncParticle().beta()
print "TEAPOT time[sec]=",b.getSyncParticle().time()
print "SIMPLE time[sec]=",lattice.getLength()/(b.getSyncParticle().beta()*2.99792458e+8)
print "Stop."
コード例 #35
0
    traj_xp_function.add(pos + pos_start, bunchI.xp(0) * 1000.)
    st = "i= %3d " % paramsDict["count"] + " pos= %8.3f " % (pos + pos_start)
    (x, xp, y, yp, z, dE) = (bunchI.x(0) * 1000., bunchI.xp(0) * 1000.,
                             bunchI.y(0) * 1000., bunchI.yp(0) * 1000.,
                             bunchI.z(0) * 1000., bunchI.dE(0) * 1000.)
    st += " (x,xp,y,yp,z,dE) = ( %8.4f %8.4f   %8.4f %8.4f   %8.4f %8.4f )" % (
        x, xp, y, yp, z, dE)
    (x, xp, y, yp, z, dE) = (bunchI.x(1) * 1000., bunchI.xp(1) * 1000.,
                             bunchI.y(1) * 1000., bunchI.yp(1) * 1000.,
                             bunchI.z(1) * 1000., bunchI.dE(1) * 1000.)
    st += " ( %8.4f %8.4f   %8.4f %8.4f   %8.4f %8.4f )" % (x, xp, y, yp, z,
                                                            dE)
    print st


actionContainer.addAction(action_account, AccActionsContainer.ENTRANCE)
actionContainer.addAction(action_account, AccActionsContainer.BODY)
actionContainer.addAction(action_account, AccActionsContainer.EXIT)

print "============================================================================================"
accLattice.trackBunch(bunch_tmp,
                      paramsDict=paramsDict,
                      actionContainer=actionContainer,
                      index_start=start_ind,
                      index_stop=stop_ind)
print "============================================================================================"

print "============================ final TEAPOT bunch ==========================="
st = ""
(x, xp, y, yp, z, dE) = (bunch_tmp.x(0) * 1000., bunch_tmp.xp(0) * 1000.,
                         bunch_tmp.y(0) * 1000., bunch_tmp.yp(0) * 1000.,
コード例 #36
0
                    #
                    bunch.deleteParticleFast(ind)
                    loss_part_pos_arr.append(pos)
            bunch.compress()
            fl_loss_pos_coord_out.flush()

        eKin = bunch.getSyncParticle().kinEnergy() * 1.0e+3
        s = " %5d  %35s  %4.5f    %5.3f  %5.3f   %5.3f    %5.3f    %5.3f  %5.3f  %7.5f  %10.6f   %8d " % (
            paramsDict["count"], node.getName(), pos, x_rms, y_rms, z_rms,
            z_rms_deg, xp_rms, yp_rms, dE_rms, eKin, bunch.getSize())
        file_out.write(s + "\n")
        print s


#actionContainer.addAction(action_entrance, AccActionsContainer.ENTRANCE)
actionContainer.addAction(action_exit, AccActionsContainer.EXIT)

time_start = time.clock()

accLattice.trackBunch(bunch_in,
                      paramsDict=paramsDict,
                      actionContainer=actionContainer)

time_exec = time.clock() - time_start
print "time[sec]=", time_exec

fl_loss_pos_coord_out.close()
file_out.close()

eKin = bunch_in.getSyncParticle().kinEnergy() * 1.0e+3
twiss_analysis.analyzeBunch(bunch_in)
コード例 #37
0
		x_rms = math.sqrt(twiss_analysis.getTwiss(0)[1]*twiss_analysis.getTwiss(0)[3])*1000.
		y_rms = math.sqrt(twiss_analysis.getTwiss(1)[1]*twiss_analysis.getTwiss(1)[3])*1000.
		z_rms = math.sqrt(twiss_analysis.getTwiss(2)[1]*twiss_analysis.getTwiss(2)[3])*1000.
		z_rms_deg = bunch_gen.getZtoPhaseCoeff(bunch)*z_rms/1000.0		
		xp_rms = math.sqrt(twiss_analysis.getTwiss(0)[2]*twiss_analysis.getTwiss(0)[3])*1000.
		yp_rms = math.sqrt(twiss_analysis.getTwiss(1)[2]*twiss_analysis.getTwiss(1)[3])*1000.
		dE_rms = math.sqrt(twiss_analysis.getTwiss(2)[2]*twiss_analysis.getTwiss(2)[3])*1000. 
		#emittX = twiss_analysis.getTwiss(0)[3]*1000.0*1000.0	*bunch.getSyncParticle().gamma()*bunch.getSyncParticle().beta()
		eKin = bunch.getSyncParticle().kinEnergy()*1.0e+3
		s = " %5d  %35s  %4.5f    %5.3f  %5.3f   %5.3f    %5.3f    %5.3f  %5.3f  %7.5f  %10.6f   %8d "%(paramsDict["count"],node.getName(),pos,x_rms,y_rms,z_rms,z_rms_deg,xp_rms,yp_rms,dE_rms,eKin,bunch.getSize())
		file_out.write(s +"\n")
		print s	
	
	
#actionContainer.addAction(action_entrance, AccActionsContainer.ENTRANCE)
actionContainer.addAction(action_exit, AccActionsContainer.EXIT)

time_start = time.clock()

accLattice.trackBunch(bunch_in, paramsDict = paramsDict, actionContainer = actionContainer)

time_exec = time.clock() - time_start
print "time[sec]=",time_exec

file_out.close()

eKin = bunch_in.getSyncParticle().kinEnergy()*1.0e+3
twiss_analysis.analyzeBunch(bunch_in)
(alphaX,betaX,emittX) = (twiss_analysis.getTwiss(0)[0],twiss_analysis.getTwiss(0)[1],twiss_analysis.getTwiss(0)[3])
(alphaY,betaY,emittY) = (twiss_analysis.getTwiss(1)[0],twiss_analysis.getTwiss(1)[1],twiss_analysis.getTwiss(1)[3])
(alphaZ,betaZ,emittZ) = (twiss_analysis.getTwiss(2)[0],twiss_analysis.getTwiss(2)[1],twiss_analysis.getTwiss(2)[3])
コード例 #38
0
#set up design
paramsDict = {"test_pos":0.,"count":0}
actionContainer = AccActionsContainer("Test Design Bunch Tracking")

outF = open("sns_linac_energy.dat","w")


print "   N           node           position           kinEnergy[MeV]      "
def test_action(paramsDict):
	node = paramsDict["node"]
	length = node.getLength()
	pos = paramsDict["test_pos"] + length
	paramsDict["test_pos"] = pos	
	bunch = paramsDict["bunch"]
	eKin = bunch.getSyncParticle().kinEnergy()*1.0e+3	
	if(node.getName().find(":Rg") >= 0):
		paramsDict["count"]	+= 1
		s = " %5d     %35s     %4.5f     %5.3f  "%(paramsDict["count"],node.getName(),(pos - length/2),eKin)
		#outF.write(s+"\n")
		print s

actionContainer.addAction(test_action, AccActionsContainer.EXIT)

accLattice.trackDesignBunch(b, paramsDict = paramsDict, actionContainer = actionContainer)

outF.close()

accLattice.trackBunch(b, paramsDict = paramsDict, actionContainer = actionContainer)