pbm2meep
is a program which takes a binary PBM image and writes a series of small blocks, useful for including directly in a meep
scheme file. In this way, it is possible to include arbitrary bitmapped geometries in meep
.
I wrote this small script to help simulate split ring resonator (SRR) arrays. Instead of using an ideal geometry, I used the outline from an SEM image of a single SRR. This outline was then saved as a PBM file using GIMP.
This sort of approach can be a bit CPU intensive to initialize the geometry, but once running there is no speed penalty.
#!/usr/bin/perl
# converts an pbm bitmap to a shape for meep!
# size of image in pixels
my $sx = 44;
my $sy = 46;
# open input file
defined($ARGV[0]) || die "Missing totally boring input filename.";
open(IN,"<$ARGV[0]") || die "Could not open totally boring input file.";
# load input data
foreach(<IN>){
chomp;
@tmp = split(/ /,$_); foreach(@tmp){
push(@data,$_);
}
}
# print out stuff for meep
for($y=0;$y<$sy;++$y){
for($x=0;$x<$sx;++$x){
if($data[$y*$sx+$x]==1){
$ly = ($y-$sy/2)/$sy;
$lx = ($x-$sx/2)/$sx;
print "(make block\n";
print "\t(center (* sx $lx) (* sy $ly) (/ srr-sz 2))\n";
print "\t(size (/ 1.25 res) (/ 1.25 res) srr-sz)\n";
print "\t(material myMaterial))\n";
}
}}