variables_3d.F90 23 KB
Newer Older
gotm's avatar
gotm committed
1 2 3 4
#include "cppdefs.h"
!-----------------------------------------------------------------------
!BOP
!
5
! !MODULE: variables_3d - global 3D related variables \label{sec-variables-3d}
gotm's avatar
gotm committed
6 7 8 9 10 11 12
!
! !INTERFACE:
   module variables_3d
!
! !DESCRIPTION:
!  This modules contains declarations for all variables related to 3D
!  hydrodynamical calculations. Information about the calculation domain
hb's avatar
hb committed
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
!  is included from the {\tt domain} module.
!  The variables are either statically defined in {\tt static\_3d.h} or
!  dynamically allocated in {\tt dynamic\_declarations\_3d.h}.
!  The variables which need to be declared have the following dimensions,
!  units and meanings:
!
! \vspace{0.5cm}
! \begin{supertabular}{llll}
! {\tt kmin} & 2D & [-] & lowest index in T-point \\
! {\tt kumin} & 2D &[-]  & lowest index in U-point \\
! {\tt kvmin} & 2D &[-]  & lowest index in V-point \\
! {\tt kmin\_pmz} & 2D &[-]  & lowest index in T-point (poor man's
! $z$-coordinate)\\
! {\tt kumin\_pmz} & 2D &[-]  & lowest index in U-point (poor man's
! $z$-coordinate)\\
! {\tt kvmin\_pmz} & 2D &[-]  & lowest index in V-point (poor man's
! $z$-coordinate)\\
! {\tt uu} & 3D & [m$^2$s$^{-1}$] & layer integrated $u$ transport
! $p_k$\\
! {\tt vv} & 3D & [m$^2$s$^{-1}$] & layer integrated $v$ transport
! $q_k$\\
! {\tt ww} & 3D & [m\,s$^{-1}$] & grid-related vertical velocity
! $\bar w_k$\\
! {\tt ho} & 3D & [m] & old layer height in T-point \\
! {\tt hn} & 3D & [m]& new layer height in T-point \\
! {\tt huo} & 3D &[m]& old layer height in U-point \\
! {\tt hun} & 3D & [m]& new layer height in U-point \\
! {\tt hvo} & 3D & [m]& old layer height in V-point \\
! {\tt hvn} & 3D & [m]& new layer height in V-point \\
! {\tt hcc} & 3D &[-] & hydrostatic consistency index in T-points\\
43
! {\tt uuEx} & 3D & [m$^2$s$^{-2}$] & sum of advection and
hb's avatar
hb committed
44
! diffusion for $u$-equation\\
45
! {\tt vvEx} & 3D &  [m$^2$s$^{-2}$]& sum of advection and
hb's avatar
hb committed
46 47 48 49 50 51 52 53 54 55 56
! diffusion for $v$-equation\\
! {\tt num} & 3D &  [m$^2$s$^{-1}$]& eddy viscosity on $w$-points
! $\nu_t$\\
! {\tt nuh} & 3D &  [m$^2$s$^{-1}$]& eddy diffusivity on $w$-points $\nu'_t$\\
! {\tt tke} & 3D &  [m$^2$s$^{-2}$]& turbulent kinetic energy $k$\\
! {\tt eps} & 3D &  [m$^2$s$^{-3}$]& turbulent dissipation rate
! $\eps$ \\
! {\tt SS} & 3D & [s$^{-2}$]& shear-frequency squared $M^2$ \\
! {\tt NN} & 3D &  [s$^{-2}$]& Brunt-V\"ais\"al\"a frequency squared$N^2$ \\
! {\tt S} & 3D & [psu] & salinity $S$ \\
! {\tt T} & 3D & [$^{\circ}$C]& potential temperature $\theta$ \\
57 58 59
! {\tt rad} & 3D & [Wm$^{-2}$]& Short wave penetration \\
! {\tt rho} & 3D & [kg\,m$^{-3}$]& density $rho$ \\
! {\tt buoy} & 3D & [m\,s$^{-2}$]& buoyancy $b$ \\
hb's avatar
hb committed
60 61 62 63 64 65 66 67 68 69 70
! {\tt idpdx} & 3D & [m$^2$s$^{-2}$] & $x$-component of internal
! pressure gradient \\
! {\tt idpdy} & 3D & [m$^2$s$^{-2}$]& $y$-component of internal
! pressure gradient\\
! {\tt spm} & 3D & [kg\,m$^{-3}$] & suspended matter concentration \\
! {\tt spm\_ws} & 3D & [m\,s$^{-1}$] & settling velocity of
! suspended matter \\
! {\tt spm\_pool} & 2D & [kg\,m$^{-2}$] & bottom pool of suspended
! matter\\
! {\tt uadv} & 3D & [m\,s$^{-1}$] & interpolated $x$-component of
! momentum advection velocity \\
71
! {\tt vadv} & 3D &  [m\,s$^{-1}$]& interpolated $y$-component of
hb's avatar
hb committed
72
! momentum advection velocity \\
73
! {\tt wadv} & 3D &  [m\,s$^{-1}$]& interpolated  vertical component of
hb's avatar
hb committed
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
! momentum advection velocity \\
! {\tt huadv} & 3D &[m] & interpolated height of advective flux
! layer ($x$-component) \\
! {\tt hvadv} & 3D &[m] & interpolated height of advective flux
! layer ($y$-component) \\
! {\tt hoadv} & 3D &[m] & old height of advective finite volume cell
! \\
! {\tt hnadv} & 3D &[m] & new height of advective finite volume
! cell\\
! {\tt sseo} & 2D & [m]& sea surface elevation before macro time
! step (T-point)\\
! {\tt ssen} & 2D & [m]& sea surface elevation after macro time
! step (T-point)\\
! {\tt ssuo} & 2D & [m]& sea surface elevation before macro time
! step (U-point)\\
! {\tt ssun} & 2D & [m]&sea surface elevation after macro time step
! (U-point)\\
! {\tt ssvo} & 2D & [m]& sea surface elevation before macro time
! step (V-point)\\
! {\tt ssvn} & 2D & [m]& sea surface elevation after macro time
! step (V-point)\\
! {\tt rru} & 2D & [m\,s$^{-1}$]&drag coefficient times curret speed
! in U-point\\
! {\tt rrv} & 2D & [m\,s$^{-1}$]&drag coefficient times curret speed
! in V-point\\
! {\tt taus} & 2D & [m$^2$s$^{-2}$]& normalised surface stress
! (T-point) \\
! {\tt taub} & 2D & [m$^2$s$^{-2}$]& normalised bottom stress
! (T-point) \\
! \end{supertabular}
!
! \vspace{0.5cm}
!
! It should be noted that depending on compiler options and runtype not
! all these variables are defined.
!
! The module contains public subroutines to initialise (see
! {\tt init\_variables\_3d}) and cleanup (see {\tt clean\_variables\_3d}).
gotm's avatar
gotm committed
112 113
!
! !USES:
Knut's avatar
Knut committed
114
   use domain,     only: imin,imax,jmin,jmax,kmax,bottfric_method,rdrag
