order = 1 pos = psi.elementBase(order) vel = np.zeros_like(pos) mass = np.ones(1) # perturb the control points, keeping them within the unit box pos -= 0.5 pos *= 0.5 + 0.4 * np.random.sample(pos.shape) pos += 0.5 # PyPSI voxelization options fields = {'m': None} grid = (64, 64, 64) window = ((0.0, 0.0, 0.0), (1.0, 1.0, 1.0)) tol = 0.01 psi.elementMesh(fields, pos, vel, mass, grid=grid, window=window, tol=tol) # print the error and show the figure print 'Global error = %.10e' % np.abs(np.sum(fields['m']) - 1.0) hlp.makeFigs( fields['m'], title='Example 1: Voxelization, tetrahedral and curvilinear finite elements' ) # In[ ]: ''' Example 2: Higher-order moments We can voxelize higher-order moments (up to second order) in position and velocity. They are requested in 'fields' as follows:
order = 1 pos = psi.elementBase(order) vel = np.zeros_like(pos) mass = np.ones(1) # perturb the control points, keeping them within the unit box pos -= 0.5 pos *= 0.5 + 0.4*np.random.sample(pos.shape) pos += 0.5 # PyPSI voxelization options fields = {'m': None} grid = (64, 64, 64) window = ((0.0, 0.0, 0.0), (1.0, 1.0, 1.0)) tol = 0.01 psi.elementMesh(fields, pos, vel, mass, grid=grid, window=window, tol=tol) # print the error and show the figure print 'Global error = %.10e' % np.abs(np.sum(fields['m'])-1.0) hlp.makeFigs(fields['m'], title='Example 1: Voxelization, tetrahedral and curvilinear finite elements') # In[ ]: ''' Example 2: Higher-order moments We can voxelize higher-order moments (up to second order) in position and velocity. They are requested in 'fields' as follows: 'm': the total mass in each voxel