Rocstar  1.0
Rocstar multiphysics simulation application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
RFLU_MinimumTimeStep.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: Calculate the minimum time step for all regions on all processors.
26 !
27 ! Description: First determine smallest time step and region in which it
28 ! occurs. If this smallest time step is smaller than that imposed by the
29 ! user and smaller than the user-specified lower limit, then print out
30 ! also in which cell the smallest time step occurs. This can be useful
31 ! to analyze problems, particularly with moving grids.
32 !
33 ! Input:
34 ! regions Data of all regions
35 !
36 ! Output: None.
37 !
38 ! Notes: None.
39 !
40 ! ******************************************************************************
41 !
42 ! $Id: RFLU_MinimumTimeStep.F90,v 1.14 2008/12/06 08:44:30 mtcampbe Exp $
43 !
44 ! Copyright: (c) 2002-2005 by the University of Illinois
45 !
46 ! ******************************************************************************
47 
48 SUBROUTINE rflu_minimumtimestep(regions)
49 
50  USE moddatatypes
51  USE moddatastruct, ONLY: t_region
52  USE modglobal, ONLY: t_global
53  USE moderror
54  USE modparameters
55  USE modmpi
56 
57  IMPLICIT NONE
58 
59 ! ******************************************************************************
60 ! Declarations and definitions
61 ! ******************************************************************************
62 
63 ! ==============================================================================
64 ! Arguments
65 ! ==============================================================================
66 
67  TYPE(t_region), POINTER :: regions(:)
68 
69 ! ==============================================================================
70 ! Locals
71 ! ==============================================================================
72 
73  CHARACTER(CHRLEN) :: rcsidentstring
74  INTEGER :: errorflag,icelldtmin,ireg,iregdtmin
75  INTEGER, DIMENSION(:), ALLOCATABLE :: globalvalsint,localvalsint
76  REAL(RFREAL) :: dtmin
77  REAL(RFREAL), DIMENSION(:), ALLOCATABLE :: globalvalsreal,localvalsreal
78  TYPE(t_global), POINTER :: global
79  TYPE(t_region), POINTER :: pregion
80 
81 ! ******************************************************************************
82 ! Start
83 ! ******************************************************************************
84 
85  rcsidentstring = '$RCSfile: RFLU_MinimumTimeStep.F90,v $ $Revision: 1.14 $'
86 
87  global => regions(1)%global
88 
89  CALL registerfunction(global,'RFLU_MinimumTimeStep',&
90  'RFLU_MinimumTimeStep.F90')
91 
92 ! ******************************************************************************
93 ! Compute actual time step for each region. NOTE take into account CFL number
94 ! and user-specified minimum time step
95 ! ******************************************************************************
96 
97  DO ireg = 1,global%nRegionsLocal
98  pregion => regions(ireg)
99 
100  IF ( pregion%mixtInput%frozenFlag .EQV. .false. ) THEN
101  pregion%dtMin = pregion%mixtInput%cfl*pregion%dtMin
102  pregion%dtMin = min(global%dtImposed,pregion%dtMin)
103  ELSE
104  pregion%dtMin = global%dtImposed
105  END IF ! pRegion%mixtInput%frozenFlag
106  END DO ! iReg
107 
108 ! ******************************************************************************
109 ! Determine minimum time step over all processors
110 ! ******************************************************************************
111 
112 ! ==============================================================================
113 ! Allocate temporary memory
114 ! ==============================================================================
115 
116  ALLOCATE(localvalsreal(0:global%nRegions),stat=errorflag)
117  global%error = errorflag
118  IF ( global%error /= err_none ) THEN
119  CALL errorstop(global,err_allocate,__line__,'localValsReal')
120  END IF ! global%error
121 
122  ALLOCATE(globalvalsreal(0:global%nRegions),stat=errorflag)
123  global%error = errorflag
124  IF ( global%error /= err_none ) THEN
125  CALL errorstop(global,err_allocate,__line__,'globalValsReal')
126  END IF ! global%error
127 
128 ! ==============================================================================
129 ! Peform reduction operation. NOTE need to include region index 0 to make sure
130 ! this works properly for serial runs.
131 ! ==============================================================================
132 
133  DO ireg = 0,global%nRegions
134  localvalsreal(ireg) = huge(1.0_rfreal)
135  END DO ! iReg
136 
137  DO ireg = 1,global%nRegionsLocal
138  pregion => regions(ireg)
139 
140  localvalsreal(pregion%iRegionGlobal) = pregion%dtMin
141  END DO ! iReg
142 
143  CALL mpi_allreduce(localvalsreal(0:global%nRegions), &
144  globalvalsreal(0:global%nRegions),global%nRegions+1, &
145  mpi_rfreal,mpi_min,global%mpiComm,errorflag)
146  global%error = errorflag
147  IF ( global%error /= err_none ) THEN
148  CALL errorstop(global,err_mpi_trouble,__line__)
149  END IF ! global%errorFlag
150 
151 ! ==============================================================================
152 ! Find smallest time step and store as global time step
153 ! ==============================================================================
154 
155  dtmin = huge(1.0_rfreal)
156 
157  DO ireg = 0,global%nRegions
158  IF ( globalvalsreal(ireg) < dtmin ) THEN
159  dtmin = globalvalsreal(ireg)
160  iregdtmin = ireg
161  END IF ! globalValsReal
162  END DO ! iReg
163 
164  DO ireg = 1,global%nRegionsLocal
165  regions(ireg)%global%dtMin = dtmin
166  END DO ! iReg
167 
168 ! ==============================================================================
169 ! Deallocate temporary memory
170 ! ==============================================================================
171 
172  DEALLOCATE(localvalsreal,stat=errorflag)
173  global%error = errorflag
174  IF ( global%error /= err_none ) THEN
175  CALL errorstop(global,err_deallocate,__line__,'localValsReal')
176  END IF ! global%error
177 
178  DEALLOCATE(globalvalsreal,stat=errorflag)
179  global%error = errorflag
180  IF ( global%error /= err_none ) THEN
181  CALL errorstop(global,err_deallocate,__line__,'globalValsReal')
182  END IF ! global%error
183 
184 #ifndef GENX
185 ! ******************************************************************************
186 ! Store minimum time step as system time step for coupled simulations
187 ! ******************************************************************************
188 
189  global%dTimeSystem = global%dtMin
190 #endif
191 
192 ! ******************************************************************************
193 ! If smallest time step is smaller than user-specified time step and smaller
194 ! than user-specified limit, determine in which cell this occurs. NOTE the
195 ! region in which the smallest time step occurs has already been determined
196 ! above.
197 ! ******************************************************************************
198 
199  IF ( global%dtMin < global%dtImposed .AND. &
200  global%dtMin < global%dtMinLimit ) THEN
201 
202 ! ==============================================================================
203 ! Allocate temporary memory
204 ! ==============================================================================
205 
206  ALLOCATE(localvalsint(0:global%nRegions),stat=errorflag)
207  global%error = errorflag
208  IF ( global%error /= err_none ) THEN
209  CALL errorstop(global,err_allocate,__line__,'localValsInt')
210  END IF ! global%error
211 
212  ALLOCATE(globalvalsint(0:global%nRegions),stat=errorflag)
213  global%error = errorflag
214  IF ( global%error /= err_none ) THEN
215  CALL errorstop(global,err_allocate,__line__,'globalValsInt')
216  END IF ! global%error
217 
218 ! ==============================================================================
219 ! Peform reduction operations. NOTE need to include region index 0 to make
220 ! sure this works properly for serial runs.
221 ! ==============================================================================
222 
223  DO ireg = 0,global%nRegions
224  localvalsint(ireg) = -huge(1)
225  END DO ! iReg
226 
227  DO ireg = 1,global%nRegionsLocal
228  pregion => regions(ireg)
229 
230  localvalsint(pregion%iRegionGlobal) = pregion%dtMinLoc
231  END DO ! iReg
232 
233  CALL mpi_allreduce(localvalsint(0:global%nRegions), &
234  globalvalsint(0:global%nRegions),global%nRegions+1, &
235  mpi_integer,mpi_max,global%mpiComm,errorflag)
236  global%error = errorflag
237  IF ( global%error /= err_none ) THEN
238  CALL errorstop(global,err_mpi_trouble,__line__)
239  END IF ! global%errorFlag
240 
241  IF ( global%myProcid == masterproc ) THEN
242  icelldtmin = globalvalsint(iregdtmin)
243  END IF ! global%myProcid
244 
245 ! ==============================================================================
246 ! Deallocate temporary memory
247 ! ==============================================================================
248 
249  DEALLOCATE(localvalsint,stat=errorflag)
250  global%error = errorflag
251  IF ( global%error /= err_none ) THEN
252  CALL errorstop(global,err_deallocate,__line__,'localValsInt')
253  END IF ! global%error
254 
255  DEALLOCATE(globalvalsint,stat=errorflag)
256  global%error = errorflag
257  IF ( global%error /= err_none ) THEN
258  CALL errorstop(global,err_deallocate,__line__,'globalValsInt')
259  END IF ! global%error
260 
261 ! ==============================================================================
262 ! Print information
263 ! ==============================================================================
264 
265  IF ( global%myProcid == masterproc .AND. &
266  global%verbLevel > verbose_none ) THEN
267  WRITE(stdout,'(A,1X,A)') solver_name,'Printing time step information...'
268  WRITE(stdout,'(A,3X,A,1X,E16.9)') solver_name,'Smallest time step:', &
269  global%dtMin
270  WRITE(stdout,'(A,3X,A)') solver_name,'Location of smallest time step:'
271  WRITE(stdout,'(A,5X,A,4X,I6)') solver_name,'Region:',iregdtmin
272  WRITE(stdout,'(A,5X,A,1X,I9)') solver_name,'Cell: ',icelldtmin
273  WRITE(stdout,'(A,1X,A)') solver_name, &
274  'Printing time step information done.'
275  END IF ! global%myProcid
276  END IF ! global%dtMin
277 
278 ! ******************************************************************************
279 ! End
280 ! ******************************************************************************
281 
282  CALL deregisterfunction(global)
283 
284 END SUBROUTINE rflu_minimumtimestep
285 
286 ! ******************************************************************************
287 !
288 ! RCS Revision history:
289 !
290 ! $Log: RFLU_MinimumTimeStep.F90,v $
291 ! Revision 1.14 2008/12/06 08:44:30 mtcampbe
292 ! Updated license.
293 !
294 ! Revision 1.13 2008/11/19 22:17:42 mtcampbe
295 ! Added Illinois Open Source License/Copyright
296 !
297 ! Revision 1.12 2005/11/10 22:24:04 fnajjar
298 ! ACH: Added IF on frozenFlag
299 !
300 ! Revision 1.11 2005/04/15 15:07:19 haselbac
301 ! Converted to MPI
302 !
303 ! Revision 1.10 2004/10/19 19:29:20 haselbac
304 ! Bug fix so serial Charm jobs work properly, cosmetics
305 !
306 ! Revision 1.9 2004/03/15 21:04:32 haselbac
307 ! Fixed bug for serial runs: Had incorrect region pointer
308 !
309 ! Revision 1.8 2003/10/19 01:45:53 haselbac
310 ! Changed verbosity level
311 !
312 ! Revision 1.7 2003/10/15 02:43:14 haselbac
313 ! Rewrite; print information about location of time step if below limit
314 !
315 ! Revision 1.6 2003/06/19 22:44:43 haselbac
316 ! Set global%dTimeSystem so can use it in Tbc in rungeKutta outside GENX
317 !
318 ! Revision 1.5 2003/03/15 18:39:12 haselbac
319 ! Deleted superfluous statement
320 !
321 ! Revision 1.4 2002/09/09 15:51:56 haselbac
322 ! global and mixtInput now under region
323 !
324 ! Revision 1.3 2002/07/25 14:28:49 haselbac
325 ! Added FEM call to find minimum timestep for parallel runs
326 !
327 ! Revision 1.2 2002/06/14 20:19:47 haselbac
328 ! Deleted ModLocal, changed local%nRegions to global%nRegionsLocal
329 !
330 ! Revision 1.1 2002/05/28 14:02:39 haselbac
331 ! Initial revision
332 !
333 ! ******************************************************************************
334 
335 
336 
337 
338 
339 
340 
subroutine registerfunction(global, funName, fileName)
Definition: ModError.F90:449
subroutine rflu_minimumtimestep(regions)
Vector_n min(const Array_n_const &v1, const Array_n_const &v2)
Definition: Vector_n.h:346
subroutine errorstop(global, errorCode, errorLine, addMessage)
Definition: ModError.F90:483
subroutine deregisterfunction(global)
Definition: ModError.F90:469