Exemple #1
0
def define_beamline():
    # initialize elements
    oe_list = []

    oe1 = Shadow.OE()
    oe_list.append(oe1)
    oe2 = Shadow.OE()
    oe_list.append(oe2)

    # Define variables. See https://raw.githubusercontent.com/oasys-kit/shadow3/master/docs/oe.nml

    oe1.DUMMY = 100.0
    oe1.FHIT_C = 1
    oe1.FWRITE = 1
    oe1.RLEN1 = 5e-05
    oe1.RLEN2 = 5e-05
    oe1.RWIDX1 = 2e-05
    oe1.RWIDX2 = 2e-05
    oe1.T_IMAGE = 6.0
    oe1.T_INCIDENCE = 88.8
    oe1.T_REFLECTION = 88.8

    oe2.DUMMY = 100.0
    oe2.FHIT_C = 1
    oe2.FWRITE = 1
    oe2.RLEN1 = 0.00015
    oe2.RLEN2 = 0.00015
    oe2.RWIDX1 = 0.0001
    oe2.RWIDX2 = 0.0001
    oe2.T_IMAGE = 100.0
    oe2.T_INCIDENCE = 89.8281126615
    oe2.T_REFLECTION = 89.8281126615

    return oe_list
def setShadowBeamline():
    hfm = sd.OE().setFrameOfReference(4200., 1300., 89.8567963, 89.8567963,
                                      90.)
    hfm = hfm.setEllipsoidAuto().setCylindric(0.)
    hfm = hfm.setReflector().setScreens(
    )  #.setCrystal(file_refl='Si111_thick')
    #.setAutoTuning(0,12663.6,5000.)
    #small deviation from default
    hfm.I_SLIT[0] = 1
    hfm.SL_DIS[0] = 1300.0
    hfm.RX_SLIT[0] = 1.0
    hfm.RZ_SLIT[0] = 3.0e-1
    #no ripple now
    #hfm = hfm.setRipple(2,np.array([0.,0.,0.,3.8e-8,1.,0.]),"mistral_80cm_4mm-sample.dat")

    kbv = sd.OE().setFrameOfReference(1100., 25., 89.8567963, 89.8567963, 90.)
    kbv = kbv.setEllipsoidAuto([6475., 100., 89.8567963]).setCylindric(0.)
    #kbv = kbv.setEllipsoidAuto([6700.,100.,89.8567963]).setCylindric(0.)
    kbv = kbv.setReflector(
    )  #.setDimensions(params=25.0*np.ones(4))#.setCrystal(file_refl='Si111_thick')
    #.setAutoTuning(0,12663.6,5000.)
    #no ripple now
    #kbv = kbv.setRipple(2,np.array([0.,0.,0.,3.8e-8,1.,0.]),"mistral_80cm_4mm-sample.dat")

    kbh = sd.OE().setFrameOfReference(25., 50., 89.8567963, 89.8567963, -90.)
    kbh = kbh.setEllipsoidAuto([1150., 50., 89.8567963]).setCylindric(0.)
    kbh = kbh.setReflector(
    )  #.setDimensions(params=25.0*np.ones(4))#.setCrystal(file_refl='Si111_thick')
    #.setAutoTuning(0,12663.6,5000.)
    #no ripple now
    #kbv = kbv.setRipple(2,np.array([0.,0.,0.,3.8e-8,1.,0.]),"mistral_80cm_4mm-sample.dat")

    return [hfm, kbv, kbh]
