Advertisement
shadvoll

MoM_thinWire

Sep 13th, 2018
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.73 KB | None | 0 0
  1. import numpy as np
  2. import math as m
  3. import cmath as cm
  4. import scipy.integrate as spint
  5. import scipy
  6. import matplotlib.pyplot as plt
  7. #Parameter
  8. lamda=300
  9. L=150
  10. a=1
  11. eps=1
  12. mu=1
  13. #number of segments
  14. N = 15
  15. #Computer constants
  16. k0=2*m.pi/lamda
  17. k=k0*m.sqrt(mu*eps)
  18. step_z=float(L/(N))
  19. #functions
  20. #integration
  21. def fun(value):
  22.     R = m.sqrt( value**2 + a**2)
  23.     return -cm.exp(-1j*k*R)/(4*R*m.pi)
  24.  
  25. def complex_quadrature(func, a, b, **kwargs):
  26.     def real_func(x):
  27.         return scipy.real(func(x))
  28.     def imag_func(x):
  29.         return scipy.imag(func(x))
  30.     real_integral = spint.quad(real_func, a, b, **kwargs)
  31.     imag_integral = spint.quad(imag_func, a, b, **kwargs)
  32.     return (real_integral[0] + 1j*imag_integral[0])
  33.  
  34. #start field
  35. V = np.ones((N,1))
  36. #Build Impedance Matrix
  37. Z_tmp = np.zeros((N,N),dtype=complex)
  38. Z = np.zeros((N,N),dtype=complex)
  39.  
  40. for i in range(N):
  41.     Z_tmp[i][i] = 1/(4*m.pi)*m.log( (m.sqrt(1+(2*a/step_z)**2)+1)/ (m.sqrt(1+(2*a/step_z)**2)-1))-1j*k*step_z/(4*m.pi)
  42. for i in range(N):
  43.     for j in range(N):
  44.         r1= cm.sqrt(((i-j)*step_z+step_z/2)**2+a**2)
  45.         r2= cm.sqrt(((i-j)*step_z-step_z/2)**2+a**2)
  46.         t1= ((i-j)*step_z+step_z/2)*(1+1j*k*r1)/r1**3 * cm.exp(-1j*k*r1)
  47.         t2= ((i-j)*step_z-step_z/2)*(1+1j*k*r2)/r2**3 * cm.exp(-1j*k*r2)
  48.         if i != j :
  49.             Z_tmp[i][j] = complex_quadrature(fun,(i-j)*step_z+step_z/2,(i-j)*step_z-step_z/2)
  50.         Z[i][j] = k**2*Z_tmp[i][j] + t2 - t1        
  51. Z = 1j*step_z/k * Z
  52. I = np.dot(Z,V)
  53. np.savetxt('out.txt',Z,fmt='%.2e')
  54. print(np.size(I))
  55. plt.plot(np.linspace(0,L,N),abs(scipy.real(I)))
  56. plt.title('Distribution of current on thin wire. Method of Moments')
  57. plt.ylabel('Amplitude I, A')
  58. plt.xlabel('L, mm')
  59. plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement