boxsize = 1. box = ((0.0, 0.0, 0.0), (boxsize, boxsize, boxsize)) nx = ds.domain_dimensions[0] ## set voxelization options order = 1 tol = 1000 subgrid = (subgridsize, subgridsize, subgridsize) window = box fields = {'m': None} ## chunk through Lagrangian patches mtot = 0.0 tstart = time.time() for pos, vel, mass, block, nblocks in psi.elementBlocksFromGrid(pos, vel, order=order, periodic=True): ## make periodic and voxelize it psi.voxelize(fields, pos, vel, mass, tol=tol, window=window, \ grid=subgrid, periodic=True, box=box) ## bookkeeping mtot += np.sum(mass) tend = time.time() sys.stdout.write("\rVoxelized block %d of %d. Time = %.1f s" % (block, nblocks, tend-tstart)) sys.stdout.flush() print '\nGlobal error = %.10e' % np.abs(np.sum(fields['m'])/mtot-1.0) # save density data to file f = tables.open_file("density%04d_64.h5" % i, mode = 'w') f.create_array(f.root, "density", fields['m'])
velgrid = np.zeros_like(posgrid) # perturb the positions somehow posgrid[:, :, :, 1] += 0.1 * np.sin(2 * np.pi * posgrid[:, :, :, 2]) posgrid[:, :, :, 2] *= 0.5 * (1.0 + posgrid[:, :, :, 1]) # set voxelization options order = 1 tol = 0.01 grid = (128, 128, 128) fields = {'m': None} # chunk through Lagrangian blocks tstart = time.time() for pos, vel, mass, block, nblocks in psi.elementBlocksFromGrid(posgrid, velgrid, order=order): psi.elementMesh(fields, pos, vel, mass, grid=grid, tol=tol) tend = time.time() sys.stdout.write("\rVoxelized block %d of %d. Time = %.1f s" % (block, nblocks, tend - tstart)) sys.stdout.flush() # show the figure and print the fractional mass error print '\nGlobal error = %.10e' % np.abs(np.sum(fields['m']) - 1.0) hlp.makeFigs( fields['m'], title= 'Example 3: Voxelizing a grid of elements using PyPSI.elementBlocksFromGrid()'
posgrid = np.array(np.meshgrid(coord, coord, coord)).T.copy(order='C') velgrid = np.zeros_like(posgrid) # perturb the positions somehow posgrid[:,:,:,1] += 0.1*np.sin(2*np.pi*posgrid[:,:,:,2]) posgrid[:,:,:,2] *= 0.5*(1.0+posgrid[:,:,:,1]) # set voxelization options order = 1 tol = 0.01 grid = (128, 128, 128) fields = {'m': None} # chunk through Lagrangian blocks tstart = time.time() for pos, vel, mass, block, nblocks in psi.elementBlocksFromGrid(posgrid, velgrid, order=order): psi.elementMesh(fields, pos, vel, mass, grid=grid, tol=tol) tend = time.time() sys.stdout.write("\rVoxelized block %d of %d. Time = %.1f s" % (block, nblocks, tend-tstart)) sys.stdout.flush() # show the figure and print the fractional mass error print '\nGlobal error = %.10e' % np.abs(np.sum(fields['m'])-1.0) hlp.makeFigs(fields['m'], title='Example 3: Voxelizing a grid of elements using PyPSI.elementBlocksFromGrid()') # In[ ]: '''