Exemple #3
0
def run_shadow_source():
    #
    # Python script to run shadow3. Created automatically with ShadowTools.make_python_script_from_list().
    #
    import Shadow
    import numpy

    # write (1) or not (0) SHADOW files start.xx end.xx star.xx
    iwrite = 0

    #
    # initialize shadow3 source (oe0) and beam
    #
    beam = Shadow.Beam()
    oe0 = Shadow.Source()
    oe1 = Shadow.OE()
    oe2 = Shadow.OE()

    #
    # Define variables. See meaning of variables in:
    #  https://raw.githubusercontent.com/srio/shadow3/master/docs/source.nml
    #  https://raw.githubusercontent.com/srio/shadow3/master/docs/oe.nml
    #

    oe0.FDISTR = 1
    oe0.FSOUR = 0
    oe0.F_PHOT = 0
    oe0.HDIV1 = 0.005
    oe0.HDIV2 = 0.005
    oe0.IDO_VX = 0
    oe0.IDO_VZ = 0
    oe0.IDO_X_S = 0
    oe0.IDO_Y_S = 0
    oe0.IDO_Z_S = 0
    oe0.NPOINT = 10000
    oe0.PH1 = 1000.0
    oe0.VDIV1 = 0.05
    oe0.VDIV2 = 0.05


    # Run SHADOW to create the source

    if iwrite:
        oe0.write("start.00")

    beam.genSource(oe0)

    if iwrite:
        oe0.write("end.00")
        beam.write("begin.dat")

    #
    # run optical element 1

    return beam
Exemple #4
0
def define_beamline():
    # initialize elements
    oe_list = []

    
    oe1 = Shadow.OE()
    oe_list.append(oe1)

    # Define variables. See https://raw.githubusercontent.com/oasys-kit/shadow3/master/docs/oe.nml


    oe1.DUMMY = 100.0
    oe1.FMIRR = 7
    oe1.FWRITE = 1
    oe1.F_DEFAULT = 0
    oe1.SIMAG = 1000.0
    oe1.SSOUR = 10.0
    oe1.THETA = 88.8
    oe1.T_IMAGE = 10.0
    oe1.T_INCIDENCE = 88.8
    oe1.T_REFLECTION = 88.8
    oe1.T_SOURCE = 20.0



    return oe_list
    def create_hyperboloid_grating(cls):
        self = ShadowOpticalElement(oe=Shadow.OE())

        self._oe.FMIRR = 7
        self._oe.F_GRATING = 1
        self._oe.F_REFRAC = 0

        return self
    def create_paraboloid_mirror(cls):
        self = ShadowOpticalElement(oe=Shadow.OE())

        self._oe.FMIRR = 4
        self._oe.F_CRYSTAL = 0
        self._oe.F_REFRAC = 0

        return self
    def create_conic_coefficients_refractor(cls):
        self = ShadowOpticalElement(oe=Shadow.OE())

        self._oe.FMIRR = 10
        self._oe.F_CRYSTAL = 0
        self._oe.F_REFRAC = 1

        return self
    def create_toroidal_grating(cls):
        self = ShadowOpticalElement(oe=Shadow.OE())

        self._oe.FMIRR = 3
        self._oe.F_GRATING = 1
        self._oe.F_REFRAC = 0

        return self
    def create_conic_coefficients_grating(cls):
        self = ShadowOpticalElement(oe=Shadow.OE())

        self._oe.FMIRR = 10
        self._oe.F_GRATING = 1
        self._oe.F_REFRAC = 0

        return self
    def create_toroidal_mirror(cls):
        self = ShadowOpticalElement(oe=Shadow.OE())

        self._oe.FMIRR = 3
        self._oe.F_CRYSTAL = 0
        self._oe.F_REFRAC = 0

        return self
