def test_waveforms_all_bends(backends): fdtd.set_backend(backends) times = np.arange(0,1000) / 1000.0 waveform_array = normalized_gaussian_pulse(times, 0.01,center =0.5) assert np.max(waveform_array) == pytest.approx(1.0, rel=0.1) assert waveform_array[0] == pytest.approx(0.0, rel=1e-6) assert waveform_array[-1] == pytest.approx(0.0, rel=1e-6)
def test_DC_absorbing_current_detector_all_bends(grid, pml, backends): fdtd.set_backend(backends) # we maybe want our test cases to be orthogonal: # The test case with the patch antenna also relies on other modules like # the electric field detector & PEC, seems like a smaller test could be in order # However, because of the overlapping object issue, seems like this'll be harder. # This doesn't seem to work properly, not sure why- # see issue #11, will look into it. conductivity = 1e9 # absorb = bd.ones((grid.Nx,grid.Ny,grid.Nz)) # absorb[x_,y_,z_] = 0 grid[x_ - 1 : x_ + 1, y_ - 1 : y_ + 1, z_ - 1 : z_ + 1] = fdtd.AbsorbingObject( permittivity=1.0, conductivity=conductivity ) # AbsorbingObject doesn't create a magnetic field? # How could that ever cause a current density? # grid[x_,y_,z_] = fdtd.PointSource(period=500) cd = fdtd.CurrentDetector(name="Dave") grid[x_, y_, z_] = cd grid[x_:x_, y_:y_, z_:z_] = fdtd.BlockDetector() # FIXME: AbsorbingObject must be added last for some reason, n = 1000 # grid.run(total_time=n) for _ in range(n): grid.update_E() grid.E[x_, y_, z_, Z] = normalized_gaussian_pulse( grid.time_passed, (n / 10.0) * grid.time_step, center=(n / 2) * grid.time_step, ) grid.update_H() grid.time_steps_passed += 1 # current_time_history = bd.array(grid.detectors[0].I).reshape(n) electric_field_time_history = bd.array(grid.detectors[1].E).reshape(n, 3)[:, Z] # print(grid.E[x_,y_,z_,Z]) # # print(current_time_history) voltage = electric_field_time_history * grid.grid_spacing resistivity = 1.0 / conductivity resistance = (resistivity * grid.grid_spacing) / ( grid.grid_spacing * grid.grid_spacing ) expected_current = voltage / resistance
def test_antenna_impedance(): fdtd.set_backend("torch.cuda.float32") # a very slow test distance_from_edge = bd.array([0.0,0.25,0.35,0.50,0.67,1.00]) samaras_FDTD_R = bd.array([169,136,106,72,32,0]) grid, source, simulation_steps = create_patch_antenna(0) for idx, d in enumerate(distance_from_edge): grid, source, _ = create_patch_antenna(d) grid.run(simulation_steps) fr = FrequencyRoutines(grid, source) fr.impedance()
A simple example on how to use the FDTD Library """ ## Imports import matplotlib.pyplot as plt import fdtd import fdtd.backend as bd ## Set Backend fdtd.set_backend("numpy") ## Constants WAVELENGTH = 1550e-9 SPEED_LIGHT: float = 299_792_458.0 # [m/s] speed of light ## Simulation # create FDTD Grid grid = fdtd.Grid( (2.5e-5, 1.5e-5, 1), grid_spacing=0.1 * WAVELENGTH, permittivity=1.0, permeability=1.0,
def test_set_backend(): fdtd.set_backend("torch") assert isinstance(fdtd.backend, TorchBackend) fdtd.set_backend("numpy") assert isinstance(fdtd.backend, NumpyBackend)
A simple example on how to use the FDTD Library """ ## Imports import matplotlib.pyplot as plt from line_profiler import LineProfiler import fdtd import fdtd.backend as bd ## Set Backend fdtd.set_backend("torch.cuda") ## Constants WAVELENGTH = 1550e-9 SPEED_LIGHT: float = 299_792_458.0 # [m/s] speed of light ## Simulation # create FDTD Grid grid = fdtd.Grid( (2.5e-5, 1.5e-5, 1), grid_spacing=0.1 * WAVELENGTH, permittivity=1.0, permeability=1.0, )