Example #1
0
def communicateWavefront(self, wavefronts, distribution_plan, global_index, root):
    communicator = distribution_plan.communicator()
    n_rank = distribution_plan.myRank()

    if n_rank != root:
        if global_index in distribution_plan.localRows():
            local_index = distribution_plan.globalToLocalIndex(global_index)
            wavefront = wavefronts[local_index]
            as_array = wavefront.asNumpyArray()

            for i_element, element in enumerate(as_array):
                communicator.send(element, dest=root, tag=i_element)

        return None
    else:
        if global_index in distribution_plan.localRows():
            local_index = distribution_plan.globalToLocalIndex(global_index)
            wavefront = wavefronts[local_index]
        else:
            as_array = list()
            i_source = distribution_plan.rankByGlobalIndex(global_index)
            for i_element in range(3):
                as_array.append(communicator.recv(source=i_source, tag=i_element))
            wavefront = NumpyWavefront.fromNumpyArray(as_array[0],as_array[1],as_array[2])

        return wavefront
Example #2
0
def communicateWavefront(self, wavefronts, distribution_plan, global_index,
                         root):
    communicator = distribution_plan.communicator()
    n_rank = distribution_plan.myRank()

    if n_rank != root:
        if global_index in distribution_plan.localRows():
            local_index = distribution_plan.globalToLocalIndex(global_index)
            wavefront = wavefronts[local_index]
            as_array = wavefront.asNumpyArray()

            for i_element, element in enumerate(as_array):
                communicator.send(element, dest=root, tag=i_element)

        return None
    else:
        if global_index in distribution_plan.localRows():
            local_index = distribution_plan.globalToLocalIndex(global_index)
            wavefront = wavefronts[local_index]
        else:
            as_array = list()
            i_source = distribution_plan.rankByGlobalIndex(global_index)
            for i_element in range(3):
                as_array.append(
                    communicator.recv(source=i_source, tag=i_element))
            wavefront = NumpyWavefront.fromNumpyArray(as_array[0], as_array[1],
                                                      as_array[2])

        return wavefront
    def fromDictionary(data_dict):

        sigma_matrix = SigmaMatrix.fromNumpyArray(data_dict["sigma_matrix"])
        undulator = undulator_from_numpy_array(data_dict["undulator"])
        detuning_parameter = data_dict["detuning_parameter"][0]
        energy = data_dict["energy"][0]

        electron_beam_energy = data_dict["electron_beam_energy"][0]


        np_wavefront_0=data_dict["wavefront_0"]
        np_wavefront_1=data_dict["wavefront_1"]
        np_wavefront_2=data_dict["wavefront_2"]
        wavefront = NumpyWavefront.fromNumpyArray(np_wavefront_0, np_wavefront_1, np_wavefront_2)

        try:
            np_exit_slit_wavefront_0=data_dict["exit_slit_wavefront_0"]
            np_exit_slit_wavefront_1=data_dict["exit_slit_wavefront_1"]
            np_exit_slit_wavefront_2=data_dict["exit_slit_wavefront_2"]
            exit_slit_wavefront = NumpyWavefront.fromNumpyArray(np_exit_slit_wavefront_0, np_exit_slit_wavefront_1, np_exit_slit_wavefront_2)
        except:
            exit_slit_wavefront = wavefront.clone()

        try:
            weighted_fields = data_dict["weighted_fields"]
        except:
            weighted_fields = None



        srw_wavefront_rx=data_dict["srw_wavefront_rx"][0]
        srw_wavefront_ry=data_dict["srw_wavefront_ry"][0]

        srw_wavefront_drx = data_dict["srw_wavefront_drx"][0]
        srw_wavefront_dry = data_dict["srw_wavefront_dry"][0]

        info_string = str(data_dict["info"])
        info = AutocorrelationInfo.fromString(info_string)


        sampling_factor=data_dict["sampling_factor"][0]
        minimal_size=data_dict["minimal_size"][0]

        beam_energies = data_dict["beam_energies"]

        static_electron_density = data_dict["static_electron_density"]
        coordinates_x = data_dict["twoform_0"]
        coordinates_y = data_dict["twoform_1"]
        diagonal_elements = data_dict["twoform_2"]
        eigenvalues = data_dict["twoform_3"]
        twoform_vectors = data_dict["twoform_4"]

        twoform = Twoform(coordinates_x, coordinates_y, diagonal_elements, eigenvalues, twoform_vectors)

        eigenvector_errors = data_dict["twoform_5"]
        twoform.setEigenvectorErrors(eigenvector_errors)

        af = AutocorrelationFunction(sigma_matrix, undulator, detuning_parameter,energy,electron_beam_energy,
                                     wavefront,exit_slit_wavefront,srw_wavefront_rx, srw_wavefront_drx, srw_wavefront_ry, srw_wavefront_dry,
                                     sampling_factor,minimal_size, beam_energies, weighted_fields,
                                     static_electron_density, twoform,
                                     info)

        return af