Exemple #11
0
def shadow_ellip_mir_trace(beam,
                           oe_num=1,
                           alpha=0.0,
                           t_source=2850.0,
                           t_image=0.0,
                           ssour=2850.0,
                           simag=900.0,
                           theta=87.9998043372,
                           offz=0.0,
                           mirinfo=0):
    """
    This function propagates an input
    beam object through an elliptical
    mirror element.
    beam: shadow beam object
    oe_num: optical element sequence number along beamline (1, 2, 3,...)
    t_source: source plane distance (drift length before mirror) - assumedly in cm
    t_image: image plane distance (drift length after mirror) - assumedly in cm
    ssour: distance from source to mirror center [cm] (object side focal distance)
    simag: distance from mirror center to second focus [cm] (image side focal distance)
    theta: incidence/reflection angle [deg]
    offz: mirror offset [cm]
    mirinfo: print mirror info; 0 = off, 1 = on
    """

    oe = Shadow.OE()
    oe.DUMMY = 100.0
    oe.FMIRR = 2  # 2: ellipsoidal, 3: toroidal, 10: conic with external coefficients
    oe.ALPHA = alpha
    oe.FHIT_C = 1
    oe.F_EXT = 0  # toggle auto-compute mirror parameters
    oe.F_DEFAULT = 0
    oe.SSOUR = ssour
    oe.SIMAG = simag
    oe.THETA = theta
    oe.FCYL = 1
    oe.FSHAPE = 2
    oe.RWIDX1 = 0.05  # added from oasys # X(+) Half Width / Int Maj Ax [m]
    oe.RWIDX2 = 0.05  # changed from oasys # X(-) Half Width / Int Maj Ax [m]
    oe.RLEN1 = 0.11  # added from oasys # Y(+) Half Width / Int Min Ax [m]
    oe.RLEN2 = 0.11  # changed from oasys # Y(-) Half Width / Int Min Ax [m]
    oe.T_INCIDENCE = theta
    oe.T_REFLECTION = theta
    oe.FWRITE = 0
    oe.T_IMAGE = t_image  # Image plane distance (drift length after mirror)
    oe.T_SOURCE = t_source  # Source plane distance (drift length before mirror)
    oe.F_MOVE = 1
    oe.OFFX = 0.0
    oe.OFFZ = offz
    #oe.Y_ROT = 0
    #oe.Z_ROT = 0
    if mirinfo == 1:
        pkdlog(oe.mirinfo())

    beam.traceOE(oe, oe_num)
    return beam
    def create_empty_oe(cls):
        self = ShadowOpticalElement(oe=Shadow.OE())

        self._oe.FMIRR = 5
        self._oe.F_CRYSTAL = 0
        self._oe.F_REFRAC = 2
        self._oe.F_SCREEN = 0
        self._oe.N_SCREEN = 0

        return self
    def create_screen_slit(cls):
        self = ShadowOpticalElement(oe=Shadow.OE())

        self._oe.FMIRR = 5
        self._oe.F_CRYSTAL = 0
        self._oe.F_REFRAC = 2
        self._oe.F_SCREEN = 1
        self._oe.N_SCREEN = 1

        return self
    def create_conic_coefficients_crystal(cls):
        self = ShadowOpticalElement(oe=Shadow.OE())

        self._oe.FMIRR = 10
        self._oe.F_CRYSTAL = 1
        self._oe.FILE_REFL = bytes("", 'utf-8')
        self._oe.F_REFLECT = 0
        self._oe.F_BRAGG_A = 0
        self._oe.A_BRAGG = 0.0
        self._oe.F_REFRAC = 0

        return self
    def create_hyperboloid_crystal(cls):
        self = ShadowOpticalElement(oe=Shadow.OE())

        self._oe.FMIRR = 7
        self._oe.F_CRYSTAL = 1
        self._oe.FILE_REFL = bytes("", 'utf-8')
        self._oe.F_REFLECT = 0
        self._oe.F_BRAGG_A = 0
        self._oe.A_BRAGG = 0.0
        self._oe.F_REFRAC = 0

        return self
Exemple #16
0
def get_beam():

    #
    # Python script to run shadow3. Created automatically with ShadowTools.make_python_script_from_list().
    #

    # write (1) or not (0) SHADOW files start.xx end.xx star.xx
    iwrite = 0

    #
    # initialize shadow3 source (oe0) and beam
    #
    beam = Shadow.Beam()
    oe0 = Shadow.Source()
    oe1 = Shadow.OE()

    #
    # Define variables. See meaning of variables in:
    #  https://raw.githubusercontent.com/srio/shadow3/master/docs/source.nml
    #  https://raw.githubusercontent.com/srio/shadow3/master/docs/oe.nml
    #

    oe0.FSOUR = 1
    oe0.HDIV1 = 1e-08
    oe0.HDIV2 = 1e-08
    oe0.IDO_VX = 0
    oe0.IDO_VZ = 0
    oe0.IDO_X_S = 0
    oe0.IDO_Y_S = 0
    oe0.IDO_Z_S = 0
    oe0.PH1 = 1.54
    oe0.VDIV1 = 1e-08
    oe0.VDIV2 = 1e-08
    oe0.WXSOU = 0.08
    oe0.WZSOU = 0.08

    #Run SHADOW to create the source

    if iwrite:
        oe0.write("start.00")

    beam.genSource(oe0)

    if iwrite:
        oe0.write("end.00")
        beam.write("begin.dat")

    return beam
