Skip to content

Commit 7c7336c

Browse files
committed
revert previous commit to undo bugs it introduced. (#4)(#6)
This reverts commit 3e22a26.
1 parent 3e22a26 commit 7c7336c

File tree

5 files changed

+20
-66
lines changed

5 files changed

+20
-66
lines changed

fdtd/boundaries.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818

1919
## Boundary Conditions [base class]
20-
class Boundary:
20+
class _Boundary:
2121
""" an FDTD Boundary [base class] """
2222

2323
def __init__(self, name: str = None):
@@ -128,7 +128,7 @@ def _handle_slice(s):
128128

129129

130130
## Periodic Boundaries
131-
class PeriodicBoundary(Boundary):
131+
class PeriodicBoundary(_Boundary):
132132
""" An FDTD Periodic Boundary
133133
134134
Note:
@@ -211,7 +211,7 @@ def update_H(self):
211211
## Perfectly Matched Layer (PML)
212212

213213

214-
class PML(Boundary):
214+
class PML(_Boundary):
215215
""" A perfectly matched layer (PML)
216216
217217
a PML is an impedence-matched area at the boundary of the grid for which

fdtd/detectors.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,6 @@
1515
from .grid import Grid
1616
from .backend import backend as bd
1717

18-
## Base detector class:
19-
class Detector:
20-
""" an FDTD Detector [base class] """
21-
22-
2318
## Detector
2419
class LineDetector:
2520
""" A detector along a line in the FDTD grid """

fdtd/grid.py

Lines changed: 4 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -71,20 +71,6 @@ def curl_H(H: Tensorlike) -> Tensorlike:
7171
return curl
7272

7373

74-
class GridList(list):
75-
""" Special list that removes item from grid when deleted from list """
76-
77-
def __init__(self, grid):
78-
super().__init__([])
79-
self.grid = grid
80-
81-
def __delitem__(self, i):
82-
item = self[i]
83-
super().__delitem__(i)
84-
if hasattr(item, "name") and hasattr(self.grid, item.name):
85-
delattr(self.grid, item.name)
86-
87-
8874
## FDTD Grid Class
8975
class Grid:
9076
""" The FDTD Grid
@@ -163,16 +149,16 @@ def __init__(
163149
self.time_steps_passed = 0
164150

165151
# dictionary containing the sources:
166-
self.sources = GridList(self)
152+
self.sources = []
167153

168154
# dictionary containing the boundaries
169-
self.boundaries = GridList(self)
155+
self.boundaries = []
170156

171157
# dictionary containing the detectors
172-
self.detectors = GridList(self)
158+
self.detectors = []
173159

174160
# dictionary containing the objects in the grid
175-
self.objects = GridList(self)
161+
self.objects = []
176162

177163
def _handle_distance(self, distance: Number) -> int:
178164
""" transform a distance to an integer number of gridpoints """
@@ -375,28 +361,6 @@ def __setitem__(self, key, attr):
375361
z=self._handle_single_key(z),
376362
)
377363

378-
def __delattr__(self, name):
379-
attr = getattr(self, name)
380-
super().__delattr__(name)
381-
if not isinstance(attr, (Object, Source, Detector, Boundary)):
382-
return
383-
try:
384-
del self.objects[self.objects.index(attr)]
385-
except ValueError:
386-
pass
387-
try:
388-
del self.sources[self.sources.index(attr)]
389-
except ValueError:
390-
pass
391-
try:
392-
del self.detectors[self.detectors.index(attr)]
393-
except ValueError:
394-
pass
395-
try:
396-
del self.boundaries[self.boundaries.index(attr)]
397-
except ValueError:
398-
pass
399-
400364
def __repr__(self):
401365
return (
402366
f"{self.__class__.__name__}(shape=({self.Nx},{self.Ny},{self.Nz}), "
@@ -426,11 +390,3 @@ def __str__(self):
426390
for obj in self.objects:
427391
s += str(obj)
428392
return s
429-
430-
431-
## Imports (placed here to prevent circular imports)
432-
# relative
433-
from .objects import Object
434-
from .sources import Source
435-
from .detectors import Detector
436-
from .boundaries import Boundary

fdtd/objects.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
## Object
2424
class Object:
25-
""" An object to place in the grid [base class] """
25+
""" An object to place in the grid """
2626

2727
def __init__(self, permittivity: Tensorlike, name: str = None):
2828
""" Create an object """
@@ -63,17 +63,24 @@ def _register_grid(
6363
self._permittivity = self._permittivity[:, :, :, None]
6464
self.inverse_permittivity = (
6565
bd.ones((self.Nx, self.Ny, self.Nz, 3)) / self._permittivity
66-
- self.grid.inverse_permittivity[self.x, self.y, self.z]
6766
)
6867

6968
# set the permittivity values of the object at its border to be equal
7069
# to the grid permittivity. This way, the object is made symmetric.
7170
if self.Nx > 1:
72-
self.inverse_permittivity[-1, :, :, 0] = 0
71+
self.inverse_permittivity[-1, :, :, 0] = self.grid.inverse_permittivity[
72+
-1, self.y, self.z, 0
73+
]
7374
if self.Ny > 1:
74-
self.inverse_permittivity[:, -1, :, 1] = 0
75+
self.inverse_permittivity[:, -1, :, 1] = self.grid.inverse_permittivity[
76+
self.x, -1, self.z, 1
77+
]
7578
if self.Nz > 1:
76-
self.inverse_permittivity[:, :, -1, 2] = 0
79+
self.inverse_permittivity[:, :, -1, 2] = self.grid.inverse_permittivity[
80+
self.x, self.y, -1, 2
81+
]
82+
83+
self.grid.inverse_permittivity[self.x, self.y, self.z] = 0
7784

7885
def _handle_slice(self, s: ListOrSlice, max_index: int = None) -> slice:
7986
if isinstance(s, list):

fdtd/sources.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,9 @@
1717
from .grid import Grid
1818
from .backend import backend as bd
1919

20-
## Base source class:
21-
class Source:
22-
""" an FDTD Source [base class] """
23-
2420

2521
## LineSource class
26-
class LineSource(Source):
22+
class LineSource:
2723
""" A source along a line in the FDTD grid """
2824

2925
def __init__(

0 commit comments

Comments
 (0)