Dear Meep users !

Research team at nanolab.phys.msu.ru (Moscow State University, Physics 
department) uses Meep for different simulations. As a side-effect of 
researches, we created python interface for libmeep (current version - 
0.20-3, also available for legacy 0.10-2) using SWIG. Currently, it is 
in the alpha state and not recommended for actual simulations, presented 
for testing and as a proof-of-concept. Hopefully, in the case of public 
interest in pythonic interface for libmeep, we will continue our efforts 
and offer Meep community a simpler way for simulations, that do not 
require C++ or Scheme experience.  The license is the same as for Meep 
itself, so it is GPL.

Unfortunately, even fresh Ubuntu release (8.10) and soon to be released 
Debian Lenny contain the legacy 0.10 version of Meep. Packages with 
current version 0.20-3 were backported for Ubuntu 8.10 and are also 
available at our site. Most probably, they can also be installed in 
Debian Lenny and Ubuntu 8.04. At least, backporting of Meep-0.20-3 for 
them is not difficult and may be performed on demand.

To use this packages, add following line to your /etc/apt/sources.list:
deb http://nanolab.phys.msu.ru/files/python-meep/intrepid-debs ./

then use 'apt-get update' and 'apt-get install meep' (or 'apt-get 
install libmeep2' for library only). MPI-version is also available 
(untested!).

Python interface is in 
http://nanolab.phys.msu.ru/files/python-meep/python-meep.tar.gz. This 
file also contains two simple tests, analogical to first two tests in 
Meep tutorial (simple waveguide and bent waveguide, 
http://ab-initio.mit.edu/wiki/index.php/Meep_Tutorial). Obtained 
simulation results are similar to these mentioned tutorials, but 
resulting png's are somewhat distorted (compared to those on Meep 
web-site).

Untar it, and look at test scripts for reference. C++ classes, methods, 
constants names, etc are mostly preserved. Following is the simplest 
waveguide simulation with comments (using "from meep import *" much 
shorter and cleaner script can be obtained, but AFAIK it is not 
generally recommended) :

#!/usr/bin/env python
import meep

class epsilon(meep.Callback):
    def __init__(self,inner_eps=1.0,outer_eps=1.0):
        meep.Callback.__init__(self)
        self.inner_eps=inner_eps
        self.outer_eps=outer_eps
    def test(self):
        print 'test message'
        print 'our material class can have own functions and variables !'
    def eps(self,vec):
        # this is our material distribution - for any Y in range 3.5-4.5 
=> width=1 , indefinitely long along the X
        if abs(vec.y()-4)<=0.5:
            return self.inner_eps
        else:
            return self.outer_eps

# create a volume, x=16 cells, y=8 cells, resolution = 10
vl=meep.vol2d(16,8,10)
#origin is in the corner, but we can change it by calling vl.shift_origin

#set our material function as callable from libmeep
eps=epsilon(12)
meep.setCallback(eps.__disown__())

# create a perfect matching layer, 1 cell deep
pml=meep.pml(1.0)

# meep.EPS is our pointer to our callback material function
# this hack allows only 1 callback function at any given time
 
st=meep.structure(vl,meep.EPS,pml)

# initialize simulation, populate initial values
fl=meep.fields(st)

# create a point source, take care about pml !
sr=meep.continuous_src_time(0.15)
r_pos=meep.vec(1.0,4.0)
fl.add_point_source(meep.Ey,sr,r_pos)
# of course,  we could also write fl.add_point_source(meep.Ey, 
meep.continuous_src_time(0.15), meep.vec(1.0,4.0) )

# let's see what we have
fl.output_hdf5(meep.Dielectric,vl.interior())

#let the simulation start
while fl.t<=1000:
    fl.step()

# what is the magnetic field distribution at the end?
fl.output_hdf5(meep.Hz,vl.surroundings())

# get_field can be used to determine value of specified fields at any point
print fl.get_field(meep.Hz,meep.vec(2,4.2))


I should note, that MPI is not tested and fl.get_eps() breaks for 
unknown reason. Of course, there could be other unnoticed bugs and 
shortcomings.
Please, do not hesitate to contact me for questions and suggestions. 
With technical questions about nanolab.phys.msu.ru contact Boris Tsema 
(tsema at nanolab.phys.msu.ru).

This work was at least partially supported by Russian Foundation for 
Basic Research, grant #08-02-90902mob_sng_st.


With best regards,
Nizamov Shawkat

_______________________________________________
meep-discuss mailing list
meep-discuss@ab-initio.mit.edu
http://ab-initio.mit.edu/cgi-bin/mailman/listinfo/meep-discuss

Reply via email to