Debian Codegraph @

src/read_data_jjm_multiphase.f90

raw
1 !-----------------------------------------------------------------
2 !
3 ! This file is (or was) part of SPLASH, a visualisation tool
4 ! for Smoothed Particle Hydrodynamics written by Daniel Price:
5 !
6 ! http://users.monash.edu.au/~dprice/splash
7 !
8 ! SPLASH comes with ABSOLUTELY NO WARRANTY.
9 ! This is free software; and you are welcome to redistribute
10 ! it under the terms of the GNU General Public License
11 ! (see LICENSE file for details) and the provision that
12 ! this notice remains intact. If you modify this file, please
13 ! note section 2a) of the GPLv2 states that:
14 !
15 ! a) You must cause the modified files to carry prominent notices
16 ! stating that you changed the files and the date of any change.
17 !
18 ! Copyright (C) 2005-2009 Daniel Price. All rights reserved.
19 ! Contact: [email protected]
20 !
21 !-----------------------------------------------------------------
22
23 !-------------------------------------------------------------------------
24 ! this subroutine reads from the data file(s)
25 ! change this to change the format of data input
26 !
27 ! THIS VERSION IS FOR JOE'S 2D SPH CODE
28 !
29 ! the data is stored in the global array dat
30 !
31 ! >> this subroutine must return values for the following: <<
32 !
33 ! ncolumns : number of data columns
34 ! ndim, ndimV : number of spatial, velocity dimensions
35 ! nstepsread : number of steps read from this file
36 !
37 ! maxplot,maxpart,maxstep : dimensions of main data array
38 ! dat(maxplot,maxpart,maxstep) : main data array
39 !
40 ! npartoftype(1:6,maxstep) : number of particles of each type in each timestep
41 ! ntot(maxstep) : total number of particles in each timestep
42 ! iam(maxpart,maxstep): integer identification of particle type
43 !
44 ! time(maxstep) : time at each step
45 ! gamma(maxstep) : gamma at each step
46 !
47 ! most of these values are stored in global arrays
48 ! in the module 'particle_data'
49 !-------------------------------------------------------------------------
50
51 module readdata_jjmmulti
52 implicit none
53
54 public :: read_data_jjmmulti, set_labels_jjmmulti
55
56 private
57 contains
58
59 subroutine read_data_jjmmulti(rootname,indexstart,ipos,nstepsread)
60 use particle_data
61 use params
62 use settings_data, only:ndim,ndimV,ncolumns
63 use mem_allocation
64 integer, intent(IN) :: indexstart,ipos
65 integer, intent(OUT) :: nstepsread
66 character(LEN=*), intent(IN) :: rootname
67 integer :: i,j,ifile,ierr,npart,nweird,nbnd,nmud
68 integer :: istep,nprint,npart_max,nstep_max,icol,ncolstep
69 logical :: iexist
70 character(LEN=LEN(rootname)+4) :: dumpfile
71 real :: timei,dti,hi,pmass,totmass,rhozero
72
73 nstepsread = 0
74 nstep_max = 0
75 npart_max = maxpart
76 ifile = 1
77
78 dumpfile = trim(rootname)
79 if (index(dumpfile,'.plt')==0) dumpfile = trim(rootname)//'.plt'
80 !
81 !--check if first data file exists
82 !
83 inquire(file=dumpfile,exist=iexist)
84 if (.not.iexist) then
85 print "(a)",' *** error: ',trim(dumpfile),' file not found ***'
86 return
87 endif
88 !
89 !--fix number of spatial dimensions
90 !
91 ndim = 2
92 ndimV = 2
93 ncolstep = 8
94 ncolumns = 8 ! number of columns in file
95 !
96 !--allocate memory initially
97 !
98 nstep_max = max(nstep_max,indexstart,2)
99
100 j = indexstart
101 nstepsread = 0
102
103 print "(1x,a)",'reading Joe Monaghan''s multiphase code format'
104 write(*,"(26('>'),1x,a,1x,26('<'))") trim(dumpfile)
105 !
106 !--open the file and read the number of particles
107 !
108 open(unit=15,iostat=ierr,file=dumpfile,status='old',form='formatted')
109 if (ierr /= 0) then
110 print*,'*** ERROR OPENING ',trim(dumpfile),' ***'
111 else
112 !
113 !--read the number of particles in the first step,
114 ! allocate memory and rewind
115 !
116 read(15,*,end=55,iostat=ierr) istep,nprint,hi
117 print*,'first time = ',hi,' npart = ',nprint
118 if (.not.allocated(dat) .or. (nprint > npart_max)) then
119 npart_max = max(npart_max,INT(1.1*(nprint)))
120 call alloc(npart_max,nstep_max,ncolumns,mixedtypes=.true.)
121 endif
122 rewind(15)
123 endif
124 if (ierr /= 0) then
125 print*,'*** ERROR READING TIMESTEP HEADER ***'
126 else
127
128 oversteps: do
129 !
130 !--loop over the timesteps in this file
131 !
132 npart_max = max(npart_max,nprint)
133 !
134 !--allocate/reallocate memory if j > maxstep
135 !
136 if (j > maxstep) then
137 call alloc(maxpart,2*j,maxcol,mixedtypes=.true.)
138 endif
139 !
140 !--now read the timestep data in the dumpfile
141 !
142 read(15,*,end=55,iostat=ierr) istep,nprint,hi,timei,dti
143 ! read(15,*)
144 nbnd = 0
145 npart = 0
146 nweird = 0
147 nmud = 0
148 do i=1,nprint
149 read(15,*,end=55,iostat=ierr) (dat(i,icol,j),icol = 1,ncolstep),iamtype(i,j)
150 select case(iamtype(i,j))
151 case(0)
152 nbnd = nbnd + 1
153 iamtype(i,j) = 3
154 case(1)
155 npart = npart + 1
156 iamtype(i,j) = 1
157 case(2)
158 nmud = nmud + 1
159 iamtype(i,j) = 2
160 case default
161 nweird = nweird + 1
162 iamtype(i,j) = 4
163 end select
164 !print*,i,(dat(i,icol,j),icol = 1,ncolstep),iamtype(i,j)
165 !--make a fake column for mass
166 enddo
167 600 format(2x,7(e12.5),1(i5))
168 time(j) = timei
169
170 if (ierr /= 0) then
171 print*,'got to ',i,' step ',j
172 print "(a)",'|*** ERROR READING TIMESTEP ***'
173 return
174 else
175 nstepsread = nstepsread + 1
176 endif
177
178 npartoftype(:,j) = 0
179 npartoftype(1,j) = npart
180 npartoftype(2,j) = nmud
181 npartoftype(3,j) = nbnd
182 npartoftype(4,j) = nweird
183 print*,'nwater=',npart,' nmud=',nmud,' nbnd=',nbnd
184 if (nweird > 0) print*,' WARNING: ',nweird,' particles of unknown type'
185 print*,j,' time = ',time(j)
186 gamma(j) = 1.666666666667
187 j = j + 1
188
189 enddo oversteps
190 endif
191
192 55 continue
193 !
194 !--reached end of file
195 !
196 close(15)
197
198 print*,'nstepsread = ',nstepsread
199 print*,'>> end of dump file: nsteps =',j-1,'nfluid = ',npartoftype(1,j-1),'nbound=',npartoftype(2,j-1)
200
201 return
202
203 end subroutine read_data_jjmmulti
204
205 !!------------------------------------------------------------
206 !! set labels for each column of data
207 !!------------------------------------------------------------
208
209 subroutine set_labels_jjmmulti
210 use labels
211 use params
212 use settings_data
213 use geometry, only:labelcoord
214 integer :: i
215
216 if (ndim <= 0 .or. ndim > 3) then
217 print*,'*** ERROR: ndim = ',ndim,' in set_labels_jjmmulti ***'
218 return
219 endif
220 if (ndimV <= 0 .or. ndimV > 3) then
221 print*,'*** ERROR: ndimV = ',ndimV,' in set_labels_jjmmulti ***'
222 return
223 endif
224
225 do i=1,ndim
226 ix(i) = i
227 enddo
228 label(ix(1:ndim)) = labelcoord(1:ndim,1)
229 ivx = ndim+1
230 ipr = ndim+ndimV+2
231 label(ipr) = 'pressure'
232 ih = ndim+ndimV+3 ! smoothing length
233 label(ih) = 'h'
234 irho = ndim+ndimV+1 ! location of rho in data array
235 label(irho) = 'density'
236 iutherm = 0 ! thermal energy
237 ! label(iutherm) = 'u'
238 ipmass = 8 ! particle mass
239 label(ipmass) = 'particle mass'
240
241 iamvec(ivx:ivx+ndimV-1) = ivx
242 labelvec(ivx:ivx+ndimV-1) = 'v'
243 do i=1,ndimV
244 label(ivx+i-1) = 'v\d'//labelcoord(i,1)
245 enddo
246 !
247 !--set labels for each particle type
248 !
249 ntypes = 4 !!maxparttypes
250 labeltype(1) = 'fluid'
251 labeltype(2) = 'mud'
252 labeltype(3) = 'boundary'
253 labeltype(4) = 'unknown'
254
255 UseTypeInRenderings(1) = .true.
256 UseTypeInRenderings(2) = .true.
257 UseTypeInRenderings(3) = .false.
258 UseTypeInRenderings(4) = .false.
259
260 !-----------------------------------------------------------
261
262 return
263 end subroutine set_labels_jjmmulti
264 end module readdata_jjmmulti