meanflow.F90 13.6 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
!$Id: meanflow.F90,v 1.16 2007-01-03 21:45:20 hb Exp $
#include"cppdefs.h"
!-----------------------------------------------------------------------
!BOP
!
! !MODULE: Mean Flow
!
! !INTERFACE:
   module meanflow
!
! !DESCRIPTION:
!  This module provides all variables necessary for the meanflow
!  calculation and also makes the proper initialisations.
!
! !USES:
   IMPLICIT NONE
!  Default all is private.
   private
!
! !PUBLIC MEMBER FUNCTIONS:
   public init_meanflow, clean_meanflow
!
! !PUBLIC DATA MEMBERS:
   logical, public                              :: grid_ready=.false.

!  coordinate z, layer thicknesses
   REALTYPE, public, dimension(:), allocatable  :: ga,z,h,ho

!  the velocity components
   REALTYPE, public, dimension(:), allocatable  :: u,v,w

!  velocity at old time step
   REALTYPE, public, dimension(:), allocatable  :: uo,vo

!  potential temperature, salinity
   REALTYPE, public, dimension(:), allocatable  :: T,S,rho

!  nitrate
   REALTYPE, public, dimension(:), allocatable  :: nit           !CHG3

!  ammonium
   REALTYPE, public, dimension(:), allocatable  :: amm           !CHG5

!  hydrocarbon
   REALTYPE, public, dimension(:), allocatable  :: hcb

!  bouyancy frequency squared
!  (total, from temperature only, from salinity only)
   REALTYPE, public, dimension(:), allocatable  :: NN,NNT,NNS

!  shear-frequency squared
!  (total, from u only, from v only)
   REALTYPE, public, dimension(:), allocatable  :: SS,SSU,SSV

!  buoyancy, short-wave radiation,
!  extra production of tke by see-grass etc
   REALTYPE, public, dimension(:), allocatable  :: buoy,rad,xP

!  a dummy array
!  (most often used for diffusivities)
   REALTYPE, public, dimension(:), allocatable  :: avh

!  grid-related vertical velocity
   REALTYPE, public, dimension(:), allocatable  :: w_grid

!  extra friction terms due to e.g. seagrass
   REALTYPE, public, dimension(:), allocatable  :: fric,drag

!  shading in the water column
   REALTYPE, public, dimension(:), allocatable  :: bioshade

# ifdef EXTRA_OUTPUT

!  dummies for testing
   REALTYPE, public, dimension(:), allocatable   :: mean1,mean2,mean3,mean4,mean5

# endif

!  the 'meanflow' namelist
   REALTYPE, public                    :: h0b=0.05
   REALTYPE, public                    :: z0s_min=0.02
   logical,  public                    :: charnock=.false.
   REALTYPE, public                    :: charnock_val=1400.
   REALTYPE, public                    :: ddu=0.
   REALTYPE, public                    :: ddl=0.
   integer,  public                    :: grid_method=1
   REALTYPE, public                    :: c1ad=0.8
   REALTYPE, public                    :: c2ad=0.0
   REALTYPE, public                    :: c3ad=0.1
   REALTYPE, public                    :: c4ad=0.1
   REALTYPE, public                    :: Tgrid=3600.
   REALTYPE, public                    :: NNnorm=0.2
   REALTYPE, public                    :: SSnorm=0.2
   REALTYPE, public                    :: dsurf=10.0
   REALTYPE, public                    :: dtgrid=5.
   character(LEN=PATH_MAX), public     :: grid_file='grid.dat'
   REALTYPE, public                    :: gravity=9.81
   REALTYPE, public                    :: rho_0=1027.
   REALTYPE, public                    :: cp=3985.
   REALTYPE, public                    :: avmolu=1.3e-6
   REALTYPE, public                    :: avmolt=1.4e-7
   REALTYPE, public                    :: avmols=1.1e-9
   REALTYPE, public                    :: avmoln=1.1e-9         !CHG3
   REALTYPE, public                    :: avmola=1.1e-9         !CHG5
   REALTYPE, public                    :: avmolhc=1.1e-9
   integer,  public                    :: MaxItz0b=10
   logical,  public                    :: no_shear=.false.

!  the roughness lengths
   REALTYPE, public                    :: z0b,z0s,za

!  the coriolis parameter
   REALTYPE, public                    :: cori