gotm's avatar
gotm committed
115 116 117
   IMPLICIT NONE
!
! !PUBLIC DATA MEMBERS:
Knut's avatar
Knut committed
118
   integer, parameter                  :: rk = kind(_ONE_)
kbk's avatar
kbk committed
119
   REALTYPE                            :: dt,cnpar=0.9
120
   REALTYPE                            :: avmback=_ZERO_,avhback=_ZERO_
Knut's avatar
Knut committed
121
   logical                             :: do_numerical_analyses_3d=.false.
gotm's avatar
gotm committed
122 123
!
#ifdef STATIC
gotm's avatar
gotm committed
124
#include "static_3d.h"
gotm's avatar
gotm committed
125
#else
gotm's avatar
gotm committed
126
#include "dynamic_declarations_3d.h"
127 128
#endif

Knut's avatar
Knut committed
129 130
   REALTYPE,dimension(:,:,:),pointer         :: numdis_3d=>null()
   REALTYPE, dimension(:,:,:), allocatable   :: numdis_3d_old,phydis_3d
Knut's avatar
Knut committed
131
   REALTYPE, dimension(:,:), allocatable     :: numdis_int,phydis_int
132 133 134
   REALTYPE,dimension(:,:,:),pointer         :: nummix_S=>null()
   REALTYPE,dimension(:,:,:),pointer         :: nummix_T=>null()
   REALTYPE, dimension(:,:,:), allocatable   :: nummix_S_old,nummix_T_old
Knut's avatar
Knut committed
135 136 137
   REALTYPE, dimension(:,:,:), allocatable   :: phymix_S,phymix_T
   REALTYPE, dimension(:,:), allocatable     :: nummix_S_int,nummix_T_int
   REALTYPE, dimension(:,:), allocatable     :: phymix_S_int,phymix_T_int
138

139 140 141
#ifdef GETM_BIO
   REALTYPE, allocatable               :: cc3d(:,:,:,:)
   REALTYPE, allocatable               :: ws3d(:,:,:,:)
142 143 144 145
#endif
#ifdef _FABM_
   REALTYPE, allocatable, dimension(:,:,:,:) :: fabm_pel,fabm_diag
   REALTYPE, allocatable, dimension(:,:,:)   :: fabm_ben,fabm_diag_hz
gotm's avatar
gotm committed
146
#endif
kbk's avatar
kbk committed
147 148
   integer                             :: size3d_field
   integer                             :: mem3d
149
   integer                             :: preadapt
gotm's avatar
gotm committed
150
!
kbk's avatar
kbk committed
151 152 153
! !REVISION HISTORY:
!  Original author(s): Karsten Bolding & Hans Burchard
!
gotm's avatar
gotm committed
154 155 156 157 158 159 160 161
!EOP
!-----------------------------------------------------------------------

   contains

!-----------------------------------------------------------------------
!BOP
!
hb's avatar
hb committed
162 163
! !IROUTINE: init_variables_3d - initialise 3D related stuff
! \label{sec-init-variables}
gotm's avatar
gotm committed
164 165 166 167 168 169
!
! !INTERFACE:
   subroutine init_variables_3d(runtype)
   IMPLICIT NONE
!
! !INPUT PARAMETERS:
kbk's avatar
kbk committed
170
   integer, intent(in)                 :: runtype
gotm's avatar
gotm committed
171 172
!
! !DESCRIPTION:
hb's avatar
hb committed
173 174 175
!  Dynamic allocation of memory for 3D related fields via
!  {\tt dynamic\_allocations\_3d.h} (unless the compiler option
!  {\tt STATIC} is set). Furthermore, most variables are initialised here.
gotm's avatar
gotm committed
176 177
!
! !LOCAL VARIABLES:
kbk's avatar
kbk committed
178
   integer                   :: rc
gotm's avatar
gotm committed
179 180 181 182 183 184 185 186 187 188
!EOP
!-------------------------------------------------------------------------
!BOC
#ifdef DEBUG
   integer, save :: Ncall = 0
   Ncall = Ncall+1
   write(debug,*) 'init_variables_3d() # ',Ncall
#endif

   LEVEL2 'init_variables_3d'
189 190
   size3d_field=((imax+HALO)-(imin+HALO)+1)*        &
                ((jmax+HALO)-(jmin+HALO)+1)*(kmax+1)
gotm's avatar
gotm committed
191 192 193 194
   mem3d=n3d_fields*size3d_field*REAL_SIZE

!  Allocates memory for the public data members - if not static
#ifndef STATIC
gotm's avatar
gotm committed
195
#include "dynamic_allocations_3d.h"
gotm's avatar
gotm committed
196 197
#endif

198 199
   kmin = 1

Knut's avatar
Knut committed
200
   ho = _ZERO_ ; hn = _ZERO_ ; hvel = _ZERO_ ; hun = _ZERO_ ; hvn = _ZERO_
kbk's avatar
kbk committed
201
   uu = _ZERO_ ; vv = _ZERO_ ; ww = _ZERO_
202
   velx3d = -9999.0 ; vely3d = -9999.0 ; w = -9999.0
203
   velx2dadv = -9999.0 ; vely2dadv = -9999.0
204

Hans Burchard's avatar
Hans Burchard committed
205 206
#ifdef _MOMENTUM_TERMS_
   tdv_u = _ZERO_ ; adv_u = _ZERO_ ; vsd_u = _ZERO_ ; hsd_u = _ZERO_
Karsten Bolding's avatar
Karsten Bolding committed
207
   cor_u = _ZERO_ ; epg_u = _ZERO_ ; ipg_u = _ZERO_
Hans Burchard's avatar
Hans Burchard committed
208
   tdv_v = _ZERO_ ; adv_v = _ZERO_ ; vsd_v = _ZERO_ ; hsd_v = _ZERO_
Karsten Bolding's avatar
Karsten Bolding committed
209
   cor_v = _ZERO_ ; epg_v = _ZERO_ ; ipg_v = _ZERO_
Hans Burchard's avatar
Hans Burchard committed
210
#endif
kbk's avatar
kbk committed
211
   ssen = _ZERO_ ; ssun = _ZERO_ ; ssvn = _ZERO_
Knut's avatar
Knut committed
212
   Dn = _ZERO_ ; Dveln = _ZERO_ ; Dun = _ZERO_ ; Dvn = _ZERO_
213
   Uadv = _ZERO_ ; Vadv = _ZERO_
Knut's avatar
Knut committed
214

Knut's avatar
Knut committed
215
   zub = -9999.0 ; zvb = -9999.0 ! must be initialised for gotm
Knut's avatar
Knut committed
216 217 218 219 220 221 222 223
   if (bottfric_method .eq. 1) then
      rru = rdrag
      rrv = rdrag
   else
      rru = _ZERO_
      rrv = _ZERO_
   end if

kbk's avatar
kbk committed
224
   uuEx= _ZERO_ ; vvEx= _ZERO_
225
   SS=_ZERO_
kbk's avatar
kbk committed
226
   tke=1.e-10 ; eps=1.e-10
227
   preadapt=0
kbk's avatar
kbk committed
228

kb's avatar
kb committed
229
#ifndef NO_BAROCLINIC
230
   NN=_ZERO_
231
   rad=_ZERO_
232
   heatflux_net = _ZERO_
233
   light=_ONE_
234 235 236 237
   idpdx=_ZERO_
   idpdy=_ZERO_
#endif

238
!  must be nonzero for gotm_fabm in case of calc_temp=F
Knut's avatar
Knut committed
239 240
   g1 = -9999._rk
   g2 = -9999._rk
241

gotm's avatar
gotm committed
242 243 244 245 246 247
#ifdef DEBUG
   write(debug,*) 'Leaving init_variables_3d()'
   write(debug,*)
#endif
   return
   end subroutine init_variables_3d
248 249 250 251 252 253 254 255
!EOC

!-----------------------------------------------------------------------
!BOP
!
! !IROUTINE: postinit_variables_3d - re-initialise some 3D stuff.
!
! !INTERFACE:
Knut's avatar
Knut committed
256
   subroutine postinit_variables_3d(update_temp,update_salt)
257 258 259
   IMPLICIT NONE
!
! !INPUT PARAMETERS:
Knut's avatar
Knut committed
260
   logical, intent(in)                 :: update_temp,update_salt
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
!
! !DESCRIPTION:
!
! !LOCAL VARIABLES:
   integer                   :: rc
!
!EOP
!-----------------------------------------------------------------------
!BOC
#ifdef DEBUG
   integer, save :: Ncall = 0
   Ncall = Ncall+1
   write(debug,*) 'postinit_variables_3d() # ',Ncall
#endif

   if (do_numerical_analyses_3d) then

      allocate(phydis_3d(I3DFIELD),stat=rc)
      if (rc /= 0) stop 'postinit_3d: Error allocating memory (phydis_3d)'
      phydis_3d = _ZERO_
      allocate(phydis_int(I2DFIELD),stat=rc)
      if (rc /= 0) stop 'postinit_3d: Error allocating memory (phydis_int)'
      phydis_int = _ZERO_
      allocate(numdis_3d(I3DFIELD),stat=rc)
      if (rc /= 0) stop 'postinit_3d: Error allocating memory (numdis_3d)'
      numdis_3d = _ZERO_
#ifdef _NUMERICAL_ANALYSES_OLD_
      allocate(numdis_3d_old(I3DFIELD),stat=rc)
      if (rc /= 0) stop 'postinit_3d: Error allocating memory (numdis_3d_old)'
      numdis_3d_old = _ZERO_
      allocate(numdis_int(I2DFIELD),stat=rc)
      if (rc /= 0) stop 'postinit_3d: Error allocating memory (numdis_int)'
      numdis_int = _ZERO_
#endif

Knut's avatar
Knut committed
296
      if (update_temp) then
297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315
         allocate(phymix_T(I3DFIELD),stat=rc)
         if (rc /= 0) stop 'postinit_3d: Error allocating memory (phymix_T)'
         phymix_T = _ZERO_
         allocate(phymix_T_int(I2DFIELD),stat=rc)
         if (rc /= 0) stop 'postinit_3d: Error allocating memory (phymix_T_int)'
         phymix_T_int = _ZERO_
         allocate(nummix_T(I3DFIELD),stat=rc)
         if (rc /= 0) stop 'postinit_3d: Error allocating memory (nummix_T)'
         nummix_T = _ZERO_
