2D AMRCLAW
setdomflags.f
Go to the documentation of this file.
1 c
2 c -----------------------------------------------------------------------------------
3 c
4  subroutine setdomflags(mptr,igridflags,ilo,ihi,jlo,jhi,
5  . mbuff,lbase,lcheck,mibuff,mjbuff)
6 
7  use amr_module
8 
9  integer*1 igridflags(ilo-mbuff:ihi+mbuff,jlo-mbuff:jhi+mbuff)
10 c icopy is dimensioned large enough, but will be used at several sizes
11 c and accessed using lo_i-mbuff:hi_i+mbuff, etc.
12 c
13  integer*1 icopy(mibuff,mjbuff)
14  dimension ist(3), iend(3), jst(3), jend(3), ishift(3), jshift(3)
15  dimension igridst(lcheck), igridend(lcheck)
16  dimension jgridst(lcheck), jgridend(lcheck)
17  logical borderx, bordery
18 
19 c
20 c set domain flags for this grid only, enlarged by buffer zone. check if any other base grids
21 c are in exterior or first interior border cell and mark ok.
22 c note that interior of base grids 1 away from edge are automatically ok for proper nesting
23 c will shrink gridflags after setting to get proper nesting region
24 c
25 c 1. initialize this grids domain flags to 0, at lcheck
26  igridflags = 0
27 c
28 c ... if lbase coarse than lcheck, set initial indices, before upscaling, for base transfer
29 c so that dont have entire base grid upscaled
30  igridst(lcheck) = ilo
31  igridend(lcheck) = ihi
32  jgridst(lcheck) = jlo
33  jgridend(lcheck) = jhi
34  do lc = lcheck-1,lbase,-1 !NB: may be a 0 trip do loop, not old fortran
35  ilo_coarse = floor(dfloat(igridst(lc+1))/intratx(lc))
36  jlo_coarse = floor(dfloat(jgridst(lc+1))/intraty(lc))
37  ihi_coarse = ceiling(dfloat(igridend(lc+1))/intratx(lc)) - 1
38  jhi_coarse = ceiling(dfloat(jgridend(lc+1))/intraty(lc)) - 1
39  if (ihi_coarse*intratx(lc) .lt. igridend(lc+1))
40  . ihi_coarse = ihi_coarse+1
41  if (jhi_coarse*intraty(lc) .lt. jgridend(lc+1))
42  . jhi_coarse = jhi_coarse+1
43  igridend(lc) = ihi_coarse
44  jgridend(lc) = jhi_coarse
45  igridst(lc) = ilo_coarse
46  jgridst(lc) = jlo_coarse
47  end do
48 ! get out coarsened indices in case level lbase == lcheck (zero trip loop)
49  ilo_coarse = igridst(lbase)
50  ihi_coarse = igridend(lbase)
51  jlo_coarse = jgridst(lbase)
52  jhi_coarse = jgridend(lbase)
53 
54 c
55 c 3. loop over all intersecting grids at base level staying fixed
56 c to make the proper nesting dodmain.
57 c set the buffer zone in igridflags to 1 if nested
58 c this is so when shrink by one you dont lose too much area.
59 c
60  mbase = lstart(lbase)
61  20 continue
62 
63  iblo = node(ndilo,mbase) ! if base grid coarser, need to scale up
64  ibhi = node(ndihi,mbase) ! if same grid will just mark interior cells as 1
65  jblo = node(ndjlo,mbase)
66  jbhi = node(ndjhi,mbase)
67 c
68 c 3.5 if periodic bcs, then if grids buffer sticks out, will have to wrap the
69 c coordinates and flag any intersecting base grids for wrapped buffer.
70 c do here instead of above since cant coarsen mbuff same way you can for regular grid
71 c also grid itself (without enlarged mbuff zone) doesnt stick out
72 
73  borderx = (ilo_coarse.le. 0 .or. ihi_coarse.ge.iregsz(lbase)-1)
74  bordery = (jlo_coarse.le. 0 .or. jhi_coarse.ge.jregsz(lbase)-1)
75  if ((xperdom .and. borderx) .or. (yperdom .and. bordery)) then
76  call setindices(ist,iend,jst,jend,
77  . ilo_coarse-mbuff,ihi_coarse+mbuff,
78  . jlo_coarse-mbuff,jhi_coarse+mbuff,
79  . ishift,jshift,lbase)
80 
81  do 25 i = 1, 3
82  i1 = max(ilo_coarse-mbuff,ist(i))
83  i2 = min(ihi_coarse+mbuff,iend(i))
84  do 24 j = 1, 3
85  j1 = max(jlo_coarse-mbuff,jst(j))
86  j2 = min(jhi_coarse+mbuff, jend(j))
87 
88  if (.not. ((i1 .le. i2) .and. (j1 .le. j2))) go to 24 ! part of patch in this region
89 c
90 c part of patch is in this region [i,j]
91 c periodically wrap and fill if it intersects with grid mbase
92 c note: this is done in two steps in hopes of greater clarity
93 
94 
95 c usual check would be -> if ((i1 .gt. i2) .or. (j1 .gt. j2)) go to 24 ! no patch
96 c cant do that since have not yet included buffer zone - which is the part that would get wrapped
97 
98 c patch exist. does it intersect with mbase grid?
99 c use wrapped coords of this grid to test if intersects with base grid
100  ixlo = max(iblo,i1+ishift(i))
101  ixhi = min(ibhi,i2+ishift(i))
102  jxlo = max(jblo,j1+jshift(j))
103  jxhi = min(jbhi,j2+jshift(j))
104 c
105  if ((ixlo .gt. ixhi) .or. (jxlo .gt. jxhi)) go to 24 !this grid doesnt intersect
106 c
107 c if wrapped region does intersect, be careful to set the INTERSECTED part of
108 c the UNWRAPPED region of original enlarged grid
109  ixlo_unwrapped = ixlo - ishift(i)
110  ixhi_unwrapped = ixhi - ishift(i)
111  jxlo_unwrapped = jxlo - jshift(j)
112  jxhi_unwrapped = jxhi - jshift(j)
113  call coarsegridflagset(igridflags,
114  . ixlo_unwrapped,ixhi_unwrapped,
115  . jxlo_unwrapped,jxhi_unwrapped,
116  . ilo_coarse,ihi_coarse,
117  . jlo_coarse,jhi_coarse,mbuff)
118 
119  24 continue
120  25 continue
121 
122  else
123  ixlo = max(iblo,ilo_coarse-mbuff)
124  ixhi = min(ibhi,ihi_coarse+mbuff)
125  jxlo = max(jblo,jlo_coarse-mbuff)
126  jxhi = min(jbhi,jhi_coarse+mbuff)
127 c
128 c does this patch intersect mbase grid?
129  if (.not.((ixlo .le. ixhi) .and. (jxlo .le. jxhi))) go to 30 !this grid doesnt intersect
130 c
131 c use subroutine call since dimension of igridflags not same as above declaration
132 c when on coarser grids
133  call coarsegridflagset(igridflags,ixlo,ixhi,jxlo,jxhi,
134  . ilo_coarse,ihi_coarse,
135  . jlo_coarse,jhi_coarse,mbuff)
136  endif
137 
138  30 mbase = node(levelptr,mbase)
139  if (mbase .ne. 0) go to 20
140 c
141 c 3.5 set any part of grid buffer zone to 1 that is at physical boundary
142  call setphysbndryflags(igridflags,ilo_coarse,ihi_coarse,
143  . jlo_coarse,jhi_coarse,mbuff,lbase)
144 
145 c 4. done setting flags on base level. next step is to transfer the
146 c properly nested domain flags to lcheck - i.e. upscale to level needed
147 c first shrink by 1 for actual nested region.
148 c always shrink once - so works if lcheck same as lbase
149 c if going up 1 level each one needs to be nested, so still shrink first before upsizing
150 c
151 c after loop above, dom flags in igridflags, copy to icopy (in subr for dimensioning reasons)
152  call griddomcopy(icopy,igridflags,ilo_coarse,ihi_coarse,
153  . jlo_coarse,jhi_coarse,mbuff)
154 c
155 c shrink from icopy to dom2 flag array. This is where shrinking occurs if
156 c lbase = lcheck, for proper nesting
157  call griddomshrink(icopy,ilo_coarse,ihi_coarse,jlo_coarse,
158  . jhi_coarse,mbuff,
159  . alloc(node(domflags2,mptr)),lbase)
160 
161  do 40 lev = lbase+1, lcheck
162 c ### for each level that upsize, calculate new coords starting from
163 c ### actual fine grid and recoarsening down to needed level
164 c ### cant take previous coarse coords and refine, since may be
165 c ### too large. grid prob. not anchored at base grid corner.
166  ilo_fine = igridst(lev)
167  ihi_fine = igridend(lev)
168  jlo_fine = jgridst(lev)
169  jhi_fine = jgridend(lev)
170 c
171 c flags in dom2, upsize to icopy array with finer dimensions
172  call griddomup(alloc(node(domflags2,mptr)),icopy,
173  . ilo_coarse,ihi_coarse,jlo_coarse,jhi_coarse,
174  . mbuff,lev-1,
175  . ilo_fine,ihi_fine,jlo_fine,jhi_fine)
176 c flags in icopy, shrink one back to dom2
177  call griddomshrink(icopy,ilo_fine,ihi_fine,jlo_fine,jhi_fine,
178  . mbuff,alloc(node(domflags2,mptr)),lev)
179  ilo_coarse = ilo_fine
180  ihi_coarse = ihi_fine
181  jlo_coarse = jlo_fine
182  jhi_coarse = jhi_fine
183 40 continue
184 c
185  return
186  end
187 
subroutine griddomup(iflags, iflags2, ilo, ihi, jlo, jhi, mbuff, lev, ilofine, ihifine, jlofine, jhifine)
Definition: griddomup.f:4
subroutine setphysbndryflags(iflags, ilo, ihi, jlo, jhi, mbuff, level)
If grid borders the physical domain then set domain flags to 1 in buffer zone (which is outside the p...
subroutine griddomshrink(iflags2, ilo, ihi, jlo, jhi, mbuff, iflags, level)
Definition: griddomshrink.f:4
subroutine coarsegridflagset(iflags, ixlo, ixhi, jxlo, jxhi, ilo_coarse, ihi_coarse, jlo_coarse, jhi_coarse, mbuff)
Flag a whole subregion from (ixlo,ixhi) to (jxlo, jxhi) with integer.
subroutine setindices(ist, iend, jst, jend, ilo, ihi, jlo, jhi, ishift, jshift, level)
Definition: setIndices.f:4
subroutine setdomflags(mptr, igridflags, ilo, ihi, jlo, jhi, mbuff, lbase, lcheck, mibuff, mjbuff)
Definition: setdomflags.f:4
subroutine griddomcopy(i1, i2, ilo, ihi, jlo, jhi, mbuff)
Definition: griddomcopy.f:4