Merge branch 'master' into devel
[wrffire.git] / standalone / fuel_interp_test_main.F
blob1f497c61e638430dfaaab09cea8ebe7d828613cf
1         program test
2         use module_fr_sfire_core
3         implicit none
4 real :: time_now
5 integer :: ims,ime,jms,jme,icl,jcl,i,j,num_tests,flag
6 real,dimension(3,3)::tff,lff,lfn,tign,real_tff,real_lff
7 real,dimension(3,3)::tff0,lff0,lfn0,tign0,real_tff0,real_lff0
8 real,dimension(3,3)::tff1,lff1,lfn1,tign1,real_tff1,real_lff1
9 real,dimension(3,3)::tff2,lff2,lfn2,tign2,real_tff2,real_lff2
10 real,dimension(3,3)::tff3,lff3,lfn3,tign3,real_tff3,real_lff3
11 real,dimension(3,3)::tff8,lff8,lfn8,tign8
12 real,dimension(3,5)::tff9,lff9,lfn9,tign9
13 real, dimension(5,5)::d
14 real,dimension(2,2)::result
15 real::test_err,error
16 real::lfn00,lfn01,lfn10,lfn11,tign00,tign01,tign10,tign11,fuel_time_cell
17 real:: result1,Result2,Result3,Result4,Result5,result6
18 real:: res,res1,res2,res3,res4!
19 real::fire_area
20 time_now=3.
21 101 format(a/(3f7.3))
22 ims=1
23 ime=3
24 jms=1
25 jme=3
26 icl=2
27 jcl=2
28 error=0.0001
29 num_tests=0
30 fire_area=0;
31 !!!!! Test #1
32 !lfn - plane Z=1.5-X;
33 ! tign -- everywhere where lfn>=0, tign=3;
34 ! everywhere where lfn<0, tign=Z+3;
35 data lfn/0.5, -0.5, -1.5, &
36          0.5, -0.5,-1.5, &
37          0.5, -0.5,-1.5/
39 data tign/3.0, 2.5, 1.5, &
40           3.0, 2.5, 1.5, &
41           3.0, 2.5, 1.5 /
43 data real_tff/3.0, 2.5, 2.0, &
44           3.0, 2.5, 2.0, &
45           3.0, 2.5, 2.0 /
47 data real_lff/0.0, -0.5, -1.0, &
48           0.0, -0.5, -1.0, &
49           0.0, -0.5, -1.0 /
51         call tign_lfn_interpolation(time_now,icl,jcl,ims,ime,jms,jme, &
52                                     tign,lfn,tff,lff)
53 test_err=1
54         test_err=maxval(abs(real_tff-tff))
55 if (test_err>error) then
56         print*,'Test #1 is not working, error ',test_err
57         print*,'is greater than 0.0001'
58 else
59 num_tests=num_tests+1;
60 endif
61 !!!! Test #2
62 !lfn - plane Z=4-X-Y;
63 ! tign -- everywhere where lfn>=0, tign=3;
64 ! everywhere where lfn<0, tign=Z+3;
65 data lfn1/2.0, 1.0, 0.0, &
66          1.0, 0.0,-1.0, &
67          0.0, -1.0,-2.0/
69 data tign1/3.0, 3.0, 3.0, &
70           3.0, 3.0, 2.0, &
71           3.0, 2.0, 1.0 /
73 data real_tff1/3.0, 3.0, 3.0, &
74           3.0, 3.0, 2.5, &
75           3.0, 2.5, 2.0 /
77 data real_lff1/1.0, 0.5, 0.0, &
78           0.5, 0.0, -0.5, &
79           0.0, -0.5, -1.0 /
81         call tign_lfn_interpolation(time_now,icl,jcl,ims,ime,jms,jme, &
82                                     tign1,lfn1,tff1,lff1)
84 test_err=1
85         test_err=maxval(abs(real_tff1-tff1))
87 if (test_err>error) then
88         print*,'Test #2 is not working, error ',test_err
89         print*,'is greater than 0.0001'
90 else
91 num_tests=num_tests+1;
92 endif
93 !!!! Test #3
95 !=======
96 !lfn - plane Z=3-X-Y;
97 ! tign -- everywhere where lfn>=0, tign=3;
98 ! everywhere where lfn<0, tign=Z+3;
99 data lfn2/1.0, 0.0, -1.0, &
100          0.0, -1.0,-2.0, &
101          -1.0, -2.0,-3.0/
103 data tign2/3.0, 3.0, 2.0, &
104           3.0, 2.0, 1.0, &
105           2.0, 1.0, 0.0 /
107 data real_tff2/3.0, 2.5, 2.0, &
108           2.5, 2.0, 1.5, &
109           2.0, 1.5, 1.0 /
111 data real_lff2/0.0, -0.5, -1.0, &
112           -0.5, -1.0, -1.5, &
113           -1.0, -1.5, -2.0 /
117         call tign_lfn_interpolation(time_now,icl,jcl,ims,ime,jms,jme, &
118                                     tign2,lfn2,tff2,lff2)
120 test_err=1
121 test_err=maxval(abs(real_tff2-tff2))
122 if (test_err>error) then
123         print*,'Test #3 is not working, error ',test_err
124         print*,'is greater than 0.0001'
125 else
126 num_tests=num_tests+1;
127 endif
128 !!!! Test #4
130 !=======
131 !lfn - plane Z=5-X-Y;
132 ! tign -- everywhere where lfn>=0, tign=3;
133 ! everywhere where lfn<0, tign=Z+3;
134 data lfn3/3.0, 2.0, 1.0, &
135          2.0, 1.0, 0.0, &
136          1.0, 0.0,-1.0/
138 data tign3/3.0, 3.0, 3.0, &
139           3.0, 3.0, 3.0, &
140           3.0, 3.0, 2.0 /
142 data real_tff3/3.0, 3.0, 3.0, &
143           3.0, 3.0, 3.0, &
144           3.0, 3.0, 3.0 /
146 data real_lff3/2.0, 1.5, 1.0, &
147           1.5, 1.0, 0.5, &
148           1.0, 0.5, 0.0 /
152         call tign_lfn_interpolation(time_now,icl,jcl,ims,ime,jms,jme, &
153                                     tign3,lfn3,tff3,lff3)
154 test_err=1
155 test_err=maxval(abs(real_tff3-tff3))
156 if (test_err>error) then
157         print*,'Test #4 is not working, error ',test_err
158         print*,'is greater than 0.0001'
159 else
160 num_tests=num_tests+1;
161 endif
162 print*,''
163 !!!Tests for fuel_left calculation!!!
164 !!!Test #5, result in Matlab u=(-2;0;1) f =0.91691!
165 res=0.9169
166 lfn00=-1.
167 lfn01=-1.
168 lfn10=1.
169 lfn11=1.
170 tign00=1.
171 tign01=1.
172 tign10=2.
173 tign11=2.
174 time_now=2
175 fuel_time_cell= 8.235294 ;
177 call fuel_left_cell_3(  &
178     result1,fire_area,  &
179     lfn00,lfn01,lfn10,lfn11, &
180     tign00,tign01,tign10,tign11,&
181     time_now, fuel_time_cell)
183 test_err=1
184 test_err=res-result1
186 if (test_err>error) then
187         print*,'Test #5 is not working, error ',test_err
188         print*,'is greater than 0.0001'
189 else
190 num_tests=num_tests+1;
191 endif
195 !Test#6, result in Matlab u=(1;0;1) f =0.1660
196 res=0.166
197 lfn00=-2.
198 lfn01=-2.
199 lfn10=-1.
200 lfn11=-1.
201 tign00=1.
202 tign01=1.
203 tign10=2.
204 tign11=2.
205 time_now=3
206 fuel_time_cell= 8.235294 ;
208 call fuel_left_cell_3(  &
209     result1,fire_area,  & 
210     lfn00,lfn01,lfn10,lfn11, &
211     tign00,tign01,tign10,tign11,&
212     time_now, fuel_time_cell)
214 test_err=1
215 test_err=res-result1
217 if (test_err>error) then
218         print*,'Test #6 is not working, error ',test_err
219         print*,'is greater than 0.0001'
220 else
221 num_tests=num_tests+1;
222 endif
224 !Test7, result in Matlab u=-(2;0;4) f =0.4538
225 res=0.4538
226 lfn00=-2.
227 lfn01=-2.
228 lfn10=-4.
229 lfn11=-4.
230 tign00=6.
231 tign01=6.
232 tign10=4.
233 tign11=4.
234 time_now=10
235 fuel_time_cell= 8.235294 ;
237 call fuel_left_cell_3(  &
238     result1,fire_area,  &
239     lfn00,lfn01,lfn10,lfn11, &
240     tign00,tign01,tign10,tign11,&
241     time_now, fuel_time_cell)
243 test_err=1
244 test_err=res-result1
245 if (test_err>error) then
246         print*,'Test #7 is not working, error ',test_err
247         print*,'is greater than 0.0001'
248 else
249 num_tests=num_tests+1;
250 endif
253 !Test#8, result in Matlab u=(-4;-4;6) f =0.5336
254 res=0.5336
255 lfn00=-3.
256 lfn01=-1.
257 lfn10=-1.
258 lfn11=1.
259 tign00=4.
260 tign01=8.
261 tign10=8.
262 tign11=10.
263 time_now=10
264 fuel_time_cell= 8.235294 ;
266 call fuel_left_cell_3(  &
267     result1,fire_area,  &
268     lfn00,lfn01,lfn10,lfn11, &
269     tign00,tign01,tign10,tign11,&
270     time_now, fuel_time_cell)
272 test_err=1
273 test_err=res-result1
274 if (test_err>error) then
275         print*,'Test #8 is not working, error ',test_err
276         print*,'is greater than 0.0001'
277 else
278 num_tests=num_tests+1;
279 endif
281 !Test9, result in Matlab u=(-2;-2;1) f =0.9692
282 res=0.9692
283 lfn00=-1.
284 lfn01=1.
285 lfn10=1.
286 lfn11=3.
287 tign00=1.
288 tign01=2.
289 tign10=2.
290 tign11=2.
291 time_now=2
292 fuel_time_cell= 8.235294 ;
294 call fuel_left_cell_3(  &
295     result1,fire_area,  &
296     lfn00,lfn01,lfn10,lfn11, &
297     tign00,tign01,tign10,tign11,&
298     time_now, fuel_time_cell)
300 test_err=1
301 test_err=res-result1
302 if (test_err>error) then
303         print*,'Test #9 is not working, error ',test_err
304         print*,'is greater than 0.0001'
305 else
306 num_tests=num_tests+1;
307 endif
309 print*,""
311 print*,"Main Test (#10), we calculate the fuel_left of the center cell"
312 print*,"(we have 9 cells initially)"
313 print*,"The initial values are"
314 print*,"lfn is described by the plane z=y-2; tign is described by the plane z=y"
317 time_now=2.
319 data lfn8/-1., 0., 1., &
320          -1., 0.,1., &
321          -1., 0.,1./
323 data tign8/1.0, 2., 2., &
324           1.0, 2., 2., &
325           1.0, 2., 2. /
326 res1=2.9752314E-02
327 res2=2.9752314E-02
328 res3=1.000
329 res4=1.000
330 print*,"time_now",time_now
331 write(*,101)'tign',tign8
332 write(*,101)'lfn',lfn8
333 print*,"icl,jcl should be equal 2 here"
334 write(*,*)'icl,jcl',icl,jcl
335 print*,"calling tign_lfn_interpolation, that calculates"
336         call tign_lfn_interpolation(time_now,icl,jcl,ims,ime,jms,jme, &
337                                     tign8,lfn8,tff8,lff8)
339 print*,"as result tff,lff are"
340 write(*,101)'tff',tff8
341 write(*,101)'lff',lff8
343 d=1e20
344 d(1:5:2,1:5:2)=tign8
345 d(2:4,2:4)=tff8
346 write(*,*)'tign and tff, here you can check whether they were  & 
347            calculated properly'
348 write(*,'(5f7.3)')d
349 write(*,*)' '
350 d(1:5:2,1:5:2)=lfn8
351 d(2:4,2:4)=lff8
352 write(*,*)'lfn and lff, here you can check whether they were calculated properly'
353 write(*,'(5f7.3)')d
354 write(*,*)' '
357 fuel_time_cell= 8.235294 ;
358 print*,"Calculation of fuel_frac over 4 subcells"
360 do i=1,2  ! Loop over 4 subcells
361    do j=1,2
362 print*,""
363 print*,"meaning of tff and lff in the subcell",i,j
364 write(*,*)'lff',lff8(i,j),lff8(i,j+1),lff8(i+1,j),lff8(i+1,j+1)
365 write(*,*)'tff',tff8(i,j),tff8(i,j+1),tff8(i+1,j),tff8(i+1,j+1)
366 call fuel_left_cell_3(  &
367     result(i,j),fire_area,  &
368     lff8(i,j),lff8(i,j+1),lff8(i+1,j),lff8(i+1,j+1), &
369     tff8(i,j),tff8(i,j+1),tff8(i+1,j),tff8(i+1,j+1),&
370     time_now, fuel_time_cell)
371 write(*,*)'result after step i and j',result(i,j),i,j
372 end do
373 end do
375 if (res1-result(1,1)>error.or.res2-result(1,2)>error.or.res3-result(2,1)>error.or.res4-result(2,2)>error) then
376         print*,'Test #10 is not working, one of errors '
377         print*,'For cell (1,1)',res1-result(1,1)
378         print*,'For cell (1,2)',res2-result(1,2)
379         print*,'For cell (2,1)',res3-result(2,1)
380         print*,'For cell (2,2)',res4-result(2,2)
381         print*,'is greater than 0.0001',error
382 else
383 num_tests=num_tests+1;
384 endif
386 print*,""
387 print*,""
388 !!!! Test #2
390 write(*,*)'MAIN TEST #2 (#11)'
391 print*,"Check for consistency, for 3 inner cells with the same results"
392 time_now=2.
393 ims=1
394 ime=5
395 jms=1
396 jme=5
397 res1=2.9752314E-02
398 res2=1.000
399 res3=2.9752314E-02
400 res4=1.000
401 flag=1
402 data lfn9/-1., -1.,-1., &
403          -1., -1.,0., &
404          0., 0.,0., &
405          0., 1., 1., &
406          1.,1.,1./
408 data tign9/1.0, 1., 1., &
409           1.0, 1., 2., &
410           2.0, 2., 2.,  &
411           2.,2.,2., &
412           2.,2.,2./
414 do icl=2,4
415         write(*,*)"icl,jcl",icl,jcl
416        call tign_lfn_interpolation(time_now,icl,jcl,ims,ime,jms,jme, &
417                                     tign9,lfn9,tff9,lff9)
419 fuel_time_cell= 8.235294 ;
420         write(*,*)"Calculation of fuel_frac over 4 subcells"
421 result6=0;
422 do i=1,2
423    do j=1,2
426 call fuel_left_cell_3(  &
427     result(i,j),fire_area,  &
428     lff9(i,j),lff9(i,j+1),lff9(i+1,j),lff9(i+1,j+1), &
429     tff9(i,j),tff9(i,j+1),tff9(i+1,j),tff9(i+1,j+1),&
430     time_now, fuel_time_cell)
431 write(*,*)'result after step i and j',result(i,j),i,j
433 end do
434 end do
436 if (res1-result(1,1)>error.or.res2-result(1,2)>error.or.res3-result(2,1)>error.or.res4-result(2,2)>error) then
437         print*,'Test #10 is not working, one of errors '
438         print*,'For cell (1,1)',res1-result(1,1)
439         print*,'For cell (1,2)',res2-result(1,2)
440         print*,'For cell (2,1)',res3-result(2,1)
441         print*,'For cell (2,2)',res4-result(2,2)
442         print*,'is greater than 0.0001',error
443         flag=0 
444 end if
446 end do
447 if (flag.eq.1) then 
448     num_tests=num_tests+1;
449 endif
450 print*,"If the results for each correspondent subcell are equal in all cells"
451 print*,"then the code is consistent"
453 print*,num_tests,'of 11 tests worked succesfully'
456  end program test