Esempio n. 1
0
    def output_component(self, c, h5file=None):
        if self.fields is None:
            raise RuntimeError("Fields must be initialized before calling output_component")

        vol = self.fields.total_volume() if self.output_volume is None else self.output_volume
        h5 = self.output_append_h5 if h5file is None else h5file
        append = h5file is None and self.output_append_h5 is not None

        self.fields.output_hdf5(c, vol, h5, append, self.output_single_precision, self.get_filename_prefix())

        if h5file is None:
            nm = self.fields.h5file_name(mp.component_name(c), self.get_filename_prefix(), True)
            if c == mp.Dielectric:
                self.last_eps_filename = nm
            self.output_h5_hook(nm)
Esempio n. 2
0
def plot_dft_fields(sim, field_cells=[], field_funcs=None,
                         ff_arrays=None, options=None, nf=0):

    options       = options if options else def_field_options
    cmap          = options['cmap']
    edgecolors    = options['line_color']
    linewidth     = options['line_width']
    alpha         = options['alpha']
    fontsize      = options['fontsize']
    plot_method   = options['plot_method']
    num_contours  = options['num_contours']
    shading       = 'gouraud' if linewidth==0.0 else 'none'
    interpolation = 'gaussian' if linewidth==0.0 else 'none'

    for ncell, cell in enumerate(field_cells):
        (x,y,z,w,cEH,EH)=unpack_dft_cell(sim,cell,nf=nf)
        X, Y = np.meshgrid(x, y)
        if ff_arrays is None:
            plt.figure()
            plt.suptitle('DFT cell {}'.format(ncell+1))

        if field_funcs==None:
            ops=['Re', 'Im', 'abs']
            field_funcs=[texify(op+'('+mp.component_name(c)+')') for c in cEH for op in ops]
            rows,cols=len(cEH),len(ops)
        else:
            rows,cols=1,len(field_funcs)

        def op(F,index):
            return np.real(F) if op=='Re' else np.imag(F) if op=='Im' else np.abs(F)

        for row in range(rows):
            for col in range(cols):
                nplot = row*cols + col
                data = ff_arrays[nplot] if ff_arrays else op(EH[row],ops[col])
                plt.subplot(rows, cols, nplot+1)
                ax=plt.gca()
                ax.set_title(field_funcs[nplot])
                ax.set_xlabel(r'$x$', fontsize=fontsize, labelpad=0.5*fontsize)
                ax.set_ylabel(r'$y$', fontsize=fontsize, labelpad=fontsize, rotation=0)
                ax.tick_params(axis='both', labelsize=0.75*fontsize)
                ax.set_aspect('equal')
                plt.tight_layout()
                if plot_method=='imshow':
                    img = plt.imshow(np.transpose(data), extent=(min(x), max(x), min(y), max(y)),
                                     cmap=cmap, interpolation=interpolation, alpha=alpha)
                elif plot_method=='pcolormesh':
                    img = plt.pcolormesh(x,y,np.transpose(data), cmap=cmap, shading=shading,
                                         edgecolors=edgecolors, linewidth=linewidth, alpha=alpha)
                else:
                    img = ax.contourf(X,Y,np.transpose(data),num_contours, cmap=cmap,alpha=alpha)
                #cb=plt.colorbar(img,shrink=options['colorbar_shrink'], pad=options['colorbar_pad'])
                cb=happy_cb(img,ax)
                #cb.ax.set_xlabel(ff,fontsize=1.5*fontsize,rotation=0,labelpad=0.5*fontsize)
                cb.locator = ticker.MaxNLocator(nbins=5)
                cb.update_ticks()

    plt.tight_layout()
    plt.show(False)
    plt.draw()
    return 0
Esempio n. 3
0
def fc_name(c,which):
    name=mp.component_name(c)
    return name if which=='scattered' else str(name[0].upper())+str(name[1])
Esempio n. 4
0
def plot_dft_fields(sim,
                    field_cells=[],
                    field_funcs=None,
                    ff_arrays=None,
                    options=None,
                    nf=0):

    options = options if options else def_field_options
    cmap = options['cmap']
    edgecolors = options['line_color']
    linewidth = options['line_width']
    alpha = options['alpha']
    fontsize = options['fontsize']
    plot_method = options['plot_method']
    num_contours = options['num_contours']
    shading = 'gouraud' if linewidth == 0.0 else 'none'
    interpolation = 'gaussian' if linewidth == 0.0 else 'none'

    for ncell, cell in enumerate(field_cells):
        (x, y, z, w, cEH, EH) = unpack_dft_cell(sim, cell, nf=nf)
        X, Y = np.meshgrid(x, y)
        if ff_arrays is None:
            plt.figure()
            plt.suptitle('DFT cell {}'.format(ncell + 1))

        if field_funcs == None:
            ops = ['Re', 'Im', 'abs']
            field_funcs = [
                texify(op + '(' + mp.component_name(c) + ')') for c in cEH
                for op in ops
            ]
            rows, cols = len(cEH), len(ops)
        else:
            rows, cols = 1, len(field_funcs)

        def op(F, index):
            return np.real(F) if op == 'Re' else np.imag(
                F) if op == 'Im' else np.abs(F)

        for row in range(rows):
            for col in range(cols):
                nplot = row * cols + col
                data = ff_arrays[nplot] if ff_arrays else op(EH[row], ops[col])
                plt.subplot(rows, cols, nplot + 1)
                ax = plt.gca()
                ax.set_title(field_funcs[nplot])
                ax.set_xlabel(r'$x$',
                              fontsize=fontsize,
                              labelpad=0.5 * fontsize)
                ax.set_ylabel(r'$y$',
                              fontsize=fontsize,
                              labelpad=fontsize,
                              rotation=0)
                ax.tick_params(axis='both', labelsize=0.75 * fontsize)
                ax.set_aspect('equal')
                plt.tight_layout()
                if plot_method == 'imshow':
                    img = plt.imshow(np.transpose(data),
                                     extent=(min(x), max(x), min(y), max(y)),
                                     cmap=cmap,
                                     interpolation=interpolation,
                                     alpha=alpha)
                elif plot_method == 'pcolormesh':
                    img = plt.pcolormesh(x,
                                         y,
                                         np.transpose(data),
                                         cmap=cmap,
                                         shading=shading,
                                         edgecolors=edgecolors,
                                         linewidth=linewidth,
                                         alpha=alpha)
                else:
                    img = ax.contourf(X,
                                      Y,
                                      np.transpose(data),
                                      num_contours,
                                      cmap=cmap,
                                      alpha=alpha)
                #cb=plt.colorbar(img,shrink=options['colorbar_shrink'], pad=options['colorbar_pad'])
                cb = happy_cb(img, ax)
                #cb.ax.set_xlabel(ff,fontsize=1.5*fontsize,rotation=0,labelpad=0.5*fontsize)
                cb.locator = ticker.MaxNLocator(nbins=5)
                cb.update_ticks()

    plt.tight_layout()
    plt.show(False)
    plt.draw()
    return 0
Esempio n. 5
0
def fc_name(c, which):
    name = mp.component_name(c)
    return name if which == 'scattered' else str(name[0].upper()) + str(
        name[1])