2D AMRCLAW
grdfit2.f
Go to the documentation of this file.
1 c
2 c ---------------------------------------------------------
3 c
4  subroutine grdfit (lbase,lcheck,nvar,naux,cut,time,
5  1 start_time)
6 c
7  use amr_module
8  implicit double precision (a-h,o-z)
9  integer clock_start, clock_finish, clock_rate
10  integer clock_start1
11 c
12  dimension corner(nsize,maxcl)
13  integer numptc(maxcl), prvptr
14  logical fit, cout
15  logical fit2, nestck2
16  data cout/.false./
17 c
18 c ::::::::::::::::::::: GRDFIT :::::::::::::::::::::::::::::::::;
19 c grdfit called by setgrd and regrid to actually fit the new grids
20 c on each level. lcheck is the level being error estimated
21 c so that lcheck+1 will be the level of the new grids.
22 c ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::;
23 c
24  call system_clock(clock_start,clock_rate)
25 
26 
27 c ### initialize region start and end indices for new level grids
28  iregst(lcheck+1) = iinfinity
29  jregst(lcheck+1) = iinfinity
30  iregend(lcheck+1) = -1
31  jregend(lcheck+1) = -1
32 
33 c ## flag all grids at given level based on error ests.
34 c ## npts is number of points actually colated - some
35 c ## flagged points turned off due to proper nesting requirement.
36 c ## (storage based on nptmax calculation however).
37 
38  call system_clock(clock_start1,clock_rate)
39  call flglvl2(nvar,naux,lcheck,nptmax,index,lbase,npts,start_time)
40  call system_clock(clock_finish,clock_rate)
41  timeflglvl = timeflglvl + clock_finish - clock_start1
42 
43  if (npts .eq. 0) go to 99
44 c
45  levnew = lcheck + 1
46  hxfine = hxposs(levnew)
47  hyfine = hyposs(levnew)
48 c
49 c ## call smart_bisect grid gen. to make the clusters
50 c till each cluster ok. needs scratch space.
51 c
52  idim = iregsz(lcheck)
53  jdim = jregsz(lcheck)
54 c lociscr = igetsp(idim+jdim)
55 c locjscr = lociscr + idim
56  call smartbis(alloc(index),npts,cut,numptc,nclust,lbase,
57  2 corner,idim,jdim)
58 c 2 corner,alloc(lociscr),alloc(locjscr),idim,jdim)
59 c call reclam(lociscr,idim+jdim)
60 
61  if (gprint) then
62  write(outunit,103) nclust
63  write(outunit,104) (icl, numptc(icl),icl=1,nclust)
64  103 format(' ',i4,' clusters after bisect')
65  104 format(' cluster ',i5,' has points: ',i8)
66  endif
67 c
68 c ## for each cluster, fit the actual grid, set up some data structures
69 c
70  50 ibase = 0
71  icl = 1
72  prvptr = null
73 c
74  70 mnew = nodget()
75 c if (lcheck .eq. 2 .and. (mnew .ne. 6 .and. mnew .ne. 7)) go to 69
76 c if (lcheck .eq. 1 .and. (mnew .ne. 3 .and. mnew .ne. 2 )) go to 69
77  75 call moment(node(1,mnew),alloc(index+2*ibase),numptc(icl),usage)
78 
79  if (gprint) write(outunit,100) icl,mnew,usage,numptc(icl)
80 100 format(' cluster ',i5,' new rect.',i5,
81  1 ' usage ',e12.5,' with ',i5,' pts.')
82 
83  node(ndilo,mnew) = node(ndilo,mnew)*intratx(lcheck)
84  node(ndjlo,mnew) = node(ndjlo,mnew)*intraty(lcheck)
85  node(ndihi,mnew) = (node(ndihi,mnew)+1)*intratx(lcheck) - 1
86  node(ndjhi,mnew) = (node(ndjhi,mnew)+1)*intraty(lcheck) - 1
87  rnode(cornxlo,mnew) = node(ndilo,mnew)*hxfine + xlower
88  rnode(cornylo,mnew) = node(ndjlo,mnew)*hyfine + ylower
89  rnode(cornxhi,mnew) = (node(ndihi,mnew)+1)*hxfine + xlower
90  rnode(cornyhi,mnew) = (node(ndjhi,mnew)+1)*hyfine + ylower
91  node(nestlevel,mnew) = levnew
92  rnode(timemult,mnew) = time
93 
94  if (gprint) write(outunit,101) (node(i,mnew),i=1,nsize),
95  & (rnode(i,mnew),i=1,rsize)
96  101 format(4i5,4i15,/,4i15,5i15,/,2i15,/,5e15.7)
97 c
98 c ## if new grid doesn't fit in base grid, nestck bisect it
99 c ## and returns 2 clusters where there used to be 1.
100 c
101 c 2/28/02 : Added naux to argument list; needed by call to outtre in nestck
102 
103  fit2 = nestck2(mnew,lbase,alloc(index+2*ibase),numptc(icl),numptc,
104  1 icl,nclust,nvar, naux)
105  if (.not. fit2) go to 75
106 c
107 c ## grid accepted. put in list.
108  if (newstl(levnew) .eq. null) then
109  newstl(levnew) = mnew
110  else
111  node(levelptr,prvptr) = mnew
112  endif
113  prvptr = mnew
114 c # keep track of min and max location of grids at this level
115  iregst(levnew) = min(iregst(levnew), node(ndilo,mnew))
116  jregst(levnew) = min(jregst(levnew), node(ndjlo,mnew))
117  iregend(levnew) = max(iregend(levnew),node(ndihi,mnew))
118  jregend(levnew) = max(jregend(levnew),node(ndjhi,mnew))
119 
120 c ## on to next cluster
121  69 ibase = ibase + numptc(icl)
122  icl = icl + 1
123  if (icl .le. nclust) go to 70
124 c
125 c ## clean up. for all grids check final size.
126  call birect(newstl(levnew))
127 
128  99 continue
129 c ## may have npts 0 but array was allocated due to initially flagged points
130 c ## that were not allowed for proper nesting or other reasons. in this case
131 c ## the array was still allocated, so need to test further to see if colating
132 c ## array space needs to be reclaimed
133  if (nptmax .gt. 0) call reclam(index, 2*nptmax)
134 c
135  call system_clock(clock_finish,clock_rate)
136  timegrdfitall = timegrdfitall + clock_finish - clock_start
137 
138  return
139  end
140 
subroutine flglvl2(nvar, naux, lcheck, nxypts, index, lbase, npts, start_time)
Controls the error estimation/flagging bad pts.
Definition: flglvl2.f:23
subroutine reclam(index, nwords)
Definition: reclam.f:4
subroutine moment(intrect, badpts, npt, usage)
Definition: moment.f:4
subroutine grdfit(lbase, lcheck, nvar, naux, cut, time, start_time)
Definition: grdfit2.f:4
logical function nestck2(mnew, lbase, badpts, npts, numptc, icl, nclust, nvar, naux)
Definition: nestck2.f:4
integer function nodget()
Definition: nodget.f:4
subroutine smartbis(badpts, npts, cutoff, numptc, nclust, lbase, intcorn, idim, jdim)
Definition: smartbis.f:4
subroutine birect(mptr1)
Definition: birect.f:4