Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add access for vtkToTensorMesh function #140

Merged
merged 3 commits into from
Mar 8, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 26 additions & 13 deletions discretize/mixins/vtkModule.py
Original file line number Diff line number Diff line change
Expand Up @@ -469,26 +469,17 @@ class vtkTensorRead(object):
"""Provides a convienance method for reading VTK Rectilinear Grid files
as ``TensorMesh`` objects."""

@classmethod
def readVTK(TensorMesh, fileName, directory=''):
"""Read VTK Rectilinear (vtr xml file) and return Tensor mesh and model

Input:

:param str fileName: path to the vtr model file to read or just its name if directory is specified
:param str directory: directory where the UBC GIF file lives
@classmethod
def vtkToTensorMesh(TensorMesh, vtrGrid):
"""Converts a ``vtkRectilinearGrid`` or :class:`vtki.RectilinearGrid`
to a :class:`discretize.TensorMesh` object.

Output:

:rtype: tuple
:return: (TensorMesh, modelDictionary)
"""
fname = os.path.join(directory, fileName)
# Read the file
vtrReader = vtkXMLRectilinearGridReader()
vtrReader.SetFileName(fname)
vtrReader.Update()
vtrGrid = vtrReader.GetOutput()
# Sort information
hx = np.abs(np.diff(nps.vtk_to_numpy(vtrGrid.GetXCoordinates())))
xR = nps.vtk_to_numpy(vtrGrid.GetXCoordinates())[0]
Expand Down Expand Up @@ -521,3 +512,25 @@ def readVTK(TensorMesh, fileName, directory=''):

# Return the data
return tensMsh, models

@classmethod
def readVTK(TensorMesh, fileName, directory=''):
"""Read VTK Rectilinear (vtr xml file) and return Tensor mesh and model

Input:

:param str fileName: path to the vtr model file to read or just its name if directory is specified
:param str directory: directory where the UBC GIF file lives

Output:

:rtype: tuple
:return: (TensorMesh, modelDictionary)
"""
fname = os.path.join(directory, fileName)
# Read the file
vtrReader = vtkXMLRectilinearGridReader()
vtrReader.SetFileName(fname)
vtrReader.Update()
vtrGrid = vtrReader.GetOutput()
return TensorMesh.vtkToTensorMesh(vtrGrid)