Example #1
0
from scipy.constants import c, epsilon_0, mu_0

import meep_utils, meep_materials, metamaterial_models
from meep_utils import in_sphere, in_xcyl, in_ycyl, in_zcyl, in_xslab, in_yslab, in_zslab, in_ellipsoid
import meep_mpi as meep
#import meep

# Model selection
model_param = meep_utils.process_param(sys.argv[1:])
model = metamaterial_models.models[model_param.get('model', 'default')](**model_param)

## Initialize volume, structure and the fields according to the model
vol = meep.vol3d(model.size_x, model.size_y, model.size_z, 1./model.resolution)
vol.center_origin()
s = meep_utils.init_structure(model=model, volume=vol, pml_axes=meep.Z)
f = meep.fields(s)
# Define the Bloch-periodic boundaries (any transversal component of k-vector is allowed)
f.use_bloch(meep.X, getattr(model, 'Kx', 0) / (-2*np.pi)) 
f.use_bloch(meep.Y, getattr(model, 'Ky', 0) / (-2*np.pi))

# Add the field source (see meep_utils for an example of how an arbitrary source waveform is defined)
if not getattr(model, 'frequency', None):       ## (temporal source shape)
    #src_time_type = meep.band_src_time(model.src_freq/c, model.src_width/c, model.simtime*c/1.1)
    src_time_type = meep.gaussian_src_time(model.src_freq/c, model.src_width/c)
else:
    src_time_type = meep.continuous_src_time(getattr(model, 'frequency', None)/c)
srcvolume = meep.volume(                    ## (spatial source shape)
        meep.vec(-model.size_x/2, -model.size_y/2, -model.size_z/2+model.pml_thickness),
        meep.vec( model.size_x/2,  model.size_y/2, -model.size_z/2+model.pml_thickness))

#f.add_volume_source(meep.Ex, src_time_type, srcvolume)
Example #2
0
    def run(self):

        ## TEMPORARY SETTINGS

        wg_bottom = 0.7
        wg_top = 0.7 + 0.22
        wg_center = (wg_bottom + wg_top) / 2.

        #top = 0.7 + 0.38

        ## preparing

        po = self.property_object
        self.engine.initialise_engine(self.landscape)
        fields = meep.fields(self.engine.structure)
        self.save_engine_dielectricum_to_file(po.eps_filename)

        ## Sources

        print 'Center wavelength:', po.wavelength
        print 'Bandwidth:', po.pulse_width
        center_freq = 1.0 / (float(po.wavelength))
        pulse_width_freq = (float(po.pulse_width)) / (
            float(po.wavelength)) * center_freq
        print 'Center frequency:', center_freq
        print 'Bandwidth:', pulse_width_freq

        if (po.pulsed_source):
            src = meep.gaussian_src_time(center_freq, pulse_width_freq)
        else:
            src = meep.continuous_src_time(center_freq)

        source_port_position = po.input_port.transform_copy(
            Translation(translation=(po.source_input_port_offset, 0))).position
        print 'wg_center_old:', wg_center
        wg_center = (po.input_port.wg_definition.process.wg_upper_z_coord +
                     po.input_port.wg_definition.process.wg_lower_z_coord) / 2.
        print 'wg_center_new:', wg_center
        c = Coord3(source_port_position[0], source_port_position[1], wg_center)
        print 'coord:', c
        source_position_vec = self.make_meep_vec(c)

        fields.add_point_source(meep.Ey, src, source_position_vec)

        ## 2D Cross section volumes

        for oc in po.output_cuts:
            fn = '%s_eps.h5' % oc.filename
            vol = oc.get_output_volume(self.engine.meepVol)
            f_eps = meep.prepareHDF5File(fn)
            fields.output_hdf5(meep.Dielectric, vol, f_eps)
            del f_eps
            system('h5topng %s' % fn)

        ### Fluxplanes

        self.fluxes = []
        for p in po.output_ports:
            pp = p.position
            port_width = p.wg_definition.wg_width
            wg_bottom = p.wg_definition.process.wg_lower_z_coord
            wg_top = p.wg_definition.process.wg_upper_z_coord

            ## Be aware: this is only for ports along y-axis!!
            vec_near = self.make_meep_vec(
                Coord3(pp[0], pp[1] - port_width / 2.0, wg_bottom))
            vec_far = self.make_meep_vec(
                Coord3(pp[0], pp[1] + port_width / 2.0, wg_top))

            fluxplane = meep.volume(vec_near, vec_far)
            fx = fields.add_dft_flux_plane(
                fluxplane, center_freq - (pulse_width_freq / 4.0),
                center_freq + (pulse_width_freq / 4.0), po.dft_terms)
            self.fluxes.append(fx)

        ## Reverse one of the fluxes if necessary

        if po.load_reversed_flux_from_file_ID > -1:
            self.fluxes[po.load_reversed_flux_from_file_ID].load_hdf5(
                fields, po.load_reversed_flux_from_file_filename)

        if (po.pulsed_source):
            stop = po.stop_time_multiplier * fields.last_source_time()
        else:
            stop = po.stop_time

        print 'Simulation will run for', stop, 'time units'

        output_files = []
        for oc in po.output_cuts:
            fn = '%s.h5' % oc.filename
            oc_file = meep.prepareHDF5File(fn)
            output_files.append(oc_file)

        i = 0
        n_o_output = 0
        while (fields.time() < stop):
            if (i > po.output_steps):
                j = 0
                for oc in po.output_cuts:
                    vol = oc.get_output_volume(self.engine.meepVol)
                    fields.output_hdf5(meep.Ey, vol, output_files[j], 1)
                    j += 1
                n_o_output += 1
                i = 0
            fields.step()
            i += 1

        print n_o_output, 'images outputted'
        print 'Outputting field images..'
        del output_files[:]
        for oc in po.output_cuts:
            fn = '%s.h5' % oc.filename
            fn_eps = '%s_eps.h5' % oc.filename
            st = 'h5topng -t 0:%d -R -Zc dkbluered -a yarg -A %s %s' % (
                n_o_output - 1, fn_eps, fn)
            print st
            system(st)
        print 'Outputting done!'

        #print 'obtaining fluxes:'
        self.flux_data = []
        for i in range(len(po.output_ports)):
            fd = meep.getFluxData(self.fluxes[i])
            self.flux_data.append(fd)
            #print fd

        ## Save flux data if necesarry

        if po.save_reversed_flux_to_file_ID > -1:
            fx = self.fluxes[po.save_reversed_flux_to_file_ID]
            fx.scale_dfts(-1)
            fx.save_hdf5(fields, po.save_reversed_flux_to_file_filename)

        return
