system.update()

# draw the boundary
plot = pv.Plotter()
plot.add_axes()
first_drawer = drawing.TriangleDrawer(plot, color="cyan", show_edges=True)
second_drawer = drawing.TriangleDrawer(plot, color="cyan", show_edges=True)

first_drawer.surface = lens.surfaces[0]
first_drawer.draw()
second_drawer.surface = lens.surfaces[1]
second_drawer.draw()

# build the engine the trace
trace_engine = engine.OpticalEngine(
    3, [operation.StandardReaction()],
    simple_ray_inheritance={"wavelength", "rank"})
trace_engine.optical_system = system
trace_engine.validate_system()
trace_engine.ray_trace(6)


# define various optimization steps
def process_gradient(engine, lr1, lr2, parameters, grad_clip, accumulator):
    """
    Calculate and process the gradient.
    
    Returns the processed gradient and the error.
    """
    with tf.GradientTape() as tape:
        engine.optical_system.update()
    -.4 * PI, .4 * PI, sample_count)
beam_points = distributions.RandomUniformBeam(-.09, .09, sample_count)
source = sources.AngularSource(2, (0, -4.001),
                               PI / 2,
                               angles,
                               beam_points, [drawing.YELLOW] * sample_count,
                               rank_type=None,
                               dense=False)

# build the system
system = eng.OpticalSystem2D()
system.optical_segments = [boundary]
system.sources = [source]
system.materials = [{"n": materials.vacuum}, {"n": materials.acrylic}]

trace_engine = eng.OpticalEngine(2, [op.StandardReaction()],
                                 compile_dead_rays=True,
                                 dead_ray_length=10,
                                 simple_ray_inheritance={"wavelength"})
trace_engine.optical_system = system
system.update()
trace_engine.validate_system()
trace_engine.ray_trace(max_iterations=50)

# set up drawers
segment_drawer = drawing.SegmentDrawer(ax,
                                       color="cyan",
                                       draw_norm_arrows=True,
                                       norm_arrow_visibility=True)
segment_drawer.segments = system.optical_segments
segment_drawer.draw()
Ejemplo n.º 3
0
    # build the source rays
    beam_points = distributions.StaticUniformBeam(-1.5, 1.5, 10)
    angles = distributions.StaticUniformAngularDistribution(0, 0, 1)
    source = sources.AngularSource((-1.0, 0.0), 0.0, angles, beam_points,
                                   drawing.RAINBOW_6)

    # build the system
    system = eng.OpticalSystem2D()
    system.optical_segments = [segments]
    system.sources = [source]
    system.target_segments = [target]
    system.materials = [{"n": materials.vacuum}, {"n": materials.acrylic}]

    trace_engine = eng.OpticalEngine(
        2, [op.StandardReaction()],
        simple_ray_inheritance={"angle_ranks", "wavelength"})
    trace_engine.optical_system = system
    system.update()
    trace_engine.validate_system()

    def test_trace():
        system.update()
        trace_engine.ray_trace(2)
        trace_engine.clear_ray_history()

    # seems like the first trace takes much longer
    test_trace()

    # test various ammounts of rays
    for rays, segs in ((10, 11), (10000, 11), (10, 1001), (10000, 1001)):
Ejemplo n.º 4
0
system.materials = [{"n": materials.vacuum}, {"n": materials.acrylic}]
system.update()

# draw the boundary
plot = pv.Plotter()
plot.add_axes()
first_drawer = drawing.TriangleDrawer(plot, color="cyan", show_edges=True)
second_drawer = drawing.TriangleDrawer(plot, color="cyan", show_edges=True)

first_drawer.surface = lens.surfaces[0]
first_drawer.draw()
second_drawer.surface = lens.surfaces[1]
second_drawer.draw()

# build the trace engine
trace_engine = engine.OpticalEngine(3, [operation.StandardReaction()],
                                    simple_ray_inheritance={
                                        "wavelength", "object_coords",
                                        "aperature_polar_ranks"
                                    })
trace_engine.optical_system = system
trace_engine.validate_system()


# define various optimization steps
def process_gradient(engine, lr1, lr2, parameters, grad_clip, accumulator):
    """
    Calculate and process the gradient.
    
    Returns the processed gradient and the error.
    """

if __name__ == "__main__":
    drawing.disable_figure_key_commands()
    # set up the figure and axes
    fig, ax = plt.subplots(1, 1, figsize=(9, 9))

    # configure axes
    ax.set_aspect("equal")
    ax.set_xbound(-2, 2)
    ax.set_ybound(-2, 2)

    angles = distributions.StaticUniformAngularDistribution(-PI/4.0, PI/4.0, 5)
    source = sources.PointSource((0.0, 0.0), 0.0, angles, [drawing.YELLOW])
    
    engine = eng.OpticalEngine(2, [op.OldestAncestor(), op.StandardReaction()])
    system = eng.OpticalSystem2D()
    system.sources = [source]
    system.update()

    # set up drawer
    drawer = drawing.RayDrawer2D(ax)
    drawer.rays = source
    drawer.draw()

    # hand over to user
    fig.canvas.mpl_connect(
        "key_press_event",
        lambda event: on_key(event, drawer, source, system),
    )
    plt.show()