← Back to team overview

python-meep team mailing list archive

Harminv helper function

 

Shawkat,

I have added better support for Harminv.

The code has been checked in on the Intec branch.
Attached is a sample.

Can you tell me if you have any remarks to this implementation?
I'd appreciate if you could reply in short notice, as people here in the
group are waiting to have this available.

thanks!

regards,
Emmanuel

'''
Example of using harminv to find the resonant modes in a ring

@author: Emmanuel.Lambert@xxxxxxxxxxxxxx
'''

from meep_mpi import *  # make it 'meep_mpi' for MPI-meep and 'meep' for non-MPI meep

from math import *
import numpy 
import matplotlib.pyplot
import sys
import glob

res = 10.0

width = 1.0
innerRadius = 1.0
outerRadius = innerRadius+width
pad = 4.0
dpml = 2.0
gridSizeX = 2 * (innerRadius + width + pad + dpml)
gridSizeY = gridSizeX

srcFreqCenter = 0.15 #gaussian source center frequency
srcPulseWidth = 0.10 #gaussian source pulse width
srcComp = Ez #gaussian source component

#this function plots the waveguide material as a function of a vector(X,Y) 
class epsilon(Callback):
    def __init__(self):
        Callback.__init__(self)
        master_printf("Callback function for epsilon activated.\n")

    def double_vec(self,vec):
        x = vec.x()
        y = vec.y()
        r = sqrt(x*x+y*y)
        if (r>innerRadius) and (r<=outerRadius):
	   return 11.56
        else:
	   return 1.0

def runSimul():
	master_printf("Starting the simulation script...\n")

	#create the computational grid 
	master_printf("Size of computational volume: %f x %f with resolution %f\n" %(gridSizeX,gridSizeY,res))
	ringWgVol = voltwo(gridSizeX,gridSizeY,res)
	ringWgVol.center_origin()

	#create the field : we create a structure with PML of thickness = 1.0 on all boundaries, in all directions, using the material function EPS
        material = epsilon()
        set_EPS_Callback(material.__disown__())        
        s = structure(ringWgVol, EPS, pml(dpml))      
        ringField = fields(s)      

        #define a gaussian line source 
        srcGaussian = gaussian_src_time(srcFreqCenter, srcPulseWidth )       
        ringField.add_point_source(srcComp, srcGaussian, vec(innerRadius + 0.1,0))
        master_printf("Field created...\n")
	filenameEps = "./harminv_Eps.h5" 
	filenameComp = "./harminv_Comp.h5" 

	#export the dielectric structure (so that we can visually verify the waveguide structure)
	ringDielectricFile =  prepareHDF5File(filenameEps)
	ringField.output_hdf5(Dielectric, ringWgVol.surroundings(), ringDielectricFile)

	#create the file for the field components 
	ringWgFileOutputComp = prepareHDF5File(filenameComp)

	master_printf("Calculating...")
	ringWgProbingPoint =  vec(innerRadius + 0.1,0)
	"""Now run the field pField until all sources have extinct. Then run for an extra 'pTimeAfterSources = 300' while
        collecting data for Harminv analysis at the probing point 'pProbingPoint = ringWgProbingPoint'. 
        After harminv analysis, run for 'pAdditionalTimeAfterHarminv' and send HDF5 output every 'pH5OutputIntervalSteps' (default 5)
        to the HDF5 file specified by 'pHDF5OutputFile'
        """
	results = runWithHarminv(ringField, ringWgVol, srcComp, ringWgProbingPoint, srcFreqCenter, srcPulseWidth, 100, pOutputHDF5OnlyAfterAnalysis = True, pAdditionalTimeAfterHarminv = (1.0 / srcFreqCenter), pTimeAfterSources = 300, pH5OutputIntervalSteps=6, pHDF5OutputFile = ringWgFileOutputComp)
	master_printf("Done..!")

	del_EPS_Callback()

	print results


master_printf("** Sample for using Harminv, version 21-01-2010 (equivalent of ring.ctl included with Meep) **\n")

master_printf("Running on %d processor(s)...\n",count_processors())

runSimul()







Follow ups

References