Changeset 4065 for trunk/LMDZ.COMMON/libf/evolution/maths.F90
- Timestamp:
- Feb 12, 2026, 9:09:12 AM (2 weeks ago)
- File:
-
- 1 moved
-
trunk/LMDZ.COMMON/libf/evolution/maths.F90 (moved) (moved from trunk/LMDZ.COMMON/libf/evolution/math_toolkit.F90) (16 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/LMDZ.COMMON/libf/evolution/maths.F90
r4064 r4065 1 module math _toolkit2 !----------------------------------------------------------------------- 3 ! NAME 4 ! math _toolkit1 module maths 2 !----------------------------------------------------------------------- 3 ! NAME 4 ! maths 5 5 ! 6 6 ! DESCRIPTION … … 15 15 !----------------------------------------------------------------------- 16 16 17 ! DECLARATION 18 ! ----------- 19 implicit none 17 ! DEPENDENCIES 18 ! ------------ 19 use numerics, only: dp, di, k4, minieps 20 21 ! DECLARATION 22 ! ----------- 23 implicit none 24 25 ! PARAMETERS 26 ! ---------- 27 real(dp), parameter :: pi = 4._dp*atan(1._dp) ! PI = 3.14159... 28 integer(di), parameter :: limiter_minmod = 1 29 integer(di), parameter :: limiter_MC = 2 30 integer(di), parameter :: limiter_vanLeer = 3 20 31 21 32 contains … … 47 58 ! ARGUMENTS 48 59 ! --------- 49 integer , intent(in) :: nz ! number of layer50 real , dimension(nz), intent(in) :: z ! depth layer51 real , dimension(nz), intent(in) :: y ! function which needs to be derived52 real , intent(in) :: y0, ybot ! boundary conditions53 real , dimension(nz), intent(out) :: dzY ! derivative of y w.r.t depth54 55 ! LOCAL VARIABLES 56 ! --------------- 57 integer :: j58 real :: hm, hp, c1, c2, c360 integer(di), intent(in) :: nz ! number of layer 61 real(dp), dimension(nz), intent(in) :: z ! depth layer 62 real(dp), dimension(nz), intent(in) :: y ! function which needs to be derived 63 real(dp), intent(in) :: y0, ybot ! boundary conditions 64 real(dp), dimension(nz), intent(out) :: dzY ! derivative of y w.r.t depth 65 66 ! LOCAL VARIABLES 67 ! --------------- 68 integer(di) :: j 69 real(dp) :: hm, hp, c1, c2, c3 59 70 60 71 ! CODE … … 69 80 hm = z(j) - z(j - 1) 70 81 c1 = +hm/(hp*(z(j + 1) - z(j - 1))) 71 c2 = 1 /hm - 1/hp82 c2 = 1._dp/hm - 1._dp/hp 72 83 c3 = -hp/(hm*(z(j + 1) - z(j - 1))) 73 84 dzY(j) = c1*y(j + 1) + c2*y(j) + c3*y(j - 1) 74 end do75 dzY(nz) = (ybot - y(nz - 1))/(2. *(z(nz) - z(nz - 1)))85 end do 86 dzY(nz) = (ybot - y(nz - 1))/(2._dp*(z(nz) - z(nz - 1))) 76 87 77 88 END SUBROUTINE deriv1 … … 101 112 ! ARGUMENTS 102 113 ! --------- 103 integer , intent(in) :: nz104 real , dimension(nz), intent(in) :: z, y105 real , intent(in) :: y0, yNp1106 real , dimension(nz), intent(out) :: yp2107 108 ! LOCAL VARIABLES 109 ! --------------- 110 integer :: j111 real :: hm, hp, c1, c2, c3112 113 ! CODE 114 ! ---- 115 c1 = +2. /((z(2) - z(1))*z(2))116 c2 = -2. /((z(2) - z(1))*z(1))117 c3 = +2. /(z(1)*z(2))114 integer(di), intent(in) :: nz 115 real(dp), dimension(nz), intent(in) :: z, y 116 real(dp), intent(in) :: y0, yNp1 117 real(dp), dimension(nz), intent(out) :: yp2 118 119 ! LOCAL VARIABLES 120 ! --------------- 121 integer(di) :: j 122 real(dp) :: hm, hp, c1, c2, c3 123 124 ! CODE 125 ! ---- 126 c1 = +2._dp/((z(2) - z(1))*z(2)) 127 c2 = -2._dp/((z(2) - z(1))*z(1)) 128 c3 = +2._dp/(z(1)*z(2)) 118 129 yp2(1) = c1*y(2) + c2*y(1) + c3*y0 119 130 do j = 2,nz - 1 120 131 hp = z(j + 1) - z(j) 121 132 hm = z(j) - z(j - 1) 122 c1 = +2. /(hp*(z(j + 1) - z(j - 1)))123 c2 = -2. /(hp*hm)124 c3 = +2. /(hm*(z(j + 1) - z(j-1)))133 c1 = +2._dp/(hp*(z(j + 1) - z(j - 1))) 134 c2 = -2._dp/(hp*hm) 135 c3 = +2._dp/(hm*(z(j + 1) - z(j - 1))) 125 136 yp2(j) = c1*y(j + 1) + c2*y(j) + c3*y(j - 1) 126 end do127 yp2(nz) = (yNp1 - 2 *y(nz) + y(nz - 1))/(z(nz) - z(nz - 1))**2137 end do 138 yp2(nz) = (yNp1 - 2._dp*y(nz) + y(nz - 1))/(z(nz) - z(nz - 1))**2 128 139 129 140 END SUBROUTINE deriv2_simple … … 154 165 ! ARGUMENTS 155 166 ! --------- 156 integer , intent(in) :: nz, j157 real , dimension(nz), intent(in) :: z, y158 real , intent(out) :: dy_zj159 160 ! LOCAL VARIABLES 161 ! --------------- 162 real :: h1, h2, c1, c2, c3167 integer(di), intent(in) :: nz, j 168 real(dp), dimension(nz), intent(in) :: z, y 169 real(dp), intent(out) :: dy_zj 170 171 ! LOCAL VARIABLES 172 ! --------------- 173 real(dp) :: h1, h2, c1, c2, c3 163 174 164 175 ! CODE 165 176 ! ---- 166 177 if (j < 1 .or. j > nz - 2) then 167 dy_zj = -1. 178 dy_zj = -1._dp 168 179 else 169 180 h1 = z(j + 1) - z(j) 170 181 h2 = z(j + 2)- z(j + 1) 171 c1 = -(2 *h1 + h2)/(h1*(h1 + h2))182 c1 = -(2._dp*h1 + h2)/(h1*(h1 + h2)) 172 183 c2 = (h1 + h2)/(h1*h2) 173 184 c3 = -h1/(h2*(h1 + h2)) 174 185 dy_zj = c1*y(j) + c2*y(j + 1) + c3*y(j + 2) 175 end if186 end if 176 187 177 188 END SUBROUTINE deriv1_onesided … … 201 212 ! ARGUMENTS 202 213 ! --------- 203 integer , intent(in) :: nz, i1, i2204 real , dimension(nz), intent(in) :: y, z205 real , intent(out) :: integral206 207 ! LOCAL VARIABLES 208 ! --------------- 209 integer :: i210 real , dimension(nz) :: dz214 integer(di), intent(in) :: nz, i1, i2 215 real(dp), dimension(nz), intent(in) :: y, z 216 real(dp), intent(out) :: integral 217 218 ! LOCAL VARIABLES 219 ! --------------- 220 integer(di) :: i 221 real(dp), dimension(nz) :: dz 211 222 212 223 ! CODE … … 215 226 do i = 2,nz - 1 216 227 dz(i) = (z(i + 1) - z(i - 1))/2. 217 end do228 end do 218 229 dz(nz) = z(nz) - z(nz - 1) 219 230 integral = sum(y(i1:i2)*dz(i1:i2)) … … 245 256 ! ARGUMENTS 246 257 ! --------- 247 real , intent(in) :: y1, y2248 real , intent(in) :: z1, z2249 real , intent(out) :: zr258 real(dp), intent(in) :: y1, y2 259 real(dp), intent(in) :: z1, z2 260 real(dp), intent(out) :: zr 250 261 251 262 ! CODE … … 283 294 ! ARGUMENTS 284 295 ! --------- 285 integer , intent(in) :: n286 real , dimension(n), intent(in) :: b, d287 real , dimension(n - 1), intent(in) :: a, c288 real , dimension(n), intent(out) :: x289 integer , intent(out) :: error290 291 ! LOCAL VARIABLES 292 ! --------------- 293 integer :: i294 real :: m295 real , dimension(n) :: cp, dp296 integer(di), intent(in) :: n 297 real(dp), dimension(n), intent(in) :: b, d 298 real(dp), dimension(n - 1), intent(in) :: a, c 299 real(dp), dimension(n), intent(out) :: x 300 integer(di), intent(out) :: error 301 302 ! LOCAL VARIABLES 303 ! --------------- 304 integer(di) :: i 305 real(dp) :: m 306 real(dp), dimension(n) :: cp, dp 296 307 297 308 ! CODE … … 302 313 error = 1 303 314 return 304 end if315 end if 305 316 do i = 2,n - 1 306 317 if (abs(b(i)) < abs(a(i - 1)) + abs(c(i))) then 307 318 error = 1 308 319 return 309 end if310 end do320 end if 321 end do 311 322 if (abs(b(n)) < abs(a(n - 1))) then 312 323 error = 1 313 324 return 314 end if325 end if 315 326 316 327 ! Initialization … … 323 334 cp(i) = c(i)/m 324 335 dp(i) = (d(i) - a(i - 1)*dp(i - 1))/m 325 end do336 end do 326 337 m = b(n) - a(n - 1)*cp(n - 1) 327 338 dp(n) = (d(n) - a(n - 1)*dp(n - 1))/m … … 331 342 do i = n - 1,1,-1 332 343 x(i) = dp(i) - cp(i)*x(i + 1) 333 end do344 end do 334 345 335 346 END SUBROUTINE solve_tridiag … … 358 369 ! DEPENDENCIES 359 370 ! ------------ 360 use stop _pem, only: stop_clean361 362 ! DECLARATION 363 ! ----------- 364 implicit none 365 366 ! ARGUMENTS 367 ! --------- 368 integer , intent(in) :: n369 real , dimension(n), intent(in) :: z, kappa370 real , dimension(n - 1), intent(in) :: mz, mkappa371 real , intent(in) :: T_left, q_right372 real , dimension(n), intent(out) :: T373 374 ! LOCAL VARIABLES 375 ! --------------- 376 integer :: i, error377 real , dimension(n) :: b, d378 real , dimension(n - 1) :: a, c371 use stoppage, only: stop_clean 372 373 ! DECLARATION 374 ! ----------- 375 implicit none 376 377 ! ARGUMENTS 378 ! --------- 379 integer(di), intent(in) :: n 380 real(dp), dimension(n), intent(in) :: z, kappa 381 real(dp), dimension(n - 1), intent(in) :: mz, mkappa 382 real(dp), intent(in) :: T_left, q_right 383 real(dp), dimension(n), intent(out) :: T 384 385 ! LOCAL VARIABLES 386 ! --------------- 387 integer(di) :: i, error 388 real(dp), dimension(n) :: b, d 389 real(dp), dimension(n - 1) :: a, c 379 390 380 391 ! CODE 381 392 ! ---- 382 393 ! Initialization 383 a = 0. ; b = 0.; c = 0.; d = 0.394 a = 0._dp; b = 0._dp; c = 0._dp; d = 0._dp 384 395 385 396 ! Left boundary condition (Dirichlet: prescribed temperature) 386 b(1) = 1. 397 b(1) = 1._dp 387 398 d(1) = T_left 388 399 … … 392 403 c(i) = -mkappa(i)/((mz(i) - mz(i - 1))*(z(i + 1) - z(i))) 393 404 b(i) = -(a(i - 1) + c(i)) 394 end do405 end do 395 406 396 407 ! Right boundary condition (Neumann: prescribed temperature) … … 401 412 ! Solve the tridiagonal linear system with the Thomas' algorithm 402 413 call solve_tridiag(a,b,c,d,n,T,error) 403 if (error /= 0) call stop_clean( "solve_steady_heat","Unstable solving!",1)414 if (error /= 0) call stop_clean(__FILE__,__LINE__,"unstable solving!",1) 404 415 405 416 END SUBROUTINE solve_steady_heat 406 417 !======================================================================= 407 418 408 end module math _toolkit419 end module maths
Note: See TracChangeset
for help on using the changeset viewer.
