Example #1
0
  def processElements(self, elems, elemserr, q, index, order=6):
    R = generateDefaultMap(order=order)
    U = generateDefaultMatrix(order=order)
    for i in xrange(len(elems)):
      e = elems[i]
      try:
        mtr = metaclass2.matrixForElement(e, order)
        if mtr == None:
          mp = metaclass2.mapForElement(e, order)
        else:
          M = mtr * U
          mp = metaclass2.matrixToMap(M, XYZD)

        # Apply misalignments here if any
        if elemserr is not None:
          if isinstance(elemserr, metaclass2.twiss2):
            dx = elemserr.elems[i].DX
            dy = elemserr.elems[i].DY
            if dx != 0:
              mp = mp(x=X+dx)
            if dy != 0:
              mp = mp(y=Y+dy)
          else:
            raise TypeError("The 'align' attribute has to be of the type 'twiss2'.")

        # Combine the map with everything else
        R = mp * R
      except Exception:
        print "No implementation for element: ", e.NAME, e.KEYWORD 	
    q.put((index, R))
    #q.cancel_join_thread()
    print "Finished in ", index
Example #2
0
    def processElements(self, elems, elemserr, q, index, order=6):
        R = generateDefaultMap(order=order)
        U = generateDefaultMatrix(order=order)
        for i in xrange(len(elems)):
            e = elems[i]
            try:
                mtr = metaclass2.matrixForElement(e, order)
                if mtr == None:
                    mp = metaclass2.mapForElement(e, order)
                else:
                    M = mtr * U
                    mp = metaclass2.matrixToMap(M, XYZD)

                # Apply misalignments here if any
                if elemserr is not None:
                    if isinstance(elemserr, metaclass2.twiss2):
                        dx = elemserr.elems[i].DX
                        dy = elemserr.elems[i].DY
                        if dx != 0:
                            mp = mp(x=X + dx)
                        if dy != 0:
                            mp = mp(y=Y + dy)
                    else:
                        raise TypeError(
                            "The 'align' attribute has to be of the type 'twiss2'."
                        )

                # Combine the map with everything else
                R = mp * R
            except Exception:
                print "No implementation for element: ", e.NAME, e.KEYWORD
        q.put((index, R))
        #q.cancel_join_thread()
        print "Finished in ", index
Example #3
0
    def fromTwiss(self, t, terr=None, order=6):
        EQnL = computeEQ(4, order, X, Y)
        EQnLR, EQnLI = separateComplexList(EQnL)
        R = generateDefaultMap(order=order)
        U = generateDefaultMatrix(order=order)
        for i in xrange(len(t.elems)):
            e = t.elems[i]
            try:
                start = time.time()
                mtr = metaclass2.matrixForElement(e, order)
                if mtr == None:
                    mp = metaclass2.mapForElement(e, order, EQnLR, EQnLI)
                else:
                    M = mtr * U
                    mp = metaclass2.matrixToMap(M, XYZD)
                end = time.time() - start
                print e.KEYWORD, "Generating map", end
                # Apply misalignments here if any
                if terr is not None:
                    if isinstance(terr, metaclass2.twiss2):
                        dx = terr.elems[i].DX
                        dy = terr.elems[i].DY
                        if dx != 0:
                            mp = mp(x=X + dx)
                        if dy != 0:
                            mp = mp(y=Y + dy)
                    else:
                        raise TypeError(
                            "The 'align' attribute has to be of the type 'twiss2'."
                        )
                # Combine the map with everything else
                tstart = time.time()
                R = mp * R
                tend = time.time() - tstart
                print e.KEYWORD, "Composition", tend

        #  print "R", "%.20f" % time()
            except Exception:
                #print "No implementation for element: ", e.NAME, e.KEYWORD
                pass
        for k in XYZD:
            self[k] = R[k]

        # Reorder the variables so that they are always in the same order
        # This is important for comparision operations but also for all
        # the other methods
        self.reorder(XYZD)

        for k in XYZD:
            print k, "=", self[k]
Example #4
0
  def fromTwiss(self, t, terr=None, order=6):
    EQnL = computeEQ(4, order, X , Y)
    EQnLR, EQnLI = separateComplexList(EQnL)
    R = generateDefaultMap(order=order)
    U = generateDefaultMatrix(order=order)
    for i in xrange(len(t.elems)):
      e = t.elems[i]
      try:
        start = time.time()
        mtr = metaclass2.matrixForElement(e, order)
        if mtr == None:
          mp = metaclass2.mapForElement(e, order, EQnLR, EQnLI)
        else:
          M = mtr * U
          mp = metaclass2.matrixToMap(M, XYZD)
        end = time.time() - start
        print e.KEYWORD, "Generating map", end
        # Apply misalignments here if any
        if terr is not None:
          if isinstance(terr, metaclass2.twiss2):
            dx = terr.elems[i].DX
            dy = terr.elems[i].DY
            if dx != 0:
              mp = mp(x=X+dx)
            if dy != 0:
              mp = mp(y=Y+dy)
          else:
            raise TypeError("The 'align' attribute has to be of the type 'twiss2'.")
        # Combine the map with everything else
        tstart = time.time()
        R = mp * R
        tend = time.time() - tstart 	
	print e.KEYWORD, "Composition" , tend
	
     #  print "R", "%.20f" % time()
      except Exception:
        #print "No implementation for element: ", e.NAME, e.KEYWORD
	pass
    for k in XYZD:
      self[k] = R[k]

    # Reorder the variables so that they are always in the same order
    # This is important for comparision operations but also for all
    # the other methods
    self.reorder(XYZD)
    
    for k in XYZD:
      print k, "=", self[k] 
Example #5
0
    def fromTwiss(self, t, terr=None, order=6):
        R = generateDefaultMap(order=order)
        U = generateDefaultMatrix(order=order)
        for i in xrange(len(t.elems)):
            e = t.elems[i]
            try:
                mtr = metaclass2.matrixForElement(e, order)
                if mtr == None:
                    mp = metaclass2.mapForElement(e, order)
                else:
                    M = mtr * U
                    mp = metaclass2.matrixToMap(M, XYZD)

                # Apply misalignments here if any
                if terr is not None:
                    if isinstance(terr, metaclass2.twiss2):
                        dx = terr.elems[i].DX
                        dy = terr.elems[i].DY
                        if dx != 0:
                            mp = mp(x=X + dx)
                        if dy != 0:
                            mp = mp(y=Y + dy)
                    else:
                        raise TypeError(
                            "The 'align' attribute has to be of the type 'twiss2'."
                        )

                # Combine the map with everything else
                R = mp * R
            except Exception:
                print "No implementation for element: ", e.NAME, e.KEYWORD

        for k in XYZD:
            self[k] = R[k]

        # Reorder the variables so that they are always in the same order
        # This is important for comparision operations but also for all
        # the other methods
        self.reorder(XYZD)
Example #6
0
  def fromTwiss(self, t, terr=None, order=6):
    R = generateDefaultMap(order=order)
    U = generateDefaultMatrix(order=order)
    for i in xrange(len(t.elems)):
      e = t.elems[i]
      try:
        mtr = metaclass2.matrixForElement(e, order)
        if mtr == None:
          mp = metaclass2.mapForElement(e, order)
        else:
          M = mtr * U
          mp = metaclass2.matrixToMap(M, XYZD)

        # Apply misalignments here if any
        if terr is not None:
          if isinstance(terr, metaclass2.twiss2):
            dx = terr.elems[i].DX
            dy = terr.elems[i].DY
            if dx != 0:
              mp = mp(x=X+dx)
            if dy != 0:
              mp = mp(y=Y+dy)
          else:
            raise TypeError("The 'align' attribute has to be of the type 'twiss2'.")

        # Combine the map with everything else
        R = mp * R
      except Exception:
        print "No implementation for element: ", e.NAME, e.KEYWORD

    for k in XYZD:
      self[k] = R[k]

    # Reorder the variables so that they are always in the same order
    # This is important for comparision operations but also for all
    # the other methods
    self.reorder(XYZD)