Rocstar  1.0
Rocstar multiphysics simulation application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PLAG_RFLU_InitSolFromSerial.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: Initialize particle solution in a region by copying data from
26 ! serial region.
27 !
28 ! Description: None.
29 !
30 ! Input:
31 ! pRegion Pointer to parallel region
32 ! pRegionSerial Pointer to serial region
33 !
34 ! Output: None.
35 !
36 ! Notes: None.
37 !
38 ! ******************************************************************************
39 !
40 ! $Id: PLAG_RFLU_InitSolFromSerial.F90,v 1.7 2008/12/06 08:44:35 mtcampbe Exp $
41 !
42 ! Copyright: (c) 2005-2007 by the University of Illinois
43 !
44 ! ******************************************************************************
45 
46 SUBROUTINE plag_rflu_initsolfromserial(pRegion,pRegionSerial)
47 
48  USE moddatatypes
49  USE moderror
50  USE moddatastruct, ONLY: t_region
51  USE modglobal, ONLY: t_global
52  USE modgrid, ONLY: t_grid
53  USE modpartlag, ONLY: t_plag
54  USE modparameters
55  USE modsortsearch
56 
58 
60 
61 
62  IMPLICIT NONE
63 
64 ! ******************************************************************************
65 ! Declarations and definitions
66 ! ******************************************************************************
67 
68 ! ==============================================================================
69 ! Arguments
70 ! ==============================================================================
71 
72  TYPE(t_region), POINTER :: pregion,pregionserial
73 
74 ! ==============================================================================
75 ! Locals
76 ! ==============================================================================
77 
78  LOGICAL :: sortflag
79  CHARACTER(CHRLEN) :: rcsidentstring
80  INTEGER :: errorflag,icg,icgs,icgsmax,icgsmin,icgsnzpcllow,icgsnzpclmax, &
81  icgsnzpclmin,icgsnzpclupp,icl,iloc,ipclpercellcsr, &
82  ipclpercellcsrlow,ipclpercellcsrupp,ipclserial,isc2pc,isc2pclow, &
83  isc2pcupp,ivar,j
84  REAL(RFREAL) :: delfrac,xdel,xmax,xmin,xpcl,xpclmax,xpclmin,ydel,ymax,ymin, &
85  ypcl,ypclmax,ypclmin,zdel,zmax,zmin,zpcl,zpclmax,zpclmin
86  TYPE(t_global), POINTER :: global
87  TYPE(t_grid), POINTER :: pgrid
88  TYPE(t_plag), POINTER :: pplag,pplagserial
89 
90 ! ******************************************************************************
91 ! Start
92 ! ******************************************************************************
93 
94  rcsidentstring = &
95  '$RCSfile: PLAG_RFLU_InitSolFromSerial.F90,v $ $Revision: 1.7 $'
96 
97  global => pregion%global
98 
99  CALL registerfunction(global,'PLAG_RFLU_InitSolFromSerial', &
100  'PLAG_RFLU_InitSolFromSerial.F90')
101 
102  IF ( global%verbLevel > verbose_none ) THEN
103  WRITE(stdout,'(A,1X,A)') solver_name,'Initializing particle solution '// &
104  'from serial region...'
105  WRITE(stdout,'(A,3X,A,1X,I5.5)') solver_name,'Global region:', &
106  pregion%iRegionGlobal
107  END IF ! global%verbLevel
108 
109 ! ******************************************************************************
110 ! Set pointers and values
111 ! ******************************************************************************
112 
113  pgrid => pregion%grid
114  pplag => pregion%plag
115  pplagserial => pregionserial%plag
116 
117  sortflag = .false.
118 
119  pplag%nPcls = 0
120 
121  delfrac = 0.05_rfreal
122 
123 ! ******************************************************************************
124 ! Get (slightly enlarged) grid bounding box
125 ! ******************************************************************************
126 
127  xmin = minval(pgrid%xyz(xcoord,1:pgrid%nVert))
128  xmax = maxval(pgrid%xyz(xcoord,1:pgrid%nVert))
129  ymin = minval(pgrid%xyz(ycoord,1:pgrid%nVert))
130  ymax = maxval(pgrid%xyz(ycoord,1:pgrid%nVert))
131  zmin = minval(pgrid%xyz(zcoord,1:pgrid%nVert))
132  zmax = maxval(pgrid%xyz(zcoord,1:pgrid%nVert))
133 
134  xdel = xmax - xmin
135  ydel = ymax - ymin
136  zdel = zmax - zmin
137 
138  xmin = xmin - delfrac*xdel
139  xmax = xmax + delfrac*xdel
140  ymin = ymin - delfrac*ydel
141  ymax = ymax + delfrac*ydel
142  zmin = zmin - delfrac*zdel
143  zmax = zmax + delfrac*zdel
144 
145 ! ******************************************************************************
146 ! Get particle bounding box
147 ! ******************************************************************************
148 
149  xpclmin = huge(1.0_rfreal)
150  xpclmax = -huge(1.0_rfreal)
151  ypclmin = huge(1.0_rfreal)
152  ypclmax = -huge(1.0_rfreal)
153  zpclmin = huge(1.0_rfreal)
154  zpclmax = -huge(1.0_rfreal)
155 
156  DO ipclserial = 1,pplagserial%nPcls
157  xpclmin = min(xpclmin,pplagserial%cv(cv_plag_xpos,ipclserial))
158  xpclmax = max(xpclmax,pplagserial%cv(cv_plag_xpos,ipclserial))
159  ypclmin = min(ypclmin,pplagserial%cv(cv_plag_ypos,ipclserial))
160  ypclmax = max(ypclmax,pplagserial%cv(cv_plag_ypos,ipclserial))
161  zpclmin = min(zpclmin,pplagserial%cv(cv_plag_zpos,ipclserial))
162  zpclmax = max(zpclmax,pplagserial%cv(cv_plag_zpos,ipclserial))
163  END DO ! iPclSerial
164 
165 ! ******************************************************************************
166 ! If particle bounding box contained at least partially in grid bounding box,
167 ! search for particles
168 ! ******************************************************************************
169 
170  IF ( ((xpclmin < xmax) .AND. (ypclmin < ymax) .AND. (zpclmin < zmax)) .AND. &
171  ((xpclmax > xmin) .AND. (ypclmax > ymin) .AND. (zpclmax > zmin)) ) THEN
172 
173 ! ==============================================================================
174 ! Read Pxxx2Sxxx maps so can build sc2pc map which will be used to copy
175 ! particle data, find range of serial indices associated with cells in this
176 ! region, and range of serial cells with non-zero particles
177 ! ==============================================================================
178 
179  CALL rflu_rnmb_createpbf2sbfmap(pregion)
180  CALL rflu_rnmb_createpc2scmap(pregion)
181  CALL rflu_rnmb_createpv2svmap(pregion)
182 
183  CALL rflu_rnmb_readpxx2sxxmaps(pregion)
184 
185  CALL rflu_rnmb_destroypbf2sbfmap(pregion)
186  CALL rflu_rnmb_destroypv2svmap(pregion)
187 
188  CALL rflu_rnmb_buildsc2pcmap(pregion,sortflag)
189 
190  icgsnzpclmin = pplagserial%icgNzPcl(1)
191  icgsnzpclmax = pplagserial%icgNzPcl(pplagserial%nCellsNzPcl)
192 
193  icgsmin = pgrid%sc2pc(1,1)
194  icgsmax = pgrid%sc2pc(1,pgrid%nCells)
195 
196 ! ==============================================================================
197 ! If cell ranges overlap, then will have particles in this region. Then find
198 ! the lower and upper indices in the sc2pc and icgNzPcl maps to reduce
199 ! looping and searching.
200 ! ==============================================================================
201 
202  IF ( (icgsnzpclmin < icgsmax) .AND. (icgsnzpclmax > icgsmin) ) THEN
203  CALL binarysearchinteger(pgrid%sc2pc(1,1:pgrid%nCells),pgrid%nCells, &
204  icgsnzpclmin,iloc,j)
205  IF ( iloc == element_not_found ) THEN
206  isc2pclow = max(1,min(j,pgrid%nCells))
207  ELSE
208  isc2pclow = iloc
209  END IF ! iLoc
210 
211  CALL binarysearchinteger(pgrid%sc2pc(1,1:pgrid%nCells),pgrid%nCells, &
212  icgsnzpclmax,iloc,j)
213  IF ( iloc == element_not_found ) THEN
214  isc2pcupp = max(1,min(j,pgrid%nCells))
215  ELSE
216  isc2pcupp = iloc
217  END IF ! iLoc
218 
219  CALL binarysearchinteger(pplagserial%icgNzPcl(1:pplagserial%nCellsNzPcl), &
220  pplagserial%nCellsNzPcl,icgsmin,iloc,j)
221  IF ( iloc == element_not_found ) THEN
222  icgsnzpcllow = max(1,min(j,pgrid%nCells))
223  ELSE
224  icgsnzpcllow = iloc
225  END IF ! iLoc
226 
227  CALL binarysearchinteger(pplagserial%icgNzPcl(1:pplagserial%nCellsNzPcl), &
228  pplagserial%nCellsNzPcl,icgsmax,iloc,j)
229  IF ( iloc == element_not_found ) THEN
230  icgsnzpclupp = max(1,min(j,pgrid%nCells))
231  ELSE
232  icgsnzpclupp = iloc
233  END IF ! iLoc
234 
235 ! ------------------------------------------------------------------------------
236 ! Loop over range of cells in this region which lie in range of cells in
237 ! serial region with non-zero particles. If cell actually has non-zero
238 ! particles, then copy all of them to this region. NOTE check whether
239 ! region index of serial particle is not crazy value anymore, which
240 ! indicates that serial particle was already assigned to another region,
241 ! and hence indicates an erroneous double assignment.
242 ! ------------------------------------------------------------------------------
243 
244  DO isc2pc = isc2pclow,isc2pcupp
245  icgs = pgrid%sc2pc(1,isc2pc)
246 
247  CALL binarysearchinteger(pplagserial%icgNzPcl(icgsnzpcllow:icgsnzpclupp), &
248  icgsnzpclupp-icgsnzpcllow+1,icgs,iloc)
249 
250  IF ( iloc /= element_not_found ) THEN
251  iloc = iloc + icgsnzpcllow - 1
252 
253  IF ( iloc > 1 ) THEN
254  ipclpercellcsrlow = pplagserial%iPclPerCellCSRInfo(iloc-1)+1
255  ELSE
256  ipclpercellcsrlow = 1
257  END IF ! iLoc
258 
259  ipclpercellcsrupp = pplagserial%iPclPerCellCSRInfo(iloc)
260 
261  DO ipclpercellcsr = ipclpercellcsrlow,ipclpercellcsrupp
262  ipclserial = pplagserial%iPclPerCellCSR(ipclpercellcsr)
263 
264  pplag%nPcls = pplag%nPcls + 1
265 
266  DO ivar = 1,pregion%plag%nCv
267  pplag%cv(ivar,pplag%nPcls) = pplagserial%cv(ivar,ipclserial)
268  END DO ! iVar
269 
270  DO ivar = 1,pregion%plag%nArv
271  pplag%arv(ivar,pplag%nPcls) = pplagserial%arv(ivar,ipclserial)
272  END DO ! iVar
273 
274  DO ivar = 1,pregion%plag%nAiv
275  pplag%aiv(ivar,pplag%nPcls) = pplagserial%aiv(ivar,ipclserial)
276  END DO ! iVar
277 
278  pplag%aiv(aiv_plag_icells,pplag%nPcls) = pgrid%sc2pc(2,isc2pc)
279  pplag%aiv(aiv_plag_regini,pplag%nPcls) = pregion%iRegionGlobal
280 
281  IF ( pplagserial%aiv(aiv_plag_regini,ipclserial) /= 0 ) THEN
282  CALL errorstop(global,err_plag_dstr_invalid,__line__)
283  ELSE
284  pplagserial%aiv(aiv_plag_regini,ipclserial) = &
285  pregion%iRegionGlobal
286  END IF ! pPlagSerial%aiv
287  END DO ! iPclSerial
288  END IF ! iloc
289  END DO ! iSc2Pc
290  END IF ! icgsNzMin
291 
292  CALL rflu_rnmb_destroysc2pcmap(pregion)
293  END IF ! xPcl
294 
295 ! ******************************************************************************
296 ! Write info
297 ! ******************************************************************************
298 
299  IF ( global%verbLevel > verbose_low ) THEN
300  WRITE(stdout,'(A,3X,A,1X,I6)') solver_name,'Number of particles:', &
301  pplag%nPcls
302  END IF ! global%verbLevel
303 
304 ! ******************************************************************************
305 ! End
306 ! ******************************************************************************
307 
308  IF ( global%verbLevel > verbose_none ) THEN
309  WRITE(stdout,'(A,1X,A)') solver_name,'Initializing particle solution '// &
310  'from serial region done.'
311  END IF ! global%verbLevel
312 
313  CALL deregisterfunction(global)
314 
315 END SUBROUTINE plag_rflu_initsolfromserial
316 
317 ! ******************************************************************************
318 !
319 ! RCS Revision history:
320 !
321 ! $Log: PLAG_RFLU_InitSolFromSerial.F90,v $
322 ! Revision 1.7 2008/12/06 08:44:35 mtcampbe
323 ! Updated license.
324 !
325 ! Revision 1.6 2008/11/19 22:17:47 mtcampbe
326 ! Added Illinois Open Source License/Copyright
327 !
328 ! Revision 1.5 2007/03/27 00:21:33 haselbac
329 ! Adaptation to new initialization
330 !
331 ! Revision 1.4 2006/05/22 15:33:09 fnajjar
332 ! Fixed bug for uninitialized delFrac
333 !
334 ! Revision 1.3 2006/05/05 17:36:24 haselbac
335 ! Changed so do not need access to serial grid
336 !
337 ! Revision 1.2 2006/04/07 15:19:24 haselbac
338 ! Removed tabs
339 !
340 ! Revision 1.1 2005/05/18 22:27:45 fnajjar
341 ! Initial revision
342 !
343 ! ******************************************************************************
344 
345 
346 
347 
348 
349 
350 
subroutine, public rflu_rnmb_readpxx2sxxmaps(pRegion)
double ymin() const
double xmax() const
subroutine, public rflu_rnmb_destroypbf2sbfmap(pRegion)
Vector_n max(const Array_n_const &v1, const Array_n_const &v2)
Definition: Vector_n.h:354
double xmin() const
subroutine plag_rflu_initsolfromserial(pRegion, pRegionSerial)
subroutine registerfunction(global, funName, fileName)
Definition: ModError.F90:449
double zmin() const
subroutine binarysearchinteger(a, n, v, i, j)
subroutine, public rflu_rnmb_buildsc2pcmap(pRegion, sortFlag)
subroutine, public rflu_rnmb_destroysc2pcmap(pRegion)
subroutine, public rflu_rnmb_destroypv2svmap(pRegion)
double zmax() const
double ymax() const
subroutine, public rflu_rnmb_createpc2scmap(pRegion)
Vector_n min(const Array_n_const &v1, const Array_n_const &v2)
Definition: Vector_n.h:346
j indices j
Definition: Indexing.h:6
subroutine, public rflu_rnmb_createpv2svmap(pRegion)
subroutine errorstop(global, errorCode, errorLine, addMessage)
Definition: ModError.F90:483
subroutine, public rflu_rnmb_createpbf2sbfmap(pRegion)
subroutine deregisterfunction(global)
Definition: ModError.F90:469