Ejemplo n.º 1
0
    def setUp(self):
        self.wp = Waveplate(direction=(0.,0.,1.))
        self.src = ParallelRaySource(rings=0,
                                     E_vector=(1,0,0),
                                     E1_amp = 1.0+0.0j,
                                     E2_amp = 0.0+0.0j,
                                     direction = (0,0,1),
                                     origin = (0,0,-10),
                                    )

        self.model = RayTraceModel(optics=[self.wp,],
                                   sources=[self.src])
Ejemplo n.º 2
0
    def test_quarter_retardance2(self):
        src = SingleRaySource(E_vector=(1,0,0),
                                 E1_amp = 1.0+0.0j,
                                 E2_amp = 0.0+0.0j,
                                 direction = (0,0,1),
                                 origin = (0,0,-40),
                                )

        wp1 = Waveplate(retardance=0.25,
                       rotation = 45.0,
                       centre=(0,0,40),
                       direction=(0,0,1))

        print("wp1 fa:", wp1.material.fast_axis)

        wp2 = Waveplate(retardance=0.25,
                       rotation = -45.0,
                       centre=(0,0,80),
                       direction=(0,0,-1))

        print("wp2 fa:", wp2.material.fast_axis)
        print("wp1 fa:", wp1.material.fast_axis)

        model = RayTraceModel(optics=[wp1,wp2], sources=[src])
        model.trace_all()

        def get_major_axis(ray):
            E1_vector = numpy.array(ray.E_vector)
            E2_vector = numpy.cross(numpy.array(ray.direction),
                                    E1_vector)
            E = (E1_vector*ray.E1_amp + E2_vector*ray.E2_amp)
            return E.real

        ray_in = src.InputRays[0]

        #print ray_in.E_vector, ray_in.E1_amp, ray_in.E2_amp

        self.assertEqual(len(src.TracedRays), 3)

        for i in range(len(src.TracedRays)):
            ray = src.TracedRays[i][0]
            print(i, "::", get_major_axis(ray), ray.E_left, ray.E_right, ray.ellipticity, ray.E_vector)
Ejemplo n.º 3
0
    def test_quarter_retardance(self):
        src = SingleRaySource(E_vector=(1,0,0),
                                 E1_amp = 1.0+0.0j,
                                 E2_amp = 0.0+0.0j,
                                 direction = (0,0,1),
                                 origin = (0,0,-40),
                                )

        wp = Waveplate(retardance=0.25,
                       rotation = 45.0,
                       centre=(0,0,40),
                       direction=(0,0,1))

        m = PECMirror(centre=(0,0,80),
                      direction=(0.0,0.0,1.0))

        model = RayTraceModel(optics=[wp,m], sources=[src])
        #model.trace_all()

        def get_major_axis(ray):
            E1_vector = numpy.array(ray.E_vector)
            E2_vector = numpy.cross(numpy.array(ray.direction),E1_vector
                                    )
            E = (E1_vector*ray.E1_amp + E2_vector*ray.E2_amp)
            return E

        ray_in = src.InputRays[0]

        #print ray_in.E_vector, ray_in.E1_amp, ray_in.E2_amp

        self.assertEqual(len(src.TracedRays), 4)

        for i in range(4):
            ray = src.TracedRays[i][0]
            print(i, "::", ray.E_left, ray.E_right, ray.E_vector, ray.E1_amp, ray.E2_amp)
            print("\t", get_major_axis(ray))

        ray_out = src.TracedRays[-1][0]
        self.assertAlmostEqual(numpy.dot(get_major_axis(ray_out),
                                    get_major_axis(ray_in)), 0.0)
sys.path.append('..')
import pyximport
pyximport.install()

from raytrace.tracer import RayTraceModel
from raytrace.sources import BroadbandRaySource
from raytrace.diffraction_gratings import RectangularGrating

source = BroadbandRaySource(number=5,
                            wavelength_start=1.5,
                            wavelength_end=1.6,
                            uniform_deltaf=True,
                            origin=(-50, 0, 0),
                            direction=(1., 0, 0))

