-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfull_array.py
More file actions
79 lines (69 loc) · 2.65 KB
/
Copy pathfull_array.py
File metadata and controls
79 lines (69 loc) · 2.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import numpy as np
import matplotlib.pyplot as plt
import multiprocessing as mp
from scipy.spatial import KDTree
from circ_rps import *
import warnings,datetime
#warnings.filterwarnings("error")
plt.rc('font',family='serif')
import eqspiral as eqsp
import patch as psim
from array_funcs import *
def getNearestNeighbors(xs,ys,idx,neighbors):
points = list(zip(xs.ravel(),ys.ravel()))
tree = KDTree(points)
ds,idxes = tree.query([xs[idx],ys[idx]],k=(neighbors+1))
txs = xs[idxes]
tys = ys[idxes]
return txs,tys,idxes
def getElementParams(xs,ys,eid,freq,hs,L,W,theta,phi):
# prepare element parameters for a multi processing worker
txs,tys,neighbor_indexes = getNearestNeighbors(xs,ys,eid,6)
centers = np.vstack((txs,tys)).T*1000
centers = centers - centers[0,:]
return [freq,hs,centers,neighbor_indexes,L,W,theta,phi,eid]
def parallelEmbeddedWorker(element):
freq,hs,centers,neighbor_indexes,L,W,theta,phi,eid = element
En,s11f,s11_db,sfreq,zin,sn1 = psim.SimulateEmbeddedFarfield(freq,hs,centers,L,W,theta,phi,eid=eid)
print(len(neighbor_indexes))
print(type(neighbor_indexes))
neighbor_indexes = np.asarray(neighbor_indexes,dtype=np.int32)
np.savetxt(f'/results/ff_{eid}.txt',En)
np.savetxt(f'/results/s11_{eid}.txt',(sfreq,s11_db,np.real(zin),np.imag(zin)))
np.savetxt(f'/results/sn{eid}.txt',(neighbor_indexes,sn1[:,151]))
return
'''
Single threaded version
=======================
'''
if __name__ == '__main__':
import matplotlib.pyplot as plt
with open('/results/times.txt',mode='a') as f:
f.write(f'start: {datetime.datetime.now()}\n')
d= rps(6e9,1,3)
xs, ys = circ_positions(d)
rs = np.array([5,-10,3,20])
#xs,ys = rotate(xs,ys,rs,d)
L = 10.2
W = 15.5
hs =1.5
freqs = [6e9]
for fdx in range(len(freqs)):
freq = freqs[fdx]
lamb = 3e8/freq
k = 2*np.pi/lamb
theta = np.linspace(0, np.pi, 181)
phi = np.linspace(0, 2*np.pi, 361)
fs = np.zeros([xs.size, theta.size, phi.size])
# -----------------------------#
# Get embedded Element Patterns
# -----------------------------#
print('=============================================')
print('Starting Embedded Element Pattern Simulation')
print('=============================================')
centers = np.vstack((xs,ys)).T*1000
smn,Enorm = psim.SimulateFullArray(freq,hs,centers,L,W,theta,phi)
print(f'smn shape: {smn[:,:,151].shape}\n')
np.savetxt('/results/fullarray_smn.txt',smn[:,:,151])
with open('/results/times.txt',mode='a') as f:
f.write(f'end: {datetime.datetime.now()}')