differt 0.11.0__tar.gz → 0.12.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {differt-0.11.0 → differt-0.12.0}/PKG-INFO +4 -4
- {differt-0.11.0 → differt-0.12.0}/README.md +1 -1
- {differt-0.11.0 → differt-0.12.0}/pyproject.toml +2 -2
- differt-0.12.0/src/differt/__init__.py +71 -0
- {differt-0.11.0 → differt-0.12.0}/src/differt/em/__init__.py +17 -3
- {differt-0.11.0 → differt-0.12.0}/src/differt/em/_antenna.py +6 -6
- {differt-0.11.0 → differt-0.12.0}/src/differt/em/_fields.py +20 -58
- {differt-0.11.0 → differt-0.12.0}/src/differt/em/_fresnel.py +1 -2
- {differt-0.11.0 → differt-0.12.0}/src/differt/em/_interaction_type.py +12 -0
- {differt-0.11.0 → differt-0.12.0}/src/differt/em/_material.py +92 -3
- {differt-0.11.0 → differt-0.12.0}/src/differt/em/_pipeline.py +72 -60
- {differt-0.11.0 → differt-0.12.0}/src/differt/em/_solvers.py +546 -399
- {differt-0.11.0 → differt-0.12.0}/src/differt/em/_utd.py +10 -7
- {differt-0.11.0 → differt-0.12.0}/src/differt/em/_utils.py +32 -1
- differt-0.12.0/src/differt/em/_wavefront.py +447 -0
- {differt-0.11.0 → differt-0.12.0}/src/differt/geometry/__init__.py +11 -16
- differt-0.12.0/src/differt/geometry/_interaction_sites.py +189 -0
- {differt-0.11.0 → differt-0.12.0}/src/differt/geometry/_mesh.py +79 -65
- {differt-0.11.0 → differt-0.12.0}/src/differt/geometry/_paths.py +252 -80
- {differt-0.11.0 → differt-0.12.0}/src/differt/geometry/_scene.py +126 -481
- {differt-0.11.0 → differt-0.12.0}/src/differt/geometry/_sionna.py +3 -3
- {differt-0.11.0 → differt-0.12.0}/src/differt/geometry/_solver_fermat.py +101 -8
- {differt-0.11.0 → differt-0.12.0}/src/differt/geometry/_solver_image_method.py +7 -3
- {differt-0.11.0 → differt-0.12.0}/src/differt/geometry/_utils.py +18 -15
- {differt-0.11.0 → differt-0.12.0}/src/differt/geometry/_warp_utils.py +4 -50
- differt-0.12.0/src/differt/geometry/solvers/__init__.py +41 -0
- differt-0.12.0/src/differt/geometry/solvers/_base.py +1192 -0
- differt-0.12.0/src/differt/geometry/solvers/_dispatch.py +342 -0
- differt-0.12.0/src/differt/geometry/solvers/_exhaustive.py +322 -0
- differt-0.12.0/src/differt/geometry/solvers/_hybrid.py +383 -0
- differt-0.12.0/src/differt/geometry/solvers/_sbr.py +555 -0
- {differt-0.11.0 → differt-0.12.0}/src/differt/plotting/_core.py +13 -11
- {differt-0.11.0 → differt-0.12.0}/src/differt/plotting/_utils.py +8 -10
- {differt-0.11.0 → differt-0.12.0}/src/differt/plugins/deepmimo.py +45 -278
- differt-0.11.0/src/differt/__init__.py +0 -8
- differt-0.11.0/src/differt/geometry/_solvers.py +0 -1914
- differt-0.11.0/src/differt/rt/__init__.py +0 -45
- differt-0.11.0/src/differt/scene/__init__.py +0 -47
- {differt-0.11.0 → differt-0.12.0}/.gitignore +0 -0
- {differt-0.11.0 → differt-0.12.0}/LICENSE.md +0 -0
- {differt-0.11.0 → differt-0.12.0}/src/differt/_version.py +0 -0
- {differt-0.11.0 → differt-0.12.0}/src/differt/em/_constants.py +0 -0
- {differt-0.11.0 → differt-0.12.0}/src/differt/plotting/__init__.py +0 -0
- {differt-0.11.0 → differt-0.12.0}/src/differt/plugins/__init__.py +0 -0
- {differt-0.11.0 → differt-0.12.0}/src/differt/plugins/_deepmimo_types.py +0 -0
- {differt-0.11.0 → differt-0.12.0}/src/differt/py.typed +0 -0
- {differt-0.11.0 → differt-0.12.0}/src/differt/utils.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: DiffeRT
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.12.0
|
|
4
4
|
Summary: Differentiable Ray Tracing Toolbox for Radio Propagation Simulations
|
|
5
5
|
Project-URL: Changelog, https://github.com/jeertmans/DiffeRT/releases
|
|
6
6
|
Project-URL: Documentation, https://eertmans.be/DiffeRT
|
|
@@ -20,10 +20,10 @@ Classifier: Programming Language :: Python :: 3.14
|
|
|
20
20
|
Classifier: Topic :: Scientific/Engineering
|
|
21
21
|
Requires-Python: >=3.11
|
|
22
22
|
Requires-Dist: chex>=0.1.86
|
|
23
|
-
Requires-Dist: differt-core==0.
|
|
23
|
+
Requires-Dist: differt-core==0.12.0
|
|
24
24
|
Requires-Dist: equinox>=0.13.7
|
|
25
25
|
Requires-Dist: filelock>=3.15.4
|
|
26
|
-
Requires-Dist: fpt-jax==0.
|
|
26
|
+
Requires-Dist: fpt-jax==0.2.0
|
|
27
27
|
Requires-Dist: jax>=0.8.1
|
|
28
28
|
Requires-Dist: jaxtyping>=0.3.11
|
|
29
29
|
Requires-Dist: numpy>=1.26.1
|
|
@@ -156,7 +156,7 @@ or:
|
|
|
156
156
|
author = {Eertmans, Jérome},
|
|
157
157
|
url = {https://github.com/jeertmans/DiffeRT},
|
|
158
158
|
license = {MIT},
|
|
159
|
-
version = {v0.
|
|
159
|
+
version = {v0.12.0}
|
|
160
160
|
}
|
|
161
161
|
```
|
|
162
162
|
|
|
@@ -15,10 +15,10 @@ classifiers = [
|
|
|
15
15
|
]
|
|
16
16
|
dependencies = [
|
|
17
17
|
"chex>=0.1.86",
|
|
18
|
-
"differt-core==0.
|
|
18
|
+
"differt-core==0.12.0",
|
|
19
19
|
"equinox>=0.13.7",
|
|
20
20
|
"filelock>=3.15.4",
|
|
21
|
-
"fpt-jax==0.
|
|
21
|
+
"fpt-jax==0.2.0",
|
|
22
22
|
"jax>=0.8.1",
|
|
23
23
|
"jaxtyping>=0.3.11",
|
|
24
24
|
"numpy>=1.26.1",
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"""Differentiable Ray Tracing Toolbox for Radio Propagation."""
|
|
2
|
+
|
|
3
|
+
__all__ = (
|
|
4
|
+
"RIS",
|
|
5
|
+
"Diffraction",
|
|
6
|
+
"InteractionType",
|
|
7
|
+
"LaunchedPaths",
|
|
8
|
+
"Material",
|
|
9
|
+
"Mesh",
|
|
10
|
+
"Scattering",
|
|
11
|
+
"Scene",
|
|
12
|
+
"SpecularReflection",
|
|
13
|
+
"TracedPaths",
|
|
14
|
+
"Transmission",
|
|
15
|
+
"WavefrontState",
|
|
16
|
+
"__version__",
|
|
17
|
+
"__version_info__",
|
|
18
|
+
"propagate_wavefront",
|
|
19
|
+
)
|
|
20
|
+
|
|
21
|
+
import importlib
|
|
22
|
+
from typing import TYPE_CHECKING
|
|
23
|
+
|
|
24
|
+
from ._version import __version__, __version_info__
|
|
25
|
+
|
|
26
|
+
if TYPE_CHECKING:
|
|
27
|
+
from .em import (
|
|
28
|
+
RIS,
|
|
29
|
+
Diffraction,
|
|
30
|
+
InteractionType,
|
|
31
|
+
Material,
|
|
32
|
+
Scattering,
|
|
33
|
+
SpecularReflection,
|
|
34
|
+
Transmission,
|
|
35
|
+
WavefrontState,
|
|
36
|
+
propagate_wavefront,
|
|
37
|
+
)
|
|
38
|
+
from .geometry import LaunchedPaths, Mesh, Scene, TracedPaths
|
|
39
|
+
|
|
40
|
+
# Lazily re-export the most commonly used names from 'differt.geometry' and
|
|
41
|
+
# 'differt.em' at the top level (PEP 562), so 'import differt' stays cheap:
|
|
42
|
+
# neither submodule (and none of their heavy dependencies, e.g. 'warp' or
|
|
43
|
+
# 'fpt_jax') is imported until one of these names is actually accessed.
|
|
44
|
+
# This also sidesteps the geometry <-> em circular import (see
|
|
45
|
+
# 'Scene.load_xml'/'Scene.trace_fields' for its existing occurrences).
|
|
46
|
+
_LAZY = {
|
|
47
|
+
"Scene": ".geometry",
|
|
48
|
+
"Mesh": ".geometry",
|
|
49
|
+
"TracedPaths": ".geometry",
|
|
50
|
+
"LaunchedPaths": ".geometry",
|
|
51
|
+
"Material": ".em",
|
|
52
|
+
"InteractionType": ".em",
|
|
53
|
+
"SpecularReflection": ".em",
|
|
54
|
+
"Diffraction": ".em",
|
|
55
|
+
"Scattering": ".em",
|
|
56
|
+
"Transmission": ".em",
|
|
57
|
+
"RIS": ".em",
|
|
58
|
+
"WavefrontState": ".em",
|
|
59
|
+
"propagate_wavefront": ".em",
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
def __getattr__(name: str) -> object:
|
|
64
|
+
if mod := _LAZY.get(name):
|
|
65
|
+
return getattr(importlib.import_module(mod, __name__), name)
|
|
66
|
+
msg = f"module {__name__!r} has no attribute {name!r}"
|
|
67
|
+
raise AttributeError(msg)
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
def __dir__() -> list[str]:
|
|
71
|
+
return sorted({*globals(), *_LAZY})
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"""Electromagnetic (EM) fields utilities."""
|
|
2
2
|
|
|
3
3
|
__all__ = (
|
|
4
|
+
"RIS",
|
|
4
5
|
"AbstractAntenna",
|
|
5
6
|
"AbstractFarFieldAntenna",
|
|
6
7
|
"AbstractFieldSolver",
|
|
@@ -8,6 +9,7 @@ __all__ = (
|
|
|
8
9
|
"AbstractScatteringPattern",
|
|
9
10
|
"BackscatteringPattern",
|
|
10
11
|
"BaseAntenna",
|
|
12
|
+
"Diffraction",
|
|
11
13
|
"Dipole",
|
|
12
14
|
"DirectivePattern",
|
|
13
15
|
"F",
|
|
@@ -19,9 +21,14 @@ __all__ = (
|
|
|
19
21
|
"LambertianPattern",
|
|
20
22
|
"Material",
|
|
21
23
|
"MaterialsDict",
|
|
24
|
+
"PathWavefront",
|
|
25
|
+
"Scattering",
|
|
22
26
|
"ShortDipole",
|
|
23
27
|
"ShortDipolePattern",
|
|
28
|
+
"SpecularReflection",
|
|
24
29
|
"TracedFields",
|
|
30
|
+
"Transmission",
|
|
31
|
+
"WavefrontState",
|
|
25
32
|
"c",
|
|
26
33
|
"compute_cir",
|
|
27
34
|
"compute_received_fields",
|
|
@@ -36,6 +43,7 @@ __all__ = (
|
|
|
36
43
|
"mu_0",
|
|
37
44
|
"path_delay",
|
|
38
45
|
"poynting_vector",
|
|
46
|
+
"propagate_wavefront",
|
|
39
47
|
"reflection_coefficients",
|
|
40
48
|
"reflection_matrix",
|
|
41
49
|
"refraction_coefficients",
|
|
@@ -45,7 +53,6 @@ __all__ = (
|
|
|
45
53
|
"slab_coefficients",
|
|
46
54
|
"sp_directions",
|
|
47
55
|
"sp_rotation_matrix",
|
|
48
|
-
"transition_matrices",
|
|
49
56
|
"transition_matrix",
|
|
50
57
|
"transmission_matrix",
|
|
51
58
|
"z_0",
|
|
@@ -72,7 +79,14 @@ from ._fresnel import (
|
|
|
72
79
|
refractive_index,
|
|
73
80
|
slab_coefficients,
|
|
74
81
|
)
|
|
75
|
-
from ._interaction_type import
|
|
82
|
+
from ._interaction_type import (
|
|
83
|
+
RIS,
|
|
84
|
+
Diffraction,
|
|
85
|
+
InteractionType,
|
|
86
|
+
Scattering,
|
|
87
|
+
SpecularReflection,
|
|
88
|
+
Transmission,
|
|
89
|
+
)
|
|
76
90
|
from ._material import (
|
|
77
91
|
AbstractScatteringPattern,
|
|
78
92
|
BackscatteringPattern,
|
|
@@ -90,7 +104,6 @@ from ._pipeline import (
|
|
|
90
104
|
reflection_matrix,
|
|
91
105
|
ris_matrix,
|
|
92
106
|
scattering_matrix,
|
|
93
|
-
transition_matrices,
|
|
94
107
|
transition_matrix,
|
|
95
108
|
transmission_matrix,
|
|
96
109
|
)
|
|
@@ -103,3 +116,4 @@ from ._utils import (
|
|
|
103
116
|
sp_directions,
|
|
104
117
|
sp_rotation_matrix,
|
|
105
118
|
)
|
|
119
|
+
from ._wavefront import PathWavefront, WavefrontState, propagate_wavefront
|
|
@@ -113,7 +113,7 @@ class AbstractAntenna(BaseAntenna):
|
|
|
113
113
|
Fields can be either real or complex-valued.
|
|
114
114
|
"""
|
|
115
115
|
|
|
116
|
-
def wavefront_radii( # ruff:ignore[no-self-use]
|
|
116
|
+
def wavefront_radii( # ruff: ignore[no-self-use]
|
|
117
117
|
self,
|
|
118
118
|
k_hat: Float[ArrayLike, "*#batch 3"],
|
|
119
119
|
) -> (
|
|
@@ -247,7 +247,7 @@ class AbstractAntenna(BaseAntenna):
|
|
|
247
247
|
ds = du * dv
|
|
248
248
|
|
|
249
249
|
# Power per unit solid angle
|
|
250
|
-
U = p / ds # ruff:ignore[non-lowercase-variable-in-function]
|
|
250
|
+
U = p / ds # ruff: ignore[non-lowercase-variable-in-function]
|
|
251
251
|
p_tot = jnp.sum(p * jnp.sin(v)) / (4 * jnp.pi)
|
|
252
252
|
|
|
253
253
|
return u, v, U / p_tot
|
|
@@ -538,9 +538,9 @@ class Dipole(AbstractAntenna):
|
|
|
538
538
|
|
|
539
539
|
return u, v, 1.5 * jax.lax.integer_pow(sin_theta, 2)
|
|
540
540
|
|
|
541
|
-
def directive_gain( # ruff:ignore[no-self-use]
|
|
541
|
+
def directive_gain( # ruff: ignore[no-self-use]
|
|
542
542
|
self,
|
|
543
|
-
num_points: int = int(1e2), # ruff:ignore[unused-method-argument]
|
|
543
|
+
num_points: int = int(1e2), # ruff: ignore[unused-method-argument]
|
|
544
544
|
) -> Float[Array, ""]:
|
|
545
545
|
return jnp.array(1.5)
|
|
546
546
|
|
|
@@ -606,9 +606,9 @@ class AbstractFarFieldAntenna(AbstractAntenna):
|
|
|
606
606
|
<differt.em.GeometricFieldSolver.spreading_factor>`.
|
|
607
607
|
"""
|
|
608
608
|
|
|
609
|
-
def wavefront_radii( # ruff:ignore[no-self-use]
|
|
609
|
+
def wavefront_radii( # ruff: ignore[no-self-use]
|
|
610
610
|
self,
|
|
611
|
-
k_hat: Float[ # ruff:ignore[unused-method-argument]
|
|
611
|
+
k_hat: Float[ # ruff: ignore[unused-method-argument]
|
|
612
612
|
ArrayLike, "*#batch 3"
|
|
613
613
|
],
|
|
614
614
|
) -> None:
|
|
@@ -3,15 +3,19 @@ from collections.abc import Callable, Sequence
|
|
|
3
3
|
from typing import TYPE_CHECKING, Any, Literal
|
|
4
4
|
|
|
5
5
|
import equinox as eqx
|
|
6
|
-
import jax
|
|
7
6
|
import jax.numpy as jnp
|
|
8
7
|
from jaxtyping import Array, ArrayLike, Bool, Complex, Float, Int, Num
|
|
9
8
|
|
|
10
9
|
from differt.geometry._mesh import Mesh
|
|
11
10
|
from differt.geometry._paths import TracedPaths
|
|
12
11
|
|
|
13
|
-
from ._constants import
|
|
14
|
-
from .
|
|
12
|
+
from ._constants import z_0
|
|
13
|
+
from ._pipeline import (
|
|
14
|
+
_resolve_solver_and_frequency,
|
|
15
|
+
compute_cir,
|
|
16
|
+
compute_received_power,
|
|
17
|
+
)
|
|
18
|
+
from ._solvers import AbstractFieldSolver
|
|
15
19
|
|
|
16
20
|
if TYPE_CHECKING or hasattr(typing, "GENERATING_DOCS"):
|
|
17
21
|
from typing import Self
|
|
@@ -19,24 +23,6 @@ else:
|
|
|
19
23
|
Self = Any # Because runtime type checking from 'beartype' will fail when combined with 'jaxtyping'
|
|
20
24
|
|
|
21
25
|
|
|
22
|
-
@jax.jit(static_argnames=("coherent", "axis"))
|
|
23
|
-
def _compute_power(
|
|
24
|
-
fields: Complex[Array, "*batch"],
|
|
25
|
-
z_0: Float[ArrayLike, ""] | float = z_0,
|
|
26
|
-
coherent: bool = True,
|
|
27
|
-
axis: int | None = None,
|
|
28
|
-
) -> Float[Array, "..."]:
|
|
29
|
-
if axis is not None:
|
|
30
|
-
if coherent:
|
|
31
|
-
summed_fields = jnp.sum(fields, axis=axis)
|
|
32
|
-
power = jnp.abs(summed_fields) ** 2 / z_0
|
|
33
|
-
else:
|
|
34
|
-
power = jnp.sum(jnp.abs(fields) ** 2 / z_0, axis=axis)
|
|
35
|
-
else:
|
|
36
|
-
power = jnp.abs(fields) ** 2 / z_0
|
|
37
|
-
return 10.0 * jnp.log10(power)
|
|
38
|
-
|
|
39
|
-
|
|
40
26
|
class TracedFields(eqx.Module):
|
|
41
27
|
"""
|
|
42
28
|
A convenient wrapper class around received electromagnetic fields, propagation delays, and masks.
|
|
@@ -206,7 +192,9 @@ class TracedFields(eqx.Module):
|
|
|
206
192
|
Returns:
|
|
207
193
|
The received power in dBW.
|
|
208
194
|
"""
|
|
209
|
-
return
|
|
195
|
+
return compute_received_power(
|
|
196
|
+
self.fields, z_0=z_0, coherent=coherent, axis=axis
|
|
197
|
+
)
|
|
210
198
|
|
|
211
199
|
def cir(self) -> tuple[Float[Array, "*batch"], Complex[Array, "*batch"]]:
|
|
212
200
|
"""
|
|
@@ -271,44 +259,18 @@ class TracedFields(eqx.Module):
|
|
|
271
259
|
Returns:
|
|
272
260
|
A :class:`TracedFields` instance wrapping the computed fields, propagation
|
|
273
261
|
delays, operating frequency, and validity mask.
|
|
274
|
-
|
|
275
|
-
Raises:
|
|
276
|
-
ValueError: If an unknown solver name is passed, if ``solver_kwargs``
|
|
277
|
-
are supplied alongside a solver instance, or if ``frequency``
|
|
278
|
-
is omitted and cannot be inferred from the transmitter antenna.
|
|
279
262
|
"""
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
elif solver_kwargs:
|
|
289
|
-
msg = "solver_kwargs cannot be used when a solver instance is provided."
|
|
290
|
-
raise ValueError(msg)
|
|
291
|
-
else:
|
|
292
|
-
solver_instance = solver
|
|
293
|
-
|
|
294
|
-
if frequency is None:
|
|
295
|
-
tx_polarization = getattr(solver_instance, "tx_polarization", None)
|
|
296
|
-
frequency_val = getattr(tx_polarization, "frequency", None)
|
|
297
|
-
if frequency_val is None:
|
|
298
|
-
msg = (
|
|
299
|
-
"'frequency' must be provided explicitly, unless "
|
|
300
|
-
"'tx_polarization' is an 'AbstractAntenna' instance."
|
|
301
|
-
)
|
|
302
|
-
raise ValueError(msg)
|
|
263
|
+
wavefront_radii = solver_kwargs.pop("wavefront_radii", None)
|
|
264
|
+
solver_instance, frequency_arr = _resolve_solver_and_frequency(
|
|
265
|
+
solver, frequency, solver_kwargs
|
|
266
|
+
)
|
|
267
|
+
if wavefront_radii is not None and hasattr(solver_instance, "compute_fields"):
|
|
268
|
+
fields = solver_instance.compute_fields(
|
|
269
|
+
paths, mesh, frequency_arr, wavefront_radii=wavefront_radii
|
|
270
|
+
)
|
|
303
271
|
else:
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
frequency_arr = jnp.asarray(frequency_val)
|
|
307
|
-
fields = solver_instance.compute_fields(paths, mesh, frequency_arr)
|
|
308
|
-
|
|
309
|
-
path_segments = jnp.diff(paths.vertices, axis=-2)
|
|
310
|
-
lengths = jnp.linalg.norm(path_segments, axis=-1).sum(axis=-1)
|
|
311
|
-
delay = lengths / c
|
|
272
|
+
fields = solver_instance.compute_fields(paths, mesh, frequency_arr)
|
|
273
|
+
delay, fields = compute_cir(paths, fields)
|
|
312
274
|
|
|
313
275
|
return cls(
|
|
314
276
|
fields=fields,
|
|
@@ -256,8 +256,7 @@ def reflection_coefficients(
|
|
|
256
256
|
... reflection_coefficients,
|
|
257
257
|
... sp_directions,
|
|
258
258
|
... )
|
|
259
|
-
>>> from differt.geometry import normalize
|
|
260
|
-
>>> from differt.rt import image_method
|
|
259
|
+
>>> from differt.geometry import image_method, normalize
|
|
261
260
|
|
|
262
261
|
The first step is to define the antenna and the geometry of the scene.
|
|
263
262
|
Here, we place a dipole antenna above the origin, and generate a
|
|
@@ -17,3 +17,15 @@ class InteractionType(IntEnum):
|
|
|
17
17
|
"""Transmission through a surface."""
|
|
18
18
|
RIS = 4
|
|
19
19
|
"""Interaction with a Reconfigurable Intelligent Surface (RIS)."""
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
SpecularReflection = InteractionType.REFLECTION
|
|
23
|
+
"""Alias for :attr:`InteractionType.REFLECTION`."""
|
|
24
|
+
Diffraction = InteractionType.DIFFRACTION
|
|
25
|
+
"""Alias for :attr:`InteractionType.DIFFRACTION`."""
|
|
26
|
+
Scattering = InteractionType.SCATTERING
|
|
27
|
+
"""Alias for :attr:`InteractionType.SCATTERING`."""
|
|
28
|
+
Transmission = InteractionType.TRANSMISSION
|
|
29
|
+
"""Alias for :attr:`InteractionType.TRANSMISSION`."""
|
|
30
|
+
RIS = InteractionType.RIS
|
|
31
|
+
"""Alias for :attr:`InteractionType.RIS`."""
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
# ruff:file-ignore[math-constant]
|
|
1
|
+
# ruff: file-ignore[math-constant]
|
|
2
2
|
|
|
3
|
+
import dataclasses
|
|
3
4
|
import typing
|
|
4
5
|
from abc import abstractmethod
|
|
5
|
-
from collections.abc import Callable, Iterable, Mapping
|
|
6
|
+
from collections.abc import Callable, Iterable, Mapping, MutableMapping
|
|
6
7
|
from functools import partial
|
|
7
8
|
from typing import TYPE_CHECKING, Any
|
|
8
9
|
|
|
@@ -11,6 +12,9 @@ import jax
|
|
|
11
12
|
import jax.numpy as jnp
|
|
12
13
|
from jaxtyping import Array, ArrayLike, Float
|
|
13
14
|
|
|
15
|
+
if TYPE_CHECKING:
|
|
16
|
+
import differt_core.geometry
|
|
17
|
+
|
|
14
18
|
if TYPE_CHECKING or hasattr(typing, "GENERATING_DOCS"):
|
|
15
19
|
from typing import Self
|
|
16
20
|
else:
|
|
@@ -244,7 +248,7 @@ class BackscatteringPattern(AbstractScatteringPattern):
|
|
|
244
248
|
|
|
245
249
|
|
|
246
250
|
class Material(eqx.Module):
|
|
247
|
-
"""A class representing a material and
|
|
251
|
+
"""A class representing a material and its electrical properties."""
|
|
248
252
|
|
|
249
253
|
name: str = eqx.field(static=True)
|
|
250
254
|
"""
|
|
@@ -684,3 +688,88 @@ or by its Sionna-compatible alias (e.g., ``'itu_concrete'``).
|
|
|
684
688
|
See :ref:`itu-materials-table` for a table of all available ITU radio materials, their aliases, and electrical properties."""
|
|
685
689
|
|
|
686
690
|
del _materials
|
|
691
|
+
|
|
692
|
+
|
|
693
|
+
def _populate_materials(
|
|
694
|
+
scene_materials: Iterable["differt_core.geometry.Material"],
|
|
695
|
+
materials: MutableMapping[str, Material],
|
|
696
|
+
) -> None:
|
|
697
|
+
"""
|
|
698
|
+
Populate ``materials`` in place with the per-shape radio material overrides of a loaded XML scene.
|
|
699
|
+
|
|
700
|
+
Used by :meth:`Scene.load_xml<differt.geometry.Scene.load_xml>` so that a scene's ITU
|
|
701
|
+
radio materials (currently, only ``thickness``, read from a
|
|
702
|
+
``<float name="thickness" value="..."/>`` child element) are ready to use, without the
|
|
703
|
+
caller having to build a materials mapping by hand.
|
|
704
|
+
|
|
705
|
+
Each overridden material is looked up in ``materials`` by its generic,
|
|
706
|
+
ITU-type-derived name (e.g., ``'itu_glass'``) to find its base electrical properties,
|
|
707
|
+
then stored back keyed the same way -- *unless* another material of the same type in
|
|
708
|
+
``scene_materials`` disagrees on the override (e.g., two ``type="glass"`` shapes with
|
|
709
|
+
different ``thickness`` values), in which case each is kept under its own, unique XML id
|
|
710
|
+
instead, so they remain distinguishable. This matches how
|
|
711
|
+
:meth:`Scene.load_xml<differt.geometry.Scene.load_xml>` keys
|
|
712
|
+
:attr:`Mesh.material_names<differt.geometry.Mesh.material_names>`.
|
|
713
|
+
|
|
714
|
+
Args:
|
|
715
|
+
scene_materials: The materials of a loaded scene, e.g., the values of
|
|
716
|
+
``differt_core.geometry.SionnaScene.load_xml(file).materials``.
|
|
717
|
+
materials: The mapping to populate, both as the source of each material's base
|
|
718
|
+
electrical properties (matched by :attr:`Material.name<differt.em._material.Material.name>`,
|
|
719
|
+
or one of its :attr:`Material.aliases<differt.em._material.Material.aliases>`) and as the
|
|
720
|
+
target it is updated in. A material whose name does not match any entry (e.g.,
|
|
721
|
+
a non-ITU, purely visual material) is skipped.
|
|
722
|
+
|
|
723
|
+
Raises:
|
|
724
|
+
ValueError: If a material is already present in ``materials`` with a different,
|
|
725
|
+
already-set ``thickness`` (e.g., from an earlier call with a conflicting scene).
|
|
726
|
+
"""
|
|
727
|
+
scene_materials = list(scene_materials)
|
|
728
|
+
|
|
729
|
+
seen: dict[str, float | None] = {}
|
|
730
|
+
non_uniform_names: set[str] = set()
|
|
731
|
+
for mat in scene_materials:
|
|
732
|
+
if mat.name in seen:
|
|
733
|
+
if seen[mat.name] != mat.thickness:
|
|
734
|
+
non_uniform_names.add(mat.name)
|
|
735
|
+
else:
|
|
736
|
+
seen[mat.name] = mat.thickness
|
|
737
|
+
|
|
738
|
+
for mat in scene_materials:
|
|
739
|
+
if mat.thickness is None:
|
|
740
|
+
continue
|
|
741
|
+
|
|
742
|
+
base = materials.get(mat.name)
|
|
743
|
+
if base is None:
|
|
744
|
+
continue
|
|
745
|
+
|
|
746
|
+
is_non_uniform = mat.name in non_uniform_names
|
|
747
|
+
key = mat.id if is_non_uniform else mat.name
|
|
748
|
+
existing = materials.get(key)
|
|
749
|
+
|
|
750
|
+
if (
|
|
751
|
+
existing is not None
|
|
752
|
+
and existing.thickness is not None
|
|
753
|
+
and existing.thickness != mat.thickness
|
|
754
|
+
):
|
|
755
|
+
msg = (
|
|
756
|
+
f"Material {key!r} is already present with a different 'thickness' "
|
|
757
|
+
f"({existing.thickness!r} != {mat.thickness!r})."
|
|
758
|
+
)
|
|
759
|
+
raise ValueError(msg)
|
|
760
|
+
|
|
761
|
+
value = existing if existing is not None else base
|
|
762
|
+
if is_non_uniform:
|
|
763
|
+
# A brand new key that does not match 'value.name' (nor any of its
|
|
764
|
+
# aliases) would otherwise be silently stored under 'value.name' by
|
|
765
|
+
# 'MaterialsDict.__setitem__', so the material must be renamed to
|
|
766
|
+
# its unique id to be kept distinguishable. 'name' is a static
|
|
767
|
+
# field, so it must be replaced via 'dataclasses.replace' rather
|
|
768
|
+
# than 'eqx.tree_at', which only rewrites pytree leaves.
|
|
769
|
+
value = dataclasses.replace(value, name=key)
|
|
770
|
+
materials[key] = eqx.tree_at(
|
|
771
|
+
lambda m: m.thickness,
|
|
772
|
+
value,
|
|
773
|
+
replace=mat.thickness,
|
|
774
|
+
is_leaf=lambda x: x is None,
|
|
775
|
+
)
|