def _init_structure(self, k=False): print('-' * 11) print('Initializing structure...') dims = self._infer_dimensions(k) if dims == 0 or dims == 1: gv = mp.vol1d(self.cell_size.z, self.resolution) elif dims == 2: self.dimensions = 2 gv = mp.vol2d(self.cell_size.x, self.cell_size.y, self.resolution) elif dims == 3: gv = mp.vol3d(self.cell_size.x, self.cell_size.y, self.cell_size.z, self.resolution) elif dims == mp.CYLINDRICAL: gv = mp.volcyl(self.cell_size.x, self.cell_size.z, self.resolution) self.dimensions = 2 self.is_cylindrical = True else: raise ValueError("Unsupported dimentionality: {}".format(dims)) gv.center_origin() sym = mp.symmetry() # Initialize swig objects for each symmetry and combine them into one for s in self.symmetries: if isinstance(s, Identity): s.swigobj = mp.identity() elif isinstance(s, Rotate2): s.swigobj = mp.rotate2(s.direction, gv) sym += s.swigobj * complex(s.phase.real, s.phase.imag) elif isinstance(s, Rotate4): s.swigobj = mp.rotate4(s.direction, gv) sym += s.swigobj * complex(s.phase.real, s.phase.imag) elif isinstance(s, Mirror): s.swigobj = mp.mirror(s.direction, gv) sym += s.swigobj * complex(s.phase.real, s.phase.imag) else: s.swigobj = mp.symmetry() br = _create_boundary_region_from_boundary_layers(self.boundary_layers, gv) if self.boundary_layers and type(self.boundary_layers[0]) is Absorber: absorbers = self.boundary_layers else: absorbers = None self.structure = mp.structure(gv, None, br, sym, self.num_chunks, self.courant, self.eps_averaging, self.subpixel_tol, self.subpixel_maxeval) if self.material_function: self.material_function.eps = False self.default_material = self.material_function elif self.epsilon_func: self.epsilon_func.eps = True self.default_material = self.epsilon_func elif self.epsilon_input_file: self.default_material = self.epsilon_input_file mp.set_materials_from_geometry(self.structure, self.geometry, self.eps_averaging, self.subpixel_tol, self.subpixel_maxeval, self.ensure_periodicity, False, self.default_material, absorbers, self.extra_materials)
def __createMeepComputationalVolume(self, volume): '''Convert the simulation volume (runtime.basic.__SimulationVolume__) into a Meep computational volume''' if not isinstance(volume, __SimulationVolume__): raise InvalidArgumentException("Invalid argument:: not of type runtime.basic.__SimulationVolume__") if isinstance(volume, SimulationVolume3D): return [ Meep.vol3d(volume.window_width, volume.window_height, volume.size_z, self.resolution), 3 ] if isinstance(volume, SimulationVolume2D): return [ Meep.vol2d(volume.window_width, volume.window_height, self.resolution), 2 ] if isinstance(volume, SimulationVolume1D): return [ Meep.vol1d(volume.window_width, self.resolution), 1 ]