From f2c36b2a9e7718bfd2f9ca6ec4e17c5292ae28e2 Mon Sep 17 00:00:00 2001 From: David Maranto Date: Mon, 14 Nov 2022 20:06:32 -0500 Subject: [PATCH] Add opticalsurface component and unit test --- architect/systems/optical/optical_surface.py | 30 ++++++++++++++++ .../test_optical/test_OpticalSurface.py | 35 +++++++++++++++++++ 2 files changed, 65 insertions(+) create mode 100644 architect/systems/optical/optical_surface.py create mode 100644 tests/test_systems/test_optical/test_OpticalSurface.py diff --git a/architect/systems/optical/optical_surface.py b/architect/systems/optical/optical_surface.py new file mode 100644 index 0000000..c36ee66 --- /dev/null +++ b/architect/systems/optical/optical_surface.py @@ -0,0 +1,30 @@ +"""An optical surface component.""" + +# external +import astropy.units as unit +import numpy as np + +# project +from architect.systems import Component + + +class OpticalSurface(Component): + """An optical surface is a component that can refract light.""" + + def __init__(self, medium_index=None): + super().__init__() + self.medium_index = medium_index + + def angle_of_refraction(self, incident_angle: unit.deg, incident_index) -> unit.deg: + """Get the angle of refraction for a given incident angle. + + Ref: https://www.notion.so/utat-ss/Angle-of-Refraction-a4c5f3235ad941398137dd3560eec717 + + """ + assert self.medium_index is not None, "medium_index must be set." + + angle_of_refraction = np.arcsin( + incident_index * np.sin(incident_angle) / self.medium_index + ) + + return angle_of_refraction.to(unit.deg) diff --git a/tests/test_systems/test_optical/test_OpticalSurface.py b/tests/test_systems/test_optical/test_OpticalSurface.py new file mode 100644 index 0000000..688b697 --- /dev/null +++ b/tests/test_systems/test_optical/test_OpticalSurface.py @@ -0,0 +1,35 @@ +"""Tests for OpticalSurface.""" + +# stdlib +import logging + +# external +import astropy.units as unit + +# project +from architect.systems.optical.optical_surface import OpticalSurface + +LOG = logging.getLogger(__name__) + + +def test_init(): + """Test init method.""" + + component = OpticalSurface() + LOG.info(component) + + +def test_angle_of_refraction(): + """Test angle_of_refraction method.""" + + component = OpticalSurface(medium_index=1.5) + + incident_angle = 45 * unit.deg + incident_index = 1.0 + angle_of_refraction = component.angle_of_refraction( + incident_angle=incident_angle, incident_index=incident_index + ) + + LOG.info(angle_of_refraction) + + assert angle_of_refraction.unit == unit.deg