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