forked from wrf-model/WRF
/
module_fr_sfire_driver.F
940 lines (795 loc) · 43.7 KB
/
module_fr_sfire_driver.F
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
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
! SFIRE - Spread fire model in WRF-Fire
!
!*** Jan Mandel August 2007 - March 2011
!*** email: Jan.Mandel@gmail.com
! For support please subscribe to the wrf-fire mailing list at NCAR at
! http://mailman.ucar.edu/mailman/listinfo/wrf-fire
! or go to http://www.openwfm.org/wiki/WRF-Fire_user_support
! Current drafts of the technical documentation and
! user's guide can be found at
! http://www.openwfm.org/wiki/WRF-Fire_documentation
! http://www.openwfm.org/wiki/WRF-Fire_publications
! This module is the only entry point from WRF-ARW to the wildland
! fire model. The call to sfire_driver advances the fire model by
! one timestep. The fire model inputs the wind and outputs
! temperature and humidity tendencies. The fire model also inputs a
! number of constant arrays (fuel data, topography). Additional
! arguments are model state (for data assimilation) and constant arrays
! the model gives to WRF for safekeeping because it is not allowed
! to save anything.
! This code as of mid-2011 is described in [1]. If you use this code,
! please acknowledge our work by citing [1].
! Thank you.
! Acknowledgements
!
! The fire physics code is adapted from the CAWFE code [2].
! The coupling with WRF is adapted from a code by Ned Patton,
! coupling a Fortran 90 port of the CAWFE fire module to WRF [3].
! Support of refined fire grids in WRF was provided by John Michalakes.
! Jonathan D. Beezley has set up and maintained the WRF build and
! execution environment, provided software engineering infrastructure
! including synchronization with the WRF repository, and was responsibe
! for all aspects of WRF modification. UCD students Minjeong Kim and
! Volodymyr Kondratenko have contributed to the implementation of the
! fire propagation by the level set method.
! Refefences
!
! [1] Jan Mandel, Jonathan D. Beezley, and Adam K. Kochanski, "Coupled
! atmosphere-wildland fire modeling with WRF 3.3 and SFIRE 2011,
! Geoscientific Model Development (GMD) 4, 591-610, 2011.
! doi:10.5194/gmd-4-591-2011
!
! [2] T. L. Clark, J. Coen, and D. Latham, Description of a coupled
! atmosphere-fire model, Intl. J. Wildland Fire, vol. 13, pp. 49-64,
! 2004
!
! [3] Edward G. Patton and Janice L. Coen, WRF-Fire: A Coupled
! Atmosphere-Fire Module for WRF, Preprints of Joint MM5/Weather
! Research and Forecasting Model Users' Workshop, Boulder, CO,
! June 22-25, 2004, pp. 221-223, NCAR
!
! ---------------------------------------------
!
! CURRENT ACTIVITY
!
! For current activity and development trends please check out
! http://ccm.ucdenver.edu/wiki/User:Jmandel/blog
! http://www.openwfm.org/wiki/WRF-Fire_development_notes
!
module module_fr_sfire_driver
! use this module for standalone call, you only need to provide some mock-up wrf modules
use module_fr_sfire_model, only: sfire_model
use module_fr_sfire_phys, only: fire_params, init_fuel_cats, set_fp_from_grid, fuel_moisture, advance_moisture, init_fuel_cats
use module_fr_sfire_atm, only: apply_windrf,interpolate_wind2fire_height,interpolate_atm2fire, &
interpolate_z2fire,setup_wind_log_interpolation
use module_fr_sfire_util
use module_fr_sfire_core, only: ignition_type,fire_max_ignitions
USE module_domain, only: domain
USE module_configure, only: grid_config_rec_type
implicit none
private
public sfire_driver_em,use_atm_vars
logical:: use_atm_vars=.true. ! interpolate wind from atm mesh and average output fluxes back
contains
! to write debugging information
#define DEBUG_OUT
subroutine sfire_driver_em ( grid , config_flags &
,time_step_start,dt &
,fire_ifun_start,fire_ifun_end,tsteps &
,ids,ide, kds,kde, jds,jde &
,ims,ime, kms,kme, jms,jme &
,ips,ipe, kps,kpe, jps,jpe &
,ifds,ifde, jfds,jfde &
,ifms,ifme, jfms,jfme &
,ifps,ifpe, jfps,jfpe )
!*** purpose: driver from grid structure
! Driver layer modules
#ifdef DM_PARALLEL
USE module_dm , ONLY : ntasks_x,ntasks_y,local_communicator,mytask,ntasks
USE module_comm_dm , ONLY : halo_fire_fuel_sub, halo_fire_tign_sub, halo_fire_wind_f_sub, &
halo_fire_wind_a_sub, halo_fire_ph_sub, halo_fire_zsf_sub, halo_fire_longlat_sub, &
halo_fire_phb_sub, halo_fire_z0_sub, halo_fire_lfn_sub, HALO_FIRE_MAG_sub, HALO_FIRE_MFG_sub
#endif
implicit none
!*** arguments
TYPE(domain) , TARGET :: grid ! state
TYPE (grid_config_rec_type) , INTENT(IN) :: config_flags ! namelist
real, intent(in):: time_step_start, dt
integer, intent(in):: fire_ifun_start,fire_ifun_end,tsteps ! driver cycle controls
integer, intent(in):: &
ids,ide, kds,kde, jds,jde, &
ims,ime, kms,kme, jms,jme, &
ips,ipe, kps,kpe, jps,jpe, &
ifds,ifde, jfds,jfde, &
ifms,ifme, jfms,jfme, &
ifps,ifpe, jfps,jfpe
!*** local
TYPE(ignition_type):: ignition
integer::fire_ifun,ir,jr,istep,itimestep
logical::restart
real, dimension(ifms:ifme, jfms:jfme)::lfn_out
real:: corner_ll,corner_ul,corner_ur,corner_lr
character(len=128)msg
type(fire_params)::fp
logical:: run_moisture
real:: dt_moisture
!*** executable
call sfire_debug_hook
call time_start
if(fire_ifun_start.le.1)call print_id ! print id only once, during initialization
! populate our structures from wrf
call set_fp_from_grid(grid,fp)
! **** THE FOLLOWING REALLY SHOULD BE DONE ONCE NOT EVERY TIMESTEP
! get ignition data
call fire_ignition_convert (config_flags,ignition)
! copy configuration flags to sfire internal structures
call set_flags(config_flags)
! refinement r
ir=grid%sr_x ! refinement ratio
jr=grid%sr_y
itimestep=grid%itimestep
restart=config_flags%restart .or. config_flags%cycling .or. config_flags%fire_restart ! skip state initialization
! **** moisture model
! run moisture model this timestep?
run_moisture = .true. .or. config_flags%dynamic_fuel_moisture
dt_moisture = dt ! Time since moisture model run the last time. Should be long. ********* REPLACE *********
!$OMP CRITICAL(SFIRE_DRIVER_CRIT)
write(msg,'(a,i1,a,i1,a,l1)') &
'sfire_driver_em: ifun from ',fire_ifun_start,' to ',fire_ifun_end,' restart=',restart
!$OMP END CRITICAL(SFIRE_DRIVER_CRIT)
call message(msg)
do istep=0,tsteps ! istep >0 is for testing only, exit after the first call
itimestep = grid%itimestep + istep ! in the first call, do fire_test_steps steps of the fire model
do fire_ifun=fire_ifun_start,fire_ifun_end
! 1 = initialize run pass 1: interpolate height to zsf=terrain
! 2 = initialize run pass 2: set fuel data, terrain gradient
! 3 = initialize timestep: interpolate winds, check for ignition, time step on moisture model
! 4 = do one timestep
! 5 = copy timestep output to input
! 6 = compute output fluxes
#ifdef DM_PARALLEL
if(fire_ifun.eq.1)then
call init_fuel_cats ! also initializes the variables for the moisture model
! halo exchange on topography
#include "HALO_FIRE_LONGLAT.inc"
!! if(fire_topo_from_atm.eq.1)then
!!#include "HALO_FIRE_HT.inc"
!! endif
! base geopotential and roughness
#include "HALO_FIRE_PHB.inc"
#include "HALO_FIRE_Z0.inc"
elseif(fire_ifun.eq.2)then
! halo exchange on zsf width 2
#include "HALO_FIRE_ZSF.inc"
elseif(fire_ifun.eq.3)then
! halo exchange on atm winds and geopotential, width 1 for interpolation
#include "HALO_FIRE_WIND_A.inc"
#include "HALO_FIRE_PH.inc"
elseif(fire_ifun.eq.4)then
! halo exchange on fire winds width 2 for a 2-step RK method
#include "HALO_FIRE_WIND_F.inc"
if(run_moisture)then
! have interpolated to the fire grid, update coefficients
#include "HALO_FIRE_MFG.inc"
endif
elseif(fire_ifun.eq.6)then
! computing fuel_left needs ignition time from neighbors
#include "HALO_FIRE_TIGN.inc"
call message('halo exchange on lfn width 2')
#include "HALO_FIRE_LFN.inc"
endif
#endif
! print *,'dt: ',dt,grid%dt,' diff ', dt-grid%dt
! need domain by 1 smaller, in last row.col winds are not set properly
call sfire_driver_phys ( &
fire_ifun, &
ids,ide-1, kds,kde, jds,jde-1, &
ims,ime, kms,kme, jms,jme, &
ips,min(ipe,ide-1), kps,kpe, jps,min(jpe,jde-1), &
ifds,ifde-ir, jfds,jfde-jr, &
ifms,ifme, jfms,jfme, &
ifps,min(ifpe,ifde-ir), jfps,min(jfpe,jfde-jr), &
ir,jr, & ! atm/fire grid ratio
grid%num_tiles, & ! atm grid tiling
grid%i_start,min(grid%i_end,ide-1), &
grid%j_start,min(grid%j_end,jde-1), &
itimestep,restart,config_flags%fire_fuel_read,config_flags%fire_fuel_cat, & ! in scalars
time_step_start,dt,grid%dx,grid%dy, &
grid%u_frame,grid%v_frame, &
config_flags%fire_ext_grnd,config_flags%fire_ext_crwn,config_flags%fire_crwn_hgt, &
ignition, &
grid%u_2,grid%v_2, & ! atm arrays in
grid%ph_2,grid%phb, & ! geopotential
grid%z0, & ! roughness height
grid%ht, & ! terrain height
grid%xlong,grid%xlat, & ! coordinates of atm grid centers, for ignition location
grid%lfn,grid%tign_g,grid%fuel_frac, & ! state arrays, fire grid
grid%fire_area, & ! redundant, for display, fire grid
lfn_out, & ! work - one timestep
grid%avg_fuel_frac, & ! out redundant arrays, atm grid
grid%grnhfx,grid%grnqfx,grid%canhfx,grid%canqfx, & ! out redundant arrays, atm grid
grid%uah,grid%vah, &
grid%fgrnhfx,grid%fgrnqfx,grid%fcanhfx,grid%fcanqfx, & ! out redundant arrays, atm grid
grid%ros,grid%flineint,grid%flineint2, & ! diagnostic variables
grid%f_ros0,grid%f_rosx,grid%f_rosy,grid%f_ros,& ! fire risk spread
grid%f_int,grid%f_lineint,grid%f_lineint2, & ! fire risk intensities
grid%fxlong,grid%fxlat, &
grid%nfuel_cat, & ! input, or internal for safekeeping
grid%fuel_time, &
grid%fz0, grid%fwh, &
fp, & ! structure with pointers passed to spread rate calculation
config_flags%nfmc, & ! moisture model variables start
config_flags%initialize_fmc, &
run_moisture,dt_moisture, & ! moisture model control
grid%rainc, grid%rainnc, & ! accumulated rain from different sources
grid%t2, grid%q2, grid%psfc, & ! temperature (K), vapor contents (kg/kg), pressure (Pa) at the surface
grid%rain_old, & ! previous value of accumulated rain
grid%t2_old, grid%q2_old, grid%psfc_old, & ! previous values of the atmospheric state at surface
grid%fmc_gc, & ! fuel moisture fields updated, by class, assumed set to something reasonable
fp%fmc_g ) ! write-only alias. need to exit before using fp again
#ifdef DM_PARALLEL
if(fire_ifun.eq.2)then
! halo exchange on all fuel data width 2
#include "HALO_FIRE_FUEL.inc"
! fire state was initialized
call message('halo exchange on lfn width 2')
#include "HALO_FIRE_LFN.inc"
elseif(fire_ifun.eq.3)then
if(run_moisture)then
! moisture model has advanced, prepare for interpolation to the fire grid
#include "HALO_FIRE_MAG.inc"
endif
endif
#endif
enddo
enddo
if(tsteps>0)call crash('sfire_driver_em: test run of uncoupled fire model completed')
call time_end('sfire')
end subroutine sfire_driver_em
!
!*******************
!
subroutine sfire_driver_phys (ifun, &
ids,ide, kds,kde, jds,jde, & ! atm grid dimensions
ims,ime, kms,kme, jms,jme, &
ips,ipe, kps,kpe, jps,jpe, &
ifds, ifde, jfds, jfde, & ! fire grid dimensions
ifms, ifme, jfms, jfme, &
ifps, ifpe, jfps, jfpe, & ! fire patch in - will use smaller
ir,jr, & ! atm/fire grid ratio
num_tiles,i_start,i_end,j_start,j_end, & ! atm grid tiling
itimestep,restart,ifuelread,nfuel_cat0, & ! in scalars
time_step_start,dt,dx,dy, & ! in scalars
u_frame,v_frame, &
fire_ext_grnd,fire_ext_crwn,fire_crwn_hgt, &
ignition, &
u,v, & ! in arrays, atm grid
ph,phb, &
z0,zs, &
xlong,xlat, &
lfn,tign,fuel_frac, & ! state arrays, fire grid
fire_area, & ! redundant state, fire grid
lfn_out, & ! out level set function
avg_fuel_frac, &
grnhfx,grnqfx,canhfx,canqfx, & ! out redundant arrays, atm grid
uah,vah, & ! out atm grid
fgrnhfx,fgrnqfx,fcanhfx,fcanqfx, & ! out redundant arrays, fire grid
ros,flineint,flineint2, & ! diagnostic variables
f_ros0,f_rosx,f_rosy,f_ros, & ! fire risk spread
f_int,f_lineint,f_lineint2, & ! fire risk intensities
fxlong,fxlat, & !
nfuel_cat, & ! in array, data, fire grid, or constant internal
fuel_time, & ! save constant internal data, fire grid
fz0,fwh, &
fp, & ! fire params
nfmc, & ! number of fuel moisture classes
initialize_fmc, &
run_moisture,dt_moisture, & ! moisture model control
rainc,rainnc, & ! accumulated rain from different sources
t2, q2, psfc, & ! temperature (K), vapor contents (kg/kg), pressure (Pa) at the surface
rain_old, & ! previous value of accumulated rain
t2_old, q2_old, psfc_old, & ! previous values of the atmospheric state at surface
fmc_gc, & ! fuel moisture fields updated, by class, assumed set to something reasonable
fmc_g) ! fuel moisture, alias of fp%fmc_g
implicit none
!*** arguments
integer, intent(in)::ifun, &
ids,ide, kds,kde, jds,jde, & ! atm domain bounds
ims,ime, kms,kme, jms,jme, & ! atm memory bounds
ips,ipe, kps,kpe, jps,jpe, & ! atm patch bounds
ifds, ifde, jfds, jfde, & ! fire domain bounds
ifms, ifme, jfms, jfme, & ! fire memory bounds
ifps, ifpe, jfps, jfpe, & ! fire patch bounds
ir,jr, & ! atm/fire grid refinement ratio
nfmc, & ! number of fuel moisture classes
itimestep, & ! number of this timestep
ifuelread, & ! how to initialize nfuel_cat:
! -1=not at all, done outside
! 0=from nfuel_cat0
! 1=from altitude
! 2=from file
nfuel_cat0, & ! fuel category to initialize everything to
num_tiles ! number of tiles
logical, intent(in)::restart
integer,dimension(num_tiles),intent(in) :: i_start,i_end,j_start,j_end ! atm grid tiling
real, intent(in):: &
time_step_start, & ! time step start
dt, & ! time step length
dx,dy, & ! atm grid step
u_frame,v_frame, & ! velocity offset
fire_crwn_hgt, & ! lowest height crown fire heat is released (m)
fire_ext_grnd, & ! extinction depth of ground fire heat (m)
fire_ext_crwn ! and for the canopy (m)
TYPE (ignition_type), intent(inout):: ignition
real,intent(in),dimension(ims:ime,kms:kme,jms:jme)::u,v, & ! wind velocity (m/s) (staggered atm grid)
ph, phb ! geopotential (w-points atm grid)
real,intent(in),dimension(ims:ime, jms:jme):: z0, & ! roughness height
zs ! terrain height
real,intent(out),dimension(ims:ime,jms:jme)::&
uah, & ! atm wind at fire_wind_height, diagnostics
vah ! atm wind at fire_wind_height, diagnostics
real, dimension(ims:ime, jms:jme), intent(inout)::xlong, xlat ! inout because of extension at bdry
real, intent(inout), dimension(ifms:ifme,jfms:jfme):: & ! fuel data; can be also set inside (cell based, fire grid)
fz0,fwh, &
nfuel_cat
real, intent(inout), dimension(ifms:ifme, jfms:jfme):: &
lfn,tign,fuel_frac, & ! state: level function, ign time, fuel left
lfn_out ! fire wind velocities
real, intent(out), dimension(ifms:ifme, jfms:jfme):: &
fire_area ! fraction of each cell burning
real, intent(out), dimension(ims:ime, jms:jme):: & ! redundant arrays, for display purposes only (atm grid)
avg_fuel_frac, & ! average fuel fraction
grnhfx, & ! heat flux from ground fire (W/m^2)
grnqfx, & ! moisture flux from ground fire (W/m^2)
canhfx, & ! heat flux from crown fire (W/m^2)
canqfx ! moisture flux from crown fire (W/m^2)
real, intent(out), dimension(ifms:ifme, jfms:jfme):: & ! redundant arrays, for display only, fire grid
fgrnhfx, & ! heat flux from ground fire (W/m^2)
fgrnqfx, & ! moisture flux from ground fire (W/m^2)
fcanhfx, & ! heat flux from crown fire (W/m^2)
fcanqfx, & ! moisture flux from crown fire (W/m^2)
ros,flineint,flineint2, & ! diagnostic variables
f_ros0,f_rosx,f_rosy,f_ros, & ! fire risk spread
f_int,f_lineint,f_lineint2 ! fire risk intensities
! moisture model arguments
logical, intent(in)::initialize_fmc,run_moisture
real, intent(in)::dt_moisture
real, intent(in), dimension(ims:ime,jms:jme):: t2, q2, psfc, rainc, rainnc
real, intent(inout), dimension(ims:ime,jms:jme):: t2_old, q2_old, psfc_old, rain_old
real, intent(inout), dimension(ims:ime,nfmc,jms:jme):: fmc_gc
real, intent(inout), dimension(ifms:ifme,jfms:jfme):: fmc_g
! ***** data (constant in time) *****
real, dimension(ifms:ifme, jfms:jfme), intent(inout)::fxlong,fxlat ! fire mesh coordinates
real, intent(out), dimension(ifms:ifme, jfms:jfme)::fuel_time ! fire params arrays
type(fire_params),intent(inout)::fp
!*** local
real :: dxf,dyf,time_start,latm, s
integer :: its,ite,jts,jte,kts,kte, & ! tile
ij,i,j,k,id,pid,ipe1,jpe1,ite1,jte1, &
ii,jj, &
ifts,ifte,jfts,jfte ! fire tile
character(len=128)::msg
character(len=3)::kk
!*** executable
! time - assume dt does not change
! time_start = (itimestep-1) * dt ! timestep 1 starts at 0
! print *,'time_start: ',time_start,time_step_start,' diff ', time_start-time_step_start
time_start = time_step_start ! use the time passed from wrf
! fire mesh step
dxf=dx/ir
dyf=dy/jr
!$OMP CRITICAL(SFIRE_DRIVER_CRIT)
write(msg,'(a,i5)')'sfire_driver_phys stage ',ifun
call message(msg)
write(msg,'(a,2f15.6)')'atmosphere mesh step:',dx,dy
call message(msg)
write(msg,'(a,2f15.6)')'fire mesh step: ',dxf,dyf
call message(msg)
write(msg,7001)'atm domain ','ids',ids,ide,jds,jde
call message(msg)
write(msg,7001)'atm memory ','ims',ims,ime,jms,jme
call message(msg)
write(msg,7001)'atm patch ','ips',ips,ipe,jps,jpe
call message(msg)
write(msg,7001)'fire domain ','ifds',ifds,ifde,jfds,jfde
call message(msg)
write(msg,7001)'fire memory ','ifms',ifms,ifme,jfms,jfme
call message(msg)
write(msg,7001)'fire patch ','ifps',ifps,ifpe,jfps,jfpe
call message(msg)
!$OMP END CRITICAL(SFIRE_DRIVER_CRIT)
! check mesh dimensions
call check_fmesh(ids,ide,ifds,ifde,ir,'id') ! check if atm and fire grids line up
call check_fmesh(jds,jde,jfds,jfde,jr,'jd')
call check_fmesh(ips,ipe,ifps,ifpe,ir,'ip')
call check_fmesh(jps,jpe,jfps,jfpe,jr,'jp')
call check_mesh_2dim(ips,ipe,jps,jpe,ims,ime,jms,jme) ! check if atm patch fits in atm array
call check_mesh_2dim(ifps,ifpe,jfps,jfpe,ifms,ifme,jfms,jfme) ! check if fire patch fits in fire array
call check_mesh_2dim(ips,ipe,jps,jpe,ids,ide,jds,jde) ! check if atm patch fits in atm domain
call check_mesh_2dim(ifps,ifpe,jfps,jfpe,ifds,ifde,jfds,jfde) ! check if fire patch fits in fire domain
pid=0
if(fire_print_file.gt.0)then
if(itimestep.le.fire_print_file.or.mod(itimestep,fire_print_file).eq.0)pid=itimestep ! print 1-fire_print_file then every fire_print_file-th
endif
if(ifun.eq.3)then
call print_chsum(itimestep,ims,ime,kms,kme,jms,jme,ids,ide,kds,kde,jds,jde,ips,ipe,kps,kpe,jps,jpe,1,0,0,u,'u')
call print_chsum(itimestep,ims,ime,kms,kme,jms,jme,ids,ide,kds,kde,jds,jde,ips,ipe,kps,kpe,jps,jpe,0,0,1,v,'v')
call print_chsum(itimestep,ims,ime,kms,kme,jms,jme,ids,ide,kds,kde,jds,jde,ips,ipe,kps,kpe,jps,jpe,0,1,0,ph,'ph')
endif
! fake atm tile bounds
kts=kps
kte=kpe
! staggered atm patch bounds
ipe1=ifval(ipe.eq.ide,ipe+1,ipe)
jpe1=ifval(jpe.eq.jde,jpe+1,jpe)
! set up fire tiles & interpolate to fire grid
!$OMP PARALLEL DO PRIVATE(ij,its,ite,jts,jte,ite1,jte1,ifts,ifte,jfts,jfte,msg,id) &
!$OMP SCHEDULE(STATIC)
do ij=1,num_tiles
id = ifval(pid.ne.0,pid+ij*10000,0) ! for print
! set up tile bounds
its = i_start(ij) ! start atmospheric tile in i
ite = i_end(ij) ! end atmospheric tile in i
jts = j_start(ij) ! start atmospheric tile in j
jte = j_end(ij) ! end atmospheric tile in j
ifts= (its-ids)*ir+ifds ! start fire tile in i
ifte= (ite-ids+1)*ir+ifds-1 ! end fire tile in i
jfts= (jts-jds)*jr+jfds ! start fire tile in j
jfte= (jte-jds+1)*jr+jfds-1 ! end fire tile in j
! staggered atm tile bounds
ite1=ifval(ite.eq.ide,ite+1,ite)
jte1=ifval(jte.eq.jde,jte+1,jte)
!$OMP CRITICAL(SFIRE_DRIVER_CRIT)
write(msg,'(a,i3,1x,a,i7,1x,a,i3)')'tile=',ij,' id=',id,' ifun=',ifun
call message(msg)
write(msg,7001)'atm tile ','its',its,ite,jts,jte
call message(msg)
write(msg,7001)'fire tile ','ifts',ifts,ifte,jfts,jfte
call message(msg)
!$OMP END CRITICAL(SFIRE_DRIVER_CRIT)
! check the tiles
call check_mesh_2dim(its,ite,jts,jte,ips,ipe,jps,jpe) ! check if atm tile fits in atm patch
call check_mesh_2dim(ifts,ifte,jfts,jfte,ifps,ifpe,jfps,jfpe) ! check if fire tile fits in fire patch
call check_mesh_2dim(ifts-2,ifte+2,jfts-2,jfte+2,ifms,ifme,jfms,jfme)! check if fire node tile fits in memory
!$OMP CRITICAL(SFIRE_DRIVER_CRIT)
write(msg,'(a,i6,a,2(f15.6,a))')'time step',itimestep,' at',time_start,' duration',dt,'s'
call message(msg)
7001 format(a,' dimensions ',a4,':',i6,' to ',i6,' by ',i6,' to ',i6)
write(msg,'(a,2i9)')'refinement ratio:',ir,jr
!$OMP END CRITICAL(SFIRE_DRIVER_CRIT)
if(ifun.eq.1)then ! set terrain
if(restart)then
call message('restart - topo initialization skipped')
else
!
! call print_2d_stats(ips,ipe,jps,jpe,ims,ime,jms,jme,zs,'driver:zs')
!
! ! interpolate terrain height
! if(fire_topo_from_atm.eq.1)then
! call interpolate_z2fire(id, & ! for debug output, <= 0 no output
! ids,ide, jds,jde, & ! atm grid dimensions
! ims,ime, jms,jme, &
! ips,ipe,jps,jpe, &
! its,ite,jts,jte, &
! ifds, ifde, jfds, jfde, & ! fire grid dimensions
! ifms, ifme, jfms, jfme, &
! ifts,ifte,jfts,jfte, &
! ir,jr, & ! atm/fire grid ratio
! zs, & ! atm grid arrays in
! fp%zsf) ! fire grid arrays out
! else
!!$OMP CRITICAL(SFIRE_DRIVER_CRIT)
! write(msg,'(a,i3,a)')'fire_topo_from_atm=',fire_topo_from_atm,' assuming ZSF set, interpolation skipped'
!!$OMP END CRITICAL(SFIRE_DRIVER_CRIT)
! endif
if(ignition%longlat .eq.0)then
! set ideal fire mesh coordinates - used for ignition only
! do not forget to set unit_fxlong, unit_fxlat outside of parallel loop
!call set_ideal_coord( dxf,dyf, &
! ifds,ifde,jfds,jfde, &
! ifms,ifme,jfms,jfme, &
! ifts,ifte,jfts,jfte, &
! fxlong,fxlat )
!call set_ideal_coord( dx,dy, &
! ids,ide,jds,jde, &
! ims,ime,jms,jme, &
! its,ite,jts,jte, &
! xlong,xlat )
elseif(use_atm_vars)then
! assume halo xlong xlat
! interpolate nodal coordinates
#ifdef DEBUG_OUT
call write_array_m(its,ite,jts,jte,ims,ime,jms,jme,xlat,'xlat',id)
call write_array_m(its,ite,jts,jte,ims,ime,jms,jme,xlong,'xlong',id)
#endif
call interpolate_z2fire(id, & ! for debug output, <= 0 no output
ids,ide, jds,jde, & ! atm grid dimensions
ims,ime, jms,jme, &
ips,ipe,jps,jpe, &
its,ite,jts,jte, &
ifds, ifde, jfds, jfde, & ! fire grid dimensions
ifms, ifme, jfms, jfme, &
ifts,ifte,jfts,jfte, &
ir,jr, & ! atm/fire grid ratio
xlat, & ! atm grid arrays in
fxlat) ! fire grid arrays out
call interpolate_z2fire(id, & ! for debug output, <= 0 no output
ids,ide, jds,jde, & ! atm grid dimensions
ims,ime, jms,jme, &
ips,ipe,jps,jpe, &
its,ite,jts,jte, &
ifds, ifde, jfds, jfde, & ! fire grid dimensions
ifms, ifme, jfms, jfme, &
ifts,ifte,jfts,jfte, &
ir,jr, & ! atm/fire grid ratio
xlong, & ! atm grid arrays in
fxlong) ! fire grid arrays out
endif
endif
elseif(ifun.eq.2)then
! after the loop where zsf created exited and all synced
call print_2d_stats(ifts,ifte,jfts,jfte,ifms,ifme,jfms,jfme,fp%zsf,'driver_phys:zsf')
! initialize the moisture model
call advance_moisture( &
.true., & ! initialize timestepping
initialize_fmc, & ! if true, set initial moisture to fuelmc_g
ims,ime, jms,jme, & ! memory dimensions
its,ite, jts,jte, & ! tile dimensions
nfmc, & ! number of moisture fields
dt_moisture, & ! moisture model time step
rainc, rainnc, & ! accumulated rain
t2, q2, psfc, & ! temperature (K), vapor contents (kg/kg), pressure (Pa) at the surface
rain_old, & ! previous value of accumulated rain
t2_old, q2_old, psfc_old, & ! previous values of the atmospheric state at surface
fmc_gc & ! fuel moisture fields updated, by class, assumed set to something reasonable
)
elseif(ifun.eq.3)then ! interpolate winds to the fire grid
if(use_atm_vars)then
call write_array_m(its,ite,jts,jte,ims,ime,jms,jme,z0,'z0',id)
call write_array_m3(its,ite1,kts,kde-1,jts,jte,ims,ime,kms,kme,jms,jme,u,'u_2',id)
call write_array_m3(its,ite,kts,kde-1,jts,jte1,ims,ime,kms,kme,jms,jme,v,'v_2',id)
call write_array_m3(its,ite,kts,kde,jts,jte,ims,ime,kms,kme,jms,jme,ph,'ph_2',id)
call write_array_m3(its,ite,kts,kde,jts,jte,ims,ime,kms,kme,jms,jme,phb,'phb',id)
if(fire_wind_log_interp.eq.4)then
call print_2d_stats(its,ite,jts,jte,ims,ime,jms,jme,z0,'driver_phys:z0')
call interpolate_atm2fire(id, & ! flag for debug output
ids,ide, kds,kde, jds,jde, & ! atm grid dimensions
ims,ime, kms,kme, jms,jme, &
ips,ipe, jps,jpe, &
its,ite,jts,jte, &
ifds, ifde, jfds, jfde, & ! fire grid dimensions
ifms, ifme, jfms, jfme, &
ifps, ifpe, jfps, jfpe, & ! fire patch bounds
ifts, ifte, jfts, jfte, &
ir,jr, & ! atm/fire grid ratio
u_frame, v_frame, & ! velocity frame correction
u,v, & ! 3D atm grid arrays in
ph,phb, &
z0,zs, & ! 2D atm grid arrays in
uah,vah, & ! 2D atm grid out
fp%vx,fp%vy) ! fire grid arrays out
call apply_windrf( &
ifms,ifme,jfms,jfme, &
ifts,ifte,jfts,jfte, &
nfuel_cat,fp%vx,fp%vy)
else
call print_2d_stats(ifts,ifte,jfts,jfte,ifms,ifme,jfms,jfme,fz0,'driver_phys:fz0')
call interpolate_wind2fire_height(id, & ! to identify debugging prints and files if needed
ids,ide, kds,kde, jds,jde, & ! atm grid dimensions
ims,ime, kms,kme, jms,jme, &
ips,ipe,jps,jpe, &
its,ite,jts,jte, &
ifds, ifde, jfds, jfde, & ! fire grid dimensions
ifms, ifme, jfms, jfme, &
ifps, ifpe, jfps, jfpe, & ! fire patch bounds
ifts,ifte,jfts,jfte, &
ir,jr, & ! atm/fire grid ratio
u_frame, v_frame, & ! velocity frame correction
u,v,ph,phb, & ! input atmospheric arrays
fz0,fwh, & ! input fire arrays
fp%vx,fp%vy) ! output fire arrays
if(fire_use_windrf.eq.1)then
call apply_windrf( &
ifms,ifme,jfms,jfme, &
ifts,ifte,jfts,jfte, &
nfuel_cat,fp%vx,fp%vy)
endif
endif
endif
! still with ifun=3
! one timestep of the moisture model
call advance_moisture( &
.false., &
.false., &
ims,ime, jms,jme, & ! memory dimensions
its,ite, jts,jte, & ! tile dimensions
nfmc, & ! number of moisture fields
dt_moisture, & ! moisture model time step
rainc, rainnc, & ! accumulated rain
t2, q2, psfc, & ! temperature (K), vapor contents (kg/kg), pressure (Pa) at the surface
rain_old, & ! previous value of accumulated rain
t2_old, q2_old, psfc_old, & ! previous values of the atmospheric state at surface
fmc_gc & ! fuel moisture fields updated, by class, assumed set to something reasonable
)
elseif(ifun.eq.4)then
! interpolate and compute weighted average to get the fuel moisture
call fuel_moisture( &
id, & ! for prints and maybe file names
nfmc, &
ids,ide, jds,jde, & ! atm grid dimensions
ims,ime, jms,jme, &
ips,ipe,jps,jpe, &
its,ite,jts,jte, &
ifds, ifde, jfds, jfde, & ! fire grid dimensions
ifms, ifme, jfms, jfme, &
ifts,ifte,jfts,jfte, &
ir,jr, & ! atm/fire grid ratio
nfuel_cat, & ! fuel data
fmc_gc, & ! moisture contents by class on atmospheric grid
fmc_g & ! weighted fuel moisture contents on fire grid
)
endif
! the following executes in any case
call print_chsum(itimestep,ifms,ifme,1,1,jfms,jfme,ifds,ifde,1,1,jfds,jfde,ifps,ifpe,1,1,jfps,jfpe,0,0,0,lfn,'lfn')
call print_chsum(itimestep,ifms,ifme,1,1,jfms,jfme,ifds,ifde,1,1,jfds,jfde,ifps,ifpe,1,1,jfps,jfpe,0,0,0,tign,'tign')
call sfire_model (id,ifun,restart, &
ifuelread,nfuel_cat0, & ! initialize fuel categories
ifds,ifde,jfds,jfde, & ! fire domain dims
ifms,ifme,jfms,jfme, & ! fire memory dims
ifps,ifpe,jfps,jfpe, &
ifts,ifte,jfts,jfte, & ! fire patch dims
time_start,dt, & ! time and increment
dxf,dyf, & ! fire mesh spacing
ignition, & ! description of ignition lines
fxlong,fxlat, & ! fire mesh coordinates
lfn,lfn_out,tign,fuel_frac, & ! state: level function, ign time, fuel left
fire_area, & ! output: fraction of cell burning
fgrnhfx,fgrnqfx, & ! output: heat fluxes
ros,flineint,flineint2, & ! diagnostic variables
f_ros0,f_rosx,f_rosy,f_ros, & ! fire risk spread
f_int,f_lineint,f_lineint2, & ! fire risk intensities
nfuel_cat, & ! fuel data per point
fuel_time,fwh,fz0, & ! save derived internal data
fp & ! fire coefficients
)
if(ifun.eq.2)then
call setup_wind_log_interpolation( &
ids,ide, jds,jde, & ! atm grid dimensions
ims,ime, jms,jme, &
ips,ipe,jps,jpe, &
its,ite,jts,jte, &
ifds, ifde, jfds, jfde, & ! fire grid dimensions
ifms, ifme, jfms, jfme, &
ifts,ifte,jfts,jfte, &
ir,jr, & ! atm/fire grid ratio
z0, & ! atm grid arrays in
nfuel_cat, & ! fuel data per point
fz0,fwh) ! fire arrays out
elseif(ifun.eq.6)then ! heat fluxes into the atmosphere
call print_2d_stats(ifts,ifte,jfts,jfte,ifms,ifme,jfms,jfme,fgrnhfx,'fire_driver:fgrnhfx')
call print_2d_stats(ifts,ifte,jfts,jfte,ifms,ifme,jfms,jfme,fgrnqfx,'fire_driver:fgrnqfx')
! sum the fluxes over atm cells
if(use_atm_vars)then
call sum_2d_cells( &
ifms,ifme,jfms,jfme, &
ifts,ifte,jfts,jfte, &
fuel_frac, &
ims, ime, jms, jme, &
its,ite,jts,jte, &
avg_fuel_frac)
call sum_2d_cells( &
ifms,ifme,jfms,jfme, &
ifts,ifte,jfts,jfte, &
fgrnhfx, &
ims, ime, jms, jme, &
its,ite,jts,jte, &
grnhfx)
!comment out the next call to get results as before commit 55fd92051196b796891b60cb7ec1c4bdb8800078
call sum_2d_cells( &
ifms,ifme,jfms,jfme, &
ifts,ifte,jfts,jfte, &
fgrnqfx, &
ims, ime, jms, jme, &
its,ite,jts,jte, &
grnqfx)
!$OMP CRITICAL(SFIRE_DRIVER_CRIT)
write(msg,'(a,f6.3)')'fire-atmosphere feedback scaling ',fire_atm_feedback
!$OMP end CRITICAL(SFIRE_DRIVER_CRIT)
call message(msg)
s = 1./(ir*jr)
do j=jts,jte
do i=its,ite
! scale ground fluxes to get the averages
avg_fuel_frac(i,j)=avg_fuel_frac(i,j)*s
grnhfx(i,j)=fire_atm_feedback*grnhfx(i,j)*s
grnqfx(i,j)=fire_atm_feedback*grnqfx(i,j)*s
! we do not have canopy fluxes yet...
canhfx(i,j)=0
canqfx(i,j)=0
enddo
enddo
call print_2d_stats(its,ite,jts,jte,ims,ime,jms,jme,grnhfx,'fire_driver:grnhfx')
call print_2d_stats(its,ite,jts,jte,ims,ime,jms,jme,grnqfx,'fire_driver:grnqfx')
endif
endif ! ifun=6
enddo ! tiles
!$OMP END PARALLEL DO
#ifdef DEBUG_OUT
if(ifun.eq.1)then
if(pid.ne.0)then
call write_array_m(ips,ipe,jps,jpe,ims,ime,jms,jme,zs,'zs',pid)
call write_array_m(ifps,ifpe,jfps,jfpe,ifms,ifme,jfms,jfme,fp%zsf,'zsf',pid)
endif
endif
#endif
if (ifun.eq.4)then
!call print_chsum(itimestep,ims,ime,1,1,jms,jme,ids,ide,1,1,jds,jde,ips,ipe,1,1,jps,jpe,1,0,0,uah,'uah')
!call print_chsum(itimestep,ims,ime,1,1,jms,jme,ids,ide,1,1,jds,jde,ips,ipe,1,1,jps,jpe,0,0,1,vah,'vah')
call print_chsum(itimestep,ifms,ifme,1,1,jfms,jfme,ifds,ifde,1,1,jfds,jfde,ifps,ifpe,1,1,jfps,jfpe,0,0,0,fp%vx,'uf')
call print_chsum(itimestep,ifms,ifme,1,1,jfms,jfme,ifds,ifde,1,1,jfds,jfde,ifps,ifpe,1,1,jfps,jfpe,0,0,0,fp%vy,'vf')
call print_chsum(itimestep,ifms,ifme,1,1,jfms,jfme,ifds,ifde,1,1,jfds,jfde,ifps,ifpe,1,1,jfps,jfpe,0,0,0,lfn,'lfn')
call print_chsum(itimestep,ifms,ifme,1,1,jfms,jfme,ifds,ifde,1,1,jfds,jfde,ifps,ifpe,1,1,jfps,jfpe,0,0,0,tign,'tign')
#ifdef DEBUG_OUT
if(pid.gt.0)then
! call write_array_m(ips,ipe1,jps,jpe,ims,ime,jms,jme,uah,'uah',pid)
! call write_array_m(ips,ipe,jps,jpe1,ims,ime,jms,jme,vah,'vah',pid)
call write_array_m(ips,ipe,jps,jpe,ims,ime,jms,jme,grnhfx,'grnhfx',pid)
call write_array_m(ips,ipe,jps,jpe,ims,ime,jms,jme,grnqfx,'grnqfx',pid)
call write_array_m3(ips,ipe1,kds,kde+1,jps,jpe,ims,ime,kms,kme,jms,jme,u,'u',pid)
call write_array_m3(ips,ipe,kds,kde+1,jps,jpe1,ims,ime,kms,kme,jms,jme,v,'v',pid)
call write_array_m(ifps,ifpe,jfps,jfpe,ifms,ifme,jfms,jfme,fp%vx,'uf',pid)
call write_array_m(ifps,ifpe,jfps,jfpe,ifms,ifme,jfms,jfme,fp%vy,'vf',pid)
endif
#endif
endif
if(ifun.eq.5)then
#ifdef DEBUG_OUT
if(pid.gt.0)then
call write_array_m(ifps,ifpe,jfps,jfpe,ifms,ifme,jfms,jfme,lfn,'lfn',pid)
call write_array_m(ifps,ifpe,jfps,jfpe,ifms,ifme,jfms,jfme,tign,'tign',pid)
endif
#endif
endif
if(ifun.eq.6)then
call print_chsum(itimestep,ifms,ifme,1,1,jfms,jfme,ifds,ifde,1,1,jfds,jfde,ifps,ifpe,1,1,jfps,jfpe,0,0,0,fgrnhfx,'fgrnhfx')
call print_chsum(itimestep,ifms,ifme,1,1,jfms,jfme,ifds,ifde,1,1,jfds,jfde,ifps,ifpe,1,1,jfps,jfpe,0,0,0,fgrnqfx,'fgrnqfx')
call print_chsum(itimestep,ims,ime,1,1,jms,jme,ids,ide,1,1,jds,jde,ips,ipe,1,1,jps,jpe,0,0,0,grnhfx,'grnhfx')
call print_chsum(itimestep,ims,ime,1,1,jms,jme,ids,ide,1,1,jds,jde,ips,ipe,1,1,jps,jpe,0,0,0,grnqfx,'grnqfx')
#ifdef DEBUG_OUT
if(pid.gt.0)then
call write_array_m(ips,ipe,jps,jpe,ims,ime,jms,jme,grnhfx,'grnhfx',pid)
call write_array_m(ips,ipe,jps,jpe,ims,ime,jms,jme,grnqfx,'grnqfx',pid)
call write_array_m(ifps,ifpe,jfps,jfpe,ifms,ifme,jfms,jfme,fuel_frac,'fuel_frac',pid)
call write_array_m(ifps,ifpe,jfps,jfpe,ifms,ifme,jfms,jfme,fgrnhfx,'fgrnhfx',pid)
call write_array_m(ifps,ifpe,jfps,jfpe,ifms,ifme,jfms,jfme,fgrnqfx,'fgrnqfx',pid)
endif
#endif
endif
end subroutine sfire_driver_phys
!
!***
!
subroutine check_fmesh(ids,ide,ifds,ifde,ir,s)
!*** purpose: check if fire and atm meshes line up
implicit none
!*** arguments
integer, intent(in)::ids,ide,ifds,ifde,ir
character(len=*),intent(in)::s
!*** local
character(len=128)msg
!*** executable
if ((ide-ids+1)*ir.ne.(ifde-ifds+1))then
!$OMP CRITICAL(SFIRE_DRIVER_CRIT)
write(msg,1)s,ids,ide,ifds,ifde,ir
1 format('module_fr_sfire_driver: incompatible bounds ',a,' atm ',i5,':',i5,' fire ',i5,':',i5,' ratio ',i3)
!$OMP END CRITICAL(SFIRE_DRIVER_CRIT)
call crash(msg)
endif
end subroutine check_fmesh
subroutine print_id
character(len=128)::id,msg
#include "sfire_id.inc"
msg=id
call message(msg,level=1)
end subroutine print_id
end module module_fr_sfire_driver