grating = RectangularGrating(length=25.4,
                             width=25.4,
                             thickness=6.0,
                             centre=(0.0, 0.0, 0.0),
                             direction=(-1, 0, 0),
                             lines_per_mm=600,
                             efficiency=1.0,
                             order=1)

rays = source.InputRays

model = RayTraceModel(optics=[grating], sources=[
    source,
])

model.configure_traits()
Ejemplo n.º 5
0
    randomness=True)
#linear dialectric filled light funnel
r1 = LDLF(  #material=OpaqueMaterial(),
    z_height_1=-20.0,
    z_height_2=20.0,
    slat_width=slat_width,
    ap_width=ex_ap,
    slant=slant,
    n_inside=1.333)  #1.333 = water

ratio = Ratio(denominator=r1.faces[2], nominator=r1.faces[0])
raypaths = RayPaths()

model = RayTraceModel(optics=[
    r1,
],
                      sources=[s1, s2, s3, s4, s5],
                      results=[ratio, raypaths],
                      recursion_limit=5)

entry_ap = r1.faces.faces[2]
newsource = trace_pretty(model, 1, [entry_ap])

model.sources = [
    newsource,
]
#model.configure_traits()
#print model.all_faces

#ap_ratio = ent_ap/ex_ap
#print "ap ratio: ", ap_ratio
#print "effective concentration: ", ap_ratio*model.results[0].result	#still not right, circular source biases ratio.
Ejemplo n.º 6
0
D2 = np.dot(rot_matrix,D2)-trans_vector
c21 = np.dot(rot_matrix,c21)-trans_vector
c22 = np.dot(rot_matrix,c22)-trans_vector
E2 = np.dot(rot_matrix,E2)-trans_vector

left_arm = Extruded_bezier(name = "left arm",control_points = np.array([[D2,c21,c22,E2]]),z_height_1 = 0, z_height_2 = system_length, material = PECMaterial())



target = RectTarget(width = len_exit_ap, length = system_length, elevation=90., rotation =90., centre = (0,0,system_length/2.))

source = RectRaySource(origin=(0,100,system_length/4.),
                            direction=(0,-1,0),
                            working_dist = 200.,
                            number=10,
                            length = system_length/4.,
            			    width = 10,   #lea+2*E[0],
            			    randomness = True,
                            theta = 10.00000001)

raypaths = RayPaths()

model = RayTraceModel(sources=[source],
                      optics=[target, right_arm,left_arm], results = [raypaths], recursion_limit=10)


model.configure_traits()


#try to make s as small as possible without making too many faces. (20 faces isn't unreasonable)

test = Extruded_interpolant(profile = [xs,ys], smoothness = 0, z_height_1 = -30, z_height_2=30, \
		material = DielectricMaterial(), n_inside=1.5, trace_ends= True,trace_top = False )

source = RectRaySource(origin=(50,0,0),
                            direction=(-1,0,0),
                            working_dist = 100.,
                            number=10,
                            length = 10,
			    width = 10,
			    randomness = True,
                            theta = 5.,
                            scale_factor=0.2)

'''
r1 = LDLF(material=PECMaterial(),
                z_height_1=-20.0,
                z_height_2=20.0,
                slat_width=20,
                ap_width=5,
                slant=75,
                n_inside=1.7)
'''


model = RayTraceModel(sources=[source],
                      optics=[test])
model.configure_traits()

            profile[len(profile):] = xtr_pts

        self.profile = profile
#print profile


#polygon approximation of parabolic trough mirror
para = approx_parabola(material=PECMaterial(),
                       z_height_1=-20.0,
                       z_height_2=20.0,
                       focal_length=10)

print(0)
model0 = RayTraceModel(optics=[
    para,
], sources=[
    source,
])
print(1)
model1 = RayTraceModel(optics=[
    para,
], sources=[
    source,
])
print(2)
model2 = RayTraceModel(optics=[
    para,
], sources=[
    source,
])
print(3)
Ejemplo n.º 9
0
from raytrace.results import Ratio

import numpy

source = ConfocalRaySource(focus=(0,0,0),
                            direction=(0,1,0),
                            working_dist = 100.,
                            number=20,
                            detail_resolution=5,
                            theta=10.)

#print source.InputDetailRays.origin.shape
                            
m1 = PECMirror(name="M1",
                centre=(0,-40,0),
                direction=(0,1,-1),
                diameter=30.,
                thickness=5.)               
    
                
l1 = PlanoConvexLens(centre=(0,-40,30),
                direction=(0,0,1))

ratio = Ratio(denominator=m1.faces[0],
              nominator=l1.faces[1])
                
model = RayTraceModel(optics=[m1,l1],
                    sources=[source,],
                    results=[ratio])               

model.configure_traits()
Ejemplo n.º 10
0
source = ParallelRaySource(
    origin=(0, 20, 0),
    direction=(0, -1, 1),
    working_dist=10.,
    #number=20,
    radius=1.)

#print source.InputDetailRays.origin.shape

m1 = TroughParabloid(width=20, length=100, EFL=5, centre=(0, 0, 0))

print(m1.intersect)

model = RayTraceModel(optics=[
    m1,
],
                      sources=[
                          source,
                      ],
                      probes=[],
                      recursion_limit=2)

#model.trace_detail_async()
#import time
#start = time.clock()
#model.trace_all()
#end = time.clock()
#print "traced in", end - start

model.configure_traits()
Ejemplo n.º 11
0
source = RectRaySource(origin=(10, 30, 0),
                       direction=(.1, -1, 0),
                       working_dist=100.,
                       number=1,
                       length=0,
                       width=0,
                       randomness=False,
                       scale_factor=0.2)
'''

source = RectRaySource(origin=(10.,10.,0),
                            direction=(.2,-1,0),
                            working_dist = 100.,
                            number=3,
                            length = 12,
            			    width = 12,
            			    randomness = False,
                            scale_factor=0.2)
'''
raypaths = RayPaths()

model = RayTraceModel(sources=[source],
                      optics=[test],
                      results=[raypaths],
                      recursion_limit=10)

#test.invert_normal = True
hits = model.sources[0].TracedRays
res = model.results[0].result
model.configure_traits()
Ejemplo n.º 12
0
l1 = EdmundOptic45805(centre=(0,-20,0),
                      direction=(0,1,0),
                      )

# l1 = Singlet(center=(0,-20,0),
#              direction=(0,1,0),
#              CT=4.0,
#              curvature1 = 50,
#              curvature2 = -50,
#              dispersion = NondispersiveCurve(1.5),
#              dispersion_coating = NondispersiveCurve(1.25),
#              coating_thickness = 0.0
#              )

                
model = RayTraceModel(optics=[l1,],
                    sources=[source,])
 
#model.trace_detail_async()
#import time
#start = time.clock()
#model.trace_all()
#end = time.clock()
#print "traced in", end - start                   

#import timeit
#t = timeit.Timer("model.update = True","from __main__ import model")
#ret = t.timeit(10)
#print "time:", ret

model.trace_all()
Ejemplo n.º 13
0
                
e1 = Ellipsoid(focus1=(0,-40,40),
                focus2=(0,0,80),
                size=80,
                X_bounds=(-30,0),
                Y_bounds=(-15,15),
                Z_bounds=(40-15.,40+15.))
                
e2 = Ellipsoid(focus1=(0,40,40),
                focus2=(0,0,80),
                size=80,
                X_bounds=(0,30),
                Y_bounds=(-15,15),
                Z_bounds=(40-15.,40+15.))      
                
l1 = PlanoConvexLens(centre=(0,-40,30),
                direction=(0,0,1))
                
model = RayTraceModel(optics=[m1,m2,m3,m4,m5,e1,e2, l1],
                    sources=[source,],
                    probes=[p1,])
 
#model.trace_detail_async()
#import time
#start = time.clock()
#model.trace_all()
#end = time.clock()
#print "traced in", end - start                   

model.configure_traits()
Ejemplo n.º 14
0
from raytrace.tracer import RayTraceModel
from raytrace.lenses import PlanoConvexLens
from raytrace.sources import ConfocalRaySource

lens = PlanoConvexLens(centre=(20, 0, 0),
                       direction=(1, 0, 0),
                       curvature=25.0,
                       diameter=25.4,
                       CT=6.0)

source = ConfocalRaySource(focus=(0, 0, 0),
                           direction=(1, 0, 0),
                           working_dist=100.0,
                           theta=15.0)

model = RayTraceModel(optics=[lens], sources=[source])

model.configure_traits()
Ejemplo n.º 15
0
              y1=height_offset,
              x2=-ent_ap / 2,
              y2=height_offset,
              z_height_1=0,
              z_height_2=30,
              material=TransparentMaterial())

exit_ap = Sheet(x1=ex_ap / 2,
                y1=0,
                x2=-ex_ap / 2,
                y2=0,
                z_height_1=0,
                z_height_2=30,
                material=TransparentMaterial())

ratio = Ratio(denominator=en_ap.faces[0], nominator=exit_ap.faces[0])

model = RayTraceModel(optics=[r1, r2, en_ap, exit_ap],
                      sources=[
                          source,
                      ],
                      results=[ratio])

model.configure_traits()

print(model.all_faces)
ap_ratio = ent_ap / ex_ap
print("ap ratio: ", ap_ratio)
print("effective concentration: ", ap_ratio *
      model.results[0].result)  #still not right, circular source biases ratio.
Ejemplo n.º 16
0
for i, center in enumerate(centers):

    Mirrors[i] = RectMirror(width=mirror_width,
                            length=300.,
                            direction=(center, numpy.tan(-phi[i]) * center, 0),
                            centre=(center, 0, 0))

Optics = Mirrors

sorber = RectAbsorber(width=mirror_width,
                      length=300.,
                      direction=(0, -1, 0),
                      centre=(0, tower_height, 0))
Optics.append(sorber)

model = RayTraceModel(
    sources=[
        sun,
    ],
    optics=Optics,
)

#model.trace_detail_async()
#import time
#start = time.clock()
#model.trace_all()
#end = time.clock()
#print "traced in", end - start

model.configure_traits()
Ejemplo n.º 17
0
from raytrace.tracer import RayTraceModel

model = RayTraceModel()

model.configure_traits()
Ejemplo n.º 18
0
                            #number=20,
                            radius=14.)
"""                            
s2 = ParallelRaySource(origin=(x,y,z),
                            direction=(xd,yd,zd),
                            working_dist = 50.,
                            #number=20,
                            radius=0)
"""                            
#print source.InputDetailRays.origin.shape
                            
m1 = CylindricalInvolute(width = 60,
                       length = 500,
                       tube_radius = 5,
                       begin_angle = -90.,
                       end_angle = 500.)
                
                
model = RayTraceModel(optics=[m1,],
                    sources=[s1,],
                    probes=[])
 
#model.trace_detail_async()
#import time
#start = time.clock()
#model.trace_all()
#end = time.clock()
#print "traced in", end - start                   

