def test_multi(): freq = 5e9 cell_sz = 30. / 1000. scale = 30 # pre calculated horn power integration at 5GHz horn_integ = 22732.769823328235 abg = (np.deg2rad(180), np.deg2rad(180), np.deg2rad(0)) src = Source() horn = get_default_pyramidal_horn(freq) src.append(horn, abg, (0., 0., cell_sz*scale)) tp = [(np.deg2rad(20), np.deg2rad(0)), (np.deg2rad(20), np.deg2rad(90)), (np.deg2rad(20), np.deg2rad(180)), (np.deg2rad(20), np.deg2rad(270))] #tp = [(np.deg2rad(0), np.deg2rad(0))] tpm = [(np.deg2rad(0), np.deg2rad(0), 1)] arr = RAInfo(src, cell_sz, (scale, scale), ('pencil', (tp)), ideal_ref_unit) #arr = RAInfo(src, cell_sz, (scale, scale), ('oam', (tpm, np.deg2rad(0))), ideal_ref_unit) solver = RASolver(arr) tsk1 = Gain2D(np.deg2rad(0), 999) tsk2 = Gain2D(np.deg2rad(90), 600) tsk3 = Gain3D(100, 100) solver.append_task(tsk1) #solver.append_task(tsk2) #solver.append_task(tsk3) #solver.run() solver.run_concurrency() tsk1.post_process(horn_integ, True)
def test_fresnel_phicut(): freq = 6.0e9 cell_sz = 25 / 1000. lmbd = 3e8 / freq scale = 20 fdr = 0.8 hz = cell_sz*scale*fdr horn = get_default_pyramidal_horn(freq) pos = (0.0, 0.0, hz) abg = (np.deg2rad(180), np.deg2rad(180), np.deg2rad(0)) showFig = True far_z = 2 * (scale*cell_sz*np.sqrt(2)) ** 2 / lmbd focal = [(0.5, 0.5, 1.0, 1.0), (-0.5, -0.5, 1.0, 1.0)] src = Source() src.append(horn, abg, pos) arr = RAInfo(src, cell_sz, (scale, scale), ('foci', focal), circle_unit) solver = RASolver(arr, type='fresnel') tsk = PhiCutPlane((2.0, 1.5), (21, 21), phi=np.deg2rad(45)) solver.append_task(tsk) solver.run() tsk.post_process(showFig, None)
def line_feed_array(): freq = 10.0e9 cell_sz = 15 / 1000. scale = 10 abg = (np.deg2rad(180), np.deg2rad(180), np.deg2rad(0)) integ = 1.2068 showFig = True hz = cell_sz*scale*0.6 fd_list = [(0.0, -cell_sz*2, hz), (0.0, -cell_sz, hz), (0.0, 0.0, hz), (0.0, cell_sz, hz), (0.0, cell_sz*2, hz)] src = Source() for i in range(len(fd_list)): src.append(get_default_pyramidal_horn(freq, E0=1.0, initp=0.0), abg, fd_list[i], dir='parallel') tp = [(0, 0)] bs = 1 arr = RAInfo(src, cell_sz, (scale, scale), ('pencil', tp), lambda p:ideal_ref_unit(p, bits=bs)) solver = RASolver(arr) phi = np.deg2rad(90) tsk1 = Gain2D(phi, 300) #tsk1 = Gain3D(200, 200) solver.append_task(tsk1) solver.run() tsk1.post_process(integ*5, showFig)
def test_fresnel_onaxis(): freq = 6.0e9 cell_sz = 25 / 1000. lmbd = 3e8 / freq scale = 20 fdr = 0.8 hz = cell_sz*scale*fdr horn = get_default_pyramidal_horn(freq) pos = (0.0, 0.0, hz) abg = (np.deg2rad(180), np.deg2rad(180), np.deg2rad(0)) showFig = True far_z = 2 * (scale*cell_sz*np.sqrt(2)) ** 2 / lmbd focal_rio = 0.1 focal = [(0.0, 0.0, focal_rio*far_z, 1.0)] src = Source() src.append(horn, abg, pos) arr = RAInfo(src, cell_sz, (scale, scale), ('foci', focal), circle_unit) solver = RASolver(arr, type='fresnel') plane_rio = np.linspace(0.01, 0.5, 200) zlist = [pr*far_z for pr in plane_rio] tsk = OnAxisLine(zlist, plane_rio) solver.append_task(tsk) solver.run() tsk.post_process(showFig, None)
def RA_12x12(): freq = 5.0e9 cell_sz = 33 / 1000. scale = 12 fdr = 0.9 hz = cell_sz*scale*fdr abg = (np.deg2rad(180), np.deg2rad(180), np.deg2rad(0)) showFig = True integ = 30.17114 # 10.0, 5.0e9 horn = get_default_pyramidal_horn(freq) pos = (0.0, 0.0, hz) src = Source() src.append(horn, abg, pos) bs = 2 tmp = [(np.deg2rad(0), np.deg2rad(0))] arr = RAInfo(src, cell_sz, (scale, scale), ('pencil', tmp), lambda p:ideal_ref_unit(p, bits=bs, amp=0.8)) solver = RASolver(arr) tsk1 = Gain2D(np.deg2rad(0), 181) solver.append_task(tsk1) solver.run() tsk1.post_process(integ, showFig, exfn='experiment/12x12/xoz-theo.csv')
def __init__(self): print("SPI Source") Source.__init__(self) self._pidaq = PiDAQ(0, 0) #self._timer = LoopingCall(self.sample) #print("Starting Sample Timer") #self._timer.start(1) self.stopping = False reactor.callInThread(self.sample)
def __init__(self): Source.__init__(self) try: self._device = InterfaceKit() except RuntimeError as e: print("Runtime Error: %s" % e.message) try: self._device.openPhidget() except PhidgetException as e: print("Phidget Exception %i: %s" % (e.code, e.detail)) self._device.setOnSensorChangeHandler(self.sensor_changed) print("Phidget: Waiting for Connection") self._device.waitForAttach(10000) self._device.setSensorChangeTrigger(0, 0) self._device.setDataRate(0, 1) print("Phidget: Connected")
def test_offset_feed(): freq = 6.0e9 cell_sz = 25 / 1000. scale = 20 horn = get_default_pyramidal_horn(freq, E0=1.0) integ = 0.07083 showFig = True abg = (np.deg2rad(180), np.deg2rad(180), np.deg2rad(0)) src = Source() fdr = 1.0 fpos_offset = (0, cell_sz*2, cell_sz*scale*fdr) fpos = (0, 0, cell_sz*scale*fdr) src.append(horn, abg, fpos_offset, dir='parallel') tp = [(np.deg2rad(30), 0)] bs = 2 arr = RAInfo(src, cell_sz, (scale, scale), ('pencil', tp), lambda p:ideal_ref_unit(p, bits=bs)) solver = RASolver(arr) phi = np.deg2rad(0) tsk1 = Gain2D(phi, 300) #tsk1 = Gain3D(150, 150) solver.append_task(tsk1) solver.run() tsk1.post_process(integ, showFig)
import plot from sources import Source import numpy as np height = 200 width = 200 Sources = [] for i in range(4): a = Source() a.X = np.random.uniform(0.0, 200.0) a.Y = np.random.uniform(0.0, 200.0) a.A = np.random.uniform(1.0, 15.0) a.R = np.random.uniform(2.0, 9.0) Sources.append(a) plot.show_source(height, width, Sources)
#################################################### from datetime import datetime import psycopg2 import pandas as pd # Local Imports import sections import scrapers from sources import Source #################################################### #################### Sources ####################### #################################################### ap = Source("Associated Press", "ap", sections.ap, scrapers.ap) bbc = Source("The BBC", "bbc", sections.bbc, scrapers.bbc) blaze = Source("The Blaze", "blaze", sections.blaze, scrapers.blaze) # bloom = Source("Bloomberg", "bloom", sections.bloom, scrapers.bloom) breitbart = Source("Breitbart", "breitbart", sections.breitbart, scrapers.breitbart) buzzfeed = Source("Buzzfeed News", "buzzfeed", sections.buzzfeed, scrapers.buzzfeed) cnn = Source("CNN", "cnn", sections.cnn, scrapers.cnn) # dailyCaller = Source("The Daily Caller", "dailyCaller", sections.dailyCaller, scrapers.dailyCaller) dailyMail = Source("The Daily Mail", "dailyMail", sections.dailyMail, scrapers.dailyMail) dailyWire = Source("The Daily Wire", "dailyWire", sections.dailyWire, scrapers.dailyWire) examiner = Source("The Washington Examiner", "examiner", sections.examiner, scrapers.examiner)
def __init__(self): Source.__init__(self) self._sample_number = 0 self._timer = LoopingCall(self.sample) self._timer.start(0.01)
# import impedance-py/C++ module # import insitu_cpp #%% # step 1 - set air properties (2 opts: (i) - set manually; (ii) - by toml file) # (i) - set manually; air = AirProperties(temperature=20) # step 2 - set your controls controls = AlgControls(c0=air.c0, freq_init=100, freq_step=25, freq_end=3000) # step 3 - set the boundary condition / absorber material = PorousAbsorber(air, controls) # material.jcal(resistivity = 10000) material.delany_bazley(resistivity=25000) material.layer_over_rigid(thickness=0.1, theta=0) # material.plot_absorption() #%% step 4 - set the sources sources = Source(coord=[0.0, 0.0, 1.5]) # step 5 - set the receivers receivers = Receiver() receivers.double_planar_array(x_len=.175, y_len=0.175, n_x=8, n_y=8, dz=0.029, zr=0.013) #%% step 7 - run/load field ### You have some options: (1) - run a new simulation; # (2) - load an existing simulation and change sound source # (3) - load an existing simulation and change receivers (calculations at Field Points are easy) # (data of matrix assembly is saved and you can run some needed steps) ######## (1) Running new and saving ###############################
def planewave_ff(self, theta=0, phi=0, Ap=1, calc_ev=False, kx_f=2, ky_f=2, Ae=1): """ Calculates the sound field due to a plane wave in free field Parameters ---------- theta : float Elevation angle of the propagating plane wave in [rad] phi : float Azimuth angle of the propagating plane wave in [rad] Ap : float Amplitude of the propagating plane wave calc_ev : bool Whether to include an evanescent wave or not in the calculations. Default is False - just a propagating wave kx_f : float Evanescent wave kx factor: kx = kx_f * k0 ky_f : float Evanescent wave ky factor: ky = ky_f * k0 Ap : float Amplitude of the evanescent plane wave """ self.sources = Source([ np.cos(phi) * np.sin(theta), np.sin(phi) * np.sin(theta), np.cos(theta) ]) self.pres_s = [] # for js, s_coord in enumerate(self.sources.coord): # hs = s_coord[2] # source height # Initialize pres_rec = np.zeros( (self.receivers.coord.shape[0], len(self.controls.freq)), dtype=np.csingle) # Loop over receivers for jrec, r_coord in enumerate(self.receivers.coord): for jf, k0 in enumerate(self.controls.k0): # Propagating wave number kx = k0 * np.cos(phi) * np.sin(theta) ky = k0 * np.sin(phi) * np.sin(theta) kz = k0 * np.cos(theta) k_vec = np.array([kx, ky, kz]) if calc_ev: # Evanescent wave number kxe = k0 * kx_f kye = k0 * ky_f kze = (kxe**2 + kye**2 - k0**2)**0.5 # Evanescent pressure p_ev = (np.exp(-kze * r_coord[2])) * (np.exp( -1j * (kxe * r_coord[0] + kye * r_coord[1]))) pres_rec[jrec, jf] = Ap * np.exp( 1j * np.dot(k_vec, r_coord)) + Ae * p_ev else: pres_rec[jrec, jf] = Ap * np.exp(1j * np.dot(k_vec, r_coord)) self.pres_s.append(pres_rec)
def __iter__(self): with self.lock: self.idx = 0 return self def __next__(self): with self.lock: if self.idx == len(self): raise StopIteration ret = self.efield[self.idx] self.idx += 1 return ret if __name__ == '__main__': freq = 5e9 cell_sz = 30. / 1000. scale = 20 abg = (np.deg2rad(180), np.deg2rad(180), np.deg2rad(0)) src = Source() src.append(get_default_pyramidal_horn(freq), abg, (0., 0., 0.5)) tp = [(np.deg2rad(0), np.deg2rad(0))] tpm = [(np.deg2rad(0), np.deg2rad(0), 1)] foci = [(0, 0, 0.8, 1.0)] arr = RAInfo(src, cell_sz, (scale, scale), ('oam', (tpm, np.deg2rad(10))), ideal_ref_unit) for (ex, ey) in arr: print(ex, ey)
def __init__( self, path='/home/eric/research/insitu_arrays/bem_bem/free sides - single sw/DATA_60cm_x_60cm_h25mm_fmax_6000Hz/s0/', fname='DATA_60cm_x_60cm_1st-rec_array_3drandom_2nd-rec_array_2layer_3rd-rec___s0_h25mm_fmax_6kHz', array_type='3D random'): # Load the .mat file mat_contents = sio.loadmat(path + fname, squeeze_me=False) # Get the air data air = mat_contents['amb'][0, 0] self.air = AirProperties(c0=air['co'].item(), rho0=air['rho'].item(), temperature=air['Tem'].item(), humid=air['HR'].item(), p_atm=air['Po'].item()) # # Get the controls data freq_vec = mat_contents['datafreq_ar'][0, 0] self.controls = AlgControls(c0=self.air.c0, freq_vec=freq_vec['frequencia'][0, :]) # Get the source data source_struct = mat_contents['fonte'][0, 0] source = source_struct['coord'][0, 0] self.sources = Source() self.sources.coord = np.array( [source['xs'].item(), source['ys'].item(), source['zs'].item()]) self.sources.coord = np.reshape(self.sources.coord, (1, 3)) r, theta, phi = cart2sph(self.sources.coord[0, 0], self.sources.coord[0, 1], self.sources.coord[0, 2]) # Get the material data material = mat_contents['material'][0, 0] self.material = PorousAbsorber(self.air, self.controls) self.material.miki(resistivity=material['resist'].item()) # self.material.resistivity = material['resist'].item() # self.material.Zp = material['imp_caract'][0,:] # self.material.kp = material['num_onda'][0,:] self.material.layer_over_rigid(thickness=material['espessura'].item(), theta=np.pi / 2 - theta) # test with my material # mymat = PorousAbsorber(self.air, self.controls) # mymat.miki(resistivity=material['resist'].item()) # mymat.layer_over_rigid(thickness=material['espessura'].item(), # theta = np.pi/2-theta) # fig = plt.figure() # fig.canvas.set_window_title("alpha test") # plt.semilogx(self.controls.freq, self.material.alpha, '--k', linewidth = 3) # plt.semilogx(self.controls.freq, mymat.alpha, 'b') # plt.grid(linestyle = '--', which='both') # plt.show() self.material.model = "Paulo's Miki" # self.material.plot_absorption() # Get receiver and sound pressure data - they depend on the type of array receivers_struct = mat_contents['recept'][0, 0] receivers = receivers_struct['coord'][0, 0] pres = mat_contents['pressoes_eric'][0, 0] # pres = pres_struct['p_total_rec'][0,,] self.receivers = Receiver() if array_type == '3D random': self.receivers.coord = (np.array([ receivers['xr'][0:290, 0], receivers['yr'][0:290, 0], receivers['zr'][0:290, 0] ])).T self.pres_s = [np.array(pres['p_total_rec'][0:290, :])] elif array_type == '2 layer': self.receivers.coord = (np.array([ receivers['xr'][290:418, 0], receivers['yr'][290:418, 0], receivers['zr'][290:418, 0] ])).T self.pres_s = [np.array(pres['p_total_rec'][290:418, :])] else: self.receivers.coord = (np.array([ receivers['xr'][418:, 0], receivers['yr'][418:, 0], receivers['zr'][418:, 0] ])).T self.pres_s = [np.array(pres['p_total_rec'][418:, :])] # Get sample size size = mat_contents['dim_max_painel'][0, 0] self.Lx = size['x'].item() self.Ly = size['y'].item()
def focal_2bit_calculation(): freq = 5.8e9 cell_sz = 30 / 1000. scale = 10 fdr = 0.9 hz = cell_sz*scale*fdr abg = (np.deg2rad(180), np.deg2rad(180), np.deg2rad(0)) showFig = True integ = 1.039 # 1.6, 5.8e9 horn = get_default_pyramidal_horn(freq, E0=1.6) pos = (0.0, 0.0, hz) src = Source() src.append(horn, abg, pos) focuses = ( [(1.0, 1.0, 1.0, 1.0)], [(-0.3, 0.3, 1.5, 1.0), (0.3, -0.3, 1.5, 1.0)], [(0.3, 0.3, 2.0, 1.0)] ) hs = ( 1.0, 1.5, 2.0 ) planes = ( (3.0, 3.0), (1.2, 1.2), (1.2, 1.2) ) points = ( (301, 301), (121, 121), (121, 121) ) ps = ( np.deg2rad(45), np.deg2rad(135), np.deg2rad(45) ) Nt, Np = 181, 181 for idx in range(3): bs = 2 arr = RAInfo(src, cell_sz, (scale, scale), ('foci', focuses[idx]), lambda p:ideal_ref_unit(p, bits=bs)) solver = RASolver(arr) tsk1 = FresnelPlane(0, 'xx', hs[idx], planes[idx], points[idx]) tsk2 = Gain2D(ps[idx], Nt, freq) tsk3 = Gain3D(Np, Nt) solver.append_task(tsk1) solver.append_task(tsk2) solver.append_task(tsk3) solver.run() tsk1.post_process(integ, showFig, exfn='experiment/2bit/case{}_plane_theo.fld'.format(idx+1)) tsk2.post_process(integ, showFig, exfn='experiment/2bit/case{}_2d_theo.csv'.format(idx+1)) tsk3.post_process(integ, showFig, exfn='experiment/2bit/case{}_3d_theo.csv'.format(idx+1))