Example #1
0
def _cpui_level_iterator(cpu, amr_filename, bisection_order, maxlevel, ndim) :
    f = file(amr_filename, 'rb')
    header = read_fortran_series(f, ramses_amr_header)
    skip_fortran(f, 13)

    n_per_level = read_fortran(f, _int_type, header['nlevelmax']*header['ncpu']).reshape(( header['nlevelmax'], header['ncpu']))
    skip_fortran(f,1)
    if header['nboundary']>0 :
        skip_fortran(f,2)
        n_per_level_boundary = read_fortran(f, _int_type, header['nlevelmax']*header['nboundary']).reshape(( header['nlevelmax'], header['nboundary']))

    skip_fortran(f,2)
    if bisection_order :
        skip_fortran(f, 5)
    else :
        skip_fortran(f, 1)
    skip_fortran(f, 3)

    offset = np.array(header['ng'],dtype='f8')/2
    offset-=0.5

    for level in xrange(maxlevel or header['nlevelmax']) :

        # loop through those CPUs with grid data (includes ghost regions)
        for cpuf in 1+np.where(n_per_level[level,:]!=0)[0] :
            #print "CPU=",cpu,"CPU on disk=",cpuf,"npl=",n_per_level[level,cpuf-1]

            if cpuf==cpu :

                # this is the data we want
                skip_fortran(f,3) # grid, next, prev index

                # store the coordinates in temporary arrays. We only want
                # to copy it if the cell is not refined
                x0,y0,z0 = [read_fortran(f, _float_type, n_per_level[level,cpu-1]) for ar in range(ndim)]

                skip_fortran(f,1 # father index
                              + 2*ndim # nbor index
                              + 2*(2**ndim) # son index,cpumap,refinement map
                              )

                refine = np.array([read_fortran(f,_int_type,n_per_level[level,cpu-1]) for i in xrange(2**ndim)])

                if level==maxlevel :
                    refine[:] = 0

                x0-=offset[0]; y0-=offset[1]; z0-=offset[2]

                yield (x0,y0,z0),refine,cpuf,level


            else :

                # skip ghost regions from other CPUs
                skip_fortran(f,3+ndim+1+2*ndim+3*2**ndim)

        if header['nboundary']>0 :
            for boundaryf in np.where(n_per_level_boundary[level, :]!=0)[0] :

                        skip_fortran(f,3+ndim+1+2*ndim+3*2**ndim)
Example #2
0
 def _load_particle_cpuid(self) :
     ind0_dm = 0
     ind0_star = 0
     for i, star_mask, nstar in zip(self._cpus, self._star_mask, self._nstar) :
         f = file(self._particle_filename(i))
         header = read_fortran_series(f, ramses_particle_header)
         f.close()
         ind1_dm = ind0_dm+header['npart']-nstar
         ind1_star = ind0_star+nstar
         self.dm['cpu'][ind0_dm:ind1_dm] = i
         self.star['cpu'][ind0_star:ind1_star] = i
         ind0_dm, ind0_star = ind1_dm, ind1_star
Example #3
0
def _cpui_count_particles(filename) :
    distinguisher_field = int(particle_distinguisher[0])
    distinguisher_type = np.dtype(particle_distinguisher[1])

    f = file(filename)
    header = read_fortran_series(f, ramses_particle_header)
    npart_this = header['npart']
    try:
        skip_fortran(f,distinguisher_field)
        data = read_fortran(f,distinguisher_type,header['npart'])
    except TypeError:
        data = np.zeros(npart_this)
    
    my_mask = (data!=0)
    nstar_this = (data!=0).sum()
    return npart_this, nstar_this, my_mask
Example #4
0
def _cpui_load_particle_block(filename, dm_ar, star_ar, offset, ind0_dm, ind0_star, _type, star_mask, nstar) :
    f = file(filename)
    header = read_fortran_series(f, ramses_particle_header)

    skip_fortran(f, offset)

    ind1_dm = ind0_dm+header['npart']-nstar
    ind1_star = ind0_star+nstar

    data = read_fortran(f, _type, header['npart'])

    if len(star_mask)>0 :
        dm_ar[ind0_dm:ind1_dm]=data[~star_mask]
        star_ar[ind0_star:ind1_star]=data[star_mask]
    else :
        dm_ar[ind0_dm:ind1_dm]=data

    f.close()
Example #5
0
def _cpui_load_particle_block(filename, dm_ar, star_ar, offset, ind0_dm, ind0_star, _type, star_mask, nstar) :
    f = file(filename)
    header = read_fortran_series(f, ramses_particle_header)

    skip_fortran(f, offset)

    ind1_dm = ind0_dm+header['npart']-nstar
    ind1_star = ind0_star+nstar

    data = read_fortran(f, _type, header['npart'])
    try:
        if len(star_mask)>0 :
            dm_ar[ind0_dm:ind1_dm]=data[~star_mask]
            star_ar[ind0_star:ind1_star]=data[star_mask]
        else :
            dm_ar[ind0_dm:ind1_dm]=data
    except ValueError:
        # this translates into the data block loaded from disk not being
        # long enough
        raise IOError, "Could not load particle block"

    f.close()
Example #6
0
def _cpui_load_gas_vars(dims, maxlevel, ndim, filename, cpu, lia, i1,
                        mode = _gv_load_hydro ) :
    
    if config['verbose'] :
        print>>sys.stderr, cpu,
        sys.stderr.flush()
        
    nvar = len(dims)
    grid_info_iter = _cpui_level_iterator(*lia)

    f = file(filename)

    check_nvar_file = False

    if mode is _gv_load_hydro :
        header = read_fortran_series(f, ramses_hydro_header)
        
        nvar_file = header['nvarh']
    else :
        header = read_fortran_series(f, ramses_grav_header)
        nvar_file=4

    if nvar_file<nvar :
        warnings.warn("Fewer hydro variables are in this RAMSES dump than are defined in config.ini (expected %d, got %d in file)"%(nvar, nvar_file), RuntimeWarning)
        nvar = nvar_file
        dims = dims[:nvar]
    elif nvar_file>nvar :
        warnings.warn("More hydro variables are in this RAMSES dump than are defined in config.ini", RuntimeWarning)

    for level in xrange(maxlevel or header['nlevelmax']) :

        for cpuf in xrange(1,header['ncpu']+1) :
            flevel = read_fortran(f, 'i4')[0]
            ncache = read_fortran(f, 'i4')[0]
            assert flevel-1==level

            if ncache>0 :
                if cpuf==cpu :

                    coords, refine, gi_cpu, gi_level =  grid_info_iter.next()
                    mark = np.where(refine==0)

                    assert gi_level==level
                    assert gi_cpu==cpu

                if cpuf==cpu and len(mark[0])>0 :
                    for icel in xrange(2**ndim) :
                        i0 = i1
                        i1 = i0+(refine[icel]==0).sum()
                        for ar in dims :
                            ar[i0:i1] = read_fortran(f, _float_type, ncache)[(refine[icel]==0)]


                        skip_fortran(f, (nvar_file-nvar))

                else :
                    skip_fortran(f, (2**ndim)*nvar_file)

        for boundary in xrange(header['nboundary']) :
            flevel = read_fortran(f, 'i4')[0]
            ncache = read_fortran(f, 'i4')[0]
            if ncache>0 :
                skip_fortran(f, (2**ndim)*nvar_file)