-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathphyspkg.F90
2398 lines (1947 loc) · 92.8 KB
/
physpkg.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
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
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
module physpkg
!-----------------------------------------------------------------------
! Purpose:
!
! Provides the interface to CAM physics package
!
! Revision history:
! Aug 2005, E. B. Kluzek, Creation of module from physpkg subroutine
! 2005-10-17 B. Eaton Add contents of inti.F90 to phys_init(). Add
! initialization of grid info in phys_state.
! Nov 2010 A. Gettelman Put micro/macro physics into separate routines
!-----------------------------------------------------------------------
use shr_kind_mod, only: r8 => shr_kind_r8
use spmd_utils, only: masterproc
use physconst, only: latvap, latice, rh2o
use physics_types, only: physics_state, physics_tend, physics_state_set_grid, &
physics_ptend, physics_tend_init, physics_update, &
physics_type_alloc, physics_ptend_dealloc,&
physics_state_alloc, physics_state_dealloc, physics_tend_alloc, physics_tend_dealloc
use phys_grid, only: get_ncols_p
use phys_gmean, only: gmean_mass
use ppgrid, only: begchunk, endchunk, pcols, pver, pverp, psubcols
use constituents, only: pcnst, cnst_name, cnst_get_ind
use camsrfexch, only: cam_out_t, cam_in_t
use cam_control_mod, only: ideal_phys, adiabatic
use phys_control, only: phys_do_flux_avg, phys_getopts, waccmx_is
use scamMod, only: single_column, scm_crm_mode
use flux_avg, only: flux_avg_init
use perf_mod
use cam_logfile, only: iulog
use camsrfexch, only: cam_export
use modal_aero_calcsize, only: modal_aero_calcsize_init, modal_aero_calcsize_diag, modal_aero_calcsize_reg
use modal_aero_wateruptake, only: modal_aero_wateruptake_init, modal_aero_wateruptake_dr, modal_aero_wateruptake_reg
implicit none
private
save
! Public methods
public phys_register ! was initindx - register physics methods
public phys_init ! Public initialization method
public phys_run1 ! First phase of the public run method
public phys_run2 ! Second phase of the public run method
public phys_final ! Public finalization method
! Private module data
! Physics package options
character(len=16) :: shallow_scheme
character(len=16) :: macrop_scheme
character(len=16) :: microp_scheme
integer :: cld_macmic_num_steps ! Number of macro/micro substeps
logical :: do_clubb_sgs
logical :: use_subcol_microp ! if true, use subcolumns in microphysics
logical :: state_debug_checks ! Debug physics_state.
logical :: clim_modal_aero ! climate controled by prognostic or prescribed modal aerosols
logical :: prog_modal_aero ! Prognostic modal aerosols present
! Physics buffer index
integer :: teout_idx = 0
integer :: landm_idx = 0
integer :: sgh_idx = 0
integer :: sgh30_idx = 0
integer :: qini_idx = 0
integer :: cldliqini_idx = 0
integer :: cldiceini_idx = 0
integer :: prec_str_idx = 0
integer :: snow_str_idx = 0
integer :: prec_sed_idx = 0
integer :: snow_sed_idx = 0
integer :: prec_pcw_idx = 0
integer :: snow_pcw_idx = 0
integer :: prec_dp_idx = 0
integer :: snow_dp_idx = 0
integer :: prec_sh_idx = 0
integer :: snow_sh_idx = 0
integer :: dlfzm_idx = 0 ! detrained convective cloud water mixing ratio.
!=======================================================================
contains
!=======================================================================
subroutine phys_register
!-----------------------------------------------------------------------
!
! Purpose: Register constituents and physics buffer fields.
!
! Author: CSM Contact: M. Vertenstein, Aug. 1997
! B.A. Boville, Oct 2001
! A. Gettelman, Nov 2010 - put micro/macro physics into separate routines
!
!-----------------------------------------------------------------------
use cam_abortutils, only: endrun
use physics_buffer, only: pbuf_init_time
use physics_buffer, only: pbuf_add_field, dtype_r8, pbuf_register_subcol
use shr_kind_mod, only: r8 => shr_kind_r8
use spmd_utils, only: masterproc
use constituents, only: pcnst, cnst_add, cnst_chk_dim, cnst_name
use cam_control_mod, only: moist_physics
use chemistry, only: chem_register
use cloud_fraction, only: cldfrc_register
use rk_stratiform, only: rk_stratiform_register
use microp_driver, only: microp_driver_register
use microp_aero, only: microp_aero_register
use macrop_driver, only: macrop_driver_register
use clubb_intr, only: clubb_register_cam
use conv_water, only: conv_water_register
use physconst, only: mwdry, cpair, mwh2o, cpwv
use tracers, only: tracers_register
use check_energy, only: check_energy_register
use carma_intr, only: carma_register
use cam3_aero_data, only: cam3_aero_data_on, cam3_aero_data_register
use cam3_ozone_data, only: cam3_ozone_data_on, cam3_ozone_data_register
use ghg_data, only: ghg_data_register
use vertical_diffusion, only: vd_register
use convect_deep, only: convect_deep_register
use convect_shallow, only: convect_shallow_register
use radiation, only: radiation_register
use co2_cycle, only: co2_register
use flux_avg, only: flux_avg_register
use iondrag, only: iondrag_register
use waccmx_phys_intr, only: waccmx_phys_ion_elec_temp_reg
use string_utils, only: to_lower
use prescribed_ozone, only: prescribed_ozone_register
use prescribed_volcaero,only: prescribed_volcaero_register
use prescribed_strataero,only: prescribed_strataero_register
use prescribed_aero, only: prescribed_aero_register
use prescribed_ghg, only: prescribed_ghg_register
use sslt_rebin, only: sslt_rebin_register
use aoa_tracers, only: aoa_tracers_register
use aircraft_emit, only: aircraft_emit_register
use cam_diagnostics, only: diag_register
use cloud_diagnostics, only: cloud_diagnostics_register
use cospsimulator_intr, only: cospsimulator_intr_register
use rad_constituents, only: rad_cnst_get_info ! Added to query if it is a modal aero sim or not
use subcol, only: subcol_register
use subcol_utils, only: is_subcol_on
use dyn_comp, only: dyn_register
use spcam_drivers, only: spcam_register
use offline_driver, only: offline_driver_reg
!---------------------------Local variables-----------------------------
!
integer :: m ! loop index
integer :: mm ! constituent index
integer :: nmodes
!-----------------------------------------------------------------------
! Get physics options
call phys_getopts(shallow_scheme_out = shallow_scheme, &
macrop_scheme_out = macrop_scheme, &
microp_scheme_out = microp_scheme, &
cld_macmic_num_steps_out = cld_macmic_num_steps, &
do_clubb_sgs_out = do_clubb_sgs, &
use_subcol_microp_out = use_subcol_microp, &
state_debug_checks_out = state_debug_checks)
! Initialize dyn_time_lvls
call pbuf_init_time()
! Register the subcol scheme
call subcol_register()
! Register water vapor.
! ***** N.B. ***** This must be the first call to cnst_add so that
! water vapor is constituent 1.
if (moist_physics) then
call cnst_add('Q', mwh2o, cpwv, 1.E-12_r8, mm, &
longname='Specific humidity', readiv=.true., is_convtran1=.true.)
else
call cnst_add('Q', mwh2o, cpwv, 0.0_r8, mm, &
longname='Specific humidity', readiv=.false., is_convtran1=.true.)
end if
! Topography file fields.
call pbuf_add_field('LANDM', 'global', dtype_r8, (/pcols/), landm_idx)
call pbuf_add_field('SGH', 'global', dtype_r8, (/pcols/), sgh_idx)
call pbuf_add_field('SGH30', 'global', dtype_r8, (/pcols/), sgh30_idx)
! Fields for physics package diagnostics
call pbuf_add_field('QINI', 'physpkg', dtype_r8, (/pcols,pver/), qini_idx)
call pbuf_add_field('CLDLIQINI', 'physpkg', dtype_r8, (/pcols,pver/), cldliqini_idx)
call pbuf_add_field('CLDICEINI', 'physpkg', dtype_r8, (/pcols,pver/), cldiceini_idx)
! check energy package
call check_energy_register
! If using a simple physics option (e.g., held_suarez, adiabatic),
! the normal CAM physics parameterizations are not called.
if (moist_physics) then
! register fluxes for saving across time
if (phys_do_flux_avg()) call flux_avg_register()
call cldfrc_register()
! cloud water
if( microp_scheme == 'RK' ) then
call rk_stratiform_register()
elseif( microp_scheme == 'MG' ) then
if (.not. do_clubb_sgs) call macrop_driver_register()
call microp_aero_register()
call microp_driver_register()
end if
! Register CLUBB_SGS here
if (do_clubb_sgs) call clubb_register_cam()
call pbuf_add_field('PREC_STR', 'physpkg',dtype_r8,(/pcols/),prec_str_idx)
call pbuf_add_field('SNOW_STR', 'physpkg',dtype_r8,(/pcols/),snow_str_idx)
call pbuf_add_field('PREC_PCW', 'physpkg',dtype_r8,(/pcols/),prec_pcw_idx)
call pbuf_add_field('SNOW_PCW', 'physpkg',dtype_r8,(/pcols/),snow_pcw_idx)
call pbuf_add_field('PREC_SED', 'physpkg',dtype_r8,(/pcols/),prec_sed_idx)
call pbuf_add_field('SNOW_SED', 'physpkg',dtype_r8,(/pcols/),snow_sed_idx)
if (is_subcol_on()) then
call pbuf_register_subcol('PREC_STR', 'phys_register', prec_str_idx)
call pbuf_register_subcol('SNOW_STR', 'phys_register', snow_str_idx)
call pbuf_register_subcol('PREC_PCW', 'phys_register', prec_pcw_idx)
call pbuf_register_subcol('SNOW_PCW', 'phys_register', snow_pcw_idx)
call pbuf_register_subcol('PREC_SED', 'phys_register', prec_sed_idx)
call pbuf_register_subcol('SNOW_SED', 'phys_register', snow_sed_idx)
end if
! Who should add FRACIS?
! -- It does not seem that aero_intr should add it since FRACIS is used in convection
! even if there are no prognostic aerosols ... so do it here for now
call pbuf_add_field('FRACIS','physpkg',dtype_r8,(/pcols,pver,pcnst/),m)
call conv_water_register()
! Determine whether its a 'modal' aerosol simulation or not
call rad_cnst_get_info(0, nmodes=nmodes)
clim_modal_aero = (nmodes > 0)
if (clim_modal_aero) then
call modal_aero_calcsize_reg()
call modal_aero_wateruptake_reg()
endif
! register chemical constituents including aerosols ...
call chem_register()
! co2 constituents
call co2_register()
! register data model ozone with pbuf
if (cam3_ozone_data_on) then
call cam3_ozone_data_register()
end if
call prescribed_volcaero_register()
call prescribed_strataero_register()
call prescribed_ozone_register()
call prescribed_aero_register()
call prescribed_ghg_register()
call sslt_rebin_register
! CAM3 prescribed aerosols
if (cam3_aero_data_on) then
call cam3_aero_data_register()
end if
! register various data model gasses with pbuf
call ghg_data_register()
! carma microphysics
!
call carma_register()
! Register iondrag variables with pbuf
call iondrag_register()
! Register ionosphere variables with pbuf if mode set to ionosphere
if( waccmx_is('ionosphere') ) then
call waccmx_phys_ion_elec_temp_reg()
endif
call aircraft_emit_register()
! deep convection
call convect_deep_register
! shallow convection
call convect_shallow_register
call spcam_register
! radiation
call radiation_register
call cloud_diagnostics_register
! COSP
call cospsimulator_intr_register
! vertical diffusion
call vd_register()
else
! held_suarez/adiabatic physics option should be in simple_physics
call endrun('phys_register: moist_physics configuration error')
end if
! Register diagnostics PBUF
call diag_register()
! Register age of air tracers
call aoa_tracers_register()
! Register test tracers
call tracers_register()
call dyn_register()
! All tracers registered, check that the dimensions are correct
call cnst_chk_dim()
! ***NOTE*** No registering constituents after the call to cnst_chk_dim.
call offline_driver_reg()
end subroutine phys_register
!=======================================================================
subroutine phys_inidat( cam_out, pbuf2d )
use cam_abortutils, only: endrun
use physics_buffer, only: pbuf_get_index, pbuf_get_field, physics_buffer_desc, pbuf_set_field, dyn_time_lvls
use cam_initfiles, only: initial_file_get_id, topo_file_get_id
use cam_grid_support, only: cam_grid_check, cam_grid_id
use cam_grid_support, only: cam_grid_get_dim_names
use pio, only: file_desc_t
use ncdio_atm, only: infld
use dycore, only: dycore_is
use polar_avg, only: polar_average
use short_lived_species, only: initialize_short_lived_species
use cam_control_mod, only: aqua_planet
use waccmx_phys_intr, only: waccmx_phys_ion_elec_temp_inidat
type(cam_out_t), intent(inout) :: cam_out(begchunk:endchunk)
type(physics_buffer_desc), pointer :: pbuf2d(:,:)
integer :: lchnk, m, n, i, k, ncol
type(file_desc_t), pointer :: fh_ini, fh_topo
character(len=8) :: fieldname
real(r8), pointer :: tptr(:,:), tptr_2(:,:), tptr3d(:,:,:), tptr3d_2(:,:,:)
real(r8), pointer :: qpert(:,:)
character(len=11) :: subname='phys_inidat' ! subroutine name
integer :: tpert_idx, qpert_idx, pblh_idx
logical :: found=.false., found2=.false.
integer :: ierr
character(len=8) :: dim1name, dim2name
integer :: ixcldice, ixcldliq
integer :: grid_id ! grid ID for data mapping
nullify(tptr,tptr_2,tptr3d,tptr3d_2)
fh_ini => initial_file_get_id()
fh_topo => topo_file_get_id()
! dynamics variables are handled in dyn_init - here we read variables needed for physics
! but not dynamics
grid_id = cam_grid_id('physgrid')
if (.not. cam_grid_check(grid_id)) then
call endrun(trim(subname)//': Internal error, no "physgrid" grid')
end if
call cam_grid_get_dim_names(grid_id, dim1name, dim2name)
allocate(tptr(1:pcols,begchunk:endchunk))
if (associated(fh_topo) .and. .not. aqua_planet) then
call infld('SGH', fh_topo, dim1name, dim2name, 1, pcols, begchunk, endchunk, &
tptr, found, gridname='physgrid')
if(.not. found) call endrun('ERROR: SGH not found on topo file')
call pbuf_set_field(pbuf2d, sgh_idx, tptr)
allocate(tptr_2(1:pcols,begchunk:endchunk))
call infld('SGH30', fh_topo, dim1name, dim2name, 1, pcols, begchunk, endchunk, &
tptr_2, found, gridname='physgrid')
if(found) then
call pbuf_set_field(pbuf2d, sgh30_idx, tptr_2)
else
if (masterproc) write(iulog,*) 'Warning: Error reading SGH30 from topo file.'
if (masterproc) write(iulog,*) 'The field SGH30 will be filled using data from SGH.'
call pbuf_set_field(pbuf2d, sgh30_idx, tptr)
end if
deallocate(tptr_2)
call infld('LANDM_COSLAT', fh_topo, dim1name, dim2name, 1, pcols, begchunk, endchunk, &
tptr, found, gridname='physgrid')
if(.not.found) call endrun(' ERROR: LANDM_COSLAT not found on topo dataset.')
call pbuf_set_field(pbuf2d, landm_idx, tptr)
else
call pbuf_set_field(pbuf2d, sgh_idx, 0._r8)
call pbuf_set_field(pbuf2d, sgh30_idx, 0._r8)
call pbuf_set_field(pbuf2d, landm_idx, 0._r8)
end if
call infld('PBLH', fh_ini, dim1name, dim2name, 1, pcols, begchunk, endchunk, &
tptr(:,:), found, gridname='physgrid')
if(.not. found) then
tptr(:,:) = 0._r8
if (masterproc) write(iulog,*) 'PBLH initialized to 0.'
end if
pblh_idx = pbuf_get_index('pblh')
call pbuf_set_field(pbuf2d, pblh_idx, tptr)
call infld('TPERT', fh_ini, dim1name, dim2name, 1, pcols, begchunk, endchunk, &
tptr(:,:), found, gridname='physgrid')
if(.not. found) then
tptr(:,:) = 0._r8
if (masterproc) write(iulog,*) 'TPERT initialized to 0.'
end if
tpert_idx = pbuf_get_index( 'tpert')
call pbuf_set_field(pbuf2d, tpert_idx, tptr)
fieldname='QPERT'
qpert_idx = pbuf_get_index( 'qpert',ierr)
if (qpert_idx > 0) then
call infld(fieldname, fh_ini, dim1name, dim2name, 1, pcols, begchunk, endchunk, &
tptr, found, gridname='physgrid')
if(.not. found) then
tptr=0_r8
if (masterproc) write(iulog,*) trim(fieldname), ' initialized to 0.'
end if
allocate(tptr3d_2(pcols,pcnst,begchunk:endchunk))
tptr3d_2 = 0_r8
tptr3d_2(:,1,:) = tptr(:,:)
call pbuf_set_field(pbuf2d, qpert_idx, tptr3d_2)
deallocate(tptr3d_2)
end if
fieldname='CUSH'
m = pbuf_get_index('cush', ierr)
if (m > 0) then
call infld(fieldname, fh_ini, dim1name, dim2name, 1, pcols, begchunk, endchunk, &
tptr, found, gridname='physgrid')
if(.not.found) then
if(masterproc) write(iulog,*) trim(fieldname), ' initialized to 1000.'
tptr=1000._r8
end if
do n=1,dyn_time_lvls
call pbuf_set_field(pbuf2d, m, tptr, start=(/1,n/), kount=(/pcols,1/))
end do
deallocate(tptr)
end if
!
! 3-D fields
!
allocate(tptr3d(pcols,pver,begchunk:endchunk))
fieldname='CLOUD'
m = pbuf_get_index('CLD')
call infld(fieldname, fh_ini, dim1name, 'lev', dim2name, 1, pcols, 1, pver, begchunk, endchunk, &
tptr3d, found, gridname='physgrid')
if(found) then
do n = 1, dyn_time_lvls
call pbuf_set_field(pbuf2d, m, tptr3d, (/1,1,n/),(/pcols,pver,1/))
end do
else
call pbuf_set_field(pbuf2d, m, 0._r8)
if (masterproc) write(iulog,*) trim(fieldname), ' initialized to 0.'
end if
fieldname='QCWAT'
m = pbuf_get_index(fieldname,ierr)
if (m > 0) then
call infld(fieldname, fh_ini, dim1name, 'lev', dim2name, 1, pcols, 1, pver, begchunk, endchunk, &
tptr3d, found, gridname='physgrid')
if(.not. found) then
call infld('Q',fh_ini,dim1name, 'lev', dim2name, 1, pcols, 1, pver, begchunk, endchunk, &
tptr3d, found, gridname='physgrid')
if (found) then
if (masterproc) write(iulog,*) trim(fieldname), ' initialized with Q'
if(dycore_is('LR')) call polar_average(pver, tptr3d)
else
if (masterproc) write(iulog,*) trim(fieldname), ' initialized to huge()'
tptr3d = huge(1.0_r8)
end if
end if
do n = 1, dyn_time_lvls
call pbuf_set_field(pbuf2d, m, tptr3d, (/1,1,n/),(/pcols,pver,1/))
end do
end if
fieldname = 'ICCWAT'
m = pbuf_get_index(fieldname, ierr)
if (m > 0) then
call infld(fieldname, fh_ini, dim1name, 'lev', dim2name, 1, pcols, 1, pver, begchunk, endchunk, &
tptr3d, found, gridname='physgrid')
if(found) then
do n = 1, dyn_time_lvls
call pbuf_set_field(pbuf2d, m, tptr3d, (/1,1,n/),(/pcols,pver,1/))
end do
else
call cnst_get_ind('CLDICE', ixcldice)
call infld('CLDICE',fh_ini,dim1name, 'lev', dim2name, 1, pcols, 1, pver, begchunk, endchunk, &
tptr3d, found, gridname='physgrid')
if(found) then
do n = 1, dyn_time_lvls
call pbuf_set_field(pbuf2d, m, tptr3d, (/1,1,n/),(/pcols,pver,1/))
end do
else
call pbuf_set_field(pbuf2d, m, 0._r8)
end if
if (masterproc) then
if (found) then
write(iulog,*) trim(fieldname), ' initialized with CLDICE'
else
write(iulog,*) trim(fieldname), ' initialized to 0.0'
end if
end if
end if
end if
fieldname = 'LCWAT'
m = pbuf_get_index(fieldname,ierr)
if (m > 0) then
call infld(fieldname, fh_ini, dim1name, 'lev', dim2name, 1, pcols, 1, pver, begchunk, endchunk, &
tptr3d, found, gridname='physgrid')
if(found) then
do n = 1, dyn_time_lvls
call pbuf_set_field(pbuf2d, m, tptr3d, (/1,1,n/),(/pcols,pver,1/))
end do
else
allocate(tptr3d_2(pcols,pver,begchunk:endchunk))
call cnst_get_ind('CLDICE', ixcldice)
call cnst_get_ind('CLDLIQ', ixcldliq)
call infld('CLDICE',fh_ini,dim1name, 'lev', dim2name, 1, pcols, 1, pver, begchunk, endchunk, &
tptr3d, found, gridname='physgrid')
call infld('CLDLIQ',fh_ini,dim1name, 'lev', dim2name, 1, pcols, 1, pver, begchunk, endchunk, &
tptr3d_2, found2, gridname='physgrid')
if(found .and. found2) then
do lchnk = begchunk, endchunk
ncol = get_ncols_p(lchnk)
tptr3d(:ncol,:,lchnk)=tptr3d(:ncol,:,lchnk)+tptr3d_2(:ncol,:,lchnk)
end do
if (masterproc) write(iulog,*) trim(fieldname), ' initialized with CLDICE + CLDLIQ'
else if (found) then ! Data already loaded in tptr3d
if (masterproc) write(iulog,*) trim(fieldname), ' initialized with CLDICE only'
else if (found2) then
tptr3d(:,:,:)=tptr3d_2(:,:,:)
if (masterproc) write(iulog,*) trim(fieldname), ' initialized with CLDLIQ only'
end if
if (found .or. found2) then
do n = 1, dyn_time_lvls
call pbuf_set_field(pbuf2d, m, tptr3d, (/1,1,n/),(/pcols,pver,1/))
end do
if(dycore_is('LR')) call polar_average(pver, tptr3d)
else
call pbuf_set_field(pbuf2d, m, 0._r8)
if (masterproc) write(iulog,*) trim(fieldname), ' initialized to 0.0'
end if
deallocate(tptr3d_2)
end if
end if
deallocate(tptr3d)
allocate(tptr3d(pcols,pver,begchunk:endchunk))
fieldname = 'TCWAT'
m = pbuf_get_index(fieldname,ierr)
if (m > 0) then
call infld(fieldname, fh_ini, dim1name, 'lev', dim2name, 1, pcols, 1, pver, begchunk, endchunk, &
tptr3d, found, gridname='physgrid')
if(.not.found) then
call infld('T', fh_ini, dim1name, 'lev', dim2name, 1, pcols, 1, pver, begchunk, endchunk, &
tptr3d, found, gridname='physgrid')
if (found) then
if(dycore_is('LR')) call polar_average(pver, tptr3d)
if (masterproc) write(iulog,*) trim(fieldname), ' initialized with T'
else
if (masterproc) write(iulog,*) trim(fieldname), ' initialized to huge()'
tptr3d = huge(1._r8)
end if
end if
do n = 1, dyn_time_lvls
call pbuf_set_field(pbuf2d, m, tptr3d, (/1,1,n/),(/pcols,pver,1/))
end do
end if
deallocate(tptr3d)
allocate(tptr3d(pcols,pverp,begchunk:endchunk))
fieldname = 'TKE'
m = pbuf_get_index( 'tke')
call infld(fieldname, fh_ini, dim1name, 'ilev', dim2name, 1, pcols, 1, pverp, begchunk, endchunk, &
tptr3d, found, gridname='physgrid')
if (found) then
call pbuf_set_field(pbuf2d, m, tptr3d)
else
call pbuf_set_field(pbuf2d, m, 0.01_r8)
if (masterproc) write(iulog,*) trim(fieldname), ' initialized to 0.01'
end if
fieldname = 'KVM'
m = pbuf_get_index('kvm')
call infld(fieldname, fh_ini, dim1name, 'ilev', dim2name, 1, pcols, 1, pverp, begchunk, endchunk, &
tptr3d, found, gridname='physgrid')
if (found) then
call pbuf_set_field(pbuf2d, m, tptr3d)
else
call pbuf_set_field(pbuf2d, m, 0._r8)
if (masterproc) write(iulog,*) trim(fieldname), ' initialized to 0.'
end if
fieldname = 'KVH'
m = pbuf_get_index('kvh')
call infld(fieldname, fh_ini, dim1name, 'ilev', dim2name, 1, pcols, 1, pverp, begchunk, endchunk, &
tptr3d, found, gridname='physgrid')
if (found) then
call pbuf_set_field(pbuf2d, m, tptr3d)
else
call pbuf_set_field(pbuf2d, m, 0._r8)
if (masterproc) write(iulog,*) trim(fieldname), ' initialized to 0.'
end if
deallocate(tptr3d)
allocate(tptr3d(pcols,pver,begchunk:endchunk))
fieldname = 'CONCLD'
m = pbuf_get_index('CONCLD',ierr)
if (m > 0) then
call infld(fieldname, fh_ini, dim1name, 'lev', dim2name, 1, pcols, 1, pver, begchunk, endchunk, &
tptr3d, found, gridname='physgrid')
if(found) then
do n = 1, dyn_time_lvls
call pbuf_set_field(pbuf2d, m, tptr3d, (/1,1,n/),(/pcols,pver,1/))
end do
else
call pbuf_set_field(pbuf2d, m, 0._r8)
if (masterproc) write(iulog,*) trim(fieldname), ' initialized to 0.'
end if
deallocate (tptr3d)
end if
call initialize_short_lived_species(fh_ini, pbuf2d)
!---------------------------------------------------------------------------------
! If needed, get ion and electron temperature fields from initial condition file
!---------------------------------------------------------------------------------
call waccmx_phys_ion_elec_temp_inidat(fh_ini,pbuf2d)
end subroutine phys_inidat
subroutine phys_init( phys_state, phys_tend, pbuf2d, cam_out )
!-----------------------------------------------------------------------
!
! Initialization of physics package.
!
!-----------------------------------------------------------------------
use physics_buffer, only: physics_buffer_desc, pbuf_initialize, pbuf_get_index
use physconst, only: rair, cpair, gravit, stebol, tmelt, &
latvap, latice, rh2o, rhoh2o, pstd, zvir, &
karman, rhodair, physconst_init
use ref_pres, only: pref_edge, pref_mid
use carma_intr, only: carma_init
use cam_control_mod, only: initial_run
use check_energy, only: check_energy_init
use chemistry, only: chem_init
use prescribed_ozone, only: prescribed_ozone_init
use prescribed_ghg, only: prescribed_ghg_init
use prescribed_aero, only: prescribed_aero_init
use aerodep_flx, only: aerodep_flx_init
use aircraft_emit, only: aircraft_emit_init
use prescribed_volcaero,only: prescribed_volcaero_init
use prescribed_strataero,only: prescribed_strataero_init
use cloud_fraction, only: cldfrc_init
use cldfrc2m, only: cldfrc2m_init
use co2_cycle, only: co2_init, co2_transport
use convect_deep, only: convect_deep_init
use convect_shallow, only: convect_shallow_init
use cam_diagnostics, only: diag_init
use gw_drag, only: gw_init
use cam3_aero_data, only: cam3_aero_data_on, cam3_aero_data_init
use cam3_ozone_data, only: cam3_ozone_data_on, cam3_ozone_data_init
use radheat, only: radheat_init
use radiation, only: radiation_init
use cloud_diagnostics, only: cloud_diagnostics_init
use rk_stratiform, only: rk_stratiform_init
use wv_saturation, only: wv_sat_init
use microp_driver, only: microp_driver_init
use microp_aero, only: microp_aero_init
use macrop_driver, only: macrop_driver_init
use conv_water, only: conv_water_init
use spcam_drivers, only: spcam_init
use tracers, only: tracers_init
use aoa_tracers, only: aoa_tracers_init
use rayleigh_friction, only: rayleigh_friction_init
use pbl_utils, only: pbl_utils_init
use vertical_diffusion, only: vertical_diffusion_init
use phys_debug_util, only: phys_debug_init
use phys_debug, only: phys_debug_state_init
use rad_constituents, only: rad_cnst_init
use aer_rad_props, only: aer_rad_props_init
use subcol, only: subcol_init
use qbo, only: qbo_init
use qneg_module, only: qneg_init
use iondrag, only: iondrag_init, do_waccm_ions
#if ( defined OFFLINE_DYN )
use metdata, only: metdata_phys_init
#endif
use epp_ionization, only: epp_ionization_init, epp_ionization_active
use waccmx_phys_intr, only: waccmx_phys_ion_elec_temp_init ! Initialization of ionosphere module (WACCM-X)
use waccmx_phys_intr, only: waccmx_phys_mspd_init ! Initialization of major species diffusion module (WACCM-X)
use clubb_intr, only: clubb_ini_cam
use sslt_rebin, only: sslt_rebin_init
use tropopause, only: tropopause_init
use solar_data, only: solar_data_init
use dadadj_cam, only: dadadj_init
use cam_abortutils, only: endrun
use nudging, only: Nudge_Model, nudging_init
! Input/output arguments
type(physics_state), pointer :: phys_state(:)
type(physics_tend ), pointer :: phys_tend(:)
type(physics_buffer_desc), pointer :: pbuf2d(:,:)
type(cam_out_t),intent(inout) :: cam_out(begchunk:endchunk)
! local variables
integer :: lchnk
integer :: ierr
!-----------------------------------------------------------------------
call physics_type_alloc(phys_state, phys_tend, begchunk, endchunk, pcols)
do lchnk = begchunk, endchunk
call physics_state_set_grid(lchnk, phys_state(lchnk))
end do
!-------------------------------------------------------------------------------------------
! Initialize any variables in physconst which are not temporally and/or spatially constant
!-------------------------------------------------------------------------------------------
call physconst_init()
! Initialize debugging a physics column
call phys_debug_init()
call pbuf_initialize(pbuf2d)
! Initialize subcol scheme
call subcol_init(pbuf2d)
! diag_init makes addfld calls for dynamics fields that are output from
! the physics decomposition
call diag_init(pbuf2d)
call check_energy_init()
call tracers_init()
! age of air tracers
call aoa_tracers_init()
teout_idx = pbuf_get_index( 'TEOUT')
! adiabatic or ideal physics should be only used if in simple_physics
if (adiabatic .or. ideal_phys) then
if (adiabatic) then
call endrun('phys_init: adiabatic configuration error')
else
call endrun('phys_init: ideal_phys configuration error')
end if
end if
if (initial_run) then
call phys_inidat(cam_out, pbuf2d)
end if
! wv_saturation is relatively independent of everything else and
! low level, so init it early. Must at least do this before radiation.
call wv_sat_init
! CAM3 prescribed aerosols
if (cam3_aero_data_on) call cam3_aero_data_init(phys_state)
! Initialize rad constituents and their properties
call rad_cnst_init()
call aer_rad_props_init()
! initialize carma
call carma_init()
! solar irradiance data modules
call solar_data_init()
! Prognostic chemistry.
call chem_init(phys_state,pbuf2d)
! Prescribed tracers
call prescribed_ozone_init()
call prescribed_ghg_init()
call prescribed_aero_init()
call aerodep_flx_init()
call aircraft_emit_init()
call prescribed_volcaero_init()
call prescribed_strataero_init()
! co2 cycle
if (co2_transport()) then
call co2_init()
end if
! CAM3 prescribed ozone
if (cam3_ozone_data_on) call cam3_ozone_data_init(phys_state)
call gw_init()
call rayleigh_friction_init()
call pbl_utils_init(gravit, karman, cpair, rair, zvir)
call vertical_diffusion_init(pbuf2d)
if ( waccmx_is('ionosphere') .or. waccmx_is('neutral') ) then
call waccmx_phys_mspd_init ()
! Initialization of ionosphere module if mode set to ionosphere
if( waccmx_is('ionosphere') ) then
call waccmx_phys_ion_elec_temp_init(pbuf2d)
endif
endif
call radiation_init(pbuf2d)
call cloud_diagnostics_init()
call radheat_init(pref_mid)
call convect_shallow_init(pref_edge, pbuf2d)
call cldfrc_init()
call cldfrc2m_init()
call convect_deep_init(pref_edge)
if( microp_scheme == 'RK' ) then
call rk_stratiform_init()
elseif( microp_scheme == 'MG' ) then
if (.not. do_clubb_sgs) call macrop_driver_init(pbuf2d)
call microp_aero_init()
call microp_driver_init(pbuf2d)
call conv_water_init
elseif( microp_scheme == 'SPCAM_m2005') then
call conv_water_init
end if
! initiate CLUBB within CAM
if (do_clubb_sgs) call clubb_ini_cam(pbuf2d)
call spcam_init(pbuf2d)
call qbo_init
call iondrag_init(pref_mid)
! Geomagnetic module -- after iondrag_init
if (epp_ionization_active) then
call epp_ionization_init()
endif
#if ( defined OFFLINE_DYN )
call metdata_phys_init()
#endif
call sslt_rebin_init()
call tropopause_init()
call dadadj_init()
prec_dp_idx = pbuf_get_index('PREC_DP')
snow_dp_idx = pbuf_get_index('SNOW_DP')
prec_sh_idx = pbuf_get_index('PREC_SH')
snow_sh_idx = pbuf_get_index('SNOW_SH')
dlfzm_idx = pbuf_get_index('DLFZM', ierr)
call phys_getopts(prog_modal_aero_out=prog_modal_aero)
! Initialize Nudging Parameters
!--------------------------------
if(Nudge_Model) call nudging_init
if (clim_modal_aero) then
! If climate calculations are affected by prescribed modal aerosols, the
! the initialization routine for the dry mode radius calculation is called
! here. For prognostic MAM the initialization is called from
! modal_aero_initialize
if (.not. prog_modal_aero) then
call modal_aero_calcsize_init(pbuf2d)
endif
call modal_aero_wateruptake_init(pbuf2d)
end if
! Initialize qneg3 and qneg4
call qneg_init()
end subroutine phys_init
!
!-----------------------------------------------------------------------
!
subroutine phys_run1(phys_state, ztodt, phys_tend, pbuf2d, cam_in, cam_out)
!-----------------------------------------------------------------------
!
! Purpose:
! First part of atmospheric physics package before updating of surface models
!
!-----------------------------------------------------------------------
use time_manager, only: get_nstep
use cam_diagnostics,only: diag_allocate, diag_physvar_ic
use check_energy, only: check_energy_gmean
use phys_control, only: phys_getopts
use spcam_drivers, only: tphysbc_spcam
use spmd_utils, only: mpicom
use physics_buffer, only: physics_buffer_desc, pbuf_get_chunk, pbuf_allocate
#if (defined BFB_CAM_SCAM_IOP )
use cam_history, only: outfld
#endif
use cam_abortutils, only: endrun
#if ( defined OFFLINE_DYN )
use metdata, only: get_met_srf1
#endif
!
! Input arguments
!
real(r8), intent(in) :: ztodt ! physics time step unless nstep=0
!
! Input/Output arguments
!
type(physics_state), intent(inout), dimension(begchunk:endchunk) :: phys_state
type(physics_tend ), intent(inout), dimension(begchunk:endchunk) :: phys_tend
type(physics_buffer_desc), pointer, dimension(:,:) :: pbuf2d
type(cam_in_t), dimension(begchunk:endchunk) :: cam_in
type(cam_out_t), dimension(begchunk:endchunk) :: cam_out
!-----------------------------------------------------------------------
!
!---------------------------Local workspace-----------------------------
!
integer :: c ! indices
integer :: ncol ! number of columns
integer :: nstep ! current timestep number
logical :: use_spcam
type(physics_buffer_desc), pointer :: phys_buffer_chunk(:)
call t_startf ('physpkg_st1')
nstep = get_nstep()
#if ( defined OFFLINE_DYN )
!
! if offline mode set SNOWH and TS for micro-phys
!
call get_met_srf1( cam_in )
#endif
! The following initialization depends on the import state (cam_in)
! being initialized. This isn't true when cam_init is called, so need
! to postpone this initialization to here.
if (nstep == 0 .and. phys_do_flux_avg()) call flux_avg_init(cam_in, pbuf2d)
! Compute total energy of input state and previous output state
call t_startf ('chk_en_gmean')
call check_energy_gmean(phys_state, pbuf2d, ztodt, nstep)
call t_stopf ('chk_en_gmean')
call t_stopf ('physpkg_st1')