Skip to content

Commit

Permalink
Added optika.materials.AbstractLayer.n() method.
Browse files Browse the repository at this point in the history
  • Loading branch information
byrdie committed Jun 10, 2024
1 parent c7a37c4 commit ce0051b
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
28 changes: 27 additions & 1 deletion optika/materials/_layers.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,20 @@ class AbstractLayer(
of homogeneous layers.
"""

@abc.abstractmethod
def n(
self,
wavelength: u.Quantity | na.AbstractScalar,
) -> na.AbstractScalar:
"""
The index of refraction on the left side of the layer.
Parameters
----------
wavelength
The wavelength of the incident light in vacuum
"""

@property
@abc.abstractmethod
def thickness(self) -> u.Quantity | na.AbstractScalar:
Expand Down Expand Up @@ -179,7 +193,7 @@ def n(
wavelength: u.Quantity | na.AbstractScalar,
) -> float | na.AbstractScalar:
"""
The complex index of refraction of this layer.
The complex index of refraction of this entire layer.
"""
if self.chemical is None:
return 1
Expand Down Expand Up @@ -384,6 +398,12 @@ class LayerSequence(AbstractLayerSequence):
layers: Sequence[AbstractLayer] = dataclasses.MISSING
"""A sequence of layers."""

def n(
self,
wavelength: u.Quantity | na.AbstractScalar,
) -> na.AbstractScalar:
return self.layers[0].n(wavelength)

@property
def thickness(self) -> u.Quantity | na.AbstractScalar:
result = 0 * u.nm
Expand Down Expand Up @@ -508,6 +528,12 @@ class PeriodicLayerSequence(AbstractLayerSequence):
num_periods: int = dataclasses.MISSING
"""The number of times to repeat the layer sequence."""

def n(
self,
wavelength: u.Quantity | na.AbstractScalar,
) -> na.AbstractScalar:
return self.layers[0].n(wavelength)

@property
def thickness(self) -> u.Quantity | na.AbstractScalar:
return self.num_periods * LayerSequence(self.layers).thickness
Expand Down
10 changes: 10 additions & 0 deletions optika/materials/_tests/test_layers.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,16 @@ class AbstractTestAbstractLayer(
optika._tests.test_mixins.AbstractTestPrintable,
):

@pytest.mark.parametrize("wavelength", [100 * u.AA])
def test_n(
self,
a: optika.materials.AbstractLayer,
wavelength: u.Quantity | na.AbstractScalar,
):
result = a.n(wavelength)
assert np.all(np.real(result) >=0)
assert np.all(np.imag(result) >=0)

def test_thickness(
self,
a: optika.materials.AbstractLayer,
Expand Down

0 comments on commit ce0051b

Please sign in to comment.