예제 #1
0
def sample_vtk(file,
               p1=None,
               p2=None,
               x_c=0,
               N_points=101,
               solver=None,
               verbose=True):
    """
    Samples velocity field in a given VTK file, along a line defined with p1 and p2, or x_c.
    :param file: Path to the VTK file
    :type file: str
    :param p1: Coordinates of the starting point of the sample line. Can be either 2D or 3D [x, y] or [x, y, z]
    :type p1: list
    :param p2: Coordinates of the ending point of the sample line. Can be either 2D or 3D [x, y] or [x, y, z]
    :type p2: list
    :param x_c: If p1 and p2 are not provided, this parameter serves the x coordinate of the vertical line.
    :type x_c: float
    :param N_points: The number of points to sample the velocity in.
    :type N_points: int
    """
    if verbose:
        print 'Sampling a VTK file: {}'.format(file)

    solver = solver or postprocess.determineSolver(file)
    if type(file) == str:
        vtkFile = vtkextract.vtkFile()
        vtkFile.solver = solver
        vtkFile.readFile(file, verbose=False)
    else:
        vtkFile = file

    centers = vtkFile.getCenters()
    vtkFile.getVolumes()
    bounds = vtkFile.bounds

    p1 = p1 or [x_c, 0, -1]
    p2 = p2 or [x_c, 0, np.max(bounds[:, 4:])]

    if len(p1) == 2: p1.insert(1, 0)  #if 2D data is provided
    if len(p2) == 2: p2.insert(1, 0)

    line = vtk.vtkLineSource()
    line.SetResolution(N_points - 1)
    line.SetPoint1(p1)
    line.SetPoint2(p2)

    probe = vtk.vtkProbeFilter()
    probe.SetInputConnection(line.GetOutputPort())
    probe.SetSourceConnection(vtkFile.outputPort)

    probe.Update()
    probe = probe.GetOutput()

    vel = probe.GetPointData().GetArray(vtkFile.velArray[solver])
    vel = np.array([vel.GetTuple(j) for j in range(probe.GetNumberOfPoints())])
    line = np.array(
        [probe.GetPoint(j) for j in range(probe.GetNumberOfPoints())])

    return line, vel
예제 #2
0
def sample_ensight(file, p1=None, p2=None, resolution=100, solver='TruchasEnSight', vtkFile=None):
    vtkFile = vtkextract.vtkFile()
    vtkFile.solver = solver
    vtkFile.sim='3D'
    
    ts = enSightTimeSteps(file)
    vtkFile.readFile(file, ts=ts-1)
    
    return sample_vtk(vtkFile, p1, p2, resolution, solver)
예제 #3
0
def sample_vtk(file, p1=None, p2=None, x_c=0, N_points=101, solver=None, verbose=True):
    """
    Samples velocity field in a given VTK file, along a line defined with p1 and p2, or x_c.
    :param file: Path to the VTK file
    :type file: str
    :param p1: Coordinates of the starting point of the sample line. Can be either 2D or 3D [x, y] or [x, y, z]
    :type p1: list
    :param p2: Coordinates of the ending point of the sample line. Can be either 2D or 3D [x, y] or [x, y, z]
    :type p2: list
    :param x_c: If p1 and p2 are not provided, this parameter serves the x coordinate of the vertical line.
    :type x_c: float
    :param N_points: The number of points to sample the velocity in.
    :type N_points: int
    """
    if verbose:
        print 'Sampling a VTK file: {}'.format(file)

    solver=solver or postprocess.determineSolver(file)
    if type(file) == str:
        vtkFile = vtkextract.vtkFile()
        vtkFile.solver = solver
        vtkFile.readFile(file, verbose=False)
    else:
        vtkFile = file
    
    centers = vtkFile.getCenters()
    vtkFile.getVolumes()
    bounds = vtkFile.bounds
        
    p1 = p1 or [x_c, 0, -1]
    p2 = p2 or [x_c, 0, np.max(bounds[:, 4:])]
    
    if len(p1) == 2: p1.insert(1, 0)  #if 2D data is provided
    if len(p2) == 2: p2.insert(1, 0)

    line = vtk.vtkLineSource()
    line.SetResolution(N_points - 1)
    line.SetPoint1(p1)
    line.SetPoint2(p2)
    
    probe = vtk.vtkProbeFilter()
    probe.SetInputConnection(line.GetOutputPort())
    probe.SetSourceConnection(vtkFile.outputPort)
    
    probe.Update()
    probe = probe.GetOutput()
    
    vel=probe.GetPointData().GetArray(vtkFile.velArray[solver])
    vel=np.array([vel.GetTuple(j) for j in range(probe.GetNumberOfPoints())])
    line=np.array([probe.GetPoint(j) for j in range(probe.GetNumberOfPoints())])
    
    return line, vel
예제 #4
0
def sample_ensight(file,
                   p1=None,
                   p2=None,
                   resolution=100,
                   solver='TruchasEnSight',
                   vtkFile=None):
    vtkFile = vtkextract.vtkFile()
    vtkFile.solver = solver
    vtkFile.sim = '3D'

    ts = enSightTimeSteps(file)
    vtkFile.readFile(file, ts=ts - 1)

    return sample_vtk(vtkFile, p1, p2, resolution, solver)