m3d.F90 15.9 KB
Newer Older
kbk's avatar
kbk committed
1
!$Id: m3d.F90,v 1.30 2006-03-01 15:54:08 kbk Exp $
gotm's avatar
gotm committed
2 3 4 5 6 7 8 9 10 11
#include "cppdefs.h"
!-----------------------------------------------------------------------
!BOP
!
! !MODULE: m3d - 3D model component
!
! !INTERFACE:
   module m3d
!
! !DESCRIPTION:
hb's avatar
hb committed
12
!  This module contains declarations for all variables related to 3D
gotm's avatar
gotm committed
13
!  hydrodynamical calculations. Information about the calculation domain
hb's avatar
hb committed
14
!  is included from the {\tt domain} module.
gotm's avatar
gotm committed
15 16
!  The module contains public subroutines for initialisation, integration
!  and clean up of the 3D model component.
hb's avatar
hb committed
17 18 19 20 21 22 23 24
!  The {\tt m3d} module is initialised in the routine {\tt init\_3d}, see
!  section \ref{sec-init-3d} described on page
!  \pageref{sec-init-3d}.
!  The actual calculation routines are called in {\tt integrate\_3d}
!  (see section \ref{sec-integrate-3d} on page \pageref{sec-integrate-3d}).
!  and are linked in from the library {\tt lib3d.a}.
!  After the simulation, the module is closed in {\tt clean\_3d}, see
!  section \ref{sec-clean-3d} on page \pageref{sec-clean-3d}.
gotm's avatar
gotm committed
25 26
!
! !USES:
27
   use exceptions
gotm's avatar
gotm committed
28
   use parameters, only: avmmol
kbk's avatar
kbk committed
29
   use domain, only: maxdepth,vert_cord
kbk's avatar
kbk committed
30
   use m2d, only: Am
kbk's avatar
kbk committed
31
   use variables_2d, only: D,z,UEx,VEx
kbk's avatar
kbk committed
32
#ifndef NO_BAROCLINIC
gotm's avatar
gotm committed
33 34
   use temperature,only: init_temperature, do_temperature
   use salinity,   only: init_salinity, do_salinity
kbk's avatar
kbk committed
35
   use eqstate,    only: init_eqstate, do_eqstate
36 37
   use internal_pressure, only: init_internal_pressure, do_internal_pressure
   use internal_pressure, only: ip_method
kbk's avatar
kbk committed
38
#endif
kbk's avatar
kbk committed
39
#ifdef SPM
kbk's avatar
kbk committed
40
   use suspended_matter, only: init_spm, do_spm
41 42 43 44
#endif
#ifdef GETM_BIO
   use bio, only: bio_calc
   use getm_bio, only: init_getm_bio, do_getm_bio
kbk's avatar
kbk committed
45
#endif
46
   use variables_3d
gotm's avatar
gotm committed
47
   use advection_3d, only: init_advection_3d
kbk's avatar
kbk committed
48
   use bdy_3d, only: init_bdy_3d, do_bdy_3d
kbk's avatar
kbk committed
49

gotm's avatar
gotm committed
50 51 52
   IMPLICIT NONE
!
! !PUBLIC DATA MEMBERS:
kbk's avatar
kbk committed
53
   integer                             :: M=1
54
   REALTYPE                            :: cord_relax=_ZERO_
kbk's avatar
kbk committed
55 56 57
   logical                             :: calc_temp=.true.
   logical                             :: calc_salt=.true.
   logical                             :: calc_spm=.false.
kbk's avatar
kbk committed
58
   logical                             :: hotstart_spm=.false.
kbk's avatar
kbk committed
59 60 61
   logical                             :: bdy3d=.false.
   integer                             :: bdyfmt_3d,bdyramp_3d
   character(len=PATH_MAX)             :: bdyfile_3d
gotm's avatar
gotm committed
62
!
kbk's avatar
kbk committed
63 64 65
! !REVISION HISTORY:
!  Original author(s): Karsten Bolding & Hans Burchard
!
gotm's avatar
gotm committed
66
! !LOCAL VARIABLES:
67
   integer         :: vel_hor_adv=1,vel_ver_adv=1,vel_adv_split=0
kbk's avatar
kbk committed
68 69 70
#ifdef NO_BAROCLINIC
   integer         :: ip_method
#endif
gotm's avatar
gotm committed
71 72 73 74 75 76 77 78
!EOP
!-----------------------------------------------------------------------

   contains

!-----------------------------------------------------------------------
!BOP
!
hb's avatar
hb committed
79
! !IROUTINE: init_3d - initialise 3D related stuff \label{sec-init-3d}
gotm's avatar
gotm committed
80 81 82 83 84 85
!
! !INTERFACE:
   subroutine init_3d(runtype,timestep,hotstart)
   IMPLICIT NONE
!
! !INPUT PARAMETERS:
kbk's avatar
kbk committed
86 87 88
   integer, intent(in)                 :: runtype
   REALTYPE, intent(in)                :: timestep
   logical, intent(in)                 :: hotstart
gotm's avatar
gotm committed
89 90 91 92 93 94
!
! !INPUT/OUTPUT PARAMETERS:
!
! !OUTPUT PARAMETERS:
!
! !DESCRIPTION:
hb's avatar
hb committed
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112
!  Here, the {\tt m3d} namelist is read from {\tt getm.inp}, and the
!  initialisation of variables is called (see routine {\tt init\_variables}
!  described on page \pageref{sec-init-variables}).
!  Furthermore, a number of consistency checks are made for the choices
!  of the momentum advection schemes. When higher-order advection schemes
!  are chosen for the momentum advection, the compiler option {\tt UV\_TVD}
!  has to be set. Here, the macro time step $\Delta t$ is calculated 
!  from the micro time step $\Delta t_m$ and the split factor {\tt M}.
!  Then, in order to have the vertical coordinate system present already here,
!  {\tt coordinates} (see page \pageref{sec-coordinates}) needs to be called,
!  in order to enable proper interpolation of initial values for 
!  potential temperature $\theta$ and salinity $S$ for cold starts. 
!  Those initial values are afterwards read in via the routines
!  {\tt init\_temperature} (page \pageref{sec-init-temperature}) and
!  {\tt init\_salinity} (page \pageref{sec-init-salinity}).
!  Finally, in order to prepare for the first time step, the momentum advection
!  and internal pressure gradient routines are initialised and the
!  internal pressure gradient routine is called.
gotm's avatar
gotm committed
113 114
!
! !LOCAL VARIABLES:
115
   integer         :: rc
kbk's avatar
kbk committed
116 117 118
   NAMELIST /m3d/ &
             M,cnpar,cord_relax,                        &
             bdy3d,bdyfmt_3d,bdyramp_3d,bdyfile_3d,     &
119
             vel_hor_adv,vel_ver_adv,vel_adv_split,     &
120
             calc_temp,calc_salt,calc_spm,              &
121
             avmback,avhback,ip_method
gotm's avatar
gotm committed
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136
!
!EOP
!-------------------------------------------------------------------------
!BOC
#ifdef DEBUG
   integer, save :: Ncall = 0
   Ncall = Ncall+1
   write(debug,*) 'init_3d() # ',Ncall
#endif

   LEVEL1 'init_3d'
!  Read 3D-model specific things from the namelist.
   read(NAMLST,m3d)
!   rewind(NAMLST)

137 138 139 140 141 142 143 144 145
   if (avmback .lt. _ZERO_) then
      LEVEL2 "setting avmback to 0."
      avmback = _ZERO_
   end if
   if (avhback .lt. _ZERO_) then
      LEVEL2 "setting avhback to 0."
      avhback = _ZERO_
   end if

kbk's avatar
kbk committed
146 147 148 149
#ifndef SPM
   if(calc_spm) stop 'To use SPM you have to recompile with -DSPM'
#endif

150 151 152 153
#ifndef GETM_BIO
!KBK   if(bio_calc) stop 'To use BIO you have to recompile with -DBIO'
#endif

gotm's avatar
gotm committed
154 155 156
! Allocates memory for the public data members - if not static
   call init_variables_3d(runtype)

157 158 159 160 161
!  Sanity checks for advection specifications
   LEVEL2 'vel_hor_adv=   ',vel_hor_adv
   LEVEL2 'vel_ver_adv=   ',vel_ver_adv
   LEVEL2 'vel_adv_split= ',vel_adv_split
   if(vel_hor_adv .gt. 1) then
gotm's avatar
gotm committed
162 163 164
#ifndef UV_TVD
      STDERR 'To run the model with higher order advection for momentum'
      STDERR 'you need to re-compile the model with the option -DUV_TVD.'
165
      call getm_error("init_3d()","GETM needs recompilation")
gotm's avatar
gotm committed
166
#endif
167 168 169 170 171 172
   else
      vel_adv_split=-1
      if(vel_ver_adv .ne. 1) then
         LEVEL2 "setting vel_ver_adv to 1 - since vel_hor_adv is 1"
         vel_ver_adv=1
      end if
gotm's avatar
gotm committed
173
   end if
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
   LEVEL2 "horizontal: ",trim(adv_schemes(vel_hor_adv))," of momentum"
   LEVEL2 "vertical:   ",trim(adv_schemes(vel_ver_adv))," of momentum"

   select case (vel_adv_split)
      case (-1)
      case (0)
         select case (vel_hor_adv)
            case (2,3,4,5,6)
            case default
               call getm_error("init_3d()", &
                    "vel_adv_split=0: vel_hor_adv not valid (2-6)")
         end select
         select case (vel_ver_adv)
            case (2,3,4,5,6)
            case default
               call getm_error("init_3d()", &
                    "vel_adv_split=0: vel_ver_adv not valid (2-6)")
         end select
         LEVEL2 "1D split --> full u, full v, full w"
      case (1)
         select case (vel_hor_adv)
            case (2,3,4,5,6)
            case default
               call getm_error("init_3d()", &
                    "vel_adv_split=1: vel_hor_adv not valid (2-6)")
         end select
         select case (vel_ver_adv)
            case (2,3,4,5,6)
            case default
               call getm_error("init_3d()", &
                    "vel_adv_split=1: vel_ver_adv not valid (2-6)")
         end select
         LEVEL2 "1D split --> half u, half v, full w, half v, half u"
      case (2)
         select case (vel_hor_adv)
            case (2,7)
            case default
               call getm_error("init_3d()", &
                    "vel_adv_split=2: vel_hor_adv not valid (2,7)")
         end select
         select case (vel_ver_adv)
            case (2,3,4,5,6)
            case default
               call getm_error("init_3d()", &
                    "vel_adv_split=2: vel_ver_adv not valid (2-6)")
         end select
         LEVEL2 "2D-hor, 1D-vert split --> full uv, full w"
      case default
   end select

gotm's avatar
gotm committed
224
   dt = M*timestep
225 226 227 228 229 230 231 232

#ifdef CONSTANT_VISCOSITY
   num=avmback
   nuh=avhback
#else
   num=1.e-15
   nuh=1.e-15
#endif
gotm's avatar
gotm committed
233 234

!  Needed for interpolation of temperature and salinity
kbk's avatar
kbk committed
235
   if (.not. hotstart) then
gotm's avatar
gotm committed
236
      call start_macro()
kbk's avatar
kbk committed
237
      call coordinates(vert_cord,cord_relax,maxdepth)
238
      call hcc_check()
kbk's avatar
kbk committed
239
   end if
gotm's avatar
gotm committed
240

kbk's avatar
kbk committed
241
#ifndef NO_BAROCLINIC
gotm's avatar
gotm committed
242
   if (runtype .eq. 3 .or. runtype .eq. 4) then
gotm's avatar
gotm committed
243
      T = _ZERO_ ; S = _ZERO_ ; rho = _ZERO_
gotm's avatar
gotm committed
244 245
      if(calc_temp) call init_temperature(1)
      if(calc_salt) call init_salinity(1)
kbk's avatar
kbk committed
246
   end if
247
#endif
kbk's avatar
kbk committed
248

249
#ifndef NO_BAROCLINIC
kbk's avatar
kbk committed
250
    if (runtype .eq. 3 .or. runtype .eq. 4) then
251
      call init_eqstate()
gotm's avatar
gotm committed
252 253 254
#ifndef PECS
      call do_eqstate()
#endif
255 256
      if (runtype .ge. 3) call init_internal_pressure()
      if (runtype .eq. 3) call do_internal_pressure()
gotm's avatar
gotm committed
257 258 259 260
      if (runtype .eq. 4) then
         call init_advection_3d(2)
      end if
   end if
kbk's avatar
kbk committed
261
#endif
262

kbk's avatar
kbk committed
263 264
#ifdef SPM
      if(calc_spm)  call init_spm(hotstart_spm,runtype)
265 266 267 268 269 270
      if(runtype .ne. 4) call init_advection_3d(2)
#endif

#ifdef GETM_BIO
!KBK      if(bio_calc) call init_getm_bio()
      call init_getm_bio()
kbk's avatar
kbk committed
271
#endif
gotm's avatar
gotm committed
272 273 274 275 276 277 278 279 280 281 282 283 284 285

   if (bdy3d) call init_bdy_3d()

#ifdef DEBUG
   write(debug,*) 'Leaving init_3d()'
   write(debug,*)
#endif
   return
   end subroutine init_3d
!EOC

!-----------------------------------------------------------------------
!BOP
!
hb's avatar
hb committed
286 287
! !IROUTINE: integrate_3d - calls to do 3D model integration
! \label{sec-integrate-3d}
gotm's avatar
gotm committed
288 289 290 291 292 293
!
! !INTERFACE:
   subroutine integrate_3d(runtype,n)
   IMPLICIT NONE
!
! !INPUT PARAMETERS:
kbk's avatar
kbk committed
294
   integer, intent(in)                 :: runtype,n
gotm's avatar
gotm committed
295 296 297 298 299 300
!
! !INPUT/OUTPUT PARAMETERS:
!
! !OUTPUT PARAMETERS:
!
! !DESCRIPTION:
hb's avatar
hb committed
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
! This is a wrapper routine to call all 3D related subroutines.
! The call position for the {\tt coordinates} routine depends on 
! the compiler option 
! {\tt MUDFLAT}: If it is defined, then the 
! call to {\tt coordinates} construction is made such that drying and flooding
! is stable. If {\tt MUDFLAT} is not defined, then the adaptive grids with
! Lagrangian component which are currently under development are supported. 
! Both, drying and flooding and
! Lagrangian coordinates does not go together yet.
! The call sequence is as follows:
!
! \vspace{0.5cm}
! 
! \begin{tabular}{lll}
! {\tt start\_macro}           & initialising a 3d step & see page
! \pageref{sec-start-macro} \\
! {\tt do\_bdy\_3d}            & boundary conditions for $\theta$ and $S$ & see
! page \pageref{sec-do-bdy-3d} \\
! {\tt coordinates}            & layer heights ({\tt MUTFLAT} defined) & see
! page \pageref{sec-coordinates} \\
! {\tt bottom\_friction\_3d}   & bottom friction & see page
! \pageref{sec-bottom-friction-3d} \\
! {\tt do\_internal\_pressure} & internal pressure gradient & see page
! \pageref{sec-do-internal-pressure} \\
! {\tt uu\_momentum\_3d}       & layer-integrated $u$-velocity & see page
! \pageref{sec-uu-momentum-3d} \\
! {\tt vv\_momentum\_3d}       & layer-integrated $v$-velocity & see page
! \pageref{sec-vv-momentum-3d} \\
! {\tt coordinates}            & layer heights ({\tt MUTFLAT} not defined) & see
! page \pageref{sec-coordinates} \\
! {\tt ww\_momentum\_3d}       & grid-related vertical velocity & see page
! \pageref{sec-ww-momentum-3d} \\
! {\tt uv\_advect\_3d}         & momentum advection & see page
! \pageref{sec-uv-advect-3d} \\
! {\tt uv\_diffusion\_3d}      & momentum diffusion & see page
! \pageref{sec-uv-diffusion-3d} \\
! {\tt stresses\_3d}           & stresses (for GOTM) & see page
! \pageref{sec-stresses-3d} \\
! {\tt ss\_nn}                 & shear and stratification (for GOTM) & see page
! \pageref{sec-ss-nn} \\
! {\tt gotm}                   & interface and call to GOTM & see page
! \pageref{sec-gotm} \\
! {\tt do\_temperature}        & potential temperature equation & see page
! \pageref{sec-do-temperature} \\
! {\tt do\_salinity}           & salinity equation & see page
! \pageref{sec-do-salinity} \\
! {\tt do\_eqstate}            & equation of state & see page
! \pageref{sec-do-eqstate} \\
! {\tt do\_spm}                & suspended matter equation & see page 
! \pageref{sec-do-spm} \\
! {\tt do\_getm\_bio}          & call to GOTM-BIO (not yet released) & \\
! {\tt slow\_bottom\_friction} & slow bottom friction & see page
! \pageref{sec-slow-bottom-friction} \\
! {\tt slow\_advection}        & slow advection terms & see page
! \pageref{sec-slow-advection} \\
! {\tt slow\_diffusion}        & slow diffusion terms & see page
! \pageref{sec-slow-diffusion} \\
! {\tt slow\_terms}            & sum of slow terms & see page
! \pageref{sec-slow-terms} \\
! {\tt stop\_macro}            & finishing a 3d step & see page
! \pageref{sec-stop-macro}
! \end{tabular}
! 
! \vspace{0.5cm}
!
! Several calls are only executed for certain compiler options. At each
! time step the call sequence for the horizontal momentum equations is
! changed in order to allow for higher order accuracy for the Coriolis
! rotation.
gotm's avatar
gotm committed
370 371
!
! !LOCAL VARIABLES:
kbk's avatar
kbk committed
372
  logical, save              :: ufirst=.true.