Example #3
0
from scipy.constants import c, epsilon_0, mu_0

import meep_utils, meep_materials, metamaterial_models
from meep_utils import in_sphere, in_xcyl, in_ycyl, in_zcyl, in_xslab, in_yslab, in_zslab, in_ellipsoid
import meep_mpi as meep
#import meep

# Model selection
model_param = meep_utils.process_param(sys.argv[1:])
model = metamaterial_models.models[model_param.get('model', 'default')](**model_param)

## Initialize volume, structure and the fields according to the model
vol = meep.vol3d(model.size_x, model.size_y, model.size_z, 1./model.resolution)
vol.center_origin()
s = meep_utils.init_structure(model=model, volume=vol, pml_axes=meep.Z)
f = meep.fields(s)
# Define the Bloch-periodic boundaries (any transversal component of k-vector is allowed)
f.use_bloch(meep.X, getattr(model, 'Kx', 0) / (-2*np.pi)) 
f.use_bloch(meep.Y, getattr(model, 'Ky', 0) / (-2*np.pi))

# Add the field source (see meep_utils for an example of how an arbitrary source waveform is defined)
if not getattr(model, 'frequency', None):       ## (temporal source shape)
    #src_time_type = meep.band_src_time(model.src_freq/c, model.src_width/c, model.simtime*c/1.1)
    src_time_type = meep.gaussian_src_time(model.src_freq/c, model.src_width/c)
else:
    src_time_type = meep.continuous_src_time(getattr(model, 'frequency', None)/c)
srcvolume = meep.volume(                    ## (spatial source shape)
        meep.vec(-model.size_x/2, -model.size_y/2, -model.size_z/2+model.pml_thickness),
        meep.vec( model.size_x/2,  model.size_y/2, -model.size_z/2+model.pml_thickness))

#f.add_volume_source(meep.Ex, src_time_type, srcvolume)
Example #4
0
        eps_matrix = numpy.absolute(
            eps_matrix / numpy.amax(eps_matrix))**2 * modulation
        print(eps_matrix[10, 10])

        # grating = numpy.abs(eps_matrix) ** 2
        # plt.figure(1)
        # plt.imshow(_eps_matrix, cmap='hot', extent=[0, gridSizeX, 0, gridSizeY])
        # plt.colorbar()
        # plt.show()

        meep.master_printf("Setting the material matrix...\n")
        self.set_matrix_2D(eps_matrix, vol)
        # self.setMatrix(grating)
        self.stored_eps_matrix = eps_matrix  # to prevent the garbage collector from cleaning up the matrix...
        meep.master_printf("MeepMaterial object initialized.\n")


meep.set_EPS_Callback(epsilon().__disown__())
struct = meep.structure(vol, EPS, no_pml())

fld = meep.fields(struct)
fld.add_volume_source(Ex, gaussian_src_time(freq_read / c, 1.5e9 / c), vol)

while fld.time() / c < 30e-15:
    fld.step()

meep.print_f.get_field(Ex, meep.vec(0.5e-6, 0.5e-6, 3e-6))

meep.del_EPS_Callback()