2D AMRCLAW
colate2.f
Go to the documentation of this file.
1 c
7 c
8 c -----------------------------------------------------------
9 c
10  subroutine colate2 (badpts, len, lcheck, nUniquePts, lbase)
11 c
12  use amr_module
13  implicit double precision (a-h,o-z)
14  dimension badpts(2,len)
15  dimension ist(3), iend(3), jst(3), jend(3), ishift(3), jshift(3)
16  logical db/.false./
17  integer*8 largestIntEquiv
18 
19 c
20 c index for flag array now based on integer index space, not 1:mibuff,1:mjbuff
21 c but if grid extends outside domain, not supposed to have flagged points
22  iadd(i,j) = locamrflags + i-(ilo-mbuff) + mibuff*(j-(jlo-mbuff))
23 c
24 c
25 c *************************************************************
26 c
27 c colate2 = takes each grids flagged points at level lcheck
28 c and puts their (i,j) cell centered
29 c indices into the badpts array.
30 c To insure proper nesting, must get rid of flagged points
31 c that dont fit into properly nested domain. Grids
32 c with flagged points include buffered region (size mbuff)now.
33 c THIS NEW VERSION may have duplicate points. need to sort
34 c and remove when colating.
35 c
36 c if checking flagged pt for nesting is expensive, might consider not doing it
37 c and revising projec2 instead. if new fine grid not nested, then go through
38 c flagged points and throw out. But presumably many grids will make it through
39 c without having to check all points.
40 c
41 c *************************************************************
42 c
43 c domain flags corresponding to each grid have already been set up.
44 c colate will check that flagged points nested or throw away
45 c
46  mbuff = max(nghost,ibuff+1) ! new way of expanding grid to do buffering in place
47  index = 0 ! for putting into badpts array
48 
49 
50  mptr = lstart(lcheck)
51  10 continue
52 c write(outunit,*)" colating flags on grid ",mptr
53 
54 c handle each of 4 sides (in 2D)
55 c set tags to negative val. reset to positive if they have a home
56  ilo = node(ndilo,mptr)
57  ihi = node(ndihi,mptr)
58  jlo = node(ndjlo,mptr)
59  jhi = node(ndjhi,mptr)
60  nx = ihi - ilo + 1
61  ny = jhi - jlo + 1
62  mibuff = nx + 2 *mbuff
63  mjbuff = ny + 2 *mbuff
64 
65 
66  locamrflags = node(storeflags,mptr)
67  if (node(numflags,mptr) .eq. 0) go to 70 !simple bypass if no tags
68 
69 
70 c
71 c more conservative alg. uses entire buffer in flagging
72  jmin = jlo-mbuff
73  jmax = jhi+mbuff
74  imin = ilo-mbuff
75  imax = ihi+mbuff
76  if (.not. xperdom) then
77  imin = max(imin,0)
78  imax = min(ihi+mbuff,iregsz(lcheck)-1)
79  endif
80  if (.not. yperdom) then
81  jmin = max(jmin,0)
82  jmax = min(jhi+mbuff,jregsz(lcheck)-1)
83  endif
84 c
85 c but to match old alg. use only this one. (not exactly the same? since
86 c old alg. used one level?)
87 
88 c jmin = max(jlo-mbuff,0)
89 c jmax = min(jhi+mbuff,jregsz(lcheck)-1)
90 c imin = max(ilo-mbuff,0)
91 c imax = min(ihi+mbuff,iregsz(lcheck)-1)
92 
93 c do we still need setPhysBndry????
94 c call setPhysBndry(alloc(locamrflags),ilo,ihi,jlo,jhi,
95 c . mbuff,lcheck)
96 c pass loop bounds to keep consistent
97 c need this next subr. to do integer indexing for iflags
98 c
99  call flagcheck(alloc(locamrflags),ilo,ihi,jlo,jhi,mbuff,
100  . alloc(node(domflags2,mptr)),
101  . imin,imax,jmin,jmax,mptr)
102 
103 
104  do 60 j = jmin, jmax
105  do 60 i = imin, imax
106 
107 c neg means no home was found. throw out
108  if (alloc(iadd(i,j)) .lt. 0) then
109  write(outunit,939) i,j
110  939 format("NOT NESTED: ignoring point ",2i5)
111  write(*,*)" still have neg points"
112  go to 60
113  endif
114  if (alloc(iadd(i,j)) .eq. goodpt) go to 60
115 c
116 c got a legit flagged point, bag it.
117 c
118  index = index + 1
119 c WARNING: to match orig program note we ADD .5, not subtract. old program used 1 based indexing
120 c for grid flagging array. we are using 0 based, so need to add to match previous
121 c grid fitting (dont want to change all routines downstream)
122 c
123 c for periodic domains, if flagged pt in buffer zone outside domain
124 c wrap it periodically back in before putting on list
125  iwrap = i
126  if (xperdom) then
127  if (i .lt. 0) iwrap = i + iregsz(lcheck)
128  if (i .ge. iregsz(lcheck)) iwrap = i - iregsz(lcheck)
129  endif
130  jwrap = j
131  if (yperdom) then
132  if (j .lt. 0) jwrap = j + jregsz(lcheck)
133  if (j .ge. jregsz(lcheck)) jwrap = j - jregsz(lcheck)
134  endif
135 c adding .5 to make it cell centered integer coords
136 c note that previous code subtracted .5 since it used 1 based indexing
137  badpts(1,index) = dble(iwrap)+.5 ! in case periodic, put flagged buffer pt
138  badpts(2,index) = dble(jwrap)+.5 ! in badpts in wrapped coords
139  if (db) write(outunit,101) badpts(1,index), badpts(2,index)
140  101 format(2f6.1)
141 
142  60 continue
143 
144  65 continue
145  66 continue
146 
147 c
148  70 continue
149 
150 c done colating - safe to reclam
151  call reclam(locamrflags,mibuff*mjbuff)
152 
153  ibytesperdp = 8
154  iflagsize = (mibuff*mjbuff)/ibytesperdp+1
155  call reclam(node(domflags_base,mptr),iflagsize)
156  call reclam(node(domflags2,mptr),iflagsize)
157 
158 c
159  mptr = node(levelptr, mptr)
160  if (mptr .ne. 0) go to 10
161 
162 
163  npts = index
164  if (gprint) then
165  write(outunit,100) npts, lcheck,len
166  100 format( i9,' flagged points initially colated on level ',i4,
167  . " badpts len = ",i10)
168  endif
169 c
170 c colate flagged points into single integer array for quicksorting
171 c
172 c sorting uses one dimensional packing of 2D indices
173 c check if domain will fit in integer*4.
174 c if not, just leave the duplicate, but rememer that efficiency
175 c of grids won't be correct (since divide by number of flaged pts in grid)
176 c If necessary, do whole process in integer*8 - then will have enough
177 c room, but will have to convert quicksort routine and drivesort
178 c the variable largestIntEquiv already declared integer*8 above.
179  largestintequiv = iregsz(lcheck)+mbuff +
180  . (iregsz(lcheck)+2*mbuff)*(jregsz(lcheck)+mbuff)
181  largestsingle = 2**30
182  if (largestintequiv .le. 0) then
183 c ## sorting alg will have integer overflow
184 c ## just use all flagged points in making grids
185 c ## this means "efficiency" count will be incorrect for
186 c ## this and higher levels
187  nuniquepts = npts ! bad name - they are not unique
188  else
189  call drivesort(npts,badpts,lcheck,nuniquepts,mbuff)
190  endif
191 
192 
193  99 return
194  end
subroutine colate2(badpts, len, lcheck, nUniquePts, lbase)
Takes flagged points on all grids on level lcheck and pack their (i,j) cell centered indices into the...
Definition: colate2.f:11
subroutine reclam(index, nwords)
Definition: reclam.f:5
subroutine flagcheck(rectflags, ilo, ihi, jlo, jhi, mbuff, iflags,
Check if every cell in grid mptr is properly nested in base level grids (base level in current refine...
Definition: flagcheck.f:10
integer, dimension(maxlv) iregsz
Definition: amr_module.f90:198
integer, parameter ndihi
global i index of right border of this grid
Definition: amr_module.f90:111
integer, dimension(maxlv) jregsz
Definition: amr_module.f90:198
integer, dimension(nsize, maxgr) node
Definition: amr_module.f90:198
logical gprint
Definition: amr_module.f90:297
real(kind=8), parameter goodpt
Definition: amr_module.f90:163
integer pure function iadd(ivar, i, j)
Definition: intfil.f90:294
integer, parameter domflags_base
domain flags, indexed within base level (lbase) index space
Definition: amr_module.f90:129
integer, parameter storeflags
pointer to the address of memory storing flags for refinement on this grid
Definition: amr_module.f90:123
logical yperdom
Definition: amr_module.f90:230
integer, parameter domflags2
domain flags, indexed within level-of-this-grid level index space
Definition: amr_module.f90:132
integer, parameter ndilo
global i index of left border of this grid
Definition: amr_module.f90:108
integer, parameter ndjlo
global j index of lower border of this grid
Definition: amr_module.f90:114
integer, dimension(maxlv) lstart
Definition: amr_module.f90:198
integer ibuff
Definition: amr_module.f90:198
integer, parameter outunit
Definition: amr_module.f90:290
subroutine drivesort(npts, badpts, level, index, mbuff)
Sort 2D points (stored in badpts) based on their equivalent integer value (based on their x...
Definition: drivesort.f:8
integer, parameter ndjhi
global j index of upper border of this grid
Definition: amr_module.f90:117
logical xperdom
Definition: amr_module.f90:230
integer, parameter levelptr
node number (index) of next grid on the same level
Definition: amr_module.f90:35
integer nghost
Definition: amr_module.f90:232
The module contains the definition of a "node descriptor" as well as other global variables used duri...
Definition: amr_module.f90:21
integer, parameter numflags
number of flagged cells on this grid
Definition: amr_module.f90:126
real(kind=8), dimension(:), allocatable alloc
Definition: amr_module.f90:218