PageRenderTime 32ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/VF/parallel_of_all_3/ParallelPole.for

http://ua-fwlis.googlecode.com/
FORTRAN Legacy | 498 lines | 303 code | 125 blank | 70 comment | 16 complexity | 834be950f8d7745becbd09fc721d6caa MD5 | raw file
Possible License(s): GPL-3.0
  1. !!=========================================================================
  2. module init
  3. DOUBLE PRECISION Freq,OMega,Mu1,Mu2,Mu0,Mur1,Mur2,Pi
  4. DOUBLE PRECISION Epsilonr1,Epsilonr2,Epsilon0,Zn1,Zn2,d
  5. DOUBLE PRECISION tanDelta1, tanDelta2, Error,lambda
  6. COMPLEX*16 Epsilon1, Epsilon2,Kp, Kz1,Kz2,j, Diff, K1,K2,DDa, DDb
  7. INTEGER Iteration
  8. end module init
  9. !!=========================================================================
  10. subroutine initValue
  11. use init
  12. implicit none
  13. j =(0.0d0,1.0d0)
  14. !Pi = 3.141592653589793d0
  15. Pi = acos(0.d0)*2
  16. Mu0 = 4*Pi*1d-7
  17. Mur1 = 1.00d0
  18. Mur2 = 1.00d0
  19. Mu1 = Mur1*Mu0
  20. Mu2 = Mur2*Mu0
  21. Epsilon0 = 8.854d-12
  22. Epsilonr1 = 1.000d0
  23. Epsilonr2 = 4.000d0
  24. tanDelta1 = 0.05d0
  25. tanDelta2 = 0.05d0
  26. ! Epsilon1 = Epsilon0*Epsilonr1*((1.0d0,0.0d0)-tanDelta1*j)
  27. ! Epsilon2 = Epsilon0*Epsilonr2*((1.0d0,0.0d0)-tanDelta2*j)
  28. Epsilon1 = Epsilon0*(Epsilonr1*(1.0d0,0.0d0)-1.d-6*j)
  29. Epsilon2 = Epsilon0*(Epsilonr2*(1.0d0,0.0d0)-1.d-4*j)
  30. Freq = 12.0e+9
  31. Lambda = 3.e8/Freq
  32. Omega = 2.0d0*Pi*Freq
  33. Diff = (Omega**2)*(Mu2*Epsilon2-Mu1*Epsilon1)
  34. K1=(Omega**2)*Mu1*Epsilon1
  35. K2=(Omega**2)*Mu2*Epsilon2
  36. ! Zn1=0.0007620d0
  37. ! Zn2=0.0000762d0
  38. zn1=Lambda/10
  39. zn2=10*Zn1
  40. d =ZN1+ZN2
  41. Error = 1e-4
  42. Iteration = 100 !1e+4
  43. end subroutine initValue
  44. !!=========================================================================
  45. module Parallel_POLE
  46. !use init_module
  47. use init
  48. implicit none
  49. contains
  50. !!!***********************************************************
  51. FUNCTION TheMerge(A,B)
  52. DOUBLE PRECISION A(:),B(:)
  53. DOUBLE PRECISION TheMerge(1:size(A)+size(B))
  54. TheMerge(1:size(A))=A
  55. TheMerge(size(A)+1:size(A)+size(B))=B
  56. end FUNCTION TheMerge
  57. !!!***********************************************************
  58. FUNCTION TheSort (A)
  59. DOUBLE PRECISION A(:)
  60. DOUBLE PRECISION TheSort(1:size(A))
  61. INTEGER sizeA, nn,mm
  62. DOUBLE PRECISION tmp
  63. sizeA = size (A)
  64. TheSort(1:sizeA)=A
  65. do nn=1, sizeA
  66. do mm=nn+1, sizeA
  67. if (TheSort(nn) > TheSort(mm)) then
  68. tmp=TheSort(nn)
  69. TheSort(nn)=TheSort(mm)
  70. TheSort(mm)=tmp
  71. end if
  72. end do
  73. end do
  74. end FUNCTION TheSort
  75. !!!***********************************************************
  76. subroutine TEtheDb(theMu1, theMu2,theEpsilon1,theEpsilon2,theZn1,
  77. & theZn2, theKz2, theFreq,thedb,thedfdr)
  78. DOUBLE PRECISION theMu1, theMu2,thePi, theFreq, theOmega,
  79. & theZn1, theZn2
  80. complex*16,intent(inout) :: thedb,thedfdr
  81. COMPLEX*16 theEpsilon1, theEpsilon2,theKz2,theKZ1,theDiff
  82. & ,tan_kz1,tan_kz2
  83. thePi = PI
  84. !theOmega = 2.0d0*thePi*theFreq
  85. theOmega = Omega
  86. theDiff = diff
  87. theKZ1 = sqrt(theKz2**2-theDiff)
  88. tan_kz1 = tan(thekz1*theZn2)
  89. tan_kz2 = tan(thekz2*theZn1)
  90. !TEtheDb = tan_kz1*theKz2+tan_kz2*theKz1
  91. thedb = tan_kz1*theKz2+tan_kz2*theKz1
  92. thedfdr = tan_kz2*thekz2/thekz1+thekz1*(1+tan_kz2*tan_kz2)*theZn1
  93. &+tan_kz1+(1+tan_kz1*tan_kz1)*thezn2*thekz2*thekz2/thekz1
  94. end subroutine TEtheDb
  95. !!!***********************************************************
  96. COMPLEX*16 FUNCTION TEtheSearchRoot(tMu1, tMu2, tEpsilon1
  97. & , tEpsilon2, tZn1,tZn2, tFreq, start_val, end_val, iter, err)
  98. DOUBLE PRECISION tMu1, tMu2, tZn1, tZn2 , InitGuess
  99. & tPi, tFreq, tOmega, err, mag, magD,
  100. & start_val, end_val,tKz2r, tKz2i,InitGuess
  101. & ,startVal,endVal
  102. COMPLEX*16 tEpsilon1, tEpsilon2, tkz1,tKz2, tDiff,
  103. & tDb, tDfdr
  104. INTEGER iter, n
  105. !!! tzn1=d2,tzn2=d1 !*** Important ***
  106. !theDiff = theOmega**2*(theMu2*theEpsilon2-theMu1*theEpsilon1)
  107. !!!tdb=FU, tdfdr=DFU
  108. startVal=start_val
  109. endval =end_val
  110. tdiff=Diff
  111. n=0
  112. InitGuess= (startVal+endval)/2.0d0
  113. tKz2r = InitGuess
  114. tKz2i =0.0d0
  115. tKz2 =tKz2r*(1.0d0,0.0d0)+tKz2i*(0.0d0,1.0d0)
  116. tkz1 = sqrt(tKz2**2-tDiff)
  117. CALL TEtheDb (tMu1,tMu2,tEpsilon1,tEpsilon2,
  118. & tZn1,tZn2,tKz2,tFreq,tDb,tDfdr)
  119. !mag= sqrt(REAL(tDb)**2+AIMAG(tDb)**2)
  120. mag= abs(tDb)
  121. magD= REAL(tDfdr)**2-AIMAG(tDfdr)**2
  122. do while ( (n<=iter) .AND. (mag>err*1.e-4*abs(tan(tkz1*tZn2)*tkz2)) )
  123. if(REAL(tKz2)<startVal) then
  124. endval=InitGuess
  125. InitGuess= (startVal+endval)/2.0d0
  126. tKz2r = InitGuess
  127. tKz2i =0.0d0
  128. tKz2 =tKz2r*(1.0d0,0.0d0)+tKz2i*(0.0d0,1.0d0)
  129. tkz1 = sqrt(tKz2**2-tDiff)
  130. CALL TEtheDb (tMu1,tMu2,tEpsilon1,tEpsilon2,
  131. & tZn1,tZn2,tKz2,tFreq,tDb,tDfdr)
  132. mag= abs(tDb)
  133. magD= REAL(tDfdr)**2-AIMAG(tDfdr)**2
  134. n=n+1
  135. else if(REAL(tKz2)>endval) then
  136. startVal=InitGuess
  137. InitGuess= (startVal+endval)/2.0d0
  138. tKz2r = InitGuess
  139. tKz2i =0.0d0
  140. tKz2 =tKz2r*(1.0d0,0.0d0)+tKz2i*(0.0d0,1.0d0)
  141. tkz1 = sqrt(tKz2**2-tDiff)
  142. CALL TEtheDb (tMu1,tMu2,tEpsilon1,tEpsilon2,
  143. & tZn1,tZn2,tKz2,tFreq,tDb,tDfdr)
  144. mag= abs(tDb)
  145. magD= REAL(tDfdr)**2-AIMAG(tDfdr)**2
  146. n=n+1
  147. else
  148. tKz2r=tKz2r-(REAL(tDb)*REAL(tDfdr)-j*AIMAG(tDb)*AIMAG(tDfdr))/magD
  149. tKz2i=tKz2i-(j*REAL(tDb)*AIMAG(tDfdr)+AIMAG(tDb)*REAL(tDfdr))/magD
  150. tKz2 =tKz2r*(1.0d0,0.0d0)+tKz2i*(0.0d0,1.0d0)
  151. !
  152. !evaluate again
  153. CALL TEtheDb (tMu1,tMu2,tEpsilon1,tEpsilon2,
  154. & tZn1,tZn2,tKz2,tFreq,tDb,tDfdr)
  155. !mag= sqrt(REAL(tDb)**2+AIMAG(tDb)**2)
  156. mag= abs(tDb)
  157. magD= REAL(tDfdr)**2-AIMAG(tDfdr)**2
  158. n=n+1
  159. end if ! if-else-if
  160. end do ! while
  161. TEtheSearchRoot=tKz2
  162. end function TEtheSearchRoot
  163. !!!***********************************************************
  164. Subroutine TMtheDa(theMu1, theMu2, theEpsilon1, theEpsilon2
  165. & ,theZn1,theZn2, theKz2, theFreq,theda,thedfdr)
  166. DOUBLE PRECISION theMu1, theMu2,
  167. & thePi, theFreq, theOmega,theZn1, theZn2
  168. complex*16,intent(inout)::theda,thedfdr
  169. COMPLEX*16 theEpsilon1, theEpsilon2, theKz2, theDiff,
  170. & thekz1,tan_kz1,tan_kz2,Er
  171. thePi = PI
  172. !theOmega = 2.0d0*thePi*theFreq
  173. theOmega = Omega
  174. !theDiff = theOmega**2*(theMu2*theEpsilon2-theMu1*theEpsilon1)
  175. theDiff = Diff
  176. theKZ1 = sqrt(theKz2**2-theDiff)
  177. tan_kz1 = tan(thekz1*theZn2)
  178. tan_kz2 = tan(thekz2*theZn1)
  179. Er = theEpsilon2/theEpsilon1
  180. theda = Er*thekz1*tan_kz1+thekz2*tan_kz2
  181. thedfdr= Er*tan_kz1*thekz2/thekz1+Er*(1+tan_kz1**2)*thekz2*thezn2
  182. & +tan_kz2+(1+tan_kz2**2)*thekz2*thezn1
  183. end Subroutine TMtheDa
  184. !!!***********************************************************
  185. COMPLEX*16 FUNCTION TMtheSearchRoot(tMu1, tMu2, tEpsilon1,
  186. & tEpsilon2, tZn1,tZn2, tFreq, start_Val, end_Val, iter, err)
  187. DOUBLE PRECISION tMu1, tMu2, tZn1, tZn2 , InitGuess
  188. & tPi, tFreq, tOmega, err, mag, magD,
  189. & start_Val, end_Val,
  190. & startVal, endVal,tKz2r, tKz2i,InitGuess
  191. COMPLEX*16:: tEpsilon1, tEpsilon2, tKz2,tkz1,tDiff,
  192. & tDa, tMdfdr
  193. INTEGER iter, n
  194. tdiff=Diff
  195. startVal=start_val
  196. endval =end_val
  197. n=0
  198. InitGuess= (startVal+endVal)/2.0d0
  199. tKz2r = InitGuess
  200. tKz2i =0.0d0
  201. tKz2 =tKz2r*(1.0d0,0.0d0)+tKz2i*(0.0d0,1.0d0)
  202. tkz1 = sqrt(tKz2**2-tDiff)
  203. CALL TMtheDa (tMu1,tMu2,tEpsilon1,tEpsilon2,
  204. & tZn1,tZn2,tKz2,tFreq,tDa,tMdfdr)
  205. !mag= sqrt(REAL(tDb)**2+AIMAG(tDb)**2)
  206. mag= abs(tDa)
  207. magD= REAL(tMdfdr)**2-AIMAG(tMdfdr)**2
  208. do while ( (n<=iter) .AND. (mag>err*1.e-4*abs(tan(tkz1*tZn2)*tkz2)) )
  209. if(REAL(tKz2)<startVal) then
  210. endVal=InitGuess
  211. InitGuess= (startVal+endVal)/2.0d0
  212. tKz2r = InitGuess
  213. tKz2i =0.0d0
  214. tKz2 =tKz2r*(1.0d0,0.0d0)+tKz2i*(0.0d0,1.0d0)
  215. tkz1 = sqrt(tKz2**2-tDiff)
  216. CALL TMtheDa(tMu1,tMu2,tEpsilon1,tEpsilon2,
  217. & tZn1,tZn2,tKz2,tFreq,tDa,tMdfdr)
  218. mag= abs(tDa)
  219. magD= REAL(tMdfdr)**2-AIMAG(tMdfdr)**2
  220. n=n+1
  221. else if(REAL(tKz2)>endVal) then
  222. startVal=InitGuess
  223. InitGuess= (startVal+endVal)/2.0d0
  224. tKz2r = InitGuess
  225. tKz2i =0.0d0
  226. tKz2 =tKz2r*(1.0d0,0.0d0)+tKz2i*(0.0d0,1.0d0)
  227. tkz1 = sqrt(tKz2**2-tDiff)
  228. CALL TMtheDa (tMu1,tMu2,tEpsilon1,tEpsilon2,
  229. & tZn1,tZn2,tKz2,tFreq,tDa,tMdfdr)
  230. mag= abs(tDa)
  231. magD= REAL(tMdfdr)**2-AIMAG(tMdfdr)**2
  232. n=n+1
  233. else
  234. tKz2r=tKz2r-(REAL(tDa)*REAL(tMdfdr)-j*AIMAG(tDa)
  235. & *AIMAG(tMdfdr))/magD
  236. tKz2i=tKz2i-(j*REAL(tDa)*AIMAG(tMdfdr)+AIMAG(tDa)
  237. & *REAL(tMdfdr))/magD
  238. tKz2 =tKz2r*(1.0d0,0.0d0)+tKz2i*(0.0d0,1.0d0)
  239. !
  240. !evaluate again
  241. CALL TMtheDa (tMu1,tMu2,tEpsilon1,tEpsilon2,
  242. & tZn1,tZn2,tKz2,tFreq,tDa,tMdfdr)
  243. !mag= sqrt(REAL(tDa)**2+AIMAG(tDa)**2)
  244. mag= abs(tDa)
  245. magD= REAL(tMdfdr)**2-AIMAG(tMdfdr)**2
  246. n=n+1
  247. end if
  248. end do
  249. TMtheSearchRoot=tKz2
  250. end function TMtheSearchRoot
  251. !!!***********************************************************
  252. FUNCTION foundKpforTE(N)
  253. ! For calculating the poles of TE mode for Horizontal Dipole in stripline
  254. !use init
  255. ***********************************
  256. INTEGER N,i,ii
  257. DOUBLE PRECISION tmag, testStart, testEnd
  258. COMPLEX*16 Db, Dfdr,foundKpforTE(1:N), Kp1,Kp2
  259. DOUBLE PRECISION, ALLOCATABLE :: Asys1(:), Asys2(:),
  260. & Asys(:), SortedAys(:)
  261. ***********************************
  262. call initValue
  263. *********************************
  264. allocate (Asys1(1:(N+5)))
  265. allocate (Asys2(1:(N+5)))
  266. allocate (Asys(1:2*(N+5)))
  267. allocate (SortedAys(1:2*(N+5)))
  268. ****************************************
  269. Do i=1, N+5
  270. Asys1(i)=(i-0.5d0)*Pi/Zn1
  271. Asys2(i)=sqrt(((i-0.5d0)*Pi/Zn2)**2+Diff)
  272. end Do
  273. Asys=TheMerge(Asys1,Asys2)
  274. SortedAys=TheSort(Asys)
  275. c print *, SortedAys
  276. open (2, FILE="./results/theResultTE.txt",STATUS='replace')
  277. ii=1
  278. Do i=1,2*(N+5)-1
  279. testStart= SortedAys(i)
  280. testEnd = SortedAys(i+1)
  281. Kz2= TEtheSearchRoot(Mu1, Mu2, Epsilon1, Epsilon2, Zn1,
  282. & Zn2, Freq, testStart, testEnd, Iteration, Error)
  283. Call TEtheDb(Mu1,Mu2,Epsilon1,Epsilon2,
  284. & Zn1,Zn2,Kz2,Freq,db,Dfdr)
  285. tmag= sqrt(REAL(Db)**2+AIMAG(Db)**2)
  286. Kz1= sqrt(Kz2**2-Diff)
  287. Kp1=sqrt(Omega**2*Mu1*Epsilon1-Kz1**2)
  288. Kp2=sqrt(Omega**2*Mu2*Epsilon2-Kz2**2)
  289. write (2,"(A20)" ) ""
  290. write (2,"('the start point=',F25.15)") (testStart)
  291. write (2,"('the end point=',F25.15)") (testEnd)
  292. write (2,"('Kz2= ', F24.15, F24.15,'j')") (REAL(Kz2),AIMAG(Kz2))
  293. write (2,"('Kz1= ', F24.15, F24.15,'j')") (REAL(Kz1),AIMAG(Kz1))
  294. write (2,"('Db =', F25.15, F25.15,'j')") (REAL(Db),AIMAG(Db))
  295. write (2,"('the error=',F25.15)") (tmag)
  296. write (2,"('Kp1(derived from K_z1)=', F22.15, F22.15,'j')")
  297. & (REAL(Kp1),AIMAG(Kp1))
  298. write (2,"('Kp2(derived from K_z2)=', F22.15, F22.15,'j')")
  299. & (REAL(Kp2),AIMAG(Kp2))
  300. if (tmag<Error) then
  301. write (2, "(A10)") "ROOT FOUND"
  302. if (ii<=N) then
  303. foundKpforTE(ii)=Kp1
  304. ii=ii+1
  305. end if
  306. end if
  307. if (tmag>=Error) then
  308. write (2, "(A19)") "ROOT NOT FOUND !!!"
  309. end if
  310. end Do
  311. end FUNCTION foundKpforTE
  312. !!!***********************************************************
  313. FUNCTION foundKpforTM(N)
  314. ! For calculating the poles of TM mode for Horizontal Dipole in stripline
  315. !use init
  316. ***********************************
  317. INTEGER N,i,ii
  318. DOUBLE PRECISION tmag, testStart, testEnd
  319. COMPLEX*16 Da, Dfdr,foundKpforTM(1:N), Kp1,Kp2
  320. DOUBLE PRECISION, ALLOCATABLE :: Asys1(:), Asys2(:),
  321. & Asys(:), SortedAys(:)
  322. ***********************************
  323. call initValue
  324. *********************************
  325. allocate (Asys1(1:(N+5)))
  326. allocate (Asys2(1:(N+5)))
  327. allocate (Asys(1:2*(N+5)))
  328. allocate (SortedAys(1:2*(N+5)))
  329. ****************************************
  330. Do i=1, N+5
  331. Asys1(i)=(i-0.5)*Pi/Zn1
  332. Asys2(i)=real(sqrt(((i-0.5)*Pi/Zn2)**2+Diff))
  333. end Do
  334. Asys=TheMerge(Asys1,Asys2)
  335. SortedAys=TheSort(Asys)
  336. c print *, SortedAys
  337. open (2, FILE="./results/theResultTM.txt",STATUS='replace')
  338. ii=1
  339. Do i=1,2*(N+5)-1
  340. testStart= SortedAys(i)
  341. testEnd = SortedAys(i+1)
  342. Kz2= TMtheSearchRoot(Mu1, Mu2, Epsilon1, Epsilon2, Zn1,
  343. & Zn2, Freq, testStart, testEnd, Iteration, Error)
  344. Call TMtheDa(Mu1,Mu2,Epsilon1,Epsilon2,
  345. & Zn1,Zn2,Kz2,Freq,Da,Dfdr)
  346. tmag= sqrt(REAL(Da)**2+AIMAG(Da)**2)
  347. Kz1= sqrt(Kz2**2-Diff)
  348. Kp1=sqrt(Omega**2*Mu1*Epsilon1-Kz1**2)
  349. Kp2=sqrt(Omega**2*Mu2*Epsilon2-Kz2**2)
  350. write (2,"(A20)" ) ""
  351. write (2,"('the start point=',F25.15)") (testStart)
  352. write (2,"('the end point=',F25.15)") (testEnd)
  353. write (2,"('Kz2= ', F24.15, F24.15,'j')") (REAL(Kz2),AIMAG(Kz2))
  354. write (2,"('Kz1= ', F24.15, F24.15,'j')") (REAL(Kz1),AIMAG(Kz1))
  355. write (2,"('Da =', F25.15, F25.15,'j')") (REAL(Da),AIMAG(Da))
  356. write (2,"('the error=',F25.15)") (tmag)
  357. write (2,"('Kp1(derived from Kz1)=', F22.15, F22.15,'j')")
  358. & (REAL(Kp1),AIMAG(Kp1))
  359. write (2,"('Kp2(derived from Kz2)=', F22.15, F22.15,'j')")
  360. & (REAL(Kp2),AIMAG(Kp2))
  361. if (tmag<Error) then
  362. write (2, "(A10)") "ROOT FOUND"
  363. if (ii<=N) then
  364. foundKpforTM(ii)=Kp1
  365. ii=ii+1
  366. end if
  367. end if
  368. if (tmag>=Error) then
  369. write (2, "(A19)") "ROOT NOT FOUND !!!"
  370. end if
  371. end Do
  372. end FUNCTION foundKpforTM
  373. end module Parallel_POLE