Line data Source code
1 : module inic_analytic_utils
2 :
3 : !-----------------------------------------------------------------------
4 : !
5 : ! Purpose: Set analytic initial conditions based on input coordinates
6 : !
7 : !
8 : !-----------------------------------------------------------------------
9 : use cam_logfile, only: iulog
10 : use shr_kind_mod, only: r8 => shr_kind_r8
11 : use cam_abortutils, only: endrun
12 : use shr_sys_mod, only: shr_sys_flush
13 :
14 : implicit none
15 : private
16 :
17 : ! Public interfaces
18 : public :: analytic_ic_readnl ! Read dyn_test_nl namelist
19 : public :: analytic_ic_active ! .true. if analytic IC should be set
20 : public :: analytic_ic_is_moist ! .true. if IC are moist
21 :
22 : ! Private module variables
23 : integer, parameter :: scheme_len = 32
24 : logical :: moist = .false.
25 :
26 : ! Protected resource
27 : character(len=scheme_len), public, protected :: analytic_ic_type = 'none'
28 :
29 : !==============================================================================
30 : CONTAINS
31 : !==============================================================================
32 :
33 96431616 : logical function analytic_ic_active()
34 96431616 : analytic_ic_active = (trim(analytic_ic_type) /= 'none')
35 96431616 : end function analytic_ic_active
36 :
37 0 : logical function analytic_ic_is_moist()
38 0 : analytic_ic_is_moist = moist
39 0 : end function analytic_ic_is_moist
40 :
41 1536 : subroutine analytic_ic_readnl(nlfile)
42 :
43 : use namelist_utils, only: find_group_name
44 : use units, only: getunit, freeunit
45 : use spmd_utils, only: masterproc, masterprocid, mpicom, mpi_character, mpi_logical
46 : use shr_string_mod, only: shr_string_toLower
47 :
48 : ! Dummy argument
49 : character(len=*), intent(in) :: nlfile ! filepath of namelist input file
50 :
51 : !
52 : ! Local variables
53 : integer :: unitn, ierr
54 : logical :: nl_not_found
55 : character(len=128) :: msg
56 : character(len=*), parameter :: subname = 'ANALYTIC_IC_READNL'
57 :
58 : #ifdef ANALYTIC_IC
59 : ! History namelist items
60 : namelist /analytic_ic_nl/ analytic_ic_type
61 :
62 : if (masterproc) then
63 : unitn = getunit()
64 : open(unitn, file=trim(nlfile), status='old')
65 : call find_group_name(unitn, 'analytic_ic_nl', status=ierr)
66 : if (ierr == 0) then
67 : nl_not_found = .false.
68 : write(iulog, *) 'Read in analytic_ic_nl namelist from: ',trim(nlfile)
69 : read(unitn, analytic_ic_nl, iostat=ierr)
70 : if (ierr /= 0) then
71 : write(msg, '(a,i0)') &
72 : ': ERROR reading namelist, analytic_ic_nl, iostat = ', ierr
73 : call endrun(subname//trim(msg))
74 : end if
75 : else
76 : nl_not_found = .true.
77 : end if
78 : close(unitn)
79 : call freeunit(unitn)
80 :
81 : analytic_ic_type = shr_string_toLower(analytic_ic_type)
82 : end if
83 :
84 : ! Broadcast namelist variables
85 : call mpi_bcast(analytic_ic_type, len(analytic_ic_type), mpi_character, masterprocid, mpicom, ierr)
86 : call mpi_bcast(nl_not_found, 1, mpi_logical, masterprocid, mpicom, ierr)
87 :
88 : if (nl_not_found) then
89 : ! If analytic IC functionality is turned on (via a configure switch), then
90 : ! build-namelist supplies the namelist group. If not found then nothing
91 : ! to do.
92 : return
93 : else
94 : select case(trim(analytic_ic_type))
95 : case('held_suarez_1994')
96 : msg = 'Dynamics state will be set to Held-Suarez (1994) initial conditions.'
97 : case('moist_baroclinic_wave_dcmip2016')
98 : moist = .true.
99 : msg = 'Dynamics state will be set to a moist baroclinic wave initial condition used in DCMIP 2016.'
100 : case('dry_baroclinic_wave_dcmip2016')
101 : moist = .false.
102 : msg = 'Dynamics state will be set to a dry baroclinic wave initial condition used in DCMIP 2016.'
103 : case('dry_baroclinic_wave_jw2006')
104 : moist = .false.
105 : msg = 'Dynamics state will be set to a dry baroclinic wave initial condition as described in JW2006.'
106 : case('us_standard_atmosphere')
107 : moist = .false.
108 : msg = 'static atmospheric state (u,v)=0, standard lapse rate for T, PS is hydrostatic equilibrium with topography.'
109 : case('none')
110 : msg = subname//': ERROR: analytic_ic_type must be set'
111 : write(iulog, *) msg
112 : call endrun(msg)
113 : case default
114 : msg = subname//': ERROR: analytic_ic_type not recognized: '//trim(analytic_ic_type)
115 : write(iulog, *) msg
116 : call endrun(msg)
117 : end select
118 :
119 : end if
120 :
121 : ! Write out initial condition scheme info
122 : if (masterproc) then
123 : write(iulog, *) msg
124 : end if
125 : #else
126 1536 : analytic_ic_type = 'none'
127 1536 : moist = .false.
128 : #endif
129 :
130 1536 : end subroutine analytic_ic_readnl
131 :
132 : end module inic_analytic_utils
|