[396] | 1 | ! |
---|
| 2 | ! $Id$ |
---|
| 3 | ! |
---|
| 4 | C AGRIF (Adaptive Grid Refinement In Fortran) |
---|
| 5 | C |
---|
| 6 | C Copyright (C) 2003 Laurent Debreu (Laurent.Debreu@imag.fr) |
---|
| 7 | C Christophe Vouland (Christophe.Vouland@imag.fr) |
---|
| 8 | C |
---|
| 9 | C This program is free software; you can redistribute it and/or modify |
---|
| 10 | C it under the terms of the GNU General Public License as published by |
---|
| 11 | C the Free Software Foundation; either version 2 of the License, or |
---|
| 12 | C (at your option) any later version. |
---|
| 13 | C |
---|
| 14 | C This program is distributed in the hope that it will be useful, |
---|
| 15 | C but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 16 | C MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 17 | C GNU General Public License for more details. |
---|
| 18 | C |
---|
| 19 | C You should have received a copy of the GNU General Public License |
---|
| 20 | C along with this program; if not, write to the Free Software |
---|
| 21 | C Foundation, Inc., 59 Temple Place- Suite 330, Boston, MA 02111-1307, USA. |
---|
| 22 | C |
---|
| 23 | C |
---|
| 24 | C |
---|
| 25 | CCC Module Agrif_Interpbasic |
---|
| 26 | C |
---|
| 27 | Module Agrif_Interpbasic |
---|
| 28 | C |
---|
| 29 | CCC Description: |
---|
| 30 | CCC Module containing different procedures of interpolation (linear,lagrange, |
---|
| 31 | CCC spline,...) used in the Agrif_Interpolation module. |
---|
| 32 | C |
---|
| 33 | C Modules used: |
---|
| 34 | USE Agrif_types |
---|
| 35 | C |
---|
| 36 | IMPLICIT NONE |
---|
| 37 | C |
---|
| 38 | CONTAINS |
---|
| 39 | C Define procedures contained in this module |
---|
| 40 | C |
---|
| 41 | C |
---|
| 42 | C ************************************************************************** |
---|
| 43 | CCC Subroutine Linear1d |
---|
| 44 | C ************************************************************************** |
---|
| 45 | C |
---|
| 46 | Subroutine Linear1d(x,y,np,nc, |
---|
| 47 | & s_parent,s_child,ds_parent,ds_child) |
---|
| 48 | C |
---|
| 49 | CCC Description: |
---|
| 50 | CCC Subroutine to do a linear 1D interpolation on a child grid (vector y) from |
---|
| 51 | CCC its parent grid (vector x). |
---|
| 52 | C |
---|
| 53 | CC Method: |
---|
| 54 | C |
---|
| 55 | C Declarations: |
---|
| 56 | C |
---|
| 57 | |
---|
| 58 | C |
---|
| 59 | C Arguments |
---|
| 60 | INTEGER :: np,nc |
---|
| 61 | REAL, DIMENSION(np) :: x |
---|
| 62 | REAL, DIMENSION(nc) :: y |
---|
| 63 | REAL :: s_parent,s_child,ds_parent,ds_child |
---|
| 64 | C |
---|
| 65 | C Local scalars |
---|
| 66 | INTEGER :: i,coeffraf,locind_parent_left |
---|
| 67 | REAL :: ypos,globind_parent_left |
---|
| 68 | C |
---|
| 69 | C |
---|
| 70 | |
---|
| 71 | coeffraf = nint(ds_parent/ds_child) |
---|
| 72 | C |
---|
| 73 | if (coeffraf == 1) then |
---|
| 74 | C |
---|
| 75 | locind_parent_left = 1 + nint((s_child - s_parent)/ds_parent) |
---|
| 76 | C |
---|
| 77 | y(1:nc) = x(locind_parent_left:locind_parent_left+nc-1) |
---|
| 78 | C |
---|
| 79 | return |
---|
| 80 | C |
---|
| 81 | endif |
---|
| 82 | C |
---|
| 83 | ypos = s_child |
---|
| 84 | C |
---|
| 85 | do i = 1,nc-1 |
---|
| 86 | C |
---|
| 87 | locind_parent_left = 1 + agrif_int((ypos - s_parent)/ds_parent) |
---|
| 88 | C |
---|
| 89 | globind_parent_left = s_parent |
---|
| 90 | & + (locind_parent_left - 1)*ds_parent |
---|
| 91 | C |
---|
| 92 | y(i) = ((globind_parent_left + ds_parent - ypos) |
---|
| 93 | & *x(locind_parent_left) |
---|
| 94 | & + (ypos - globind_parent_left) |
---|
| 95 | & *x(locind_parent_left+1)) |
---|
| 96 | & / ds_parent |
---|
| 97 | C |
---|
| 98 | ypos = ypos + ds_child |
---|
| 99 | C |
---|
| 100 | enddo |
---|
| 101 | C |
---|
| 102 | locind_parent_left = 1 + agrif_int((ypos - s_parent)/ds_parent) |
---|
| 103 | C |
---|
| 104 | if (locind_parent_left == np) then |
---|
| 105 | C |
---|
| 106 | y(nc) = x(np) |
---|
| 107 | C |
---|
| 108 | else |
---|
| 109 | C |
---|
| 110 | globind_parent_left = s_parent |
---|
| 111 | & + (locind_parent_left - 1)*ds_parent |
---|
| 112 | C |
---|
| 113 | y(nc) = ((globind_parent_left + ds_parent - ypos) |
---|
| 114 | & *x(locind_parent_left) |
---|
| 115 | & + (ypos - globind_parent_left) |
---|
| 116 | & *x(locind_parent_left+1)) |
---|
| 117 | & / ds_parent |
---|
| 118 | C |
---|
| 119 | endif |
---|
| 120 | C |
---|
| 121 | Return |
---|
| 122 | C |
---|
| 123 | C |
---|
| 124 | End Subroutine Linear1d |
---|
| 125 | C |
---|
| 126 | C |
---|
| 127 | C |
---|
| 128 | C ************************************************************************** |
---|
| 129 | CCC Subroutine Lagrange1d |
---|
| 130 | C ************************************************************************** |
---|
| 131 | C |
---|
| 132 | Subroutine Lagrange1d(x,y,np,nc, |
---|
| 133 | & s_parent,s_child,ds_parent,ds_child) |
---|
| 134 | C |
---|
| 135 | CCC Description: |
---|
| 136 | CCC Subroutine to do a lagrange 1D interpolation on a child grid (vector y) |
---|
| 137 | CCC from its parent grid (vector x). |
---|
| 138 | C |
---|
| 139 | CC Method: |
---|
| 140 | C |
---|
| 141 | C Declarations: |
---|
| 142 | C |
---|
| 143 | |
---|
| 144 | C |
---|
| 145 | C Arguments |
---|
| 146 | INTEGER :: np,nc |
---|
| 147 | REAL, DIMENSION(np) :: x |
---|
| 148 | REAL, DIMENSION(nc) :: y |
---|
| 149 | REAL :: s_parent,s_child,ds_parent,ds_child |
---|
| 150 | C |
---|
| 151 | C Local scalars |
---|
| 152 | INTEGER :: i,coeffraf,locind_parent_left |
---|
| 153 | REAL :: ypos,globind_parent_left |
---|
| 154 | REAL :: X1,X2,X3 |
---|
| 155 | C |
---|
| 156 | C |
---|
| 157 | if (np <= 2) then |
---|
| 158 | C |
---|
| 159 | Call Linear1D(x,y,np,nc, |
---|
| 160 | & s_parent,s_child,ds_parent,ds_child) |
---|
| 161 | C |
---|
| 162 | Return |
---|
| 163 | C |
---|
| 164 | endif |
---|
| 165 | C |
---|
| 166 | coeffraf = nint(ds_parent/ds_child) |
---|
| 167 | C |
---|
| 168 | if (coeffraf == 1) then |
---|
| 169 | C |
---|
| 170 | locind_parent_left = 1 + nint((s_child - s_parent)/ds_parent) |
---|
| 171 | C |
---|
| 172 | y(1:nc) = x(locind_parent_left:locind_parent_left+nc-1) |
---|
| 173 | C |
---|
| 174 | return |
---|
| 175 | C |
---|
| 176 | endif |
---|
| 177 | C |
---|
| 178 | ypos = s_child |
---|
| 179 | C |
---|
| 180 | do i = 1,nc |
---|
| 181 | C |
---|
| 182 | locind_parent_left = 1 + agrif_int((ypos - s_parent)/ds_parent) |
---|
| 183 | C |
---|
| 184 | globind_parent_left = s_parent |
---|
| 185 | & + (locind_parent_left - 1)*ds_parent |
---|
| 186 | C |
---|
| 187 | if (locind_parent_left+2 <= np) then |
---|
| 188 | C |
---|
| 189 | X1 = (x(locind_parent_left+1)-x(locind_parent_left)) |
---|
| 190 | & /ds_parent |
---|
| 191 | C |
---|
| 192 | X2 = (x(locind_parent_left+2)-x(locind_parent_left+1)) |
---|
| 193 | & /ds_parent |
---|
| 194 | C |
---|
| 195 | X3 = (X2 - X1)/(2.*ds_parent) |
---|
| 196 | C |
---|
| 197 | y(i) = x(locind_parent_left) + |
---|
| 198 | & (ypos - globind_parent_left)*X1 + |
---|
| 199 | & (ypos - globind_parent_left)* |
---|
| 200 | & (ypos - globind_parent_left - ds_parent)*X3 |
---|
| 201 | C |
---|
| 202 | elseif (locind_parent_left+1 <= np) then |
---|
| 203 | C |
---|
| 204 | X1 = (x(locind_parent_left)-x(locind_parent_left-1)) |
---|
| 205 | & /ds_parent |
---|
| 206 | C |
---|
| 207 | X2 = (x(locind_parent_left+1)-x(locind_parent_left)) |
---|
| 208 | & /ds_parent |
---|
| 209 | C |
---|
| 210 | X3 = (X2 - X1)/(2.*ds_parent) |
---|
| 211 | C |
---|
| 212 | y(i) = x(locind_parent_left-1) + |
---|
| 213 | & (ypos - globind_parent_left - ds_parent)*X1 + |
---|
| 214 | & (ypos - globind_parent_left - ds_parent)* |
---|
| 215 | & (ypos - globind_parent_left)*X3 |
---|
| 216 | C |
---|
| 217 | else |
---|
| 218 | C |
---|
| 219 | X1 = (x(locind_parent_left-1)-x(locind_parent_left-2)) |
---|
| 220 | & /ds_parent |
---|
| 221 | C |
---|
| 222 | X2 = (x(locind_parent_left)-x(locind_parent_left-1)) |
---|
| 223 | & /ds_parent |
---|
| 224 | C |
---|
| 225 | X3 = (X2 - X1)/(2.*ds_parent) |
---|
| 226 | C |
---|
| 227 | y(i) = x(locind_parent_left-2) + |
---|
| 228 | & (ypos - globind_parent_left - 2.*ds_parent)*X1 + |
---|
| 229 | & (ypos - globind_parent_left - 2.*ds_parent)* |
---|
| 230 | & (ypos - globind_parent_left - ds_parent)*X3 |
---|
| 231 | C |
---|
| 232 | endif |
---|
| 233 | C |
---|
| 234 | ypos = ypos + ds_child |
---|
| 235 | C |
---|
| 236 | enddo |
---|
| 237 | C |
---|
| 238 | return |
---|
| 239 | C |
---|
| 240 | C |
---|
| 241 | End Subroutine Lagrange1d |
---|
| 242 | C |
---|
| 243 | C |
---|
| 244 | C ************************************************************************** |
---|
| 245 | CCC Subroutine Constant1d |
---|
| 246 | C ************************************************************************** |
---|
| 247 | C |
---|
| 248 | Subroutine constant1d(x,y,np,nc, |
---|
| 249 | & s_parent,s_child,ds_parent,ds_child) |
---|
| 250 | C |
---|
| 251 | CCC Description: |
---|
| 252 | CCC Subroutine to do a linear 1D interpolation on a child grid (vector y) from |
---|
| 253 | CCC its parent grid (vector x). |
---|
| 254 | C |
---|
| 255 | CC Method: |
---|
| 256 | C |
---|
| 257 | C Declarations: |
---|
| 258 | C |
---|
| 259 | |
---|
| 260 | C |
---|
| 261 | C Arguments |
---|
| 262 | INTEGER :: np,nc |
---|
| 263 | REAL, DIMENSION(np) :: x |
---|
| 264 | REAL, DIMENSION(nc) :: y |
---|
| 265 | REAL :: s_parent,s_child,ds_parent,ds_child |
---|
| 266 | C |
---|
| 267 | C Local scalars |
---|
| 268 | INTEGER :: i,coeffraf,locind_parent |
---|
| 269 | REAL :: ypos |
---|
| 270 | C |
---|
| 271 | C |
---|
| 272 | |
---|
| 273 | coeffraf = nint(ds_parent/ds_child) |
---|
| 274 | C |
---|
| 275 | if (coeffraf == 1) then |
---|
| 276 | C |
---|
| 277 | locind_parent = 1 + nint((s_child - s_parent)/ds_parent) |
---|
| 278 | C |
---|
| 279 | y(1:nc) = x(locind_parent:locind_parent+nc-1) |
---|
| 280 | C |
---|
| 281 | return |
---|
| 282 | C |
---|
| 283 | endif |
---|
| 284 | C |
---|
| 285 | ypos = s_child |
---|
| 286 | C |
---|
| 287 | do i = 1,nc |
---|
| 288 | C |
---|
| 289 | locind_parent = 1 + nint((ypos - s_parent)/ds_parent) |
---|
| 290 | C |
---|
| 291 | y(i) = x(locind_parent) |
---|
| 292 | C |
---|
| 293 | ypos = ypos + ds_child |
---|
| 294 | C |
---|
| 295 | enddo |
---|
| 296 | C |
---|
| 297 | Return |
---|
| 298 | C |
---|
| 299 | C |
---|
| 300 | End Subroutine constant1d |
---|
| 301 | C |
---|
| 302 | C ************************************************************************** |
---|
| 303 | CCC Subroutine Linear1dconserv |
---|
| 304 | C ************************************************************************** |
---|
| 305 | C |
---|
| 306 | Subroutine Linear1dconserv(x,y,np,nc, |
---|
| 307 | & s_parent,s_child,ds_parent,ds_child) |
---|
| 308 | C |
---|
| 309 | CCC Description: |
---|
| 310 | CCC Subroutine to do a linear 1D interpolation on a child grid (vector y) from |
---|
| 311 | CCC its parent grid (vector x). |
---|
| 312 | C |
---|
| 313 | CC Method: |
---|
| 314 | C |
---|
| 315 | C Declarations: |
---|
| 316 | C |
---|
| 317 | Implicit none |
---|
| 318 | C |
---|
| 319 | C Arguments |
---|
| 320 | Integer :: np,nc |
---|
| 321 | Real, Dimension(np) :: x |
---|
| 322 | Real, Dimension(nc) :: y |
---|
| 323 | Real, Dimension(:),Allocatable :: ytemp |
---|
| 324 | Real :: s_parent,s_child,ds_parent,ds_child |
---|
| 325 | C |
---|
| 326 | C Local scalars |
---|
| 327 | Integer :: i,coeffraf,locind_parent_left,locind_parent_last |
---|
| 328 | Real :: ypos |
---|
| 329 | integer :: i1,i2,ii |
---|
| 330 | real :: xpmin,xpmax,slope |
---|
| 331 | INTEGER :: diffmod |
---|
| 332 | REAL :: xdiffmod |
---|
| 333 | |
---|
| 334 | C |
---|
| 335 | C |
---|
| 336 | |
---|
| 337 | coeffraf = nint(ds_parent/ds_child) |
---|
| 338 | C |
---|
| 339 | If (coeffraf == 1) Then |
---|
| 340 | C |
---|
| 341 | locind_parent_left = 1 + nint((s_child - s_parent)/ds_parent) |
---|
| 342 | C |
---|
| 343 | y(1:nc) = x(locind_parent_left:locind_parent_left+nc-1) |
---|
| 344 | C |
---|
| 345 | return |
---|
| 346 | C |
---|
| 347 | End If |
---|
| 348 | C |
---|
| 349 | diffmod = 0 |
---|
| 350 | IF (mod(coeffraf,2) == 0) diffmod = 1 |
---|
| 351 | |
---|
| 352 | xdiffmod = real(diffmod)/2. |
---|
| 353 | |
---|
| 354 | allocate(ytemp(-2*coeffraf:nc+2*coeffraf)) |
---|
| 355 | C |
---|
| 356 | ypos = s_child |
---|
| 357 | C |
---|
| 358 | locind_parent_left = 1 + agrif_int((ypos - s_parent)/ds_parent) |
---|
| 359 | |
---|
| 360 | locind_parent_last = 1 + |
---|
| 361 | & agrif_ceiling((ypos +(nc - 1) *ds_child - s_parent)/ds_parent) |
---|
| 362 | |
---|
| 363 | xpmin = s_parent + (locind_parent_left-1)*ds_parent |
---|
| 364 | xpmax = s_parent + (locind_parent_last-1)*ds_parent |
---|
| 365 | |
---|
| 366 | i1 = 1+agrif_int((xpmin-s_child)/ds_child) |
---|
| 367 | i2 = 1+agrif_int((xpmax-s_child)/ds_child) |
---|
| 368 | |
---|
| 369 | i = i1 |
---|
| 370 | |
---|
| 371 | if (locind_parent_left == 1) then |
---|
| 372 | slope= |
---|
| 373 | & (x(locind_parent_left+1)-x(locind_parent_left))/(coeffraf) |
---|
| 374 | else |
---|
| 375 | slope= |
---|
| 376 | & (x(locind_parent_left+1)-x(locind_parent_left-1))/(2.*coeffraf) |
---|
| 377 | endif |
---|
| 378 | |
---|
| 379 | do ii=i-coeffraf/2+diffmod,i+coeffraf/2 |
---|
| 380 | ytemp(ii) = x(locind_parent_left)+(ii-i-xdiffmod/2.)*slope |
---|
| 381 | enddo |
---|
| 382 | |
---|
| 383 | locind_parent_left = locind_parent_left + 1 |
---|
| 384 | |
---|
| 385 | do i=i1 + coeffraf, i2 - coeffraf,coeffraf |
---|
| 386 | slope= |
---|
| 387 | & (x(locind_parent_left+1)-x(locind_parent_left-1))/(2.*coeffraf) |
---|
| 388 | do ii=i-coeffraf/2+diffmod,i+coeffraf/2 |
---|
| 389 | ytemp(ii) = x(locind_parent_left)+(ii-i-xdiffmod/2.)*slope |
---|
| 390 | enddo |
---|
| 391 | locind_parent_left = locind_parent_left + 1 |
---|
| 392 | enddo |
---|
| 393 | |
---|
| 394 | i = i2 |
---|
| 395 | |
---|
| 396 | if (locind_parent_left == np) then |
---|
| 397 | slope= |
---|
| 398 | & (x(locind_parent_left)-x(locind_parent_left-1))/(coeffraf) |
---|
| 399 | else |
---|
| 400 | slope= |
---|
| 401 | & (x(locind_parent_left+1)-x(locind_parent_left-1))/(2.*coeffraf) |
---|
| 402 | endif |
---|
| 403 | |
---|
| 404 | do ii=i-coeffraf/2+diffmod,nc |
---|
| 405 | ytemp(ii) = x(locind_parent_left)+(ii-i-xdiffmod/2.)*slope |
---|
| 406 | enddo |
---|
| 407 | C |
---|
| 408 | y(1:nc)=ytemp(1:nc) |
---|
| 409 | C |
---|
| 410 | deallocate(ytemp) |
---|
| 411 | Return |
---|
| 412 | C |
---|
| 413 | End Subroutine Linear1dconserv |
---|
| 414 | |
---|
| 415 | C |
---|
| 416 | C ************************************************************************** |
---|
| 417 | CCC Subroutine Linear1dconservlim |
---|
| 418 | C ************************************************************************** |
---|
| 419 | C |
---|
| 420 | Subroutine Linear1dconservlim(x,y,np,nc, |
---|
| 421 | & s_parent,s_child,ds_parent,ds_child) |
---|
| 422 | C |
---|
| 423 | CCC Description: |
---|
| 424 | CCC Subroutine to do a linear 1D interpolation on a child grid (vector y) from |
---|
| 425 | CCC its parent grid (vector x). |
---|
| 426 | C |
---|
| 427 | CC Method: |
---|
| 428 | C |
---|
| 429 | C Declarations: |
---|
| 430 | C |
---|
| 431 | Implicit none |
---|
| 432 | C |
---|
| 433 | C Arguments |
---|
| 434 | Integer :: np,nc |
---|
| 435 | Real, Dimension(np) :: x |
---|
| 436 | Real, Dimension(nc) :: y |
---|
| 437 | Real, Dimension(:),Allocatable :: ytemp |
---|
| 438 | Real :: s_parent,s_child,ds_parent,ds_child |
---|
| 439 | C |
---|
| 440 | C Local scalars |
---|
| 441 | Integer :: i,coeffraf,locind_parent_left,locind_parent_last |
---|
| 442 | Real :: ypos |
---|
| 443 | integer :: i1,i2,ii |
---|
| 444 | real :: xpmin,xpmax,slope |
---|
| 445 | INTEGER :: diffmod |
---|
| 446 | real :: xdiffmod |
---|
| 447 | C |
---|
| 448 | C |
---|
| 449 | |
---|
| 450 | coeffraf = nint(ds_parent/ds_child) |
---|
| 451 | C |
---|
| 452 | If (coeffraf == 1) Then |
---|
| 453 | C |
---|
| 454 | locind_parent_left = 1 + nint((s_child - s_parent)/ds_parent) |
---|
| 455 | C |
---|
| 456 | y(1:nc) = x(locind_parent_left:locind_parent_left+nc-1) |
---|
| 457 | C |
---|
| 458 | return |
---|
| 459 | C |
---|
| 460 | End If |
---|
| 461 | C |
---|
| 462 | IF (coeffraf .NE.3) THEN |
---|
| 463 | print *,'LINEARCONSERVLIM not ready for refinement ratio = ', |
---|
| 464 | & coeffraf |
---|
| 465 | stop |
---|
| 466 | ENDIF |
---|
| 467 | |
---|
| 468 | diffmod = 0 |
---|
| 469 | IF (mod(coeffraf,2) == 0) diffmod = 1 |
---|
| 470 | |
---|
| 471 | xdiffmod = real(diffmod)/2. |
---|
| 472 | |
---|
| 473 | allocate(ytemp(-2*coeffraf:nc+2*coeffraf)) |
---|
| 474 | C |
---|
| 475 | ypos = s_child |
---|
| 476 | C |
---|
| 477 | locind_parent_left = 1 + agrif_int((ypos - s_parent)/ds_parent) |
---|
| 478 | |
---|
| 479 | locind_parent_last = 1 + |
---|
| 480 | & agrif_ceiling((ypos +(nc - 1) *ds_child - s_parent)/ds_parent) |
---|
| 481 | |
---|
| 482 | xpmin = s_parent + (locind_parent_left-1)*ds_parent |
---|
| 483 | xpmax = s_parent + (locind_parent_last-1)*ds_parent |
---|
| 484 | |
---|
| 485 | i1 = 1+agrif_int((xpmin-s_child)/ds_child) |
---|
| 486 | i2 = 1+agrif_int((xpmax-s_child)/ds_child) |
---|
| 487 | |
---|
| 488 | i = i1 |
---|
| 489 | |
---|
| 490 | if (locind_parent_left == 1) then |
---|
| 491 | slope=0. |
---|
| 492 | else |
---|
| 493 | slope = vanleer(x(locind_parent_left-1:locind_parent_left+1)) |
---|
| 494 | slope = slope / coeffraf |
---|
| 495 | endif |
---|
| 496 | |
---|
| 497 | do ii=i-coeffraf/2+diffmod,i+coeffraf/2 |
---|
| 498 | ytemp(ii) = x(locind_parent_left)+(ii-i-xdiffmod/2.)*slope |
---|
| 499 | enddo |
---|
| 500 | |
---|
| 501 | locind_parent_left = locind_parent_left + 1 |
---|
| 502 | |
---|
| 503 | do i=i1 + coeffraf, i2 - coeffraf,coeffraf |
---|
| 504 | slope = vanleer(x(locind_parent_left-1:locind_parent_left+1)) |
---|
| 505 | slope = slope / coeffraf |
---|
| 506 | |
---|
| 507 | do ii=i-coeffraf/2+diffmod,i+coeffraf/2 |
---|
| 508 | ytemp(ii) = x(locind_parent_left)+(ii-i-xdiffmod/2.)*slope |
---|
| 509 | enddo |
---|
| 510 | locind_parent_left = locind_parent_left + 1 |
---|
| 511 | enddo |
---|
| 512 | |
---|
| 513 | i = i2 |
---|
| 514 | |
---|
| 515 | if (locind_parent_left == np) then |
---|
| 516 | slope=0. |
---|
| 517 | else |
---|
| 518 | slope = vanleer(x(locind_parent_left-1:locind_parent_left+1)) |
---|
| 519 | slope = slope / coeffraf |
---|
| 520 | endif |
---|
| 521 | |
---|
| 522 | do ii=i-coeffraf/2+diffmod,nc |
---|
| 523 | ytemp(ii) = x(locind_parent_left)+(ii-i-xdiffmod/2.)*slope |
---|
| 524 | enddo |
---|
| 525 | C |
---|
| 526 | y(1:nc)=ytemp(1:nc) |
---|
| 527 | C |
---|
| 528 | deallocate(ytemp) |
---|
| 529 | Return |
---|
| 530 | C |
---|
| 531 | End Subroutine Linear1dconservlim |
---|
| 532 | C |
---|
| 533 | |
---|
| 534 | C ************************************************************************** |
---|
| 535 | CCC Subroutine ppm1d |
---|
| 536 | C ************************************************************************** |
---|
| 537 | C |
---|
| 538 | Subroutine ppm1d(x,y,np,nc, |
---|
| 539 | & s_parent,s_child,ds_parent,ds_child) |
---|
| 540 | C |
---|
| 541 | CCC Description: |
---|
| 542 | CCC Subroutine to do a 1D interpolation and apply monotonicity constraints |
---|
| 543 | CCC using piecewise parabolic method |
---|
| 544 | CCC on a child grid (vector y) from its parent grid (vector x). |
---|
| 545 | CC Method: |
---|
| 546 | C |
---|
| 547 | C Declarations: |
---|
| 548 | C |
---|
| 549 | Implicit none |
---|
| 550 | C |
---|
| 551 | C Arguments |
---|
| 552 | Integer :: np,nc |
---|
| 553 | Real, Dimension(np) :: x |
---|
| 554 | Real, Dimension(nc) :: y |
---|
| 555 | Real, Dimension(:),Allocatable :: ytemp |
---|
| 556 | Real :: s_parent,s_child,ds_parent,ds_child |
---|
| 557 | C |
---|
| 558 | C Local scalars |
---|
| 559 | Integer :: i,coeffraf,locind_parent_left,locind_parent_last |
---|
| 560 | Integer :: iparent,ipos,pos,nmin,nmax |
---|
| 561 | Real :: ypos |
---|
| 562 | integer :: i1,jj |
---|
| 563 | Real :: xpmin,cavg,a,b |
---|
| 564 | C |
---|
| 565 | Real :: xrmin,xrmax,am3,s2,s1 |
---|
| 566 | Real, Dimension(np) :: dela,xr,xl,delta,a6,slope,slope2 |
---|
| 567 | Real, Dimension(:),Allocatable :: diff,diff2,diff3 |
---|
| 568 | INTEGER :: diffmod |
---|
| 569 | C |
---|
| 570 | coeffraf = nint(ds_parent/ds_child) |
---|
| 571 | C |
---|
| 572 | If (coeffraf == 1) Then |
---|
| 573 | locind_parent_left = 1 + nint((s_child - s_parent)/ds_parent) |
---|
| 574 | y(1:nc) = x(locind_parent_left:locind_parent_left+nc-1) |
---|
| 575 | return |
---|
| 576 | End If |
---|
| 577 | C |
---|
| 578 | Allocate(ytemp(-2*coeffraf:nc+2*coeffraf)) |
---|
| 579 | ypos = s_child |
---|
| 580 | C |
---|
| 581 | locind_parent_left = 1 + agrif_int((ypos - s_parent)/ds_parent) |
---|
| 582 | locind_parent_last = 1 + |
---|
| 583 | & agrif_ceiling((ypos +(nc - 1) |
---|
| 584 | & *ds_child - s_parent)/ds_parent) |
---|
| 585 | C |
---|
| 586 | xpmin = s_parent + (locind_parent_left-1)*ds_parent |
---|
| 587 | i1 = 1+agrif_int((xpmin-s_child)/ds_child) |
---|
| 588 | C |
---|
| 589 | Allocate( diff(coeffraf),diff2(coeffraf),diff3(coeffraf) ) |
---|
| 590 | C |
---|
| 591 | diff(:) = ds_child/ds_parent |
---|
| 592 | C |
---|
| 593 | Do i=1,coeffraf |
---|
| 594 | a = real(i-1)*ds_child/ds_parent |
---|
| 595 | b = real(i)*ds_child/ds_parent |
---|
| 596 | diff2(i) = 0.5*(b*b - a*a) |
---|
| 597 | diff3(i) = (1./3.)*(b*b*b - a*a*a) |
---|
| 598 | End do |
---|
| 599 | C |
---|
| 600 | if( locind_parent_last+2 <= np ) then |
---|
| 601 | nmax = locind_parent_last+2 |
---|
| 602 | else if( locind_parent_last+1 <= np ) then |
---|
| 603 | nmax = locind_parent_last+1 |
---|
| 604 | else |
---|
| 605 | nmax = locind_parent_last |
---|
| 606 | endif |
---|
| 607 | C |
---|
| 608 | if(locind_parent_left-1 >= 1) then |
---|
| 609 | nmin = locind_parent_left-1 |
---|
| 610 | else |
---|
| 611 | nmin = locind_parent_left |
---|
| 612 | endif |
---|
| 613 | C |
---|
| 614 | Do i = nmin,nmax |
---|
| 615 | slope(i) = x(i) - x(i-1) |
---|
| 616 | slope2(i) = 2.*abs(slope(i)) |
---|
| 617 | Enddo |
---|
| 618 | C |
---|
| 619 | Do i = nmin,nmax-1 |
---|
| 620 | dela(i) = 0.5 * ( slope(i) + slope(i+1) ) |
---|
| 621 | C Van Leer slope limiter |
---|
| 622 | dela(i) = min( abs(dela(i)),slope2(i), |
---|
| 623 | & slope2(i+1) )*sign(1.,dela(i)) |
---|
| 624 | IF( slope(i)*slope(i+1) <= 0. ) dela(i) = 0. |
---|
| 625 | Enddo |
---|
| 626 | C |
---|
| 627 | Do i = nmin,nmax-2 |
---|
| 628 | xr(i) = x(i) + (1./2.)*slope(i+1) + (-1./6.)*dela(i+1) |
---|
| 629 | & + ( 1./6. )*dela(i) |
---|
| 630 | Enddo |
---|
| 631 | C |
---|
| 632 | Do i = nmin,nmax-2 |
---|
| 633 | xrmin = min(x(i),x(i+1)) |
---|
| 634 | xrmax = max(x(i),x(i+1)) |
---|
| 635 | xr(i) = min(xr(i),xrmax) |
---|
| 636 | xr(i) = max(xr(i),xrmin) |
---|
| 637 | xl(i+1) = xr(i) |
---|
| 638 | Enddo |
---|
| 639 | C apply parabolic monotonicity |
---|
| 640 | Do i = locind_parent_left,locind_parent_last |
---|
| 641 | If( ( (xr(i)-x(i))* (x(i)-xl(i)) ) .le. 0. ) then |
---|
| 642 | xl(i) = x(i) |
---|
| 643 | xr(i) = x(i) |
---|
| 644 | Endif |
---|
| 645 | delta(i) = xr(i) - xl(i) |
---|
| 646 | am3 = 3. * x(i) |
---|
| 647 | s1 = am3 - 2. * xr(i) |
---|
| 648 | s2 = am3 - 2. * xl(i) |
---|
| 649 | IF( delta(i) * (xl(i) - s1) .le. 0. ) xl(i) = s1 |
---|
| 650 | IF( delta(i) * (s2 - xr(i)) .le. 0. ) xr(i) = s2 |
---|
| 651 | delta(i) = xr(i) - xl(i) |
---|
| 652 | a6(i) = 6.*x(i)-3.*(xl(i) +xr(i)) |
---|
| 653 | C |
---|
| 654 | End do |
---|
| 655 | C |
---|
| 656 | diffmod = 0 |
---|
[447] | 657 | IF (mod(coeffraf,2) == 0) diffmod = 1 |
---|
[396] | 658 | C |
---|
| 659 | ipos = i1 |
---|
| 660 | C |
---|
| 661 | Do iparent = locind_parent_left,locind_parent_last |
---|
| 662 | pos=1 |
---|
| 663 | cavg = 0. |
---|
| 664 | Do jj = ipos - coeffraf/2+diffmod,ipos + coeffraf/2 |
---|
| 665 | C |
---|
| 666 | ytemp(jj) = (diff(pos)*xl(iparent) |
---|
| 667 | & + diff2(pos) |
---|
| 668 | & * (delta(iparent)+a6(iparent)) |
---|
| 669 | & - diff3(pos)*a6(iparent))*coeffraf |
---|
| 670 | |
---|
| 671 | cavg = cavg + ytemp(jj) |
---|
| 672 | pos = pos+1 |
---|
| 673 | End do |
---|
| 674 | ipos = ipos + coeffraf |
---|
| 675 | C |
---|
| 676 | End do |
---|
| 677 | C |
---|
| 678 | C |
---|
| 679 | y(1:nc)=ytemp(1:nc) |
---|
| 680 | deallocate(ytemp) |
---|
| 681 | deallocate(diff, diff2, diff3) |
---|
| 682 | Return |
---|
| 683 | End Subroutine ppm1d |
---|
| 684 | C |
---|
| 685 | C ************************************************************************** |
---|
| 686 | CCC Subroutine eno1d |
---|
| 687 | C ************************************************************************** |
---|
| 688 | C |
---|
| 689 | Subroutine eno1d(x,y,np,nc, |
---|
| 690 | & s_parent,s_child,ds_parent,ds_child) |
---|
| 691 | C |
---|
| 692 | CCC Description: |
---|
| 693 | CCC ---- p 163-164 Computational gasdynamics ---- |
---|
| 694 | CCC Subroutine to do a 1D interpolation |
---|
| 695 | CCC using piecewise polynomial ENO reconstruction technique |
---|
| 696 | CCC on a child grid (vector y) from its parent grid (vector x). |
---|
| 697 | CC Method: |
---|
| 698 | C |
---|
| 699 | C Declarations: |
---|
| 700 | C |
---|
| 701 | Implicit none |
---|
| 702 | C |
---|
| 703 | C Arguments |
---|
| 704 | Integer :: np,nc |
---|
| 705 | Real, Dimension(np) :: x |
---|
| 706 | Real, Dimension(nc) :: y |
---|
| 707 | Real, Dimension(:),Allocatable :: ytemp |
---|
| 708 | Real :: s_parent,s_child,ds_parent,ds_child |
---|
| 709 | C |
---|
| 710 | C Local scalars |
---|
| 711 | Integer :: i,coeffraf,locind_parent_left,locind_parent_last |
---|
| 712 | Integer :: ipos,pos |
---|
| 713 | Real :: ypos,xi |
---|
| 714 | integer :: i1,jj |
---|
| 715 | Real :: xpmin,cavg |
---|
| 716 | C |
---|
| 717 | Real, Dimension(3,np) :: dd,c |
---|
| 718 | Integer :: left |
---|
| 719 | C |
---|
| 720 | Real, DImension(1:np+1) :: xhalf |
---|
| 721 | Real, Dimension(:,:),Allocatable :: Xbar |
---|
| 722 | INTEGER :: diffmod |
---|
| 723 | C |
---|
| 724 | coeffraf = nint(ds_parent/ds_child) |
---|
| 725 | C |
---|
| 726 | If (coeffraf == 1) Then |
---|
| 727 | locind_parent_left = 1 + nint((s_child - s_parent)/ds_parent) |
---|
| 728 | y(1:nc) = x(locind_parent_left:locind_parent_left+nc-1) |
---|
| 729 | return |
---|
| 730 | End If |
---|
| 731 | |
---|
| 732 | diffmod = 0 |
---|
| 733 | IF (mod(coeffraf,2) == 0) diffmod = 1 |
---|
| 734 | C |
---|
| 735 | Allocate(ytemp(-2*coeffraf:nc+2*coeffraf)) |
---|
| 736 | ypos = s_child |
---|
| 737 | locind_parent_left = 1 + agrif_int((ypos - s_parent)/ds_parent) |
---|
| 738 | locind_parent_last = 1 + |
---|
| 739 | & agrif_ceiling((ypos +(nc - 1) *ds_child - |
---|
| 740 | & s_parent)/ds_parent) |
---|
| 741 | xpmin = s_parent + (locind_parent_left-1)*ds_parent |
---|
| 742 | i1 = 1+agrif_int((xpmin-s_child)/ds_child) |
---|
| 743 | C |
---|
| 744 | xhalf(np+1) = np + 0.5 |
---|
| 745 | Do i = 1,np |
---|
| 746 | xhalf(i) = i - 0.5 |
---|
| 747 | Enddo |
---|
| 748 | C |
---|
| 749 | C compute divided differences |
---|
| 750 | C |
---|
| 751 | dd(1,1:np) = x(1:np) |
---|
| 752 | dd(2,1:np-1) = 0.5*( dd(1,2:np) - dd(1,1:np-1) ) |
---|
| 753 | dd(3,1:np-2) = (1./3.)*( dd(2,2:np-1) - dd(2,1:np-2) ) |
---|
| 754 | C |
---|
| 755 | Allocate( Xbar( coeffraf,2 ) ) |
---|
| 756 | xi = 0.5 |
---|
| 757 | Do i = 1,coeffraf |
---|
| 758 | Xbar(i,1) = (i-1)*ds_child/ds_parent - xi |
---|
| 759 | Xbar(i,2) = i*ds_child/ds_parent - xi |
---|
| 760 | Enddo |
---|
| 761 | C |
---|
| 762 | ipos = i1 |
---|
| 763 | C |
---|
| 764 | DO i = locind_parent_left,locind_parent_last |
---|
| 765 | left = i |
---|
| 766 | do jj = 2,3 |
---|
| 767 | If(abs(dd(jj,left)) .gt. abs(dd(jj,left-1))) |
---|
| 768 | & left = left-1 |
---|
| 769 | enddo |
---|
| 770 | C |
---|
| 771 | C convert to Taylor series form |
---|
| 772 | C |
---|
| 773 | Call Taylor(i,xhalf(left:left+2),dd(1:3,left),c(1:3,i)) |
---|
| 774 | ENDDO |
---|
| 775 | C |
---|
| 776 | C evaluate the reconstruction on each cell |
---|
| 777 | C |
---|
| 778 | DO i = locind_parent_left,locind_parent_last |
---|
| 779 | C |
---|
| 780 | cavg = 0. |
---|
| 781 | pos = 1. |
---|
| 782 | C |
---|
| 783 | Do jj = ipos - coeffraf/2+diffmod,ipos + coeffraf/2 |
---|
| 784 | ytemp(jj) =(c(1,i)*(Xbar(pos,2)-Xbar(pos,1)) |
---|
| 785 | & +c(2,i)*(Xbar(pos,2)*Xbar(pos,2)- |
---|
| 786 | & Xbar(pos,1)*Xbar(pos,1)) |
---|
| 787 | & +c(3,i)*(Xbar(pos,2)*Xbar(pos,2)*Xbar(pos,2)- |
---|
| 788 | & Xbar(pos,1)*Xbar(pos,1)*Xbar(pos,1))) |
---|
| 789 | & *coeffraf |
---|
| 790 | cavg = cavg + ytemp(jj) |
---|
| 791 | pos = pos+1 |
---|
| 792 | Enddo |
---|
| 793 | ipos = ipos + coeffraf |
---|
| 794 | ENDDO |
---|
| 795 | C |
---|
| 796 | y(1:nc)=ytemp(1:nc) |
---|
| 797 | deallocate(ytemp,Xbar) |
---|
| 798 | C |
---|
| 799 | Return |
---|
| 800 | End Subroutine eno1d |
---|
| 801 | C |
---|
| 802 | C |
---|
| 803 | C ************************************************************************** |
---|
| 804 | CCC Subroutine taylor |
---|
| 805 | C ************************************************************************** |
---|
| 806 | C |
---|
| 807 | subroutine taylor(ind,xhalf,dd,c) |
---|
| 808 | C |
---|
| 809 | Integer :: ind |
---|
| 810 | real,dimension(3) :: dd,c |
---|
| 811 | real,dimension(0:3,0:3) :: d |
---|
| 812 | real,dimension(3) :: xhalf |
---|
| 813 | integer ::i,j |
---|
| 814 | C |
---|
| 815 | C |
---|
| 816 | d(0,0:3)=1. |
---|
| 817 | do i = 1,3 |
---|
| 818 | d(i,0)=(ind-xhalf(i))*d(i-1,0) |
---|
| 819 | enddo |
---|
| 820 | C |
---|
| 821 | do i = 1,3 |
---|
| 822 | do j = 1,3-i |
---|
| 823 | d(i,j) = d(i,j-1) + (ind-xhalf(i+j))*d(i-1,j) |
---|
| 824 | enddo |
---|
| 825 | enddo |
---|
| 826 | C |
---|
| 827 | do j = 1,3 |
---|
| 828 | c(j) = 0. |
---|
| 829 | do i=0,3-j |
---|
| 830 | c(j) = c(j) + d(i,j)*dd(i+j) |
---|
| 831 | enddo |
---|
| 832 | enddo |
---|
| 833 | C |
---|
| 834 | end subroutine taylor |
---|
| 835 | |
---|
| 836 | |
---|
| 837 | REAL FUNCTION vanleer(tab) |
---|
| 838 | REAL, DIMENSION(3) :: tab |
---|
| 839 | real res1 |
---|
| 840 | real p1,p2,p3 |
---|
| 841 | |
---|
| 842 | p1=(tab(3)-tab(1))/2. |
---|
| 843 | p2=2.*(tab(2)-tab(1)) |
---|
| 844 | p3=2.*(tab(3)-tab(2)) |
---|
| 845 | |
---|
| 846 | if ((p1>0.).AND.(p2>0.).AND.(p3>0)) then |
---|
| 847 | res1=minval((/p1,p2,p3/)) |
---|
| 848 | elseif ((p1<0.).AND.(p2<0.).AND.(p3<0)) then |
---|
| 849 | res1=maxval((/p1,p2,p3/)) |
---|
| 850 | else |
---|
| 851 | res1=0. |
---|
| 852 | endif |
---|
| 853 | |
---|
| 854 | vanleer = res1 |
---|
| 855 | |
---|
| 856 | |
---|
| 857 | END FUNCTION vanleer |
---|
| 858 | |
---|
| 859 | C |
---|
| 860 | End Module Agrif_Interpbasic |
---|