-
Notifications
You must be signed in to change notification settings - Fork 1
/
fine-2D-TE-FDTD.f90~
404 lines (314 loc) · 12.9 KB
/
fine-2D-TE-FDTD.f90~
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
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
!------------------------------------------------------------------
!
! 2D FDTD implementation
!
! (TE mode -Hz,Ey and Ey-)
!
!------------------------------------------------------------------
PROGRAM FD_FDTD
IMPLICIT NONE
!----------------------------------------------------------------
! Variables for input_params
!----------------------------------------------------------------
!----------------------------------------------------------------
! Number of elements in each direction
!----------------------------------------------------------------
INTEGER :: nx, ny
!----------------------------------------------------------------
! Maximum number of steps
!----------------------------------------------------------------
INTEGER :: t_max
!----------------------------------------------------------------
! Data output directory
!----------------------------------------------------------------
CHARACTER(len=128) :: dirname, rdirname
CHARACTER :: outformat*3, chr
integer, dimension(1) :: iop
integer, dimension(3) :: jop
character :: filename*128
!----------------------------------------------------------------
! Time step skip
!----------------------------------------------------------------
REAL :: timeskip
!----------------------------------------------------------------
! Length of the time step
!----------------------------------------------------------------
REAL :: dt
!----------------------------------------------------------------
! Distance between 2 cells
!----------------------------------------------------------------
REAL :: dx,dy,dz
!----------------------------------------------------------------
! Epsilon0, permittivity of free space (in farad/meter)
!----------------------------------------------------------------
REAL :: eps_0
!----------------------------------------------------------------
! Light speed (v in m/s)
!----------------------------------------------------------------
REAL, parameter :: C = 3.0*10.0**8
!----------------------------------------------------------------
! mu0, permeability of free space (in henry/meter)
!----------------------------------------------------------------
REAL :: mu_0
!----------------------------------------------------------------
! Pi
!----------------------------------------------------------------
REAL :: pi
!----------------------------------------------------------------
! Variables for loop
!----------------------------------------------------------------
INTEGER :: i, j, k, t, err
INTEGER :: i1, i2, j1, j2
INTEGER :: op1, op2
REAL :: ax, ay
!----------------------------------------------------------------
! field values
!----------------------------------------------------------------
REAL, DIMENSION(:,:), ALLOCATABLE :: ex, ey
REAL, DIMENSION(:,:), ALLOCATABLE :: hz
REAL, DIMENSION(:,:), ALLOCATABLE :: epsr_x
REAL, DIMENSION(:,:), ALLOCATABLE :: epsr_y, eps_r
INTEGER, dimension(:,:), allocatable :: flagx, flagy
integer :: iobj1, iobj2, jobj1, jobj2
integer :: nxh, nyh, movex, movey
INTEGER, dimension(:,:), allocatable :: m_code
!---------------------------------------------------------------
! Variables for source excitation
!----------------------------------------------------------------
INTEGER :: temp, fine, islide, istart, sum
REAL :: anormalize, isourcecase
REAL :: amplite, amplith, decal, tau, t1, t2
REAL :: teta, steta, cteta, dxcteta, dysteta
REAL :: to, tt2, te, th, raise, einc, hinc
REAL :: eix, eiy, hix, hiy
INTEGER :: ihuyg1, ihuyg2, jhuyg1, jhuyg2, ihuyg22, jhuyg22, io, jo, ii, jj
REAL :: evalue, tgauss
INTEGER :: imin, imax, jmin, jmax, ia, ja, temps, tempf, h_rate
REAL, allocatable :: mspecs(:,:)
REAL, allocatable :: mspecs_read(:)
character(len=32), allocatable :: mdesc(:)
character(len=32) :: mdesc_read
character(len=2) :: magic ! magic number
character(len=64) :: comment
integer :: width, height, maxv ! maximum value
integer :: ke, mcode, nmat, ke, rate
!---------------------------------------------------------------
! Reading input parameters
!----------------------------------------------------------------
open(unit=51, &
file='input_params_fine', &
status="old", &
iostat=err)
if (err.NE.0) then
print *, "Error reading file: 'input_params'"
stop
endif
read(51, *, iostat=err) chr, nx, ny
read(51, *, iostat=err) chr, t_max
read(51, *, iostat=err) chr, dx
read(51, *, iostat=err) chr, ihuyg1, ihuyg2, jhuyg1, jhuyg2
read(51, *, iostat=err) chr, iobj1, iobj2, jobj1, jobj2
read(51, *, iostat=err) chr, nxh, nyh
close(unit=51)
!----------------------------------------------------------------
! Allocate field arrays
!----------------------------------------------------------------
allocate(ex(1:nx, 1:ny), stat=err)
allocate(ey(1:nx, 1:ny), stat=err)
allocate(hz(1:nx, 1:ny), stat=err)
allocate(epsr_x(1:nx, 1:ny), stat=err)
allocate(epsr_y(1:nx, 1:ny), stat=err)
allocate(flagx(1:nx,1:nx), stat=err)
allocate(flagy(1:ny,1:ny), stat=err)
allocate( m_code(1:nxh,1:nyh), stat=err)
allocate( eps_r(1:nxh,1:nyh), stat=err)
!----------------------------------------------------------------
! Initialising the fields with 0
!----------------------------------------------------------------
ex(1:nx,1:ny) = 0.0
ey(1:nx,1:ny) = 0.0
hz(1:nx,1:ny) = 0.0
m_code = 0
eps_r = 1
epsr_x = 1
epsr_y = 1
!----------------------------------------------------------------
! pi
!----------------------------------------------------------------
pi = acos(-1.0)
!----------------------------------------------------------------
! setting dx and dt
!----------------------------------------------------------------
dy=dx
timeskip = 0.95
dt = 1.0d0 * timeskip / (C*sqrt(1.0d0/(dx**2)+1.0d0/(dy**2)))
! dt = 3.6e-12/2.
! in jean pierre code- (dt about 3D stability condition => representative of applications) formula: dt = 1.0d0 * timeskip / (C*sqrt(3.0d0/(dx**2)))
imin=50
imax=nx-50
jmin=50
jmax=ny-50
!--------------------------------------------------------------
! setting huygens excitation parameters
!----------------------------------------------------------------
amplite=100.
amplith=amplite/376.99
! tt2=tau**2
! to=5*tau
tgauss = 134.5e-12 !30*dt*2
to=3*tgauss
teta=0
teta=teta*pi/180.
steta=sin(teta)
cteta=cos(teta)
if(steta.gt.-0.01.and.steta.lt.0.01) steta=0.
if(cteta.gt.-0.01.and.cteta.lt.0.01) cteta=0.
dxcteta=dx*cteta/3e8
dysteta=dy*steta/3e8
eix=-amplite*steta
eiy=amplite*cteta
print *, eix, eiy
io = ihuyg1-2
jo = jhuyg1-2
ihuyg22=ihuyg2-1
jhuyg22=jhuyg2-1
!----------------------------------------------------------------
! mu_0
!----------------------------------------------------------------
mu_0 = 4*pi*10**(-7.0)
!----------------------------------------------------------------
! eps_0
!----------------------------------------------------------------
eps_0 = 1.0/(mu_0*C*C)
!----------------------------------------------------------------
! print out settings
!----------------------------------------------------------------
print *," "
print *,"FDTD algorithm"
print *," "
print *,"Meshing parameters:"
print *," ",nx,ny,"x,y"," cells"
print *," dx=",dx," meters", dt
print *," "
print *,"Time simulated will be ",dt*t_max," seconds"
print *," ",t_max," timesteps"
print *," timesteps of ",dt," seconds"
print *," "
print *, "huygens surface",ihuyg1, ihuyg2, jhuyg1, jhuyg2
include 'set_materials.f90'
include 'flags-fine.f90'
include 'constants-fine.f90'
!------------------------------------------------------------------------------
! main loop
!------------------------------------------------------------------------------
print *, "Starting time step iteration"
DO t=1, t_max
t1=dt*(t-1)+2*dt
!----------------------------------------------------------------
! Updating Hz
!----------------------------------------------------------------
do j=jmin,jmax
do i=imin,imax
!
hz(i,j)=hz(i,j)-dt/(mu_0*dx)*(ey(i+1,j)-ey(i,j))+dt/(mu_0*dy)*(ex(i,j+1)-ex(i,j))
!
end do
end do
!----------------------------------------------------------------
! source excitation for Hz
!----------------------------------------------------------------
do j=jhuyg1,jhuyg22
te=t1-(ihuyg1-io)*dxcteta-(j-jo+0.5)*dysteta
einc=eiy*exp(-((te-to)/tgauss)**2)
if(te.lt.0) einc=0.
hz(ihuyg1-1,j)=hz(ihuyg1-1,j)+dt/(mu_0*dx)*einc
end do
do j=jhuyg1,jhuyg22
te=t1-(ihuyg2-io)*dxcteta-(j-jo+0.5)*dysteta
einc=eiy*exp(-((te-to)/tgauss)**2)
if(te.lt.0) einc=0.
hz(ihuyg2,j)=hz(ihuyg2,j)-dt/(mu_0*dx)*einc
end do
do i=ihuyg1,ihuyg22
te=t1-(i-io+0.5)*dxcteta-(jhuyg1-jo)*dysteta
einc=eix*exp(-((te-to)/tgauss)**2)
if(te.lt.0) einc=0.
hz(i,jhuyg1-1)=hz(i,jhuyg1-1)-dt/(mu_0*dy)*einc
end do
do i=ihuyg1,ihuyg22
te=t1-(i-io+0.5)*dxcteta-(jhuyg2-jo)*dysteta
einc=eix*exp(-((te-to)/tgauss)**2)
if(te.lt.0) einc=0.
hz(i,jhuyg2)=hz(i,jhuyg2)+dt/(mu_0*dy)*einc
end do
!----------------------------------------------------------------
! Updating Ex
!----------------------------------------------------------------
do j=jmin,jmax
do i=imin,imax
ex(i,j)=ex(i,j) &
& +dt/(eps_0*dy)/epsr_x(i,j)*(hz(i,j)-hz(i,j-1))
end do
end do
!----------------------------------------------------------------
! Updating Ey
!----------------------------------------------------------------
do j=jmin,jmax
do i=imin,imax
ey(i,j)=ey(i,j) &
& -dt/(eps_0*dx)/epsr_y(i,j)*(hz(i,j)-hz(i-1,j))
end do
end do
!----------------------------------------------------------------
! source excitation for Ey
!----------------------------------------------------------------
do j=jhuyg1,jhuyg22
th=t1+dt*0.5-(ihuyg1-io-0.5)*dxcteta-(j-jo+0.5)*dysteta
hinc=amplith*exp(-((th-to)/tgauss)**2)
if(th.lt.0) hinc=0.
ey(ihuyg1,j)=ey(ihuyg1,j)+dt/(eps_0*dx)*hinc
end do
do j=jhuyg1,jhuyg22
th=t1+dt*0.5-(ihuyg2-io+0.5)*dxcteta-(j-jo+0.5)*dysteta
hinc=amplith*exp(-((th-to)/tgauss)**2)
if(th.lt.0) hinc=0.
ey(ihuyg2,j)=ey(ihuyg2,j)-dt/(eps_0*dx)*hinc
end do
!----------------------------------------------------------------
! source excitation for Ex
!----------------------------------------------------------------
do i=ihuyg1,ihuyg22
th=t1+dt*0.5-(i-io+0.5)*dxcteta-(jhuyg1-jo-0.5)*dysteta
hinc=amplith*exp(-((th-to)/tgauss)**2)
if(th.lt.0) hinc=0.
ex(i,jhuyg1)=ex(i,jhuyg1)-dt/(eps_0*dy)*hinc
end do
do i=ihuyg1,ihuyg22
th=t1+dt*0.5-(i-io+0.5)*dxcteta-(jhuyg2-jo+0.5)*dysteta
hinc=amplith*exp(-((th-to)/tgauss)**2)
if(th.lt.0) hinc=0.
ex(i,jhuyg2)=ex(i,jhuyg2)+dt/(eps_0*dy)*hinc
end do
!----------------------------------------------------------------
! Output in the function of time step
!----------------------------------------------------------------
! write(100,*) t, (ex(596,636)+ex(597,636))/2.0, t*dt*1e9 !A
! write(200,*) t, (ey(596,634)+ey(596,635))/2.0, t*dt*1e9 !B
! write(300,*) t, (ey(596,636)+ey(596,637))/2.0, t*dt*1e9 !C
! write(400,*) t, (ex(596,638)+ex(597,638))/2.0, t*dt*1e9 !D
!----------------------------------------------------------------
! Output in the function of space
!----------------------------------------------------------------
include 'auto_observation-fine.f90'
END DO ! DO t=0, t_max
!------------------------------------------------------------------------------
! end main loop
!------------------------------------------------------------------------------
!----------------------------------------------------------------
! deallocate variables
!----------------------------------------------------------------
deallocate(ex, stat=err)
deallocate(ey, stat=err)
deallocate(hz, stat=err)
stop
END PROGRAM FD_FDTD