compute_energy(
E: Array,
H: Array,
inv_permittivity: Array | float,
inv_permeability: Array | float,
axis: int = 0,
) -> jax.Array
Computes the total electromagnetic energy density of the field.
Parameters: |
-
E
(Array )
–
Electric field array with shape (3, nx, ny, nz)
-
H
(Array )
–
Magnetic field array with shape (3, nx, ny, nz)
-
inv_permittivity
(Array | float )
–
Inverse of the electric permittivity array
-
inv_permeability
(Array | float )
–
Inverse of the magnetic permeability array
-
axis
(int , default:
0
)
–
Axis index of the X,Y,Z component for the E and H field. Defaults to 0.
|
Returns:
jax.Array: Total energy density array with shape (nx, ny, nz)
Source code in src/fdtdx/core/physics/metrics.py
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38 | def compute_energy(
E: jax.Array,
H: jax.Array,
inv_permittivity: jax.Array | float,
inv_permeability: jax.Array | float,
axis: int = 0,
) -> jax.Array:
"""Computes the total electromagnetic energy density of the field.
Args:
E (jax.Array): Electric field array with shape (3, nx, ny, nz)
H (jax.Array): Magnetic field array with shape (3, nx, ny, nz)
inv_permittivity (jax.Array | float): Inverse of the electric permittivity array
inv_permeability (jax.Array | float): Inverse of the magnetic permeability array
axis (int, optional): Axis index of the X,Y,Z component for the E and H field. Defaults to 0.
Returns:
jax.Array: Total energy density array with shape (nx, ny, nz)
"""
abs_E = jnp.sum(jnp.square(jnp.abs(E)), axis=axis)
energy_E = 0.5 * (1 / inv_permittivity) * abs_E
abs_H = jnp.sum(jnp.square(jnp.abs(H)), axis=axis)
energy_H = 0.5 * (1 / inv_permeability) * abs_H
total_energy = energy_E + energy_H
return total_energy
|