Exemple #17
0
def shadow_drift_trace(beam, length=900.0):
    """
    This function propagates an input
    beam object through a drift.
    beam: shadow beam object
    length: drift length [cm]
    """

    oe = Shadow.OE()
    oe.DUMMY = 1.0
    #oe.set_empty()
    oe.FWRITE = 3
    oe.T_IMAGE = 0.0
    oe.T_SOURCE = length
    beam.traceOE(oe, 2)

    return beam
Exemple #18
0
def create_start_files():

    # write (1) or not (0) SHADOW files start.xx end.xx star.xx
    iwrite = 1

    #
    # initialize shadow3 source (oe0) and beam
    #
    oe0 = Shadow.Source()
    oe1 = Shadow.OE()

    #
    # Define variables. See meaning of variables in:
    #  https://raw.githubusercontent.com/srio/shadow3/master/docs/source.nml
    #  https://raw.githubusercontent.com/srio/shadow3/master/docs/oe.nml
    #

    oe0.FDISTR = 3
    oe0.F_COLOR = 3
    oe0.F_PHOT = 0
    oe0.HDIV1 = 0.0
    oe0.HDIV2 = 0.0
    oe0.IDO_VX = 0
    oe0.IDO_VZ = 0
    oe0.IDO_X_S = 0
    oe0.IDO_Y_S = 0
    oe0.IDO_Z_S = 0
    oe0.PH1 = 5000.0
    oe0.PH2 = 45000.0
    oe0.SIGDIX = 8.84999972e-05
    oe0.SIGDIZ = 7.1999998e-06
    oe0.SIGMAX = 0.0057000001
    oe0.SIGMAZ = 0.00104
    oe0.VDIV1 = 0.0
    oe0.VDIV2 = 0.0

    oe1.DUMMY = 1.0
    oe1.FMIRR = 3
    oe1.T_IMAGE = 1000.0
    oe1.T_INCIDENCE = 89.885408
    oe1.T_REFLECTION = 89.885408
    oe1.T_SOURCE = 3000.0


    oe0.write("start.00")
    oe1.write("start.01")
Exemple #19
0
def test_1(capsys):
    from sys import stderr
    import Shadow
    beam = Shadow.Beam()
    src = Shadow.Source()
    assert 2 == src.FDISTR, \
        'Basic value for Source'
    # Would like to capture stdout, but too complex with extensions.
    # Probably extension needs to call a python output method.
    beam.genSource(src)
    assert 5000 == beam.nrays(), \
        'Basic method call for Beam'
    oe = Shadow.OE()
    oe.D_SPACING = 3
    assert 3 == oe.D_SPACING, \
        'Basic assignment for OE'
    beam.traceOE(oe, 1)
Exemple #20
0
def run_shadow_spherical_mirror(beam):
    #
    # Python script to run shadow3. Created automatically with ShadowTools.make_python_script_from_list().
    #
    import Shadow
    import numpy

    # write (1) or not (0) SHADOW files start.xx end.xx star.xx
    iwrite = 0

    #
    # initialize shadow3 source (oe0) and beam
    #

    oe1 = Shadow.OE()

    #
    # Define variables. See meaning of variables in:
    #  https://raw.githubusercontent.com/srio/shadow3/master/docs/source.nml
    #  https://raw.githubusercontent.com/srio/shadow3/master/docs/oe.nml
    #


    oe1.DUMMY = 100.0
    oe1.FMIRR = 1
    oe1.FWRITE = 1
    oe1.T_IMAGE = 1.0
    oe1.T_INCIDENCE = 41.0
    oe1.T_REFLECTION = 41.0
    oe1.T_SOURCE = 2.0


    #
    # run optical element 1
    #
    print("    Running optical element: %d" % (1))
    if iwrite:
        oe1.write("start.01")
    beam.traceOE(oe1, 1)
    if iwrite:
        oe1.write("end.01")
        beam.write("star.01")

    return beam
