2D AMRCLAW
projec2.f
Go to the documentation of this file.
1 c ::::::::::::::::::::::: PROJEC2 ::::::::::::::::::::::::::::::
2 ! For all newly created fine grids, project area onto a coarser
3 ! grid 2 levels down. Used to recreate grids 1 level down, and
4 ! insure proper level nesting.
5 !
6 ! on entry, all coarse grids have already had error estimated, so
7 ! add bad flags. count number of 'added' flags only.
8 !
9 !
39 c :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
40 c
41  subroutine projec2(level,numpro,rectflags,ilo,ihi,jlo,jhi,mbuff)
42 
43  use amr_module
44  implicit double precision (a-h,o-z)
45  dimension rectflags(ilo-mbuff:ihi+mbuff,jlo-mbuff:jhi+mbuff)
46  logical borderx, bordery
47  integer ist(3),iend(3),jst(3),jend(3),ishift(3),jshift(3)
48 
49  levpro = level + 2
50  lrat2x = intratx(level)*intratx(level+1)
51  lrat2y = intraty(level)*intraty(level+1)
52 
53 ! local variables:
54 ! mkid = grid doing the projecting
55  mkid = newstl(levpro)
56  10 if (mkid .eq. 0) go to 90
57  ikidlo = node(ndilo,mkid)
58  jkidlo = node(ndjlo,mkid)
59  ikidhi = node(ndihi,mkid)
60  jkidhi = node(ndjhi,mkid)
61 c
62 c project entire region of fine grids onto rectflag array if intersects
63 c possibly take care of buffering.
64 c adjust since grid descriptor (integer indices) is 0 based,
65 c do not projec the buffer region, only interior needs it
66 c since buffering will take care of rest (unless ibuff=0-see below)
67 c
68 c redo formulas using approach of nestck/baseCheck, simplified to 2 levels
69  istc = ikidlo/intratx(level+1) - 1 ! one level down
70  istc = istc/intratx(level) - 1 ! project to second level coords
71  jstc = jkidlo/intraty(level+1) - 1
72  jstc = jstc/intraty(level) - 1
73  iendc = ikidhi/intratx(level+1) + 1
74  iendc = iendc/intratx(level) + 1
75  jendc = jkidhi/intraty(level+1) + 1
76  jendc = jendc/intraty(level) + 1
77 
78 c if coarse grid not near edge of domain then periodicity wont affect it
79  borderx = (istc .le. 0 .or. iendc .ge. iregsz(level)-1) ! subtract 1 to get last cell index
80  bordery = (jstc .le. 0 .or. jendc .ge. jregsz(level)-1) ! since i/jregsz is num cells
81 
82 c
83 c take care of indices outside actual domain, in non-periodic case first
84  if (.not. (xperdom .and. borderx) .and.
85  . .not. (yperdom .and. bordery)) then
86  istc = max(istc,0)
87  jstc = max(jstc,0)
88  iendc = min(iendc,iregsz(level))
89  jendc = min(jendc,jregsz(level))
90 
91 c include mbuff in intersection test here since is ok in new alg. to project to buffer region
92  ixlo = max(istc, ilo-mbuff)
93  ixhi = min(iendc,ihi+mbuff)
94  jxlo = max(jstc, jlo-mbuff)
95  jxhi = min(jendc,jhi+mbuff)
96 
97 c test if coarsened grid mkid intersects with this grids rectflags
98  ! has not intersection
99  if (.not.((ixlo .le. ixhi) .and. (jxlo .le. jxhi))) go to 80
100 c
101  ! has intersection
102  do 60 j = jxlo, jxhi
103  do 60 i = ixlo, ixhi
104  if (rectflags(i,j) .eq. goodpt) then
105  rectflags(i,j) = badpro
106  numpro = numpro + 1
107  if (pprint) write(outunit,101) i,j,mkid
108  101 format(' pt.',2i5,' of grid ',i5,' projected' )
109  endif
110  60 continue
111  go to 80 ! done with projected this fine grid in non-periodic case
112  endif
113 
114 c
115 c periodic case. compute indics on coarsened level to find grids to project to
116  call setindices(ist,iend,jst,jend,iclo,ichi,jclo,jhci,
117  . ishift,jshift,level)
118 
119 c compare all regions of coarsened patch with one lbase grid at a time
120  do 25 i = 1, 3
121  i1 = max(istc, ist(i))
122  i2 = min(iendc, iend(i))
123  do 25 j = 1, 3
124  j1 = max(jstc, jst(j))
125  j2 = min(jendc, jend(j))
126 
127  if (.not. ((i1 .le. i2) .and. (j1 .le. j2))) go to 25
128 c
129 c patch (possibly periodically wrapped) not empty.
130 c see if intersects base grid. wrap coords for periodicity
131  i1 = i1 + ishift(i)
132  i2 = i2 + ishift(i)
133  j1 = j1 + jshift(j)
134  j2 = j2 + jshift(j)
135 
136  ixlo = max(i1,ilo-mbuff)
137  ixhi = min(i2,ihi+mbuff)
138  jxlo = max(j1,jlo-mbuff)
139  jxhi = min(j2,jhi+mbuff)
140 
141  if (.not.((ixlo.le.ixhi) .and. (jxlo.le.jxhi))) go to 25
142 
143  do jx = jxlo, jxhi
144  do ix = ixlo, ixhi
145 c project flagged point in intersected regions
146  if (rectflags(ix,jx) .eq. goodpt) then
147  rectflags(ix,jx) = badpro ! i,j already coarse grid indices
148  numpro = numpro + 1
149  if (pprint) write(outunit,101) ix,jx,mkid
150  endif
151  end do
152  end do
153 
154  25 continue
155  go to 80 ! down with simple periodic case
156 c
157 c repeat above procedure for wrapped area if nec. if ibuff > 0
158 c this will be caught in shiftset flagging
159 c DID NOT MODIFY THIS SPHEREDOM BLOCK WHEN FIXING OTHER BUGS. NEED TO LOOK AT IT
160  if (spheredom .and. ibuff .eq. 0) then
161  jstc = jkidlo/lrat2y
162  jendc = jkidhi/lrat2y
163  if (jstc .eq. 0) then
164  iwrap1 = iregsz(level) - iendc - 1
165  iwrap2 = iregsz(level) - istc - 1
166 c do 61 i = iwrap1+1, iwrap2+1
167  do 61 i = iwrap1, iwrap2 !changing this WITHOUT CHECKING, AS ABOVE. STILL NEED TO CHECK***
168  if (rectflags(i,1) .eq. goodpt) then
169  rectflags(i,1) = badpro ! only need to flag 1 wrapped buffer cell
170  numpro = numpro + 1
171  if (pprint) write(outunit,101) i,1,mkid
172  endif
173  61 continue
174 
175  endif
176  if (jendc .eq. jsize-1) then
177  iwrap1 = iregsz(level) - iendc - 1
178  iwrap2 = iregsz(level) - istc - 1
179 c do 62 i = iwrap1+1, iwrap2+1
180  do 62 i = iwrap1, iwrap2 !CHANGING W/O CHECKING
181  if (rectflags(i,jsize-1) .eq. goodpt) then
182  rectflags(i,jsize-1) = badpro ! only need to flag 1 wrapped buffer cell
183  numpro = numpro + 1
184  if (pprint) write(outunit,101) i,j,mkid
185  endif
186  62 continue
187  endif
188  endif
189 c
190 c done with gridpt. loop for grid mkid.
191 c
192  80 mkid = node(levelptr, mkid)
193  go to 10
194 c
195  90 if (pprint) then
196  write(outunit,102) numpro,level
197  102 format(i9,' more pts. projected to level ',i5)
198 
199  write(outunit,103) level
200  103 format(/,' from projec: flagged pts. (incl. buffer zone)',
201  & ' at level ',i4,':')
202 
203  do 110 j = jhi+mbuff, jlo-mbuff, -1
204  write(outunit,104)(int(rectflags(i,j)),i=ilo-mbuff,ihi+mbuff)
205 104 format(80i1)
206  110 continue
207  endif
208 c
209  99 return
210  end
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 setindices(ist, iend, jst, jend, ilo, ihi, jlo, jhi, ishift, jshift, level)
Definition: setIndices.f:4