Rocstar  1.0
Rocstar multiphysics simulation application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
RFLO_WriteGrid.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 x-,y-,z-coordinates of grid nodes to file.
26 !
27 ! Description: the following grid formats are supported:
28 ! - RocfloMP ASCII
29 ! - RocfloMP binary
30 ! - HDF.
31 !
32 ! Input: regions = dimensions and coordinates of all regions
33 ! global%currentTime = physical time.
34 !
35 ! Output: to file.
36 !
37 ! Notes: additionaly, the physical time is stored at the beginning of the file
38 ! (set to zero in the case of steady flow and/or fixed grid). Only the
39 ! finest grid gets stored. All regions are written into one file.
40 !
41 !******************************************************************************
42 !
43 ! $Id: RFLO_WriteGrid.F90,v 1.3 2008/12/06 08:44:07 mtcampbe Exp $
44 !
45 ! Copyright: (c) 2001 by the University of Illinois
46 !
47 !******************************************************************************
48 
49 SUBROUTINE rflo_writegrid( regions )
50 
51  USE moddatatypes
52  USE moddatastruct, ONLY : t_region
53  USE modglobal, ONLY : t_global
56  USE moderror
57  USE modmpi
58  USE modparameters
59  IMPLICIT NONE
60 
61 #include "Indexing.h"
62 
63 ! ... parameters
64  TYPE(t_region), POINTER :: regions(:)
65 
66 ! ... loop variables
67  INTEGER :: ireg, i, j, k, n
68 
69 ! ... local variables
70  CHARACTER(2*CHRLEN+17) :: fname
71 
72 #ifdef MPI
73  INTEGER :: status(mpi_status_size)
74 #endif
75  INTEGER :: iregfile, ipc, jpc, kpc, ndim
76  INTEGER :: ipnbeg, ipnend, jpnbeg, jpnend, kpnbeg, kpnend
77  INTEGER :: inoff, ijnoff, ijkn, errorflag
78  INTEGER, ALLOCATABLE :: ivar(:,:)
79 
80  LOGICAL :: movegrid
81 
82  REAL(RFREAL), POINTER :: xyz(:,:)
83  REAL(RFREAL), ALLOCATABLE :: rvar(:,:), xyzfile(:,:)
84 
85  TYPE(t_global), POINTER :: global
86 
87 !******************************************************************************
88 
89  global => regions(1)%global
90 
91  CALL registerfunction( global,'RFLO_WriteGrid',&
92  'RFLO_WriteGrid.F90' )
93 
94 ! allocate fixed-size temporary data arrays -----------------------------------
95 
96  ALLOCATE( ivar(4,1),stat=errorflag )
97  ALLOCATE( rvar(1,1),stat=errorflag )
98  global%error = errorflag
99  IF (global%error /= 0) CALL errorstop( global,err_allocate,__line__ )
100 
101 ! open grid file (only master proc.) ------------------------------------------
102 
103  IF (global%myProcid == masterproc) THEN
104 
105  movegrid = .false.
106  DO ireg=1,global%nRegions
107  IF (regions(ireg)%mixtInput%moveGrid) movegrid = .true.
108  ENDDO
109 
110 ! - unsteady flow
111 
112  IF (global%flowType==flow_unsteady .AND. &
113  movegrid .AND. global%currentTime>0._rfreal) THEN
114  IF (global%gridFormat == format_ascii) THEN
115  WRITE(fname,'(A,1PE11.5)') trim(global%outDir)//trim(global%casename)//'.grda_', &
116  global%currentTime
117  OPEN(if_grid,file=fname,form='formatted',status='unknown', &
118  iostat=errorflag)
119  ELSE IF (global%gridFormat == format_binary) THEN
120  WRITE(fname,'(A,1PE11.5)') trim(global%outDir)//trim(global%casename)//'.grdb_', &
121  global%currentTime
122  OPEN(if_grid,file=fname,form='unformatted',status='unknown', &
123  iostat=errorflag)
124  ELSE
125  CALL errorstop( global,err_unknown_format,__line__ )
126  ENDIF
127  rvar(1,1) = global%currentTime
128 
129 ! - steady flow
130 
131  ELSE
132  IF (global%gridFormat == format_ascii) THEN
133  WRITE(fname,'(A)') trim(global%outDir)//trim(global%casename)//'.grda'
134  OPEN(if_grid,file=fname,form='formatted',status='unknown', &
135  iostat=errorflag)
136  ELSE IF (global%gridFormat == format_binary) THEN
137  WRITE(fname,'(A)') trim(global%outDir)//trim(global%casename)//'.grdb'
138  OPEN(if_grid,file=fname,form='unformatted',status='unknown', &
139  iostat=errorflag)
140  ELSE
141  CALL errorstop( global,err_unknown_format,__line__ )
142  ENDIF
143  rvar(1,1) = 0._rfreal
144  ENDIF
145 
146  global%error = errorflag
147  IF (global%error /= 0) &
148  CALL errorstop( global,err_file_open,__line__,'File: '//trim(fname) )
149 
150  ENDIF ! MASTERPROC
151 
152 ! write time to file ----------------------------------------------------------
153 
154  IF (global%myProcid == masterproc) THEN
155  CALL rflo_writedatafilereal( global,if_grid,global%gridFormat,1,1,rvar )
156  ENDIF
157 
158 ! write grid data -------------------------------------------------------------
159 
160  DO ireg=1,global%nRegions
161 
162 ! - allocate memory for data field
163 
164  IF (regions(ireg)%procid==global%myProcid .OR. &
165  global%myProcid==masterproc) THEN
166  ndim = (regions(ireg)%levels(1)%grid%ipc+1)* &
167  (regions(ireg)%levels(1)%grid%jpc+1)* &
168  (regions(ireg)%levels(1)%grid%kpc+1)
169  ALLOCATE( xyzfile(3,ndim),stat=errorflag )
170  global%error = errorflag
171  IF (global%error /= 0) CALL errorstop( global,err_allocate,__line__ )
172  ENDIF
173 
174 ! - copy grid into data structure
175 
176  IF (regions(ireg)%procid == global%myProcid) THEN
177  CALL rflo_getdimensphysnodes( regions(ireg),1,ipnbeg,ipnend, &
178  jpnbeg,jpnend,kpnbeg,kpnend )
179  CALL rflo_getnodeoffset( regions(ireg),1,inoff,ijnoff )
180  xyz => regions(ireg)%levels(1)%grid%xyz
181 
182  n = 0
183  DO k=kpnbeg,kpnend
184  DO j=jpnbeg,jpnend
185  DO i=ipnbeg,ipnend
186  n = n + 1
187  ijkn = indijk(i,j,k,inoff,ijnoff)
188  xyzfile(1,n) = xyz(xcoord,ijkn)
189  xyzfile(2,n) = xyz(ycoord,ijkn)
190  xyzfile(3,n) = xyz(zcoord,ijkn)
191  ENDDO
192  ENDDO
193  ENDDO
194  ENDIF
195 
196 ! - write region number and dimensions (only master)
197 
198  IF (global%myProcid == masterproc) THEN
199  ivar(1,1) = ireg
200  ivar(2,1) = regions(ireg)%levels(1)%grid%ipc
201  ivar(3,1) = regions(ireg)%levels(1)%grid%jpc
202  ivar(4,1) = regions(ireg)%levels(1)%grid%kpc
203  CALL rflo_writedatafileint( global,if_grid,global%gridFormat,4,1,ivar )
204  ENDIF
205 
206 ! - master receives and writes data, others send them
207 
208  IF (global%myProcid == masterproc) THEN
209 #ifdef MPI
210  IF (regions(ireg)%procid /= masterproc) THEN
211  CALL mpi_recv( xyzfile,3*ndim,mpi_rfreal,regions(ireg)%procid,ireg, &
212  global%mpiComm,status,global%mpierr )
213  IF (global%mpierr /=0 ) CALL errorstop( global,err_mpi_trouble,__line__ )
214  ENDIF
215 #endif
216  CALL rflo_writedatafilereal( global,if_grid,global%gridFormat,3,ndim, &
217  xyzfile )
218 
219  ELSE ! not the master
220 #ifdef MPI
221  IF (regions(ireg)%procid == global%myProcid) THEN
222  CALL mpi_send( xyzfile,3*ndim,mpi_rfreal,masterproc,ireg, &
223  global%mpiComm,global%mpierr )
224  IF (global%mpierr /=0 ) CALL errorstop( global,err_mpi_trouble,__line__ )
225  ENDIF
226 #endif
227  ENDIF
228 
229  IF (ALLOCATED(xyzfile)) THEN
230  DEALLOCATE( xyzfile,stat=errorflag )
231  global%error = errorflag
232  IF (global%error /= 0) CALL errorstop( global,err_deallocate,__line__ )
233  ENDIF
234 
235  ENDDO ! iReg
236 
237 ! finalize --------------------------------------------------------------------
238 
239  IF (global%myProcid == masterproc) THEN
240  CLOSE(if_grid,iostat=errorflag)
241  global%error = errorflag
242  IF (global%error /= 0) &
243  CALL errorstop( global,err_file_close,__line__,'File: '//trim(fname) )
244  ENDIF
245 
246  CALL deregisterfunction( global )
247 
248 END SUBROUTINE rflo_writegrid
249 
250 !******************************************************************************
251 !
252 ! RCS Revision history:
253 !
254 ! $Log: RFLO_WriteGrid.F90,v $
255 ! Revision 1.3 2008/12/06 08:44:07 mtcampbe
256 ! Updated license.
257 !
258 ! Revision 1.2 2008/11/19 22:17:21 mtcampbe
259 ! Added Illinois Open Source License/Copyright
260 !
261 ! Revision 1.1 2004/11/29 21:25:17 wasistho
262 ! lower to upper case
263 !
264 ! Revision 1.12 2003/11/20 16:40:34 mdbrandy
265 ! Backing out RocfluidMP changes from 11-17-03
266 !
267 ! Revision 1.9 2003/05/15 02:57:01 jblazek
268 ! Inlined index function.
269 !
270 ! Revision 1.8 2002/10/23 18:43:24 jblazek
271 ! Changed temporary pointer arrays into allocatable arrays
272 ! in grid and solution I/O routines.
273 !
274 ! Revision 1.7 2002/10/12 03:20:50 jblazek
275 ! Replaced [io]stat=global%error with local errorFlag for Rocflo.
276 !
277 ! Revision 1.6 2002/09/20 22:22:35 jblazek
278 ! Finalized integration into GenX.
279 !
280 ! Revision 1.5 2002/09/05 17:40:19 jblazek
281 ! Variable global moved into regions().
282 !
283 ! Revision 1.4 2002/06/07 16:40:36 jblazek
284 ! Grid & solution for all regions in one file.
285 !
286 ! Revision 1.3 2002/02/21 23:25:04 jblazek
287 ! Blocks renamed as regions.
288 !
289 ! Revision 1.2 2002/01/08 22:09:16 jblazek
290 ! Added calculation of face vectors and volumes.
291 !
292 ! Revision 1.1 2001/12/22 00:09:37 jblazek
293 ! Added routines to store grid and solution.
294 !
295 !******************************************************************************
296 
297 
298 
299 
300 
301 
302 
**********************************************************************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 jpnbeg
subroutine rflo_writedatafileint(global, fileId, form, nDim1, nDim2, ivar)
j indices k indices k
Definition: Indexing.h:6
**********************************************************************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 kpnbeg
subroutine registerfunction(global, funName, fileName)
Definition: ModError.F90:449
int status() const
Obtain the status of the attribute.
Definition: Attribute.h:240
**********************************************************************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 jpnend
subroutine rflo_getnodeoffset(region, iLev, iNodeOffset, ijNodeOffset)
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 ipnbeg
**********************************************************************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
const NT & n
subroutine rflo_writegrid(regions)
subroutine rflo_getdimensphysnodes(region, iLev, ipnbeg, ipnend, jpnbeg, jpnend, kpnbeg, kpnend)
j indices j
Definition: Indexing.h:6
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
**********************************************************************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 ipnend