gotm's avatar
gotm committed
373 374 375 376 377 378 379 380 381 382
!
!EOP
!-------------------------------------------------------------------------
!BOC
#ifdef DEBUG
   integer, save :: Ncall = 0
   Ncall = Ncall+1
   write(debug,*) 'integrate_3d() # ',Ncall
#endif
   call start_macro()
kbk's avatar
kbk committed
383
#ifndef NO_BAROCLINIC
gotm's avatar
gotm committed
384
   if (bdy3d) call do_bdy_3d(0,T)
kbk's avatar
kbk committed
385
#endif
386 387 388
#ifdef MUDFLAT
   call coordinates(vert_cord,cord_relax,maxdepth)
#endif
gotm's avatar
gotm committed
389
#ifndef NO_BOTTFRIC
kbk's avatar
kbk committed
390
   if (kmax .gt. 1) then
gotm's avatar
gotm committed
391 392 393 394
      call bottom_friction_3d()
   end if
#endif
   SS = _ZERO_
kbk's avatar
kbk committed
395
#ifndef NO_BAROCLINIC
gotm's avatar
gotm committed
396
   NN = _ZERO_
397
   if (runtype .eq. 4) call do_internal_pressure()
kbk's avatar
kbk committed
398
#endif
399 400
   huo=hun
   hvo=hvn
gotm's avatar
gotm committed
401 402 403 404 405 406 407 408 409
   if (ufirst) then
      call uu_momentum_3d(bdy3d)
      call vv_momentum_3d(bdy3d)
      ufirst=.false.
   else
      call vv_momentum_3d(bdy3d)
      call uu_momentum_3d(bdy3d)
      ufirst=.true.
   end if
410
#ifndef MUDFLAT
411
   call coordinates(vert_cord,cord_relax,maxdepth)
412
#endif
gotm's avatar
gotm committed
413 414 415 416
   if (kmax .gt. 1) then
      call ww_momentum_3d()
   end if
#ifndef NO_ADVECT
kbk's avatar
kbk committed
417
   if (kmax .gt. 1) then
418
      call uv_advect_3d(vel_hor_adv,vel_ver_adv,vel_adv_split)
gotm's avatar
gotm committed
419 420 421 422 423 424 425
      if (Am .gt. _ZERO_) then
         call uv_diffusion_3d(Am)  ! Must be called after uv_advect_3d
      end if
   end if
