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
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