#ifdef _NUMERICAL_ANALYSES_OLD_
         allocate(nummix_T_old(I3DFIELD),stat=rc)
         if (rc /= 0) stop 'postinit_3d: Error allocating memory (nummix_T_old)'
         nummix_T_old = _ZERO_
         allocate(nummix_T_int(I2DFIELD),stat=rc)
         if (rc /= 0) stop 'postinit_3d: Error allocating memory (nummix_T_int)'
         nummix_T_int = _ZERO_
#endif
      end if

Knut's avatar
Knut committed
316
      if (update_salt) then
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
         allocate(phymix_S(I3DFIELD),stat=rc)
         if (rc /= 0) stop 'postinit_3d: Error allocating memory (phymix_S)'
         phymix_S = _ZERO_
         allocate(phymix_S_int(I2DFIELD),stat=rc)
         if (rc /= 0) stop 'postinit_3d: Error allocating memory (phymix_S_int)'
         phymix_S_int = _ZERO_
         allocate(nummix_S(I3DFIELD),stat=rc)
         if (rc /= 0) stop 'postinit_3d: Error allocating memory (nummix_S)'
         nummix_S = _ZERO_
#ifdef _NUMERICAL_ANALYSES_OLD_
         allocate(nummix_S_old(I3DFIELD),stat=rc)
         if (rc /= 0) stop 'postinit_3d: Error allocating memory (nummix_S_old)'
         nummix_S_old = _ZERO_
         allocate(nummix_S_int(I2DFIELD),stat=rc)
         if (rc /= 0) stop 'postinit_3d: Error allocating memory (nummix_S_int)'
         nummix_S_int = _ZERO_
#endif
      end if

   end if


#ifdef DEBUG
   write(debug,*) 'Leaving postinit_variables_3d()'
   write(debug,*)
#endif
   return
   end subroutine postinit_variables_3d
gotm's avatar
gotm committed
345 346
!EOC

Knut's avatar
Knut committed
347 348 349 350 351 352
!-----------------------------------------------------------------------
!BOP
!
! !ROUTINE: register_3d_variables() - register GETM variables.
!
! !INTERFACE:
Knut's avatar
Knut committed
353
   subroutine register_3d_variables(fm,runtype,update_temp,update_salt)
Knut's avatar
Knut committed
354 355 356 357
!
! !DESCRIPTION:
!
! !USES:
358
   use field_manager
Knut's avatar
Knut committed
359 360 361 362 363
   IMPLICIT NONE
!
! !INPUT PARAMETERS:
   type (type_field_manager) :: fm
   integer, intent(in)       :: runtype
Knut's avatar
Knut committed
364
   logical, intent(in)       :: update_temp,update_salt
Knut's avatar
Knut committed
365 366 367 368 369
!
! !REVISION HISTORY:
!  Original author(s): Karsten Bolding & Jorn Bruggeman
!
! !LOCAL VARIABLES:
Knut's avatar
Knut committed
370
!
Knut's avatar
Knut committed
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
!EOP
!-----------------------------------------------------------------------
!BOC
   LEVEL2 'register_3d_variables()'

!:: kmin(I2DFIELD)
!:: kumin(I2DFIELD)
!:: kvmin(I2DFIELD)
!:: kmin_pmz(I2DFIELD)
!:: kumin_pmz(I2DFIELD)
!:: kvmin_pmz(I2DFIELD)

!:: uu(I3DFIELD)
!:: vv(I3DFIELD)
!:: ww(I3DFIELD)
#ifdef _MOMENTUM_TERMS_
!:: tdv_u(I3DFIELD)
!:: adv_u(I3DFIELD)
!:: vsd_u(I3DFIELD)
!:: hsd_u(I3DFIELD)
!:: cor_u(I3DFIELD)
!:: epg_u(I3DFIELD)
!:: ipg_u(I3DFIELD)

