Beispiel #1
0
    def coherentModeAsWavefront(self, i_mode):
        mode = self.coherentMode(i_mode)
        e_field = np.zeros((1, mode.shape[0], mode.shape[1], 2),
                           dtype=mode.dtype)
        e_field[0, :, :, 0] = mode[:, :]

        e_field[abs(e_field) < 0.00001] = 0.0

        wavefront = NumpyWavefront(
            e_field,
            self.xCoordinates().min(),
            self.xCoordinates().max(),
            self.yCoordinates().min(),
            self.yCoordinates().max(),
            self._wavefront.z(),
            self._wavefront.energies(),
        )
        return wavefront
Beispiel #2
0
    def _buildForXY(self, electron_beam, x_0, y_0, xp_0, yp_0, z, X, Y):

        #TODO: X dimension equals Y dimension?
        Y = X

        beam = ElectronBeam(Electron_energy=electron_beam.energy(),
                            I_current=electron_beam.averageCurrent())
        undulator = Undulator(K=self._undulator.K_vertical(),
                              period_length=self._undulator.periodLength(),
                              length=self._undulator.length())

        initial_conditions = SourceUndulatorPlane(
            undulator=undulator, electron_beam=beam,
            magnetic_field=None).choose_initial_contidion_automatic()

        v_z = initial_conditions[2]

        initial_conditions[0] = xp_0 * speed_of_light
        initial_conditions[1] = yp_0 * speed_of_light
        initial_conditions[2] = np.sqrt(beam.electron_speed()**2 - xp_0**2 -
                                        yp_0**2) * speed_of_light
        initial_conditions[3] = x_0
        initial_conditions[4] = y_0

        if self._source_position == VIRTUAL_SOURCE_CENTER:
            initial_conditions[5] = 0.0
        print("initial cond:", initial_conditions)

        simulation = create_simulation(
            magnetic_structure=undulator,
            electron_beam=beam,
            traj_method=TRAJECTORY_METHOD_ODE,
            rad_method=RADIATION_METHOD_NEAR_FIELD,  #RADIATION_METHOD_FARFIELD,
            distance=z,
            X=X,
            Y=Y,
            photon_energy=self._photon_energy,
            initial_condition=initial_conditions)
        #simulation.trajectory.plot_3D()
        #simulation.trajectory.plot()
        #simulation.radiation.plot()

        electrical_field = simulation.radiation_fact.calculate_electrical_field(
            trajectory=simulation.trajectory,
            source=simulation.source,
            distance=simulation.radiation.distance,
            X_array=simulation.radiation.X,
            Y_array=simulation.radiation.Y)

        efield = electrical_field.electrical_field()[np.newaxis, :, :, :]
        efield = efield[:, :, :, 0:2]

        calc_wavefront = NumpyWavefront(
            e_field=efield,
            x_start=X.min(),
            x_end=X.max(),
            y_start=Y.min(),
            y_end=Y.max(),
            z=z,
            energies=np.array([self._photon_energy]),
        )

        #calc_wavefront.showEField()

        self._last_simulation = simulation
        self._last_initial_conditions = initial_conditions.copy()

        return calc_wavefront