Пример #1
0
    def test_copy(self):
        K = 1.87
        lambda_u = 0.035
        L = 0.035 * 14
        E=1.3
        I=1.0
        undulator = Undulator(K=K, period_length=lambda_u, length=L)
        beam=ElectronBeam(Electron_energy=E, I_current=I)
        source=SourceUndulatorPlane(undulator=undulator, electron_beam=beam)

        source2=source.copy()
        source2.electron_beam.I_current=0.3
        self.assertEqual(source.I_current(),1.0)
        self.assertEqual(source2.I_current() ,0.3)

        self.assertAlmostEqual(source.harmonic_frequency(1)/1e17, 2.5346701615509917,5)
        self.assertAlmostEqual(source.Lorentz_factor(), 2544.0367765521196,2 )
        self.assertAlmostEqual(source.electron_speed(), 0.99999992274559524,5)
        self.assertEqual(source.magnetic_structure.period_number(), 14)
        self.assertAlmostEqual(source.choose_distance_automatic(2),49.000000000000,10 )
Пример #2
0
    def test_copy(self):
        K = 1.87
        lambda_u = 0.035
        L = 0.035 * 14
        E = 1.3
        I = 1.0
        undulator = Undulator(K=K, period_length=lambda_u, length=L)
        beam = ElectronBeam(Electron_energy=E, I_current=I)
        source = SourceUndulatorPlane(undulator=undulator, electron_beam=beam)

        source2 = source.copy()
        source2.electron_beam.I_current = 0.3
        self.assertEqual(source.I_current(), 1.0)
        self.assertEqual(source2.I_current(), 0.3)

        self.assertAlmostEqual(
            source.harmonic_frequency(1) / 1e17, 2.5346701615509917, 5)
        self.assertAlmostEqual(source.Lorentz_factor(), 2544.0367765521196, 2)
        self.assertAlmostEqual(source.electron_speed(), 0.99999992274559524, 5)
        self.assertEqual(source.magnetic_structure.period_number(), 14)
        self.assertAlmostEqual(source.choose_distance_automatic(2),
                               49.000000000000, 10)
Пример #3
0
def create_simulation(magnetic_structure,
                      electron_beam,
                      magnetic_field=None,
                      photon_energy=None,
                      traj_method=TRAJECTORY_METHOD_ANALYTIC,
                      Nb_pts_trajectory=None,
                      rad_method=RADIATION_METHOD_APPROX_FARFIELD,
                      Nb_pts_radiation=101,
                      initial_condition=None,
                      distance=None,
                      XY_are_list=False,
                      X=None,
                      Y=None):

    if type(magnetic_structure) == Undulator:
        source = SourceUndulatorPlane(undulator=magnetic_structure,
                                      electron_beam=electron_beam,
                                      magnetic_field=magnetic_field)
        print("Calculating undulator source...")
    elif type(magnetic_structure) == BM:
        source = SourceBendingMagnet(magnetic_structure=magnetic_structure,
                                     electron_beam=electron_beam,
                                     magnetic_field=magnetic_field)
        print("Calculating bending magnet source...")
    else:
        raise Exception('magnet type unknown')

    if photon_energy == None:
        omega = source.choose_photon_frequency()
    else:
        omega = photon_energy * eV_to_J / codata.hbar

    #
    # XY grid
    #
    if distance == None and (rad_method == RADIATION_METHOD_NEAR_FIELD):
        distance = source.choose_distance_automatic(2)

    if Nb_pts_trajectory == None:
        Nb_pts_trajectory = int(
            source.choose_nb_pts_trajectory(0.01, photon_frequency=omega))

    if X is None or Y is None:
        if (X != None):
            Y = X
        elif Y != None:
            X = Y
        else:
            theta_max = source.choose_angle_deflection_max()
            if distance == None:
                X_max = theta_max
                Y_max = theta_max
            else:
                X_max = distance * theta_max
                Y_max = distance * theta_max
            X = np.linspace(0.0, X_max, Nb_pts_radiation)
            Y = np.linspace(0.0, Y_max, Nb_pts_radiation)

    if type(X) == float:
        X = np.linspace(0.0, X, Nb_pts_radiation)
    if type(Y) == float:
        Y = np.linspace(0.0, Y, Nb_pts_radiation)

    # if X.shape != Y.shape :
    #     raise Exception('X and Y must have the same shape')
    Nb_pts_radiation = X.size  # len(X.flatten())

    #print('step 1')
    traj_fact = TrajectoryFactory(Nb_pts=Nb_pts_trajectory,
                                  method=traj_method,
                                  initial_condition=initial_condition)

    if (traj_fact.initial_condition == None):
        # print('crearte initial cond automat')
        traj_fact.initial_condition = source.choose_initial_contidion_automatic(
        )

    #print('step 2')

    rad_fact = RadiationFactory(method=rad_method, photon_frequency=omega)

    #print('step 3')
    trajectory = traj_fact.create_from_source(source=source)
    #print('step 4')
    radiation = rad_fact.create_for_one_relativistic_electron(
        trajectory=trajectory,
        source=source,
        XY_are_list=XY_are_list,
        distance=distance,
        X=X,
        Y=Y)

    #print('step 5')
    return Simulation(source=source,
                      trajectory_fact=traj_fact,
                      radiation_fact=rad_fact,
                      trajectory=trajectory,
                      radiation=radiation)