!:: tdv_v(I3DFIELD)
!:: adv_v(I3DFIELD)
!:: vsd_v(I3DFIELD)
!:: hsd_v(I3DFIELD)
!:: cor_v(I3DFIELD)
!:: epg_v(I3DFIELD)
!:: ipg_v(I3DFIELD)
#endif
#ifdef STRUCTURE_FRICTION
!:: sf(I3DFIELD)
#endif
!:: ho(I3DFIELD)
!:: hn(I3DFIELD)
!:: huo(I3DFIELD)
!:: hun(I3DFIELD)
!:: hvo(I3DFIELD)
!:: hvn(I3DFIELD)
!:: hcc(I3DFIELD)
!:: uuEx(I3DFIELD)
!:: vvEx(I3DFIELD)
!:: num(I3DFIELD)
!:: nuh(I3DFIELD)

! 3D turbulent fields
!:: tke(I3DFIELD)
!:: eps(I3DFIELD)
!:: SS(I3DFIELD)
#ifndef NO_BAROCLINIC
! 3D baroclinic fields
!:: NN(I3DFIELD)
!:: S(I3DFIELD)
!:: T(I3DFIELD)
!:: rho(I3DFIELD)
!:: rad(I3DFIELD)
!:: buoy(I3DFIELD)
!:: alpha(I3DFIELD)
!:: beta(I3DFIELD)
!:: idpdx(I3DFIELD)
!:: idpdy(I3DFIELD)
!:: light(I3DFIELD)
#endif

#ifdef SPM
! suspended matter
!:: spm(I3DFIELD)
!:: spm_ws(I3DFIELD)
!:: spm_pool(I2DFIELD)
#endif

! 2D fields in 3D domain
!:: sseo(I2DFIELD)
!:: ssen(I2DFIELD)
!:: Dn(I2DFIELD)
!:: ssuo(I2DFIELD)
!:: ssun(I2DFIELD)
!:: ssvo(I2DFIELD)
!:: ssvn(I2DFIELD)
!:: Dun,Dvn

! 3D friction in 3D domain
!:: rru(I2DFIELD)
!:: rrv(I2DFIELD)
!:: taus(I2DFIELD)
!:: taubx(I2DFIELD)
!:: tauby(I2DFIELD)
!:: taub(I2DFIELD)

! light attenuation
!:: A(I2DFIELD)
!:: g1(I2DFIELD)
!:: g2(I2DFIELD)

!  category - 3d
   if (runtype .ge. 2) then
      call fm%register('zc', 'm', 'center coordinate', standard_name='', dimensions=(/id_dim_z/),data3d=zc(_3D_W_), category='grid', part_of_state=.false.)
470
      call fm%register('zcn', 'm', 'z', standard_name='', dimensions=(/id_dim_z/), data3d=zcn(_3D_W_), category='grid')
Knut's avatar
Knut committed
471 472 473 474 475 476 477 478 479 480 481
      call fm%register('hn', 'm', 'layer thickness', standard_name='cell_thickness', dimensions=(/id_dim_z/),data3d=hn(_3D_W_), category='grid', part_of_state=.true.)
      call fm%register('hun', 'm', 'layer thickness - U-points', standard_name='cell_thickness', dimensions=(/id_dim_z/),data3d=hun(_3D_W_), category='grid', output_level=output_level_debug)
      call fm%register('hvn', 'm', 'layer thickness - V-points', standard_name='cell_thickness', dimensions=(/id_dim_z/),data3d=hvn(_3D_W_), category='grid', output_level=output_level_debug)
      call fm%register('ho', 'm', 'old layer thickness', standard_name='cell_thickness', dimensions=(/id_dim_z/),data3d=ho(_3D_W_), category='grid', output_level=output_level_debug)
      call fm%register('ssen', 'm', 'elevation at T-points (3D)', standard_name='', data2d=ssen(_2D_W_), category='3d', fill_value=-9999.0_rk, output_level=output_level_debug, part_of_state=.true.)
      call fm%register('ssun', 'm', 'elevation at U-points (3D)', standard_name='', data2d=ssun(_2D_W_), category='3d', output_level=output_level_debug, part_of_state=.true.)
      call fm%register('ssvn', 'm', 'elevation at V-points (3D)', standard_name='', data2d=ssvn(_2D_W_), category='3d', output_level=output_level_debug, part_of_state=.true.)
      call fm%register('sseo', 'm', 'old elevation at T-points (3D)', standard_name='', data2d=sseo(_2D_W_), category='3d', fill_value=-9999.0_rk, output_level=output_level_debug, part_of_state=.true.)
      call fm%register('uu', 'm2/s', 'transport in local x-direction (3D)', standard_name='', dimensions=(/id_dim_z/), data3d=uu(_3D_W_), category='3d', output_level=output_level_debug, part_of_state=.true.)
      call fm%register('vv', 'm2/s', 'transport in local y-direction (3D)', standard_name='', dimensions=(/id_dim_z/), data3d=vv(_3D_W_), category='3d', output_level=output_level_debug, part_of_state=.true.)
      call fm%register('ww', 'm/s', 'grid-related vertical velocity', standard_name='', dimensions=(/id_dim_z/), data3d=ww(_3D_W_), category='3d', output_level=output_level_debug)
Knut's avatar
Knut committed
482 483 484 485 486
      call fm%register('velx3d', 'm/s', 'velocity in global x-direction (3D)', standard_name='', dimensions=(/id_dim_z/), data3d=velx3d(_3D_W_), category='3d', fill_value=-9999.0_rk, output_level=output_level_debug)
      call fm%register('vely3d', 'm/s', 'velocity in global y-direction (3D)', standard_name='', dimensions=(/id_dim_z/), data3d=vely3d(_3D_W_), category='3d', fill_value=-9999.0_rk, output_level=output_level_debug)
      call fm%register('w', 'm/s', 'vertical velocity', standard_name='', dimensions=(/id_dim_z/), data3d=w(_3D_W_), category='3d', fill_value=-9999.0_rk, output_level=output_level_debug)
      call fm%register('velx2dadv', 'm/s', 'depth-avg. velocity in global x-direction (3D)', standard_name='', data2d=velx2dadv(_2D_W_), category='3d', fill_value=-9999.0_rk, output_level=output_level_debug)
      call fm%register('vely2dadv', 'm/s', 'depth-avg. velocity in global y-direction (3D)', standard_name='', data2d=vely2dadv(_2D_W_), category='3d', fill_value=-9999.0_rk, output_level=output_level_debug)
Knut's avatar
Knut committed
487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512
      call fm%register('SS', 's-2', 'shear frequency squared', standard_name='', dimensions=(/id_dim_z/), data3d=SS(_3D_W_), category='3d', output_level=output_level_debug)

   end if

!  category - turbulence
   if (runtype .ge. 2) then
      call fm%register('tke' , 'm2/s2', 'TKE'        , standard_name='', dimensions=(/id_dim_z/), data3d=tke(_3D_W_), category='turbulence', output_level=output_level_debug)
      call fm%register('diss', 'm2/s3', 'dissipation', standard_name='', dimensions=(/id_dim_z/), data3d=eps(_3D_W_), category='turbulence', output_level=output_level_debug)
      call fm%register('num' , 'm2/s' , 'viscosity'  , standard_name='', dimensions=(/id_dim_z/), data3d=num(_3D_W_), category='turbulence', output_level=output_level_debug)
      call fm%register('nuh' , 'm2/s' , 'diffusivity', standard_name='', dimensions=(/id_dim_z/), data3d=nuh(_3D_W_), category='turbulence', output_level=output_level_debug)
   end if

#ifndef NO_BAROCLINIC
!  category - baroclinic
   if (runtype .ge. 3) then
      call fm%register('temp', 'Celsius', 'temperature', standard_name='', dimensions=(/id_dim_z/), fill_value=-9999.0_rk, data3d=T  (_3D_W_), category='baroclinic', part_of_state=.true.)
      call fm%register('salt', '1e-3'   , 'salinity'   , standard_name='', dimensions=(/id_dim_z/), fill_value=-9999.0_rk, data3d=S  (_3D_W_), category='baroclinic', part_of_state=.true.)
      call fm%register('rho' , 'kg/m3'  , 'density'    , standard_name='', dimensions=(/id_dim_z/), fill_value=-9999.0_rk, data3d=rho(_3D_W_), category='baroclinic', output_level=output_level_debug)
      call fm%register('NN', 's-2', 'buoyancy frequency squared', standard_name='', dimensions=(/id_dim_z/), data3d=NN(_3D_W_), category='baroclinic', output_level=output_level_debug)
      call fm%register('idpdx', 'm2/s2', 'baroclinic pressure gradient - x', standard_name='', dimensions=(/id_dim_z/),data3d=idpdx(_3D_W_), category='baroclinic', output_level=output_level_debug)
#ifndef SLICE_MODEL
      call fm%register('idpdy', 'm2/s2', 'baroclinic pressure gradient - y', standard_name='', dimensions=(/id_dim_z/),data3d=idpdy(_3D_W_), category='baroclinic', output_level=output_level_debug)
#endif
   end if
#endif

513 514 515
   if (do_numerical_analyses_3d) then
      call fm%register('numdis_3d', 'W/kg', 'numerical dissipation (3D)', standard_name='', dimensions=(/id_dim_z/), category='3d', output_level=output_level_debug)
      call fm%register('phydis_3d', 'W/kg', 'physical dissipation (3D)' , standard_name='', dimensions=(/id_dim_z/), category='3d', output_level=output_level_debug)
Knut's avatar
Knut committed
516
      if (update_temp) then
517 518 519
         call fm%register('nummix_temp', 'degC**2/s', 'numerical mixing of temperature', standard_name='', dimensions=(/id_dim_z/), category='3d', output_level=output_level_debug)
         call fm%register('phymix_temp', 'degC**2/s', 'physical mixing of temperature' , standard_name='', dimensions=(/id_dim_z/), category='3d', output_level=output_level_debug)
      end if
Knut's avatar
Knut committed
520
      if (update_salt) then
521 522 523 524 525
         call fm%register('nummix_salt', 'psu**2/s', 'numerical mixing of salinity', standard_name='', dimensions=(/id_dim_z/), category='3d', output_level=output_level_debug)
         call fm%register('phymix_salt', 'psu**2/s', 'physical mixing of salinity' , standard_name='', dimensions=(/id_dim_z/), category='3d', output_level=output_level_debug)
      end if
   end if

Knut's avatar
Knut committed
526 527 528 529
   return
   end subroutine register_3d_variables
!EOC

530 531 532 533 534 535
!-----------------------------------------------------------------------
!BOP
!
! !ROUTINE: finalize_register_3d_variables() - send optional variables.
!
! !INTERFACE:
Knut's avatar
Knut committed
536
   subroutine finalize_register_3d_variables(fm,update_temp,update_salt)
537 538 539 540 541 542 543 544 545
!
! !DESCRIPTION:
!
! !USES:
   use field_manager
   IMPLICIT NONE
!
! !INPUT PARAMETERS:
   type (type_field_manager) :: fm
Knut's avatar
Knut committed
546
   logical, intent(in)       :: update_temp,update_salt
547 548 549 550 551 552 553 554 555 556 557 558 559
!
! !REVISION HISTORY:
!  Original author(s): Karsten Bolding & Jorn Bruggeman
!
! !LOCAL VARIABLES:
!EOP
!-----------------------------------------------------------------------
!BOC
   LEVEL1 'finalize_register_3d_variables()'

   if (do_numerical_analyses_3d) then
      call fm%send_data('numdis_3d', numdis_3d(_3D_W_))
      call fm%send_data('phydis_3d', phydis_3d(_3D_W_))
Knut's avatar
Knut committed
560
      if (update_temp) then
561 562 563
         call fm%send_data('nummix_temp', nummix_T(_3D_W_))
         call fm%send_data('phymix_temp', phymix_T(_3D_W_))
      end if
Knut's avatar
Knut committed
564
      if (update_salt) then
565 566 567 568 569 570 571 572
         call fm%send_data('nummix_salt', nummix_S(_3D_W_))
         call fm%send_data('phymix_salt', phymix_S(_3D_W_))
      end if
   end if

   return
   end subroutine finalize_register_3d_variables
!EOC
Knut's avatar
Knut committed
573

gotm's avatar
gotm committed
574 575 576 577 578 579 580 581 582 583
!-----------------------------------------------------------------------
!BOP
!
! !IROUTINE: clean_variables_3d - cleanup after 3D run.
!
! !INTERFACE:
   subroutine clean_variables_3d()
   IMPLICIT NONE
!
! !DESCRIPTION:
hb's avatar
hb committed
584
!  This routine cleans up after a 3D integrationby doing nothing so far.
gotm's avatar
gotm committed
585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611
!
!EOP
!-----------------------------------------------------------------------
!BOC
#ifdef DEBUG
   integer, save :: Ncall = 0
   Ncall = Ncall+1
   write(debug,*) 'clean_3d() # ',Ncall
#endif

! Deallocates memory for the public data members

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

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

   end module variables_3d

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