Last active
November 8, 2018 16:43
-
-
Save ChristopherHogan/23d0741d75852c535db0c48a8ac19804 to your computer and use it in GitHub Desktop.
Scaling
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import math | |
import time | |
from multiprocessing import Pool | |
import boto3 | |
import meep as mp | |
from meep.materials import Al | |
resolution = 30 | |
def get_results(fragment_stats, total_pixels, total_time): | |
assert len(fragment_stats) == 1 | |
stats = fragment_stats[0] | |
results = "{},{},{},{},{},{},{},{:.4f}\n" | |
return results.format(stats.num_anisotropic_eps_pixels, | |
stats.num_anisotropic_mu_pixels, | |
stats.num_nonlinear_pixels, | |
stats.num_susceptibility_pixels, | |
stats.num_nonzero_conductivity_pixels, | |
stats.num_dft_pixels, | |
total_pixels, | |
total_time) | |
def absorber_boundaries(s): | |
d = 1.0 | |
abs_layers = [mp.Absorber(thickness=d)] | |
cell_size = mp.Vector3(s+d, s+d, s+d) | |
sources = [mp.Source(mp.GaussianSource(1, 0.2), | |
component=mp.Ex, | |
center=mp.Vector3())] | |
sim = mp.Simulation(resolution=resolution, | |
cell_size=cell_size, | |
k_point=mp.Vector3(), | |
sources=sources, | |
boundary_layers=abs_layers) | |
start = time.time() | |
sim.run(until_after_sources=100) | |
total_time = time.time() - start | |
return get_results(sim.fragment_stats, (s * resolution)**3, total_time) | |
def aniso_medium(s): | |
cell_size = mp.Vector3(s, s, s) | |
sources = [mp.Source(mp.GaussianSource(1, 0.2), | |
component=mp.Ex, | |
center=mp.Vector3())] | |
aniso_mat = mp.Medium(epsilon_diag=mp.Vector3(5.56984083, 9.44501035, 2.09631405), | |
epsilon_offdiag=mp.Vector3(1.20637481, 1.59461922, 1.41411461)) | |
sim = mp.Simulation(resolution=resolution, | |
cell_size=cell_size, | |
k_point=mp.Vector3(), | |
sources=sources, | |
default_material=aniso_mat) | |
start = time.time() | |
sim.run(until_after_sources=100) | |
total_time = time.time() - start | |
return get_results(sim.fragment_stats, (s * resolution)**3, total_time) | |
def conductive_medium(s): | |
cell_size = mp.Vector3(s, s, s) | |
sources = [mp.Source(mp.GaussianSource(1, 0.2), | |
component=mp.Ex, | |
center=mp.Vector3())] | |
eps_real = 6.5 | |
eps_imag = 0.2 | |
cond_mat = mp.Medium(epsilon=eps_real, D_conductivity=2*math.pi*eps_imag/eps_real) | |
sim = mp.Simulation(resolution=resolution, | |
cell_size=cell_size, | |
k_point=mp.Vector3(), | |
sources=sources, | |
default_material=cond_mat) | |
start = time.time() | |
sim.run(until_after_sources=100) | |
total_time = time.time() - start | |
return get_results(sim.fragment_stats, (s * resolution)**3, total_time) | |
def dft_flux(s): | |
cell_size = mp.Vector3(s, s, s) | |
fcen = 1.0 | |
df = 0.2 | |
sources = [mp.Source(mp.GaussianSource(fcen, df), | |
component=mp.Ex, | |
center=mp.Vector3())] | |
sim = mp.Simulation(resolution=resolution, | |
cell_size=cell_size, | |
k_point=mp.Vector3(), | |
sources=sources) | |
nfreq = 21 | |
sim.add_flux(fcen, df, nfreq, mp.FluxRegion(center=mp.Vector3(z=0.4*s), | |
size=mp.Vector3(s, s))) | |
sim.add_flux(fcen, df, nfreq, mp.FluxRegion(center=mp.Vector3(z=-0.4*s), | |
size=mp.Vector3(s, s), weight=-1.0)) | |
start = time.time() | |
sim.run(until_after_sources=100) | |
total_time = time.time() - start | |
return get_results(sim.fragment_stats, (s * resolution)**3, total_time) | |
def dispersive_medium(s): | |
cell_size = mp.Vector3(s, s, s) | |
sources = [mp.Source(mp.GaussianSource(1, 0.2), | |
component=mp.Ex, | |
center=mp.Vector3())] | |
sim = mp.Simulation(resolution=resolution, | |
cell_size=cell_size, | |
k_point=mp.Vector3(), | |
sources=sources, | |
default_material=Al) | |
start = time.time() | |
sim.run(until_after_sources=100) | |
total_time = time.time() - start | |
return get_results(sim.fragment_stats, (s * resolution)**3, total_time) | |
def empty(s): | |
cell_size = mp.Vector3(s, s, s) | |
sources = [mp.Source(mp.GaussianSource(1, 0.2), | |
component=mp.Ex, | |
center=mp.Vector3())] | |
sim = mp.Simulation(resolution=resolution, | |
cell_size=cell_size, | |
k_point=mp.Vector3(), | |
sources=sources) | |
start = time.time() | |
sim.run(until_after_sources=100) | |
total_time = time.time() - start | |
return get_results(sim.fragment_stats, (s * resolution)**3, total_time) | |
def empty_complex_fields(s): | |
cell_size = mp.Vector3(s, s, s) | |
sources = [mp.Source(mp.GaussianSource(1, 0.2), | |
component=mp.Ex, | |
center=mp.Vector3())] | |
sim = mp.Simulation(resolution=resolution, | |
cell_size=cell_size, | |
k_point=mp.Vector3(), | |
force_complex_fields=True, | |
sources=sources) | |
start = time.time() | |
sim.run(until_after_sources=100) | |
total_time = time.time() - start | |
return get_results(sim.fragment_stats, (s * resolution)**3, total_time) | |
def nonlinear_medium(s): | |
cell_size = mp.Vector3(s, s, s) | |
sources = [mp.Source(mp.GaussianSource(1, 0.2), | |
component=mp.Ex, | |
center=mp.Vector3())] | |
nonlinear_mat = mp.Medium(index=1, chi3=0.1) | |
sim = mp.Simulation(resolution=resolution, | |
cell_size=cell_size, | |
k_point=mp.Vector3(), | |
sources=sources, | |
default_material=nonlinear_mat) | |
start = time.time() | |
sim.run(until_after_sources=100) | |
total_time = time.time() - start | |
return get_results(sim.fragment_stats, (s * resolution)**3, total_time) | |
def pml_boundaries(s): | |
d = 1.0 | |
pml_layers = [mp.PML(thickness=d)] | |
cell_size = mp.Vector3(s+d, s+d, s+d) | |
sources = [mp.Source(mp.GaussianSource(1, 0.2), | |
component=mp.Ex, | |
center=mp.Vector3())] | |
sim = mp.Simulation(resolution=resolution, | |
cell_size=cell_size, | |
k_point=mp.Vector3(), | |
sources=sources, | |
boundary_layers=pml_layers) | |
start = time.time() | |
sim.run(until_after_sources=100) | |
total_time = time.time() - start | |
return get_results(sim.fragment_stats, (s * resolution)**3, total_time) | |
def write_csv(fn, res): | |
header = 'aniso_eps,aniso_mu,nonlinear,susceptibility,nonzer_cond,dft,total_pixels,total_time\n' | |
with open(fn, 'w') as f: | |
f.write(header) | |
for line in res: | |
f.write(line) | |
def put_s3_file(fn, bucket, destdir=''): | |
s3 = boto3.client('s3') | |
s3.upload_file(fn, bucket, destdir + fn) | |
print("Uploaded {} to S3".format(fn)) | |
if __name__ == '__main__': | |
bucket = 'hogan-fragment-stats' | |
pool = Pool(processes=4) | |
sizes = [1, 2, 3, 4] | |
fn = 'absorber_boundaries.csv' | |
res = pool.map(absorber_boundaries, sizes) | |
write_csv(fn, res) | |
put_s3_file(fn, bucket) | |
fn = 'aniso_medium.csv' | |
res = pool.map(aniso_medium, sizes) | |
write_csv(fn, res) | |
put_s3_file(fn, bucket) | |
fn = 'conductive_medium.csv' | |
res = pool.map(conductive_medium, sizes) | |
write_csv(fn, res) | |
put_s3_file(fn, bucket) | |
fn = 'dft_flux.csv' | |
res = pool.map(dft_flux, sizes) | |
write_csv(fn, res) | |
put_s3_file(fn, bucket) | |
fn = 'dispersive_medium.csv' | |
res = pool.map(dispersive_medium, sizes) | |
write_csv(fn, res) | |
put_s3_file(fn, bucket) | |
fn = 'empty.csv' | |
res = pool.map(empty, sizes) | |
write_csv(fn, res) | |
put_s3_file(fn, bucket) | |
# fn = 'empty_complex_fields.csv' | |
# res = pool.map(empty_complex_fields, sizes) | |
# write_csv(fn, res) | |
# put_s3_file(fn, bucket) | |
fn = 'nonlinear_medium.csv' | |
res = pool.map(nonlinear_medium, sizes) | |
write_csv(fn, res) | |
put_s3_file(fn, bucket) | |
fn = 'pml_boundaries.csv' | |
res = pool.map(pml_boundaries, sizes) | |
write_csv(fn, res) | |
put_s3_file(fn, bucket) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Two comments:
(1) The horizontal axis should be the number of pixels and the vertical axis the wall clock time of the simulation including axes labels. It seems the axes are reversed in these plots.
(2) As a reference, it would be helpful to add to each plot a straight line (linear dependence between simulation time and number of pixels). See the plot in the mode decomposition tutorial for an example.