Пример #4
0
def create_simulation(magnetic_structure,electron_beam, magnetic_field=None, photon_energy=None,
                      traj_method=TRAJECTORY_METHOD_ANALYTIC,Nb_pts_trajectory=None,
                      rad_method=RADIATION_METHOD_APPROX_FARFIELD, Nb_pts_radiation=101,
                      initial_condition=None, distance=None,XY_are_list=False,X=None,Y=None) :

    if type(magnetic_structure)==Undulator :
        source=SourceUndulatorPlane(undulator=magnetic_structure,
                                    electron_beam=electron_beam, magnetic_field=magnetic_field)
        print("Calculating undulator source...")
    elif type(magnetic_structure)==BM:
        source = SourceBendingMagnet(magnetic_structure=magnetic_structure,
                                      electron_beam=electron_beam, magnetic_field=magnetic_field)
        print("Calculating bending magnet source...")
    else :
        raise Exception('magnet type unknown')

    if photon_energy==None :
        omega=source.choose_photon_frequency()
    else :
        omega = photon_energy * eV_to_J / codata.hbar

    #
    # XY grid
    #
    if distance==None and (rad_method==RADIATION_METHOD_NEAR_FIELD) :
        distance=source.choose_distance_automatic(2)

    if Nb_pts_trajectory==None :
        Nb_pts_trajectory = int(source.choose_nb_pts_trajectory(0.01,photon_frequency=omega))

    if X is None or Y is None :
        if (X != None) :
            Y=X
        elif Y != None :
            X=Y
        else :
            theta_max=source.choose_angle_deflection_max()
            if distance==None :
                X_max=theta_max
                Y_max=theta_max
            else :
                X_max = distance * theta_max
                Y_max = distance * theta_max
            X = np.linspace(0.0, X_max, Nb_pts_radiation)
            Y = np.linspace(0.0, Y_max, Nb_pts_radiation)

    if type(X) == float:
        X= np.linspace(0.0, X, Nb_pts_radiation)
    if type(Y) == float:
        Y = np.linspace(0.0, Y, Nb_pts_radiation)

    # if X.shape != Y.shape :
    #     raise Exception('X and Y must have the same shape')
    Nb_pts_radiation = X.size # len(X.flatten())

    #print('step 1')
    traj_fact=TrajectoryFactory(Nb_pts=Nb_pts_trajectory,method=traj_method,initial_condition=initial_condition)

    if (traj_fact.initial_condition == None):
        # print('crearte initial cond automat')
        traj_fact.initial_condition = source.choose_initial_contidion_automatic()



    #print('step 2')

    rad_fact=RadiationFactory(method=rad_method, photon_frequency=omega)


    #print('step 3')
    trajectory=traj_fact.create_from_source(source=source)
    #print('step 4')
    radiation = rad_fact.create_for_one_relativistic_electron(trajectory=trajectory, source=source, XY_are_list=XY_are_list,
                                                              distance=distance, X=X, Y=Y)

    #print('step 5')
    return Simulation(source=source, trajectory_fact=traj_fact,
                               radiation_fact=rad_fact, trajectory=trajectory, radiation=radiation)