Rocstar  1.0
Rocstar multiphysics simulation application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
RFLU_ModSplitTree.F90
Go to the documentation of this file.
1 ! *********************************************************************
2 ! * Rocstar Simulation Suite *
3 ! * Copyright@2015, Illinois Rocstar LLC. All rights reserved. *
4 ! * *
5 ! * Illinois Rocstar LLC *
6 ! * Champaign, IL *
7 ! * www.illinoisrocstar.com *
8 ! * sales@illinoisrocstar.com *
9 ! * *
10 ! * License: See LICENSE file in top level of distribution package or *
11 ! * http://opensource.org/licenses/NCSA *
12 ! *********************************************************************
13 ! *********************************************************************
14 ! * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, *
15 ! * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES *
16 ! * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND *
17 ! * NONINFRINGEMENT. IN NO EVENT SHALL THE CONTRIBUTORS OR *
18 ! * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
19 ! * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, *
20 ! * Arising FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE *
21 ! * USE OR OTHER DEALINGS WITH THE SOFTWARE. *
22 ! *********************************************************************
23 !*******************************************************************************
24 !
25 ! Purpose: Suite of routines to carry out split tree operations.
26 !
27 ! Description: None.
28 !
29 ! Notes: To create and use a split tree, one has to take the following steps:
30 ! 1.
31 ! 2.
32 ! 3. Deallocate the table by calling DestroyHashTable.
33 !
34 !*******************************************************************************
35 !
36 ! $Id: RFLU_ModSplitTree.F90,v 1.6 2008/12/06 08:44:24 mtcampbe Exp $
37 !
38 ! Copyright: (c) 2002 by the University of Illinois
39 !
40 !*******************************************************************************
41 
43 
44  USE modglobal, ONLY: t_global
45  USE moddatatypes
46  USE modparameters
47  USE moderror
48  USE modsortsearch
49 
50  IMPLICIT NONE
51 
52  PRIVATE
53  PUBLIC :: rflu_createsplittree, &
56 
57  SAVE
58 
59 ! ******************************************************************************
60 ! Declarations and definitions
61 ! ******************************************************************************
62 
63  INTEGER, PARAMETER :: NLEVELS_MAX = 50, & ! Must be greater than 1
64  NBUCKETS_MAX = 10000, & ! Must be greater than 2
65  NPOINTS_MAX = 5
66 
67  INTEGER, PRIVATE :: nPoints
68 
69  INTEGER, DIMENSION(:), ALLOCATABLE :: pointList
70  INTEGER, DIMENSION(:,:), ALLOCATABLE :: tree
71 
72  REAL(RFREAL), DIMENSION(:), ALLOCATABLE :: pointXyz
73 
74 ! ******************************************************************************
75 ! Routines
76 ! ******************************************************************************
77 
78  CONTAINS
79 
80 ! ==============================================================================
81 ! Create split tree
82 ! ==============================================================================
83 
84  SUBROUTINE rflu_createsplittree(global,nDataPoints)
85 
86  IMPLICIT NONE
87 
88  INTEGER, INTENT(IN) :: ndatapoints
89  TYPE(t_global), POINTER :: global
90 
91  INTEGER :: errorflag,ip
92 
93  CALL registerfunction(global,'RFLU_CreateSplitTree',&
94  'RFLU_ModSplitTree.F90')
95 
96 ! ------------------------------------------------------------------------------
97 ! Copy argument into nPoints variable
98 ! ------------------------------------------------------------------------------
99 
100  npoints = ndatapoints
101 
102 ! ------------------------------------------------------------------------------
103 ! Allocate memory
104 ! ------------------------------------------------------------------------------
105 
106  ALLOCATE(tree(7,nbuckets_max),stat=errorflag)
107  global%error = errorflag
108  IF ( global%error /= err_none ) THEN
109  CALL errorstop(global,err_allocate,__line__)
110  END IF ! global%error)
111 
112  ALLOCATE(pointlist(npoints),stat=errorflag)
113  global%error = errorflag
114  IF ( global%error /= err_none ) THEN
115  CALL errorstop(global,err_allocate,__line__)
116  END IF ! global%error
117 
118  ALLOCATE(pointxyz(npoints),stat=errorflag)
119  global%error = errorflag
120  IF ( global%error /= err_none ) THEN
121  CALL errorstop(global,err_allocate,__line__)
122  END IF ! global%error
123 
124 ! ------------------------------------------------------------------------------
125 ! Initialize
126 ! ------------------------------------------------------------------------------
127 
128  tree(:,:) = 0
129 
130  DO ip = 1,npoints
131  pointlist(ip) = ip
132  END DO ! ip
133 
134  CALL deregisterfunction(global)
135 
136  END SUBROUTINE rflu_createsplittree
137 
138 ! ==============================================================================
139 ! Build split tree
140 ! ==============================================================================
141 
142  SUBROUTINE rflu_buildsplittree(global,xyz)
143 
144  IMPLICIT NONE
145 
146  INTEGER :: errorflag,ibranch1,ibranch2,ibucket,ibucketlast,ipl,ipm,ipg, &
147  isplitdir,nbuckets,nlevels
148 
149  REAL(RFREAL), INTENT(IN) :: xyz(3,npoints)
150  TYPE(t_global), POINTER :: global
151 
152 ! ------------------------------------------------------------------------------
153 ! Start
154 ! ------------------------------------------------------------------------------
155 
156  CALL registerfunction(global,'RFLU_BuildSplitTree',&
157  'RFLU_ModSplitTree.F90')
158 
159  nlevels = 1
160  nbuckets = 1
161 
162  ibucket = 1
163  ibucketlast = 1
164  isplitdir = 1
165 
166  tree(1,ibucket) = 1
167  tree(2,ibucket) = npoints
168  tree(3,ibucket) = npoints
169  tree(4,ibucket) = isplitdir
170 
171 ! ------------------------------------------------------------------------------
172 ! Loop over levels
173 ! ------------------------------------------------------------------------------
174 
175  outer: DO
176  isplitdir = isplitdir + 1
177  IF ( isplitdir > 3 ) THEN
178  isplitdir = 1
179  END IF ! iSplitDir
180 
181 ! ----- Loop over buckets
182 
183  inner: DO
184 
185 ! ------- Determine whether bucket should be split
186 
187  IF ( tree(3,ibucket) > npoints_max ) THEN ! Split bucket
188 
189 ! --------- Check whether more buckets can be generated
190 
191  IF ( nbuckets > nbuckets_max-2 ) THEN
192  EXIT outer
193  END IF ! nBuckets
194 
195 ! --------- Determine where bucket should be split - use median
196 
197  ipl = 0
198  DO ipg = tree(1,ibucket),tree(2,ibucket)
199  ipl = ipl + 1
200  pointxyz(ipl) = xyz(isplitdir,pointlist(ipg))
201  END DO ! ipg
202 
203  CALL quicksortrfrealinteger(pointxyz(1:tree(3,ibucket)), &
204  pointlist(tree(1,ibucket):tree(2,ibucket)), &
205  tree(3,ibucket))
206 
207  ipm = tree(3,ibucket)/2 + 1 ! NOTE integer division
208 
209 ! --------- Update information for current bucket
210 
211  tree(5,ibucket) = pointlist(ipm)
212 
213  ibranch1 = ibucket + 1
214  ibranch2 = ibucket + 2
215 
216  tree(6,ibucket) = ibranch1
217  tree(7,ibucket) = ibranch2
218 
219 ! --------- Create new buckets
220 
221  nbuckets = nbuckets + 2
222 
223  tree(1,ibranch1) = tree(1,ibucket)
224  tree(2,ibranch1) = ipm - 1
225  tree(3,ibranch1) = tree(2,ibranch1) - tree(1,ibranch1) + 1
226  tree(4,ibranch1) = isplitdir
227 
228  tree(1,ibranch2) = ipm
229  tree(2,ibranch2) = tree(3,ibucket)
230  tree(3,ibranch2) = tree(2,ibranch2) - tree(1,ibranch2) + 1
231  tree(4,ibranch2) = tree(4,ibranch1)
232  END IF ! tree(3,iBucket)
233 
234 ! ------- Check whether more buckets to be split
235 
236  IF ( ibucket < nbuckets ) THEN
237  IF ( ibucket /= ibucketlast ) THEN
238  ibucket = ibucket + 1
239  ELSE
240  ibucketlast = nbuckets
241  EXIT inner
242  END IF ! iBucket
243  ELSE
244  EXIT outer
245  END IF ! iBucket
246  END DO inner
247 
248 ! ----- Check whether more levels can be inserted
249 
250  IF ( nlevels < nlevels_max ) THEN
251  nlevels = nlevels + 1
252  ibucket = ibucket + 1
253  ELSE
254  EXIT outer
255  END IF ! nLevels
256  END DO outer
257 
258  WRITE(*,*) nlevels,nbuckets
259 
260  DO ipl = 1,nbuckets
261  WRITE(*,*) ipl,tree(1:7,ipl)
262  END DO ! ipl
263 
264  CALL deregisterfunction(global)
265 
266  END SUBROUTINE rflu_buildsplittree
267 
268 ! ==============================================================================
269 ! Destroy split tree
270 ! ==============================================================================
271 
272  SUBROUTINE rflu_destroysplittree(global)
273 
274  IMPLICIT NONE
275 
276  TYPE(t_global), POINTER :: global
277 
278  INTEGER :: errorflag
279 
280  CALL registerfunction(global,'RFLU_DestroySplitTree',&
281  'RFLU_ModSplitTree.F90')
282 
283  DEALLOCATE(tree,stat=errorflag)
284  global%error = errorflag
285  IF ( global%error /= err_none ) THEN
286  CALL errorstop(global,err_deallocate,__line__)
287  END IF ! global%error)
288 
289  DEALLOCATE(pointlist,stat=errorflag)
290  global%error = errorflag
291  IF ( global%error /= err_none ) THEN
292  CALL errorstop(global,err_deallocate,__line__)
293  END IF ! global%error
294 
295  DEALLOCATE(pointxyz,stat=errorflag)
296  global%error = errorflag
297  IF ( global%error /= err_none ) THEN
298  CALL errorstop(global,err_deallocate,__line__)
299  END IF ! global%error
300 
301  CALL deregisterfunction(global)
302 
303  END SUBROUTINE rflu_destroysplittree
304 
305 
306 
307 
308 ! ******************************************************************************
309 ! End
310 ! ******************************************************************************
311 
312 END MODULE rflu_modsplittree
313 
314 
315 ! ******************************************************************************
316 !
317 ! RCS Revision history:
318 !
319 ! $Log: RFLU_ModSplitTree.F90,v $
320 ! Revision 1.6 2008/12/06 08:44:24 mtcampbe
321 ! Updated license.
322 !
323 ! Revision 1.5 2008/11/19 22:17:35 mtcampbe
324 ! Added Illinois Open Source License/Copyright
325 !
326 ! Revision 1.4 2004/01/22 16:03:59 haselbac
327 ! Made contents of modules PRIVATE, only procs PUBLIC, to avoid errors on ALC and titan
328 !
329 ! Revision 1.3 2002/10/08 15:49:21 haselbac
330 ! {IO}STAT=global%error replaced by {IO}STAT=errorFlag - SGI problem
331 !
332 ! Revision 1.2 2002/09/09 15:12:12 haselbac
333 ! global now under regions
334 !
335 ! Revision 1.1 2002/04/11 18:48:48 haselbac
336 ! Initial revision
337 !
338 !
339 ! ******************************************************************************
340 
341 
342 
343 
344 
345 
346 
347 
348 
subroutine registerfunction(global, funName, fileName)
Definition: ModError.F90:449
subroutine, public rflu_destroysplittree(global)
subroutine, public rflu_buildsplittree(global, xyz)
subroutine, public rflu_createsplittree(global, nDataPoints)
subroutine quicksortrfrealinteger(a, b, n)
subroutine errorstop(global, errorCode, errorLine, addMessage)
Definition: ModError.F90:483
subroutine deregisterfunction(global)
Definition: ModError.F90:469