From 81b5191c2ede54e9be7faaf1df4a710fd39e11a9 Mon Sep 17 00:00:00 2001 From: tylerflex Date: Mon, 25 Apr 2022 15:05:03 -0700 Subject: [PATCH] changed inheritance structure to make PointDipole work properly --- tests/test_IO.py | 1 + tests/utils.py | 10 +++++++++- tidy3d/components/source.py | 32 +++++++++++++++++++------------- 3 files changed, 29 insertions(+), 14 deletions(-) diff --git a/tests/test_IO.py b/tests/test_IO.py index 27eacb7c2..c92d90686 100644 --- a/tests/test_IO.py +++ b/tests/test_IO.py @@ -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) diff --git a/tests/utils.py b/tests/utils.py index 1f679f1a7..ecb05adac 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -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"), diff --git a/tidy3d/components/source.py b/tidy3d/components/source.py index c07b33c4e..853971af0 100644 --- a/tidy3d/components/source.py +++ b/tidy3d/components/source.py @@ -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", @@ -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)