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 make_fields(self): if self.gridSizeZ == None: self.meep_space = voltwo(self.gridSizeX,self.gridSizeY,self.res) else: self.meep_space = vol3d(self.gridSizeX,self.gridSizeY,self.gridSizeZ,self.res) material = epsilon(self.my_structure) set_EPS_Callback(material.__disown__()) if self.symmetry_direction == None: sym = identity() else: sym = mirror(self.symmetry_direction,self.meep_space)*self.symmetry_val self.meep_structure = structure(self.meep_space, EPS, self.boundary_conditions,sym) the_fields = fields(self.meep_structure) for direc in self.periodic_directions: the_fields.set_boundary(Low,direc,Periodic) the_fields.set_boundary(High,direc,Periodic) the_fields.use_bloch(self.bloch) if self.my_source is not None: self.my_source.add_to_fields(the_fields) for f in self.fluxes: f.add_to_fields(the_fields) self.meep_fields = the_fields return the_fields
self.material = MeepMaterial2DPolygons( landscape.simulation_volume, self.meepVol) except Exception, err: LOG.error( "MeepMaterial2DPolygons gives errors -> using MeepMaterial2DMatrix instead..." ) self.material = MeepMaterial2DMatrix( landscape.simulation_volume, self.meepVol) else: #dim == 3 self.material = MeepMaterial3DPolygons(landscape.simulation_volume, self.meepVol) Meep.set_EPS_Callback(self.material.__disown__()) LOG.debug("Meep node %i -Defining structure..." % (self.node_nr)) symmetry_object = Meep.identity() if (self.symmY): LOG.debug("Meep node %i -Using y symmetry!" % (self.node_nr)) symmetry_object = Meep.mirror(Meep.Y, self.meepVol) symmetry_object = symmetry_object * complex(1.0, 0.0) # When there is a certain PML direction, use that one. if isinstance(landscape.pml_direction, str): dirint = 'XYZ'.rfind(str.upper(landscape.pml_direction)) assert dirint <= 0, 'PML direction should be either X, Y or Z' if dirint == 0: direction = Meep.X if dirint == 1: direction = Meep.Y if dirint == 2: direction = Meep.Z pml = Meep.pml(landscape.pml_thickness, direction) else: pml = Meep.pml(landscape.pml_thickness)