2D AMRCLAW
bufnst2.f
Go to the documentation of this file.
1 c :::::::::::::::::::::::::: BUFNST :::::::::::::::::::::::::::::::::::
4 c :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
5 c
6 c -------------------------------------------------------------
7 c
8  subroutine bufnst2(nvar,naux,numbad,lcheck,lbase)
9 c
10  use amr_module
11  implicit double precision (a-h,o-z)
12 
13 
14  logical vtime
15  integer listgrids(numgrids(lcheck))
16  integer omp_get_thread_num, omp_get_max_threads
17  integer mythread/0/, maxthreads/1/
18  data vtime/.false./
19 
20 c this indexing is for amrflags array, in flag2refine from 1-mbuff:mx+mbuff
21 c but here is from 1:mibuff
22  iadd(i,j) = locamrflags + i-1+ mibuff*(j-1)
23 c
24 
25 c
26 c
27 c
28 !$ maxthreads = omp_get_max_threads()
29 c call prepgrids(listgrids,numgrids(lcheck),lcheck)
30 
31  numpro = 0
32  numbad = 0
33  time = rnode(timemult,lstart(lcheck))
34  dx = hxposs(lcheck)
35  dy = hyposs(lcheck)
36 
37 c mptr = lstart(lcheck)
38  levst = liststart(lcheck)
39 c41 continue
40 !$OMP PARALLEL DO REDUCTION(+:numbad)
41 !$OMP& PRIVATE(jg,mptr,ilo,ihi,jlo,jhi,nx,ny,mitot,mjtot),
42 !$OMP& PRIVATE(mibuff,mjbuff,locamrflags,mbuff,ibytesPerDP),
43 !$OMP& PRIVATE(loctmp,locbig,j,i,numpro2,numflagged),
44 !$OMP& PRIVATE(locdomflags,locdom2),
45 !$OMP& SHARED(numgrids, listgrids,nghost,flag_richardson),
46 !$OMP& SHARED(nvar,eprint,maxthreads,node,rnode,lbase,ibuff),
47 !$OMP& SHARED(alloc,lcheck,numpro,mxnest,dx,dy,time),
48 !$OMP& SHARED(levSt,listOfGrids),
49 !$OMP& DEFAULT(none),
50 !$OMP& SCHEDULE (DYNAMIC,1)
51  do jg = 1, numgrids(lcheck)
52 c mptr = listgrids(jg)
53  mptr = listofgrids(levst+jg-1)
54  ilo = node(ndilo,mptr)
55  ihi = node(ndihi,mptr)
56  jlo = node(ndjlo,mptr)
57  jhi = node(ndjhi,mptr)
58  nx = node(ndihi,mptr) - node(ndilo,mptr) + 1
59  ny = node(ndjhi,mptr) - node(ndjlo,mptr) + 1
60  mitot = nx + 2*nghost
61  mjtot = ny + 2*nghost
62  mbuff = max(nghost,ibuff+1)
63  mibuff = nx + 2*mbuff
64  mjbuff = ny + 2*mbuff
65  locamrflags = node(storeflags,mptr)
66 
67 c ### is richardson used, add those flags to flags computed by spatial gradients
68 c ### (or whatever user-defined criteria used). Even if nothing else used,
69 c ### put flags into locamrflag array.
70 !-- if (flag_richardson) then
71 !-- loctmp = node(store2, mptr)
72 !-- call addflags(alloc(locamrflags),mibuff,mjbuff,
73 !-- . alloc(loctmp),nvar,mitot,mjtot,mptr)
74 !-- endif
75 
76 c still need to reclaim error est space from spest.f
77 c which was saved for possible errest reuse
78  if (flag_richardson) then
79  locbig = node(tempptr,mptr)
80  call reclam(locbig,mitot*mjtot*nvar)
81  endif
82 c
83  if (eprint .and. maxthreads .eq. 1) then ! otherwise race for printing
84  write(outunit,*)" flagged points before projec2",
85  . lcheck," grid ",mptr, " (no buff cells)"
86  do j = mjbuff-mbuff, mbuff+1, -1
87  write(outunit,100)(int(alloc(iadd(i,j))),
88  & i=mbuff+1,mibuff-mbuff)
89  enddo
90  endif
91 
92 c ## new call to flag regions: check if cells must be refined, or exceed
93 c ## maximum refinement level for that region. used to be included with
94 c ## flag2refine. moved here to include flags from richardson too.
95  call flagregions2(nx,ny,mbuff,rnode(cornxlo,mptr),
96  1 rnode(cornylo,mptr),dx,dy,lcheck,time,
97  2 alloc(locamrflags),goodpt,badpt)
98 
99 c for this version project to each grid separately, no giant iflags
100  if (lcheck+2 .le. mxnest) then
101  numpro2 = 0
102  call projec2(lcheck,numpro2,alloc(locamrflags),
103  . ilo,ihi,jlo,jhi,mbuff)
104 c numpro = numpro + numpro2 not used for now. would need critical section for numpro
105  endif
106 
107  if (eprint .and. maxthreads .eq. 1) then
108  write(outunit,*)" flagged points before buffering on level",
109  . lcheck," grid ",mptr, " (no buff cells)"
110  do 47 j = mjbuff-mbuff, mbuff+1, -1
111  write(outunit,100)(int(alloc(iadd(i,j))),
112  & i=mbuff+1,mibuff-mbuff)
113  100 format(80i1)
114  47 continue
115  endif
116 c
117  if (eprint .and. maxthreads .eq. 1) then
118  write(outunit,*)" flagged points after projecting to level",
119  . lcheck, " grid ",mptr,
120  . "(withOUT buff cells)"
121 c . "(with buff cells)"
122 c buffer zone (wider ghost cell region) now set after buffering
123 c so loop over larger span of indices
124  do 49 j = mjbuff-mbuff, mbuff+1, -1
125  write(outunit,100)(int(alloc(iadd(i,j))),
126  . i=mbuff+1,mibuff-mbuff)
127  49 continue
128  endif
129 
130 c
131 c diffuse flagged points in all 4 directions to make buffer zones
132 c note that this code flags with a same value as true flagged
133 c points, not a different number.
134  call shiftset2(alloc(locamrflags),ilo,ihi,jlo,jhi,mbuff)
135 
136  if (eprint .and. maxthreads .eq. 1) then
137  write(outunit,*)" flagged points after buffering on level",
138  . lcheck," grid ",mptr," (WITHOUT buff cells))"
139  do 51 j = mjbuff-mbuff, mbuff+1, -1
140  write(outunit,100)(int(alloc(iadd(i,j))),
141  . i=mbuff+1, mibuff-mbuff)
142  51 continue
143  endif
144 c
145 c count up
146 c
147  numflagged = 0
148  do 82 j = 1, mjbuff
149  do 82 i = 1, mibuff
150  if (alloc(iadd(i,j)) .ne. goodpt) then
151  numflagged=numflagged + 1
152  endif
153  82 continue
154  ! TODO: this is broken?
155 c write(outunit,116) numflagged, mptr
156  116 format(i5,' points flagged on level ',i4,' grid ',i4)
157  node(numflags,mptr) = numflagged
158 !$OMP CRITICAL(nb)
159  numbad = numbad + numflagged
160 !$OMP END CRITICAL(nb)
161 
162 c ADD WORK THAT USED TO BE IN FLGLVL2 FOR MORE PARALLEL WORK WITHOUT JOINING AND SPAWNING AGAIN
163 c in effect this is domgrid, but since variables already defined just need half of it, inserted here
164  ibytesperdp = 8
165 c bad names, for historical reasons. they are both smae size now
166  locdomflags = igetsp( (mibuff*mjbuff)/ibytesperdp+1)
167  locdom2 = igetsp( (mibuff*mjbuff)/ibytesperdp+1)
168 
169  node(domflags_base,mptr) = locdomflags
170  node(domflags2,mptr) = locdom2
171  call setdomflags(mptr,alloc(locdomflags),ilo,ihi,jlo,jhi,
172  . mbuff,lbase,lcheck,mibuff,mjbuff)
173 
174 
175  end do
176 !$OMP END PARALLEL DO
177 c mptr = node(levelptr,mptr)
178 c if (mptr .ne. 0) go to 41
179 
180  if (verbosity_regrid .ge. lcheck) then
181  write(outunit,*)" total flagged points counted on level ",
182  . lcheck," is ",numbad
183  write(outunit,*)"this may include double counting buffer cells",
184  & " on multiple grids"
185  endif
186 
187  return
188  end
subroutine flagregions2(mx, my, mbuff, xlower, ylower, dx, dy, level, t, amrflags, DONTFLAG, DOFLAG)
Modify array of flagged points to respect minlevels and maxlevels specified by regions.
function igetsp(nwords)
Definition: igetsp.f:4
subroutine reclam(index, nwords)
Definition: reclam.f:4
subroutine bufnst2(nvar, naux, numbad, lcheck, lbase)
After error estimation, need to tag the cell for refinement, buffer the tags, take care of level nest...
Definition: bufnst2.f:8
subroutine shiftset2(rectflags, ilo, ihi, jlo, jhi, mbuff)
For an input grid, flag cells near the previously flagged cells for creating buffer zone...
Definition: shiftset2.f:25
integer pure function iadd(ivar, i, j)
Definition: intfil.f90:293
subroutine projec2(level, numpro, rectflags, ilo, ihi, jlo, jhi, mbuff)
This subroutine projects all level level+1 and level+2 grids to a level level grid and flag the cells...
Definition: projec2.f:41
subroutine setdomflags(mptr, igridflags, ilo, ihi, jlo, jhi, mbuff, lbase, lcheck, mibuff, mjbuff)
Definition: setdomflags.f:4