Example #4
0
    def fromDictionary(data_dict):

        sigma_matrix = SigmaMatrix.fromNumpyArray(data_dict["sigma_matrix"])
        undulator = undulator_from_numpy_array(data_dict["undulator"])
        detuning_parameter = data_dict["detuning_parameter"][0]
        energy = data_dict["energy"][0]

        electron_beam_energy = data_dict["electron_beam_energy"][0]

        np_wavefront_0 = data_dict["wavefront_0"]
        np_wavefront_1 = data_dict["wavefront_1"]
        np_wavefront_2 = data_dict["wavefront_2"]
        wavefront = NumpyWavefront.fromNumpyArray(np_wavefront_0,
                                                  np_wavefront_1,
                                                  np_wavefront_2)

        try:
            np_exit_slit_wavefront_0 = data_dict["exit_slit_wavefront_0"]
            np_exit_slit_wavefront_1 = data_dict["exit_slit_wavefront_1"]
            np_exit_slit_wavefront_2 = data_dict["exit_slit_wavefront_2"]
            exit_slit_wavefront = NumpyWavefront.fromNumpyArray(
                np_exit_slit_wavefront_0, np_exit_slit_wavefront_1,
                np_exit_slit_wavefront_2)
        except:
            exit_slit_wavefront = wavefront.clone()

        try:
            weighted_fields = data_dict["weighted_fields"]
        except:
            weighted_fields = None

        srw_wavefront_rx = data_dict["srw_wavefront_rx"][0]
        srw_wavefront_ry = data_dict["srw_wavefront_ry"][0]

        srw_wavefront_drx = data_dict["srw_wavefront_drx"][0]
        srw_wavefront_dry = data_dict["srw_wavefront_dry"][0]

        info_string = str(data_dict["info"])
        info = AutocorrelationInfo.fromString(info_string)

        sampling_factor = data_dict["sampling_factor"][0]
        minimal_size = data_dict["minimal_size"][0]

        beam_energies = data_dict["beam_energies"]

        static_electron_density = data_dict["static_electron_density"]
        coordinates_x = data_dict["twoform_0"]
        coordinates_y = data_dict["twoform_1"]
        diagonal_elements = data_dict["twoform_2"]
        eigenvalues = data_dict["twoform_3"]
        twoform_vectors = data_dict["twoform_4"]

        twoform = Twoform(coordinates_x, coordinates_y, diagonal_elements,
                          eigenvalues, twoform_vectors)

        eigenvector_errors = data_dict["twoform_5"]
        twoform.setEigenvectorErrors(eigenvector_errors)

        af = AutocorrelationFunction(
            sigma_matrix, undulator, detuning_parameter, energy,
            electron_beam_energy, wavefront, exit_slit_wavefront,
            srw_wavefront_rx, srw_wavefront_drx, srw_wavefront_ry,
            srw_wavefront_dry, sampling_factor, minimal_size, beam_energies,
            weighted_fields, static_electron_density, twoform, info)

        return af