Skip to content

Commit 4e2aa43

Browse files
committed
1.1.2 updates: support *.F90 vs *.f90
1 parent 435b8b6 commit 4e2aa43

File tree

3 files changed

+250
-0
lines changed

3 files changed

+250
-0
lines changed

example/ex_1.F90

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
2+
! gfortran -O3 -flto ex_1.F90 -o ex_1
3+
! ./ex_1
4+
5+
! Same as ex_1.f90, but with a capitalised *.F90 to enable
6+
! the preprocessor directives without the -cpp flag.
7+
!
8+
9+
# include "../src/ppr_1d.F90" ! note: *.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+
!------------------------------ setup some simple data !
54+
55+
do ipos = +1, npos-1
56+
57+
xmid = xpos(ipos+0) * 0.5d+0 &
58+
& + xpos(ipos+1) * 0.5d+0
59+
60+
init(1,1,ipos) = xmid ** 2
61+
62+
end do
63+
64+
!------------------------------ specify method options !
65+
66+
opts%edge_meth = p3e_method ! 3rd-order edge interp.
67+
opts%cell_meth = ppm_method ! PPM method in cells
68+
opts%cell_lims = null_limit ! no slope limiter
69+
70+
!------------------------------ set BC.'s at endpoints !
71+
72+
bc_l%bcopt = bcon_loose ! "loose" = extrapolate
73+
bc_r%bcopt = bcon_loose
74+
75+
!------------------------------ init. method workspace !
76+
77+
call work%init(npos,nvar,opts)
78+
79+
!------------------------------ re-map back-and-forth: !
80+
81+
fdat = init
82+
83+
do ipos = +1, +1000
84+
85+
!------------------------------ re-map from dat-to-tmp !
86+
87+
call rmap1d(npos,ntmp,nvar,ndof, &
88+
& xpos,xtmp,fdat,ftmp, &
89+
& bc_l,bc_r,work,opts)
90+
91+
!------------------------------ re-map from tmp-to-dat !
92+
93+
call rmap1d(ntmp,npos,nvar,ndof, &
94+
& xtmp,xpos,ftmp,fdat, &
95+
& bc_l,bc_r,work,opts)
96+
97+
end do
98+
99+
!------------------------------ clear method workspace !
100+
101+
call work%free()
102+
103+
!------------------------------ dump results to stdout !
104+
105+
print*,"Cell data: [INIT] [RMAP] "
106+
107+
do ipos = +1, npos-1
108+
109+
print *, init(1,1,ipos) &
110+
& , fdat(1,1,ipos)
111+
112+
end do
113+
114+
print*,"Conservation defect := " &
115+
& , sum(init) - sum(fdat)
116+
117+
end program
118+
119+
120+

example/ex_7.f90

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
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+

src/ppr_1d.F90

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
2+
!-- an alternative to buidling w the -cpp compile flag
3+
4+
# include "ppr_1d.f90"
5+
6+
7+

0 commit comments

Comments
 (0)