def notify(title, run_time=None):#{{{ """ Shows a bubble with notification that your results are about to be ready! Requires python-notify installed, otherwise just quits Note: you may also use similar call with libnotify-bin from your bash scripts: run_bash('notify-send -t 3000 -i "face-glasses" "MEEP simulation finished %s" "%s"' % (timestring, title)) """ if meep.my_rank() != 0: return try: if run_time: timestring = "in %d s" % int(run_time) else: timestring = "" import pynotify pynotify.init("image") n = pynotify.Notification("MEEP simulation finished %s" % (timestring), title, "face-glasses") n.show() except: pass
f.step(); timer = meep_utils.Timer(simtime=model.simtime); meep.quiet(True) # use custom progress messages while (f.time()/c < model.simtime): # timestepping cycle f.step() timer.print_progress(f.time()/c) for monitor in (monitor1_Ex, monitor1_Hy, monitor2_Ex, monitor2_Hy): monitor.record(field=f) for slice_ in slices: slice_.poll(f.time()/c) for slice_ in slices: slice_.finalize() meep_utils.notify(model.simulation_name, run_time=timer.get_time()) else: ## frequency-domain computation f.solve_cw(getattr(model, 'MaxTol',0.001), getattr(model, 'MaxIter', 5000), getattr(model, 'BiCGStab', 8)) for monitor in (monitor1_Ex, monitor1_Hy, monitor2_Ex, monitor2_Hy): monitor.record(field=f) for slice_ in slices: slice_.finalize() meep_utils.notify(model.simulation_name) ## Get the reflection and transmission of the structure if meep.my_rank() == 0: #t = monitor1_Ex.get_time() #Ex1, Hy1, Ex2, Hy2 = [mon.get_field_waveform() for mon in (monitor1_Ex, monitor1_Hy, monitor2_Ex, monitor2_Hy)] freq, s11, s12, columnheaderstring = meep_utils.get_s_parameters(monitor1_Ex, monitor1_Hy, monitor2_Ex, monitor2_Hy, frequency_domain=True if getattr(model, 'frequency', None) else False, frequency=getattr(model, 'frequency', None), ## procedure compatible with both FDTD and FDFD intf=getattr(model, 'interesting_frequencies', [0, model.src_freq+model.src_width]), ## clip the frequency range for plotting pad_zeros=1.0, ## speed-up FFT, and stabilize eff-param retrieval Kx=getattr(model, 'Kx', 0), Ky=getattr(model, 'Ky', 0), ## enable oblique incidence (works only if monitors in vacuum) eps1=getattr(model, 'mon1eps', 1), eps2=getattr(model, 'mon2eps', 1)) ## enable monitors inside dielectrics print "EVERYTHING OK" meep_utils.savetxt(fname=model.simulation_name+".dat", fmt="%.6e", X=zip(freq, np.abs(s11), np.angle(s11), np.abs(s12), np.angle(s12)), ## Save 5 columns: freq, amplitude/phase for reflection/transmission header=model.parameterstring+columnheaderstring) ## Export header
def run_bash(cmd, anyprocess=False): #{{{ if meep.my_rank() == 0 or anyprocess: #meep.master_printf("CMD: " + cmd+ "\n") p = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE) out = p.stdout.read().strip() return out
field.get_field(meep.Ey, monitor_point) + field.get_field(meep.Ez, monitor_point)) for slice_maker in slice_makers: slice_maker.poll(field.time() / c) for slice_maker in slice_makers: slice_maker.finalize() meep_utils.notify(model.simulation_name, run_time=timer.get_time()) else: ## frequency-domain computation field.step() field.solve_cw(sim_param['MaxTol'], sim_param['MaxIter'], sim_param['BiCGStab']) for slice_maker in slice_makers: slice_maker.finalize() meep_utils.notify(model.simulation_name) # Get the reflection and transmission of the structure if meep.my_rank() == 0 and not sim_param['frequency_domain']: ## Convert to polar notation and save the time-domain record x, y = np.array(x), np.array(y) meep_utils.savetxt(fname=model.simulation_name + "_timedomain.dat", X=zip(x, np.abs(y), meep_utils.get_phase(y)), fmt="%.6e", header=model.parameterstring + meep_utils.sim_param_string(sim_param) + "#x-column time [s]\n#column ampli\n#column phase\n") with open("./last_simulation_name.dat", "w") as outfile: outfile.write(model.simulation_name) meep.all_wait() # Wait until all file operations are finished
print sim_param['MaxIter'] f.solve_cw(sim_param['MaxTol'], sim_param['MaxIter'], sim_param['BiCGStab']) for monitor in (monitor1_Ex, monitor1_Hy, monitor2_Ex, monitor2_Hy): monitor.record(field=f) snapshot_maker.take_snapshot(0) meep_utils.notify(model.simulation_name) with open("./last_simulation_name.txt", "w") as outfile: outfile.write(model.simulation_name) meep.master_printf("=== Processing recorded fields ===\n") ## Get the reflection and transmission of the structure meep.master_printf(" getting s-params\n") import time if meep.my_rank() == 0: time1 = time.time() freq, s11, s12 = meep_utils.get_s_parameters( monitor1_Ex, monitor1_Hy, monitor2_Ex, monitor2_Hy, frequency_domain=sim_param['frequency_domain'], frequency=sim_param['frequency'], maxf=model.srcFreq + model.srcWidth, pad_zeros=1.0, Kx=model.Kx, Ky=model.Ky) #side_wavenumber=2*pi*modenumber*1/model.size_y) print "S-parameter retrieval (FFT etc.) took", time.time() - time1, "s" #meep.master_printf(" saving\n")
meep_utils.notify(model.simulation_name, run_time=timer.get_time()) else: f.step() print sim_param['MaxIter'] f.solve_cw(sim_param['MaxTol'], sim_param['MaxIter'], sim_param['BiCGStab']) for monitor in (monitor1_Ex, monitor1_Hy, monitor2_Ex, monitor2_Hy): monitor.record(field=f) snapshot_maker.take_snapshot(0) meep_utils.notify(model.simulation_name) with open("./last_simulation_name.txt", "w") as outfile: outfile.write(model.simulation_name) meep.master_printf("=== Processing recorded fields ===\n") ## Get the reflection and transmission of the structure meep.master_printf(" getting s-params\n") import time if meep.my_rank() == 0: time1 = time.time() freq, s11, s12 = meep_utils.get_s_parameters(monitor1_Ex, monitor1_Hy, monitor2_Ex, monitor2_Hy, frequency_domain=sim_param['frequency_domain'], frequency=sim_param['frequency'], maxf=model.srcFreq+model.srcWidth, pad_zeros=1.0, Kx=model.Kx, Ky=model.Ky) #side_wavenumber=2*pi*modenumber*1/model.size_y) print "S-parameter retrieval (FFT etc.) took", time.time()-time1, "s" #meep.master_printf(" saving\n") meep_utils.savetxt(freq=freq, s11=s11, s12=s12, model=model) import effparam #meep.master_printf(" done.\n")
dt = (field.time()/c) meep_utils.lorentzian_unstable_check_new(model, dt, quit_on_warning=False) timer = meep_utils.Timer(simtime=model.simtime); meep.quiet(True) # use custom progress messages monitor_point = meep.vec(-model.radius*.5, model.radius*.3, model.height*.3) x,y = [], [] while (field.time()/c < model.simtime): # timestepping cycle field.step() timer.print_progress(field.time()/c) if field.time()/c > 30/model.src_width: x.append(field.time()/c); y.append(field.get_field(meep.Ex, monitor_point)+field.get_field(meep.Ey, monitor_point)+field.get_field(meep.Ez, monitor_point)) for slice_maker in slice_makers: slice_maker.poll(field.time()/c) for slice_maker in slice_makers: slice_maker.finalize() meep_utils.notify(model.simulation_name, run_time=timer.get_time()) else: ## frequency-domain computation field.step() field.solve_cw(sim_param['MaxTol'], sim_param['MaxIter'], sim_param['BiCGStab']) for slice_maker in slice_makers: slice_maker.finalize() meep_utils.notify(model.simulation_name) # Get the reflection and transmission of the structure if meep.my_rank() == 0 and not sim_param['frequency_domain']: ## Convert to polar notation and save the time-domain record x, y = np.array(x), np.array(y) meep_utils.savetxt(fname=model.simulation_name+"_timedomain.dat", X=zip(x, np.abs(y), meep_utils.get_phase(y)), fmt="%.6e", header=model.parameterstring + meep_utils.sim_param_string(sim_param) + "#x-column time [s]\n#column ampli\n#column phase\n") with open("./last_simulation_name.dat", "w") as outfile: outfile.write(model.simulation_name) meep.all_wait() # Wait until all file operations are finished