-
Notifications
You must be signed in to change notification settings - Fork 11
/
dipole.py
227 lines (216 loc) · 11.4 KB
/
dipole.py
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
# -*- coding: utf-8 -*-
"""
This file gives the dipole radiation (E and B field) in the far field, the full radiation (near field + far field) and the near field radiation only
@author: manu
"""
from __future__ import division
import numpy
c=299792458.
pi=numpy.pi
mu0=4*pi*1e-7
eps0=1./(mu0*c**2)
def Hertz_dipole (r, p, R, phi, f, t=0, epsr=1.):
"""
Calculate E and B field strength radiated by hertzian dipole(s).
p: array of dipole moments [[px0,py0,pz0],[px1,py1,pz1],...[pxn,pyn,pzn]]
R: array of dipole positions [[X0,Y0,Z0],[X1,Y1,Z1],...[Xn,Yn,Zn]]
r: observation point [x,y,z]
f: array of frequencies [f0,f1,...]
t: time
phi: array with dipole phase angles (0..2pi) [phi0,phi1,...,phin]
return: fields values at observation point r at time t for every frequency in f. E and B are (3 components,number of frequencies) arrays.
"""
nf = len(f)
rprime = r-R # r'=r-R
if numpy.ndim(p) < 2:
magrprime = numpy.sqrt(numpy.sum((rprime)**2))
magrprimep = numpy.tile(magrprime, (len(f),1)).T
phip = numpy.tile(phi, (len(f),1))
w = 2*pi*f # \omega
k = w/c # wave number
krp = k*magrprimep # k|r'|
rprime_cross_p = numpy.cross(rprime, p) # r'x p
rp_c_p_c_rp = numpy.cross(rprime_cross_p, rprime) # (r' x p) x r'
rprime_dot_p = numpy.sum(rprime*p)
expfac = numpy.exp(1j*(w*t-krp+phip.T))/(4*pi*eps0*epsr)
Ex = expfac*(w**2/(c**2*magrprimep**3) * (numpy.tile(rp_c_p_c_rp[0],(nf,1))).T+(1/magrprimep**3-w*1j/(c*magrprimep**2))*(numpy.tile(3*rprime[0]*rprime_dot_p,(len(f),1)).T/magrprimep**2-numpy.tile(p[0].T,(len(f),1)).T))
Ey = expfac*(w**2/(c**2*magrprimep**3) * (numpy.tile(rp_c_p_c_rp[1],(nf,1))).T+(1/magrprimep**3-w*1j/(c*magrprimep**2))*(numpy.tile(3*rprime[1]*rprime_dot_p,(len(f),1)).T/magrprimep**2-numpy.tile(p[1].T,(len(f),1)).T))
Ez = expfac*(w**2/(c**2*magrprimep**3) * (numpy.tile(rp_c_p_c_rp[2],(nf,1))).T+(1/magrprimep**3-w*1j/(c*magrprimep**2))*(numpy.tile(3*rprime[2]*rprime_dot_p,(len(f),1)).T/magrprimep**2-numpy.tile(p[2].T,(len(f),1)).T))
Bx = expfac/(magrprimep**2*c**3)*(w**2*numpy.tile(rprime_cross_p[0],(nf,1)).T)*(1-c/(1j*w*magrprimep))
By = expfac/(magrprimep**2*c**3)*(w**2*numpy.tile(rprime_cross_p[1],(nf,1)).T)*(1-c/(1j*w*magrprimep))
Bz = expfac/(magrprimep**2*c**3)*(w**2*numpy.tile(rprime_cross_p[2],(nf,1)).T)*(1-c/(1j*w*magrprimep))
E = numpy.vstack((Ex,Ey,Ez))
B = numpy.vstack((Bx,By,Bz))
else:
magrprime = numpy.sqrt(numpy.sum((rprime)**2,axis=1))
magrprimep = numpy.tile(magrprime, (len(f),1)).T
phip = numpy.tile(phi, (len(f),1))
fp = numpy.tile(f,(len(magrprime),1))
w = 2*pi*fp # \omega
k = w/c # wave number
krp = k*magrprimep # k|r'|
rprime_cross_p = numpy.cross(rprime, p) # r' x p
rp_c_p_c_rp = numpy.cross(rprime_cross_p, rprime) # (r' x p) x r'
rprime_dot_p = numpy.sum(rprime*p,axis=1)
expfac = numpy.exp(1j*(w*t-krp+phip.T))/(4*pi*eps0*epsr)
Ex = expfac*(w**2/(c**2*magrprimep**3) * (numpy.tile(rp_c_p_c_rp[:,0],(nf,1))).T+(1/magrprimep**3-w*1j/(c*magrprimep**2))*(numpy.tile(3*rprime[:,0]*rprime_dot_p,(len(f),1)).T/magrprimep**2-numpy.tile(p[:,0].T,(len(f),1)).T))
Ey = expfac*(w**2/(c**2*magrprimep**3) * (numpy.tile(rp_c_p_c_rp[:,1],(nf,1))).T+(1/magrprimep**3-w*1j/(c*magrprimep**2))*(numpy.tile(3*rprime[:,1]*rprime_dot_p,(len(f),1)).T/magrprimep**2-numpy.tile(p[:,1].T,(len(f),1)).T))
Ez = expfac*(w**2/(c**2*magrprimep**3) * (numpy.tile(rp_c_p_c_rp[:,2],(nf,1))).T+(1/magrprimep**3-w*1j/(c*magrprimep**2))*(numpy.tile(3*rprime[:,2]*rprime_dot_p,(len(f),1)).T/magrprimep**2-numpy.tile(p[:,2].T,(len(f),1)).T))
Bx = expfac/(magrprimep**2*c**3)*(w**2*numpy.tile(rprime_cross_p[:,0],(nf,1)).T)*(1-c/(1j*w*magrprimep))
By = expfac/(magrprimep**2*c**3)*(w**2*numpy.tile(rprime_cross_p[:,1],(nf,1)).T)*(1-c/(1j*w*magrprimep))
Bz = expfac/(magrprimep**2*c**3)*(w**2*numpy.tile(rprime_cross_p[:,2],(nf,1)).T)*(1-c/(1j*w*magrprimep))
E = numpy.vstack((numpy.sum(Ex,axis=0),numpy.sum(Ey,axis=0),numpy.sum(Ez,axis=0)))
B = numpy.vstack((numpy.sum(Bx,axis=0),numpy.sum(By,axis=0),numpy.sum(Bz,axis=0)))
return E,B
def Hertz_dipole_ff (r, p, R, phi, f, t=0, epsr=1.):
"""
Calculate E and B field strength radaited by hertzian dipole(s) in the far field.
p: array of dipole moments [[px0,py0,pz0],[px1,py1,pz1],...[pxn,pyn,pzn]]
R: array of dipole positions [[X0,Y0,Z0],[X1,Y1,Z1],...[Xn,Yn,Zn]]
r: observation point [x,y,z]
f: array of frequencies [f0,f1,...]
t: time
phi: array with dipole phase angles (0..2pi) [phi0,phi1,...,phin]
return: fields values at observation point r at time t for every frequency in f. E and B are (3 components,number of frequencies) arrays.
"""
nf = len(f)
rprime = r-R # r'=r-R
if numpy.ndim(p) < 2:
magrprime = numpy.sqrt(numpy.sum((rprime)**2))
magrprimep = numpy.tile(magrprime, (len(f),1)).T
phip = numpy.tile(phi, (len(f),1))
w = 2*pi*f # \omega
k = w/c # wave number
krp = k*magrprimep # k|r'|
rprime_cross_p = numpy.cross(rprime, p) # r'x p
rp_c_p_c_rp = numpy.cross(rprime_cross_p, rprime) # (r' x p) x r'
expfac = numpy.exp(1j*(w*t-krp+phip.T))/(4*pi*eps0*epsr)
Ex = (w**2/(c**2*magrprimep**3) * expfac)* (numpy.tile(rp_c_p_c_rp[0],(nf,1))).T
Ey = (w**2/(c**2*magrprimep**3) * expfac)* (numpy.tile(rp_c_p_c_rp[1],(nf,1))).T
Ez = (w**2/(c**2*magrprimep**3) * expfac)* (numpy.tile(rp_c_p_c_rp[2],(nf,1))).T
Bx = expfac/(magrprimep**2*c**3)*(w**2*numpy.tile(rprime_cross_p[0],(nf,1)).T)
By = expfac/(magrprimep**2*c**3)*(w**2*numpy.tile(rprime_cross_p[1],(nf,1)).T)
Bz = expfac/(magrprimep**2*c**3)*(w**2*numpy.tile(rprime_cross_p[2],(nf,1)).T)
E = numpy.vstack((Ex,Ey,Ez))
B = numpy.vstack((Bx,By,Bz))
else:
magrprime = numpy.sqrt(numpy.sum((rprime)**2,axis=1)) # |r'|
magrprimep = numpy.tile(magrprime, (len(f),1)).T
phip = numpy.tile(phi, (len(f),1))
fp = numpy.tile(f,(len(magrprime),1))
w = 2*pi*fp # \omega
k = w/c # wave number
krp = k*magrprimep # k|r'|
rprime_cross_p = numpy.cross(rprime, p) # r'x p
rp_c_p_c_rp = numpy.cross(rprime_cross_p, rprime) # (r' x p) x r'
expfac = numpy.exp(1j*(w*t-krp+phip.T))/(4*pi*eps0*epsr)
Ex = (w**2/(c**2*magrprimep**3) * expfac)* (numpy.tile(rp_c_p_c_rp[:,0],(nf,1))).T
Ey = (w**2/(c**2*magrprimep**3) * expfac)* (numpy.tile(rp_c_p_c_rp[:,1],(nf,1))).T
Ez = (w**2/(c**2*magrprimep**3) * expfac)* (numpy.tile(rp_c_p_c_rp[:,2],(nf,1))).T
Bx = expfac/(magrprimep**2*c**3)*(w**2*numpy.tile(rprime_cross_p[:,0],(nf,1)).T)
By = expfac/(magrprimep**2*c**3)*(w**2*numpy.tile(rprime_cross_p[:,1],(nf,1)).T)
Bz = expfac/(magrprimep**2*c**3)*(w**2*numpy.tile(rprime_cross_p[:,2],(nf,1)).T)
E = numpy.vstack((numpy.sum(Ex,axis=0),numpy.sum(Ey,axis=0),numpy.sum(Ez,axis=0)))
B = numpy.vstack((numpy.sum(Bx,axis=0),numpy.sum(By,axis=0),numpy.sum(Bz,axis=0)))
return E,B
def Hertz_dipole_nf (r, p, R, phi, f, t=0, epsr=1.):
"""
Calculate E and B field strength radiated by hertzian dipole(s) in the near field.
p: array of dipole moments [[px0,py0,pz0],[px1,py1,pz1],...[pxn,pyn,pzn]]
R: array of dipole positions [[X0,Y0,Z0],[X1,Y1,Z1],...[Xn,Yn,Zn]]
r: observation point [x,y,z]
f: array of frequencies [f0,f1,...]
t: time
phi: array with dipole phase angles (0..2pi) [phi0,phi1,...,phin]
return: fields values at observation point r at time t for every frequency in f. E and B are (3 components,number of frequencies) arrays.
"""
nf = len(f)
rprime = r-R # r'=r-R
if numpy.ndim(p) < 2:
magrprime = numpy.sqrt(numpy.sum((rprime)**2))
magrprimep = numpy.tile(magrprime, (len(f),1)).T
phip = numpy.tile(phi, (len(f),1))
w = 2*pi*f # \omega
k = w/c # wave number
krp = k*magrprimep # k|r'|
rprime_cross_p = numpy.cross(rprime, p) # r'x p
rprime_dot_p = numpy.sum(rprime*p)
expfac = numpy.exp(1j*(w*t-krp+phip.T))/(4*pi*eps0*epsr)
Ex = expfac*((1/magrprimep**3-w*1j/(c*magrprimep**2))*(numpy.tile(3*rprime[0]*rprime_dot_p,(len(f),1)).T/magrprimep**2-numpy.tile(p[0].T,(len(f),1)).T))
Ey = expfac*((1/magrprimep**3-w*1j/(c*magrprimep**2))*(numpy.tile(3*rprime[1]*rprime_dot_p,(len(f),1)).T/magrprimep**2-numpy.tile(p[1].T,(len(f),1)).T))
Ez = expfac*((1/magrprimep**3-w*1j/(c*magrprimep**2))*(numpy.tile(3*rprime[2]*rprime_dot_p,(len(f),1)).T/magrprimep**2-numpy.tile(p[2].T,(len(f),1)).T))
Bx = expfac/(magrprimep**3*c**2)*(w*numpy.tile(rprime_cross_p[0],(nf,1)).T)*1j
By = expfac/(magrprimep**3*c**2)*(w*numpy.tile(rprime_cross_p[1],(nf,1)).T)*1j
Bz = expfac/(magrprimep**3*c**2)*(w*numpy.tile(rprime_cross_p[2],(nf,1)).T)*1j
E = numpy.vstack((Ex,Ey,Ez))
B = numpy.vstack((Bx,By,Bz))
else:
magrprime = numpy.sqrt(numpy.sum((rprime)**2,axis=1)) #|r'|
magrprimep = numpy.tile(magrprime, (len(f),1)).T
phip = numpy.tile(phi, (len(f),1))
fp = numpy.tile(f,(len(magrprime),1))
w = 2*pi*fp # \omega
k = w/c # wave number
krp = k*magrprimep # k|r'|
rprime_cross_p = numpy.cross(rprime, p) # r' x p
rprime_dot_p = numpy.sum(rprime*p,axis=1) # r'.p
expfac = numpy.exp(1j*(w*t-krp+phip.T))/(4*pi*eps0*epsr)
Ex = expfac*((1/magrprimep**3-w*1j/(c*magrprimep**2))*(numpy.tile(3*rprime[:,0]*rprime_dot_p,(len(f),1)).T/magrprimep**2-numpy.tile(p[:,0].T,(len(f),1)).T))
Ey = expfac*((1/magrprimep**3-w*1j/(c*magrprimep**2))*(numpy.tile(3*rprime[:,1]*rprime_dot_p,(len(f),1)).T/magrprimep**2-numpy.tile(p[:,1].T,(len(f),1)).T))
Ez = expfac*((1/magrprimep**3-w*1j/(c*magrprimep**2))*(numpy.tile(3*rprime[:,2]*rprime_dot_p,(len(f),1)).T/magrprimep**2-numpy.tile(p[:,2].T,(len(f),1)).T))
Bx = expfac/(magrprimep**3*c**2)*(w*numpy.tile(rprime_cross_p[:,0],(nf,1)).T)*1j
By = expfac/(magrprimep**3*c**2)*(w*numpy.tile(rprime_cross_p[:,1],(nf,1)).T)*1j
Bz = expfac/(magrprimep**3*c**2)*(w*numpy.tile(rprime_cross_p[:,2],(nf,1)).T)*1j
E = numpy.vstack((numpy.sum(Ex,axis=0),numpy.sum(Ey,axis=0),numpy.sum(Ez,axis=0)))
B = numpy.vstack((numpy.sum(Bx,axis=0),numpy.sum(By,axis=0),numpy.sum(Bz,axis=0)))
return E,B
if __name__ == "__main__":
from pylab import *
#observation points
nx=401
xmax=2
nz=201
zmax=1
x=numpy.linspace(-xmax,xmax,nx)
y=0
z=numpy.linspace(-zmax,zmax,nz)
#dipole
freq=numpy.array([1000e6])
#dipole moment
#total time averaged radiated power P= 1 W dipole moment => |p|=sqrt(12pi*c*P/muO/w**4)
Pow=1
norm_p=sqrt(12*pi*c*Pow/(mu0*(2*pi*freq)**4))
#dipole moment
p=numpy.array([0,0,norm_p])
R=numpy.array([0,0,0])
#dipole phases
phases_dip=0
nt=100
t0=1/freq/10
t1=5/freq
nt=int(t1/t0)
t=numpy.linspace(t0,t1,nt)
print("Computing the radiation...")
fig = figure(num=1,figsize=(10,6),dpi=300)
for k in range(nt):
P=numpy.zeros((nx,nz))
for i in range(nx):
for j in range(nz):
r=array([x[i],y,z[j]])
E,B=Hertz_dipole (r, p, R, phases_dip, freq, t[k], epsr=1.)
S=real(E)**2#0.5*numpy.cross(E.T,conjugate(B.T))
P[i,j]=sum(S)
print('%2.1f/100'%((k+1)/nt*100))
#Radiation diagram
pcolor(x,z,P[:,:].T,cmap='hot')
fname = 'img_%s' %(k)
clim(0,1000)
axis('scaled')
xlim(-xmax,xmax)
ylim(-zmax,zmax)
xlabel(r'$x/$m')
ylabel(r'$z/$m')
title(r'$t=%2.2f$ ns'%(t[k]/1e-9))
print 'Saving frame', fname
fig.savefig(fname+'.png',bbox='tight')
clf()