Exemple #21
0
def define_beamline():
    # initialize elements
    oe_list = []

    oe1 = Shadow.OE()
    oe_list.append(oe1)

    # Define variables. See https://raw.githubusercontent.com/oasys-kit/shadow3/master/docs/oe.nml

    oe1.DUMMY = 100.0
    oe1.FCYL = 1
    oe1.FMIRR = 4
    oe1.FWRITE = 1
    oe1.F_SIDE = 1
    oe1.T_IMAGE = 10.0
    oe1.T_INCIDENCE = 89.8281126615
    oe1.T_REFLECTION = 89.8281126615
    oe1.T_SOURCE = 20.0

    return oe_list
Exemple #22
0
def define_beamline():
    # initialize elements
    oe_list = []

    oe1 = Shadow.OE()
    oe_list.append(oe1)

    # Define variables. See https://raw.githubusercontent.com/oasys-kit/shadow3/master/docs/oe.nml

    oe1.CCC = numpy.array(
        [1.0, 1.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, -954.999, 0.0])
    oe1.DUMMY = 100.0
    oe1.FMIRR = 10
    oe1.FWRITE = 1
    oe1.F_EXT = 1
    oe1.T_IMAGE = 10.0
    oe1.T_INCIDENCE = 88.8
    oe1.T_REFLECTION = 88.8

    return oe_list
Exemple #23
0
def define_beamline():
    # initialize elements
    oe_list = []

    oe1 = Shadow.OE()
    oe_list.append(oe1)

    # Define variables. See https://raw.githubusercontent.com/oasys-kit/shadow3/master/docs/oe.nml

    oe1.CIL_ANG = 90.0
    oe1.DUMMY = 100.0
    oe1.FCYL = 1
    oe1.FMIRR = 1
    oe1.FWRITE = 1
    oe1.F_EXT = 1
    oe1.RMIRR = 0.20942419859430253
    oe1.T_IMAGE = 10.0
    oe1.T_INCIDENCE = 88.8
    oe1.T_REFLECTION = 88.8

    return oe_list
Exemple #24
0
def define_beamline():
    # initialize elements
    oe_list = []

    oe1 = Shadow.OE()
    oe_list.append(oe1)

    # Define variables. See https://raw.githubusercontent.com/oasys-kit/shadow3/master/docs/oe.nml

    oe1.DUMMY = 100.0
    oe1.FHIT_C = 1
    oe1.FILE_REFL = b'/users/srio/OASYS1.2/shadow4tests/shadow4tests/oasys_workspaces/SiC.dat'
    oe1.FWRITE = 1
    oe1.F_REFLEC = 1
    oe1.RLEN1 = 5e-05
    oe1.RLEN2 = 5e-05
    oe1.RWIDX1 = 2e-05
    oe1.RWIDX2 = 2e-05
    oe1.T_IMAGE = 6.0
    oe1.T_INCIDENCE = 88.8
    oe1.T_REFLECTION = 88.8

    return oe_list
Exemple #25
0
#
# It uses the currently defined Shadow system defined in the (existing)
# files start.xx and systemfile.dat
#
# Author: Niccolo Canestrari, Manuel Sanchew del Rio
#         ESRF (c) 2011
#

#
# import block
#
import Shadow
import sys

src = Shadow.Source()
oe1 = Shadow.OE()
beam = Shadow.Beam()
i = 0

if len(sys.argv) == 1:
    print(
        "Usage: \n  trace3_py.py -a ->creates source \n  trace3_py.py -t ->runs trace (optical system) \n  trace3_py.py -a ->runs both source and trace \n"
    )
    exit()

if sys.argv[1] == '-s':
    src.load('start.00')
    beam.genSource(src)

if sys.argv[1] == '-t':
    beam.load('begin.dat')
Exemple #26
0
def trace_shadow(beam):
    #
    # Python script to run shadow3. Created automatically with ShadowTools.make_python_script_from_list().
    #
    import Shadow
    import numpy

    # write (1) or not (0) SHADOW files start.xx end.xx star.xx
    iwrite = 0

    #

    oe1 = Shadow.OE()
    oe2 = Shadow.OE()


    oe1.DUMMY = 100.0
    oe1.FHIT_C = 1
    oe1.FWRITE = 1
    oe1.RLEN1 = 0.05
    oe1.RLEN2 = 0.05
    oe1.RWIDX1 = 0.005
    oe1.RWIDX2 = 0.005
    oe1.T_IMAGE = 1.0
    oe1.T_INCIDENCE = 65.0
    oe1.T_REFLECTION = 65.0
    oe1.T_SOURCE = 2.0

    oe2.ALPHA = 90
    oe2.DUMMY = 100.0
    oe2.FHIT_C = 1
    oe2.FMIRR = 4
    oe2.FWRITE = 1
    oe2.RLEN1 = 0.1
    oe2.RLEN2 = 0.1
    oe2.RWIDX1 = 0.01
    oe2.RWIDX2 = 0.01
    oe2.T_IMAGE = 2.0
    oe2.T_INCIDENCE = 28.0
    oe2.T_REFLECTION = 28.0
    oe2.T_SOURCE = 5.0

    #
    # run optical element 1
    #
    print("    Running optical element: %d" % (1))
    if iwrite:
        oe1.write("start.01")
    beam.traceOE(oe1, 1)
    if iwrite:
        oe1.write("end.01")
        beam.write("star.01")

    #
    # run optical element 2
    #
    print("    Running optical element: %d" % (2))
    if iwrite:
        oe2.write("start.02")
    beam.traceOE(oe2, 2)
    if iwrite:
        oe2.write("end.02")
        beam.write("star.02")

    return beam
Exemple #27
0
def test_empty_element(
        do_plot=0,
        do_assert=True,
        do_shadow3_fortran=True,
        N=1000,
        alpha_deg=None,  # 20,    # None=rondomize
        theta1_deg=None,  # 10.0,  # None=rondomize
        theta2_deg=None,  # 170.0,  # None=rondomize
        p=None,  # 15.0,  # None=rondomize
        q=None,  # 100.0  # None=rondomize,
):

    source = SourceGeometrical()
    source.set_angular_distribution_gaussian(1e-6, 1e-6)
    beam0 = source.calculate_beam(N=N, POL_DEG=1)
    print(beam0.info())

    beam0s3 = Beam3.initialize_from_shadow4_beam(beam0)

    beam1s3 = Beam3.initialize_from_shadow4_beam(beam0)

    if alpha_deg is None: alpha_deg = numpy.random.random() * 360.0
    if theta1_deg is None: theta1_deg = numpy.random.random() * 90.0
    if theta2_deg is None: theta2_deg = numpy.random.random() * 180.0
    if p is None: p = numpy.random.random() * 100.0
    if q is None: q = numpy.random.random() * 100.0

    #
    # shadow4
    #

    empty = S4EmptyElement()
    empty.get_coordinates().set_positions(
        angle_radial=theta1_deg * numpy.pi / 180,
        angle_radial_out=theta2_deg * numpy.pi / 180,
        angle_azimuthal=alpha_deg * numpy.pi / 180,
        p=p,
        q=q)

    beam1, mirr1 = empty.trace_beam(beam0)

    #
    # shadow3
    #
    oe1 = Shadow.OE()
    oe1.ALPHA = alpha_deg
    oe1.DUMMY = 100.0
    oe1.FWRITE = 0  # 1
    oe1.F_REFRAC = 2
    oe1.T_IMAGE = q
    oe1.T_INCIDENCE = theta1_deg
    oe1.T_REFLECTION = theta2_deg
    oe1.T_SOURCE = p

    if do_shadow3_fortran:
        import os
        os.system("/bin/rm begin.dat start.01 star.01")

        beam0s3.write("begin.dat")
        oe1.write("start.01")
        f = open("systemfile.dat", "w")
        f.write("start.01\n")
        f.close()
        f = open("shadow3.inp", "w")
        f.write("trace\nsystemfile\n0\nexit\n")
        f.close()

        os.system("%s < shadow3.inp" % SHADOW3_BINARY)

        beam1f = Beam3(N=N)
        beam1f.load("star.01")

    beam1s3.traceOE(oe1, 1)

    if do_plot:
        plotxy(beam1, 4, 6, title="Image shadow4", nbins=201)
        plotxy(beam1s3, 4, 6, title="Image shadow3", nbins=201)

    print("alpha_deg, theta1_deg, theta2_deg = ", alpha_deg, theta1_deg,
          theta2_deg)
    print("p, q = ", p, q)
    print("\ncol#   shadow4  shadow3 (shadow3_fortran) (source)")
    for i in range(18):
        if do_shadow3_fortran:
            print("col%d   %f  %f  %f  %f " %
                  (i + 1, beam1.rays[0, i], beam1s3.rays[0, i],
                   beam1f.rays[0, i], beam0s3.rays[0, i]))
        else:
            print("col%d   %f  %f  " %
                  (i + 1, beam1.rays[0, i], beam1s3.rays[0, i]))

        if do_assert:
            assert_almost_equal(beam1.rays[:, i], beam1s3.rays[:, i], 4)
Exemple #28
0
def run_example_grating(user_units_to_cm=1.0, npoint=5000, iwrite=0):
    #
    # Python script to run shadow3. Created automatically with ShadowTools.make_python_script_from_list().
    #
    #
    # initialize shadow3 source (oe0) and beam
    #
    beam = Shadow.Beam()
    oe0 = Shadow.Source()
    oe1 = Shadow.OE()
    oe2 = Shadow.OE()
    oe3 = Shadow.OE()

    #
    # Define variables. See meaning of variables in:
    #  https://raw.githubusercontent.com/srio/shadow3/master/docs/source.nml
    #  https://raw.githubusercontent.com/srio/shadow3/master/docs/oe.nml
    #

    oe0.CONE_MAX = 0.0549999997
    oe0.FDISTR = 5
    oe0.FSOUR = 0
    oe0.FSOURCE_DEPTH = 0
    oe0.F_COLOR = 2
    oe0.F_POLAR = 0
    oe0.NPOINT = npoint
    oe0.PH1 = 5145.0
    oe0.PH2 = 5145.24023

    oe1.FMIRR = 1
    oe1.F_DEFAULT = 0
    oe1.THETA = 5.0
    oe1.T_INCIDENCE = 5.0
    oe1.T_REFLECTION = 5.0

    oe1.DUMMY = user_units_to_cm
    oe1.SIMAG = 1.00000003e+16 / user_units_to_cm
    oe1.SSOUR = 85.0 / user_units_to_cm
    oe1.T_SOURCE = 85.0 / user_units_to_cm
    oe1.T_IMAGE = 75.0 / user_units_to_cm

    oe2.ALPHA = 180.0
    oe2.F_CENTRAL = 1
    oe2.F_GRATING = 1
    oe2.F_PHOT_CENT = 1
    oe2.R_LAMBDA = 5145.0
    oe2.T_INCIDENCE = 5.0
    oe2.T_REFLECTION = 5.0

    oe2.F_RULING = 1  # works for 0, 1 and 4 (cte in XY, cte in grating, VLS with zero coeffs)
    oe2.DUMMY = user_units_to_cm
    oe2.RULING = 18000.0 * user_units_to_cm
    oe2.T_IMAGE = 0.0 / user_units_to_cm
    oe2.T_SOURCE = 0.0 / user_units_to_cm

    oe3.ALPHA = 180.0
    oe3.FMIRR = 1
    oe3.F_DEFAULT = 0
    oe3.THETA = 5.0
    oe3.T_INCIDENCE = 5.0
    oe3.T_REFLECTION = 5.0

    oe3.DUMMY = user_units_to_cm
    oe3.SIMAG = 85.0 / user_units_to_cm
    oe3.SSOUR = 100000000000000.0 / user_units_to_cm
    oe3.T_IMAGE = 85.0 / user_units_to_cm
    oe3.T_SOURCE = 105.0 / user_units_to_cm

    #Run SHADOW to create the source

    if iwrite:
        oe0.write("start.00")

    beam.genSource(oe0)

    if iwrite:
        oe0.write("end.00")
        beam.write("begin.dat")

    #
    #run optical element 1
    #
    print("    Running optical element: %d" % (1))
    if iwrite:
        oe1.write("start.01")
    beam.traceOE(oe1, 1)
    if iwrite:
        oe1.write("end.01")
        beam.write("star.01")

    #
    #run optical element 2
    #
    print("    Running optical element: %d" % (2))
    if iwrite:
        oe2.write("start.02")
    beam.traceOE(oe2, 2)
    if iwrite:
        oe2.write("end.02")
        beam.write("star.02")

    #
    #run optical element 3
    #
    print("    Running optical element: %d" % (3))
    if iwrite:
        oe3.write("start.03")
    beam.traceOE(oe3, 3)
    if iwrite:
        oe3.write("end.03")
        beam.write("star.03")

    #print(oe1.mirinfo())
    print(oe2.mirinfo())
    #print(oe3.mirinfo())

    return beam
Exemple #29
0
def run_shadow3_from_start_files(iwrite=0):
    #
    # initialize shadow3 source (oe0) and beam
    #
    beam = Shadow.Beam()
    oe0 = Shadow.Source()
    oe0_before_run = Shadow.Source()

    # TODO: this is a turn-around for the Linux bug...
    if platform.system() == "Linux":
        str = open('start.00', 'r').read()
        lines = str.split("\n")
        for line in lines:
            command = "oe0." + line
            try:
                exec(command)
            except:
                print("run_shadow3_from_start_files: Failed to exec: %s" %
                      command)

            command = "oe0_before_run." + line
            try:
                exec(command)
            except:
                print("run_shadow3_from_start_files: Failed to exec: %s" %
                      command)
    else:
        oe0.load("start.00")
        oe0_before_run.load("start.00")

    beam.genSource(oe0)

    if iwrite:
        oe0.write("end.00")
        beam.write("begin.dat")

    beam_source = beam.duplicate()
    # return beam,beam.rays.T.copy()

    oe1 = Shadow.OE()
    oe1_before_run = Shadow.OE()

    if platform.system() == "Linux":
        str = open('start.01', 'r').read()
        lines = str.split("\n")
        for line in lines:
            command1 = "oe1."+line.replace("(1)","[0]")\
            .replace("(2)","[1]")\
            .replace("(3)","[2]")\
            .replace("(4)","[3]")\
            .replace("(5)","[4]")\
            .replace("(6)","[5]")\
            .replace("(7)","[6]")\
            .replace("(8)","[7]")\
            .replace("(9)","[8]")\
            .replace("(10)","[9]")
            command2 = "oe1_before_run."+line.replace("(1)","[0]")\
            .replace("(2)","[1]")\
            .replace("(3)","[2]")\
            .replace("(4)","[3]")\
            .replace("(5)","[4]")\
            .replace("(6)","[5]")\
            .replace("(7)","[6]")\
            .replace("(8)","[7]")\
            .replace("(9)","[8]")\
            .replace("(10)","[9]")

            try:
                exec(command1)
            except:
                print("run_shadow3_from_start_files: Failed to exec: %s" %
                      command1)

            try:
                exec(command2)
            except:
                print("run_shadow3_from_start_files: Failed to exec: %s" %
                      command2)

    else:
        oe1.load("start.01")
        oe1_before_run.load("start.01")

    beam.traceOE(oe1, 1)

    if iwrite:
        oe1.write("end.01")
        beam.write("star.01")

    return beam_source, beam, oe0_before_run, oe1_before_run
# -More information in these files available in the source distribution:
#      README_PYTHON.txt General information on SHADOW-python
#      source.nml the description of the variables in Shadow.Source
#      oe.nml the description of the variables in Shadow.OE
#

import Shadow

# write (1) or not (0) SHADOW files start.xx end.xx star.xx
iwrite = 0

#
# initialize elements
#
source = Shadow.Source()
oe = Shadow.OE()
beam = Shadow.Beam()

#
# Source definition: point source with flat divergence
#
source.NPOINT = 30000  #number of rays
source.ISTAR1 = 10001  #seed
source.FSOUR = 0  #point source
source.FDISTR = 1  #flat distribution in divergences, and values
source.HDIV1 = 0.05
source.HDIV2 = 0.05
source.VDIV1 = 0.01
source.VDIV2 = 0.01
#monochromatic: 0 eV
source.F_COLOR = 1