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

optimize import by loading subset from vtk #60

Merged
merged 2 commits into from
Jul 31, 2021
Merged
Show file tree
Hide file tree
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
14 changes: 8 additions & 6 deletions ansys/mapdl/reader/archive.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,21 @@
from functools import wraps

import numpy as np
from vtk import (VTK_TETRA, VTK_QUADRATIC_TETRA, VTK_PYRAMID,
VTK_QUADRATIC_PYRAMID, VTK_WEDGE, VTK_QUADRATIC_WEDGE,
VTK_HEXAHEDRON, VTK_QUADRATIC_HEXAHEDRON, VTK_TRIANGLE, VTK_QUAD,
VTK_QUADRATIC_TRIANGLE, VTK_QUADRATIC_QUAD)
import vtk
from pyvista._vtk import (VTK_TETRA, VTK_QUADRATIC_TETRA, VTK_PYRAMID,
VTK_QUADRATIC_PYRAMID, VTK_WEDGE,
VTK_QUADRATIC_WEDGE, VTK_HEXAHEDRON,
VTK_QUADRATIC_HEXAHEDRON, VTK_TRIANGLE,
VTK_QUAD, VTK_QUADRATIC_TRIANGLE,
VTK_QUADRATIC_QUAD)
from pyvista import _vtk as vtk
from pyvista._vtk import VTK9
import pyvista as pv

from ansys.mapdl.reader import _reader, _archive
from ansys.mapdl.reader.misc import vtk_cell_info, chunks
from ansys.mapdl.reader.mesh import Mesh
from ansys.mapdl.reader.cell_quality import quality

VTK9 = vtk.vtkVersion().GetVTKMajorVersion() >= 9

log = logging.getLogger(__name__)
log.setLevel('CRITICAL')
Expand Down
5 changes: 4 additions & 1 deletion ansys/mapdl/reader/cell_quality.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import numpy as np
import pyvista as pv

from ansys.mapdl.reader._cellqual import cell_quality_float, cell_quality
from ansys.mapdl.reader.misc import vtk_cell_info


Expand Down Expand Up @@ -32,6 +31,10 @@ def quality(grid):
array([1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1.,
1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1.])
"""

# lazy load to speed up import
from ansys.mapdl.reader._cellqual import cell_quality_float, cell_quality

flip = False
if isinstance(grid, pv.StructuredGrid):
grid = grid.cast_to_unstructured_grid()
Expand Down
2 changes: 1 addition & 1 deletion ansys/mapdl/reader/cyclic_reader.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Supports reading cyclic structural result files from ANSYS"""
from functools import wraps

from vtk import vtkMatrix4x4, vtkTransform, vtkAppendFilter
from pyvista._vtk import vtkMatrix4x4, vtkTransform, vtkAppendFilter
import numpy as np
import pyvista as pv

Expand Down
2 changes: 1 addition & 1 deletion ansys/mapdl/reader/dis_result.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import pyvista as pv
import numpy as np
from vtk import vtkAppendFilter
from pyvista._vtk import vtkAppendFilter

from ansys.mapdl.reader.misc import is_float, vtk_cell_info
from ansys.mapdl.reader.mesh import Mesh
Expand Down
4 changes: 2 additions & 2 deletions ansys/mapdl/reader/mesh.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
"""Module for common class between Archive, and result mesh"""
import pyvista as pv
import vtk
from pyvista import _vtk as vtk
from pyvista._vtk import VTK9
import numpy as np

from ansys.mapdl.reader import _relaxmidside, _reader
from ansys.mapdl.reader.misc import unique_rows
from ansys.mapdl.reader.elements import ETYPE_MAP


VTK9 = vtk.vtkVersion().GetVTKMajorVersion() >= 9
INVALID_ALLOWABLE_TYPES = TypeError('`allowable_types` must be an array '
'of ANSYS element types from 1 and 300')

Expand Down
4 changes: 1 addition & 3 deletions ansys/mapdl/reader/rst.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
from threading import Thread
from functools import wraps

import vtk
import numpy as np
import pyvista as pv
from pyvista import _vtk as vtk
from tqdm import tqdm

from ansys.mapdl.reader import _binary_reader, _reader
Expand All @@ -36,8 +36,6 @@
from ansys.mapdl.reader.misc import vtk_cell_info, break_apart_surface
from ansys.mapdl.reader.rst_avail import AvailableResults

VTK9 = vtk.vtkVersion().GetVTKMajorVersion() >= 9


def access_bit(data, num):
base = int(num // 8)
Expand Down
14 changes: 8 additions & 6 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,14 @@ def compilerName():

# perform python version checking
# this is necessary to avoid the new pip package checking as vtk does
# not support Python 3.9 or any 32-bit as of 17 June 2021.
is64 = struct.calcsize("P")*8 == 64
if not is64:
raise RuntimeError('\n\n``ansys-mapdl-reader`` requires 64-bit Python due to vtk.\n'
'Please check the version of Python installed at\n'
'%s' % sys.executable)
# not support Python 32-bit as of 17 June 2021.
if not struct.calcsize("P")*8 == 64:
try:
import vtk
except ImportError:
raise RuntimeError('\n\n``ansys-mapdl-reader`` requires 64-bit Python due to vtk.\n'
'Please check the version of Python installed at\n'
'%s' % sys.executable)

# Actual setup
setup(
Expand Down