[1873] | 1 | !> @file eqn_state_seawater.f90 |
---|
[1320] | 2 | !------------------------------------------------------------------------------! |
---|
[1036] | 3 | ! This file is part of PALM. |
---|
| 4 | ! |
---|
[2000] | 5 | ! PALM is free software: you can redistribute it and/or modify it under the |
---|
| 6 | ! terms of the GNU General Public License as published by the Free Software |
---|
| 7 | ! Foundation, either version 3 of the License, or (at your option) any later |
---|
| 8 | ! version. |
---|
[1036] | 9 | ! |
---|
| 10 | ! PALM is distributed in the hope that it will be useful, but WITHOUT ANY |
---|
| 11 | ! WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR |
---|
| 12 | ! A PARTICULAR PURPOSE. See the GNU General Public License for more details. |
---|
| 13 | ! |
---|
| 14 | ! You should have received a copy of the GNU General Public License along with |
---|
| 15 | ! PALM. If not, see <http://www.gnu.org/licenses/>. |
---|
| 16 | ! |
---|
[2101] | 17 | ! Copyright 1997-2017 Leibniz Universitaet Hannover |
---|
[1320] | 18 | !------------------------------------------------------------------------------! |
---|
[1036] | 19 | ! |
---|
[484] | 20 | ! Current revisions: |
---|
[96] | 21 | ! ----------------- |
---|
[1354] | 22 | ! |
---|
[2233] | 23 | ! |
---|
[1321] | 24 | ! Former revisions: |
---|
| 25 | ! ----------------- |
---|
| 26 | ! $Id: eqn_state_seawater.f90 2233 2017-05-30 18:08:54Z hoffmann $ |
---|
| 27 | ! |
---|
[2233] | 28 | ! 2232 2017-05-30 17:47:52Z suehring |
---|
| 29 | ! Adjustments to new topography and surface concept |
---|
| 30 | ! |
---|
[2032] | 31 | ! 2031 2016-10-21 15:11:58Z knoop |
---|
| 32 | ! renamed variable rho to rho_ocean |
---|
| 33 | ! |
---|
[2001] | 34 | ! 2000 2016-08-20 18:09:15Z knoop |
---|
| 35 | ! Forced header and separation lines into 80 columns |
---|
| 36 | ! |
---|
[1874] | 37 | ! 1873 2016-04-18 14:50:06Z maronga |
---|
| 38 | ! Module renamed (removed _mod) |
---|
| 39 | ! |
---|
| 40 | ! |
---|
[1851] | 41 | ! 1850 2016-04-08 13:29:27Z maronga |
---|
| 42 | ! Module renamed |
---|
| 43 | ! |
---|
| 44 | ! |
---|
[1683] | 45 | ! 1682 2015-10-07 23:56:08Z knoop |
---|
| 46 | ! Code annotations made doxygen readable |
---|
| 47 | ! |
---|
[1354] | 48 | ! 1353 2014-04-08 15:21:23Z heinze |
---|
| 49 | ! REAL constants provided with KIND-attribute |
---|
| 50 | ! |
---|
[1321] | 51 | ! 1320 2014-03-20 08:40:49Z raasch |
---|
[1320] | 52 | ! ONLY-attribute added to USE-statements, |
---|
| 53 | ! kind-parameters added to all INTEGER and REAL declaration statements, |
---|
| 54 | ! kinds are defined in new module kinds, |
---|
| 55 | ! revision history before 2012 removed, |
---|
| 56 | ! comment fields (!:) to be used for variable explanations added to |
---|
| 57 | ! all variable declaration statements |
---|
[96] | 58 | ! |
---|
[1037] | 59 | ! 1036 2012-10-22 13:43:42Z raasch |
---|
| 60 | ! code put under GPL (PALM 3.9) |
---|
| 61 | ! |
---|
[98] | 62 | ! 97 2007-06-21 08:23:15Z raasch |
---|
[96] | 63 | ! Initial revision |
---|
| 64 | ! |
---|
| 65 | ! |
---|
| 66 | ! Description: |
---|
| 67 | ! ------------ |
---|
[1682] | 68 | !> Equation of state for seawater as a function of potential temperature, |
---|
| 69 | !> salinity, and pressure. |
---|
| 70 | !> For coefficients see Jackett et al., 2006: J. Atm. Ocean Tech. |
---|
| 71 | !> eqn_state_seawater calculates the potential density referred at hyp(0). |
---|
| 72 | !> eqn_state_seawater_func calculates density. |
---|
[96] | 73 | !------------------------------------------------------------------------------! |
---|
[1682] | 74 | MODULE eqn_state_seawater_mod |
---|
| 75 | |
---|
[1320] | 76 | |
---|
| 77 | USE kinds |
---|
[96] | 78 | |
---|
| 79 | IMPLICIT NONE |
---|
| 80 | |
---|
| 81 | PRIVATE |
---|
| 82 | PUBLIC eqn_state_seawater, eqn_state_seawater_func |
---|
| 83 | |
---|
[1320] | 84 | REAL(wp), DIMENSION(12), PARAMETER :: nom = & |
---|
| 85 | (/ 9.9984085444849347D2, 7.3471625860981584D0, & |
---|
| 86 | -5.3211231792841769D-2, 3.6492439109814549D-4, & |
---|
| 87 | 2.5880571023991390D0, -6.7168282786692354D-3, & |
---|
| 88 | 1.9203202055760151D-3, 1.1798263740430364D-2, & |
---|
| 89 | 9.8920219266399117D-8, 4.6996642771754730D-6, & |
---|
| 90 | -2.5862187075154352D-8, -3.2921414007960662D-12 /) |
---|
[1682] | 91 | !< |
---|
[96] | 92 | |
---|
[1320] | 93 | REAL(wp), DIMENSION(13), PARAMETER :: den = & |
---|
| 94 | (/ 1.0D0, 7.2815210113327091D-3, & |
---|
| 95 | -4.4787265461983921D-5, 3.3851002965802430D-7, & |
---|
| 96 | 1.3651202389758572D-10, 1.7632126669040377D-3, & |
---|
| 97 | -8.8066583251206474D-6, -1.8832689434804897D-10, & |
---|
| 98 | 5.7463776745432097D-6, 1.4716275472242334D-9, & |
---|
| 99 | 6.7103246285651894D-6, -2.4461698007024582D-17, & |
---|
| 100 | -9.1534417604289062D-18 /) |
---|
[1682] | 101 | !< |
---|
[96] | 102 | |
---|
| 103 | INTERFACE eqn_state_seawater |
---|
| 104 | MODULE PROCEDURE eqn_state_seawater |
---|
| 105 | MODULE PROCEDURE eqn_state_seawater_ij |
---|
| 106 | END INTERFACE eqn_state_seawater |
---|
| 107 | |
---|
| 108 | INTERFACE eqn_state_seawater_func |
---|
| 109 | MODULE PROCEDURE eqn_state_seawater_func |
---|
| 110 | END INTERFACE eqn_state_seawater_func |
---|
| 111 | |
---|
| 112 | CONTAINS |
---|
| 113 | |
---|
| 114 | |
---|
| 115 | !------------------------------------------------------------------------------! |
---|
[1682] | 116 | ! Description: |
---|
| 117 | ! ------------ |
---|
| 118 | !> Call for all grid points |
---|
[96] | 119 | !------------------------------------------------------------------------------! |
---|
| 120 | SUBROUTINE eqn_state_seawater |
---|
| 121 | |
---|
[1320] | 122 | USE arrays_3d, & |
---|
[2031] | 123 | ONLY: hyp, prho, pt_p, rho_ocean, sa_p |
---|
[1320] | 124 | USE indices, & |
---|
[2232] | 125 | ONLY: nxl, nxr, nyn, nys, nzb, nzt, wall_flags_0 |
---|
[96] | 126 | |
---|
[2232] | 127 | USE surface_mod, & |
---|
| 128 | ONLY : bc_h |
---|
| 129 | |
---|
[96] | 130 | IMPLICIT NONE |
---|
| 131 | |
---|
[2232] | 132 | INTEGER(iwp) :: i !< running index x direction |
---|
| 133 | INTEGER(iwp) :: j !< running index y direction |
---|
| 134 | INTEGER(iwp) :: k !< running index z direction |
---|
| 135 | INTEGER(iwp) :: l !< running index of surface type, south- or north-facing wall |
---|
| 136 | INTEGER(iwp) :: m !< running index surface elements |
---|
| 137 | INTEGER(iwp) :: surf_e !< End index of surface elements at (j,i)-gridpoint |
---|
| 138 | INTEGER(iwp) :: surf_s !< Start index of surface elements at (j,i)-gridpoint |
---|
[96] | 139 | |
---|
[2232] | 140 | REAL(wp) :: flag !< flag to mask topography grid points |
---|
| 141 | REAL(wp) :: pden !< |
---|
| 142 | REAL(wp) :: pnom !< |
---|
| 143 | REAL(wp) :: p1 !< |
---|
| 144 | REAL(wp) :: p2 !< |
---|
| 145 | REAL(wp) :: p3 !< |
---|
| 146 | REAL(wp) :: pt1 !< |
---|
| 147 | REAL(wp) :: pt2 !< |
---|
| 148 | REAL(wp) :: pt3 !< |
---|
| 149 | REAL(wp) :: pt4 !< |
---|
| 150 | REAL(wp) :: sa1 !< |
---|
| 151 | REAL(wp) :: sa15 !< |
---|
| 152 | REAL(wp) :: sa2 !< |
---|
[1320] | 153 | |
---|
| 154 | |
---|
[96] | 155 | |
---|
| 156 | DO i = nxl, nxr |
---|
| 157 | DO j = nys, nyn |
---|
[2232] | 158 | DO k = nzb+1, nzt |
---|
[96] | 159 | ! |
---|
| 160 | !-- Pressure is needed in dbar |
---|
[1353] | 161 | p1 = hyp(k) * 1E-4_wp |
---|
[96] | 162 | p2 = p1 * p1 |
---|
| 163 | p3 = p2 * p1 |
---|
| 164 | |
---|
| 165 | ! |
---|
| 166 | !-- Temperature needed in degree Celsius |
---|
[1353] | 167 | pt1 = pt_p(k,j,i) - 273.15_wp |
---|
[96] | 168 | pt2 = pt1 * pt1 |
---|
| 169 | pt3 = pt1 * pt2 |
---|
| 170 | pt4 = pt2 * pt2 |
---|
| 171 | |
---|
| 172 | sa1 = sa_p(k,j,i) |
---|
| 173 | sa15 = sa1 * SQRT( sa1 ) |
---|
| 174 | sa2 = sa1 * sa1 |
---|
| 175 | |
---|
[1320] | 176 | pnom = nom(1) + nom(2)*pt1 + nom(3)*pt2 + & |
---|
| 177 | nom(4)*pt3 + nom(5)*sa1 + nom(6)*sa1*pt1 + & |
---|
[388] | 178 | nom(7)*sa2 |
---|
[96] | 179 | |
---|
[1320] | 180 | pden = den(1) + den(2)*pt1 + den(3)*pt2 + & |
---|
| 181 | den(4)*pt3 + den(5)*pt4 + den(6)*sa1 + & |
---|
| 182 | den(7)*sa1*pt1 + den(8)*sa1*pt3 + den(9)*sa15 + & |
---|
[388] | 183 | den(10)*sa15*pt2 |
---|
| 184 | ! |
---|
[2232] | 185 | !-- Predetermine flag to mask topography |
---|
| 186 | flag = MERGE( 1.0_wp, 0.0_wp, BTEST( wall_flags_0(k,j,i), 0 ) ) |
---|
| 187 | ! |
---|
[388] | 188 | !-- Potential density (without pressure terms) |
---|
[2232] | 189 | prho(k,j,i) = pnom / pden * flag |
---|
[388] | 190 | |
---|
[1320] | 191 | pnom = pnom + nom(8)*p1 + nom(9)*p1*pt2 + & |
---|
[388] | 192 | nom(10)*p1*sa1 + nom(11)*p2 + nom(12)*p2*pt2 |
---|
| 193 | |
---|
[1320] | 194 | pden = pden + den(11)*p1 + den(12)*p2*pt3 + & |
---|
[388] | 195 | den(13)*p3*pt1 |
---|
| 196 | |
---|
| 197 | ! |
---|
| 198 | !-- In-situ density |
---|
[2232] | 199 | rho_ocean(k,j,i) = pnom / pden * flag |
---|
[388] | 200 | |
---|
[96] | 201 | ENDDO |
---|
[97] | 202 | ! |
---|
[2232] | 203 | !-- Neumann conditions are assumed at top boundary |
---|
| 204 | prho(nzt+1,j,i) = prho(nzt,j,i) |
---|
| 205 | rho_ocean(nzt+1,j,i) = rho_ocean(nzt,j,i) |
---|
[388] | 206 | |
---|
[96] | 207 | ENDDO |
---|
| 208 | ENDDO |
---|
[2232] | 209 | ! |
---|
| 210 | !-- Neumann conditions at up/downward-facing surfaces |
---|
| 211 | !$OMP PARALLEL DO PRIVATE( i, j, k ) |
---|
| 212 | DO m = 1, bc_h(0)%ns |
---|
| 213 | i = bc_h(0)%i(m) |
---|
| 214 | j = bc_h(0)%j(m) |
---|
| 215 | k = bc_h(0)%k(m) |
---|
| 216 | prho(k-1,j,i) = prho(k,j,i) |
---|
| 217 | rho_ocean(k-1,j,i) = rho_ocean(k,j,i) |
---|
| 218 | ENDDO |
---|
| 219 | ! |
---|
| 220 | !-- Downward facing surfaces |
---|
| 221 | !$OMP PARALLEL DO PRIVATE( i, j, k ) |
---|
| 222 | DO m = 1, bc_h(1)%ns |
---|
| 223 | i = bc_h(1)%i(m) |
---|
| 224 | j = bc_h(1)%j(m) |
---|
| 225 | k = bc_h(1)%k(m) |
---|
| 226 | prho(k+1,j,i) = prho(k,j,i) |
---|
| 227 | rho_ocean(k+1,j,i) = rho_ocean(k,j,i) |
---|
| 228 | ENDDO |
---|
[96] | 229 | |
---|
| 230 | END SUBROUTINE eqn_state_seawater |
---|
| 231 | |
---|
| 232 | |
---|
| 233 | !------------------------------------------------------------------------------! |
---|
[1682] | 234 | ! Description: |
---|
| 235 | ! ------------ |
---|
| 236 | !> Call for grid point i,j |
---|
[96] | 237 | !------------------------------------------------------------------------------! |
---|
| 238 | SUBROUTINE eqn_state_seawater_ij( i, j ) |
---|
| 239 | |
---|
[1320] | 240 | USE arrays_3d, & |
---|
[2031] | 241 | ONLY: hyp, prho, pt_p, rho_ocean, sa_p |
---|
[1320] | 242 | |
---|
| 243 | USE indices, & |
---|
[2232] | 244 | ONLY: nzb, nzt, wall_flags_0 |
---|
[96] | 245 | |
---|
[2232] | 246 | USE surface_mod, & |
---|
| 247 | ONLY : bc_h |
---|
| 248 | |
---|
[96] | 249 | IMPLICIT NONE |
---|
| 250 | |
---|
[2232] | 251 | INTEGER(iwp) :: i !< running index x direction |
---|
| 252 | INTEGER(iwp) :: j !< running index y direction |
---|
| 253 | INTEGER(iwp) :: k !< running index z direction |
---|
| 254 | INTEGER(iwp) :: l !< running index of surface type, south- or north-facing wall |
---|
| 255 | INTEGER(iwp) :: m !< running index surface elements |
---|
| 256 | INTEGER(iwp) :: surf_e !< End index of surface elements at (j,i)-gridpoint |
---|
| 257 | INTEGER(iwp) :: surf_s !< Start index of surface elements at (j,i)-gridpoint |
---|
[96] | 258 | |
---|
[2232] | 259 | REAL(wp) :: flag !< flag to mask topography grid points |
---|
| 260 | REAL(wp) :: pden !< |
---|
| 261 | REAL(wp) :: pnom !< |
---|
| 262 | REAL(wp) :: p1 !< |
---|
| 263 | REAL(wp) :: p2 !< |
---|
| 264 | REAL(wp) :: p3 !< |
---|
| 265 | REAL(wp) :: pt1 !< |
---|
| 266 | REAL(wp) :: pt2 !< |
---|
| 267 | REAL(wp) :: pt3 !< |
---|
| 268 | REAL(wp) :: pt4 !< |
---|
| 269 | REAL(wp) :: sa1 !< |
---|
| 270 | REAL(wp) :: sa15 !< |
---|
| 271 | REAL(wp) :: sa2 !< |
---|
[96] | 272 | |
---|
[2232] | 273 | DO k = nzb+1, nzt |
---|
[96] | 274 | ! |
---|
| 275 | !-- Pressure is needed in dbar |
---|
[1353] | 276 | p1 = hyp(k) * 1E-4_wp |
---|
[96] | 277 | p2 = p1 * p1 |
---|
| 278 | p3 = p2 * p1 |
---|
| 279 | |
---|
| 280 | ! |
---|
| 281 | !-- Temperature needed in degree Celsius |
---|
[1353] | 282 | pt1 = pt_p(k,j,i) - 273.15_wp |
---|
[96] | 283 | pt2 = pt1 * pt1 |
---|
| 284 | pt3 = pt1 * pt2 |
---|
| 285 | pt4 = pt2 * pt2 |
---|
| 286 | |
---|
| 287 | sa1 = sa_p(k,j,i) |
---|
| 288 | sa15 = sa1 * SQRT( sa1 ) |
---|
| 289 | sa2 = sa1 * sa1 |
---|
| 290 | |
---|
[1320] | 291 | pnom = nom(1) + nom(2)*pt1 + nom(3)*pt2 + & |
---|
| 292 | nom(4)*pt3 + nom(5)*sa1 + nom(6)*sa1*pt1 + & |
---|
[388] | 293 | nom(7)*sa2 |
---|
| 294 | |
---|
[1320] | 295 | pden = den(1) + den(2)*pt1 + den(3)*pt2 + & |
---|
| 296 | den(4)*pt3 + den(5)*pt4 + den(6)*sa1 + & |
---|
| 297 | den(7)*sa1*pt1 + den(8)*sa1*pt3 + den(9)*sa15 + & |
---|
[388] | 298 | den(10)*sa15*pt2 |
---|
| 299 | ! |
---|
[2232] | 300 | !-- Predetermine flag to mask topography |
---|
| 301 | flag = MERGE( 1.0_wp, 0.0_wp, BTEST( wall_flags_0(k,j,i), 0 ) ) |
---|
| 302 | ! |
---|
[388] | 303 | !-- Potential density (without pressure terms) |
---|
[2232] | 304 | prho(k,j,i) = pnom / pden * flag |
---|
[388] | 305 | |
---|
[1320] | 306 | pnom = pnom + nom(8)*p1 + nom(9)*p1*pt2 + & |
---|
[388] | 307 | nom(10)*p1*sa1 + nom(11)*p2 + nom(12)*p2*pt2 |
---|
[1320] | 308 | pden = pden + den(11)*p1 + den(12)*p2*pt3 + & |
---|
[388] | 309 | den(13)*p3*pt1 |
---|
| 310 | |
---|
| 311 | ! |
---|
| 312 | !-- In-situ density |
---|
[2232] | 313 | rho_ocean(k,j,i) = pnom / pden * flag |
---|
[388] | 314 | |
---|
| 315 | |
---|
[96] | 316 | ENDDO |
---|
[97] | 317 | ! |
---|
[2232] | 318 | !-- Neumann conditions at up/downward-facing walls |
---|
| 319 | surf_s = bc_h(0)%start_index(j,i) |
---|
| 320 | surf_e = bc_h(0)%end_index(j,i) |
---|
| 321 | DO m = surf_s, surf_e |
---|
| 322 | k = bc_h(0)%k(m) |
---|
| 323 | prho(k-1,j,i) = prho(k,j,i) |
---|
| 324 | rho_ocean(k-1,j,i) = rho_ocean(k,j,i) |
---|
| 325 | ENDDO |
---|
| 326 | ! |
---|
| 327 | !-- Downward facing surfaces |
---|
| 328 | surf_s = bc_h(1)%start_index(j,i) |
---|
| 329 | surf_e = bc_h(1)%end_index(j,i) |
---|
| 330 | DO m = surf_s, surf_e |
---|
| 331 | k = bc_h(1)%k(m) |
---|
| 332 | prho(k+1,j,i) = prho(k,j,i) |
---|
| 333 | rho_ocean(k+1,j,i) = rho_ocean(k,j,i) |
---|
| 334 | ENDDO |
---|
| 335 | ! |
---|
| 336 | !-- Neumann condition are assumed at top boundary |
---|
| 337 | prho(nzt+1,j,i) = prho(nzt,j,i) |
---|
| 338 | rho_ocean(nzt+1,j,i) = rho_ocean(nzt,j,i) |
---|
[96] | 339 | |
---|
| 340 | END SUBROUTINE eqn_state_seawater_ij |
---|
| 341 | |
---|
| 342 | |
---|
| 343 | !------------------------------------------------------------------------------! |
---|
[1682] | 344 | ! Description: |
---|
| 345 | ! ------------ |
---|
| 346 | !> Equation of state as a function |
---|
[96] | 347 | !------------------------------------------------------------------------------! |
---|
[1320] | 348 | REAL(wp) FUNCTION eqn_state_seawater_func( p, pt, sa ) |
---|
[96] | 349 | |
---|
| 350 | IMPLICIT NONE |
---|
| 351 | |
---|
[1682] | 352 | REAL(wp) :: p !< |
---|
| 353 | REAL(wp) :: p1 !< |
---|
| 354 | REAL(wp) :: p2 !< |
---|
| 355 | REAL(wp) :: p3 !< |
---|
| 356 | REAL(wp) :: pt !< |
---|
| 357 | REAL(wp) :: pt1 !< |
---|
| 358 | REAL(wp) :: pt2 !< |
---|
| 359 | REAL(wp) :: pt3 !< |
---|
| 360 | REAL(wp) :: pt4 !< |
---|
| 361 | REAL(wp) :: sa !< |
---|
| 362 | REAL(wp) :: sa15 !< |
---|
| 363 | REAL(wp) :: sa2 !< |
---|
[96] | 364 | |
---|
| 365 | ! |
---|
| 366 | !-- Pressure is needed in dbar |
---|
[1353] | 367 | p1 = p * 1E-4_wp |
---|
[96] | 368 | p2 = p1 * p1 |
---|
| 369 | p3 = p2 * p1 |
---|
| 370 | |
---|
| 371 | ! |
---|
| 372 | !-- Temperature needed in degree Celsius |
---|
[1353] | 373 | pt1 = pt - 273.15_wp |
---|
[96] | 374 | pt2 = pt1 * pt1 |
---|
| 375 | pt3 = pt1 * pt2 |
---|
| 376 | pt4 = pt2 * pt2 |
---|
| 377 | |
---|
| 378 | sa15 = sa * SQRT( sa ) |
---|
| 379 | sa2 = sa * sa |
---|
| 380 | |
---|
| 381 | |
---|
| 382 | eqn_state_seawater_func = & |
---|
| 383 | ( nom(1) + nom(2)*pt1 + nom(3)*pt2 + nom(4)*pt3 + & |
---|
| 384 | nom(5)*sa + nom(6)*sa*pt1 + nom(7)*sa2 + nom(8)*p1 + & |
---|
| 385 | nom(9)*p1*pt2 + nom(10)*p1*sa + nom(11)*p2 + nom(12)*p2*pt2 & |
---|
| 386 | ) / & |
---|
| 387 | ( den(1) + den(2)*pt1 + den(3)*pt2 + den(4)*pt3 + & |
---|
| 388 | den(5)*pt4 + den(6)*sa + den(7)*sa*pt1 + den(8)*sa*pt3 + & |
---|
| 389 | den(9)*sa15 + den(10)*sa15*pt2 + den(11)*p1 + den(12)*p2*pt3 + & |
---|
| 390 | den(13)*p3*pt1 & |
---|
| 391 | ) |
---|
| 392 | |
---|
| 393 | |
---|
| 394 | END FUNCTION eqn_state_seawater_func |
---|
| 395 | |
---|
| 396 | END MODULE eqn_state_seawater_mod |
---|