|
| 1 | + |
| 2 | +! gfortran -cpp -O3 -flto ex_7.f90 -o ex_7 |
| 3 | +! ./ex_7 |
| 4 | + |
| 5 | +! Same as ex_1, but with xdir reversed so that xpos, xnew |
| 6 | +! become more -ve with increasing array indices. |
| 7 | +! |
| 8 | + |
| 9 | +# include "../src/ppr_1d.f90" |
| 10 | + |
| 11 | + program ex |
| 12 | + |
| 13 | + use ppr_1d |
| 14 | + |
| 15 | + implicit none |
| 16 | + |
| 17 | + integer, parameter :: npos = 31 ! no. edge (old grid) |
| 18 | + integer, parameter :: ntmp = 23 ! no. edge (new grid) |
| 19 | + integer, parameter :: nvar = 1 ! no. variables to remap |
| 20 | + integer, parameter :: ndof = 1 ! no. FV DoF per cell |
| 21 | + integer :: ipos |
| 22 | + |
| 23 | + !------------------------------ position of cell edges ! |
| 24 | + real*8 :: xpos(npos),xtmp(ntmp) |
| 25 | + real*8 :: xmid |
| 26 | + |
| 27 | + !-------------------------------- finite-volume arrays ! |
| 28 | + |
| 29 | + ! Arrays represent a "block" of finite-volume tracers |
| 30 | + ! to remap. The 1st dim. is the no. of DoF per cell, |
| 31 | + ! NDOF=1 is a standard finite-volume scheme where the |
| 32 | + ! data is specified as cell means. NDOF>1 is reserved |
| 33 | + ! for future use with DG-style schemes. NVAR is the |
| 34 | + ! number of tracers to remap. Processing tracers in a |
| 35 | + ! batch is typically more efficient than one-by-one. |
| 36 | + ! The last dim. is the no. cells (layers) in the grid. |
| 37 | + |
| 38 | + real*8 :: init(ndof,nvar,npos-1) |
| 39 | + real*8 :: ftmp(ndof,nvar,ntmp-1) |
| 40 | + real*8 :: fdat(ndof,nvar,npos-1) |
| 41 | + |
| 42 | + !------------------------------ method data-structures ! |
| 43 | + type(rmap_work) :: work |
| 44 | + type(rmap_opts) :: opts |
| 45 | + type(rcon_ends) :: bc_l(nvar) |
| 46 | + type(rcon_ends) :: bc_r(nvar) |
| 47 | + |
| 48 | + !------------------------------ define a simple domain ! |
| 49 | + |
| 50 | + call linspace(0.d0,1.d0,npos,xpos) |
| 51 | + call linspace(0.d0,1.d0,ntmp,xtmp) |
| 52 | + |
| 53 | + xpos = xpos * -1.d0 |
| 54 | + xtmp = xtmp * -1.d0 |
| 55 | + |
| 56 | + !------------------------------ setup some simple data ! |
| 57 | + |
| 58 | + do ipos = +1, npos-1 |
| 59 | + |
| 60 | + xmid = xpos(ipos+0) * 0.5d+0 & |
| 61 | + & + xpos(ipos+1) * 0.5d+0 |
| 62 | + |
| 63 | + init(1,1,ipos) = xmid ** 2 |
| 64 | + |
| 65 | + end do |
| 66 | + |
| 67 | + !------------------------------ specify method options ! |
| 68 | + |
| 69 | + opts%edge_meth = p3e_method ! 3rd-order edge interp. |
| 70 | + opts%cell_meth = ppm_method ! PPM method in cells |
| 71 | + opts%cell_lims = null_limit ! no slope limiter |
| 72 | + |
| 73 | + !------------------------------ set BC.'s at endpoints ! |
| 74 | + |
| 75 | + bc_l%bcopt = bcon_loose ! "loose" = extrapolate |
| 76 | + bc_r%bcopt = bcon_loose |
| 77 | + |
| 78 | + !------------------------------ init. method workspace ! |
| 79 | + |
| 80 | + call work%init(npos,nvar,opts) |
| 81 | + |
| 82 | + !------------------------------ re-map back-and-forth: ! |
| 83 | + |
| 84 | + fdat = init |
| 85 | + |
| 86 | + do ipos = +1, +1000 |
| 87 | + |
| 88 | + !------------------------------ re-map from dat-to-tmp ! |
| 89 | + |
| 90 | + call rmap1d(npos,ntmp,nvar,ndof, & |
| 91 | + & xpos,xtmp,fdat,ftmp, & |
| 92 | + & bc_l,bc_r,work,opts) |
| 93 | + |
| 94 | + !------------------------------ re-map from tmp-to-dat ! |
| 95 | + |
| 96 | + call rmap1d(ntmp,npos,nvar,ndof, & |
| 97 | + & xtmp,xpos,ftmp,fdat, & |
| 98 | + & bc_l,bc_r,work,opts) |
| 99 | + |
| 100 | + end do |
| 101 | + |
| 102 | + !------------------------------ clear method workspace ! |
| 103 | + |
| 104 | + call work%free() |
| 105 | + |
| 106 | + !------------------------------ dump results to stdout ! |
| 107 | + |
| 108 | + print*,"Cell data: [INIT] [RMAP] " |
| 109 | + |
| 110 | + do ipos = +1, npos-1 |
| 111 | + |
| 112 | + print *, init(1,1,ipos) & |
| 113 | + & , fdat(1,1,ipos) |
| 114 | + |
| 115 | + end do |
| 116 | + |
| 117 | + print*,"Conservation defect := " & |
| 118 | + & , sum(init) - sum(fdat) |
| 119 | + |
| 120 | + end program |
| 121 | + |
| 122 | + |
| 123 | + |
0 commit comments