!  the friction velocities
   REALTYPE, public                    :: u_taub,u_taus

!  other stuff
   integer,  public                    :: eq_state_method
   REALTYPE, public                    :: depth0=0.
   REALTYPE, public                    :: depth
   REALTYPE, public                    :: obs_heat_content=0.
   REALTYPE, public                    :: calc_heat_content=0.
!
! !DEFINED PARAMETERS:
   REALTYPE, public, parameter         :: pi=3.141592654
!
! !REVISION HISTORY:
!  Original author(s): Karsten Bolding & Hans Burchard
!
!  $Log: meanflow.F90,v $
!  Revision 1.16  2007-01-03 21:45:20  hb
!  LaTeX bug fix in documentation
!
!  Revision 1.15  2006-11-27 15:26:37  kbk
!  initialise grid depending on grid_ready
!
!  Revision 1.14  2006-11-27 08:44:33  kbk
!  de-allocate ga
!
!  Revision 1.13  2006-11-24 15:13:41  kbk
!  de-allocate memory and close open files
!
!  Revision 1.12  2006-11-20 17:26:15  kbk
!  [Cc]harnok -> [Cc]harnock - A. Jenkins
!
!  Revision 1.11  2005/06/27 13:44:07  kbk
!  modified + removed traling blanks
!
!  Revision 1.10  2004/01/27 08:33:20  lars
!  omega-value bug fix
!
!  Revision 1.9  2004/01/12 15:21:09  lars
!  added za for sediment-induced bottom roughness
!
!  Revision 1.8  2003/07/23 12:33:21  hb
!  fixed bioshade init and use
!
!  Revision 1.6  2003/04/05 07:01:16  kbk
!  moved bioshade variable to meanflow - to compile properly
!
!  Revision 1.5  2003/03/28 09:20:35  kbk
!  added new copyright to files
!
!  Revision 1.4  2003/03/28 08:15:01  kbk
!  removed tabs
!
!  Revision 1.3  2003/03/10 08:50:06  gotm
!  Improved documentation and cleaned up code
!
!  Revision 1.2  2001/11/18 15:58:02  gotm
!  Vertical grid can now be read from file
!  Revision 1.1.1.1  2001/02/12 15:55:57  gotm
!  initial import into CVS
!
!EOP
!
!  private date members
   REALTYPE, parameter       :: omega=2*pi/86164.
!
!-----------------------------------------------------------------------

   contains

!-----------------------------------------------------------------------
!BOP
!
! !IROUTINE: Initialisation of the mean flow variables
!
! !INTERFACE:
   subroutine init_meanflow(namlst,fn,nlev,latitude)
