Rocstar  1.0
Rocstar multiphysics simulation application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PLAG_ModReallocateMemory.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 dynamically reallocate memory.
26 !
27 ! Description: None.
28 !
29 ! Notes: None.
30 !
31 !*******************************************************************************
32 !
33 ! $Id: PLAG_ModReallocateMemory.F90,v 1.9 2008/12/06 08:44:34 mtcampbe Exp $
34 !
35 ! Copyright: (c) 2004 by the University of Illinois
36 !
37 !*******************************************************************************
38 
40 
41  USE moddatatypes
42  USE moderror
43  USE modparameters
44  USE modglobal, ONLY: t_global
45  USE moddatastruct, ONLY: t_region
46  USE modpartlag, ONLY: t_plag
47  USE modmpi
55 
57 
58  IMPLICIT NONE
59 
60  REAL(RFREAL), PARAMETER :: PLAG_EXPAND_RATIO = 0.90_RFREAL
61  REAL(RFREAL), PARAMETER :: PLAG_SHRINK_RATIO = 0.25_RFREAL
62 
63  PRIVATE
64  PUBLIC :: plag_reallocmemwrapper
65 
66 ! ******************************************************************************
67 ! Declarations and definitions
68 ! ******************************************************************************
69 
70  CHARACTER(CHRLEN) :: RCSIdentString = &
71  '$RCSfile: PLAG_ModReallocateMemory.F90,v $ $Revision: 1.9 $'
72 
73 ! ******************************************************************************
74 ! Routines
75 ! ******************************************************************************
76 
77  CONTAINS
78 
79 
80 
81 
82 ! ******************************************************************************
83 !
84 ! Purpose: Copy dimensions for Lagrangian particle solution.
85 !
86 ! Description: None.
87 !
88 ! Input:
89 ! global Global pointer
90 ! pPlag Plag pointer
91 ! pPlagCopy Plag pointer to copy
92 !
93 ! Output: None.
94 !
95 ! Notes: Memory dimensions operation is performed at the last RK-stage following
96 ! particle relocation, communication and injection.
97 !
98 ! ******************************************************************************
99 
100 SUBROUTINE plag_copydimensions(global,pPlag,pPlagCopy)
101 
102  IMPLICIT NONE
103 
104 ! ******************************************************************************
105 ! Definitions and declarations
106 ! ******************************************************************************
107 
108 ! ==============================================================================
109 ! Arguments
110 ! ==============================================================================
111 
112  TYPE(t_global), POINTER :: global
113  TYPE(t_plag), POINTER :: pplag,pplagcopy
114 
115 ! ==============================================================================
116 ! Locals
117 ! ==============================================================================
118 
119  CHARACTER(CHRLEN) :: rcsidentstring
120 
121 ! ******************************************************************************
122 ! Start
123 ! ******************************************************************************
124 
125  rcsidentstring = '$RCSfile: PLAG_ModReallocateMemory.F90,v $ $Revision: 1.9 $'
126 
127  CALL registerfunction(global,'PLAG_CopyDimensions',&
128  'PLAG_ModReallocateMemory.F90')
129 
130 ! *****************************************************************************
131 ! Copy particle dimensions from original datastructure to temporary datastructure
132 ! *****************************************************************************
133 
134  pplagcopy%nAiv = pplag%nAiv
135  pplagcopy%nArv = pplag%nArv
136  pplagcopy%nCv = pplag%nCv
137  pplagcopy%nDv = pplag%nDv
138  pplagcopy%nTv = pplag%nTv
139  pplagcopy%nPcls = pplag%nPcls
140 
141 ! ******************************************************************************
142 ! End
143 ! ******************************************************************************
144 
145  CALL deregisterfunction(global)
146 
147 END SUBROUTINE plag_copydimensions
148 
149 
150 
151 ! ******************************************************************************
152 !
153 ! Purpose: Copy memory for Lagrangian particle solution.
154 !
155 ! Description: None.
156 !
157 ! Input:
158 ! global Global pointer
159 ! pPlag Plag pointer
160 ! pPlagCopy Plag pointer to copy
161 !
162 ! Output: None.
163 !
164 ! Notes:
165 ! 1. Memory copy operation is performed at the last RK-stage following
166 ! particle relocation, communication and injection.
167 ! 2. Copying of dv and tv data is not required given the memory swap
168 ! occurs at the last RK stage; but it is kept for consistency.
169 !
170 ! ******************************************************************************
171 
172 SUBROUTINE plag_copymemory(global,pPlag,pPlagCopy)
173 
174  IMPLICIT NONE
175 
176 ! ******************************************************************************
177 ! Definitions and declarations
178 ! ******************************************************************************
179 
180 ! ==============================================================================
181 ! Arguments
182 ! ==============================================================================
183 
184  TYPE(t_global), POINTER :: global
185  TYPE(t_plag), POINTER :: pplag,pplagcopy
186 
187 ! ==============================================================================
188 ! Locals
189 ! ==============================================================================
190 
191  CHARACTER(CHRLEN) :: rcsidentstring
192  INTEGER :: ipcl,ivar,naiv,narv,ncont,ncv,ndv,npcls,ntv
193 
194 ! ******************************************************************************
195 ! Start
196 ! ******************************************************************************
197 
198  rcsidentstring = '$RCSfile: PLAG_ModReallocateMemory.F90,v $ $Revision: 1.9 $'
199 
200  CALL registerfunction(global,'PLAG_CopyMemory',&
201  'PLAG_ModReallocateMemory.F90')
202 
203 ! ******************************************************************************
204 ! Set variables
205 ! ******************************************************************************
206 
207  npcls = pplag%nPcls
208 
209  naiv = pplag%nAiv
210  narv = pplag%nArv
211 
212  ncv = pplag%nCv
213  ndv = pplag%nDv
214  ntv = pplag%nTv
215 
216 ! *****************************************************************************
217 ! Copy particle data from original datastructure to temporary datastructure
218 ! *****************************************************************************
219 
220  DO ipcl = 1,npcls
221  DO ivar = 1,ncv
222  pplagcopy%cv(ivar,ipcl) = pplag%cv(ivar,ipcl)
223  pplagcopy%cvOld(ivar,ipcl) = pplag%cvOld(ivar,ipcl)
224  pplagcopy%rhsSum(ivar,ipcl) = pplag%rhsSum(ivar,ipcl)
225  END DO ! iVar
226 
227  DO ivar = 1,ndv
228  pplagcopy%dv(ivar,ipcl) = pplag%dv(ivar,ipcl)
229  END DO ! iVar
230 
231  DO ivar = 1,ntv
232  pplagcopy%tv(ivar,ipcl) = pplag%tv(ivar,ipcl)
233  END DO ! iVar
234 
235  DO ivar = 1,naiv
236  pplagcopy%aiv(ivar,ipcl) = pplag%aiv(ivar,ipcl)
237  pplagcopy%aivOld(ivar,ipcl) = pplag%aivOld(ivar,ipcl)
238  END DO ! iVar
239 
240  DO ivar = 1,narv
241  pplagcopy%arv(ivar,ipcl) = pplag%arv(ivar,ipcl)
242  pplagcopy%arvOld(ivar,ipcl) = pplag%arvOld(ivar,ipcl)
243  END DO ! iVar
244  END DO ! iPcl
245 
246 ! ******************************************************************************
247 ! End
248 ! ******************************************************************************
249 
250  CALL deregisterfunction(global)
251 
252 END SUBROUTINE plag_copymemory
253 
254 
255 
256 
257 
258 
259 
260 
261 ! ******************************************************************************
262 !
263 ! Purpose: Decide to reallocate memory for particle datastructure.
264 !
265 ! Description: None.
266 !
267 ! Input:
268 ! pRegion Region pointer
269 !
270 ! Output:
271 ! pDecideReallocMem Logical flag for decision
272 !
273 ! Notes: None.
274 !
275 ! ******************************************************************************
276 
277 SUBROUTINE plag_decidereallocmem(pRegion,pDecideReallocMem)
278 
279  IMPLICIT NONE
280 
281 ! ******************************************************************************
282 ! Definitions and declarations
283 ! ******************************************************************************
284 
285 ! ==============================================================================
286 ! Arguments
287 ! ==============================================================================
288 
289  TYPE(t_region), POINTER :: pregion
290  LOGICAL, INTENT(INOUT) :: pdecidereallocmem
291 
292 ! ==============================================================================
293 ! Locals
294 ! ==============================================================================
295 
296  CHARACTER(CHRLEN) :: rcsidentstring
297 
298  INTEGER :: errorflag,npcls,npclsmax
299 
300  REAL(RFREAL) :: pclratio
301 
302  TYPE(t_global), POINTER :: global
303 
304 ! ******************************************************************************
305 ! Start
306 ! ******************************************************************************
307 
308  rcsidentstring = '$RCSfile: PLAG_ModReallocateMemory.F90,v $ $Revision: 1.9 $'
309 
310  global => pregion%global
311 
312  CALL registerfunction(global,'PLAG_DecideReallocMem',&
313  'PLAG_ModReallocateMemory.F90')
314 
315 ! ******************************************************************************
316 ! Set variables
317 ! ******************************************************************************
318 
319  npclsmax = pregion%plag%nPclsMax
320  npcls = pregion%plag%nPcls
321 
322  pdecidereallocmem = .false.
323 
324 ! ******************************************************************************
325 ! Set logical flag depending on ratio of nPcls to maximum size of datastructure
326 ! ******************************************************************************
327 
328  pclratio = REAL(npcls,kind=rfreal)/REAL(npclsmax,kind=rfreal)
329 
330  IF ( pclratio >= plag_expand_ratio .OR. &
331  ( pclratio <= plag_shrink_ratio .AND. &
332  npclsmax > npcls_tot_min ) ) pdecidereallocmem = .true.
333 
334 ! ******************************************************************************
335 ! End
336 ! ******************************************************************************
337 
338  CALL deregisterfunction(global)
339 
340 END SUBROUTINE plag_decidereallocmem
341 
342 
343 
344 
345 
346 
347 
348 ! ******************************************************************************
349 !
350 ! Purpose: Realllocate memory for Lagrangian particle datastructure.
351 !
352 ! Description: None.
353 !
354 ! Input:
355 ! pRegion Region pointer
356 !
357 ! Output: None.
358 !
359 ! Notes: None.
360 !
361 ! ******************************************************************************
362 
363 SUBROUTINE plag_reallocmem(pRegion)
364 
365  IMPLICIT NONE
366 
367 ! ******************************************************************************
368 ! Definitions and declarations
369 ! ******************************************************************************
370 
371 ! ==============================================================================
372 ! Arguments
373 ! ==============================================================================
374 
375  TYPE(t_region), POINTER :: pregion
376 
377 ! ==============================================================================
378 ! Locals
379 ! ==============================================================================
380 
381  CHARACTER(CHRLEN) :: rcsidentstring
382 
383  INTEGER :: errorflag,npcls,nplagpclstot
384 
385  TYPE(t_global), POINTER :: global
386  TYPE(t_plag), POINTER :: pplag,pplagtemp
387 
388 ! ******************************************************************************
389 ! Start
390 ! ******************************************************************************
391 
392  rcsidentstring = '$RCSfile: PLAG_ModReallocateMemory.F90,v $ $Revision: 1.9 $'
393 
394  global => pregion%global
395 
396  CALL registerfunction(global,'PLAG_ReallocMem',&
397  'PLAG_ModReallocateMemory.F90')
398 
399 ! ******************************************************************************
400 ! Set pointers and variables
401 ! ******************************************************************************
402 
403  pplag => pregion%plag
404  pplagtemp => pregion%plagTemp
405 
406 ! ******************************************************************************
407 ! Copy particle dimensions from original datastructure
408 ! to temporary datastructure
409 ! ******************************************************************************
410 
411  CALL plag_copydimensions( global,pplag,pplagtemp )
412 
413 ! ******************************************************************************
414 ! Allocate memory for intermediate datastructure
415 ! ******************************************************************************
416 
417  CALL plag_rflu_allocmemsol( pregion,pplagtemp )
418  CALL plag_rflu_allocmemtstep( pregion,pplagtemp )
419 
420 ! *****************************************************************************
421 ! Copy particle data from original datastructure to temporary datastructure
422 ! *****************************************************************************
423 
424  CALL plag_copymemory( global,pplag,pplagtemp )
425 
426 ! ******************************************************************************
427 ! Destroy memory of original datastructure
428 ! ******************************************************************************
429 
430  CALL plag_rflu_deallocmemsol( pregion,pplag )
431  CALL plag_rflu_deallocmemtstep( pregion,pplag )
432  CALL plag_inrt_deallocmemtstep( pregion,pplag )
433 
434 ! ******************************************************************************
435 ! Allocate memory for original datastructure with updated maximum value
436 ! ******************************************************************************
437 
438  CALL plag_rflu_allocmemsol( pregion,pplag )
439  CALL plag_rflu_allocmemtstep( pregion,pplag )
440  CALL plag_inrt_allocmemtstep( pregion,pplag )
441 
442 ! *****************************************************************************
443 ! Copy particle data from temporary datastructure to original datastructre
444 ! *****************************************************************************
445 
446  CALL plag_copymemory( global,pplagtemp,pplag )
447 
448 ! ******************************************************************************
449 ! Destroy memory of temporary datastructure
450 ! ******************************************************************************
451 
452  CALL plag_rflu_deallocmemsol( pregion,pplagtemp )
453  CALL plag_rflu_deallocmemtstep( pregion,pplagtemp )
454 
455 ! ******************************************************************************
456 ! End
457 ! ******************************************************************************
458 
459  CALL deregisterfunction(global)
460 
461 END SUBROUTINE plag_reallocmem
462 
463 
464 
465 
466 
467 
468 
469 ! ******************************************************************************
470 !
471 ! Purpose: Wrapper routine to realllocate memory for Lagrangian
472 !particle datastructure.
473 !
474 ! Description: None.
475 !
476 ! Input:
477 ! pRegion Region pointer
478 !
479 ! Output: None.
480 !
481 ! Notes: None.
482 !
483 ! ******************************************************************************
484 
485 SUBROUTINE plag_reallocmemwrapper(pRegion)
486 
487  IMPLICIT NONE
488 
489 ! ******************************************************************************
490 ! Definitions and declarations
491 ! ******************************************************************************
492 
493 ! ==============================================================================
494 ! Arguments
495 ! ==============================================================================
496 
497  TYPE(t_region), POINTER :: pregion
498 
499 ! ==============================================================================
500 ! Locals
501 ! ==============================================================================
502 
503  CHARACTER(CHRLEN) :: rcsidentstring
504 
505  LOGICAL :: pdecidereallocmem
506 
507  TYPE(t_global), POINTER :: global
508  TYPE(t_plag), POINTER :: pplag
509 
510 ! ******************************************************************************
511 ! Start
512 ! ******************************************************************************
513 
514  rcsidentstring = '$RCSfile: PLAG_ModReallocateMemory.F90,v $ $Revision: 1.9 $'
515 
516  global => pregion%global
517 
518  CALL registerfunction(global,'PLAG_ReallocMem',&
519  'PLAG_ModReallocateMemory.F90')
520 
521 ! ******************************************************************************
522 ! Set pointers
523 ! ******************************************************************************
524 
525  pplag => pregion%plag
526 
527 ! ******************************************************************************
528 ! Driver for memory reallocation
529 ! ******************************************************************************
530 
531  CALL plag_decidereallocmem( pregion, pdecidereallocmem )
532 
533  IF ( pdecidereallocmem .EQV. .true. ) THEN
534  CALL plag_setmaxdimensions( pregion )
535  CALL plag_reallocmem( pregion )
536 
537 ! TEMPORARY
538  WRITE(stdout,'(A,I2,2X,I10,2X,I10)') ' PLAG_ReallocMem-iReg: nPcls, nPclsMax = ',&
539  pregion%iRegionGlobal,pregion%plag%nPcls,pregion%plag%nPclsMax
540 ! END TEMPORARY
541 
542  END IF ! pDecideReallocMem
543 
544 ! ******************************************************************************
545 ! End
546 ! ******************************************************************************
547 
548  CALL deregisterfunction(global)
549 
550 END SUBROUTINE plag_reallocmemwrapper
551 
552 
553 
554 
555 
556 
557 
558 ! ******************************************************************************
559 ! End
560 ! ******************************************************************************
561 
562 END MODULE plag_modreallocatememory
563 
564 !******************************************************************************
565 !
566 ! RCS Revision history:
567 !
568 ! $Log: PLAG_ModReallocateMemory.F90,v $
569 ! Revision 1.9 2008/12/06 08:44:34 mtcampbe
570 ! Updated license.
571 !
572 ! Revision 1.8 2008/11/19 22:17:46 mtcampbe
573 ! Added Illinois Open Source License/Copyright
574 !
575 ! Revision 1.7 2007/03/20 17:37:25 fnajjar
576 ! Moved USE call for PLAG_SetMaxDimensions to new module PLAG_ModDimensions
577 !
578 ! Revision 1.6 2007/03/06 23:15:32 fnajjar
579 ! Renamed nPclsTot to nPclsMax
580 !
581 ! Revision 1.5 2006/05/02 17:47:19 fnajjar
582 ! Increased integer size in format statement
583 !
584 ! Revision 1.4 2005/12/13 23:09:09 fnajjar
585 ! Added memory allocation, copying and deallocation of cvOld,rhsSum,aivOld and arvOld to fix bug for parallel PLAG w RFLU
586 !
587 ! Revision 1.3 2004/07/29 20:03:56 fnajjar
588 ! Bug fix in PLAG_DecideReallocMem
589 !
590 ! Revision 1.2 2004/07/29 16:32:50 fnajjar
591 ! Included temporary io statement for monitoring
592 !
593 ! Revision 1.1 2004/07/28 18:59:50 fnajjar
594 ! Initial import for dynamic memory reallocation
595 !
596 !******************************************************************************
597 
598 
599 
600 
601 
602 
603 
604 
605 
606 
607 
subroutine plag_rflu_deallocmemsol(pRegion, pPlag)
subroutine plag_rflu_deallocmemtstep(pRegion, pPlag)
subroutine plag_inrt_deallocmemtstep(pRegion, pPlag)
subroutine plag_copymemory(global, pPlag, pPlagCopy)
subroutine plag_rflu_allocmemsol(pRegion, pPlag)
subroutine plag_copydimensions(global, pPlag, pPlagCopy)
subroutine registerfunction(global, funName, fileName)
Definition: ModError.F90:449
subroutine, public plag_setmaxdimensions(pRegion)
subroutine plag_inrt_allocmemtstep(pRegion, pPlag)
subroutine deregisterfunction(global)
Definition: ModError.F90:469
subroutine plag_rflu_allocmemtstep(pRegion, pPlag)
subroutine plag_decidereallocmem(pRegion, pDecideReallocMem)
subroutine, public plag_reallocmemwrapper(pRegion)