forked from pressel/pycles
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRadiationRRTM_CGILS.pyx
1467 lines (1281 loc) · 70.6 KB
/
RadiationRRTM_CGILS.pyx
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
__author__ = 'pressel'
import numpy as np
cimport numpy as np
import sys
from libc.math cimport exp, fmin, fmax
from libc.stdlib cimport malloc, free
# from Parallel import get_z_pencils_double, z_pencils_inverse_double
# import pylab as plt
cimport ThermodynamicFunctions
import cython
from cython.parallel import prange
import ProfileStatistics
import timeit
from Parallel import reduce_to_root_2d
include 'Parameters.pxi'
from mpi4py import MPI
# Note: the RRTM modules are compiled in directories:
# ~/PyRRTM/rrtmg_lw_v4.85/gcm_model_column_gfortran_f2py/build/f2py/rrtmg_lw.so
# ~/PyRRTM/rrtmg_sw_v3.9/gcm_model_column_gfortran_f2py/build/f2py/rrtmg_sw.so
# And they are manually copied to the current directory
import rrtmg_lw
import rrtmg_sw
# import time # DEBUG
import netCDF4 as nc
class RadiationRRTM_CGILS: # No change currently, should use the reference profile to extend the calculation.
def __init__(self,grid):
self.lw_flux_down = np.zeros(grid.nz)
self.lw_flux_up = np.zeros(grid.nz)
self.sw_flux_down = np.zeros(grid.nz)
self.sw_flux_up = np.zeros(grid.nz)
self.lw_flux_down_clear = np.zeros(grid.nz)
self.lw_flux_up_clear = np.zeros(grid.nz)
self.sw_flux_down_clear = np.zeros(grid.nz)
self.sw_flux_up_clear = np.zeros(grid.nz)
self.dTdt_clear = np.zeros(grid.nz)
self.dTdt_rad = np.zeros((grid.nxl,grid.nyl,grid.nzl))
self.dsdt_rad = np.zeros((grid.nxl,grid.nyl,grid.nzl))
self.osr = np.zeros((grid.nxl, grid.nyl))
self.olr = np.zeros((grid.nxl, grid.nyl))
self.rel_tropo_T = None
self.rel_toa_T = None
self.n_ext = None
# CGILS-specific:
self.ref_aloft = None
self.pressure_aloft = None
self.p0i_aloft = None
self.temperature_aloft = None
self.y_vapor_aloft = None
self.y_cond_aloft = None
self.cloud_fraction_aloft = None
# Test:
self.p0i_ext = None
self.pressure_ext = None
self.temperature_ext = None
self.y_vapor_ext = None
self.y_cond_ext = None
self.cloud_fraction_ext = None
self.is_vapor = None
self.is_liquid = None
self.is_ice = None
# Added for PyRRTM
self.lw_input_file = None
self.lw_gas = None
self.trace = None
self.co2_factor = None
self.h2o_factor = None
self.lw_np = None
self.uniform_reliq = None
self.smooth_qc = None
self.radiation_frequency = None
self.o3vmr = None
self.co2vmr = None
self.ch4vmr = None
self.n2ovmr = None
self.o2vmr = None
self.cfc11vmr = None
self.cfc12vmr = None
self.cfc22vmr = None
self.ccl4vmr = None
self.dyofyr = None
self.adjes = None
self.scon = None
self.coszen = None
self.adif = None
# Test
self.play_in_ext = None
self.plev_in_ext = None
self.tlay_in_ext = None
self.tlev_in_ext = None
self.h2ovmr_in_ext = None
self.cldfr_in_ext = None
self.cliqwp_in_ext = None
self.reliq_in_ext = None
self.tsfc_in_ext = None
self.debug_mode = None
self.n_ext = None
return
def initialize(self,case_dict,grid,basicstate,scalars,thermodynamics,io):
self.n_ext = 50
try:
self.ref_aloft = case_dict['radiation']['ref_aloft']
except:
print('Reference profile of radiation is not set, using default: ref_aloft = False')
self.ref_aloft = False
self.pressure_aloft = np.zeros(self.n_ext,dtype=np.double,order='c')
self.p0i_aloft = np.zeros(self.n_ext+1 ,dtype=np.double,order='c')
self.temperature_aloft = np.zeros(self.n_ext,dtype=np.double,order='c')
self.y_vapor_aloft = np.zeros(self.n_ext ,dtype=np.double,order='c')
self.y_cond_aloft = np.zeros(self.n_ext ,dtype=np.double,order='c')
self.cloud_fraction_aloft = np.zeros(self.n_ext ,dtype=np.double,order='c')
if self.ref_aloft:
self.p0i_aloft[0] = basicstate.p0_i_global_ghosted[grid.gw + grid.nz-1]
for k in xrange(1,self.n_ext+1):
self.p0i_aloft[k] = self.p0i_aloft[k-1] - self.p0i_aloft[0]/self.n_ext
self.pressure_aloft[k-1] = (self.p0i_aloft[k] + self.p0i_aloft[k-1])*0.5
p = case_dict['forcing']['pressure']
# Interpolate for temperature and moisture aloft (above of domain top)
try:
self.temperature_aloft = np.interp(self.pressure_aloft,p,case_dict['forcing']['t_ref'])
except:
self.temperature_aloft = np.interp(self.pressure_aloft,p,case_dict['forcing']['thl_ref']*(p/basicstate.p00)**(Ra/cpa))
self.y_vapor_aloft = np.interp(self.pressure_aloft,p,case_dict['forcing']['yv_ref'])
else: # ADDED BY ZTAN FOR EXTENDED TEMPERATURE PROFILE BEYOND LES TOP, ONLY USED WHEN self.ref_aloft = False
try:
self.rel_tropo_T = case_dict['forcing']['rel_tropo_T']
except:
print('Tropopause Temperature not set so RadiationFMS takes default value: rel_tropo_T = 240.0K .')
self.rel_tropo_T = 240.0
try:
self.rel_toa_T = case_dict['forcing']['rel_toa_T']
except:
print('TOA Temperature not set so RadiationFMS takes default value: rel_toa_T = 220.0K .')
self.rel_toa_T = 220.0
try:
self.rel_rh = case_dict['forcing']['rel_rh']
except:
print('Reference Relative Humidity not set so RadiationFMS takes default value: rel_rh = 0.4 .')
self.rel_rh = 0.4
# Added: calculate the extended pressure profiles
pressure = basicstate.p0_global_noghost
p0i = basicstate.p0_i_global_ghosted
self.pressure_ext = np.zeros(grid.nz + self.n_ext ,dtype=np.double,order='c')
self.p0i_ext = np.zeros(grid.nz + self.n_ext+1 ,dtype=np.double,order='c')
for k in xrange(grid.nz + self.n_ext):
if k <= grid.nz :
self.p0i_ext[k] = p0i[grid.gw + k-1]
elif self.ref_aloft:
self.p0i_ext[k] = self.p0i_aloft[k-grid.nz]
else:
self.p0i_ext[k] = self.p0i_ext[k-1] - self.p0i_ext[grid.nz]/self.n_ext
for k in xrange(grid.nz + self.n_ext):
if k <= (grid.nz-1):
self.pressure_ext[k] = pressure[k]
else:
self.pressure_ext[k] = (self.p0i_ext[k] + self.p0i_ext[k+1])*0.5
# Added: Initialize rrtmg_lw and rrtmg_sw
rrtmg_lw.rrtmg_lw_init.rrtmg_lw_ini(np.float64(cpa))
rrtmg_sw.rrtmg_sw_init.rrtmg_sw_ini(np.float64(cpa))
# Added: Read in gas data (with CO2 multiplier)
# Compute top of atmosphere solar insolation
try:
lw_input_file = case_dict['radiation']['lw_input_file']
except:
print('RRTM GHG values are not given a member of forcing case_dict dictionary. Required by RadiationFMS')
sys.exit()
try:
self.co2_factor = case_dict['radiation']['co2_factor']
except:
print('CO2_factor not set so RadiationFMS takes default value: co2_factor = 1.0 .')
self.co2_factor = 1.0
try:
self.h2o_factor = case_dict['radiation']['h2o_factor']
except:
print('h2o_factor not set so RadiationFMS takes default value: h2o_factor = 1.0 .')
self.h2o_factor = 1.0
try:
self.uniform_reliq = case_dict['radiation']['uniform_reliq']
except:
print('uniform_reliq not set so RadiationFMS takes default value: uniform_reliq = False.')
self.uniform_reliq = False
try:
self.uniform_dTrad = case_dict['radiation']['uniform_dTrad']
except:
print('uniform_dTrad not set so RadiationFMS takes default value: uniform_dTrad = True.')
self.uniform_dTrad = True
try:
self.smooth_qc = case_dict['radiation']['smooth_qc']
except:
# print('smooth_qc not set so RadiationFMS takes default value: smooth_qc = False.')
self.smooth_qc = False
try: # WRITE HERE !!
o3_trace = case_dict['radiation']['o3mmr'][::-1]*28.97/47.9982 # O3 VMR (from SRF to TOP)
o3_pressure = case_dict['forcing']['pressure'][::-1]/100.0 # Pressure (from SRF to TOP) in hPa
# can't do simple interpolation... Need to conserve column path !!!
self.use_o3in = True
except:
print('O3 profile not set so RadiationFMS takes default RRTM profile.')
self.use_o3in = False
lw_gas = nc.Dataset(lw_input_file, "r")
# Trace Gases
lw_pressure = np.asarray(lw_gas.variables['Pressure'])
lw_absorber = np.asarray(lw_gas.variables['AbsorberAmountMLS'])
lw_absorber = np.where(lw_absorber>2.0, np.zeros_like(lw_absorber), lw_absorber)
lw_ngas = lw_absorber.shape[1]
self.lw_np = lw_absorber.shape[0]
# 9 Gases: O3, CO2, CH4, N2O, O2, CFC11, CFC12, CFC22, CCL4
# From rad_driver.f90, lines 546 to 552
trace = np.zeros((9,self.lw_np),dtype=np.double,order='c')
for i in xrange(lw_ngas):
gas_name = ''.join(lw_gas.variables['AbsorberNames'][i,:])
if 'O3' in gas_name:
trace[0,:] = lw_absorber[:,i].reshape(1,self.lw_np)
elif 'CO2' in gas_name:
trace[1,:] = lw_absorber[:,i].reshape(1,self.lw_np)*self.co2_factor
elif 'CH4' in gas_name:
trace[2,:] = lw_absorber[:,i].reshape(1,self.lw_np)
elif 'N2O' in gas_name:
trace[3,:] = lw_absorber[:,i].reshape(1,self.lw_np)
elif 'O2' in gas_name:
trace[4,:] = lw_absorber[:,i].reshape(1,self.lw_np)
elif 'CFC11' in gas_name:
trace[5,:] = lw_absorber[:,i].reshape(1,self.lw_np)
elif 'CFC12' in gas_name:
trace[6,:] = lw_absorber[:,i].reshape(1,self.lw_np)
elif 'CFC22' in gas_name:
trace[7,:] = lw_absorber[:,i].reshape(1,self.lw_np)
elif 'CCL4' in gas_name:
trace[8,:] = lw_absorber[:,i].reshape(1,self.lw_np)
# From rad_driver.f90, lines 585 to 620
trpath = np.zeros((grid.nz + self.n_ext+1,9),dtype=np.double,order='c')
plev = self.p0i_ext/100.0
for i in xrange(1,grid.nz + self.n_ext+1):
trpath[i,:] = trpath[i-1,:]
if (plev[i-1] > lw_pressure[0]):
trpath[i,:] = trpath[i,:] + (plev[i-1] - np.max((plev[i],lw_pressure[0])))/g*trace[:,0]
for m in xrange(1,self.lw_np):
#print i, m
plow = np.min((plev[i-1],np.max((plev[i], lw_pressure[m-1]))))
pupp = np.min((plev[i-1],np.max((plev[i], lw_pressure[m]))))
if (plow > pupp):
pmid = 0.5*(plow+pupp)
wgtlow = (pmid-lw_pressure[m])/(lw_pressure[m-1]-lw_pressure[m])
wgtupp = (lw_pressure[m-1]-pmid)/(lw_pressure[m-1]-lw_pressure[m])
trpath[i,:] = trpath[i,:] + (plow-pupp)/g*(wgtlow*trace[:,m-1] + wgtupp*trace[:,m])
if (plev[i] < lw_pressure[self.lw_np-1]):
trpath[i,:] = trpath[i,:] + (np.min((plev[i-1],lw_pressure[self.lw_np-1]))-plev[i])/g*trace[:,self.lw_np-1]
tmpTrace = np.zeros((grid.nz + self.n_ext,9),dtype=np.double,order='c')
for i in xrange(9):
tmpTrace[:,i] = g/(plev[:-1]-plev[1:])*(trpath[1:,i]-trpath[:-1,i])
self.o3vmr = np.zeros(grid.nz + self.n_ext,dtype=np.double,order='c')
self.co2vmr = np.zeros(grid.nz + self.n_ext,dtype=np.double,order='c')
self.ch4vmr = np.zeros(grid.nz + self.n_ext,dtype=np.double,order='c')
self.n2ovmr = np.zeros(grid.nz + self.n_ext,dtype=np.double,order='c')
self.o2vmr = np.zeros(grid.nz + self.n_ext,dtype=np.double,order='c')
self.cfc11vmr = np.zeros(grid.nz + self.n_ext,dtype=np.double,order='c')
self.cfc12vmr = np.zeros(grid.nz + self.n_ext,dtype=np.double,order='c')
self.cfc22vmr = np.zeros(grid.nz + self.n_ext,dtype=np.double,order='c')
self.ccl4vmr = np.zeros(grid.nz + self.n_ext,dtype=np.double,order='c')
if self.use_o3in == False:
self.o3vmr[:] = tmpTrace[:,0]
else:
# o3_trace, o3_pressure
trpath_o3 = np.zeros(grid.nz + self.n_ext+1,dtype=np.double,order='c')
plev = self.p0i_ext/100.0
self.o3_np = o3_trace.shape[0]
for i in xrange(1,grid.nz + self.n_ext+1):
trpath_o3[i] = trpath_o3[i-1]
if (plev[i-1] > o3_pressure[0]):
trpath_o3[i] = trpath_o3[i] + (plev[i-1] - np.max((plev[i],o3_pressure[0])))/g*o3_trace[0]
for m in xrange(1,self.o3_np):
#print i, m
plow = np.min((plev[i-1],np.max((plev[i], o3_pressure[m-1]))))
pupp = np.min((plev[i-1],np.max((plev[i], o3_pressure[m]))))
if (plow > pupp):
pmid = 0.5*(plow+pupp)
wgtlow = (pmid-o3_pressure[m])/(o3_pressure[m-1]-o3_pressure[m])
wgtupp = (o3_pressure[m-1]-pmid)/(o3_pressure[m-1]-o3_pressure[m])
trpath_o3[i] = trpath_o3[i] + (plow-pupp)/g*(wgtlow*o3_trace[m-1] + wgtupp*o3_trace[m])
if (plev[i] < o3_pressure[self.o3_np-1]):
trpath_o3[i] = trpath_o3[i] + (np.min((plev[i-1],o3_pressure[self.o3_np-1]))-plev[i])/g*o3_trace[self.o3_np-1]
tmpTrace_o3 = np.zeros(grid.nz + self.n_ext,dtype=np.double,order='c')
tmpTrace_o3[:] = g/(plev[:-1]-plev[1:])*(trpath_o3[1:]-trpath_o3[:-1])
self.o3vmr[:] = tmpTrace_o3[:]
self.co2vmr[:] = tmpTrace[:,1]
self.ch4vmr[:] = tmpTrace[:,2]
self.n2ovmr[:] = tmpTrace[:,3]
self.o2vmr[:] = tmpTrace[:,4]
self.cfc11vmr[:] = tmpTrace[:,5]
self.cfc12vmr[:] = tmpTrace[:,6]
self.cfc22vmr[:] = tmpTrace[:,7]
self.ccl4vmr[:] = tmpTrace[:,8]
try:
self.debug_mode = case_dict['radiation']['debug_mode']
except:
print('Debug Mode not set so RadiationFMS takes default value: debug_mode = False .')
self.debug_mode = False
try:
self.dyofyr = case_dict['radiation']['dyofyr']
except:
print('Day of year not set so RadiationFMS takes default value: dyofyr = 0 .')
self.dyofyr = 0
try:
self.adjes = case_dict['radiation']['adjes']
except:
print('Insolation adjustive factor not set so RadiationFMS takes default value: adjes = 0.5 (12 hour of daylight).')
self.adjes = 0.5
try:
self.scon = case_dict['radiation']['solar_constant']
except:
print('Solar Constant not set so RadiationFMS takes default value: scon = 1360.0 .')
self.scon = 1360.0
try:
self.coszen = case_dict['radiation']['coszen']
except:
print('Mean Daytime cos(SZA) not set so RadiationFMS takes default value: coszen = 2.0/pi .')
self.coszen = 2.0/pi
try:
self.adif = case_dict['radiation']['adif']
except:
print('Surface diffusive albedo not set so RadiationFMS takes default value: adif = 0.06 .')
self.adif = 0.06
try:
self.adir = case_dict['radiation']['adir']
except:
if (self.coszen > 0.0):
self.adir = (.026/(self.coszen**1.7 + .065)+(.15*(self.coszen-0.10)*(self.coszen-0.50)*(self.coszen- 1.00)))
else:
self.adir = 0.0
print('Surface direct albedo not set so RadiationFMS computes value: adif = %5.4f .'%(self.adir))
try:
self.radiation_frequency = case_dict['radiation']['radiation_frequency']
except:
print('radiation_frequency not set so RadiationFMS takes default value: radiation_frequency = 0.0 (compute at every step).')
self.radiation_frequency = 0.0
self.next_radiation_calculate = 0.0
self.is_vapor = True
try:
type(thermodynamics.y_vapor)
print('RadiationFMS: Thermodynamics With Vapor')
except:
self.is_vapor = False
print('RadiationFMS: Thermodynamics WithOUT Vapor')
self.is_liquid = True
try:
type(thermodynamics.y_liquid)
print('RadiationFMS: Thermodynamics With Liquid')
except:
self.is_liquid = False
print('RadiationFMS: Thermodynamics WithOUT Liquid')
self.is_ice = True
try:
type(thermodynamics.y_ice)
print('RadiationFMS: Thermodynamics With Ice')
except:
self.is_ice = False
print('RadiationFMS: Thermodynamics WithOUT Ice')
#Initialize statistical output file
self.init_output(grid, io)
return
@cython.boundscheck(False)
@cython.wraparound(False)
def update(self,grid,basicstate,scalars,velocities,thermodynamics,surface,comm,io,timestepping):
# cdef double toc, tic
cdef int gw = grid.gw
cdef int nxl = grid.nxl
cdef int nyl = grid.nyl
cdef int nzl = grid.nzl
cdef double [:,:,:] temperature = thermodynamics.temperature
# Added liquid variables: will only work with (and only with) liquid !!
cdef double [:,:,:] y_vapor
cdef double [:,:,:] y_liquid
cdef double [:,:,:] y_ice
cdef bint is_vapor = self.is_vapor
cdef bint is_liquid = self.is_liquid
cdef bint is_ice = self.is_ice
if (self.is_vapor == True):
y_vapor = thermodynamics.y_vapor
if (self.is_liquid == True):
y_liquid = thermodynamics.y_liquid
if (self.is_ice == True):
y_ice = thermodynamics.y_ice
cdef int i,j,k
if (timestepping.rk_step==0): # Compute RRTM only on the first RK step
if self.radiation_frequency <= 0.0: # Frequency = 0.0: RRTM every step
self.update_calculate(grid,basicstate,scalars,velocities,thermodynamics,surface,comm,io,timestepping)
elif timestepping.time >= self.next_radiation_calculate: # Frequency > 0.0: RRTM whenever time > n*freq
self.update_calculate(grid,basicstate,scalars,velocities,thermodynamics,surface,comm,io,timestepping)
self.next_radiation_calculate = (timestepping.time//self.radiation_frequency + 1.0) * self.radiation_frequency
# tic=timeit.default_timer()
cdef double [:] total_tt_ext = self.total_tt_ext
cdef double [:,:,:] total_tt_ext_3d = self.total_tt_ext_3d # Added for 3D output
cdef bint uniform_dTrad = self.uniform_dTrad
#Now add radiative temperature tendency
cdef int y_water_dof = scalars.get_dof('y_water')
cdef int specific_entropy_dof = scalars.get_dof('specific_entropy')
cdef double [:,:,:] y_water = scalars.values[:,:,:,y_water_dof]
cdef double [:,:,:] specific_entropy = scalars.values[:,:,:,specific_entropy_dof]
cdef double [:,:,:] specific_entropy_t = scalars.tendencies[:,:,:,specific_entropy_dof]
# cdef double [:,:,:] y_vapor = thermodynamics.y_vapor
# cdef double [:,:,:] y_liquid = thermodynamics.y_liquid
cdef double [:] alpha0 = basicstate.alpha0
cdef double [:] p0 = basicstate.p0
cdef double [:,:,:] tendency_T = self.dTdt_rad[:,:,:]
cdef double [:,:,:] tendency_s = self.dsdt_rad[:,:,:]
with nogil:
for i in prange(gw,nxl-gw,schedule='static'):
for j in xrange(gw,nyl-gw):
for k in xrange(gw,nzl-gw):
if uniform_dTrad:
tendency_T [i,j,k] = total_tt_ext[k-gw] #total_tt[k-gw]
else:
tendency_T [i,j,k] = total_tt_ext_3d[i-gw, j-gw, k-gw]
if is_vapor:
if is_liquid:
if is_ice: # With Vapor, Liquid and Ice
specific_entropy_t[i,j,k] = specific_entropy_t[i,j,k] + ( ThermodynamicFunctions.entropy_tendency(temperature[i,j,k],
p0[k],alpha0[k], y_vapor[i,j,k],y_liquid[i,j,k],
y_ice[i,j,k], 0.0,0.0,0.0,tendency_T [i,j,k]) )
tendency_s [i,j,k] = ( ThermodynamicFunctions.entropy_tendency(temperature[i,j,k],
p0[k],alpha0[k], y_vapor[i,j,k],y_liquid[i,j,k],
y_ice[i,j,k], 0.0,0.0,0.0,tendency_T [i,j,k]) )
else: # With Vapor and Liquid, No Ice
specific_entropy_t[i,j,k] = specific_entropy_t[i,j,k] + ( ThermodynamicFunctions.entropy_tendency(temperature[i,j,k],
p0[k],alpha0[k], y_vapor[i,j,k],y_liquid[i,j,k],
0.0, 0.0,0.0,0.0,tendency_T [i,j,k]) )
tendency_s [i,j,k] = ( ThermodynamicFunctions.entropy_tendency(temperature[i,j,k],
p0[k],alpha0[k], y_vapor[i,j,k],y_liquid[i,j,k],
0.0, 0.0,0.0,0.0,tendency_T [i,j,k]) )
else: # With Vapor, No Liquid or Ice
specific_entropy_t[i,j,k] = specific_entropy_t[i,j,k] + ( ThermodynamicFunctions.entropy_tendency(temperature[i,j,k],
p0[k],alpha0[k], y_vapor[i,j,k],0.0,
0.0, 0.0,0.0,0.0,tendency_T [i,j,k]) )
tendency_s [i,j,k] = ( ThermodynamicFunctions.entropy_tendency(temperature[i,j,k],
p0[k],alpha0[k], y_vapor[i,j,k],0.0,
0.0, 0.0,0.0,0.0,tendency_T [i,j,k]) )
else: # No Vapor, Liquid or Ice
specific_entropy_t[i,j,k] = specific_entropy_t[i,j,k] + ( ThermodynamicFunctions.entropy_tendency(temperature[i,j,k],
p0[k],alpha0[k], 0.0,0.0,
0.0, 0.0,0.0,0.0,tendency_T [i,j,k]) )
tendency_s [i,j,k] = ( ThermodynamicFunctions.entropy_tendency(temperature[i,j,k],
p0[k],alpha0[k], 0.0,0.0,
0.0, 0.0,0.0,0.0,tendency_T [i,j,k]) )
#if comm.rank==0:
#time.sleep(comm.rank/10.0)
#print 'rk step is: ', timestepping.rk_step
#print 'comm.rank is: ', comm.rank
#print 'dTdt_rad, mean', np.mean(np.mean(self.dTdt_rad, axis=1),axis=0)
#print 'dsdt_rad, mean', np.mean(np.mean(self.dsdt_rad, axis=1),axis=0)
#print 'dsdt_all, mean', np.mean(np.mean(scalars.tendencies[:,:,:,specific_entropy_dof], axis=1),axis=0)
#toc=timeit.default_timer()
# print 'Timer 10: ', toc-tic
#tic=toc
@cython.boundscheck(False)
@cython.wraparound(False)
def update_calculate(self,grid,basicstate,scalars,velocities,thermodynamics,surface,comm,io,timestepping):
cdef double toc, tic
# tic=timeit.default_timer()
cdef int gw = grid.gw
cdef int nzg = grid.nzg
cdef int nxl = grid.nxl
cdef int nyl = grid.nyl
cdef int nzl = grid.nzl
cdef int kmin = grid.global_kmin
cdef int nz = grid.nz
cdef int nx = grid.nx
cdef int ny = grid.ny
cdef int ishift, jshift, kshift, ijshift
cdef int n_ext = self.n_ext
cdef double [:,:,:] temperature = thermodynamics.temperature
# Added liquid variables: will only work with (and only with) liquid !!
cdef double [:,:,:] y_vapor
cdef double [:,:,:] y_liquid
cdef double [:,:,:] y_ice
cdef bint is_vapor = self.is_vapor
cdef bint is_liquid = self.is_liquid
cdef bint is_ice = self.is_ice
cdef bint uniform_reliq = self.uniform_reliq
cdef bint smooth_qc = self.smooth_qc
if (self.is_vapor == True):
y_vapor = thermodynamics.y_vapor
if (self.is_liquid == True):
y_liquid = thermodynamics.y_liquid
if (self.is_ice == True):
y_ice = thermodynamics.y_ice
# LOOK FROM HERE ON ...
# Don't average T, q, cc here - rather, do it later
# Note: this code does not work with 3D-decomposition currently
cdef int i,j,k
cdef double [:] temperature_mean_ = np.zeros(nz,dtype=np.double,order='c')
cdef double [:,:,:] temperature_ext = np.zeros((nxl-2*gw,nyl-2*gw,nz + n_ext),dtype=np.double,order='c')
cdef double [:,:,:] y_vapor_ext = np.zeros((nxl-2*gw,nyl-2*gw,nz + n_ext),dtype=np.double,order='c')
cdef double [:,:,:] y_cond_ext = np.zeros((nxl-2*gw,nyl-2*gw,nz + n_ext),dtype=np.double,order='c')
cdef double [:,:,:] cloud_fraction_ext = np.zeros((nxl-2*gw,nyl-2*gw,nz + n_ext),dtype=np.double,order='c')
# Added for 3D output
cdef double [:,:,:] total_tt_ext_3d = np.zeros((nxl-2*gw,nyl-2*gw,nz + n_ext),dtype=np.double,order='c')
# toc=timeit.default_timer()
# print 'Timer 1: ', toc-tic
# tic=toc
with nogil:
for i in xrange(nxl-2*gw):
for j in xrange(nyl-2*gw):
for k in xrange(nzl-2*gw):
kshift = k + gw
ishift = i + gw
jshift = j + gw
temperature_mean_[kmin + k] += temperature[ishift,jshift,kshift]
temperature_ext[i,j,kmin + k] = temperature[ishift,jshift,kshift]
# Need water vapor, liquid water, cloud fraction too...
if is_vapor:
y_vapor_ext[i,j,kmin + k] = y_vapor[ishift,jshift,kshift]
if smooth_qc: # Added 09/15/2015: smoothing
if is_liquid:
if is_ice: # With Vapor, Liquid and Ice
y_cond_ext[i,j,kmin + k] = ( (y_liquid[ishift,jshift,kshift-1] + y_ice[ishift,jshift,kshift-1]) +
2.0*(y_liquid[ishift,jshift,kshift] + y_ice[ishift,jshift,kshift]) +
(y_liquid[ishift,jshift,kshift+1] + y_ice[ishift,jshift,kshift+1]) ) / 4.0
else: # With Vapor and Liquid, No Ice
y_cond_ext[i,j,kmin + k] = ( y_liquid[ishift,jshift,kshift-1] +
2.0*y_liquid[ishift,jshift,kshift] +
y_liquid[ishift,jshift,kshift+1] ) / 4.0
else: # With Vapor, No Liquid or Ice
y_cond_ext[i,j,kmin + k] = ( y_ice[ishift,jshift,kshift-1] +
2.0*y_ice[ishift,jshift,kshift] +
y_ice[ishift,jshift,kshift+1] ) / 4.0
else:
if is_liquid:
if is_ice: # With Vapor, Liquid and Ice
y_cond_ext[i,j,kmin + k] = (y_liquid[ishift,jshift,kshift] + y_ice[ishift,jshift,kshift])
else: # With Vapor and Liquid, No Ice
y_cond_ext[i,j,kmin + k] = y_liquid[ishift,jshift,kshift]
else: # With Vapor, No Liquid or Ice
y_cond_ext[i,j,kmin + k] = y_ice[ishift,jshift,kshift]
if (y_cond_ext[i,j,kmin + k] > 1.0e-8):
cloud_fraction_ext[i,j,kmin + k] = 1.0
# else: # No Vapor, Liquid or Ice
# toc=timeit.default_timer()
# print 'Timer 2: ', toc-tic
# tic=toc
cdef double [:] temperature_mean = np.empty(nz,dtype=np.double,order='c')
comm.cart_comm.Allreduce(temperature_mean_, temperature_mean,op = MPI.SUM)
cdef double nxny = np.double(nx * ny)
for k in xrange(nz):
temperature_mean[k] = temperature_mean[k]/nxny
# cdef double [:] temperature_ext = np.zeros(nz + n_ext ,dtype=np.double,order='c')
cdef double [:] pressure = basicstate.p0_global_noghost
cdef double [:] pressure_ext = self.pressure_ext
cdef double [:] p0i_ext = self.p0i_ext
cdef double [:] p0i = basicstate.p0_i_global_ghosted
cdef bint ref_aloft = self.ref_aloft
cdef double [:] temperature_aloft = self.temperature_aloft
cdef double [:] y_vapor_aloft = self.y_vapor_aloft
cdef double [:] y_cond_aloft = self.y_cond_aloft
cdef double [:] cloud_fraction_aloft = self.cloud_fraction_aloft
cdef ThermodynamicFunctions.ref_adiabat_struct _ref
cdef double t00 = temperature_mean[nz-1]
cdef double p00 = pressure[nz-1] #pressure_ext[nz-1]
# Compute the extended T-profile from a saturated adiabat
# (cut off at rel_tropo_T and linearly extend to rel_toa_T)
# q-profile: Assume RH to be rel_rh
if ref_aloft:
with nogil:
for k in xrange(nz, nz + n_ext):
for i in xrange(nxl-2*gw):
for j in xrange(nyl-2*gw):
temperature_ext[i,j,k] = temperature_aloft[k-nz]
y_vapor_ext[i,j,k] = y_vapor_aloft[k-nz]
y_cond_ext[i,j,k] = y_cond_aloft[k-nz]
cloud_fraction_ext[i,j,k] = cloud_fraction_aloft[k-nz]
else:
_ref = ThermodynamicFunctions.compute_adiabat(p00, t00, pressure_ext[nz:], 1.0, self.rel_rh, 1.0,
self.rel_tropo_T, self.rel_toa_T, n_ext)
with nogil:
for k in xrange(nz, nz + n_ext):
for i in xrange(nxl-2*gw):
for j in xrange(nyl-2*gw):
temperature_ext[i,j,k] = _ref.t_ref[k-nz]
y_vapor_ext[i,j,k] = _ref.yv1_ref[k-nz]
free(_ref.t_ref )
free(_ref.yv1_ref)
free(_ref.yv2_ref)
cdef double h2o_factor = self.h2o_factor
# toc=timeit.default_timer()
# print 'Timer 3: ', toc-tic
# tic=toc
# Create input for rrtmg_lw and rrtmg_sw modules and call modules
# LW GHG (size: nz+n_ext)
cdef double surface_temperature = surface.sst
cdef double [:] o3vmr = self.o3vmr
cdef double [:] co2vmr = self.co2vmr
cdef double [:] ch4vmr = self.ch4vmr
cdef double [:] n2ovmr = self.n2ovmr
cdef double [:] o2vmr = self.o2vmr
cdef double [:] cfc11vmr = self.cfc11vmr
cdef double [:] cfc12vmr = self.cfc12vmr
cdef double [:] cfc22vmr = self.cfc22vmr
cdef double [:] ccl4vmr = self.ccl4vmr
# Now we have 3d arrays: temperature_ext, y_vapor_ext, y_cond_ext, cloud_fraction_ext (nxl-2*gw, nyl-2*gw, nz+n_ext)
# And 1d arrays: o3vmr, co2vmr, ch4vmr, n2ovmr, o2vmr, cfc11vmr, cfc12vmr, cfc22vmr, ccl4vmr (n_ext)
# First: create input arrays for rrtmg: play, plev, tlay, tlev, tsfc, ... for rrtmg
# should loop through all points
# Second: call both subroutines
# Third: convert the output arrays to the output array size
cdef int ncol = (nxl-2*gw)*(nyl-2*gw)
cdef double [:,:] play_in = np.zeros((ncol,nz + n_ext),dtype=np.double,order='c')
cdef double [:,:] plev_in = np.zeros((ncol,nz + n_ext +1),dtype=np.double,order='c')
cdef double [:,:] tlay_in = np.zeros((ncol,nz + n_ext),dtype=np.double,order='c')
cdef double [:,:] tlev_in = np.zeros((ncol,nz + n_ext +1),dtype=np.double,order='c')
cdef double [:] tsfc_in = np.zeros((ncol),dtype=np.double,order='c')
cdef double [:,:] h2ovmr_in = np.zeros((ncol,nz + n_ext),dtype=np.double,order='c')
cdef double [:,:] o3vmr_in = np.zeros((ncol,nz + n_ext),dtype=np.double,order='c')
cdef double [:,:] co2vmr_in = np.zeros((ncol,nz + n_ext),dtype=np.double,order='c')
cdef double [:,:] ch4vmr_in = np.zeros((ncol,nz + n_ext),dtype=np.double,order='c')
cdef double [:,:] n2ovmr_in = np.zeros((ncol,nz + n_ext),dtype=np.double,order='c')
cdef double [:,:] o2vmr_in = np.zeros((ncol,nz + n_ext),dtype=np.double,order='c')
cdef double [:,:] cfc11vmr_in = np.zeros((ncol,nz + n_ext),dtype=np.double,order='c')
cdef double [:,:] cfc12vmr_in = np.zeros((ncol,nz + n_ext),dtype=np.double,order='c')
cdef double [:,:] cfc22vmr_in = np.zeros((ncol,nz + n_ext),dtype=np.double,order='c')
cdef double [:,:] ccl4vmr_in = np.zeros((ncol,nz + n_ext),dtype=np.double,order='c')
cdef double [:,:] emis_in = np.zeros((ncol,16),dtype=np.double,order='c')
cdef double [:,:] cldfr_in = np.zeros((ncol,nz + n_ext),dtype=np.double,order='c')
cdef double [:,:] cicewp_in = np.zeros((ncol,nz + n_ext),dtype=np.double,order='c')
cdef double [:,:] cliqwp_in = np.zeros((ncol,nz + n_ext),dtype=np.double,order='c')
cdef double [:,:] reice_in = np.zeros((ncol,nz + n_ext),dtype=np.double,order='c')
cdef double [:,:] reliq_in = np.zeros((ncol,nz + n_ext),dtype=np.double,order='c')
cdef int dyofyr_in = self.dyofyr
cdef double adjes_in = self.adjes
cdef double scon_in = self.scon
cdef double coszen = self.coszen
cdef double adif = self.adif
cdef double adir = self.adir
cdef double [:] coszen_in = np.zeros((ncol),dtype=np.double,order='c')
cdef double [:] asdir_in = np.zeros((ncol),dtype=np.double,order='c')
cdef double [:] asdif_in = np.zeros((ncol),dtype=np.double,order='c')
cdef double [:] aldir_in = np.zeros((ncol),dtype=np.double,order='c')
cdef double [:] aldif_in = np.zeros((ncol),dtype=np.double,order='c')
cdef double [:,:,:] taucld_lw_in = np.zeros((16,ncol,nz + n_ext),dtype=np.double,order='c')
cdef double [:,:,:] tauaer_lw_in = np.zeros((ncol,nz + n_ext,16),dtype=np.double,order='c')
cdef double [:,:,:] taucld_sw_in = np.zeros((14,ncol,nz + n_ext),dtype=np.double,order='c')
cdef double [:,:,:] ssacld_sw_in = np.zeros((14,ncol,nz + n_ext),dtype=np.double,order='c')
cdef double [:,:,:] asmcld_sw_in = np.zeros((14,ncol,nz + n_ext),dtype=np.double,order='c')
cdef double [:,:,:] fsfcld_sw_in = np.zeros((14,ncol,nz + n_ext),dtype=np.double,order='c')
cdef double [:,:,:] tauaer_sw_in = np.zeros((ncol,nz + n_ext,14),dtype=np.double,order='c')
cdef double [:,:,:] ssaaer_sw_in = np.zeros((ncol,nz + n_ext,14),dtype=np.double,order='c')
cdef double [:,:,:] asmaer_sw_in = np.zeros((ncol,nz + n_ext,14),dtype=np.double,order='c')
cdef double [:,:,:] ecaer_sw_in = np.zeros((ncol,nz + n_ext,6),dtype=np.double,order='c')
# toc=timeit.default_timer()
# print 'Timer 4: ', toc-tic
# tic=toc
cdef double rv_to_reff = np.exp(np.log(1.2)**2.0)*10.0*1000.0
with nogil:
for i in prange(nxl-2*gw,schedule='static'):
# for i in xrange(nxl-2*gw):
for j in xrange(nyl-2*gw):
ishift = i + gw
jshift = j + gw
ijshift = i*(nyl-2*gw)+j
tsfc_in[ijshift] = surface_temperature
coszen_in[ijshift] = coszen
asdif_in[ijshift] = adif
aldif_in[ijshift] = adif
asdir_in[ijshift] = adir
aldir_in[ijshift] = adir
for k in xrange(16):
emis_in[ijshift, k] = 0.95
for k in xrange(nz + n_ext):
kshift = k + gw
play_in[ijshift, k] = pressure_ext[k]/100.0
plev_in[ijshift, k] = p0i_ext[k]/100.0
tlay_in[ijshift, k] = temperature_ext[i, j, k]
# tlev_in: a separate loop
h2ovmr_in[ijshift, k] = Rv/Ra*y_vapor_ext[i,j,k] * h2o_factor # Irrational Test Parameter...
o3vmr_in [ijshift, k] = o3vmr[k]
co2vmr_in[ijshift, k] = co2vmr[k]
ch4vmr_in[ijshift, k] = ch4vmr[k]
n2ovmr_in[ijshift, k] = n2ovmr[k]
o2vmr_in [ijshift, k] = o2vmr[k]
o3vmr_in [ijshift, k] = o3vmr[k]
cfc11vmr_in[ijshift, k] = cfc11vmr[k]
cfc12vmr_in[ijshift, k] = cfc12vmr[k]
cfc22vmr_in[ijshift, k] = cfc22vmr[k]
ccl4vmr_in[ijshift, k] = ccl4vmr[k]
cldfr_in[ijshift, k] = cloud_fraction_ext[i,j,k]
cliqwp_in[ijshift, k] = y_cond_ext[i,j,k]*1.0e3*(p0i_ext[k] - p0i_ext[k+1])/g
if uniform_reliq:
reliq_in[ijshift, k] = 14.0*cloud_fraction_ext[i,j,k]
else:
reliq_in[ijshift, k] = ((3.0*pressure_ext[k]/Ra/temperature_ext[i,j,k]*y_cond_ext[i,j,k]/
fmax(cloud_fraction_ext[i,j,k],1.0e-6))/(4.0*pi*1.0e3*100.0))**(1.0/3.0)
reliq_in[ijshift, k] = fmin(fmax(reliq_in[ijshift, k]*rv_to_reff, 2.5), 60.0)
tlev_in[ijshift, 0] = surface_temperature
for k in xrange(1,nz+n_ext):
tlev_in[ijshift, k] = 0.5*(tlay_in[ijshift,k-1]+tlay_in[ijshift,k])
tlev_in[ijshift, nz+n_ext] = 2.0*tlay_in[ijshift,nz+n_ext-1] - tlev_in[ijshift,nz+n_ext-1]
# toc=timeit.default_timer()
# print 'Timer 5: ', toc-tic
# tic=toc
# BEGIN: Debug Outputs
cdef double [:] play_in_ext_ = np.zeros(nz+ n_ext,dtype=np.double,order='c')
cdef double [:] plev_in_ext_ = np.zeros(nz+ n_ext +1,dtype=np.double,order='c')
cdef double [:] tlay_in_ext_ = np.zeros(nz+ n_ext,dtype=np.double,order='c')
cdef double [:] tlev_in_ext_ = np.zeros(nz+ n_ext +1,dtype=np.double,order='c')
cdef double [:] h2ovmr_in_ext_ = np.zeros(nz+ n_ext,dtype=np.double,order='c')
cdef double tsfc_in_ext_ = 0.0
cdef double [:] cldfr_in_ext_ = np.zeros(nz+ n_ext,dtype=np.double,order='c')
cdef double [:] cliqwp_in_ext_ = np.zeros(nz+ n_ext,dtype=np.double,order='c')
cdef double [:] reliq_in_ext_ = np.zeros(nz+ n_ext,dtype=np.double,order='c')
with nogil:
for i in xrange(ncol):
# ncol = (nxl-2*gw)*(nyl-2*gw)
for k in xrange(nz+n_ext+1):
plev_in_ext_[k] += plev_in[i,k] # Debug Outputs
tlev_in_ext_[k] += tlev_in[i,k] # Debug Outputs
for k in xrange(nz+n_ext):
play_in_ext_[k] += play_in[i,k] # Debug Outputs
tlay_in_ext_[k] += tlay_in[i,k] # Debug Outputs
h2ovmr_in_ext_[k] += h2ovmr_in[i,k] # Debug Outputs
cldfr_in_ext_[k] += cldfr_in[i,k] # Debug Outputs
cliqwp_in_ext_[k] += cliqwp_in[i,k] # Debug Outputs
reliq_in_ext_[k] += reliq_in[i,k] # Debug Outputs
tsfc_in_ext_ += tsfc_in[i]
cdef double [:] play_in_ext = np.zeros(nz+ n_ext,dtype=np.double,order='c')
cdef double [:] plev_in_ext = np.zeros(nz+ n_ext +1,dtype=np.double,order='c')
cdef double [:] tlay_in_ext = np.zeros(nz+ n_ext,dtype=np.double,order='c')
cdef double [:] tlev_in_ext = np.zeros(nz+ n_ext +1,dtype=np.double,order='c')
cdef double [:] h2ovmr_in_ext = np.zeros(nz+ n_ext,dtype=np.double,order='c')
cdef double tsfc_in_ext = 0.0
cdef double [:] cldfr_in_ext = np.zeros(nz+ n_ext,dtype=np.double,order='c')
cdef double [:] cliqwp_in_ext = np.zeros(nz+ n_ext,dtype=np.double,order='c')
cdef double [:] reliq_in_ext = np.zeros(nz+ n_ext,dtype=np.double,order='c')
comm.cart_comm.Allreduce(play_in_ext_, play_in_ext, op = MPI.SUM)
comm.cart_comm.Allreduce(plev_in_ext_, plev_in_ext, op = MPI.SUM)
comm.cart_comm.Allreduce(tlay_in_ext_, tlay_in_ext, op = MPI.SUM)
comm.cart_comm.Allreduce(tlev_in_ext_, tlev_in_ext, op = MPI.SUM)
comm.cart_comm.Allreduce(h2ovmr_in_ext_, h2ovmr_in_ext, op = MPI.SUM)
comm.cart_comm.Allreduce(cldfr_in_ext_, cldfr_in_ext, op = MPI.SUM)
comm.cart_comm.Allreduce(cliqwp_in_ext_, cliqwp_in_ext, op = MPI.SUM)
comm.cart_comm.Allreduce(reliq_in_ext_, reliq_in_ext, op = MPI.SUM)
#comm.cart_comm.Allreduce(tsfc_in_ext_, tsfc_in_ext, op = MPI.SUM)
with nogil:
for k in xrange(nz+n_ext+1):
# nxny = (nx * ny)
plev_in_ext[k] = plev_in_ext[k]/nxny # Debug Outputs
tlev_in_ext[k] = tlev_in_ext[k]/nxny # Debug Outputs
for k in xrange(nz+n_ext):
play_in_ext[k] = play_in_ext[k]/nxny # Debug Outputs
tlay_in_ext[k] = tlay_in_ext[k]/nxny # Debug Outputs
h2ovmr_in_ext[k] = h2ovmr_in_ext[k]/nxny # Debug Outputs
cldfr_in_ext[k] = cldfr_in_ext[k]/nxny # Debug Outputs
cliqwp_in_ext[k] = cliqwp_in_ext[k]/nxny # Debug Outputs
reliq_in_ext[k] = reliq_in_ext[k]/nxny # Debug Outputs
tsfc_in_ext = surface_temperature #tsfc_in_ext/nxny
if self.debug_mode:
self.play_in_ext = np.copy(play_in_ext)
self.plev_in_ext = np.copy(plev_in_ext)
self.tlay_in_ext = np.copy(tlay_in_ext)
self.tlev_in_ext = np.copy(tlev_in_ext)
self.h2ovmr_in_ext = np.copy(h2ovmr_in_ext)
self.cldfr_in_ext = np.copy(cldfr_in_ext)
self.cliqwp_in_ext = np.copy(cliqwp_in_ext)
self.reliq_in_ext = np.copy(reliq_in_ext)
self.tsfc_in_ext = np.copy(tsfc_in_ext)
if comm.rank == 0:
tic=timeit.default_timer()
# toc=timeit.default_timer()
# print 'Timer 6: ', toc-tic
# tic=toc
# np.set_printoptions(threshold=np.nan)
# if comm.rank == 0:
# print 'p0i_ext', self.p0i_ext[:]
# print 'pressure_ext', self.pressure_ext[:]
# print 'play_in_ext', self.play_in_ext[:]
# print 'plev_in_ext', self.plev_in_ext[:]
# print 'tlay_in_ext', self.tlay_in_ext[:]
# print 'tlev_in_ext', self.tlev_in_ext[:]
# print 'h2ovmr_in_ext', self.h2ovmr_in_ext[:]
# print 'cldfr_in_ext', self.cldfr_in_ext[:]
# print 'cliqwp_in_ext', self.cliqwp_in_ext[:]
# print 'tsfc_in_ext', self.tsfc_in_ext
# END: Debug Outputs
# Added: Initialize rrtmg_lw and rrtmg_sw
#rrtmg_lw.rrtmg_lw_init.rrtmg_lw_ini(np.float64(cpa))
#rrtmg_sw.rrtmg_sw_init.rrtmg_sw_ini(np.float64(cpa))
uflx_lw_out,dflx_lw_out,hr_lw_out,uflxc_lw_out,dflxc_lw_out,hrc_lw_out,duflx_dt_out,duflxc_dt_out = rrtmg_lw.rrtmg_lw_rad.rrtmg_lw(
1,0,play_in,plev_in,tlay_in,tlev_in,tsfc_in,
h2ovmr_in,o3vmr_in,co2vmr_in,ch4vmr_in,n2ovmr_in,o2vmr_in,
cfc11vmr_in,cfc12vmr_in,cfc22vmr_in,ccl4vmr_in,emis_in,
2,3,1,cldfr_in,
taucld_lw_in,cicewp_in,cliqwp_in,reice_in,reliq_in,tauaer_lw_in,
ncol, nz+n_ext)
# toc=timeit.default_timer()
# print 'Timer 7 (RRTM LW): ', toc-tic
# tic=toc
# Formulate: asdir, asdif, aldir, aldif, coszen, adjes, dyofyr, scon
uflx_sw_out, dflx_sw_out, hr_sw_out, uflxc_sw_out, dflxc_sw_out, hrc_sw_out, dirdflx_sw_out, difdflx_sw_out = rrtmg_sw.rrtmg_sw_rad.rrtmg_sw(
1, 0, 0, play_in,plev_in,tlay_in,tlev_in,tsfc_in,
h2ovmr_in, o3vmr_in, co2vmr_in, ch4vmr_in, n2ovmr_in, o2vmr_in,
asdir_in ,asdif_in ,aldir_in ,aldif_in ,
coszen_in ,adjes_in ,dyofyr_in ,scon_in ,
2, 3, 1, cldfr_in,
taucld_sw_in, ssacld_sw_in, asmcld_sw_in, fsfcld_sw_in,
cicewp_in, cliqwp_in, reice_in, reliq_in,
tauaer_sw_in, ssaaer_sw_in, asmaer_sw_in, ecaer_sw_in,
ncol, nz+n_ext)
# toc=timeit.default_timer()
# print 'Timer 8 (RRTM SW): ', toc-tic
# tic=toc
cdef double [:,:] uflx_lw = np.asarray(uflx_lw_out, dtype=np.double,order='c')
cdef double [:,:] dflx_lw = np.asarray(dflx_lw_out, dtype=np.double,order='c')
cdef double [:,:] hr_lw = np.asarray(hr_lw_out, dtype=np.double,order='c')
cdef double [:,:] uflxc_lw = np.asarray(uflxc_lw_out,dtype=np.double,order='c')
cdef double [:,:] dflxc_lw = np.asarray(dflxc_lw_out,dtype=np.double,order='c')
cdef double [:,:] hrc_lw = np.asarray(hrc_lw_out, dtype=np.double,order='c')
cdef double [:,:] uflx_sw = np.asarray(uflx_sw_out, dtype=np.double,order='c')
cdef double [:,:] dflx_sw = np.asarray(dflx_sw_out, dtype=np.double,order='c')
cdef double [:,:] hr_sw = np.asarray(hr_sw_out, dtype=np.double,order='c')
cdef double [:,:] uflxc_sw = np.asarray(uflxc_sw_out,dtype=np.double,order='c')
cdef double [:,:] dflxc_sw = np.asarray(dflxc_sw_out,dtype=np.double,order='c')
cdef double [:,:] hrc_sw = np.asarray(hrc_sw_out, dtype=np.double,order='c')
# Averaging using MPI ...
# Flux output dim: (ncol,nz + n_ext +1); heat-rate output dim: (ncol,nz + n_ext)
cdef double [:] lw_up_flux_ext_ = np.zeros(nz+ n_ext+1,dtype=np.double,order='c')
cdef double [:] lw_down_flux_ext_ = np.zeros(nz+ n_ext+1,dtype=np.double,order='c')
cdef double [:] sw_up_flux_ext_ = np.zeros(nz+ n_ext+1,dtype=np.double,order='c')
cdef double [:] sw_down_flux_ext_ = np.zeros(nz+ n_ext+1,dtype=np.double,order='c')
cdef double [:] lw_up_fluxc_ext_ = np.zeros(nz+ n_ext+1,dtype=np.double,order='c')
cdef double [:] lw_down_fluxc_ext_ = np.zeros(nz+ n_ext+1,dtype=np.double,order='c')
cdef double [:] sw_up_fluxc_ext_ = np.zeros(nz+ n_ext+1,dtype=np.double,order='c')
cdef double [:] sw_down_fluxc_ext_ = np.zeros(nz+ n_ext+1,dtype=np.double,order='c')
cdef double [:] lw_tt_ext_ = np.zeros(nz+ n_ext,dtype=np.double,order='c')
cdef double [:] sw_tt_ext_ = np.zeros(nz+ n_ext,dtype=np.double,order='c')
cdef double [:] total_tt_ext_ = np.zeros(nz+ n_ext,dtype=np.double,order='c')
cdef double [:] lw_ttc_ext_ = np.zeros(nz+ n_ext,dtype=np.double,order='c')
cdef double [:] sw_ttc_ext_ = np.zeros(nz+ n_ext,dtype=np.double,order='c')
cdef double [:] total_ttc_ext_ = np.zeros(nz+ n_ext,dtype=np.double,order='c')
with nogil:
for i in xrange(ncol):
# ncol = (nxl-2*gw)*(nyl-2*gw)
for k in xrange(nz+n_ext+1):
lw_up_flux_ext_[k] += uflx_lw[i,k]
lw_down_flux_ext_[k] += dflx_lw[i,k]
sw_up_flux_ext_[k] += uflx_sw[i,k]
sw_down_flux_ext_[k] += dflx_sw[i,k]
lw_up_fluxc_ext_[k] += uflxc_lw[i,k]
lw_down_fluxc_ext_[k] += dflxc_lw[i,k]
sw_up_fluxc_ext_[k] += uflxc_sw[i,k]
sw_down_fluxc_ext_[k] += dflxc_sw[i,k]
for k in xrange(nz+n_ext):
lw_tt_ext_[k] += hr_lw[i,k]
sw_tt_ext_[k] += hr_sw[i,k]
lw_ttc_ext_[k] += hrc_lw[i,k]
sw_ttc_ext_[k] += hrc_sw[i,k]
total_tt_ext_[k] += (hr_lw[i,k]+hr_sw[i,k])
total_ttc_ext_[k] += (hrc_lw[i,k]+hrc_sw[i,k])