def get_solid_velocity(bucket, data, volfrac): """Calculate the particle volume fraction using control volumes""" linear_data = IO.get_linear_block(data) is2d = linear_data.GetCell(0).GetCellType()==vtk.VTK_TRIANGLE cvs = vtp.vtkShowCVs() cvs.SetContinuity(-1) if vtk.vtkVersion.GetVTKMajorVersion()<6: cvs.SetInput(linear_data) else: cvs.SetInputData(linear_data) cvs.Update() cv_data = cvs.GetOutput() locator = vtk.vtkCellLocator() locator.SetDataSet(cv_data) locator.BuildLocator() if is2d: dim=2 else: dim=3 output = numpy.zeros((linear_data.GetNumberOfPoints(),dim)) volume = numpy.zeros(linear_data.GetNumberOfPoints()) for par in bucket.particles: index = locator.FindCell(par.pos) if index<0: continue ele, l_id = divmod(index,linear_data.GetCell(0).GetNumberOfPoints()) gid = linear_data.GetCell(ele).GetPointId(l_id) if is2d: volume[gid] += par.parameters.get_area() output[gid,:] += par.parameters.get_area()*par.vel[:dim] else: volume[gid] += par.parameters.get_volume() output[gid,:] += par.parameters.get_volume()*par.vel[:dim] for _ in range(linear_data.GetNumberOfPoints()): if volume[_]>0.0: output[_,:] = output[_,:]/volume[_] return output
def get_cv_fraction(bucket, data): """Calculate the particle volume fraction using control volumes""" linear_data = IO.get_linear_block(data) is2d = linear_data.GetCell(0).GetCellType()==vtk.VTK_TRIANGLE cvs = vtp.vtkShowCVs() cvs.SetContinuity(-1) if vtk.vtkVersion.GetVTKMajorVersion()<6: cvs.SetInput(linear_data) else: cvs.SetInputData(linear_data) cvs.Update() cv_data = cvs.GetOutput() locator = vtk.vtkCellLocator() locator.SetDataSet(cv_data) locator.BuildLocator() output = numpy.zeros(linear_data.GetNumberOfPoints()) volume = numpy.zeros(linear_data.GetNumberOfPoints()) for _ in range(linear_data.GetNumberOfCells()): cell = linear_data.GetCell(_) pntIds = cell.GetPointIds() cv_mass = IO.get_measure(cell)/cell.GetNumberOfPoints() for dummy_1 in range(pntIds.GetNumberOfIds()): volume[pntIds.GetId(dummy_1)] += cv_mass for par in bucket.particles: index = locator.FindCell(par.pos) if index<0: continue ele, l_id = divmod(index,linear_data.GetCell(0).GetNumberOfPoints()) gid = linear_data.GetCell(ele).GetPointId(l_id) if is2d: output[gid] += par.parameters.get_area() else: output[gid] += par.parameters.get_volume() return output/volume
def fpick(infile, locator,names): """ Extract fluid velocity and pressure from single .vtu file""" locator.BuildLocatorIfNeeded() cell_index = self.find_cell(locator, pos) cell = IO.get_linear_block(infile).GetCell(cell_index) linear_cell = IO.get_linear_cell(cell) pids = cell.GetPointIds() dim = linear_cell.GetNumberOfPoints()-1 upos = numpy.zeros(linear_cell.GetNumberOfPoints()) dummy_func = linear_cell.GetPoints().GetPoint args = [dummy_func(i+1)[:dim] for i in range(dim)] args.append(dummy_func(0)[:dim]) args.append(upos) linear_cell.BarycentricCoords(pos[:dim], *args) # collision == Collision.testInCell(linear_cell, pos) data_u = IO.get_vector(infile, names[0], cell_index) data_p = IO.get_scalar(infile, names[1], cell_index) shape_funs = numpy.zeros(cell.GetNumberOfPoints()) deriv_funs = numpy.zeros(dim*cell.GetNumberOfPoints()) cell.InterpolateFunctions(upos[:3], shape_funs) cell.InterpolateDerivs(upos[:3], deriv_funs) rhs = data_p[1:dim+1]-data_p[0] mat = numpy.zeros((dim, dim)) pts = numpy.array([cell.GetPoints().GetPoint(i) for i in range(dim+1)]) for i in range(dim): mat[i, :] = pts[i+1, :dim] - pts[0, :dim] # mat=la.inv(mat) mat = invert(mat) out = numpy.dot(shape_funs, data_u) grad_p = numpy.zeros(3) grad_p[:dim] = numpy.dot(mat, rhs) return out, grad_p
def get_solid_velocity(bucket, data, volfrac): """Calculate the particle volume fraction using control volumes""" linear_data = IO.get_linear_block(data) is2d = linear_data.GetCell(0).GetCellType() == vtk.VTK_TRIANGLE if is2d: dim = 2 else: dim = 3 cvs = vtp.vtkShowCVs() cvs.SetContinuity(-1) if vtk.vtkVersion.GetVTKMajorVersion() < 6: cvs.SetInput(linear_data) else: cvs.SetInputData(linear_data) cvs.Update() cv_data = cvs.GetOutput() locator = vtk.vtkCellLocator() locator.SetDataSet(cv_data) locator.BuildLocator() output = numpy.zeros((linear_data.GetNumberOfPoints(), dim)) volume = numpy.zeros(linear_data.GetNumberOfPoints()) for par in bucket.particles: index = locator.FindCell(par.pos) if index < 0: continue ele, l_id = divmod(index, linear_data.GetCell(0).GetNumberOfPoints()) gid = linear_data.GetCell(ele).GetPointId(l_id) if is2d: volume[gid] += par.parameters.get_area() output[gid, :] += par.parameters.get_area() * par.vel[:dim] else: volume[gid] += par.parameters.get_volume() output[gid, :] += par.parameters.get_volume() * par.vel[:dim] for _ in range(linear_data.GetNumberOfPoints()): if volume[_] > 0.0: output[_, :] = output[_, :] / volume[_] return output
def get_cv_fraction(bucket, data): """Calculate the particle volume fraction using control volumes""" linear_data = IO.get_linear_block(data) is2d = linear_data.GetCell(0).GetCellType() == vtk.VTK_TRIANGLE cvs = vtp.vtkShowCVs() cvs.SetContinuity(-1) if vtk.vtkVersion.GetVTKMajorVersion() < 6: cvs.SetInput(linear_data) else: cvs.SetInputData(linear_data) cvs.Update() cv_data = cvs.GetOutput() locator = vtk.vtkCellLocator() locator.SetDataSet(cv_data) locator.BuildLocator() output = numpy.zeros(linear_data.GetNumberOfPoints()) volume = numpy.zeros(linear_data.GetNumberOfPoints()) for _ in range(linear_data.GetNumberOfCells()): cell = linear_data.GetCell(_) pnt_ids = cell.GetPointIds() cv_mass = IO.get_measure(cell) / cell.GetNumberOfPoints() for dummy_1 in range(pnt_ids.GetNumberOfIds()): volume[pnt_ids.GetId(dummy_1)] += cv_mass for par in bucket: index = locator.FindCell(par.pos) if index < 0: continue ele, l_id = divmod(index, linear_data.GetCell(0).GetNumberOfPoints()) gid = linear_data.GetCell(ele).GetPointId(l_id) if is2d: output[gid] += par.parameters.get_area() else: output[gid] += par.parameters.get_volume() return output / volume