Consolidate variables in test case setups
This commit is contained in:
parent
f858cb8bbb
commit
950e70213a
@ -77,107 +77,84 @@ class BasicTests():
|
|||||||
class Basic2DNoDXOnlyVacuum(unittest.TestCase, BasicTests):
|
class Basic2DNoDXOnlyVacuum(unittest.TestCase, BasicTests):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
shape = [3, 5, 5, 1]
|
shape = [3, 5, 5, 1]
|
||||||
dt = 0.5
|
self.dt = 0.5
|
||||||
epsilon = numpy.ones(shape, dtype=float)
|
self.epsilon = numpy.ones(shape, dtype=float)
|
||||||
j_mag = 32
|
self.j_mag = 32
|
||||||
dxes = None
|
self.dxes = None
|
||||||
|
|
||||||
src_mask = numpy.zeros_like(epsilon, dtype=bool)
|
self.src_mask = numpy.zeros_like(self.epsilon, dtype=bool)
|
||||||
src_mask[1, 2, 2, 0] = True
|
self.src_mask[1, 2, 2, 0] = True
|
||||||
|
|
||||||
e = numpy.zeros_like(epsilon)
|
e = numpy.zeros_like(self.epsilon)
|
||||||
h = numpy.zeros_like(epsilon)
|
h = numpy.zeros_like(self.epsilon)
|
||||||
e[src_mask] = j_mag / epsilon[src_mask]
|
e[self.src_mask] = self.j_mag / self.epsilon[self.src_mask]
|
||||||
es = [e]
|
self.es = [e]
|
||||||
hs = [h]
|
self.hs = [h]
|
||||||
|
|
||||||
eh2h = fdtd.maxwell_h(dt=dt, dxes=dxes)
|
eh2h = fdtd.maxwell_h(dt=self.dt, dxes=self.dxes)
|
||||||
eh2e = fdtd.maxwell_e(dt=dt, dxes=dxes)
|
eh2e = fdtd.maxwell_e(dt=self.dt, dxes=self.dxes)
|
||||||
for _ in range(9):
|
for _ in range(9):
|
||||||
e = e.copy()
|
e = e.copy()
|
||||||
h = h.copy()
|
h = h.copy()
|
||||||
eh2h(e, h)
|
eh2h(e, h)
|
||||||
eh2e(e, h, epsilon)
|
eh2e(e, h, self.epsilon)
|
||||||
es.append(e)
|
self.es.append(e)
|
||||||
hs.append(h)
|
self.hs.append(h)
|
||||||
|
|
||||||
self.es = es
|
|
||||||
self.hs = hs
|
|
||||||
self.dt = dt
|
|
||||||
self.epsilon = epsilon
|
|
||||||
self.dxes = dxes
|
|
||||||
self.src_mask = src_mask
|
|
||||||
self.j_mag = j_mag
|
|
||||||
|
|
||||||
|
|
||||||
class Basic3DUniformDXOnlyVacuum(unittest.TestCase, BasicTests):
|
class Basic3DUniformDXOnlyVacuum(unittest.TestCase, BasicTests):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
shape = [3, 5, 5, 5]
|
shape = [3, 5, 5, 5]
|
||||||
dt = 0.33
|
self.dt = 0.33
|
||||||
epsilon = numpy.ones(shape, dtype=float)
|
self.epsilon = numpy.ones(shape, dtype=float)
|
||||||
j_mag = 32
|
self.j_mag = 32
|
||||||
dxes = tuple(tuple(numpy.ones(s) for s in shape[1:]) for _ in range(2))
|
self.dxes = tuple(tuple(numpy.ones(s) for s in shape[1:]) for _ in range(2))
|
||||||
|
|
||||||
src_mask = numpy.zeros_like(epsilon, dtype=bool)
|
self.src_mask = numpy.zeros_like(self.epsilon, dtype=bool)
|
||||||
src_mask[1, 2, 2, 0] = True
|
self.src_mask[1, 2, 2, 0] = True
|
||||||
|
|
||||||
e = numpy.zeros_like(epsilon)
|
e = numpy.zeros_like(self.epsilon)
|
||||||
h = numpy.zeros_like(epsilon)
|
h = numpy.zeros_like(self.epsilon)
|
||||||
e[src_mask] = j_mag / epsilon[src_mask]
|
e[self.src_mask] = self.j_mag / self.epsilon[self.src_mask]
|
||||||
es = [e]
|
self.es = [e]
|
||||||
hs = [h]
|
self.hs = [h]
|
||||||
|
|
||||||
eh2h = fdtd.maxwell_h(dt=dt, dxes=dxes)
|
eh2h = fdtd.maxwell_h(dt=self.dt, dxes=self.dxes)
|
||||||
eh2e = fdtd.maxwell_e(dt=dt, dxes=dxes)
|
eh2e = fdtd.maxwell_e(dt=self.dt, dxes=self.dxes)
|
||||||
for _ in range(9):
|
for _ in range(9):
|
||||||
e = e.copy()
|
e = e.copy()
|
||||||
h = h.copy()
|
h = h.copy()
|
||||||
eh2h(e, h)
|
eh2h(e, h)
|
||||||
eh2e(e, h, epsilon)
|
eh2e(e, h, self.epsilon)
|
||||||
es.append(e)
|
self.es.append(e)
|
||||||
hs.append(h)
|
self.hs.append(h)
|
||||||
|
|
||||||
self.es = es
|
|
||||||
self.hs = hs
|
|
||||||
self.dt = dt
|
|
||||||
self.epsilon = epsilon
|
|
||||||
self.dxes = dxes
|
|
||||||
self.src_mask = src_mask
|
|
||||||
self.j_mag = j_mag
|
|
||||||
|
|
||||||
|
|
||||||
class Basic3DUniformDX(unittest.TestCase, BasicTests):
|
class Basic3DUniformDX(unittest.TestCase, BasicTests):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
shape = [3, 5, 5, 5]
|
shape = [3, 5, 5, 5]
|
||||||
dt = 0.33
|
self.dt = 0.33
|
||||||
epsilon = numpy.full(shape, 2, dtype=float)
|
self.epsilon = numpy.full(shape, 2, dtype=float)
|
||||||
j_mag = 32
|
self.j_mag = 32
|
||||||
dxes = tuple(tuple(numpy.ones(s) for s in shape[1:]) for _ in range(2))
|
self.dxes = tuple(tuple(numpy.ones(s) for s in shape[1:]) for _ in range(2))
|
||||||
|
|
||||||
src_mask = numpy.zeros_like(epsilon, dtype=bool)
|
self.src_mask = numpy.zeros_like(self.epsilon, dtype=bool)
|
||||||
src_mask[1, 2, 2, 0] = True
|
self.src_mask[1, 2, 2, 0] = True
|
||||||
|
|
||||||
e = numpy.zeros_like(epsilon)
|
e = numpy.zeros_like(self.epsilon)
|
||||||
h = numpy.zeros_like(epsilon)
|
h = numpy.zeros_like(self.epsilon)
|
||||||
e[src_mask] = j_mag / epsilon[src_mask]
|
e[self.src_mask] = self.j_mag / self.epsilon[self.src_mask]
|
||||||
es = [e]
|
self.es = [e]
|
||||||
hs = [h]
|
self.hs = [h]
|
||||||
|
|
||||||
eh2h = fdtd.maxwell_h(dt=dt, dxes=dxes)
|
eh2h = fdtd.maxwell_h(dt=self.dt, dxes=self.dxes)
|
||||||
eh2e = fdtd.maxwell_e(dt=dt, dxes=dxes)
|
eh2e = fdtd.maxwell_e(dt=self.dt, dxes=self.dxes)
|
||||||
for _ in range(9):
|
for _ in range(9):
|
||||||
e = e.copy()
|
e = e.copy()
|
||||||
h = h.copy()
|
h = h.copy()
|
||||||
eh2h(e, h)
|
eh2h(e, h)
|
||||||
eh2e(e, h, epsilon)
|
eh2e(e, h, self.epsilon)
|
||||||
es.append(e)
|
self.es.append(e)
|
||||||
hs.append(h)
|
self.hs.append(h)
|
||||||
|
|
||||||
self.es = es
|
|
||||||
self.hs = hs
|
|
||||||
self.dt = dt
|
|
||||||
self.epsilon = epsilon
|
|
||||||
self.dxes = dxes
|
|
||||||
self.src_mask = src_mask
|
|
||||||
self.j_mag = j_mag
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user