Skip to content

Commit

Permalink
chore(docs): cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
jeertmans committed Jan 10, 2025
1 parent 19cd268 commit 45a54fa
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 8 deletions.
9 changes: 8 additions & 1 deletion differt/src/differt/em/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"refractive_indices",
"sp_directions",
"sp_rotation_matrix",
"transition_matrices",
"z_0",
)

Expand All @@ -49,4 +50,10 @@
from ._interaction_type import InteractionType
from ._material import Material, materials
from ._utd import F, L_i, diffraction_coefficients
from ._utils import lengths_to_delays, path_delays, sp_directions, sp_rotation_matrix
from ._utils import (
lengths_to_delays,
path_delays,
sp_directions,
sp_rotation_matrix,
transition_matrices,
)
4 changes: 2 additions & 2 deletions differt/src/differt/em/_material.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class Material(eqx.Module):

@eqx.filter_jit
def relative_permittivity(
self, frequency: Float[Array, " *batch"]
self, frequency: Float[ArrayLike, " *batch"]
) -> Float[Array, " *batch"]:
"""
Compute the relative permittivity of the material at the given frequency.
Expand All @@ -61,7 +61,7 @@ def relative_permittivity(

@eqx.filter_jit
def conductivity(
self, frequency: Float[Array, " *batch"]
self, frequency: Float[ArrayLike, " *batch"]
) -> Float[Array, " *batch"]:
"""
Compute the conductivity of the material at the given frequency.
Expand Down
20 changes: 20 additions & 0 deletions differt/tests/em/test_fresnel.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,35 @@
import chex
import jax
import jax.experimental
import jax.numpy as jnp
import pytest
from jaxtyping import PRNGKeyArray

from differt.em import materials
from differt.em._fresnel import (
fresnel_coefficients,
reflection_coefficients,
refraction_coefficients,
refractive_indices,
)


@pytest.mark.parametrize(
("mat_name", "expected"),
[
("Vacuum", 1.0),
("Glass", 2.511971),
],
)
@jax.experimental.enable_x64()
def test_refractive_indices(mat_name: str, expected: float) -> None:
frequency = 1e9 # Hz
mat = materials[mat_name]
eta = mat.relative_permittivity(frequency)
got = refractive_indices(eta)
chex.assert_trees_all_close(got, expected)


def test_fresnel_coefficients(key: PRNGKeyArray) -> None:
key_n_1, key_n_2 = jax.random.split(key, 2)

Expand Down
25 changes: 25 additions & 0 deletions differt/tests/em/test_material.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,19 @@ def test_concrete(self) -> None:
chex.assert_trees_all_close(got_rel_perm, expected_rel_perm)
chex.assert_trees_all_close(got_cond, expected_cond)

def test_concrete_scalar(self) -> None:
mat = self.materials["itu_concrete"]

for f, expected_rel_perm, expected_cond in zip(
[0.1e9, 1e9, 10e9, 100e9, 1000e9],
[-1.0, 5.24, 5.24, 5.24, -1.0],
[-1.0, 0.0462, 0.279796, 1.694501, -1.0],
strict=False,
):
got_rel_perm, got_cond = mat.properties(f)
chex.assert_trees_all_close(got_rel_perm, expected_rel_perm)
chex.assert_trees_all_close(got_cond, expected_cond)

def test_glass(self) -> None:
mat = self.materials["itu_glass"]

Expand Down Expand Up @@ -144,3 +157,15 @@ def test_metal(self) -> None:
expected_cond = jnp.array([-1.0, 1e7, 1e7, 1e7, -1.0])
chex.assert_trees_all_close(got_rel_perm, expected_rel_perm)
chex.assert_trees_all_close(got_cond, expected_cond)

def test_wet_ground(self) -> None:
mat = self.materials["itu_wet_ground"]

f = jnp.array([0.1e9, 1e9, 10e9, 100e9])

got_rel_perm, got_cond = mat.relative_permittivity(f), mat.conductivity(f)

expected_rel_perm = jnp.array([-1.0, 30.0, 11.943215, -1.0])
expected_cond = jnp.array([-1.0, 0.15, 2.992893, -1.0])
chex.assert_trees_all_close(got_rel_perm, expected_rel_perm)
chex.assert_trees_all_close(got_cond, expected_cond)
19 changes: 14 additions & 5 deletions docs/source/reference/differt.em.rst
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ where :math:`\boldsymbol{D}` is the dyadic matrix with the diffraction coefficie
.. autosummary::
:toctree: _autosummary

diffraction_coefficients
fresnel_coefficients
reflection_coefficients
refraction_coefficients
Expand All @@ -80,10 +79,6 @@ when relevant.
BaseAntenna
Antenna
Dipole
ShortDipole
RadiationPattern
HWDipolePattern
ShortDipolePattern

.. rubric:: Materials

Expand Down Expand Up @@ -122,3 +117,17 @@ Utility functions, mostly used internally for computing EM fields.
sp_rotation_matrix
F
L_i

.. rubric:: Work in progress

The following utilities are still under development, and using them is not recommended.

.. autosummary::
:toctree: _autosummary

diffraction_coefficients
transition_matrices
ShortDipole
RadiationPattern
HWDipolePattern
ShortDipolePattern

0 comments on commit 45a54fa

Please sign in to comment.