Commit 4e976f44 authored by Stephan Rave's avatar Stephan Rave
Browse files

[config] remove config check in discretizers.builtin.grids.vtkio

parent 542f4e03
......@@ -2,20 +2,15 @@
# Copyright 2013-2021 pyMOR developers and contributors. All rights reserved.
# License: BSD 2-Clause License (https://opensource.org/licenses/BSD-2-Clause)
from pymor.core.config import config
from pymor.core.exceptions import IOLibsMissing
from pymor.core.config import require_dependency
require_dependency('VTKIO')
if config.HAVE_VTKIO:
from pymor.discretizers.builtin.grids.io import to_meshio
from pymor.tools.io.vtk import write_vtk_collection
from pymor.discretizers.builtin.grids.io import to_meshio
from pymor.tools.io.vtk import write_vtk_collection
def write_vtk(grid, data, filename_base, codim=2, metadata=None):
"""Convenience function around write_vtk_collection(to_meshio(...))"""
return write_vtk_collection(meshes=to_meshio(grid, data, codim=codim),
filename_base=filename_base, metadata=metadata)
else:
def write_vtk(*args, **kwargs):
raise IOLibsMissing()
def write_vtk(grid, data, filename_base, codim=2, metadata=None):
"""Convenience function around write_vtk_collection(to_meshio(...))"""
return write_vtk_collection(meshes=to_meshio(grid, data, codim=codim),
filename_base=filename_base, metadata=metadata)
......@@ -25,7 +25,6 @@ from pymor.core.config import config
from pymor.core.defaults import defaults
from pymor.core.logger import getLogger
from pymor.core.pickle import dump
from pymor.discretizers.builtin.grids.vtkio import write_vtk
from pymor.vectorarrays.interface import VectorArray
from pymor.vectorarrays.numpy import NumpyVectorSpace
......@@ -433,6 +432,7 @@ def visualize_patch(grid, U, bounding_box=([0, 0], [1, 1]), codim=2, title=None,
msg = QMessageBox(QMessageBox.Critical, 'Error', 'VTK output disabled. Please install pyvtk.')
msg.exec_()
return
from pymor.discretizers.builtin.grids.vtkio import write_vtk
filename = QFileDialog.getSaveFileName(self, 'Save as vtk file')[0]
base_name = filename.split('.vtu')[0].split('.vtk')[0].split('.pvd')[0]
if base_name:
......
......@@ -8,7 +8,6 @@ from pymor.core.defaults import defaults
from pymor.core.config import is_jupyter
from pymor.discretizers.builtin.grids.oned import OnedGrid
from pymor.discretizers.builtin.grids.referenceelements import triangle, square
from pymor.discretizers.builtin.grids.vtkio import write_vtk
from pymor.vectorarrays.interface import VectorArray
......@@ -79,6 +78,7 @@ class PatchVisualizer(ImmutableObject):
and all(isinstance(u, VectorArray) for u in U)
and all(len(u) == len(U[0]) for u in U))
if filename:
from pymor.discretizers.builtin.grids.vtkio import write_vtk
if not isinstance(U, tuple):
write_vtk(self.grid, U, filename, codim=self.codim)
else:
......
......@@ -14,7 +14,6 @@ from hypothesis import given
from pymor.core.config import config
from pymor.core.logger import getLogger
from pymor.discretizers.builtin.grids.vtkio import write_vtk
from pymor.discretizers.builtin.quadratures import GaussQuadratures
from pymor.tools import formatsrc, timing
from pymor.tools.deprecated import Deprecated
......@@ -125,6 +124,7 @@ def test_almost_less():
@pytest.mark.skipif(not config.HAVE_VTKIO, reason='VTKIO support libraries missing')
@given(hy_rect_or_tria_grid)
def test_vtkio(grid):
from pymor.discretizers.builtin.grids.vtkio import write_vtk
steps = 4
for codim, data in enumerate((NumpyVectorSpace.from_numpy(np.ones((steps, grid.size(c))))
for c in range(grid.dim+1))):
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment