def pyoptools_repr(self, obj):
        dist = obj.distribution
        nr = obj.nr
        na = obj.na
        wl = obj.wl.getValueAs("µm").Value
        ang = obj.angle.getValueAs("rad").Value

        pla = obj.getGlobalPlacement()
        X, Y, Z = pla.Base
        RZ, RY, RX = pla.Rotation.toEuler()

        if dist == "polar":
            r = rs_lib.point_source_p(
                origin=(X, Y, Z),
                direction=(radians(RX), radians(RY), radians(RZ)),
                span=ang,
                num_rays=(nr, na),
                wavelength=wl,
                label="",
            )
        elif dist == "cartesian":
            r = rs_lib.point_source_c(
                origin=(X, Y, Z),
                direction=(radians(RX), radians(RY), radians(RZ)),
                span=(ang, ang),
                num_rays=(nr, na),
                wavelength=wl,
                label="",
            )
        elif dist == "random":
            print("random ray distribution, not implemented yet")
        else:
            print("Warning ray distribution {} not recognized".format(dist))

        return r
Esempio n. 2
0
    def pyoptools_repr(self,obj):
        X,Y,Z = obj.Placement.Base
        dist=obj.distribution.lower()
        nr=obj.nr
        na=obj.na
        ang = obj.angle
        wl=obj.wavelenght
        RZ,RY,RX = obj.Placement.Rotation.toEuler()
        rm = rot_mat((radians(RX),radians(RY),radians(RZ)))
        dire=((radians(RX),radians(RY),radians(RZ)))

        r=[]
        if obj.enabled:
            if dist=="polar":
                for x in linspace(-obj.xSize/2,obj.xSize/2,obj.Nx):
                    for y in linspace(-obj.ySize/2,obj.ySize/2,obj.Ny):
                        xr,yr,zr =dot(rm,array((x,y,0),dtype="float64"))
                        r=r+rs_lib.point_source_p(origin=(X+xr,Y+yr,Z+zr),direction=dire,span=radians(ang),
                                      num_rays=(nr,na),wavelength=wl/1000., label="")

            elif dist=="cartesian":
                for x in linspace(-obj.xSize/2,obj.xSize/2,obj.Nx):
                    for y in linspace(-obj.ySize/2,obj.ySize/2,obj.Ny):
                        xr,yr,zr =dot(rm,array((x,y,0),dtype="float64"))
                        r=r+rs_lib.point_source_c(origin=(X+xr,Y+yr,Z+zr),direction=dire,span=(radians(ang),radians(ang))\
                                                  ,num_rays=(nr,na),wavelength=wl/1000., label="")
            elif dist=="random":
                print("random ray distribution, not implemented yet")
            else:
                print("Warning ray distribution {} not recognized".format(dist))

        return r
Esempio n. 3
0
def test_point_source_p():
    # point_source_p(origin=(0., 0., 0.), direction=(0., 0., 0), span=pi / 8, num_rays=(10, 10), wavelength=0.58929,
    # label="")
    pos_origin_ray = np.array([1.0, 1.5, 3.1416])
    direction = np.array([0.2, 0.3, 0.5])
    span = np.pi / 16
    num_rays = (2, 3)
    wavelength = 0.432
    label = "one_more_test"

    expected_dir = [
        np.array([0.34942093, -0.03549297, 0.93629336]),
        np.array([0.38874339, -0.12238449, 0.91318159]),
        np.array([0.39840259, 0.04708771, 0.91600116]),
        np.array([0.25606913, -0.03066941, 0.96617182]),
    ]
    expected = [
        ray.Ray(
            pos=pos_origin_ray,
            dir=i,
            intensity=1.0,
            wavelength=wavelength,
            n=None,
            label=label,
            orig_surf=None,
            order=0,
        ) for i in expected_dir
    ]

    calculated = ray_source.point_source_p(
        origin=pos_origin_ray,
        direction=direction,
        span=span,
        num_rays=num_rays,
        wavelength=wavelength,
        label=label,
    )

    assert beam_almost_equal(calculated, expected)