Rocstar  1.0
Rocstar multiphysics simulation application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
RFLO_ModRestartInfo.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 for restart info routines
26 !
27 ! Description: None.
28 !
29 ! ******************************************************************************
30 !
31 ! $Id: RFLO_ModRestartInfo.F90,v 1.5 2008/12/06 08:44:17 mtcampbe Exp $
32 !
33 ! Copyright: (c) 2004 by the University of Illinois
34 !
35 ! ******************************************************************************
36 
38 
39  USE modglobal, ONLY : t_global
40  USE moddatastruct, ONLY: t_region
41  USE modgrid, ONLY : t_grid
42  USE modbndpatch, ONLY : t_patch
43  USE modparameters
44  USE moddatatypes
45  USE moderror
46  USE modmpi
47 
48  IMPLICIT NONE
49 
50  PRIVATE
51  PUBLIC :: rflo_readrestartinfo, &
53 
54 ! private : RFLO_OpenRestartInfo
55 ! RFLO_CloseRestartInfo
56 
57 ! ******************************************************************************
58 ! Declarations and definitions
59 ! ******************************************************************************
60 
61  CHARACTER(CHRLEN) :: RCSIdentString = &
62  '$RCSfile: RFLO_ModRestartInfo.F90,v $ $Revision: 1.5 $'
63 
64 ! ******************************************************************************
65 ! Routines
66 ! ******************************************************************************
67 
68  CONTAINS
69 
70 ! ******************************************************************************
71 !
72 ! Purpose: Open restart file.
73 !
74 ! Description: None.
75 !
76 ! Input:
77 ! global Pointer to global data
78 ! filePosition Position at which file to be opened (start or end)
79 !
80 ! Output:
81 ! fileExists Logical indicating whether file exists
82 !
83 ! Notes:
84 ! 1. The filePosition parameter is needed because the restart info file
85 ! is opened with two goals. The first is to open it with the goal of
86 ! getting the last output iteration or time (ReadRestartInfo).
87 ! The second is to be able to write to it by appending additional
88 ! lines (WriteRestartInfo).
89 ! 2. The fileExists parameter is needed because if the file exists
90 ! on restarting the code, it will need to be read to determine the
91 ! last output iteration or time.
92 !
93 ! ******************************************************************************
94 
95 SUBROUTINE rflo_openrestartinfo(global,filePosition,fileExists)
96 
98 
99 ! *****************************************************************************
100 ! Declarations and definitions
101 ! *****************************************************************************
102 
103 ! =============================================================================
104 ! Arguments
105 ! =============================================================================
106 
107  INTEGER, INTENT(IN) :: fileposition
108  TYPE(t_global), POINTER :: global
109 
110  LOGICAL, INTENT(OUT) :: fileexists
111 
112 ! =============================================================================
113 ! Locals
114 ! =============================================================================
115 
116  CHARACTER(CHRLEN) :: ifilename
117  INTEGER :: errorflag
118 
119 ! *****************************************************************************
120 ! Start
121 ! *****************************************************************************
122 
123  CALL registerfunction(global,'RFLO_OpenRestartInfo',&
124  'RFLO_ModRestartInfo.F90')
125 
126  IF ( global%myProcid == masterproc .AND. &
127  global%verbLevel > verbose_low ) THEN
128  WRITE(stdout,'(A,1X,A)') solver_name, &
129  'Opening restart info file...'
130  END IF ! global%verbLevel
131 
132 ! =============================================================================
133 ! Open file
134 ! =============================================================================
135 
136  CALL buildfilenameplain(global,filedest_outdir,'.rin',ifilename)
137 
138  INQUIRE(file=ifilename,exist=fileexists)
139 
140  IF ( fileexists .EQV. .true. ) THEN
141  IF ( fileposition == file_position_start ) THEN
142  OPEN(if_restinfo,file=ifilename,form='FORMATTED',status='OLD', &
143  iostat=errorflag)
144  ELSE IF ( fileposition == file_position_end ) THEN
145  OPEN(if_restinfo,file=ifilename,form='FORMATTED',status='OLD', &
146  position='APPEND',iostat=errorflag)
147  ELSE
148  CALL errorstop(global,err_reached_default,&
149  __line__)
150  END IF ! filePosition
151  ELSE
152  OPEN(if_restinfo,file=ifilename,form='FORMATTED',status='NEW', &
153  iostat=errorflag)
154  END IF ! file
155 
156  global%error = errorflag
157  IF ( global%error /= 0 ) THEN
158  CALL errorstop(global,err_file_open,&
159  __line__,'File: '//trim(ifilename))
160  END IF ! global%error
161 
162 ! *****************************************************************************
163 ! End
164 ! *****************************************************************************
165 
166  IF ( global%myProcid == masterproc .AND. &
167  global%verbLevel > verbose_low ) THEN
168  WRITE(stdout,'(A,1X,A)') solver_name, &
169  'Opening restart info file done.'
170  END IF ! global%verbLevel
171 
172  CALL deregisterfunction(global)
173 
174 END SUBROUTINE rflo_openrestartinfo
175 
176 
177 ! ******************************************************************************
178 !
179 ! Purpose: Close restart info file.
180 !
181 ! Description: None.
182 !
183 ! Input:
184 ! global Pointer to global data
185 !
186 ! Output: None.
187 !
188 ! Notes: None.
189 !
190 ! ******************************************************************************
191 
192 SUBROUTINE rflo_closerestartinfo(global)
193 
195 
196 ! *****************************************************************************
197 ! Declarations and definitions
198 ! *****************************************************************************
199 
200 ! =============================================================================
201 ! Arguments
202 ! =============================================================================
203 
204  TYPE(t_global), POINTER :: global
205 
206 ! =============================================================================
207 ! Locals
208 ! =============================================================================
209 
210  CHARACTER(CHRLEN) :: ifilename
211  INTEGER :: errorflag
212 
213 ! *****************************************************************************
214 ! Start
215 ! *****************************************************************************
216 
217  CALL registerfunction(global,'RFLO_CloseRestartInfo',&
218  'RFLO_ModRestartInfo.F90')
219 
220  IF ( global%myProcid == masterproc .AND. &
221  global%verbLevel > verbose_low ) THEN
222  WRITE(stdout,'(A,1X,A)') solver_name,'Closing restart info file...'
223  END IF ! global%verbLevel
224 
225 ! =============================================================================
226 ! Close file
227 ! =============================================================================
228 
229  CALL buildfilenameplain(global,filedest_outdir,'.rin',ifilename)
230 
231  CLOSE(if_restinfo,iostat=errorflag)
232  global%error = errorflag
233  IF ( global%error /= 0 ) THEN
234  CALL errorstop(global,err_file_close,&
235  __line__,'File: '//trim(ifilename))
236  END IF ! global%error
237 
238 ! *****************************************************************************
239 ! End
240 ! *****************************************************************************
241 
242  IF ( global%myProcid == masterproc .AND. &
243  global%verbLevel > verbose_low ) THEN
244  WRITE(stdout,'(A,1X,A)') solver_name,'Closing restart info file done.'
245  END IF ! global%verbLevel
246 
247  CALL deregisterfunction(global)
248 
249 END SUBROUTINE rflo_closerestartinfo
250 
251 
252 ! ******************************************************************************
253 !
254 ! Purpose: Read restart info file to get last output iteration or time.
255 !
256 ! Description: None.
257 !
258 ! Input:
259 ! global Pointer to global data
260 !
261 ! Output: None.
262 !
263 ! Notes: None.
264 !
265 ! ******************************************************************************
266 
267 SUBROUTINE rflo_readrestartinfo(global)
268 
269 ! ******************************************************************************
270 ! Declarations and definitions
271 ! ******************************************************************************
272 
273 ! ==============================================================================
274 ! Arguments
275 ! ==============================================================================
276 
277  TYPE(t_global), POINTER :: global
278 
279 ! ==============================================================================
280 ! Locals
281 ! ==============================================================================
282 
283  LOGICAL :: fileexists
284  INTEGER :: dummyinteger,errorflag
285  REAL(RFREAL) :: dummyrfreal
286 
287 ! ******************************************************************************
288 ! Start
289 ! ******************************************************************************
290 
291  CALL registerfunction(global,'RFLO_ReadRestartInfo',&
292  'RFLO_ModRestartInfo.F90')
293 
294  IF ( global%myProcid == masterproc .AND. &
295  global%verbLevel > verbose_none ) THEN
296  WRITE(stdout,'(A,1X,A)') solver_name, &
297  'Reading restart info file...'
298  END IF ! global%verbLevel
299 
300 ! ==============================================================================
301 ! Open file
302 ! ==============================================================================
303 
304  CALL rflo_openrestartinfo(global,file_position_start,fileexists)
305 
306 ! ==============================================================================
307 ! Set or read restart iteration or time
308 ! ==============================================================================
309 
310  IF ( global%flowType == flow_steady ) THEN ! steady flow
311  global%currentIter = 0
312 
313  IF ( fileexists .EQV. .true. ) THEN
314  DO
315  READ(if_restinfo,*,iostat=errorflag) dummyinteger
316 
317  IF ( errorflag /= err_none ) THEN
318  EXIT
319  ELSE
320  global%currentIter = dummyinteger
321  END IF ! errorFlag
322  END DO ! <empty>
323  END IF ! fileExists
324  ELSE ! unsteady flow
325  global%currentTime = 0.0_rfreal
326 
327  IF ( fileexists .EQV. .true. ) THEN
328  DO
329  READ(if_restinfo,*,iostat=errorflag) dummyrfreal
330 
331  IF ( errorflag /= err_none ) THEN
332  EXIT
333  ELSE
334  global%currentTime = dummyrfreal
335  global%timeStamp = global%currentTime
336  END IF ! errorFlag
337  END DO ! <empty>
338  END IF ! fileExists
339  END IF ! global%flowType
340 
341 ! ==============================================================================
342 ! Write info
343 ! ==============================================================================
344 
345  IF ( global%myProcid == masterproc .AND. &
346  global%verbLevel > verbose_low ) THEN
347  IF ( global%flowType == flow_steady ) THEN
348  WRITE(stdout,'(A,3X,A,1X,I6.6)') solver_name, &
349  'Restart iteration:',global%currentIter
350  ELSE
351  WRITE(stdout,'(A,3X,A,1X,1PE11.5)') solver_name, &
352  'Restart time:',global%currentTime
353  END IF ! global%flowType
354  END IF ! global%myProcid
355 
356 ! ==============================================================================
357 ! Close file
358 ! ==============================================================================
359 
360  CALL rflo_closerestartinfo(global)
361 
362 ! ******************************************************************************
363 ! End
364 ! ******************************************************************************
365 
366  IF ( global%myProcid == masterproc .AND. &
367  global%verbLevel > verbose_none ) THEN
368  WRITE(stdout,'(A,1X,A)') solver_name, &
369  'Reading restart info file done.'
370  END IF ! global%verbLevel
371 
372  CALL deregisterfunction(global)
373 
374 END SUBROUTINE rflo_readrestartinfo
375 
376 
377 !******************************************************************************
378 !
379 ! Purpose: Write iteration or time to restart info file.
380 !
381 ! Description: None.
382 !
383 ! Input:
384 ! global Pointer to global data
385 !
386 ! Output: None.
387 !
388 ! Notes:
389 ! 1. Only master process writes to file.
390 ! 2. Every time write to file, open and close it to make sure always have
391 ! latest data in file.
392 !
393 !******************************************************************************
394 
395 SUBROUTINE rflo_writerestartinfo(global)
396 
397 ! *****************************************************************************
398 ! Declarations and definitions
399 ! *****************************************************************************
400 
401 ! =============================================================================
402 ! Arguments
403 ! =============================================================================
404 
405  TYPE(t_global), POINTER :: global
406 
407 ! =============================================================================
408 ! Locals
409 ! =============================================================================
410 
411  LOGICAL :: dummylogical
412 
413 ! *****************************************************************************
414 ! Start
415 ! *****************************************************************************
416 
417  CALL registerfunction(global,'RFLO_WriteRestartInfo',&
418  'RFLO_ModRestartInfo.F90')
419 
420 ! =============================================================================
421 ! Write restart info to file
422 ! =============================================================================
423 
424  IF ( global%myProcid == masterproc ) THEN
425  CALL rflo_openrestartinfo(global,file_position_end,dummylogical)
426 
427  IF ( global%flowType == flow_steady ) THEN
428  WRITE(if_restinfo,*) global%currentIter
429  ELSE
430  WRITE(if_restinfo,*) global%currentTime
431  END IF ! global%flowType
432 
433  CALL rflo_closerestartinfo(global)
434  END IF ! global%myProcid
435 
436 ! *****************************************************************************
437 ! End
438 ! *****************************************************************************
439 
440  CALL deregisterfunction(global)
441 
442 END SUBROUTINE rflo_writerestartinfo
443 
444 
445 ! ******************************************************************************
446 ! End
447 ! ******************************************************************************
448 
449 END MODULE rflo_modrestartinfo
450 
451 ! ******************************************************************************
452 !
453 ! RCS Revision history:
454 !
455 ! $Log: RFLO_ModRestartInfo.F90,v $
456 ! Revision 1.5 2008/12/06 08:44:17 mtcampbe
457 ! Updated license.
458 !
459 ! Revision 1.4 2008/11/19 22:17:28 mtcampbe
460 ! Added Illinois Open Source License/Copyright
461 !
462 ! Revision 1.3 2006/04/07 15:19:17 haselbac
463 ! Removed tabs
464 !
465 ! Revision 1.2 2006/02/04 03:59:11 wasistho
466 ! global%timeStamp copied from currentTime in ReadRestartInfo
467 !
468 ! Revision 1.1 2006/02/01 20:03:51 wasistho
469 ! initial import
470 !
471 !
472 !
473 ! ******************************************************************************
474 
475 
476 
477 
478 
479 
480 
481 
482 
483 
subroutine rflo_closerestartinfo(global)
subroutine registerfunction(global, funName, fileName)
Definition: ModError.F90:449
int status() const
Obtain the status of the attribute.
Definition: Attribute.h:240
subroutine, public rflo_writerestartinfo(global)
subroutine buildfilenameplain(global, dest, ext, fileName)
**********************************************************************Rocstar Simulation Suite Illinois Rocstar LLC All rights reserved ****Illinois Rocstar LLC IL **www illinoisrocstar com **sales illinoisrocstar com WITHOUT WARRANTY OF ANY **EXPRESS OR INCLUDING BUT NOT LIMITED TO THE WARRANTIES **OF FITNESS FOR A PARTICULAR PURPOSE AND **NONINFRINGEMENT IN NO EVENT SHALL THE CONTRIBUTORS OR **COPYRIGHT HOLDERS BE LIABLE FOR ANY DAMAGES OR OTHER WHETHER IN AN ACTION OF TORT OR **Arising OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE **USE OR OTHER DEALINGS WITH THE SOFTWARE **********************************************************************INTERFACE SUBROUTINE form
subroutine, public rflo_readrestartinfo(global)
subroutine rflo_openrestartinfo(global, filePosition, fileExists)
subroutine errorstop(global, errorCode, errorLine, addMessage)
Definition: ModError.F90:483
subroutine deregisterfunction(global)
Definition: ModError.F90:469