model.configure_traits()
Ejemplo n.º 19
0
class TestWaveplate(unittest.TestCase):
    def setUp(self):
        self.wp = Waveplate(direction=(0.,0.,1.))
        self.src = ParallelRaySource(rings=0,
                                     E_vector=(1,0,0),
                                     E1_amp = 1.0+0.0j,
                                     E2_amp = 0.0+0.0j,
                                     direction = (0,0,1),
                                     origin = (0,0,-10),
                                    )

        self.model = RayTraceModel(optics=[self.wp,],
                                   sources=[self.src])

    def test_retardance_property(self):
        wp = self.wp
        for val in [0.0, 0.25, 0.5, 0.75, 1.0]:
            wp.retardance = val
            self.assertEqual(wp.retardance, val)

    def test_input_ray(self):
        ray = self.src.InputRays[0]
        print(ray.power, ray.ellipticity, ray.E_vector, ray.E1_amp, ray.E2_amp)
        self.assertEqual(ray.ellipticity, 0.0)

    def test_zero_retardance(self):
        wp = self.wp
        wp.retardance = 0.0
        wp.rotation = 19.235
        direction=(0.,0.,1.)
        print(wp.x_axis)
        self.model.trace_all()

        ray_in = self.src.InputRays[0]
        ray_out = self.src.TracedRays[-1][0]

        ray_in.project_E(1,1,0)
        ray_out.project_E(1,1,0)

        self.assertEqual(ray_in.E_vector, ray_out.E_vector)
        self.assertAlmostEqual(ray_in.E1_amp, ray_out.E1_amp)
        self.assertAlmostEqual(ray_in.E2_amp, ray_out.E2_amp)

    def test_zero_retardance2(self):
        wp = self.wp
        wp.retardance = 0.0
        wp.rotation = 19.235
        direction=(0.,0.,-1.)
        print(wp.x_axis)
        self.model.trace_all()

        ray_in = self.src.InputRays[0]
        ray_out = self.src.TracedRays[-1][0]

        ray_in.project_E(1,1,0)
        ray_out.project_E(1,1,0)

        self.assertEqual(ray_in.E_vector, ray_out.E_vector)
        self.assertAlmostEqual(ray_in.E1_amp, ray_out.E1_amp)
        self.assertAlmostEqual(ray_in.E2_amp, ray_out.E2_amp)

    def test_half_wave_plate(self):
        wp = self.wp
        wp.retardance = 0.5
        for rot in numpy.linspace(-180,180,20):
            wp.rotation = rot
            self.model.trace_all()

            ray_in = self.src.InputRays[0]
            ray_out = self.src.TracedRays[-1][0]

            self.assertAlmostEqual(ray_in.ellipticity, ray_out.ellipticity)
Ejemplo n.º 20
0
#print source.InputDetailRays.origin.shape
                            
m1 = PECMirror(name="M1",
                centre=(0,-40,0),
                direction=(0,1,-1),
                diameter=30.,
                thickness=5.)
                
aligned = RectAperture(name="entry",
                    centre = (0,5,15),
                    direction = (0,1,0),
                    length = 30.,
                    width = 30.)
                    
antialigned = RectAperture(name="reversed",
                    centre = (0,-5,15),
                    direction = (0,-1,0),
                    length = 30.,
                    width = 30.)
                
l1 = PlanoConvexLens(centre=(0,-40,30),
                direction=(0,0,1))
                
ratio = Total_Efficency(Target=m1.faces[0],
              Aperture=aligned.faces[0])

model = RayTraceModel(optics=[m1,aligned,antialigned],
                    sources=[source,],
                    results=[ratio])               

model.configure_traits()
Ejemplo n.º 21
0
    z_height_1=-20.0,
    z_height_2=20.0,
    slat_width=5.0,  #
    ap_width=3.0,
    slant=80.0,
    n_inside=3)  #1.5 = glass, 3 = something crazy


class Ap_match_Constraint(BaseConstraint):
    r1 = Instance(LDLF, ())
    r2 = Instance(LDLF, ())

    @on_trait_change("r1.update")
    def calc_r2_param(self):
        h = self.r1.slat_width / numpy.sin(self.r1.slant * numpy.pi / 180.)
        self.r2.centre = (0, h, 0)
        x = self.r1.ap_width + 2 * self.r1.slat_width * numpy.cos(
            self.r1.slant * numpy.pi / 180.)
        self.r2.ap_width = x


c = Ap_match_Constraint(r1=r1, r2=r2)

model = RayTraceModel(optics=[r1, r2], constraints=[
    c,
], sources=[
    source,
])

model.configure_traits()