-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodule_planet_utilities.f90
1294 lines (1115 loc) · 43.1 KB
/
module_planet_utilities.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 module_planet_utilities
USE module_model_constants
USE module_wrf_error
! Parameter variables
REAL, PARAMETER :: AA0 = 6.107799961
REAL, PARAMETER :: AA1 = 4.436518521e-01
REAL, PARAMETER :: AA2 = 1.428945805e-02
REAL, PARAMETER :: AA3 = 2.650648471e-04
REAL, PARAMETER :: AA4 = 3.031240396e-06
REAL, PARAMETER :: AA5 = 2.034080948e-08
REAL, PARAMETER :: AA6 = 6.136820929e-11
REAL, PARAMETER :: CC1 = 9.09718
REAL, PARAMETER :: CC2 = 3.56654
REAL, PARAMETER :: CC3 = 0.876793
REAL, PARAMETER :: EIS = 6.1071
REAL, PARAMETER :: TC = 273.16
REAL, PARAMETER :: LN10 = LOG(10.)
REAL, PARAMETER :: pi = pi_s
CONTAINS
!----------------------------------------------------------------
REAL FUNCTION get_julian(ls,eccentricity_local, &
equinox_fraction_local,zero_date_local) RESULT (julian)
!----------------------------------------------------------------
!
! Calculate Julian day for a given Ls.
! The definition used for this subroutine (and similarly for
! the calculation in phys/module_radation_driver.F:radconst is
! midnight at the beginning of the first day of the year is
! equal to a "Julian day" of 0.0....
!
! Input: Solar longitude (degrees)
!
! Output: Julian day (sols, fractional)
!
!----------------------------------------------------------------
USE module_model_constants
IMPLICIT NONE
!----------------------------------------------------------------
! Input/Ouptut variables
REAL, INTENT(IN) :: ls, & ! Day of the year, sols
eccentricity_local, &
equinox_fraction_local, &
zero_date_local
! Parameter variables
REAL(KIND (0d0)), PARAMETER :: SMALL_VALUE = 1.D-6
INTEGER, PARAMETER :: PLANET_YEAR_LOCAL = 669
! Local Variables
REAL(KIND (0d0)) :: pi
REAL(KIND (0d0)) :: deleqn, date_dbl
REAL(KIND (0d0)) :: er, qq, e, cd0, ep, em
REAL(KIND (0d0)) :: eq, w, als, ajulian, dp_date
PI=ACOS(-1.d0)
deleqn = equinox_fraction_local * REAL(PLANET_YEAR_LOCAL)
er = SQRT( (1.d0+eccentricity_local)/(1.d0-eccentricity_local) )
! qq is the mean anomaly
qq = 2.d0 * (pi * deleqn / REAL(PLANET_YEAR_LOCAL))
! determine true anomaly at equinox: eq
! Iteration for eq
e = 1.d0
cd0 = 1.d0
DO WHILE (cd0 > SMALL_VALUE)
ep = e - (e-eccentricity_local*SIN(e)-qq)/(1.d0-eccentricity_local*COS(e))
cd0 = ABS(e-ep)
e = ep
END DO
eq = 2.d0 * ATAN( er * TAN(0.5d0*e) )
w = eq + real(ls,kind(0.d0))*pi/180.
! e is the eccentric anomaly
e = 2.0*atan((tan(w*0.5))/er)
em = e - eccentricity_local*sin(e)
dp_date = em * PLANET_YEAR_LOCAL / (2.0 * pi)
ajulian = dp_date + zero_date_local
if(ajulian .lt. 0) ajulian = ajulian + PLANET_YEAR_LOCAL
if(ajulian .gt. PLANET_YEAR_LOCAL) ajulian = ajulian - PLANET_YEAR_LOCAL
julian = REAL(ajulian)
END FUNCTION get_julian
!----------------------------------------------------------------
REAL FUNCTION emissivity_lw(emiss, n_ices, surface_ice, &
#if ( WRF_MARS == 1 )
CO2ICE_THRESHOLD, &
H2OICE_THRESHOLD, &
#endif
#if ( WRF_PLUTO )
N2ICE_THRESHOLD, &
CH4ICE_THRESHOLD, &
#endif
latitude, temperature, emiss_ice)
!----------------------------------------------------------------
!
! Calculate the long-wave infrared surface emissivity.
!
! Wrapper function for calculations based on surface ices
! and latitudes appropriate to each planet
!
! Input: emiss (unitless)
! 2D field of (typically bedrock) surface emissivity
! suface ice (kg/m^2)
! 2D field of surface ice column density
! latitude (degrees N)
! latitude of grid point
! temperature (K)
! surface temperature of grid point
!
! Output: emissivity (unitless)
!
!----------------------------------------------------------------
USE module_wrf_error
IMPLICIT NONE
!----------------------------------------------------------------
! Input variables
INTEGER, INTENT(IN) :: n_ices
REAL, INTENT(IN) :: emiss
REAL, INTENT(IN) :: latitude
REAL, INTENT(IN) :: temperature
REAL, DIMENSION(n_ices), INTENT(IN) :: surface_ice
REAL, DIMENSION(n_ices), INTENT(IN), OPTIONAL :: emiss_ice
#if ( WRF_MARS == 1 )
REAL, INTENT(IN) :: CO2ICE_THRESHOLD, &
H2OICE_THRESHOLD
#endif
#if ( WRF_PLUTO == 1 )
REAL, INTENT(IN) :: N2ICE_THRESHOLD, &
CH4ICE_THRESHOLD
#endif
! Local variables
! ice_threshold (kg/m^2)
! critical value of surface ice column density
! above which the emissivity of the ice (as opposed
! to say underlying bedrock) should be used
REAL, DIMENSION(n_ices) :: ice_threshold
LOGICAL :: use_ice_emissivities
#ifdef WRF_MARS
! Infrared emissivity of CO2 ice
!REAL, PARAMETER :: emiss_mars_co2ice= 0.8
! Better fits to Viking lander pressure curves
REAL, PARAMETER :: emiss_mars_co2ice_north = 0.485
REAL, PARAMETER :: emiss_mars_co2ice_south = 0.785
! Infrared emissivity of H2O ice
REAL, PARAMETER :: emiss_mars_h2oice= 1.
ice_threshold = (/ CO2ICE_THRESHOLD, &
H2OICE_THRESHOLD /)
#endif
#ifdef WRF_PLUTO
IF (n_ices < 2) THEN
WRITE(wrf_err_message,*) 'Not enough ices and/or ice emissivities '//&
'specified!'
CALL wrf_error_fatal(TRIM(wrf_err_message))
END IF
ice_threshold = (/ N2ICE_THRESHOLD, &
CH4ICE_THRESHOLD /)
use_ice_emissivities = .FALSE.
IF (PRESENT(emiss_ice)) use_ice_emissivities = .TRUE.
#endif
! Default value
emissivity_lw = emiss
#if defined ( WRF_MARS )
! Check on CO2 ice
IF ( surface_ice(1) > ice_threshold(1) ) THEN
IF (latitude > 0.) THEN
emissivity_lw = emiss_mars_co2ice_north
ELSE
emissivity_lw = emiss_mars_co2ice_south
END IF
! Modify longwave surface emissivity for H2O ice here, if necessary
!ELSE IF (surface_ice(2) > ice_threshold(2)) THEN
! emissivity_lw=emiss_h2oice
END IF
#elif defined ( WRF_PLUTO )
#if 0
IF ( surface_ice(1) > ice_threshold(1) ) THEN
! Stansberry, J. A., and R. V. Yelle, "Emissivity and the Fate of
! Pluto's Atmosphere", Icarus, 141, pp. 299-306, 1999
IF (temperature < 35.6) THEN
emissivity_lw = 0.30 ! (N2(s), T<35.6K).
ELSE
emissivity_lw = 0.75 ! (N2(s), T>35.6K)
END IF
END IF
#else
IF (use_ice_emissivities) THEN
IF ( surface_ice(2) > ice_threshold(2) ) THEN
emissivity_lw = emiss_ice(2)
ELSE IF ( surface_ice(1) > ice_threshold(1) ) THEN
emissivity_lw = emiss_ice(1)
ELSE
emissivity_lw = emiss
END IF
END IF
#endif
#elif defined ( WRF_TITAN )
#elif defined ( WRF_VENUS )
#elif defined ( WRF_EARTH )
#endif
END FUNCTION emissivity_lw
!----------------------------------------------------------------
REAL FUNCTION esat(temperature)
!----------------------------------------------------------------
!
! Calculate saturation vapour pressure of water using a formulas
! that are valid over ice at low temperatures and over ice and
! liquid at higher pressures
!
! Input: temperature (K)
!
! Output: Saturation vapor pressure (Pa)
!
!----------------------------------------------------------------
IMPLICIT NONE
!----------------------------------------------------------------
! Input/Ouptut variables
REAL, INTENT(IN ) :: temperature
esat = PFROST_H2O(temperature,.FALSE.)
END FUNCTION esat
!----------------------------------------------------------------
REAL FUNCTION rsat_h2o(temperature,pressure)
!----------------------------------------------------------------
!
! Calculate saturation vapor pressure of water using a formulas
! that are valid over ice at low temperatures and over ice and
! liquid at higher pressures
!
! Input: temperature (K), pressure (Pa)
!
! Output: Saturation mass mixing ratio (kg/kg)
!
!----------------------------------------------------------------
IMPLICIT NONE
!----------------------------------------------------------------
! Input/Ouptut variables
REAL, INTENT(IN ) :: temperature, pressure
! Local variables
REAL :: esat
esat = PFROST_H2O(temperature,.FALSE.)
! With the following definition of rsat, the assumption is that the
! moisture variables (Q_vapor, Q_ice, etc.) refer to mass mixing
! ratio per mass of the _TOTAL_ atmosphere, not to merely the dry
! atmosphere. This issue arises in planetary atmospheres because,
! for Mars in particular, the saturation vapor pressure of water
! is nearly equal to the total atmospheric pressure at some temperatures,
! and thus using the defintion of mass mixing ration per mass of dry
! air would give a value of infinity ( something/(x-x) = 1/0 = infinity)
! which would be useless (as well as crash the model). Hopefully
! the only place this difference in definition should matter is here
! (with the saturation values), in the surface pressure fluxes (we
! account for dry air mass changes, e.g., CO2, but not for pressure
! changes due to H2O vapor pressure) and in adding the water vapor
! amounts to the total atmospheric pressure.
rsat_h2o = MW_H2O * esat / (MW_AIR * pressure)
! WRONG!: Limit saturation between 0 and 1
!rsat_h2o = MAX(MIN(rsat_h2o,1.),0.)
! Limit saturation to positive values
rsat_h2o = MAX(rsat_h2o,0.)
END FUNCTION rsat_h2o
!----------------------------------------------------------------
REAL FUNCTION rsat_ch4(temperature,pressure)
!----------------------------------------------------------------
!
! Calculate saturation mixing ratio of methane
!
! Input: temperature (K), pressure (Pa)
!
! Output: Saturation mass mixing ratio (kg/kg)
!
!----------------------------------------------------------------
IMPLICIT NONE
!----------------------------------------------------------------
! Input/Ouptut variables
REAL, INTENT(IN ) :: temperature, pressure
! Local variables
REAL :: esat
! See full comments on methodology in function RSAT_H2O
esat = PFROST_CH4(temperature,.FALSE.)
rsat_ch4 = MW_CH4 * esat / (MW_AIR * pressure)
! WRONG!: Limit saturation between 0 and 1
!rsat_ch4 = MAX(MIN(rsat_ch4,1.),0.)
! Limit saturation to positive values
rsat_ch4 = MAX(rsat_ch4,0.)
END FUNCTION rsat_ch4
!----------------------------------------------------------------
REAL FUNCTION molecular_diffusivity(temperature, pressure) &
RESULT (diffusivity)
!----------------------------------------------------------------
!
! Calculate the molecular self-diffusivity of a gas at a given
! temperature and pressure.
!
! Input: Temperature (K), Pressure (Pa), Planet identifier ID
!
! Output: diffusivity (m^2/s)
!
!----------------------------------------------------------------
IMPLICIT NONE
!----------------------------------------------------------------
! Input/Ouptut variables
REAL, INTENT(IN) :: temperature ! K
REAL, INTENT(IN) :: pressure ! Pa
! Parameter variables
! Also prevent roundoff and over/underflow errors
REAL, PARAMETER :: c1 = k_boltzmann/(molecular_diameter*molecular_diameter)
REAL, PARAMETER :: c2 = k_boltzmann/(pi*mw_air*m_amu)
! Local Variables
REAL :: term
term = SQRT(c2 * temperature)
diffusivity = term * c1 * (3. * temperature) / (8. * pressure)
END FUNCTION molecular_diffusivity
!----------------------------------------------------------------
REAL FUNCTION tfrost(pressure)
!----------------------------------------------------------------
!
! Calculate the deposition ("frost" = "meteorological deposition",
! <http://en.wikipedia.org/wiki/Sublimation_(chemistry)>)
! temperature of a gas as a function of pressure.
!
! Wrapper function for the gas appropriate to each planet
! Input: pressure (Pa)
!
! Output: frost temperature (K)
!
!----------------------------------------------------------------
IMPLICIT NONE
!----------------------------------------------------------------
! Input/Ouptut variables
REAL, INTENT(IN ) :: pressure
#if defined WRF_MARS
tfrost = tfrost_co2(pressure)
#elif defined WRF_PLUTO
tfrost = tfrost_n2(pressure)
#elif defined WRF_TITAN
! Return flag value
tfrost = 0.
#elif defined WRF_VENUS
! Return flag value
tfrost = 0.
#elif defined WRF_EARTH
! Return flag value
tfrost = 0.
#endif
END FUNCTION tfrost
!----------------------------------------------------------------
REAL FUNCTION tfrost_h2o(pressure)
!----------------------------------------------------------------
!
! Calculate the deposition ("frost" = "meteorological deposition",
! <http://en.wikipedia.org/wiki/Sublimation_(chemistry)>)
! temperature of H2O as a function of pressure.
!
! Input: pressure (Pa)
!
! Output: H2O frost temperature (K)
!
!----------------------------------------------------------------
USE module_nrutils, ONLY : zroots, zbrak, rtsafe
USE module_wrf_error
IMPLICIT NONE
!----------------------------------------------------------------
! Input/Ouptut variables
REAL, INTENT(IN ) :: pressure
! Local variables
REAL(KIND(0d0)) :: p
COMPLEX(KIND((0d0,0d0))), DIMENSION(7) :: coeffs
COMPLEX(KIND((0d0,0d0))), DIMENSION(6) :: roots
REAL(KIND(0d0)) :: x1, x2, xl, xh
INTEGER :: n, nb
REAL(KIND(0d0)), DIMENSION(:), POINTER :: xb1, xb2
! esat is in mbar -- need to convert to Pa
p = pressure * 1.d-2
IF ( p > aa0 ) THEN
coeffs(1) = CMPLX(REAL(AA0,KIND(0d0))-p,KIND=KIND(0d0))
coeffs(2) = CMPLX(AA1,KIND=KIND(0d0))
coeffs(3) = CMPLX(AA2,KIND=KIND(0d0))
coeffs(4) = CMPLX(AA3,KIND=KIND(0d0))
coeffs(5) = CMPLX(AA4,KIND=KIND(0d0))
coeffs(6) = CMPLX(AA5,KIND=KIND(0d0))
coeffs(7) = CMPLX(AA6,KIND=KIND(0d0))
CALL ZROOTS(coeffs, roots, .TRUE.)
! The correct root is the larger of the two real roots (i.e., no
! imaginary part)
tfrost_h2o = TC + MAXVAL(REAL(roots,KIND(0.)), &
MASK=(ABS(AIMAG(roots)) < 1.d-6))
ELSE
! Find a 1 K bracketing range to search for root to invert equation
x1 = 50.d0
x2 = 274.d0
n = 224
CALL ZBRAK(PFROST_H2O_ROOT,x1,x2,n,p,xb1,xb2,nb)
IF (nb == 0) THEN
! No roots found in our range! Something massively wrong!
WRITE(wrf_err_message,*) 'No roots found in the range:',x1, &
' to ',x2
CALL wrf_error_fatal(TRIM(wrf_err_message))
ELSE IF (nb > 1) THEN
! We probably have a root that sits exactly on the edge of our
! attempted bracketing range. Compensate by extending range by
! 1 K on either side
xl = xb1(1) - 1
xh = xb2(1) + 1
WRITE(wrf_err_message,*) 'Found more than one root with zbrak:',nb
!c-mm CALL WRF_debug(100,TRIM(wrf_err_message))
ELSE
xl = xb1(1)
xh = xb2(1)
END IF
DEALLOCATE(xb1,xb2)
NULLIFY(xb1,xb2)
tfrost_h2o = REAL(RTSAFE(PFROST_H2O_ROOT_DERIV,xl,xh,1.d-6,p), &
KIND=KIND(0.))
END IF
END FUNCTION tfrost_h2o
!----------------------------------------------------------------
REAL FUNCTION tfrost_co2(pressure)
!----------------------------------------------------------------
!
! Calculate the deposition ("frost" = "meteorological deposition",
! <http://en.wikipedia.org/wiki/Sublimation_(chemistry)>)
! temperature of CO2 as a function of pressure for a range that is
! typical of Martian pressures.
!
! Input: pressure (Pa)
!
! Output: CO2 frost temperature (K)
!
!----------------------------------------------------------------
IMPLICIT NONE
!----------------------------------------------------------------
! Input/Ouptut variables
REAL, INTENT(IN ) :: pressure
! Parameter variables
! for equation of the form y = A/(B-ln(C*x))
REAL, PARAMETER :: C = 0.9532 ! This represents the fraction of Mars
! atmospheric gas that is CO2 (as opposed
! to Ar, N2, etc.) If necessary, this
! could become an input variable as well...
! James et al., 1992 formula
!REAL, PARAMETER :: A = 3182.48
!REAL, PARAMETER :: B = 23.3493
! MCS team formula (Armin Kleinbohl fit to CRC Handbook data)
! This forumula used base 10 logarithm, which can be converted to a
! natural logarithm by noting that log10 x = ln x / ln 10.
! Thus y = A2/(B2-log10(C2*C*x)) is equivalent to y = A/(B-ln(C*x))
! where:
! A = A2 ln 10
! B = B2 ln 10 - ln C2
REAL, PARAMETER :: A = 3148.4278 ! (1367.3448 * ln 10)
REAL, PARAMETER :: B = 27.707244 ! (9.9082 * ln 10 - ln 0.00750061674)
tfrost_co2 = A / ( B - LOG( C * pressure ) )
! Old formula, diverges from others at low pressures
!tfrost_co2 = 149.2 + 6.48 * LOG( 1.35e-3 * pressure )
END FUNCTION tfrost_co2
!----------------------------------------------------------------
REAL FUNCTION tfrost_n2(pressure)
!----------------------------------------------------------------
!
! Calculate the deposition ("frost" = "meteorological deposition",
! <http://en.wikipedia.org/wiki/Sublimation_(chemistry)>)
! temperature of N2 as a function of pressure for a range that is
! typical of the outer planets and satellites
!
! Input: pressure (Pa)
!
! Output: N2 frost temperature (K)
!
!----------------------------------------------------------------
IMPLICIT NONE
!----------------------------------------------------------------
! Input/Ouptut variables
REAL, INTENT(IN ) :: pressure
! Parameter variables
! For equation of the form log_10(P) = A + B/T + C/T^2
! Invert to solve for T(P):
! T = 2*C / (-B - SQRT(B^2 - 4*C*(A - LOG10(P))))
REAL, PARAMETER :: A = 7.98698
REAL, PARAMETER :: B = -161.597 ! K
REAL, PARAMETER :: C = -5363.80 ! K^2
IF (pressure <= 0.) THEN
tfrost_n2 = 0. ! in an asymptotic sense...
ELSE
tfrost_n2 = 2.d0*C / (-B - SQRT(B*B - 4.d0*C*(A - LOG10(pressure))))
END IF
END FUNCTION tfrost_n2
!----------------------------------------------------------------
REAL FUNCTION tfrost_ch4(pressure)
!----------------------------------------------------------------
!
! Calculate the deposition ("frost" = "meteorological deposition",
! <http://en.wikipedia.org/wiki/Sublimation_(chemistry)>)
! temperature of CH4 as a function of pressure for a range that is
! typical of the outer planets and satellites
!
! Input: pressure (Pa)
!
! Output: CH4 frost temperature (K)
!
!----------------------------------------------------------------
IMPLICIT NONE
!----------------------------------------------------------------
! Input/Ouptut variables
REAL, INTENT(IN ) :: pressure
! Parameter variables
! For equation of the form P = A e^(-B/(T+C))
!pfrost_ch4 = A * EXP(-B/(temperature+C))
! Invert to solve for T(P):
! T = -C + B/(ln(A) - ln(P))
REAL, PARAMETER :: A = 133.3224*EXP(6.61184*LN10) ! Pa
REAL, PARAMETER :: B = 389.93*LN10 ! K
REAL, PARAMETER :: C = 266.-273.15 ! K
IF (pressure <= 0.) THEN
tfrost_ch4 = 0. ! in an asymptotic sense...
ELSE
tfrost_ch4 = -C + B/(LOG(A)-LOG(pressure))
END IF
END FUNCTION tfrost_ch4
!----------------------------------------------------------------
REAL FUNCTION pfrost(temperature, dpdt)
!----------------------------------------------------------------
!
! Calculate the equilibrium vapor pressure of a gas as a function
! of temperature, unless the "dpdt" optional parameter is set to
! .TRUE., in which case the function returns the value of dP/dT
! (the Clausius-Clapeyron relation) of the equilibrium vapor
! pressure equation at the input temperature
!
! Wrapper function for the gas appropriate to each planet
! Input: temperature (K)
!
! Output: pressure (Pa)
! OR
! pressure/temperature (Pa/K)
!
!----------------------------------------------------------------
IMPLICIT NONE
!----------------------------------------------------------------
! Input/Ouptut variables
REAL, INTENT(IN) :: temperature
LOGICAL, INTENT(IN), OPTIONAL :: dpdt
LOGICAL :: calculate_dpdt
calculate_dpdt = .FALSE.
IF (PRESENT(dpdt)) calculate_dpdt = dpdt
#if defined WRF_MARS
pfrost = pfrost_co2(temperature, calculate_dpdt)
#elif defined WRF_PLUTO
pfrost = pfrost_n2( temperature, calculate_dpdt)
#elif defined WRF_TITAN
! Return flag value
pfrost = 0.
#elif defined WRF_VENUS
! Return flag value
pfrost = 0.
#elif defined WRF_EARTH
! Return flag value
pfrost = 0.
#endif
END FUNCTION pfrost
!----------------------------------------------------------------
REAL FUNCTION pfrost_h2o(temperature,calculate_dpdt)
!----------------------------------------------------------------
!
! Calculate the equilibrium vapor pressure of H2O gas as a function
! of temperature, unless the "calculate_dpdt" optional parameter is
! set to .TRUE., in which case the function returns the value of
! dP/dT (the Clausius-Clapeyron relation) of the equilibrium vapor
! pressure equation at the input temperature
!
! Input: temperature (K)
!
! Output: pressure (Pa)
! OR
! pressure/temperature (Pa/K)
!
!----------------------------------------------------------------
IMPLICIT NONE
!----------------------------------------------------------------
! Input/Ouptut variables
REAL, INTENT(IN) :: temperature
LOGICAL, INTENT(IN) :: calculate_dpdt
! Local variables
REAL :: t1, esat, rhs
IF ( temperature > TC ) THEN
t1 = temperature - TC
esat = AA0 + t1 * (AA1 + t1 * (AA2 + t1 * (AA3 + t1 * &
(AA4 + t1 * (AA5 + t1 * AA6)))))
esat = MAX(esat,0.)
IF (calculate_dpdt) THEN
esat = AA1 + t1 * (2.*AA2 + t1 * (3.*AA3 + t1 * &
(4.*AA4 + t1 * (5.*AA5 + t1 * 6.*AA6))))
END IF
ELSE
rhs = -CC1 * (TC / temperature - 1.) &
- CC2 * LOG10(TC / temperature) &
+ CC3 * (1. - temperature / TC) + LOG10(EIS)
esat = 10.**rhs
esat = MAX(esat,0.)
IF (calculate_dpdt) THEN
esat = esat * &
(CC1*TC*LN10/(temperature*temperature) + &
CC2/temperature - CC3*LN10/TC)
END IF
END IF
! esat is in mbar -- need to convert to Pa
pfrost_h2o = 100.*esat
END FUNCTION pfrost_h2o
!----------------------------------------------------------------
REAL FUNCTION pfrost_co2(temperature,calculate_dpdt)
!----------------------------------------------------------------
!
! Calculate the equilibrium vapor pressure of CO2 gas as a function
! of temperature for a range that is typical for Mars, unless the
! "calculate_dpdt" optional parameter is set to .TRUE., in which
! case the function returns the value of dP/dT (the
! Clausius-Clapeyron relation) of the equilibrium vapor pressure
! equation at the input temperature
!
! Input: temperature (K)
!
! Output: pressure (Pa)
! OR
! pressure/temperature (Pa/K)
!
!----------------------------------------------------------------
IMPLICIT NONE
!----------------------------------------------------------------
! Input/Ouptut variables
REAL, INTENT(IN) :: temperature
LOGICAL, INTENT(IN) :: calculate_dpdt
! Parameter variables
! for equation of the form y = A/(B-ln(C*x))
REAL, PARAMETER :: C = 0.9532 ! This represents the fraction of Mars
! atmospheric gas that is CO2 (as opposed
! to Ar, N2, etc.) If necessary, this
! could become an input variable as well...
! James et al., 1992 formula
!REAL, PARAMETER :: A = 3182.48
!REAL, PARAMETER :: B = 23.3493
! MCS team formula (Armin Kleinbohl fit to CRC Handbook data)
! This forumula used base 10 logarithm, which can be converted to a
! natural logarithm by noting that log10 x = ln x / ln 10.
! Thus y = A2/(B2-log10(C2*C*x)) is equivalent to y = A/(B-ln(C*x))
! where:
! A = A2 ln 10
! B = B2 ln 10 - ln C2
REAL, PARAMETER :: A = 3148.4278 ! (1367.3448 * ln 10)
REAL, PARAMETER :: B = 27.707244 ! (9.9082 * ln 10 - ln 0.00750061674)
pfrost_co2 = EXP(B - A/temperature) / C
IF (calculate_dpdt) THEN
pfrost_co2 = pfrost_co2 * A/temperature/temperature
ENDIF
! Old formula, diverges from others at low pressures
!pfrost_co2 = EXP( (temperature - 149.2) / 6.48 ) / 1.35e-3
END FUNCTION pfrost_co2
!----------------------------------------------------------------
REAL FUNCTION pfrost_n2(temperature,calculate_dpdt)
!----------------------------------------------------------------
!
! Calculate the equilibrium vapor pressure of N2 gas as a function
! of temperature for a range that is typical of the outer planets
! and satellites, unless the "calculate_dpdt" optional parameter
! is set to .TRUE., in which case the function returns the value
! of dP/dT (the Clausius-Clapeyron relation) of the equilibrium
! vapor pressure equation at the input temperature
!
! Input: temperature (K)
!
! Output: pressure (Pa)
! OR
! pressure/temperature (Pa/K)
!
!----------------------------------------------------------------
IMPLICIT NONE
!----------------------------------------------------------------
! Input/Ouptut variables
REAL, INTENT(IN) :: temperature
LOGICAL, INTENT(IN) :: calculate_dpdt
! Parameter variables
! log_10(P) = A + B/T + C/T^2
! Rewrite in natural logarithm:
! ln P = A ln 10 + B ln 10 / T + C ln 10 / T^2
! ln P = A' + B'/T + C'/T^2
!REAL, PARAMETER :: A = 7.98698
!REAL, PARAMETER :: B = -161.597 ! K
!REAL, PARAMETER :: C = -5363.80 ! K^2
REAL, PARAMETER :: A = 18.3907
REAL, PARAMETER :: B = -372.090731 ! K
REAL, PARAMETER :: C = -12350.598 ! K^2
IF (temperature == 0.) THEN
pfrost_n2 = 0.
ELSE
pfrost_n2 = EXP(A + B/temperature + (C/temperature)/temperature)
END IF
IF (calculate_dpdt) THEN
pfrost_n2 = pfrost_n2 * (-B/(temperature*temperature) &
- 2.*C/(temperature**3))
ENDIF
END FUNCTION pfrost_n2
!----------------------------------------------------------------
REAL FUNCTION pfrost_ch4(temperature,calculate_dpdt)
!----------------------------------------------------------------
!
! Calculate the equilibrium vapor pressure of CH4 gas as a function
! of temperature for a range that is typical of the outer planets
! and satellites, unless the "calculate_dpdt" optional parameter
! is set to .TRUE., in which case the function returns the value
! of dP/dT (the Clausius-Clapeyron relation) of the equilibrium
! vapor pressure equation at the input temperature
!
! Input: temperature (K)
!
! Output: pressure (Pa)
! OR
! pressure/temperature (Pa/K)
!
!----------------------------------------------------------------
IMPLICIT NONE
!----------------------------------------------------------------
! Input/Ouptut variables
REAL, INTENT(IN) :: temperature
LOGICAL, INTENT(IN) :: calculate_dpdt
! Parameter variables
! P = A e^(-B/(T+C))
REAL, PARAMETER :: A = 133.3224*EXP(6.61184*LN10) ! Pa
REAL, PARAMETER :: B = 389.93*LN10 ! K
REAL, PARAMETER :: C = 266.-273.15 ! K
IF (temperature == 0.) THEN
pfrost_ch4 = 0.
ELSE
pfrost_ch4 = A * EXP(-B/(temperature+C))
END IF
IF (calculate_dpdt) THEN
! P = A e^(-B/(T+C))
! dP/dT = P * b / (T+C)^2
pfrost_ch4 = pfrost_ch4 * B / ((temperature+C)*(temperature+C))
ENDIF
END FUNCTION pfrost_ch4
!----------------------------------------------------------------
REAL(KIND(0d0)) FUNCTION pfrost_h2o_root(temperature,pressure)
!----------------------------------------------------------------
!
! Function to help invert the P_eq(T) equation for H2O when T < 273.16
! and a non-linear (i.e., non-polynomial) equation.
!
! Input: temperature (K)
! pressure (Pa)
!
!----------------------------------------------------------------
IMPLICIT NONE
!----------------------------------------------------------------
! Input/Ouptut variables
REAL(KIND(0d0)), INTENT(IN) :: temperature, pressure
pfrost_h2o_root = (CC1*TC*LN10)/temperature - CC2*LOG(temperature) + &
(CC3*LN10/TC)*temperature + &
(-CC1*LN10 + CC2*LOG(TC) - CC3*LN10 - LOG(EIS) + &
LOG(pressure))
END FUNCTION pfrost_h2o_root
!----------------------------------------------------------------
SUBROUTINE pfrost_h2o_root_deriv(temperature,pressure,f,df)
!----------------------------------------------------------------
!
! Function to help invert the P_eq(T) equation for H2O when T < 273.16
! and a non-linear (i.e., non-polynomial) equation.
!
! Input: temperature (K)
! pressure (Pa)
! Output: f: Value of root-finding function with given inputs (ln[Pa])
! df: Derivative of root-finding function with repsect to
! temperature at the given input values (ln[Pa] K^-1)
!
!----------------------------------------------------------------
IMPLICIT NONE
!----------------------------------------------------------------
! Input/Ouptut variables
REAL(KIND(0d0)), INTENT(IN ) :: temperature, pressure
REAL(KIND(0d0)), INTENT( OUT) :: f, df
f = PFROST_H2O_ROOT(temperature, pressure)
df = -(CC1*TC*LN10)/(temperature*temperature) - (CC2/temperature) + &
CC3*LN10/TC
END SUBROUTINE pfrost_h2o_root_deriv
!----------------------------------------------------------------
SUBROUTINE pfrost_cooling_root(temperature,b,c,f,df)
!----------------------------------------------------------------
!
! Function to help solve for the energy balance when surface
! temperature must remain in equilibrium balance with surface
! pressure when cooling (due to radiation, etc.). Equation
! to be solved is non-linear.
!
! Input: temperature (K)
! b, c: parameters used in defining equation
! Output: f: Value of root-finding function with given inputs (K)
! df: Derivative of root-finding function with repsect to
! temperature at the given input values (unitless, K/K)
!
!----------------------------------------------------------------
IMPLICIT NONE
!----------------------------------------------------------------
! Input/Ouptut variables
REAL(KIND(0d0)), INTENT(IN ) :: temperature, b, c
REAL(KIND(0d0)), INTENT( OUT) :: f, df
f = temperature + b*PFROST(REAL(temperature)) + c
df = 1.d0 + b*PFROST(REAL(temperature),dpdt=.TRUE.)
END SUBROUTINE pfrost_cooling_root
!----------------------------------------------------------------
REAL FUNCTION VISCOSITY(temperature)
!----------------------------------------------------------------
!
! Calculate the dynamic viscosity of air at a given temperature.
! Wrapper function for the gas appropriate to each planet.
!
! Input: temperature (K)
!
! Output: dynamic viscosity (Pa s == kg/m/s)
!
!----------------------------------------------------------------
IMPLICIT NONE
!----------------------------------------------------------------
! Input/Ouptut variables
REAL, INTENT(IN) :: temperature
#if defined WRF_MARS
viscosity = VISCOSITY_CO2(temperature)
#elif defined WRF_PLUTO
viscosity = VISCOSITY_N2( temperature)
#elif defined WRF_TITAN
! Return flag value
viscosity = 0.
#elif defined WRF_VENUS
! Return flag value
viscosity = 0.
#elif defined WRF_EARTH
! Return flag value
viscosity = 0.
#endif
END FUNCTION VISCOSITY
!----------------------------------------------------------------
REAL FUNCTION VISCOSITY_CO2(temperature)
!----------------------------------------------------------------
!
! Calculate the dynamic viscosity of CO2 gas
! Reference: Fenghour, A., W. A. Wakeham, and V. Vesovic,
! "The Viscosity of Carbon Dioxide", J. Phys. Chem. Ref. Data, 27 (1),
! pp. 31--44, 1998
!
! Input: temperature (K)
!
! Output: viscosity (Pa s == kg/m/s)
!
!----------------------------------------------------------------
IMPLICIT NONE
!----------------------------------------------------------------
! Input variables
REAL, INTENT(IN) :: temperature
! Local variables
REAL, PARAMETER :: c0 = 1.006970e-6 ! Pa s K^-(1/2)
REAL, PARAMETER :: a0 = 0.235156 ! unitless
REAL, PARAMETER :: a1 = -0.491266 ! unitless
REAL, PARAMETER :: a2 = 5.211155e-2 ! unitless
REAL, PARAMETER :: a3 = 5.347906e-2 ! unitless
REAL, PARAMETER :: a4 = -1.537102e-2 ! unitless
REAL, PARAMETER :: eovk = 251.196 ! K
REAL :: gstarn, lntstar
lntstar = LOG(temperature/eovk)
gstarn = EXP(a0 + lntstar*(a1 + lntstar*(a2 + lntstar*(a3 + lntstar*a4))))
viscosity_co2 = c0*SQRT(temperature)/gstarn
! Alternate "Sutherland's formula":
! viscosity = K * T^(3/2) / (T + C)
! where K and C are constants characteristic of the gas
END FUNCTION VISCOSITY_CO2
!----------------------------------------------------------------
REAL FUNCTION VISCOSITY_N2(temperature)
!----------------------------------------------------------------
!