Advertisement
Guest User

Untitled

a guest
Feb 20th, 2017
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. !! Reads a mameclot file : Units must have been converted to kpc and Ms before !
  3. subroutine load_mameclot
  4.   use amr_commons
  5.   use pm_commons
  6.  
  7.   implicit none
  8. #ifndef WITHOUTMPI
  9.   include 'mpif.h'
  10. #endif
  11.  
  12.   logical :: ok
  13.   integer :: i, ipart
  14.   character (len=128) :: filename
  15.  
  16.   integer  :: nparts, icpu, info
  17.   real(dp) :: tot_mass
  18.   real(dp), dimension(1:1, 1:3) :: xx_dp
  19.   real(dp) :: mm1, xx1, xx2, xx3, vv1, vv2, vv3
  20.   real(dp) :: scale_l, scale_m, scale_d, scale_v, tmp
  21.   integer, dimension(1:nvector)::cc
  22.   integer(i8b),dimension(1:ncpu)::npart_cpu,npart_all
  23.   logical eof
  24.  
  25.   ! Getting the units for the conversion
  26.   call units(scale_l, tmp, scale_d, scale_v, tmp, tmp)
  27.  
  28.   ! Mass conversion
  29.   scale_m = scale_d * scale_l**3
  30.  
  31.   ! Converting boxlen to user units
  32.   write(6,*) 'Mameclot reader. Converting boxlen to user units'
  33.   boxlen = boxlen / scale_l
  34.   write(6,*) 'Boxlen = ', boxlen
  35.  
  36.   ipart = 0
  37.  
  38.   if (TRIM(initfile(levelmin)) /= ' ') then
  39.      ! Opening data file
  40.      filename = TRIM(initfile(levelmin))
  41.  
  42.      inquire(file=filename, exist=ok)
  43.      if (.not. ok) then
  44.         write(*,*) 'No file'//filename
  45.         RETURN
  46.      end if
  47.  
  48.      eof = .false.
  49.  
  50.      ! Now we read the data
  51.      open(unit=1, file=filename, action='read', form='formatted')
  52.      
  53.      ! Distributing particles over processors
  54.      i = 1
  55.      do
  56.         read(1, *, end=100) mm1, xx_dp(1, 1), xx_dp(1, 2), xx_dp(1, 3), vv1, vv2, vv3
  57.  
  58.         ! Rescaling to user units
  59.         mm1   = mm1   / scale_m
  60.         xx_dp = xx_dp / scale_l
  61.         vv1   = vv1   / scale_v
  62.         vv2   = vv2   / scale_v
  63.         vv3   = vv3   / scale_v
  64.  
  65.         call cmp_cpumap(xx_dp, cc, 1)
  66.  
  67.         ! Completely inefficient !
  68.         ! TODO : rework that !
  69.         if (cc(1) == myid) then
  70.            ipart = ipart + 1
  71.            if (ipart .ge. size(mp)) then
  72.               write(*,*) "For ", myid, ipart, " exceeds ", size(mp)
  73.               call clean_stop
  74.            end if
  75.            xp(ipart,1:3) = xx_dp(1,1:3) + boxlen * 0.5
  76.            vp(ipart,1)   = vv1
  77.            vp(ipart,2)   = vv2
  78.            vp(ipart,3)   = vv3
  79.            mp(ipart)     = mm1
  80.            levelp(ipart) = levelmin
  81.            idp(ipart)    = i
  82.         endif
  83.  
  84.         i = i + 1
  85.      end do
  86. 100  continue
  87.      
  88.      npart = ipart
  89.      if (myid == 1) then
  90.         write(6,*) 'Mameclot reader, ', i-1, 'particles found'
  91.      end if
  92.  
  93.      npart_cpu=0; npart_all=0
  94.      npart_cpu(myid)=npart
  95. #ifndef WITHOUTMPI
  96. #ifndef LONGINT
  97.      call MPI_ALLREDUCE(npart_cpu,npart_all,ncpu,MPI_INTEGER,MPI_SUM,MPI_COMM_RAMSES,info)
  98. #else
  99.      call MPI_ALLREDUCE(npart_cpu,npart_all,ncpu,MPI_INTEGER8,MPI_SUM,MPI_COMM_RAMSES,info)
  100. #endif
  101.      npart_cpu(1)=npart_all(1)
  102. #endif
  103.      do icpu=2,ncpu
  104.         npart_cpu(icpu)=npart_cpu(icpu-1)+npart_all(icpu)
  105.      end do
  106.      write(*,*)'npart=',npart,'/',npartmax
  107.      call flush(6)
  108.   end if
  109.  
  110. end subroutine load_mameclot
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement