update to use gridlock >=1.0
This commit is contained in:
		
							parent
							
								
									4c81f33d05
								
							
						
					
					
						commit
						26ae8578c9
					
				
							
								
								
									
										18
									
								
								fdtd.py
									
									
									
									
									
								
							
							
						
						
									
										18
									
								
								fdtd.py
									
									
									
									
									
								
							| @ -114,14 +114,17 @@ def main(): | |||||||
| #    edge_coords = [numpy.arange(-100.5, 101), numpy.arange(-100.5, 101), numpy.arange(-1, 1)] | #    edge_coords = [numpy.arange(-100.5, 101), numpy.arange(-100.5, 101), numpy.arange(-1, 1)] | ||||||
| 
 | 
 | ||||||
|     # #### Create the grid, mask, and draw the device #### |     # #### Create the grid, mask, and draw the device #### | ||||||
|     grid = gridlock.Grid(edge_coords, initial=n_air**2, num_grids=3) |     grid = gridlock.Grid(edge_coords) | ||||||
| #    grid.draw_slab(surface_normal=gridlock.Direction.z, |     epsilon = grid.allocate(n_air**2) | ||||||
|  | #    grid.draw_slab(epsilon, | ||||||
|  | #                   surface_normal=2, | ||||||
| #                   center=[0, 0, 0], | #                   center=[0, 0, 0], | ||||||
| #                   thickness=th, | #                   thickness=th, | ||||||
| #                   eps=n_slab**2) | #                   eps=n_slab**2) | ||||||
| #    mask = perturbed_l3(a, r) | #    mask = perturbed_l3(a, r) | ||||||
| # | # | ||||||
| #    grid.draw_polygons(surface_normal=gridlock.Direction.z, | #    grid.draw_polygons(epsilon, | ||||||
|  | #                       surface_normal=2, | ||||||
| #                       center=[0, 0, 0], | #                       center=[0, 0, 0], | ||||||
| #                       thickness=2 * th, | #                       thickness=2 * th, | ||||||
| #                       eps=n_air**2, | #                       eps=n_air**2, | ||||||
| @ -135,7 +138,7 @@ def main(): | |||||||
|             for a in 'xz' for p in 'np'] |             for a in 'xz' for p in 'np'] | ||||||
|     #bloch = [{'axis': a, 'real': 1, 'imag': 0} for a in 'x'] |     #bloch = [{'axis': a, 'real': 1, 'imag': 0} for a in 'x'] | ||||||
|     bloch = [] |     bloch = [] | ||||||
|     sim = Simulation(grid.grids, do_poynting=True, pmls=pmls, bloch_boundaries=bloch) |     sim = Simulation(epsilon, do_poynting=True, pmls=pmls, bloch_boundaries=bloch) | ||||||
| 
 | 
 | ||||||
|     # Source parameters and function |     # Source parameters and function | ||||||
|     w = 2 * numpy.pi * dx / wl |     w = 2 * numpy.pi * dx / wl | ||||||
| @ -188,7 +191,7 @@ def main(): | |||||||
| #            e = sim.update_G([e]) | #            e = sim.update_G([e]) | ||||||
|         e.wait() |         e.wait() | ||||||
| 
 | 
 | ||||||
|         S = sim.S.get().reshape(grid.grids.shape) * sim.dt * dx * dx *dx |         S = sim.S.get().reshape(epsilon.shape) * sim.dt * dx * dx *dx | ||||||
|         m = 30 |         m = 30 | ||||||
|         planes[t] = ( |         planes[t] = ( | ||||||
|             S[0][+pml_thickness+2, :, pml_thickness+3:-pml_thickness-3].sum(), |             S[0][+pml_thickness+2, :, pml_thickness+3:-pml_thickness-3].sum(), | ||||||
| @ -217,9 +220,9 @@ def main(): | |||||||
| #            ) | #            ) | ||||||
|         Ectr[t] = sim.E[ind].get() |         Ectr[t] = sim.E[ind].get() | ||||||
|         u[t] = pyopencl.array.sum(sim.E * sim.E * sim.eps + h_old * sim.H).get() * dx * dx * dx |         u[t] = pyopencl.array.sum(sim.E * sim.E * sim.eps + h_old * sim.H).get() * dx * dx * dx | ||||||
|         ui[t] = (sim.E * sim.E * sim.eps + h_old * sim.H).reshape(grid.grids.shape).get()[:, pml_thickness+m:-pml_thickness-m, :, |         ui[t] = (sim.E * sim.E * sim.eps + h_old * sim.H).reshape(epsilon.shape).get()[:, pml_thickness+m:-pml_thickness-m, :, | ||||||
|                                                                                             pml_thickness+m:-pml_thickness-m].sum() * dx * dx * dx |                                                                                             pml_thickness+m:-pml_thickness-m].sum() * dx * dx * dx | ||||||
| #        ui[t] = (sim.E * sim.E * sim.eps + h_old * sim.H).reshape(grid.grids.shape).get()[:, pml_thickness+m:-pml_thickness-m, | #        ui[t] = (sim.E * sim.E * sim.eps + h_old * sim.H).reshape(epsilon.shape).get()[:, pml_thickness+m:-pml_thickness-m, | ||||||
| #                                                                                            pml_thickness+m:-pml_thickness-m, :].sum() * dx * dx * dx | #                                                                                            pml_thickness+m:-pml_thickness-m, :].sum() * dx * dx * dx | ||||||
| 
 | 
 | ||||||
|         if t % 100 == 0: |         if t % 100 == 0: | ||||||
| @ -231,6 +234,7 @@ def main(): | |||||||
|             return meanas.fdmath.unvec(f, grid.shape) |             return meanas.fdmath.unvec(f, grid.shape) | ||||||
|         d = { |         d = { | ||||||
|             'grid': grid, |             'grid': grid, | ||||||
|  |             'epsilon': epsilon, | ||||||
|             'E': unvec(sim.E.get()), |             'E': unvec(sim.E.get()), | ||||||
|             'H': unvec(sim.H.get()), |             'H': unvec(sim.H.get()), | ||||||
|             'dt': sim.dt, |             'dt': sim.dt, | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user