def testReadH5(self):
        """ Testing the read function and conversion of openpmd input to native beam file."""

        # Construct the object.
        xfel_source = GenesisPhotonSource(parameters=None, input_path=TestUtilities.generateTestFilePath('simData_8000.h5'), output_path='FELsource_out.h5')

        xfel_source._readH5()
        self.assertTrue( hasattr( xfel_source, '_GenesisPhotonSource__input_data' ) )
    def testConstructionNativeBeamFile(self):
        """ Testing the construction of the class with a native genesis beam file."""

        # Construct the object.
        xfel_source = GenesisPhotonSource(parameters=None, input_path=TestUtilities.generateTestFilePath('genesis_beam.dat'))

        self.assertIsInstance(xfel_source, AbstractPhotonSource)
        self.assertIsInstance(xfel_source, GenesisPhotonSource)
    def testConstructionPicH5(self):
        """ Testing the construction of the class with a given PIC snapshot. """

        # Construct the object.
        xfel_source = GenesisPhotonSource(parameters=None, input_path=TestUtilities.generateTestFilePath('simData_8000.h5'))

        self.assertIsInstance(xfel_source, AbstractPhotonSource)
        self.assertIsInstance(xfel_source, GenesisPhotonSource)
    def testPrepareRun(self):
        """ Tests the method that sets up input files and directories for a genesis run. """

        # Ensure proper cleanup.
        self.__dirs_to_remove.append('source')

        # Get SASE1 template undulator object.
        undulator = sase1.und
        photon_energy = 200.0 # eV
        electron_energy = 16.0e-3 # GeV
        undulator.Kx = Ephoton2K(photon_energy, undulator.lperiod, electron_energy)

        # Calculate undulator-radiator parameters.
        undulator_parameters = UndulatorParameters(undulator, electron_energy)


        # Setup parameters.
        parameters_dict = {
                'time_averaging_window': 1e-8,
                'is_time_dependent': False,
                'undulator_parameters': undulator_parameters,
                }

        # Construct the object.
        xfel_source = GenesisPhotonSource(parameters=parameters_dict, input_path=TestUtilities.generateTestFilePath('simData_8000.h5'), output_path='source')

        # Read the input distribution.
        xfel_source._readH5()

        # Prepare the run.
        xfel_source._prepareGenesisRun()

        # Check generated data.
        self.assertIsInstance( xfel_source._GenesisPhotonSource__genesis_input, genesis.GenesisInput )
        self.assertIsInstance( xfel_source._GenesisPhotonSource__genesis_beam, genesis.GenesisBeam )
    def testBackengine(self):
        """ Testing the read function and conversion of openpmd input to native beam file."""

        # Ensure proper cleanup.
        #self.__dirs_to_remove.append('source')

        # Get SASE1 template undulator object.
        undulator = sase1.und
        photon_energy = 200.0  # eV
        electron_energy = 16.0e-3  # GeV
        undulator.Kx = Ephoton2K(photon_energy, undulator.lperiod,
                                 electron_energy)

        # Calculate undulator-radiator parameters.
        undulator_parameters = UndulatorParameters(undulator, electron_energy)

        # Setup parameters.
        parameters_dict = {
            'time_averaging_window': 1e-8,
            'is_time_dependent': False,
            'undulator_parameters': undulator_parameters,
        }

        # Construct the object.
        xfel_source = GenesisPhotonSource(
            parameters=parameters_dict,
            input_path=TestUtilities.generateTestFilePath('simData_8000.h5'),
            output_path='source')

        # Read the input distribution.
        xfel_source._readH5()

        # Prepare the run.
        xfel_source._prepareGenesisRun()

        # This should not throw.
        try:
            xfel_source.backengine()
            throws = False
        except:
            throws = True

        self.assertFalse(throws)