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
filesample.close() 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()) ## 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, intf=getattr(model, 'interesting_frequencies', [0, model.src_freq + model.src_width]), pad_zeros=1.0, Kx=model_param.get('Kx', 0), Ky=model_param.get('Ky', 0), eps1=1.0, eps2=3.24) print "Saving the fields as a reference" np.savetxt(fname='./' + model.simulation_name + '/sparam.dat', fmt="%.6e", X=zip(freq, np.abs(s11), np.angle(s11), np.abs(s12), np.angle(s12))) with open("./last_simulation_name.dat", "w") as outfile: outfile.write(model.simulation_name) meep.all_wait() # Wait until all file operations are finished
slices += [meep_utils.Slice(model=model, field=f, components=meep.Ex, at_z=model.monitor_z2, min_timestep=.05e-14, outputhdf=True, outputgif=True, name='PerpendicularCut')] slices += [meep_utils.Slice(model=model, field=f, components=meep.Ex, at_z=model.monitor_z3, at_y=0, outputhdf=True, name='Line')] f.step(); timer = meep_utils.Timer(simtime=model.simtime); meep.quiet(True) # use custom progress messages controlsample = 0 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) #filesample = open('./'+model.simulation_name + '/Exsampleafter.dat','a') #filesample.write(str(f.time()/c)+' ') #filesample.write(str(f.get_field(meep.Ex, meep.vec(0, 0,model.monitor_z1)))+'\n') #filesample.close() 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()) ## 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, intf=getattr(model, 'interesting_frequencies', [0, model.src_freq+model.src_width]), pad_zeros=1.0, Kx=model_param.get('Kx', 0), Ky=model_param.get('Ky', 0),eps1=3.133,eps2=1.0) print "Saving the fields as a reference" np.savetxt(fname='./'+model.simulation_name + "/sparam.dat", fmt="%.6e", X=zip(freq, np.abs(s11), np.angle(s11), np.abs(s12), np.angle(s12))) 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
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
#print f.get_field(meep.Ex, meep.vec(0,0,0)) 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.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)
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) +