本文整理汇总了Python中tracer.ray_bundle.RayBundle.set_ref_index方法的典型用法代码示例。如果您正苦于以下问题:Python RayBundle.set_ref_index方法的具体用法?Python RayBundle.set_ref_index怎么用?Python RayBundle.set_ref_index使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tracer.ray_bundle.RayBundle
的用法示例。
在下文中一共展示了RayBundle.set_ref_index方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_up_down
# 需要导入模块: from tracer.ray_bundle import RayBundle [as 别名]
# 或者: from tracer.ray_bundle.RayBundle import set_ref_index [as 别名]
def test_up_down(self):
"""Rays coming from below are absorbed, from above reflected"""
going_down = N.c_[[1, 1, -1], [-1, 1, -1], [-1, -1, -1], [1, -1, -1]] / N.sqrt(3)
going_up = going_down.copy()
going_up[2] = 1 / N.sqrt(3)
pos_up = N.c_[[0,0,1], [1,-1,1], [1,1,1], [-1,1,1]]
pos_down = pos_up.copy()
pos_down[2] = -1
bund = RayBundle()
bund.set_directions(N.hstack((going_down, going_up)))
bund.set_vertices(N.hstack((pos_up, pos_down)))
bund.set_energy(N.tile(100, 8))
bund.set_ref_index(N.tile(1, 8))
gm = FlatGeometryManager()
prm = gm.find_intersections(N.eye(4), bund)
absref = optics_callables.AbsorberReflector(0.)
selector = N.arange(8)
gm.select_rays(selector)
outg = absref(gm, bund, selector)
e = outg.get_energy()
N.testing.assert_array_equal(e[:4], 100)
N.testing.assert_array_equal(e[4:], 0)
示例2: TestTraceProtocol6
# 需要导入模块: from tracer.ray_bundle import RayBundle [as 别名]
# 或者: from tracer.ray_bundle.RayBundle import set_ref_index [as 别名]
class TestTraceProtocol6(unittest.TestCase):
"""
Tests a spherical surface
"""
def setUp(self):
surface1 = Surface(HemisphereGM(2.), opt.perfect_mirror,
rotation=general_axis_rotation(N.r_[1,0,0], N.pi/2.))
surface2 = Surface(HemisphereGM(2.), opt.perfect_mirror,
location=N.array([0,-2,0]),
rotation=general_axis_rotation(N.r_[1,0,0], -N.pi/2.))
self._bund = RayBundle()
self._bund.set_directions(N.c_[[0,1,0]])
self._bund.set_vertices(N.c_[[0,-1,0]])
self._bund.set_energy(N.r_[[1]])
self._bund.set_ref_index(N.r_[[1]])
assembly = Assembly()
object1 = AssembledObject()
object2 = AssembledObject()
object1.add_surface(surface1)
object2.add_surface(surface2)
assembly.add_object(object1)
assembly.add_object(object2)
self.engine = TracerEngine(assembly)
def test_ray_tracers1(self):
params = self.engine.ray_tracer(self._bund, 1, .05)[0]
correct_params = N.c_[[0,2,0]]
N.testing.assert_array_almost_equal(params,correct_params)
示例3: TestHomogenizer
# 需要导入模块: from tracer.ray_bundle import RayBundle [as 别名]
# 或者: from tracer.ray_bundle.RayBundle import set_ref_index [as 别名]
class TestHomogenizer(unittest.TestCase):
def setUp(self):
"""A homogenizer transforms a bundle correctly"""
hmg = rect_homogenizer(5., 3., 10., 0.9)
self.engine = TracerEngine(hmg)
self.bund = RayBundle()
# 4 rays starting somewhat above (+z) the homogenizer
pos = N.zeros((3,4))
pos[2] = N.r_[11, 11, 11, 11]
self.bund.set_vertices(pos)
# One ray going to each wall:
dir = N.c_[[1, 0, -1], [-1, 0, -1], [0, 1, -1], [0, -1, -1]]/N.sqrt(2)
self.bund.set_directions(dir)
# Laborious setup details:
self.bund.set_energy(N.ones(4)*4.)
self.bund.set_ref_index(N.ones(4))
def test_first_hits(self):
"""Test bundle enters homogenizer correctly"""
v, d = self.engine.ray_tracer(self.bund, 1, 0.05)
out_dirs = N.c_[[-1, 0, -1], [1, 0, -1], [0, -1, -1], [0, 1, -1]]/N.sqrt(2)
N.testing.assert_array_almost_equal(d, out_dirs)
out_hits = N.c_[
[2.5, 0, 8.5],
[-2.5, 0, 8.5],
[0, 1.5, 9.5],
[0, -1.5, 9.5]]
N.testing.assert_array_almost_equal(v, out_hits)
示例4: TestObjectBuilding1
# 需要导入模块: from tracer.ray_bundle import RayBundle [as 别名]
# 或者: from tracer.ray_bundle.RayBundle import set_ref_index [as 别名]
class TestObjectBuilding1(unittest.TestCase):
"""Tests an object composed of sphere surfaces"""
def setUp(self):
self.assembly = Assembly()
surface1 = Surface(HemisphereGM(3.), optics_callables.perfect_mirror,
location=N.array([0,0,-1.]),
rotation=general_axis_rotation(N.r_[1,0,0], N.pi))
surface2 = Surface(HemisphereGM(3.), optics_callables.perfect_mirror,
location=N.array([0,0,1.]))
self.object = AssembledObject()
self.object.add_surface(surface1)
self.object.add_surface(surface2)
self.assembly.add_object(self.object)
dir = N.c_[[0,0,1.],[0,0,1.]]
position = N.c_[[0,0,-3.],[0,0,-1.]]
self._bund = RayBundle(position, dir, energy=N.ones(2))
def test_object(self):
"""Tests that the assembly heirarchy works at a basic level"""
self.engine = TracerEngine(self.assembly)
inters = self.engine.ray_tracer(self._bund,1,.05)[0]
correct_inters = N.c_[[0,0,2],[0,0,-2]]
N.testing.assert_array_almost_equal(inters, correct_inters)
def test_translation(self):
"""Tests an assembly that has been translated"""
trans = N.array([[1,0,0,0],[0,1,0,0],[0,0,1,1],[0,0,0,1]])
self.assembly.transform_children(trans)
self.engine = TracerEngine(self.assembly)
params = self.engine.ray_tracer(self._bund,1,.05)[0]
correct_params = N.c_[[0,0,3],[0,0,-1]]
N.testing.assert_array_almost_equal(params, correct_params)
def test_rotation_and_translation(self):
"""Tests an assembly that has been translated and rotated"""
self._bund = RayBundle()
self._bund.set_vertices(N.c_[[0,-5,1],[0,5,1]])
self._bund.set_directions(N.c_[[0,1,0],[0,1,0]])
self._bund.set_energy(N.r_[[1,1]])
self._bund.set_ref_index(N.r_[[1,1]])
trans = generate_transform(N.r_[[1,0,0]], N.pi/2, N.c_[[0,0,1]])
self.assembly.transform_children(trans)
self.engine = TracerEngine(self.assembly)
params = self.engine.ray_tracer(self._bund,1,.05)[0]
correct_params = N.c_[[0,-2,1]]
N.testing.assert_array_almost_equal(params, correct_params)
示例5: test_paraxial_ray
# 需要导入模块: from tracer.ray_bundle import RayBundle [as 别名]
# 或者: from tracer.ray_bundle.RayBundle import set_ref_index [as 别名]
def test_paraxial_ray(self):
"""A paraxial ray in reflected correctly"""
bund = RayBundle()
bund.set_vertices(N.c_[[0.01, 0., 2.]])
bund.set_directions(N.c_[[0., 0., -1.]])
bund.set_energy(N.r_[100.])
bund.set_ref_index(N.r_[1])
self.engine.ray_tracer(bund, 15, 10.)
non_degenerate = self.engine.tree[-1].get_energy() > 10
v = self.engine.tree[-1].get_vertices()[:,non_degenerate]
d = self.engine.tree[-1].get_directions()[:,non_degenerate]
# Not high equality demanded, because of spherical aberration.
N.testing.assert_array_almost_equal(v, N.c_[[-0.01, 0., 1.5]], 2)
N.testing.assert_array_almost_equal(d, N.c_[[0., 0., 1.]], 2)
示例6: TestRectOneSided
# 需要导入模块: from tracer.ray_bundle import RayBundle [as 别名]
# 或者: from tracer.ray_bundle.RayBundle import set_ref_index [as 别名]
class TestRectOneSided(unittest.TestCase):
def setUp(self):
self.mirror = rect_one_sided_mirror(1.5, 1.5, 0.9)
pos = N.zeros((3,8))
pos[0] = N.tile(N.r_[0, 0.5, 2, -2], 2)
pos[2] = N.repeat(N.r_[1, -1], 4)
dir = N.zeros((3,8))
dir[2] = N.repeat(N.r_[-1, 1], 4)
self.bund = RayBundle()
self.bund.set_vertices(pos)
self.bund.set_directions(dir)
self.bund.set_energy(N.ones(8)*1000)
self.bund.set_ref_index(N.ones(8))
def test_regular(self):
"""One-sided plate without rotation"""
e = TracerEngine(Assembly(objects=[self.mirror]))
e.ray_tracer(self.bund, 1, 0.05)
outg = e.tree[-1]
correct_verts = N.zeros((3,2))
correct_verts[0] = N.r_[0, 0.5]
N.testing.assert_array_equal(
outg.get_vertices()[:,outg.get_energy() > 0], correct_verts)
N.testing.assert_array_almost_equal(
outg.get_energy(), N.r_[100., 100., 0, 0])
def test_rotated(self):
"""One-sided plate with rotation"""
rot = sp.roty(N.pi/4.)
self.mirror.set_transform(rot)
e = TracerEngine(Assembly(objects=[self.mirror]))
e.ray_tracer(self.bund, 1, 0.05)
outg = e.tree[-1]
correct_verts = N.array([[0., 0.5], [0., 0.], [0., -0.5]])
N.testing.assert_array_almost_equal(
outg.get_vertices()[:,outg.get_energy() > 0], correct_verts)
N.testing.assert_array_almost_equal(
outg.get_energy(), N.r_[100., 100., 0, 0])