forked from pressel/pycles
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInitialization.pyx
More file actions
2687 lines (2237 loc) · 106 KB
/
Initialization.pyx
File metadata and controls
2687 lines (2237 loc) · 106 KB
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
#!python
#cython: boundscheck=False
#cython: wraparound=True
#cython: initializedcheck=False
#cython: cdivision=True
import pylab as plt
import netCDF4 as nc
import numpy as np
cimport numpy as np
from scipy.interpolate import PchipInterpolator,pchip_interpolate
cimport ParallelMPI
from NetCDFIO cimport NetCDFIO_Stats
cimport Grid
cimport PrognosticVariables
cimport DiagnosticVariables
from thermodynamic_functions cimport exner_c, entropy_from_thetas_c, thetas_t_c, qv_star_c, thetas_c, thetali_c
cimport ReferenceState
from Forcing cimport AdjustedMoistAdiabat
from Thermodynamics cimport LatentHeat
from libc.math cimport sqrt, fmin, cos, exp, fabs
include 'parameters.pxi'
# import matplotlib.pyplot as plt
def InitializationFactory(namelist):
casename = namelist['meta']['casename']
if casename == 'SullivanPatton':
return InitSullivanPatton
elif casename == 'ColdPoolDry_2D':
print('calling Initialization ColdPoolDry 2D')
return InitColdPoolDry_2D
elif casename == 'ColdPoolDry_double_2D':
print('calling Initialization double ColdPoolDry 2D')
return InitColdPoolDry_double_2D
elif casename == 'ColdPoolDry_single_3D':
print('calling Initialization single ColdPoolDry 3D')
return InitColdPoolDry_single_3D
elif casename == 'ColdPoolDry_double_3D':
return InitColdPoolDry_double_3D
elif casename == 'ColdPoolDry_triple_3D':
return InitColdPoolDry_triple_3D
elif casename == 'ColdPoolDry_single_3D_stable':
return InitColdPoolDry_single_3D
elif casename == 'ColdPoolDry_triple_3D_stable':
return InitColdPoolDry_triple_3D
elif casename == 'StableBubble':
return InitStableBubble
elif casename == 'SaturatedBubble':
return InitSaturatedBubble
elif casename == 'Bomex':
return InitBomex
elif casename == 'Gabls':
return InitGabls
elif casename == 'DYCOMS_RF01':
return InitDYCOMS_RF01
elif casename == 'DYCOMS_RF02':
return InitDYCOMS_RF02
elif casename == 'SMOKE':
return InitSmoke
elif casename == 'Rico':
return InitRico
elif casename == 'Isdac':
return InitIsdac
elif casename == 'IsdacCC':
return InitIsdacCC
elif casename == 'Mpace':
return InitMpace
elif casename == 'Sheba':
return InitSheba
elif casename == 'CGILS':
return InitCGILS
elif casename == 'ZGILS':
return InitZGILS
elif casename == 'DCBLSoares':
return InitSoares
elif casename == 'DCBLSoares_moist':
return InitSoares_moist
else:
pass
def InitColdPoolDry_single_3D(namelist, Grid.Grid Gr,PrognosticVariables.PrognosticVariables PV,
ReferenceState.ReferenceState RS, Th, NetCDFIO_Stats NS,
ParallelMPI.ParallelMPI Pa, LatentHeat LH):
Pa.root_print('')
Pa.root_print('Initialization: Single Dry Cold Pool (3D)')
Pa.root_print('')
casename = namelist['meta']['casename']
# set zero ground humidity, no horizontal wind at ground
#Generate reference profiles
RS.Pg = 1.0e5
RS.Tg = 300.0
RS.qtg = 0.0
#Set velocities for Galilean transformation
RS.u0 = 0.0
RS.v0 = 0.0
RS.initialize(Gr, Th, NS, Pa)
Pa.root_print('finished RS.initialize')
#Get the variable number for each of the velocity components
cdef:
Py_ssize_t u_varshift = PV.get_varshift(Gr,'u')
Py_ssize_t v_varshift = PV.get_varshift(Gr,'v')
Py_ssize_t w_varshift = PV.get_varshift(Gr,'w')
Py_ssize_t s_varshift = PV.get_varshift(Gr,'s')
Py_ssize_t i,j,k
Py_ssize_t ishift, jshift
Py_ssize_t ijk
Py_ssize_t gw = Gr.dims.gw
# parameters
cdef:
double dTh = namelist['init']['dTh']
double rstar = namelist['init']['r'] # half of the width of initial cold-pools [m]
double zstar = namelist['init']['h']
Py_ssize_t kstar = np.int(np.round(zstar / Gr.dims.dx[2]))
double marg = namelist['init']['marg']
Py_ssize_t ic = np.int(namelist['init']['ic']) # np.int(Gr.dims.n[0] / 2)
Py_ssize_t jc = np.int(namelist['init']['jc']) # np.int(Gr.dims.n[1] / 2)
double xc = Gr.x_half[ic + Gr.dims.gw] # center of cold-pool
double yc = Gr.y_half[jc + Gr.dims.gw] # center of cold-pool
double [:,:,:] z_max_arr = np.zeros((2, Gr.dims.nlg[0], Gr.dims.nlg[1]), dtype=np.double)
double z_max = 0
double r
Pa.root_print('ic, jc: '+str(ic)+', '+str(jc))
Pa.root_print('xc, yc: '+str(xc)+', '+str(yc))
# theta anomaly
np.random.seed(Pa.rank) # make Noise reproducable
cdef:
double th
double th_g = 300.0 # temperature for neutrally stratified background (value from Soares Surface)
double [:] theta_bg = np.empty((Gr.dims.nlg[2]),dtype=np.double,order='c') # background stratification
double [:,:,:] theta = th_g * np.ones(shape=(Gr.dims.nlg[0], Gr.dims.nlg[1], Gr.dims.nlg[2]))
double [:] theta_pert = np.random.random_sample(Gr.dims.npg)
double theta_pert_
# initialize background stratification
if casename[22:28] == 'stable':
Pa.root_print('initializing stable CP')
Nv2 = 5e-5 # Brunt-Vaisalla frequency [Nv2] = s^-2
g = 9.81
for k in xrange(Gr.dims.nlg[2]):
if Gr.zl_half[k] <= 1000.:
theta_bg[k] = th_g
else:
theta_bg[k] = th_g * np.exp(Nv2/g*(Gr.zl_half[k]-1000.))
else:
for k in xrange(Gr.dims.nlg[2]):
theta_bg[k] = th_g
# initialize Cold Pool
for i in xrange(Gr.dims.nlg[0]):
ishift = i * Gr.dims.nlg[1] * Gr.dims.nlg[2]
for j in xrange(Gr.dims.nlg[1]):
jshift = j * Gr.dims.nlg[2]
r = np.sqrt( (Gr.x_half[i + Gr.dims.indx_lo[0]] - xc)**2 +
(Gr.y_half[j + Gr.dims.indx_lo[1]] - yc)**2 )
if r <= rstar:
z_max = zstar * ( np.cos( r/rstar * np.pi/2 ) ) ** 2
z_max_arr[0, i, j] = z_max
if r <= (rstar + marg):
z_max = (zstar + marg) * ( np.cos( r/(rstar + marg) * np.pi / 2 )) ** 2
z_max_arr[1, i, j] = z_max
for k in xrange(Gr.dims.nlg[2]):
ijk = ishift + jshift + k
theta[i, j, k] = theta_bg[k]
PV.values[u_varshift + ijk] = 0.0
PV.values[v_varshift + ijk] = 0.0
PV.values[w_varshift + ijk] = 0.0
if Gr.z_half[k] <= z_max_arr[0,i,j]:
theta[i,j,k] = theta_bg[k] - dTh
elif Gr.z_half[k] <= z_max_arr[1,i,j]:
th = theta_bg[k] - dTh * np.sin((Gr.z_half[k] - z_max_arr[1, i, j]) / (z_max_arr[0, i, j] - z_max_arr[1, i, j]) * np.pi/2) ** 2
theta[i, j, k] = th
if k <= kstar + 2:
theta_pert_ = (theta_pert[ijk] - 0.5) * 0.1
else:
theta_pert_ = 0.0
PV.values[s_varshift + ijk] = entropy_from_thetas_c(theta[i, j, k] + theta_pert_, 0.0)
# Sullivan, Bomex, etc.:
# t = (theta[k] + theta_pert_)*exner_c(RS.p0_half[k])
# PV.values[s_varshift + ijk] = Th.entropy(RS.p0_half[k],t,0.0,0.0,0.0)
# ''' Initialize passive tracer phi '''
Pa.root_print('initialize passive tracer phi')
init_tracer(namelist, Gr, PV, Pa, z_max_arr, np.asarray(ic), np.asarray(jc))
Pa.root_print('Initialization: finished initialization')
return
def InitColdPoolDry_single_3D_stable(namelist, Grid.Grid Gr,PrognosticVariables.PrognosticVariables PV,
ReferenceState.ReferenceState RS, Th, NetCDFIO_Stats NS,
ParallelMPI.ParallelMPI Pa, LatentHeat LH):
Pa.root_print('')
Pa.root_print('Initialization: Single Dry Cold Pool (3D)')
Pa.root_print('')
# set zero ground humidity, no horizontal wind at ground
#Generate reference profiles
RS.Pg = 1.0e5
RS.Tg = 300.0
RS.qtg = 0.0
#Set velocities for Galilean transformation
RS.u0 = 0.0
RS.v0 = 0.0
RS.initialize(Gr, Th, NS, Pa)
Pa.root_print('finished RS.initialize')
#Get the variable number for each of the velocity components
cdef:
Py_ssize_t u_varshift = PV.get_varshift(Gr,'u')
Py_ssize_t v_varshift = PV.get_varshift(Gr,'v')
Py_ssize_t w_varshift = PV.get_varshift(Gr,'w')
Py_ssize_t s_varshift = PV.get_varshift(Gr,'s')
Py_ssize_t i,j,k
Py_ssize_t ishift, jshift
Py_ssize_t ijk
Py_ssize_t gw = Gr.dims.gw
# parameters
cdef:
double dTh = namelist['init']['dTh']
double rstar = namelist['init']['r'] # half of the width of initial cold-pools [m]
double zstar = namelist['init']['h']
Py_ssize_t kstar = np.int(np.round(zstar / Gr.dims.dx[2]))
double marg = namelist['init']['marg']
Py_ssize_t ic = np.int(namelist['init']['ic']) # np.int(Gr.dims.n[0] / 2)
Py_ssize_t jc = np.int(namelist['init']['jc']) # np.int(Gr.dims.n[1] / 2)
double xc = Gr.x_half[ic + Gr.dims.gw] # center of cold-pool
double yc = Gr.y_half[jc + Gr.dims.gw] # center of cold-pool
double [:,:,:] z_max_arr = np.zeros((2, Gr.dims.nlg[0], Gr.dims.nlg[1]), dtype=np.double)
double z_max = 0
double r
double rstar_marg = (rstar+marg)
Pa.root_print('ic, jc: '+str(ic)+', '+str(jc))
Pa.root_print('xc, yc: '+str(xc)+', '+str(yc))
# theta anomaly
np.random.seed(Pa.rank) # make Noise reproducable
cdef:
double th
double th_g = 300.0 # temperature for neutrally stratified background (value from Soares Surface)
double [:] theta_bg = np.empty((Gr.dims.nlg[2]),dtype=np.double,order='c') # background stratification
double [:,:,:] theta = th_g * np.ones(shape=(Gr.dims.nlg[0], Gr.dims.nlg[1], Gr.dims.nlg[2]))
double [:] theta_pert = np.random.random_sample(Gr.dims.npg)
double theta_pert_
# crate background profile
Nv = 5e-5
g = 9.81
for k in xrange(Gr.dims.nlg[2]):
if Gr.zl_half[k] <= 1000.:
theta_bg[k] = th_g
else:
theta_bg[k] = th_g * np.exp(Nv/g*(Gr.zl_half[k]-1000.))
# Cold Pool
for i in xrange(Gr.dims.nlg[0]):
ishift = i * Gr.dims.nlg[1] * Gr.dims.nlg[2]
for j in xrange(Gr.dims.nlg[1]):
jshift = j * Gr.dims.nlg[2]
r = np.sqrt( (Gr.x_half[i + Gr.dims.indx_lo[0]] - xc)**2 +
(Gr.y_half[j + Gr.dims.indx_lo[1]] - yc)**2 )
if r <= rstar:
z_max = zstar * ( np.cos( r/rstar * np.pi/2 ) ) ** 2
z_max_arr[0, i, j] = z_max
if r <= rstar_marg:
z_max = (zstar + marg) * ( np.cos( r/(rstar + marg) * np.pi / 2 )) ** 2
z_max_arr[1, i, j] = z_max
for k in xrange(Gr.dims.nlg[2]):
ijk = ishift + jshift + k
theta[i, j, k] = theta_bg[k]
PV.values[u_varshift + ijk] = 0.0
PV.values[v_varshift + ijk] = 0.0
PV.values[w_varshift + ijk] = 0.0
if Gr.z_half[k] <= z_max_arr[0,i,j]:
theta[i,j,k] = theta[i,j,k] - dTh
elif Gr.z_half[k] <= z_max_arr[1,i,j]:
th = dTh * np.sin((Gr.z_half[k] - z_max_arr[1, i, j]) / (z_max_arr[0, i, j] - z_max_arr[1, i, j]) * np.pi/2) ** 2
theta[i, j, k] = theta[i,j,k] - th
if k <= kstar + 2:
theta_pert_ = (theta_pert[ijk] - 0.5) * 0.1
else:
theta_pert_ = 0.0
PV.values[s_varshift + ijk] = entropy_from_thetas_c(theta[i, j, k] + theta_pert_, 0.0)
# ''' Initialize passive tracer phi '''
Pa.root_print('initialize passive tracer phi')
init_tracer(namelist, Gr, PV, Pa, z_max_arr, np.asarray(ic), np.asarray(jc))
Pa.root_print('Initialization: finished initialization')
return
def InitColdPoolDry_double_3D(namelist, Grid.Grid Gr,PrognosticVariables.PrognosticVariables PV,
ReferenceState.ReferenceState RS, Th, NetCDFIO_Stats NS,
ParallelMPI.ParallelMPI Pa, LatentHeat LH):
Pa.root_print('')
Pa.root_print('Initialization: Double Dry Cold Pool (3D)')
Pa.root_print('')
# set zero ground humidity, no horizontal wind at ground
# ASSUME COLDPOOLS DON'T HAVE AN INITIAL HORIZONTAL VELOCITY
# # for plotting
#from Init_plot import plot_k_profile_3D, plot_var_image, plot_imshow
cdef:
PrognosticVariables.PrognosticVariables PV_ = PV
#Generate reference profiles
RS.Pg = 1.0e5
RS.Tg = 300.0
RS.qtg = 0.0
#Set velocities for Galilean transformation
RS.u0 = 0.0
RS.v0 = 0.0
RS.initialize(Gr, Th, NS, Pa)
#Get the variable number for each of the velocity components
cdef:
Py_ssize_t u_varshift = PV.get_varshift(Gr,'u')
Py_ssize_t v_varshift = PV.get_varshift(Gr,'v')
Py_ssize_t w_varshift = PV.get_varshift(Gr,'w')
Py_ssize_t s_varshift = PV.get_varshift(Gr,'s')
Py_ssize_t i,j,k
Py_ssize_t ishift, jshift
Py_ssize_t ijk
Py_ssize_t gw = Gr.dims.gw
# parameters
cdef:
double dTh = namelist['init']['dTh']
double rstar = namelist['init']['r'] # half of the width of initial cold-pools [m]
double zstar = namelist['init']['h']
Py_ssize_t kstar = np.int(np.round(zstar / Gr.dims.dx[2]))
double marg = namelist['init']['marg']
double [:] r = np.ndarray((2), dtype=np.double)
double [:] r2 = np.ndarray((2), dtype=np.double)
double rstar2 = rstar**2
double rstar_marg2 = (rstar+marg)**2
Py_ssize_t n, nmin
# geometry of cold pool
cdef:
double sep = namelist['init']['sep']
Py_ssize_t isep = np.int(np.round(sep/Gr.dims.dx[0]))
Py_ssize_t jsep = 0
Py_ssize_t ic = np.int(np.round(Gr.dims.n[0]/2))
Py_ssize_t jc = np.int(np.round(Gr.dims.n[1]/2))
Py_ssize_t ic1 = ic - np.int(np.round(isep / 2))
Py_ssize_t jc1 = jc
Py_ssize_t ic2 = ic1 + isep
Py_ssize_t jc2 = jc1 + jsep
Py_ssize_t [:] ic_arr = np.asarray([ic1,ic2])
Py_ssize_t [:] jc_arr = np.asarray([jc1,jc2])
double [:] xc = np.asarray([Gr.x_half[ic1 + gw], Gr.x_half[ic2 + gw]])
double [:] yc = np.asarray([Gr.y_half[jc1 + gw], Gr.y_half[jc2 + gw]])
double [:,:,:] z_max_arr = np.zeros((2, Gr.dims.ng[0], Gr.dims.ng[1]), dtype=np.double)
double z_max = 0
# theta-anomaly
np.random.seed(Pa.rank) # make Noise reproducable
# from thermodynamic_functions cimport theta_c
cdef:
double th
double th_g = 300.0 # value from Soares Surface
double [:,:,:] theta = th_g * np.ones(shape=(Gr.dims.nlg[0], Gr.dims.nlg[1], Gr.dims.nlg[2]))
double [:] theta_pert = np.random.random_sample(Gr.dims.npg)
# qt_pert = (np.random.random_sample(Gr.dims.npg )-0.5)*0.025/1000.0
double theta_pert_
''' compute z_max '''
# method here requires to define (ic1, jc1) as the CP center that is the closest to (0,0)
# (i.e., ic1<=ic2, jc1<=jc2 etc.)
for i in xrange(Gr.dims.nlg[0]):
ishift = i * Gr.dims.nlg[1] * Gr.dims.nlg[2]
for j in xrange(Gr.dims.nlg[1]):
jshift = j * Gr.dims.nlg[2]
# r = np.sqrt((Gr.x_half[i]-xc1)**2 + (Gr.y_half[j]-yc1)**2) # not MPI-compatible
for n in range(2):
r[n] = np.sqrt( (Gr.x_half[i + Gr.dims.indx_lo[0]] - xc[n])**2 +
(Gr.y_half[j + Gr.dims.indx_lo[1]] - yc[n])**2 )
nmin = np.argmin(r) # find closest CP to point (i,j); making use of having non-overlapping CPs
if (r[nmin] <= (rstar + marg)):
z_max = (zstar + marg) * ( np.cos( r[nmin]/(rstar + marg) * np.pi / 2 )) ** 2
z_max_arr[1, i, j] = z_max
z_max_arr[1, i+isep, j+jsep] = z_max
if (r[nmin] <= rstar):
z_max = zstar * ( np.cos( r[nmin]/rstar * np.pi/2 ) ) ** 2
z_max_arr[0, i, j] = z_max
z_max_arr[0, i+isep, j+jsep] = z_max
for k in xrange(Gr.dims.nlg[2]):
ijk = ishift + jshift + k
PV.values[u_varshift + ijk] = 0.0
PV.values[v_varshift + ijk] = 0.0
PV.values[w_varshift + ijk] = 0.0
if Gr.z_half[k] <= z_max_arr[0,i,j]:
theta[i,j,k] = th_g - dTh
elif Gr.z_half[k] <= z_max_arr[1,i,j]:
th = th_g - dTh * np.sin((Gr.z_half[k] - z_max_arr[1, i, j]) / (z_max_arr[0, i, j] - z_max_arr[1, i, j]) * np.pi/2) ** 2
theta[i, j, k] = th
# --- adding noise ---
# Sullivan, DYCOMS RF01: Gr.zl_half[k] < 200.0
# Bomex: Gr.zl_half[k] < 1600.0
# Gabls: Gr.zl_half[k] < 50.0 (well-mixed layer for z<=100.0)
# DYCOMS RF02: Gr.zl_half[k] < 795.0
# Rico: < 740.0 (in well-mixed layer)
# Isdac: < 825.0 (below stably stratified layer)
# Smoke: < 700.0 (in well-mixed layer)
if k <= kstar + 2:
theta_pert_ = (theta_pert[ijk] - 0.5) * 0.1
else:
theta_pert_ = 0.0
PV.values[s_varshift + ijk] = entropy_from_thetas_c(theta[i, j, k] + theta_pert_, 0.0)
''' Initialize passive tracer phi '''
Pa.root_print('initialize passive tracer phi')
init_tracer(namelist, Gr, PV, Pa, z_max_arr, ic_arr, jc_arr)
Pa.root_print('Initialization: finished initialization')
return
def InitColdPoolDry_triple_3D(namelist, Grid.Grid Gr,PrognosticVariables.PrognosticVariables PV,
ReferenceState.ReferenceState RS, Th, NetCDFIO_Stats NS,
ParallelMPI.ParallelMPI Pa, LatentHeat LH):
Pa.root_print('')
Pa.root_print('Initialization: Triple Dry Cold Pool (3D)')
Pa.root_print('')
casename = namelist['meta']['casename']
# set zero ground humidity, no horizontal wind at ground
# ASSUME COLDPOOLS DON'T HAVE AN INITIAL HORIZONTAL VELOCITY
#Generate reference profiles
RS.Pg = 1.0e5
RS.Tg = 300.0
RS.qtg = 0.0
#Set velocities for Galilean transformation
RS.u0 = 0.0
RS.v0 = 0.0
RS.initialize(Gr, Th, NS, Pa)
#Get the variable number for each of the velocity components
cdef:
Py_ssize_t u_varshift = PV.get_varshift(Gr,'u')
Py_ssize_t v_varshift = PV.get_varshift(Gr,'v')
Py_ssize_t w_varshift = PV.get_varshift(Gr,'w')
Py_ssize_t s_varshift = PV.get_varshift(Gr,'s')
Py_ssize_t i,j,k
Py_ssize_t ishift, jshift
Py_ssize_t ijk
Py_ssize_t gw = Gr.dims.gw
# parameters
cdef:
double dTh = namelist['init']['dTh']
double rstar = namelist['init']['r'] # half of the width of initial cold-pools [m]
double zstar = namelist['init']['h']
Py_ssize_t kstar = np.int(np.round(zstar / Gr.dims.dx[2]))
double marg = namelist['init']['marg']
double [:] r = np.ndarray((3), dtype=np.double)
Py_ssize_t n, nmin
# geometry of cold pool: equilateral triangle with center in middle of domain
# d: side length of the triangle
# a: height of the equilateral triangle
# configuration: ic1 = ic2, ic3 = ic1+a; jc
cdef:
double d = namelist['init']['d']
Py_ssize_t i_d = np.int(np.round(d/Gr.dims.dx[0]))
Py_ssize_t idhalf = np.int(np.round(i_d/2))
Py_ssize_t a = np.int(np.round(i_d*np.sin(60.0/360.0*2*np.pi))) # sin(60 degree) = np.sqrt(3)/2
Py_ssize_t r_int = np.int(np.round(np.sqrt(3.)/6*i_d)) # radius of inscribed circle
# point of 3-CP collision (ic, jc)
Py_ssize_t ic = np.int(np.round(Gr.dims.n[0]/2))
Py_ssize_t jc = np.int(np.round(Gr.dims.n[1]/2))
Py_ssize_t ic1 = ic - r_int
Py_ssize_t ic2 = ic1
Py_ssize_t ic3 = ic + (a - r_int)
Py_ssize_t jc1 = jc - idhalf
Py_ssize_t jc2 = jc + idhalf
Py_ssize_t jc3 = jc
Py_ssize_t [:] ic_arr = np.asarray([ic1,ic2,ic3])
Py_ssize_t [:] jc_arr = np.asarray([jc1,jc2,jc3])
double [:] xc = np.asarray([Gr.x_half[ic1 + gw], Gr.x_half[ic2 + gw], Gr.x_half[ic3 + gw]])
double [:] yc = np.asarray([Gr.y_half[jc1 + gw], Gr.y_half[jc2 + gw], Gr.y_half[jc3 + gw]])
double [:,:,:] z_max_arr = np.zeros((2, Gr.dims.nlg[0], Gr.dims.nlg[1]), dtype=np.double)
double z_max = 0
# theta-anomaly
np.random.seed(Pa.rank) # make Noise reproducable
cdef:
double th
double th_g = 300.0 # value from Soares Surface
double [:] theta_bg = np.empty((Gr.dims.nlg[2]),dtype=np.double,order='c') # background stratification
double [:,:,:] theta = th_g * np.ones(shape=(Gr.dims.nlg[0], Gr.dims.nlg[1], Gr.dims.nlg[2]))
# Noise
double [:] theta_pert = np.random.random_sample(Gr.dims.npg)
# qt_pert = (np.random.random_sample(Gr.dims.npg )-0.5)*0.025/1000.0
double theta_pert_
# initialize background stratification
if casename[22:28] == 'stable':
Pa.root_print('initializing stable CP')
Nv = 5e-5
g = 9.81
for k in xrange(Gr.dims.nlg[2]):
if Gr.zl_half[k] <= 1000.:
theta_bg[k] = th_g
else:
theta_bg[k] = th_g * np.exp(Nv/g*(Gr.zl_half[k]-1000.))
else:
for k in xrange(Gr.dims.nlg[2]):
theta_bg[k] = th_g
Pa.root_print('initial settings: r='+str(rstar)+', z='+str(zstar)+', k='+str(kstar))
Pa.root_print('margin of Th-anomaly: marg='+str(marg)+'m')
Pa.root_print('distance btw cps: d='+str(d*Gr.dims.dx[0])+', id='+str(d))
Pa.root_print('')
Pa.root_print('nx: ' + str(Gr.dims.n[0]) + ', ' + str(Gr.dims.n[1]))
Pa.root_print('nyg: ' + str(Gr.dims.ng[0]) + ', ' + str(Gr.dims.ng[1]))
Pa.root_print('gw: ' + str(Gr.dims.gw))
Pa.root_print('d: ' + str(d) + ', id: ' + str(i_d))
Pa.root_print('Cold Pools:')
Pa.root_print('cp1: [' + str(ic1) + ', ' + str(jc1) + ']')
Pa.root_print('cp2: [' + str(ic2) + ', ' + str(jc2) + ']')
Pa.root_print('cp3: [' + str(ic3) + ', ' + str(jc3) + ']')
Pa.root_print('')
''' compute z_max '''
for i in xrange(Gr.dims.nlg[0]):
ishift = i * Gr.dims.nlg[1] * Gr.dims.nlg[2]
for j in xrange(Gr.dims.nlg[1]):
jshift = j * Gr.dims.nlg[2]
for n in range(3):
r[n] = np.sqrt( (Gr.x_half[i + Gr.dims.indx_lo[0]] - xc[n])**2 +
(Gr.y_half[j + Gr.dims.indx_lo[1]] - yc[n])**2 )
nmin = np.argmin(r) # find closest CP to point (i,j); making use of having non-overlapping CPs
if (r[nmin] <= (rstar + marg)):
z_max = (zstar + marg) * ( np.cos( r[nmin]/(rstar + marg) * np.pi / 2 )) ** 2
z_max_arr[1, i, j] = z_max
if (r[nmin] <= rstar):
z_max = zstar * ( np.cos( r[nmin]/rstar * np.pi / 2 )) ** 2
z_max_arr[0, i, j] = z_max
for k in xrange(Gr.dims.nlg[2]):
ijk = ishift + jshift + k
theta[i, j, k] = theta_bg[k]
PV.values[u_varshift + ijk] = 0.0
PV.values[v_varshift + ijk] = 0.0
PV.values[w_varshift + ijk] = 0.0
if Gr.z_half[k] <= z_max_arr[0,i,j]:
theta[i,j,k] = theta_bg[k] - dTh
elif Gr.z_half[k] <= z_max_arr[1,i,j]:
th = theta_bg[k] - dTh * np.sin((Gr.z_half[k] - z_max_arr[1, i, j]) / (z_max_arr[0, i, j] - z_max_arr[1, i, j]) * np.pi/2) ** 2
theta[i, j, k] = th
# --- adding noise ---
if k <= kstar + 2:
theta_pert_ = (theta_pert[ijk] - 0.5) * 0.1
else:
theta_pert_ = 0.0
PV.values[s_varshift + ijk] = entropy_from_thetas_c(theta[i, j, k] + theta_pert_, 0.0)
''' Initialize passive tracer phi '''
Pa.root_print('initialize passive tracer phi')
init_tracer(namelist, Gr, PV, Pa, z_max_arr, ic_arr, jc_arr)
Pa.root_print('Initialization: finished initialization')
return
def InitStableBubble(namelist, Grid.Grid Gr,PrognosticVariables.PrognosticVariables PV,
ReferenceState.ReferenceState RS, Th, NetCDFIO_Stats NS, ParallelMPI.ParallelMPI Pa, LatentHeat LH):
#Generate reference profiles
RS.Pg = 1.0e5
RS.Tg = 300.0
RS.qtg = 0.0
#Set velocities for Galilean transformation
RS.u0 = 0.0
RS.v0 = 0.0
RS.initialize(Gr, Th, NS, Pa)
#Get the variable number for each of the velocity components
cdef:
Py_ssize_t u_varshift = PV.get_varshift(Gr,'u')
Py_ssize_t v_varshift = PV.get_varshift(Gr,'v')
Py_ssize_t w_varshift = PV.get_varshift(Gr,'w')
Py_ssize_t s_varshift = PV.get_varshift(Gr,'s')
Py_ssize_t i,j,k
Py_ssize_t ishift, jshift
Py_ssize_t ijk
double t
double dist
t_min = 9999.9
for i in xrange(Gr.dims.nlg[0]):
ishift = i * Gr.dims.nlg[1] * Gr.dims.nlg[2]
for j in xrange(Gr.dims.nlg[1]):
jshift = j * Gr.dims.nlg[2]
for k in xrange(Gr.dims.nlg[2]):
ijk = ishift + jshift + k
PV.values[u_varshift + ijk] = 0.0
PV.values[v_varshift + ijk] = 0.0
PV.values[w_varshift + ijk] = 0.0
# dist = np.sqrt(((Gr.x_half[i + Gr.dims.indx_lo[0]]/1000.0 - 25.6)/4.0)**2.0 + ((Gr.z_half[k + Gr.dims.indx_lo[2]]/1000.0 - 3.0)/2.0)**2.0)
# dist = np.sqrt(((Gr.x_half[i + Gr.dims.indx_lo[0]]/1000.0 - 25.6)/8.0)**2.0 + ((Gr.z_half[k + Gr.dims.indx_lo[2]]/1000.0 - 3.0)/2.0)**2.0)
dist = np.sqrt(((Gr.y_half[j + Gr.dims.indx_lo[1]]/1000.0 - 25.6)/4.0)**2.0 + ((Gr.z_half[k + Gr.dims.indx_lo[2]]/1000.0 - 10.0)/1.2)**2.0) # changed since VisualizationOutput defined in yz-plane
dist = fmin(dist,1.0)
t = (300.0 )*exner_c(RS.p0_half[k]) - 15.0*( cos(np.pi * dist) + 1.0) /2.0
PV.values[s_varshift + ijk] = Th.entropy(RS.p0_half[k],t,0.0,0.0,0.0)
return
def InitSaturatedBubble(namelist,Grid.Grid Gr,PrognosticVariables.PrognosticVariables PV,
ReferenceState.ReferenceState RS, Th, NetCDFIO_Stats NS, ParallelMPI.ParallelMPI Pa, LatentHeat LH ):
#Generate reference profiles
RS.Pg = 1.0e5
RS.qtg = 0.02
#RS.Tg = 300.0
thetas_sfc = 320.0
qt_sfc = 0.0196 #RS.qtg
RS.qtg = qt_sfc
#Set velocities for Galilean transformation
RS.u0 = 0.0
RS.v0 = 0.0
def theta_to_T(p0_,thetas_,qt_):
T1 = Tt
T2 = Tt + 1.
pv1 = Th.get_pv_star(T1)
pv2 = Th.get_pv_star(T2)
qs1 = qv_star_c(p0_, RS.qtg,pv1)
ql1 = np.max([0.0,qt_ - qs1])
L1 = Th.get_lh(T1)
f1 = thetas_ - thetas_t_c(p0_,T1,qt_,qt_-ql1,ql1,L1)
delta = np.abs(T1 - T2)
while delta >= 1e-12:
L2 = Th.get_lh(T2)
pv2 = Th.get_pv_star(T2)
qs2 = qv_star_c(p0_, RS.qtg, pv2)
ql2 = np.max([0.0,qt_ - qs2])
f2 = thetas_ - thetas_t_c(p0_,T2,qt_,qt_-ql2,ql2,L2)
Tnew = T2 - f2 * (T2 - T1)/(f2 - f1)
T1 = T2
T2 = Tnew
f1 = f2
delta = np.abs(T1 - T2)
return T2, ql2
RS.Tg, ql = theta_to_T(RS.Pg,thetas_sfc,qt_sfc)
RS.initialize(Gr, Th, NS, Pa)
#Get the variable number for each of the velocity components
cdef:
Py_ssize_t u_varshift = PV.get_varshift(Gr,'u')
Py_ssize_t v_varshift = PV.get_varshift(Gr,'v')
Py_ssize_t w_varshift = PV.get_varshift(Gr,'w')
Py_ssize_t s_varshift = PV.get_varshift(Gr,'s')
Py_ssize_t qt_varshift = PV.get_varshift(Gr,'qt')
Py_ssize_t i,j,k
Py_ssize_t ishift, jshift
Py_ssize_t ijk
double t
double dist
double thetas
for i in xrange(Gr.dims.nlg[0]):
ishift = i * Gr.dims.nlg[1] * Gr.dims.nlg[2]
for j in xrange(Gr.dims.nlg[1]):
jshift = j * Gr.dims.nlg[2]
for k in xrange(Gr.dims.nlg[2]):
ijk = ishift + jshift + k
dist = np.sqrt(((Gr.x_half[i + Gr.dims.indx_lo[0]]/1000.0 - 10.0)/2.0)**2.0 + ((Gr.z_half[k + Gr.dims.indx_lo[2]]/1000.0 - 2.0)/2.0)**2.0)
dist = np.minimum(1.0,dist)
thetas = RS.Tg
thetas += 2.0 * np.cos(np.pi * dist / 2.0)**2.0
PV.values[s_varshift + ijk] = entropy_from_thetas_c(thetas,RS.qtg)
PV.values[u_varshift + ijk] = 0.0 - RS.u0
PV.values[v_varshift + ijk] = 0.0 - RS.v0
PV.values[w_varshift + ijk] = 0.0
PV.values[qt_varshift + ijk] = RS.qtg
return
def InitSullivanPatton(namelist,Grid.Grid Gr,PrognosticVariables.PrognosticVariables PV,
ReferenceState.ReferenceState RS, Th, NetCDFIO_Stats NS,
ParallelMPI.ParallelMPI Pa, LatentHeat LH ):
#Generate the reference profiles
RS.Pg = 1.0e5 #Pressure at ground
RS.Tg = 300.0 #Temperature at ground
RS.qtg = 0.0 #Total water mixing ratio at surface
RS.u0 = 1.0 # velocities removed in Galilean transformation
RS.v0 = 0.0
RS.initialize(Gr, Th, NS, Pa)
#Get the variable number for each of the velocity components
np.random.seed(Pa.rank)
cdef:
Py_ssize_t u_varshift = PV.get_varshift(Gr,'u')
Py_ssize_t v_varshift = PV.get_varshift(Gr,'v')
Py_ssize_t w_varshift = PV.get_varshift(Gr,'w')
Py_ssize_t s_varshift = PV.get_varshift(Gr,'s')
Py_ssize_t i,j,k
Py_ssize_t ishift, jshift, e_varshift
Py_ssize_t ijk
double [:] theta = np.empty((Gr.dims.nlg[2]),dtype=np.double,order='c')
double t
#Generate initial perturbations (here we are generating more than we need)
cdef double [:] theta_pert = np.random.random_sample(Gr.dims.npg)
cdef double theta_pert_
for k in xrange(Gr.dims.nlg[2]):
if Gr.zl_half[k] <= 974.0:
theta[k] = 300.0
elif Gr.zl_half[k] <= 1074.0:
theta[k] = 300.0 + (Gr.zl_half[k] - 974.0) * 0.08
else:
theta[k] = 308.0 + (Gr.zl_half[k] - 1074.0) * 0.003
cdef double [:] p0 = RS.p0_half
#Now loop and set the initial condition
for i in xrange(Gr.dims.nlg[0]):
ishift = i * Gr.dims.nlg[1] * Gr.dims.nlg[2]
for j in xrange(Gr.dims.nlg[1]):
jshift = j * Gr.dims.nlg[2]
for k in xrange(Gr.dims.nlg[2]):
ijk = ishift + jshift + k
PV.values[u_varshift + ijk] = 1.0 - RS.u0
PV.values[v_varshift + ijk] = 0.0 - RS.v0
PV.values[w_varshift + ijk] = 0.0
#Now set the entropy prognostic variable including a potential temperature perturbation
if Gr.zl_half[k] < 200.0:
theta_pert_ = (theta_pert[ijk] - 0.5)* 0.1
else:
theta_pert_ = 0.0
t = (theta[k] + theta_pert_)*exner_c(RS.p0_half[k])
PV.values[s_varshift + ijk] = Th.entropy(RS.p0_half[k],t,0.0,0.0,0.0)
if 'e' in PV.name_index:
e_varshift = PV.get_varshift(Gr, 'e')
for i in xrange(Gr.dims.nlg[0]):
ishift = i * Gr.dims.nlg[1] * Gr.dims.nlg[2]
for j in xrange(Gr.dims.nlg[1]):
jshift = j * Gr.dims.nlg[2]
for k in xrange(Gr.dims.nlg[2]):
ijk = ishift + jshift + k
PV.values[e_varshift + ijk] = 0.0
return
def InitBomex(namelist,Grid.Grid Gr,PrognosticVariables.PrognosticVariables PV,
ReferenceState.ReferenceState RS, Th, NetCDFIO_Stats NS,
ParallelMPI.ParallelMPI Pa, LatentHeat LH ):
# First generate the reference profiles
RS.Pg = 1.015e5 #Pressure at ground
RS.Tg = 300.4 #Temperature at ground
RS.qtg = 0.02245 #Total water mixing ratio at surface
RS.initialize(Gr, Th, NS, Pa)
try:
random_seed_factor = namelist['initialization']['random_seed_factor']
except:
random_seed_factor = 1
np.random.seed(Pa.rank * random_seed_factor)
# Get the variable number for each of the velocity components
cdef:
Py_ssize_t u_varshift = PV.get_varshift(Gr,'u')
Py_ssize_t v_varshift = PV.get_varshift(Gr,'v')
Py_ssize_t w_varshift = PV.get_varshift(Gr,'w')
Py_ssize_t s_varshift = PV.get_varshift(Gr,'s')
Py_ssize_t qt_varshift = PV.get_varshift(Gr,'qt')
Py_ssize_t i,j,k
Py_ssize_t ishift, jshift
Py_ssize_t ijk, e_varshift
double temp
double qt_
double [:] thetal = np.empty((Gr.dims.nlg[2]),dtype=np.double,order='c')
double [:] qt = np.empty((Gr.dims.nlg[2]),dtype=np.double,order='c')
double [:] u = np.empty((Gr.dims.nlg[2]),dtype=np.double,order='c')
Py_ssize_t count
theta_pert = (np.random.random_sample(Gr.dims.npg )-0.5)*0.1
qt_pert = (np.random.random_sample(Gr.dims.npg )-0.5)*0.025/1000.0
for k in xrange(Gr.dims.nlg[2]):
# Set Thetal profile
if Gr.zl_half[k] <= 520.:
thetal[k] = 298.7
elif Gr.zl_half[k] > 520.0 and Gr.zl_half[k] <= 1480.0: # 3.85 K / km
thetal[k] = 298.7 + (Gr.zl_half[k] - 520) * (302.4 - 298.7)/(1480.0 - 520.0)
elif Gr.zl_half[k] > 1480.0 and Gr.zl_half[k] <= 2000: # 11.15 K / km
thetal[k] = 302.4 + (Gr.zl_half[k] - 1480.0) * (308.2 - 302.4)/(2000.0 - 1480.0)
elif Gr.zl_half[k] > 2000.0: # 3.65 K / km
thetal[k] = 308.2 + (Gr.zl_half[k] - 2000.0) * (311.85 - 308.2)/(3000.0 - 2000.0)
# Set qt profile
if Gr.zl_half[k] <= 520:
qt[k] = 17.0 + (Gr.zl_half[k]) * (16.3-17.0)/520.0
if Gr.zl_half[k] > 520.0 and Gr.zl_half[k] <= 1480.0:
qt[k] = 16.3 + (Gr.zl_half[k] - 520.0)*(10.7 - 16.3)/(1480.0 - 520.0)
if Gr.zl_half[k] > 1480.0 and Gr.zl_half[k] <= 2000.0:
qt[k] = 10.7 + (Gr.zl_half[k] - 1480.0) * (4.2 - 10.7)/(2000.0 - 1480.0)
if Gr.zl_half[k] > 2000.0:
qt[k] = 4.2 + (Gr.zl_half[k] - 2000.0) * (3.0 - 4.2)/(3000.0 - 2000.0)
# Change units to kg/kg
qt[k]/= 1000.0
# Set u profile
if Gr.zl_half[k] <= 700.0:
u[k] = -8.75
if Gr.zl_half[k] > 700.0:
u[k] = -8.75 + (Gr.zl_half[k] - 700.0) * (-4.61 - -8.75)/(3000.0 - 700.0)
# Set velocities for Galilean transformation
RS.v0 = 0.0
RS.u0 = 0.5 * (np.amax(u)+np.amin(u))
# Now loop and set the initial condition
# First set the velocities
count = 0
for i in xrange(Gr.dims.nlg[0]):
ishift = i * Gr.dims.nlg[1] * Gr.dims.nlg[2]
for j in xrange(Gr.dims.nlg[1]):
jshift = j * Gr.dims.nlg[2]
for k in xrange(Gr.dims.nlg[2]):
ijk = ishift + jshift + k
PV.values[u_varshift + ijk] = u[k] - RS.u0
PV.values[v_varshift + ijk] = 0.0 - RS.v0
PV.values[w_varshift + ijk] = 0.0
if Gr.zl_half[k] <= 1600.0:
temp = (thetal[k] + (theta_pert[count])) * exner_c(RS.p0_half[k])
qt_ = qt[k]+qt_pert[count]
else:
temp = (thetal[k]) * exner_c(RS.p0_half[k])
qt_ = qt[k]
PV.values[s_varshift + ijk] = Th.entropy(RS.p0_half[k],temp,qt_,0.0,0.0)
PV.values[qt_varshift + ijk] = qt_
count += 1
if 'e' in PV.name_index:
e_varshift = PV.get_varshift(Gr, 'e')
for i in xrange(Gr.dims.nlg[0]):
ishift = i * Gr.dims.nlg[1] * Gr.dims.nlg[2]
for j in xrange(Gr.dims.nlg[1]):
jshift = j * Gr.dims.nlg[2]
for k in xrange(Gr.dims.nlg[2]):
ijk = ishift + jshift + k
PV.values[e_varshift + ijk] = 1.0-Gr.zl_half[k]/3000.0
return
def InitGabls(namelist,Grid.Grid Gr, PrognosticVariables.PrognosticVariables PV,
ReferenceState.ReferenceState RS, Th, NetCDFIO_Stats NS, ParallelMPI.ParallelMPI Pa, LatentHeat LH ):
#Generate the reference profiles
RS.Pg = 1.0e5 #Pressure at ground
RS.Tg = 265.0 #Temperature at ground
RS.qtg = 0.0 #Total water mixing ratio at surface
RS.u0 = 8.0 # velocities removed in Galilean transformation
RS.v0 = 0.0
RS.initialize(Gr, Th, NS, Pa)
#Get the variable number for each of the velocity components
np.random.seed(Pa.rank)
cdef:
Py_ssize_t u_varshift = PV.get_varshift(Gr,'u')
Py_ssize_t v_varshift = PV.get_varshift(Gr,'v')
Py_ssize_t w_varshift = PV.get_varshift(Gr,'w')
Py_ssize_t s_varshift = PV.get_varshift(Gr,'s')
Py_ssize_t i,j,k
Py_ssize_t ishift, jshift, e_varshift
Py_ssize_t ijk
double [:] theta = np.empty((Gr.dims.nlg[2]),dtype=np.double,order='c')
double t
#Generate initial perturbations (here we are generating more than we need)
cdef double [:] theta_pert = np.random.random_sample(Gr.dims.npg)
cdef double theta_pert_
for k in xrange(Gr.dims.nlg[2]):
if Gr.zl_half[k] <= 100.0:
theta[k] = 265.0
else:
theta[k] = 265.0 + (Gr.zl_half[k] - 100.0) * 0.01
cdef double [:] p0 = RS.p0_half
#Now loop and set the initial condition
#First set the velocities
for i in xrange(Gr.dims.nlg[0]):
ishift = i * Gr.dims.nlg[1] * Gr.dims.nlg[2]
for j in xrange(Gr.dims.nlg[1]):
jshift = j * Gr.dims.nlg[2]
for k in xrange(Gr.dims.nlg[2]):
ijk = ishift + jshift + k
PV.values[u_varshift + ijk] = 8.0 - RS.u0
PV.values[v_varshift + ijk] = 0.0 - RS.v0
PV.values[w_varshift + ijk] = 0.0
#Now set the entropy prognostic variable including a potential temperature perturbation
if Gr.zl_half[k] < 50.0:
theta_pert_ = (theta_pert[ijk] - 0.5)* 0.1
else:
theta_pert_ = 0.0
t = (theta[k] + theta_pert_)*exner_c(RS.p0_half[k])
PV.values[s_varshift + ijk] = Th.entropy(RS.p0_half[k],t,0.0,0.0,0.0)
if 'e' in PV.name_index:
e_varshift = PV.get_varshift(Gr, 'e')
for i in xrange(Gr.dims.nlg[0]):
ishift = i * Gr.dims.nlg[1] * Gr.dims.nlg[2]
for j in xrange(Gr.dims.nlg[1]):
jshift = j * Gr.dims.nlg[2]
for k in xrange(Gr.dims.nlg[2]):
ijk = ishift + jshift + k
if Gr.zl_half[k] <= 250.0:
PV.values[e_varshift + ijk] = 0.4*(1.0-Gr.zl_half[k]/250.0)**3.0
else:
PV.values[e_varshift + ijk] = 0.0
return
def InitDYCOMS_RF01(namelist,Grid.Grid Gr,PrognosticVariables.PrognosticVariables PV,