18 integer,
parameter:: n_rms=6
22 real(8):: time, out_time
31 real,
dimension(:),
allocatable:: bins, counts
32 real(8):: out_time=0.1_8
33 real:: bin_min=-12.0, bin_max=10.0, bin_delta
43 SUBROUTINE init (self, patch)
48 logical:: first_time=.true.
49 namelist /pdf_io_params/ on, verbose, out_time, nbins, bin_min, bin_max
51 call trace%begin (
'pdf_io_t%init')
56 read (io%input, pdf_io_params, iostat=iostat)
57 write (io%output, pdf_io_params)
59 allocate (bins(nbins), counts(nbins))
60 bin_delta = (bin_max-bin_min)/(nbins-1.0)
62 bins(i) = bin_min + (i-1)*bin_delta
72 self%out_time = out_time
73 if (patch%pdf_next==0d0) &
74 patch%pdf_next = out_time
75 call self%counters%init
83 SUBROUTINE update (self, patch)
87 character(len=80):: filename
88 integer:: ix, iy, iz, l(3), u(3), i, ibin, jt(2), iout, count
89 real:: dv, bin, pt(2), d, px, py, pz, ux, uy, uz, u2, rms(n_rms)
90 real(8):: v_tot, d_tot, px_tot, py_tot, pz_tot, u2_tot
94 if (patch%is_set(bits%remove))
then 95 write (stdout,*)
'WARNING: tried to count PDF of removed', patch%id
98 if (patch%is_set(bits%virtual))
then 99 write (stderr,*)
'ERROR: tried to count PDF of virtual', patch%id
102 call trace%begin (
'pdf_io_t%update')
103 if (patch%time > patch%pdf_next)
then 104 call patch%time_interval (patch%pdf_next, jt, pt)
105 deallocated = .not.
allocated(patch%irefine)
107 allocate (patch%irefine(patch%gn(1),patch%gn(2),patch%gn(3)))
108 call make_irefine (patch)
109 dv = product(patch%mesh%d)
121 if (patch%irefine(ix,iy,iz) == 0)
then 122 d = patch%mem(ix,iy,iz,patch%idx%d ,jt(1),1)*pt(1) &
123 + patch%mem(ix,iy,iz,patch%idx%d ,jt(2),1)*pt(2)
124 px = patch%mem(ix,iy,iz,patch%idx%px,jt(1),1)*pt(1) &
125 + patch%mem(ix,iy,iz,patch%idx%px,jt(2),1)*pt(2)
126 py = patch%mem(ix,iy,iz,patch%idx%py,jt(1),1)*pt(1) &
127 + patch%mem(ix,iy,iz,patch%idx%py,jt(2),1)*pt(2)
128 pz = patch%mem(ix,iy,iz,patch%idx%pz,jt(1),1)*pt(1) &
129 + patch%mem(ix,iy,iz,patch%idx%pz,jt(2),1)*pt(2)
133 u2 = ux**2 + uy**2 + uz**2
134 px_tot = px_tot + px*dv
135 py_tot = py_tot + py*dv
136 pz_tot = pz_tot + pz*dv
137 u2_tot = u2_tot + u2*dv
140 bin = (alog(d) - bin_min)/bin_delta
142 ibin = max(1,min(ibin,nbins))
143 counts(ibin) = counts(ibin) + dv
148 rms = [v_tot, d_tot, px_tot, py_tot, pz_tot, u2_tot]
151 self%rms(i) = self%rms(i) + rms(i)
154 deallocate (patch%irefine)
163 iout = nint(patch%pdf_next/pdf_io%out_time)
164 call self%counters%update (iout+1, io%nwrite, -1, count)
166 write(stdout,
'(a,i6,3f12.6,4i4,i5,2x,a)') &
167 'pdf_io_t%update: id, time, pdf_next =', patch%id, patch%time, &
168 patch%time-patch%dtime, patch%pdf_next, count, self%iout, iout, &
169 patch%level, patch%n_nbors,
'output' 175 self%time = patch%pdf_next
178 patch%pdf_next = (iout+1)*out_time
182 END SUBROUTINE update
189 SUBROUTINE output (self)
192 character(len=80):: file
194 integer,
parameter:: ioformat=1
196 call trace%begin (
'pdf_io_t%output')
202 self%iout = self%iout+1
203 write (file,
'(a,"pdf_",i5.5,"_",i5.5,".dat")') &
204 trim(io%outputname), self%iout, mpi%rank
205 open (io_unit%tmp, file=file, form=
'unformatted', status=
'unknown')
206 write (io_unit%tmp) ioformat, nbins
207 write (io_unit%tmp) self%time
208 write (io_unit%tmp) bins
209 write (io_unit%tmp) counts
210 write (io_unit%tmp) self%rms
213 write (stdout,*) trim(file)
217 END SUBROUTINE output
222 SUBROUTINE make_irefine (patch)
224 class(
link_t),
pointer:: nbor
225 class(
task_t),
pointer:: nbpatch
230 nbor => patch%link%nbor
231 do while (
associated(nbor))
233 if (nbpatch%level > patch%level+1)
then 234 write (stderr,*)
'WARNING: nbpatch w/o support =', nbpatch%id, patch%id
235 else if (nbpatch%level > patch%level)
then 236 select type (nbpatch)
238 if (patch%contains(nbpatch))
then 239 dist = (nbpatch%size-nbpatch%ds)/2d0
240 l = patch%index_only (nbpatch%position-dist)
241 u = patch%index_only (nbpatch%position+dist)
243 write(stdout,*)
'irefine: nbpatch =', &
244 nbpatch%id, nbpatch%level, l, u, product(u-l+1)
245 patch%irefine(l(1):u(1),l(2):u(2),l(3):u(3)) = 1
251 if (verbose > 0)
then 254 write(stdout,*)
'make_irefine: unrefined =', &
255 sum(1-patch%irefine(l(1):u(1),l(2):u(2),l(3):u(3))), product(u-l+1)
257 END SUBROUTINE make_irefine
Help keep track of when all patches have passed some counter, by decrementing a counter, from start to 0. Typical use:
Template module for patches, which adds pointers to memory and mesh, and number of dimensions and var...
Module to periodically output a density probability density function (PDF). The procedure assumes tha...
Module with list handling for generic class task_t objects.
Template module for tasks.