Rocstar  1.0
Rocstar multiphysics simulation application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
RFLO_WriteRandomState.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: write state of random number generator for structured code
26 !
27 ! Description: the following solution formats are supported:
28 ! - RocfloMP ASCII
29 ! - RocfloMP binary.
30 !
31 ! Input: regions(:)%randData = state of RNG for each region
32 ! global%currentTime = physical time
33 !
34 ! Output: to file.
35 !
36 ! Notes: none.
37 !
38 !******************************************************************************
39 !
40 ! $Id: RFLO_WriteRandomState.F90,v 1.3 2008/12/06 08:44:07 mtcampbe Exp $
41 !
42 ! Copyright: (c) 2003 by the University of Illinois
43 !
44 !******************************************************************************
45 
46 SUBROUTINE rflo_writerandomstate( regions )
47 
48  USE moddatatypes
49  USE moddatastruct, ONLY : t_region
50  USE modglobal, ONLY : t_global
51  USE moderror
52  USE modmpi
53  USE modparameters
54  USE modrandom
55 
57  IMPLICIT NONE
58 
59 #include "Indexing.h"
60 
61 ! ... parameters
62  TYPE(t_region), POINTER :: regions(:)
63 
64 ! ... loop variables
65  INTEGER :: ireg, i
66 
67 ! ... local variables
68  INTEGER, PARAMETER :: n_rvar = 1
69  INTEGER, PARAMETER :: n_ivar_extra = 1
70  INTEGER, PARAMETER :: randstate_offset = n_ivar_extra+1
71  INTEGER, PARAMETER :: n_randstate = rand_total_size+n_ivar_extra
72 
73  CHARACTER(2*CHRLEN+18) :: fname, fhead
74  CHARACTER(CHRLEN) :: rcsidentstring, msg
75 
76 #ifdef MPI
77  INTEGER :: status(mpi_status_size)
78 #endif
79  INTEGER :: errorflag, randstate(n_randstate,1)
80 
81  REAL(RFREAL) :: rvar(n_rvar,1)
82 
83  TYPE(t_global), POINTER :: global
84 
85 !******************************************************************************
86 
87  global => regions(1)%global
88 
89  CALL registerfunction( global,'RFLO_WriteRandomState',&
90  'RFLO_WriteRandomState.F90' )
91 
92 ! begin -----------------------------------------------------------------------
93 
94 ! open random state file (only master proc.) ----------------------------------
95 
96  IF (global%myProcid == masterproc) THEN
97 
98  fhead = trim(global%inDir)//trim(global%casename)
99 
100  SELECT CASE(global%solutFormat)
101  CASE (format_ascii)
102  fhead = trim(fhead)//'.randa_'
103  CASE (format_binary)
104  fhead = trim(fhead)//'.randb_'
105  CASE default
106  CALL errorstop( global,err_unknown_format,&
107  __line__ )
108  END SELECT
109 
110  IF (global%flowType == flow_unsteady) THEN
111  WRITE(fname,'(A,ES11.5)') trim(fhead), global%currentTime
112  rvar(1,1) = global%currentTime
113  ELSE
114  WRITE(fname,'(A,I6.6)') trim(fhead), global%currentIter
115  rvar(1,1) = 0._rfreal
116  ENDIF
117 
118  SELECT CASE(global%solutFormat)
119  CASE (format_ascii)
120  OPEN(if_rand_state,file=fname,form= 'formatted',status='unknown', &
121  iostat=errorflag)
122  CASE (format_binary)
123  OPEN(if_rand_state,file=fname,form='unformatted',status='unknown', &
124  iostat=errorflag)
125  CASE default
126  CALL errorstop( global,err_unknown_format,&
127  __line__ )
128  END SELECT
129 
130  global%error = errorflag
131  IF (global%error /= 0) &
132  CALL errorstop( global,err_file_open,&
133  __line__,'File: '//trim(fname) )
134 
135 ! - Write time stamp to file --------------------------------------------------
136 
137  CALL rflo_writedatafilereal( global,if_rand_state,global%solutFormat, &
138  n_rvar,1,rvar )
139 
140  ENDIF ! MASTERPROC
141 
142 ! write data -----------------------------------------------------------------
143 
144  DO ireg=1,global%nRegions
145 
146 ! - copy randData into temporary array
147 
148  IF (regions(ireg)%procid == global%myProcid) THEN
149  randstate(1,1) = ireg
150  DO i=0,rand_total_size-1
151  randstate(i+randstate_offset,1) = regions(ireg)%randData%mt(i)
152  ENDDO ! i
153  ENDIF ! global%myProcid
154 
155 ! - master receives and writes data, others send them -------------------------
156 
157  IF (global%myProcid == masterproc) THEN
158 
159 #ifdef MPI
160  IF (regions(ireg)%procid /= masterproc) THEN
161 
162  CALL mpi_recv( randstate,n_randstate,mpi_integer, &
163  regions(ireg)%procid,ireg, &
164  global%mpiComm,status,global%mpierr )
165  IF (global%mpierr /=0) CALL errorstop(global,err_mpi_trouble,&
166  __line__)
167 
168  ENDIF
169 #endif
170 
171  CALL rflo_writedatafileint( global,if_rand_state,global%solutFormat, &
172  n_randstate,1,randstate )
173 
174  ELSE ! not the master
175 
176 #ifdef MPI
177  IF (regions(ireg)%procid == global%myProcid) THEN
178 
179  CALL mpi_send( randstate,n_randstate,mpi_integer,masterproc,ireg, &
180  global%mpiComm,global%mpierr )
181  IF (global%mpierr /=0) CALL errorstop(global,err_mpi_trouble,&
182  __line__)
183 
184  ENDIF
185 #endif
186 
187  ENDIF ! MASTERPROC
188 
189  ENDDO ! iReg
190 
191 ! finalize --------------------------------------------------------------------
192 
193  IF (global%myProcid == masterproc) THEN
194  CLOSE(if_rand_state,iostat=errorflag)
195  global%error = errorflag
196  IF (global%error /= 0) &
197  CALL errorstop( global,err_file_close,&
198  __line__,'File: '//trim(fname) )
199  ENDIF
200 
201 999 CONTINUE
202  CALL deregisterfunction( global )
203 
204 END SUBROUTINE rflo_writerandomstate
205 
206 !******************************************************************************
207 !
208 ! RCS Revision history:
209 !
210 ! $Log: RFLO_WriteRandomState.F90,v $
211 ! Revision 1.3 2008/12/06 08:44:07 mtcampbe
212 ! Updated license.
213 !
214 ! Revision 1.2 2008/11/19 22:17:21 mtcampbe
215 ! Added Illinois Open Source License/Copyright
216 !
217 ! Revision 1.1 2004/11/29 21:25:17 wasistho
218 ! lower to upper case
219 !
220 ! Revision 1.1 2003/11/21 22:29:02 fnajjar
221 ! Added Write capability for Random Number Generator
222 !
223 !******************************************************************************
224 
225 
226 
227 
228 
229 
230 
subroutine rflo_writerandomstate(regions)
subroutine rflo_writedatafileint(global, fileId, form, nDim1, nDim2, ivar)
subroutine registerfunction(global, funName, fileName)
Definition: ModError.F90:449
int status() const
Obtain the status of the attribute.
Definition: Attribute.h:240
blockLoc i
Definition: read.cpp:79
**********************************************************************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 errorstop(global, errorCode, errorLine, addMessage)
Definition: ModError.F90:483
subroutine rflo_writedatafilereal(global, fileId, form, nDim1, nDim2, var)
subroutine deregisterfunction(global)
Definition: ModError.F90:469