!
! !DESCRIPTION:
!  Allocates memory and initialises everything related
!  to the `meanflow' component of GOTM.
!
! !USES:
   IMPLICIT NONE
!
! !INPUT PARAMETERS:
   integer, intent(in)                  :: namlst
   character(len=*), intent(in)         :: fn
   integer, intent(in)                  :: nlev
   REALTYPE, intent(in)                 :: latitude
!
! !REVISION HISTORY:
!  Original author(s): Karsten Bolding & Hans Burchard
!
!  See log for the meanflow module
!
!EOP
!
! !LOCAL VARIABLES:
   integer                   :: rc

   namelist /meanflow/  h0b,z0s_min,charnock,charnock_val,ddu,ddl,     &
                        grid_method,c1ad,c2ad,c3ad,c4ad,Tgrid,NNnorm,  &
                        SSnorm,dsurf,dtgrid,grid_file,gravity,rho_0,cp,&
                        avmolu,avmolT,avmolS,MaxItz0b,no_shear,        &
                        avmoln,avmola                                        !CHG3-5
!
!-----------------------------------------------------------------------
!BOC
   LEVEL1 'init_meanflow'

   open(namlst,file=fn,status='old',action='read',err=80)
   LEVEL2 'reading meanflow namelists..'
   read(namlst,nml=meanflow,err=81)
   close (namlst)
   LEVEL2 'done.'

   LEVEL2 'allocation meanflow memory..'

   allocate(ga(0:nlev),stat=rc)
   if (rc /= 0) STOP 'init_meanflow: Error allocating (ga)'
   ga = _ZERO_

   allocate(z(0:nlev),stat=rc)
   if (rc /= 0) STOP 'init_meanflow: Error allocating (z)'
   z = _ZERO_

   allocate(h(0:nlev),stat=rc)
   if (rc /= 0) STOP 'init_meanflow: Error allocating (h)'
   h = _ZERO_

   allocate(ho(0:nlev),stat=rc)
   if (rc /= 0) STOP 'init_meanflow: Error allocating (ho)'
   ho = _ZERO_

   allocate(u(0:nlev),stat=rc)
   if (rc /= 0) STOP 'init_meanflow: Error allocating (u)'
   u = _ZERO_

   allocate(uo(0:nlev),stat=rc)
   if (rc /= 0) STOP 'init_meanflow: Error allocating (uo)'
   uo = _ZERO_

   allocate(v(0:nlev),stat=rc)
   if (rc /= 0) STOP 'init_meanflow: Error allocating (v)'
   v = _ZERO_

   allocate(vo(0:nlev),stat=rc)
   if (rc /= 0) STOP 'init_meanflow: Error allocating (vo)'
   vo = _ZERO_

   allocate(w(0:nlev),stat=rc)
   if (rc /= 0) STOP 'init_meanflow: Error allocating (w)'
   w = _ZERO_

   allocate(fric(0:nlev),stat=rc)
   if (rc /= 0) STOP 'init_meanflow: Error allocating (fric)'
   fric = _ZERO_

   allocate(drag(0:nlev),stat=rc)
   if (rc /= 0) STOP 'init_meanflow: Error allocating (drag)'
   drag = _ZERO_

   allocate(T(0:nlev),stat=rc)
   if (rc /= 0) STOP 'init_meanflow: Error allocating (T)'
   T = _ZERO_

   allocate(S(0:nlev),stat=rc)
   if (rc /= 0) STOP 'init_meanflow: Error allocating (S)'
   S = _ZERO_

   allocate(nit(0:nlev),stat=rc)                            !CHG3
   if (rc /= 0) STOP 'init_meanflow: Error allocating (nit)'
   nit = _ZERO_

   allocate(amm(0:nlev),stat=rc)                            !CHG5
   if (rc /= 0) STOP 'init_meanflow: Error allocating (amm)'
   amm = _ZERO_

   allocate(hcb(0:nlev),stat=rc)
   if (rc /= 0) STOP 'init_meanflow: Error allocating (hcb)'
   hcb = _ZERO_

   allocate(rho(0:nlev),stat=rc)
   if (rc /= 0) STOP 'init_meanflow: Error allocating (rho)'
   rho = _ZERO_

   allocate(NN(0:nlev),stat=rc)
   if (rc /= 0) STOP 'init_meanflow: Error allocating (NN)'
   NN = _ZERO_

   allocate(NNT(0:nlev),stat=rc)
   if (rc /= 0) STOP 'init_meanflow: Error allocating (NNT)'
   NNT = _ZERO_

   allocate(NNS(0:nlev),stat=rc)
   if (rc /= 0) STOP 'init_meanflow: Error allocating (NNS)'
   NNS = _ZERO_

   allocate(SS(0:nlev),stat=rc)
   if (rc /= 0) STOP 'init_meanflow: Error allocating (SS)'
   SS = _ZERO_

   allocate(SSU(0:nlev),stat=rc)
   if (rc /= 0) STOP 'init_meanflow: Error allocating (SSU)'
   SSU = _ZERO_

   allocate(SSV(0:nlev),stat=rc)
   if (rc /= 0) STOP 'init_meanflow: Error allocating (SSV)'
   SSV = _ZERO_

   allocate(xP(0:nlev),stat=rc)
   if (rc /= 0) STOP 'init_meanflow: Error allocating (xP)'
   xP = _ZERO_

   allocate(buoy(0:nlev),stat=rc)
   if (rc /= 0) STOP 'init_meanflow: Error allocating (buoy)'
   buoy = _ZERO_

   allocate(rad(0:nlev),stat=rc)
   if (rc /= 0) STOP 'init_meanflow: Error allocating (rad)'
   rad = _ZERO_

   allocate(avh(0:nlev),stat=rc)
   if (rc /= 0) STOP 'init_meanflow: Error allocating (avh)'
   avh = _ZERO_

   allocate(w_grid(0:nlev),stat=rc)
   if (rc /= 0) STOP 'init_meanflow: Error allocating (w_grid)'
   w_grid = _ZERO_

   allocate(bioshade(0:nlev),stat=rc)
   if (rc /= 0) STOP 'init_meanflow: Error allocating (bioshade)'
   bioshade= _ONE_

# ifdef EXTRA_OUTPUT

   allocate(mean1(0:nlev),stat=rc)
   if (rc /= 0) stop 'init_meanflow: Error allocating (mean1)'
   mean1 = _ZERO_

   allocate(mean2(0:nlev),stat=rc)
   if (rc /= 0) stop 'init_meanflow: Error allocating (mean2)'
   mean2 = _ZERO_

   allocate(mean3(0:nlev),stat=rc)
   if (rc /= 0) stop 'init_meanflow: Error allocating (mean3)'
   mean3 = _ZERO_

   allocate(mean4(0:nlev),stat=rc)
   if (rc /= 0) stop 'init_meanflow: Error allocating (mean4)'
   mean4 = _ZERO_

   allocate(mean5(0:nlev),stat=rc)
   if (rc /= 0) stop 'init_meanflow: Error allocating (mean5)'
   mean5 = _ZERO_

# endif

   LEVEL2 'done.'

   depth0=depth
   z0b=0.03*h0b

   z0s=z0s_min    ! lu (otherwise z0s is not initialized)

   za=_ZERO_      ! roughness caused by suspended sediment

   cori=2*omega * sin(2*pi*latitude/360.)

   return
80 FATAL 'I could not open: ',trim(fn)
   stop 'init_meanflow'
81 FATAL 'I could not read "meanflow" namelist'
   stop 'init_meanflow'

   end subroutine init_meanflow
!EOC

!-----------------------------------------------------------------------
!BOP
!
! !IROUTINE: Cleaning up the mean flow variables
!
! !INTERFACE:
   subroutine clean_meanflow()
!
! !DESCRIPTION:
!  De-allocates all memory allocated via init\_meanflow()
!
! !USES:
   IMPLICIT NONE
!
! !INPUT PARAMETERS:
!
! !REVISION HISTORY:
!  Original author(s): Karsten Bolding & Hans Burchard
!
!  See log for the meanflow module
!
!EOP
!-----------------------------------------------------------------------
!BOC
   LEVEL1 'clean_meanflow'

   LEVEL2 'de-allocation meanflow memory ...'
   if (allocated(ga)) deallocate(ga)
   if (allocated(z)) deallocate(z)
   if (allocated(h)) deallocate(h)
   if (allocated(ho)) deallocate(ho)
   if (allocated(u)) deallocate(u)
   if (allocated(uo)) deallocate(uo)
   if (allocated(v)) deallocate(v)
   if (allocated(vo)) deallocate(vo)
   if (allocated(w)) deallocate(w)
   if (allocated(fric)) deallocate(fric)
   if (allocated(drag)) deallocate(drag)
   if (allocated(T)) deallocate(T)
   if (allocated(S)) deallocate(S)
   if (allocated(nit)) deallocate(nit)               !CHG3
   if (allocated(amm)) deallocate(amm)               !CHG5
   if (allocated(hcb)) deallocate(hcb)
   if (allocated(rho)) deallocate(rho)
   if (allocated(NN)) deallocate(NN)
   if (allocated(NNT)) deallocate(NNT)
   if (allocated(NNS)) deallocate(NNS)
   if (allocated(SS)) deallocate(SS)
   if (allocated(SSU)) deallocate(SSU)
   if (allocated(SSV)) deallocate(SSV)
   if (allocated(xP)) deallocate(xP)
   if (allocated(buoy)) deallocate(buoy)
   if (allocated(rad)) deallocate(rad)
   if (allocated(avh)) deallocate(avh)
   if (allocated(w_grid)) deallocate(w_grid)
   if (allocated(bioshade)) deallocate(bioshade)
# ifdef EXTRA_OUTPUT
   if (allocated(mean1)) dallocate(mean1)
   if (allocated(mean2)) dallocate(mean2)
   if (allocated(mean3)) dallocate(mean3)
   if (allocated(mean4)) dallocate(mean4)
   if (allocated(mean5)) dallocate(mean5)
# endif
   LEVEL2 'done.'

   grid_ready=.false.

   return
   end subroutine clean_meanflow
!EOC

!-----------------------------------------------------------------------

   end module meanflow

!-----------------------------------------------------------------------
! Copyright by the GOTM-team under the GNU Public License - www.gnu.org
!-----------------------------------------------------------------------