#else
   STDERR 'NO_ADVECT 3D'
#endif
kbk's avatar
kbk committed
426 427

   if (kmax .gt. 1) then
428
#ifndef NO_BOTTFRIC
gotm's avatar
gotm committed
429
      call stresses_3d()
430 431
#endif
#ifndef CONSTANT_VISCOSITY
gotm's avatar
gotm committed
432 433 434 435 436
#ifndef PARABOLIC_VISCOSITY
      call ss_nn()
#endif
      call gotm()
#endif
437
   end if
kbk's avatar
kbk committed
438
#ifndef NO_BAROCLINIC
kbk's avatar
kbk committed
439
   if(runtype .eq. 4) then        ! prognostic T and S
gotm's avatar
gotm committed
440 441
      if (calc_temp) call do_temperature(n)
      if (calc_salt) call do_salinity(n)
kbk's avatar
kbk committed
442
   end if
443
#endif
kbk's avatar
kbk committed
444

445 446
#ifndef NO_BAROCLINIC
   if(runtype .eq. 4) then
gotm's avatar
gotm committed
447 448 449 450
#ifndef PECS
      call do_eqstate()
#endif
   end if
kbk's avatar
kbk committed
451
#endif
gotm's avatar
gotm committed
452

kbk's avatar
kbk committed
453
#ifdef SPM
454 455 456 457 458
   if (calc_spm) call do_spm()
#endif

#ifdef GETM_BIO
   if (bio_calc) call do_getm_bio(dt)
kbk's avatar
kbk committed
459 460
#endif

kbk's avatar
kbk committed
461
   UEx=_ZERO_ ; VEx=_ZERO_
kbk's avatar
kbk committed
462
   if (kmax .gt. 1) then
gotm's avatar
gotm committed
463
#ifndef NO_BOTTFRIC
kbk's avatar
kbk committed
464
      call slow_bottom_friction()
gotm's avatar
gotm committed
465 466 467
#endif
#ifndef NO_ADVECT
#ifndef UV_ADV_DIRECT
kbk's avatar
kbk committed
468 469 470 471
      call slow_advection()
      if (Am .gt. _ZERO_) then
         call slow_diffusion(Am) ! Has to be called after slow_advection.
      end if
gotm's avatar
gotm committed
472 473 474
#endif
#endif
   end if
gotm's avatar
gotm committed
475

gotm's avatar
gotm committed
476 477 478 479 480 481 482 483 484 485 486 487 488 489
   call slow_terms()
   call stop_macro()

#ifdef DEBUG
     write(debug,*) 'Leaving integrate_3d()'
     write(debug,*)
#endif
   return
   end subroutine integrate_3d
!EOC

!-----------------------------------------------------------------------
!BOP
!
hb's avatar
hb committed
490
! !IROUTINE: clean_3d - cleanup after 3D run \label{sec-clean-3d}
gotm's avatar
gotm committed
491 492 493 494 495 496 497 498 499 500 501 502
!
! !INTERFACE:
   subroutine clean_3d()
   IMPLICIT NONE
!
! !INPUT PARAMETERS:
!
! !INPUT/OUTPUT PARAMETERS:
!
! !OUTPUT PARAMETERS:
!
! !DESCRIPTION:
hb's avatar
hb committed
503 504
! Here, a call to the routine {\tt clean\_variables\_3d} which howewer
! does not do anything yet.
gotm's avatar
gotm committed
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
!
! !LOCAL VARIABLES:
!
!EOP
!-----------------------------------------------------------------------
!BOC
#ifdef DEBUG
   integer, save :: Ncall = 0
   Ncall = Ncall+1
   write(debug,*) 'clean_3d() # ',Ncall
#endif

   call clean_variables_3d()

#ifdef DEBUG
     write(debug,*) 'Leaving clean_3d()'
     write(debug,*)
#endif
   return
   end subroutine clean_3d
!EOC

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

   end module m3d

!-----------------------------------------------------------------------
! Copyright (C) 2000 - Hans Burchard and Karsten Bolding (BBH)         !
!-----------------------------------------------------------------------