implicit none c Hydra simulation header file, should not touch this. include 'pinfo.inc' c Parameter file, this is what you want to modify! include 'pars.inc' c Particle data arrays, don't touch (cannot include this in pars.inc). include 'particledata.inc' c real sphgrid(n1d,n1d,n1d) real tmass, CurrentHubbleCt, box4kms integer iselect CALL readdata_tt(simdatafile,.true.,nobj,rm,r & ,v,hi,hei,heiii,h,dn,e,zmetal,itype) CALL readdata_tt(simdatafile,.false.,nobj,rm,r & ,v,hi,hei,heiii,h,dn,e,zmetal,itype) write (*,*) ' data read-in ' call flush(6) c CurrentHubbleCt = 100. * h100 * & sqrt(1. + omega0*(1./atime-1.) + xlambda0* & (atime**2-1.)) /atime boxkms = box100 / h100 * atime * CurrentHubbleCt box4kms = boxkms c compute density on grid using TSC interpolation iselect = 1 call tsc_density(iselect,tmass,sphgrid) write (*,*) ' tsc density: total mass = ',tmass open(unit=1,file='tscgrid_bar.d',status='unknown',form='unformatted') write (1) n1d write (1) tmass,box100,h100,atime,box4kms write (1) sphgrid close (1) write (*,*) ' step 1 ' call flush(6) c iselect = 2 call tsc_density(iselect,tmass,sphgrid) write (*,*) ' tsc density: total mass = ',tmass open(unit=1,file='tscgrid_gas.d',status='unknown',form='unformatted') write (1) n1d write (1) tmass,box100,h100,atime,box4kms write (1) sphgrid close (1) write (*,*) ' step 2 ' call flush(6) c iselect = 3 call tsc_density(iselect,tmass,sphgrid) write (*,*) ' tsc density: total mass = ',tmass open(unit=1,file='tscgrid_dark.d',status='unknown',form='unformatted') write (1) n1d write (1) tmass,box100,h100,atime,box4kms write (1) sphgrid close (1) write (*,*) ' step 3 ' call flush(6) c stop 'tsc_density written' c compute density on grid using SPH interpolation call sph_density(tmass,sphgrid) write (*,*) ' sph density: total mass = ',tmass open(unit=1,file='sphgrid.d',status='unknown',form='unformatted') write (1) n1d write (1) tmass,box100,h100,atime,box4kms write (1) sphgrid close (1) end subroutine tsc_density(iselect,tmass,sphgrid) implicit none include 'pinfo.inc' include 'pars.inc' include 'particledata.inc' c real sphgrid(n1d,n1d,n1d),rmp c compute density on rectangular grid using SPH interpolation real tmass,dx,rdx,box,box2,hh,h2,h4,hinv2,hinv3,hinv4,xx,yy,zz,xgrid,ygrid,zgrid,dx,dy,dz,dr2,q,kernel real*8 tmass8 real dxgrid,rdxgrid,norm,DensCon integer i,j,k,ii,jj,kk,ipart,ioff,ix,iy,iz integer imass integer nper integer iselect c initialize grid do k=1,n1d do j=1,n1d do i=1,n1d sphgrid(i,j,k)=0.0 enddo enddo enddo tmass = 0.0 c dxgrid = 1./float(n1d) rdxgrid = 1./dxgrid box = 1.0 box2 = 0.5*box tmass8 = tmass nper = 0 c do ipart=1,nobj if(iselect .eq. 1)then if(itype(ipart) .eq. itdark) goto 200 ! stars and gas else if (iselect .eq. 2) then if(itype(ipart) .ne. itgas) goto 200 ! gas only else if(itype(ipart) .ne. itdark) goto 200 ! dark matter only endif c if(float(ipart) .ge. float(nper)*float(nobj)/100.) then write (*,*) ' percent done = ',nper nper = nper + 5 call flush(6) endif c rmp = rm(ipart) tmass8 = tmass8 + rmp imass = imass + 1 c xx = r(1,ipart) ix = int(xx*rdxgrid) dx = xx*rdxgrid-float(ix) ix = ix+1 ii = mod(ix,n1d)+1 c yy = r(2,ipart) iy = int(yy*rdxgrid) dy = yy*rdxgrid-float(iy) iy = iy+1 jj = mod(iy,n1d)+1 c zz = r(3,ipart) iz = int(zz*rdxgrid) dz = zz*rdxgrid-float(iz) iz = iz+1 kk = mod(iz,n1d)+1 c sphgrid(ix,iy,iz) = sphgrid(ix,iy,iz)+(1.-dx)*(1.-dy)*(1.-dz)*rmp c sphgrid(ii,iy,iz) = sphgrid(ii,iy,iz)+ dx *(1.-dy)*(1.-dz)*rmp sphgrid(ix,jj,iz) = sphgrid(ix,jj,iz)+(1.-dx)* dy *(1.-dz)*rmp sphgrid(ix,iy,kk) = sphgrid(ix,iy,kk)+(1.-dx)*(1.-dy) *dz *rmp c sphgrid(ii,jj,iz) = sphgrid(ii,jj,iz)+ dx * dy *(1.-dz)*rmp sphgrid(ii,iy,kk) = sphgrid(ii,iy,kk)+ dx *(1.-dy) *dz *rmp sphgrid(ix,jj,kk) = sphgrid(ix,jj,kk)+(1.-dx) *dy *dz *rmp c sphgrid(ii,jj,kk) = sphgrid(ii,jj,kk)+ dx *dy *dz *rmp c 200 continue ! particle of right type enddo ! i=1,nobj c normalise density to mean of 1. tmass = tmass8 c$$$ tmass8 = 0.0 c$$$ do k=1,n1d c$$$ do j=1,n1d c$$$ do i=1,n1d c$$$ tmass8 = tmass8 + sphgrid(i,j,k) c$$$ enddo c$$$ enddo c$$$ enddo c convert to equivalent Hydrogen atoms/cm^3. DensCon = 10.**(alog10(munit) -3.*alog10(lunit)-alog10(m_H))*float(n1d)**3 do k=1,n1d do j=1,n1d do i=1,n1d sphgrid(i,j,k)=sphgrid(i,j,k)*DensCon enddo enddo enddo return end subroutine sph_density(tmass,sphgrid) implicit none include 'pinfo.inc' include 'pars.inc' include 'particledata.inc' c real sphgrid(n1d,n1d,n1d) real*8 tmass8 c compute density on rectangular grid using SPH interpolation real tmass,dx,rdx,box,box2,hh,h2,h4,hinv2,hinv3,hinv4,xx,yy,zz,xgrid,ygrid,zgrid,dx,dy,dz,dr2,q,kernel real dxgrid,rdxgrid,norm,DensCon integer i,j,k,ii,jj,kk,ipart,ioff,ix,iy,iz integer nper c initialize grid do k=1,n1d do j=1,n1d do i=1,n1d sphgrid(i,j,k)=0.0 enddo enddo enddo tmass8 = 0.0 c dxgrid = 1./float(n1d) rdxgrid = 1./dxgrid box = 1.0 box2 = 0.5*box nper = 0 do ipart=1,nobj if(itype(ipart) .eq. itgas)then if(float(ipart) .ge. float(nper)*float(nobj)/100.) then write (*,*) ' percent done = ',nper nper = nper + 5 call flush(6) endif tmass8 = tmass8 + rm(ipart) c hh = h(ipart) h2 = hh*hh h4 = 4.*h2 hinv2 = 1. / h2 hinv3 = hinv2 / hh c xx = r(1,ipart) ix = int(xx*rdxgrid)+1 yy = r(2,ipart) iy = int(yy*rdxgrid)+1 zz = r(3,ipart) iz = int(zz*rdxgrid)+1 ioff = int(hh*2.*rdxgrid)+2 c loop over all contributing vertices do k=iz-ioff,iz+ioff kk = k if (kk .gt. n1d) kk=kk-n1d if (kk .le. 0) kk=kk+n1d zgrid = float(kk-1)*dxgrid do j=iy-ioff,iy+ioff jj = j if (jj .gt. n1d) jj=jj-n1d if (jj .le. 0) jj=jj+n1d ygrid = float(jj-1)*dxgrid do i=ix-ioff,ix+ioff ii = i if (ii .gt. n1d) ii=ii-n1d if (ii .le. 0) ii=ii+n1d xgrid = float(ii-1)*dxgrid c test whether vertex is close enough dx = abs(xx-xgrid) if(dx .gt. box2) dx=box-dx dr2 = dx*dx if(dr2 .lt. h4)then dy = abs(yy-ygrid) if(dy .gt. box2) dy=box-dy dr2 = dr2+dy*dy if(dr2 .le. h4)then dz = abs(zz-zgrid) if(dz .gt. box2) dz=box-dz dr2 = dr2+dz*dz if(dr2 .le. h4)then q = sqrt(dr2 * hinv2) if (q .le. 1.) then kernel = (1.+q**2*(-1.5+0.75*q))/pi else kernel = 0.25*(2.-q)**3/pi endif kernel = kernel * hinv3 kernel = kernel * rm(ipart) sphgrid(ii,jj,kk) = sphgrid(ii,jj,kk) + kernel endif ! dr2< h4 endif ! dr2 < h4 endif ! dx^2