Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions examples/free_particle_and_dipole_interaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,15 @@ def plot_z_position(ax, times, z_pos, color, title, vline_time=None):
ts_fs = ts * 1e15 # Time in femtoseconds

# Create titles with charge and position information
d1_title = f"Dipole Charge 1 (q={-q_dipole / e:.0f}e)\n(x={dipole_origin[0] * 1e9:.1f} nm, y={dipole_origin[1] * 1e9:.1f} nm)"
d2_title = f"Dipole Charge 2 (q={q_dipole / e:.0f}e)\n(x={dipole_origin[0] * 1e9:.1f} nm, y={dipole_origin[1] * 1e9:.1f} nm)"
p_title = f"Free Particle (q={q_particle / e:.0f}e)\n(x={particle_position[0] * 1e9:.1f} nm, y={particle_position[1] * 1e9:.1f} nm)"


def charge_title(label: str, q: float, pos: list) -> str:
return f"{label} (q={q / e:.0f}e)\n(x={pos[0] * 1e9:.1f} nm, y={pos[1] * 1e9:.1f} nm)"


d1_title = charge_title("Dipole Charge 1", -q_dipole, dipole_origin)
d2_title = charge_title("Dipole Charge 2", q_dipole, dipole_origin)
p_title = charge_title("Free Particle", q_particle, particle_position)

plot_z_position(axes[0], ts_fs, d1_z, "C0", d1_title)
plot_z_position(axes[1], ts_fs, d2_z, "C1", d2_title)
Expand Down
4 changes: 4 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ where = ["src"]
[tool.ruff]
line-length = 110

[tool.ruff.lint]
select = ["E", "F", "I", "UP", "B", "SIM", "C4"]
ignore = ["B905"]

[tool.coverage.report]
omit = ["tests/*"]
exclude_lines = [
Expand Down
2 changes: 1 addition & 1 deletion src/pycharge/charge.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Point charge representation and solver configuration for electromagnetic simulations."""

from collections.abc import Callable
from dataclasses import dataclass, field
from typing import Callable

from scipy.constants import e

Expand Down
3 changes: 2 additions & 1 deletion src/pycharge/functional/functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

from __future__ import annotations

from typing import TYPE_CHECKING, Callable
from collections.abc import Callable
from typing import TYPE_CHECKING

import jax
import jax.numpy as jnp
Expand Down
3 changes: 2 additions & 1 deletion src/pycharge/potentials_and_fields.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Liénard-Wiechert potentials and electromagnetic fields from moving point charges."""

from typing import Callable, Iterable, NamedTuple
from collections.abc import Callable, Iterable
from typing import NamedTuple

import jax
import jax.numpy as jnp
Expand Down
2 changes: 1 addition & 1 deletion src/pycharge/simulate.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Time-stepping simulation of interacting electromagnetic sources."""

from collections.abc import Callable, Sequence
from dataclasses import replace
from typing import Callable, Sequence

import jax
import jax.numpy as jnp
Expand Down
2 changes: 1 addition & 1 deletion src/pycharge/sources.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Defines electromagnetic sources used in simulations."""

from collections.abc import Callable, Sequence
from dataclasses import dataclass
from typing import Callable, Sequence

import jax.numpy as jnp
from scipy.constants import c, e, epsilon_0, m_e
Expand Down
3 changes: 2 additions & 1 deletion src/pycharge/types.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Type aliases for scalar values and 3D vectors."""

from typing import Sequence, TypeAlias
from collections.abc import Sequence
from typing import TypeAlias

from jax.typing import ArrayLike

Expand Down
6 changes: 1 addition & 5 deletions tests/test_functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,7 @@ def test_source_time_moving(t_val):
t_switch = R / v0 # where the physical branch switches
t = jnp.array(t_val)

if t_val <= t_switch: # Branch: R - v0 * tr >= 0 → tr = (c * t - R) / (c - v0)
expected_tr = (c * t - R) / (c - v0)
else: # Branch: R - v0 * tr < 0 → tr = (c * t + R) / (c + v0)
expected_tr = (c * t + R) / (c + v0)

expected_tr = (c * t - R) / (c - v0) if t_val <= t_switch else (c * t + R) / (c + v0)
tr = emission_time(r, t, charge)
print(tr)
assert jnp.allclose(tr, expected_tr)
Expand Down