1 | MODULE diacfl |
---|
2 | !!====================================================================== |
---|
3 | !! *** MODULE diacfl *** |
---|
4 | !! Output CFL diagnostics to ascii file |
---|
5 | !!====================================================================== |
---|
6 | !! History : 3.4 ! 2010-03 (E. Blockley) Original code |
---|
7 | !! 3.6 ! 2014-06 (T. Graham) Removed CPP key & Updated to vn3.6 |
---|
8 | !! 4.0 ! 2017-09 (G. Madec) style + comments |
---|
9 | !!---------------------------------------------------------------------- |
---|
10 | !! dia_cfl : Compute and output Courant numbers at each timestep |
---|
11 | !!---------------------------------------------------------------------- |
---|
12 | USE oce ! ocean dynamics and active tracers |
---|
13 | USE dom_oce ! ocean space and time domain |
---|
14 | USE domvvl ! |
---|
15 | ! |
---|
16 | USE lib_mpp ! distribued memory computing |
---|
17 | USE lbclnk ! ocean lateral boundary condition (or mpp link) |
---|
18 | USE in_out_manager ! I/O manager |
---|
19 | USE timing ! Performance output |
---|
20 | |
---|
21 | IMPLICIT NONE |
---|
22 | PRIVATE |
---|
23 | |
---|
24 | CHARACTER(LEN=50) :: clname="cfl_diagnostics.ascii" ! ascii filename |
---|
25 | INTEGER :: numcfl ! outfile unit |
---|
26 | ! |
---|
27 | INTEGER, DIMENSION(3) :: nCu_loc, nCv_loc, nCw_loc ! U, V, and W run max locations in the global domain |
---|
28 | REAL(wp) :: rCu_max, rCv_max, rCw_max ! associated run max Courant number |
---|
29 | |
---|
30 | !!gm CAUTION: need to declare these arrays here, otherwise the calculation fails in multi-proc ! |
---|
31 | !!gm I don't understand why. |
---|
32 | REAL(wp), ALLOCATABLE, DIMENSION(:,:,:) :: zCu_cfl, zCv_cfl, zCw_cfl ! workspace |
---|
33 | !!gm end |
---|
34 | |
---|
35 | PUBLIC dia_cfl ! routine called by step.F90 |
---|
36 | PUBLIC dia_cfl_init ! routine called by nemogcm |
---|
37 | |
---|
38 | !! * Substitutions |
---|
39 | # include "vectopt_loop_substitute.h90" |
---|
40 | !!---------------------------------------------------------------------- |
---|
41 | !! NEMO/OCE 4.0 , NEMO Consortium (2018) |
---|
42 | !! $Id$ |
---|
43 | !! Software governed by the CeCILL license (see ./LICENSE) |
---|
44 | !!---------------------------------------------------------------------- |
---|
45 | CONTAINS |
---|
46 | |
---|
47 | SUBROUTINE dia_cfl ( kt ) |
---|
48 | !!---------------------------------------------------------------------- |
---|
49 | !! *** ROUTINE dia_cfl *** |
---|
50 | !! |
---|
51 | !! ** Purpose : Compute the Courant numbers Cu=u*dt/dx and Cv=v*dt/dy |
---|
52 | !! and output to ascii file 'cfl_diagnostics.ascii' |
---|
53 | !!---------------------------------------------------------------------- |
---|
54 | INTEGER, INTENT(in) :: kt ! ocean time-step index |
---|
55 | ! |
---|
56 | INTEGER :: ji, jj, jk ! dummy loop indices |
---|
57 | REAL(wp) :: z2dt, zCu_max, zCv_max, zCw_max ! local scalars |
---|
58 | INTEGER , DIMENSION(3) :: iloc_u , iloc_v , iloc_w , iloc ! workspace |
---|
59 | !!gm this does not work REAL(wp), DIMENSION(jpi,jpj,jpk) :: zCu_cfl, zCv_cfl, zCw_cfl ! workspace |
---|
60 | !!---------------------------------------------------------------------- |
---|
61 | ! |
---|
62 | IF( ln_timing ) CALL timing_start('dia_cfl') |
---|
63 | ! |
---|
64 | ! ! setup timestep multiplier to account for initial Eulerian timestep |
---|
65 | IF( neuler == 0 .AND. kt == nit000 ) THEN ; z2dt = rdt |
---|
66 | ELSE ; z2dt = rdt * 2._wp |
---|
67 | ENDIF |
---|
68 | ! |
---|
69 | ! |
---|
70 | DO jk = 1, jpk ! calculate Courant numbers |
---|
71 | DO jj = 1, jpj |
---|
72 | DO ji = 1, fs_jpim1 ! vector opt. |
---|
73 | zCu_cfl(ji,jj,jk) = ABS( un(ji,jj,jk) ) * z2dt / e1u (ji,jj) ! for i-direction |
---|
74 | zCv_cfl(ji,jj,jk) = ABS( vn(ji,jj,jk) ) * z2dt / e2v (ji,jj) ! for j-direction |
---|
75 | zCw_cfl(ji,jj,jk) = ABS( wn(ji,jj,jk) ) * z2dt / e3w_n(ji,jj,jk) ! for k-direction |
---|
76 | END DO |
---|
77 | END DO |
---|
78 | END DO |
---|
79 | ! |
---|
80 | ! ! calculate maximum values and locations |
---|
81 | IF( lk_mpp ) THEN |
---|
82 | CALL mpp_maxloc( 'diacfl', zCu_cfl, umask, zCu_max, iloc_u ) |
---|
83 | CALL mpp_maxloc( 'diacfl', zCv_cfl, vmask, zCv_max, iloc_v ) |
---|
84 | CALL mpp_maxloc( 'diacfl', zCw_cfl, wmask, zCw_max, iloc_w ) |
---|
85 | ELSE |
---|
86 | iloc = MAXLOC( ABS( zcu_cfl(:,:,:) ) ) |
---|
87 | iloc_u(1) = iloc(1) + nimpp - 1 |
---|
88 | iloc_u(2) = iloc(2) + njmpp - 1 |
---|
89 | iloc_u(3) = iloc(3) |
---|
90 | zCu_max = zCu_cfl(iloc(1),iloc(2),iloc(3)) |
---|
91 | ! |
---|
92 | iloc = MAXLOC( ABS( zcv_cfl(:,:,:) ) ) |
---|
93 | iloc_v(1) = iloc(1) + nimpp - 1 |
---|
94 | iloc_v(2) = iloc(2) + njmpp - 1 |
---|
95 | iloc_v(3) = iloc(3) |
---|
96 | zCv_max = zCv_cfl(iloc(1),iloc(2),iloc(3)) |
---|
97 | ! |
---|
98 | iloc = MAXLOC( ABS( zcw_cfl(:,:,:) ) ) |
---|
99 | iloc_w(1) = iloc(1) + nimpp - 1 |
---|
100 | iloc_w(2) = iloc(2) + njmpp - 1 |
---|
101 | iloc_w(3) = iloc(3) |
---|
102 | zCw_max = zCw_cfl(iloc(1),iloc(2),iloc(3)) |
---|
103 | ENDIF |
---|
104 | ! |
---|
105 | ! ! write out to file |
---|
106 | IF( lwp ) THEN |
---|
107 | WRITE(numcfl,FMT='(2x,i4,5x,a6,4x,f7.4,1x,i4,1x,i4,1x,i4)') kt, 'Max Cu', zCu_max, iloc_u(1), iloc_u(2), iloc_u(3) |
---|
108 | WRITE(numcfl,FMT='(11x, a6,4x,f7.4,1x,i4,1x,i4,1x,i4)') 'Max Cv', zCv_max, iloc_v(1), iloc_v(2), iloc_v(3) |
---|
109 | WRITE(numcfl,FMT='(11x, a6,4x,f7.4,1x,i4,1x,i4,1x,i4)') 'Max Cw', zCw_max, iloc_w(1), iloc_w(2), iloc_w(3) |
---|
110 | ENDIF |
---|
111 | ! |
---|
112 | ! ! update maximum Courant numbers from whole run if applicable |
---|
113 | IF( zCu_max > rCu_max ) THEN ; rCu_max = zCu_max ; nCu_loc(:) = iloc_u(:) ; ENDIF |
---|
114 | IF( zCv_max > rCv_max ) THEN ; rCv_max = zCv_max ; nCv_loc(:) = iloc_v(:) ; ENDIF |
---|
115 | IF( zCw_max > rCw_max ) THEN ; rCw_max = zCw_max ; nCw_loc(:) = iloc_w(:) ; ENDIF |
---|
116 | |
---|
117 | ! ! at end of run output max Cu and Cv and close ascii file |
---|
118 | IF( kt == nitend .AND. lwp ) THEN |
---|
119 | ! to ascii file |
---|
120 | WRITE(numcfl,*) '******************************************' |
---|
121 | WRITE(numcfl,FMT='(3x,a12,6x,f7.4,1x,i4,1x,i4,1x,i4)') 'Run Max Cu', rCu_max, nCu_loc(1), nCu_loc(2), nCu_loc(3) |
---|
122 | WRITE(numcfl,FMT='(3x,a8,11x,f15.1)') ' => dt/C', z2dt/rCu_max |
---|
123 | WRITE(numcfl,*) '******************************************' |
---|
124 | WRITE(numcfl,FMT='(3x,a12,6x,f7.4,1x,i4,1x,i4,1x,i4)') 'Run Max Cv', rCv_max, nCv_loc(1), nCv_loc(2), nCv_loc(3) |
---|
125 | WRITE(numcfl,FMT='(3x,a8,11x,f15.1)') ' => dt/C', z2dt/rCv_max |
---|
126 | WRITE(numcfl,*) '******************************************' |
---|
127 | WRITE(numcfl,FMT='(3x,a12,6x,f7.4,1x,i4,1x,i4,1x,i4)') 'Run Max Cw', rCw_max, nCw_loc(1), nCw_loc(2), nCw_loc(3) |
---|
128 | WRITE(numcfl,FMT='(3x,a8,11x,f15.1)') ' => dt/C', z2dt/rCw_max |
---|
129 | CLOSE( numcfl ) |
---|
130 | ! |
---|
131 | ! to ocean output |
---|
132 | WRITE(numout,*) |
---|
133 | WRITE(numout,*) 'dia_cfl : Maximum Courant number information for the run ' |
---|
134 | WRITE(numout,*) '~~~~~~~' |
---|
135 | WRITE(numout,*) ' Max Cu = ', rCu_max, ' at (i,j,k) = (',nCu_loc(1),nCu_loc(2),nCu_loc(3),') => dt/C = ', z2dt/rCu_max |
---|
136 | WRITE(numout,*) ' Max Cv = ', rCv_max, ' at (i,j,k) = (',nCv_loc(1),nCv_loc(2),nCv_loc(3),') => dt/C = ', z2dt/rCv_max |
---|
137 | WRITE(numout,*) ' Max Cw = ', rCw_max, ' at (i,j,k) = (',nCw_loc(1),nCw_loc(2),nCw_loc(3),') => dt/C = ', z2dt/rCw_max |
---|
138 | ENDIF |
---|
139 | ! |
---|
140 | IF( ln_timing ) CALL timing_stop('dia_cfl') |
---|
141 | ! |
---|
142 | END SUBROUTINE dia_cfl |
---|
143 | |
---|
144 | |
---|
145 | SUBROUTINE dia_cfl_init |
---|
146 | !!---------------------------------------------------------------------- |
---|
147 | !! *** ROUTINE dia_cfl_init *** |
---|
148 | !! |
---|
149 | !! ** Purpose : create output file, initialise arrays |
---|
150 | !!---------------------------------------------------------------------- |
---|
151 | ! |
---|
152 | IF(lwp) THEN |
---|
153 | WRITE(numout,*) |
---|
154 | WRITE(numout,*) 'dia_cfl : Outputting CFL diagnostics to ',TRIM(clname), ' file' |
---|
155 | WRITE(numout,*) '~~~~~~~' |
---|
156 | WRITE(numout,*) |
---|
157 | ! |
---|
158 | ! create output ascii file |
---|
159 | CALL ctl_opn( numcfl, clname, 'UNKNOWN', 'FORMATTED', 'SEQUENTIAL', 1, numout, lwp, 1 ) |
---|
160 | WRITE(numcfl,*) 'Timestep Direction Max C i j k' |
---|
161 | WRITE(numcfl,*) '******************************************' |
---|
162 | ENDIF |
---|
163 | ! |
---|
164 | rCu_max = 0._wp |
---|
165 | rCv_max = 0._wp |
---|
166 | rCw_max = 0._wp |
---|
167 | ! |
---|
168 | !!gm required to work |
---|
169 | ALLOCATE ( zCu_cfl(jpi,jpj,jpk), zCv_cfl(jpi,jpj,jpk), zCw_cfl(jpi,jpj,jpk) ) |
---|
170 | !!gm end |
---|
171 | ! |
---|
172 | END SUBROUTINE dia_cfl_init |
---|
173 | |
---|
174 | !!====================================================================== |
---|
175 | END MODULE diacfl |
---|