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 with open("./last_simulation_name.dat", "w") as outfile: outfile.write(model.simulation_name) meep.all_wait() # Wait until all file operations are finished
timer.print_progress(f.time() / c) for monitor in (monitor1_Ex, ): monitor.record(field=f) 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, ): monitor.record(field=f) meep_utils.notify(model.simulation_name) ## Get the reflection and transmission of the structure if meep.my_rank() == 0: # TODO update to new saving syntax, and test #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 headerstring = "#x-column Frequency [Hz]\n#Column Ex real\n#Column Ex imag\n" t, E = monitor1_Ex.get_waveforms() if not os.path.exists("cdh"): os.mkdir("cdh") meep_utils.savetxt(fname=os.path.join('cdh', model.simulation_name + ".dat"), fmt="%.6e", X=zip(t, E.real, E.imag), header=model.parameterstring + headerstring) with open("./last_simulation_name.dat", "w") as outfile: outfile.write(model.simulation_name) meep.all_wait() # Wait until all file operations are finished
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") print "All processes finishing", meep.my_rank() meep.all_wait() # Wait until all file operations are finished
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
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") print "All processes finishing", meep.my_rank() meep.all_wait() # Wait until all file operations are finished
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
else: ## frequency-domain computation f.step() 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) 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: freq, s11, s12, headerstring = meep_utils.get_s_parameters(monitor1_Ex, monitor1_Hy, monitor2_Ex, monitor2_Hy, frequency_domain=sim_param['frequency_domain'], frequency=sim_param['frequency'], intf=getattr(model, 'interesting_frequencies', [0, model.src_freq+model.src_width]), pad_zeros=1.0, Kx=sim_param.get('Ky', 0), Ky=sim_param.get('Ky', 0)) print 'np.abs(s11)', np.abs(s11) if not os.path.isfile('ref.dat'): ## no reference yet, let us save one print "Saving the fields as a reference" 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)), header=model.parameterstring + meep_utils.sim_param_string(sim_param) + headerstring) else: ## save fields normalized to the reference print "Saving fields normalized to the reference (loaded from ref.dat)" (fref, s11refabs, s11refangle, s12refabs, s12refangle) = np.loadtxt('ref.dat', usecols=list(range(5)), unpack=True) meep_utils.savetxt(fname=model.simulation_name+"_NORMALIZED.dat", fmt="%.6e", X=zip(freq, np.abs(s11)/s11refabs, np.angle(s11)-s11refangle, np.abs(s12)/s12refabs, np.angle(s12)-s12refangle), header=model.parameterstring + meep_utils.sim_param_string(sim_param) + headerstring) with open("./last_simulation_name.dat", "w") as outfile: outfile.write(model.simulation_name) meep.all_wait() # Wait until all file operations are finished
f.step() dt = (f.time()/c) meep_utils.lorentzian_unstable_check_new(model, dt) 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,): monitor.record(field=f) #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,): monitor.record(field=f) meep_utils.notify(model.simulation_name) ## Get the reflection and transmission of the structure if meep.my_rank() == 0: # TODO update to new saving syntax, and test #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 headerstring = "#x-column Frequency [Hz]\n#Column Ex real\n#Column Ex imag\n" t, E = monitor1_Ex.get_waveforms() if not os.path.exists("cdh"): os.mkdir("cdh") meep_utils.savetxt(fname=os.path.join('cdh',model.simulation_name+".dat"), fmt="%.6e", X=zip(t, E.real, E.imag), header=model.parameterstring + headerstring) with open("./last_simulation_name.dat", "w") as outfile: outfile.write(model.simulation_name) meep.all_wait() # Wait until all file operations are finished
monitor2_Hy, frequency_domain=sim_param['frequency_domain'], frequency=sim_param['frequency'], intf=getattr(model, 'interesting_frequencies', [0, model.src_freq + model.src_width]), pad_zeros=1.0, Kx=sim_param.get('Ky', 0), Ky=sim_param.get('Ky', 0)) print 'np.abs(s11)', np.abs(s11) if not os.path.isfile('ref.dat'): ## no reference yet, let us save one print "Saving the fields as a reference" 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)), header=model.parameterstring + meep_utils.sim_param_string(sim_param) + headerstring) else: ## save fields normalized to the reference print "Saving fields normalized to the reference (loaded from ref.dat)" (fref, s11refabs, s11refangle, s12refabs, s12refangle) = np.loadtxt('ref.dat', usecols=list(range(5)), unpack=True) meep_utils.savetxt(fname=model.simulation_name + "_NORMALIZED.dat", fmt="%.6e", X=zip(freq, np.abs(s11) / s11refabs, np.angle(s11) - s11refangle, np.abs(s12) / s12refabs,