CCPP SciDoc v7.0.x  v7.0.0
Common Community Physics Package Developed at DTC
 
Loading...
Searching...
No Matches
mp_tempo_post.F90
2
3 use machine, only : kind_phys
4
5 implicit none
6
7 public :: mp_tempo_post_init, mp_tempo_post_run, mp_tempo_post_finalize
8
9 private
10
11 logical :: is_initialized = .false.
12
13 logical :: apply_limiter
14
15contains
16
17!! \section arg_table_mp_tempo_post_init Argument Table
18!! \htmlinclude mp_tempo_post_init.html
19!!
20 subroutine mp_tempo_post_init(ttendlim, errmsg, errflg)
21
22 implicit none
23
24 ! Interface variables
25 real(kind_phys), intent(in) :: ttendlim
26
27 ! CCPP error handling
28 character(len=*), intent( out) :: errmsg
29 integer, intent( out) :: errflg
30
31 ! Local variables
32 integer :: i
33
34 ! Initialize the CCPP error handling variables
35 errmsg = ''
36 errflg = 0
37
38 ! Check initialization state
39 if (is_initialized) return
40
41 if (ttendlim < 0) then
42 apply_limiter = .false.
43 else
44 apply_limiter = .true.
45 end if
46
47 is_initialized = .true.
48
49 end subroutine mp_tempo_post_init
50
54 subroutine mp_tempo_post_run(ncol, nlev, tgrs_save, tgrs, prslk, dtp, ttendlim, &
55 kdt, errmsg, errflg)
56
57 implicit none
58
59 ! Interface variables
60 integer, intent(in) :: ncol
61 integer, intent(in) :: nlev
62 real(kind_phys), dimension(:,:), intent(in) :: tgrs_save
63 real(kind_phys), dimension(:,:), intent(inout) :: tgrs
64 real(kind_phys), dimension(:,:), intent(in) :: prslk
65 real(kind_phys), intent(in) :: dtp
66 real(kind_phys), intent(in) :: ttendlim
67 integer, intent(in) :: kdt
68
69 ! CCPP error handling
70 character(len=*), intent( out) :: errmsg
71 integer, intent( out) :: errflg
72
73 ! Local variables
74 real(kind_phys), dimension(1:ncol,1:nlev) :: mp_tend
75 integer :: i, k
76#ifdef DEBUG
77 integer :: events
78#endif
79
80 ! Initialize the CCPP error handling variables
81 errmsg = ''
82 errflg = 0
83
84 ! Check initialization state
85 if (.not.is_initialized) then
86 write(errmsg, fmt='((a))') 'mp_tempo_post_run called before mp_tempo_post_init'
87 errflg = 1
88 return
89 end if
90
91 ! If limiter is deactivated, return immediately
92 if (.not.apply_limiter) return
93
94 ! mp_tend and ttendlim are expressed in potential temperature
95 mp_tend = (tgrs - tgrs_save)/prslk
96
97#ifdef DEBUG
98 events = 0
99#endif
100 do k=1,nlev
101 do i=1,ncol
102 mp_tend(i,k) = max( -ttendlim*dtp, min( ttendlim*dtp, mp_tend(i,k) ) )
103
104#ifdef DEBUG
105 if (tgrs_save(i,k) + mp_tend(i,k)*prslk(i,k) .ne. tgrs(i,k)) then
106 write(0,'(a,3i6,3e16.7)') "mp_tempo_post_run mp_tend limiter: kdt, i, k, t_old, t_new, t_lim:", &
107 & kdt, i, k, tgrs_save(i,k), tgrs(i,k), tgrs_save(i,k) + mp_tend(i,k)*prslk(i,k)
108 events = events + 1
109 end if
110#endif
111 tgrs(i,k) = tgrs_save(i,k) + mp_tend(i,k)*prslk(i,k)
112 end do
113 end do
114
115#ifdef DEBUG
116 if (events > 0) then
117 write(0,'(a,i0,a,i0,a,i0)') "mp_tempo_post_run: ttendlim applied ", events, "/", nlev*ncol, &
118 & " times at timestep ", kdt
119 end if
120#endif
121
122 end subroutine mp_tempo_post_run
123
124!! \section arg_table_mp_tempo_post_finalize Argument Table
125!! \htmlinclude mp_tempo_post_finalize.html
126!!
127 subroutine mp_tempo_post_finalize(errmsg, errflg)
128
129 implicit none
130
131 ! CCPP error handling
132 character(len=*), intent( out) :: errmsg
133 integer, intent( out) :: errflg
134
135 ! initialize ccpp error handling variables
136 errmsg = ''
137 errflg = 0
138
139 ! Check initialization state
140 if (.not. is_initialized) return
141
142 is_initialized = .false.
143
144 end subroutine mp_tempo_post_finalize
145
146end module mp_tempo_post