def get_virtual_source():
    return WiserOpticalElement(
        name="Virtual source",
        isSource=True,
        native_CoreOptics=Optics.SourceVirtual(),
        native_PositioningDirectives=Foundation.PositioningDirectives(
            ReferTo=Foundation.PositioningDirectives.ReferTo.AbsoluteReference,
            XYCentre=[0.0, 0.0],
            Angle=0.0))
def get_dummy_source(wofry_wavefront):
    return Foundation.OpticalElement(
        Name="Wofry Source",
        IsSource=True,
        CoreOpticsElement=DummyElement(wofry_wavefront=wofry_wavefront),
        PositioningDirectives=Foundation.PositioningDirectives(
            ReferTo=Foundation.PositioningDirectives.ReferTo.AbsoluteReference,
            XYCentre=[0.0, 0.0],
            Angle=0.0))
def get_wavefront_source(wofry_wavefront):
    mesh_x = wofry_wavefront.get_abscissas()

    return WiserOpticalElement(
        name="Wavefront Source",
        isSource=False,
        native_CoreOptics=Optics.SourceWavefront(
            Lambda=wofry_wavefront.get_wavelength(),
            L=numpy.abs(mesh_x[0]) + numpy.abs(mesh_x[-1]),
            Field=wofry_wavefront.get_amplitude() *
            numpy.exp(1j * wofry_wavefront.get_phase()),
            Orientation=Optics.OPTICS_ORIENTATION.ISOTROPIC),
        native_PositioningDirectives=Foundation.PositioningDirectives(
            ReferTo=Foundation.PositioningDirectives.ReferTo.Source,
            PlaceWhat='centre',
            PlaceWhere='centre',
            Distance=4))
    PropagationManager.Instance().add_propagator(WiserPropagator())

    tl.Debug.On = True
    N = 3000
    UseCustomSampling = True
    # SOURCE
    #==========================================================================
    Lambda = 2e-9
    Waist0 = 180e-6  #Fermi.Waist0E(Lambda)

    ww_s = WiserOpticalElement(
        name='FEL2 source',
        boundary_shape=None,
        isSource=True,
        native_CoreOptics=Optics.SourceGaussian(Lambda=Lambda, Waist0=Waist0),
        native_PositioningDirectives=Foundation.PositioningDirectives(
            ReferTo='absolute', XYCentre=[0, 0], Angle=pi / 4. - AngleGrazing))

    s = ww_s.native_optical_element  # Wiser optical element
    s.ComputationSettings.UseSmallDisplacements = True
    s.Orientation = Optics.OPTICS_ORIENTATION.ANY
    s.CoreOptics.SmallDisplacements.Long = DeltaSourceList[0]
    s.CoreOptics.SmallDisplacements.Rotation = 0.

    # PM1 (h)
    #==========================================================================
    ww_pm1_h = WiserOpticalElement(
        name='pm1h',
        boundary_shape=None,
        native_CoreOptics=Optics.MirrorPlane(L=L, AngleGrazing=AngleGrazing),
        native_PositioningDirectives=Foundation.PositioningDirectives(
            ReferTo='upstream',