Skip to content

Commit

Permalink
changed inheritance structure to make PointDipole work properly
Browse files Browse the repository at this point in the history
  • Loading branch information
tylerflex committed Apr 25, 2022
1 parent be978ab commit 81b5191
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 14 deletions.
1 change: 1 addition & 0 deletions tests/test_IO.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

@clear_tmp
def test_simulation_load_export():

path = "tests/tmp/simulation.json"
SIM.to_file(path)
SIM2 = Simulation.from_file(path)
Expand Down
10 changes: 9 additions & 1 deletion tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,15 @@ def prepend_tmp(path):
freq0=2e14,
fwidth=4e13,
),
)
),
PointDipole(
center=(0, 0.5, 0),
polarization="Ex",
source_time=GaussianPulse(
freq0=2e14,
fwidth=4e13,
),
),
],
monitors={
FieldMonitor(size=(0, 0, 0), center=(0, 0, 0), freqs=[1.5e14, 2e14], name="point"),
Expand Down
32 changes: 19 additions & 13 deletions tidy3d/components/source.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,19 +323,9 @@ def plot(
""" Sources either: (1) implement current distributions or (2) generate fields."""


class CurrentSource(Source):
class CurrentSource(Source, ABC):
"""Source implements a current distribution directly."""


class UniformCurrentSource(CurrentSource):
"""Source in a rectangular volume with uniform time dependence. size=(0,0,0) gives point source.
Example
-------
>>> pulse = GaussianPulse(freq0=200e12, fwidth=20e12)
>>> pt_source = UniformCurrentSource(size=(0,0,0), source_time=pulse, polarization='Ex')
"""

polarization: Polarization = pydantic.Field(
...,
title="Polarization",
Expand All @@ -354,8 +344,24 @@ def _pol_vector(self) -> Tuple[float, float, float]:
return None


class PointDipole(UniformCurrentSource):
"""Uniform current source with a zero size."""
class UniformCurrentSource(CurrentSource):
"""Source in a rectangular volume with uniform time dependence. size=(0,0,0) gives point source.
Example
-------
>>> pulse = GaussianPulse(freq0=200e12, fwidth=20e12)
>>> pt_source = UniformCurrentSource(size=(0,0,0), source_time=pulse, polarization='Ex')
"""


class PointDipole(CurrentSource):
"""Uniform current source with a zero size.
Example
-------
>>> pulse = GaussianPulse(freq0=200e12, fwidth=20e12)
>>> pt_dipole = PointDipole(center=(1,2,3), source_time=pulse, polarization='Ex')
"""

size: Tuple[Literal[0], Literal[0], Literal[0]] = (0, 0, 0)

Expand Down

0 comments on commit 81b5191

Please sign in to comment.