Ejemplo n.º 1
0
def write_vtk(grid, data, filename_base, codim=2, binary_vtk=True, last_step=None):
    '''Output grid-associated data in (legacy) vtk format

    Parameters
    ----------
    grid
        a |Grid| with triangular or rectilinear reference element

    data
        VectorArrayInterface instance with either cell (ie one datapoint per codim 0 entity)
        or vertex (ie one datapoint per codim 2 entity) data in each array element

    filename_base
        common component for output files in timeseries

    last_step
        if set must be <= len(data) to restrict output of timeseries
    '''
    if not HAVE_PYVTK:
        raise ImportError('could not import pyvtk')
    if grid.dim != 2 or grid.dim_outer != 2:
        raise NotImplementedError
    if codim not in (0, 2):
        raise NotImplementedError

    subentities, coordinates, entity_map = flatten_grid(grid)

    x, y = coordinates[:, 0], coordinates[:, 1]
    z = np.zeros(len(x))
    coords = (x, y, z)
    us_grid = _vtk_grid(grid.reference_element, subentities, coords)
    if codim == 0:
        _write_vtu_series(us_grid, data.data, filename_base, binary_vtk, last_step, True)
    else:
        _write_vtu_series(us_grid, data.data[:, entity_map], filename_base, binary_vtk, last_step, False)
Ejemplo n.º 2
0
    def __init__(self, figure, grid, bounding_box=None, vmin=None, vmax=None, codim=2,
                 colorbar=True):
        assert grid.reference_element in (triangle, square)
        assert grid.dim == 2
        assert codim in (0, 2)

        subentities, coordinates, entity_map = flatten_grid(grid)
        self.subentities = subentities if grid.reference_element is triangle \
            else np.vstack((subentities[:, 0:3], subentities[:, [2, 3, 0]]))
        self.coordinates = coordinates
        self.entity_map = entity_map
        self.reference_element = grid.reference_element
        self.vmin = vmin
        self.vmax = vmax
        self.codim = codim
        a = figure.gca()
        if self.codim == 2:
            self.p = a.tripcolor(self.coordinates[:, 0], self.coordinates[:, 1], self.subentities,
                                 np.zeros(len(self.coordinates)),
                                 vmin=self.vmin, vmax=self.vmax, shading='gouraud')
        else:
            self.p = a.tripcolor(self.coordinates[:, 0], self.coordinates[:, 1], self.subentities,
                                 facecolors=np.zeros(len(self.subentities)),
                                 vmin=self.vmin, vmax=self.vmax, shading='flat')
        if colorbar:
            figure.colorbar(self.p, ax=a)
Ejemplo n.º 3
0
def write_vtk(grid, data, filename_base, codim=2, binary_vtk=True, last_step=None):
    """Output grid-associated data in (legacy) vtk format

    Parameters
    ----------
    grid
        a |Grid| with triangular or rectilinear reference element

    data
        VectorArrayInterface instance with either cell (ie one datapoint per codim 0 entity)
        or vertex (ie one datapoint per codim 2 entity) data in each array element
    codim
        the codimension associated with the data
    filename_base
        common component for output files in timeseries
    binary_vtk
        if false, output files contain human readable inline ascii data, else appended binary
    last_step
        if set must be <= len(data) to restrict output of timeseries
    """
    if not config.HAVE_PYVTK:
        raise ImportError('could not import pyevtk')
    if grid.dim != 2:
        raise NotImplementedError
    if codim not in (0, 2):
        raise NotImplementedError

    subentities, coordinates, entity_map = flatten_grid(grid)
    data = data.data if codim == 0 else data.data[:, entity_map].copy()
    x, y, z = coordinates[:, 0].copy(), coordinates[:, 1].copy(), np.zeros(coordinates[:, 1].size)
    _write_vtu_series(grid, coordinates=(x, y, z), connectivity=subentities, data=data,
                      filename_base=filename_base, last_step=last_step, is_cell_data=(codim == 0))
Ejemplo n.º 4
0
        def __init__(self,
                     parent,
                     grid,
                     bounding_box=None,
                     vmin=None,
                     vmax=None,
                     codim=2,
                     dpi=100):
            assert grid.reference_element in (triangle, square)
            assert grid.dim == 2
            assert codim in (0, 2)

            self.figure = Figure(dpi=dpi)
            super().__init__(self.figure)

            subentities, coordinates, entity_map = flatten_grid(grid)
            self.subentities = subentities if grid.reference_element is triangle \
                else np.vstack((subentities[:, 0:3], subentities[:, [2, 3, 0]]))
            self.coordinates = coordinates
            self.entity_map = entity_map
            self.reference_element = grid.reference_element
            self.vmin = vmin
            self.vmax = vmax
            self.codim = codim
            self.setParent(parent)
            self.setMinimumSize(300, 300)
            self.setSizePolicy(
                QSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding))
Ejemplo n.º 5
0
def write_vtk(grid, data, filename_base, codim=2, binary_vtk=True, last_step=None):
    """Output grid-associated data in (legacy) vtk format

    Parameters
    ----------
    grid
        a |Grid| with triangular or rectilinear reference element

    data
        VectorArrayInterface instance with either cell (ie one datapoint per codim 0 entity)
        or vertex (ie one datapoint per codim 2 entity) data in each array element

    filename_base
        common component for output files in timeseries

    last_step
        if set must be <= len(data) to restrict output of timeseries
    """
    if not HAVE_PYVTK:
        raise ImportError('could not import pyvtk')
    if grid.dim != 2 or grid.dim_outer != 2:
        raise NotImplementedError
    if codim not in (0, 2):
        raise NotImplementedError

    subentities, coordinates, entity_map = flatten_grid(grid)

    x, y = coordinates[:, 0], coordinates[:, 1]
    z = np.zeros(len(x))
    coords = (x, y, z)
    us_grid = _vtk_grid(grid.reference_element, subentities, coords)
    if codim == 0:
        _write_vtu_series(us_grid, data.data, filename_base, binary_vtk, last_step, True)
    else:
        _write_vtu_series(us_grid, data.data[:, entity_map], filename_base, binary_vtk, last_step, False)
Ejemplo n.º 6
0
def write_vtk(grid, data, filename_base, codim=2, binary_vtk=True, last_step=None):
    """Output grid-associated data in (legacy) vtk format

    Parameters
    ----------
    grid
        A |Grid| with triangular or rectilinear reference element.
    data
        |VectorArray| with either cell (ie one datapoint per codim 0 entity)
        or vertex (ie one datapoint per codim 2 entity) data in each array element.
    codim
        the codimension associated with the data
    filename_base
        common component for output files in timeseries
    binary_vtk
        if false, output files contain human readable inline ascii data, else appended binary
    last_step
        if set must be <= len(data) to restrict output of timeseries
    """
    if not config.HAVE_PYVTK:
        raise ImportError('could not import pyevtk')
    if grid.dim != 2:
        raise NotImplementedError
    if codim not in (0, 2):
        raise NotImplementedError

    subentities, coordinates, entity_map = flatten_grid(grid)
    data = data.to_numpy() if codim == 0 else data.to_numpy()[:, entity_map].copy()
    x, y, z = coordinates[:, 0].copy(), coordinates[:, 1].copy(), np.zeros(coordinates[:, 1].size)
    _write_vtu_series(grid, coordinates=(x, y, z), connectivity=subentities, data=data,
                      filename_base=filename_base, last_step=last_step, is_cell_data=(codim == 0))
Ejemplo n.º 7
0
        def __init__(self, parent, grid, vmin=None, vmax=None, bounding_box=[[0, 0], [1, 1]], codim=2):
            assert grid.reference_element in (triangle, square)
            assert grid.dim == 2
            assert codim in (0, 2)
            super(GlumpyPatchWidget, self).__init__(parent)
            self.setMinimumSize(300, 300)
            self.setSizePolicy(QSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding))

            subentities, coordinates, entity_map = flatten_grid(grid)

            self.subentities = subentities
            self.entity_map = entity_map
            self.reference_element = grid.reference_element
            self.vmin = vmin
            self.vmax = vmax
            self.bounding_box = bounding_box
            self.codim = codim
            self.update_vbo = False
            bb = self.bounding_box
            self.size = np.array([bb[1][0] - bb[0][0], bb[1][1] - bb[0][1]])
            self.scale = 1 / self.size
            self.shift = - np.array(bb[0]) - self.size / 2

            # setup buffers
            if self.reference_element == triangle:
                if codim == 2:
                    self.vertex_data = np.empty(len(coordinates),
                                                dtype=[('position', 'f4', 4), ('color', 'f4', 4)])
                    self.indices = subentities
                else:
                    self.vertex_data = np.empty(len(subentities) * 3,
                                                dtype=[('position', 'f4', 4), ('color', 'f4', 4)])
                    self.indices = np.arange(len(subentities) * 3, dtype=np.uint32)
            else:
                if codim == 2:
                    self.vertex_data = np.empty(len(coordinates),
                                                dtype=[('position', 'f4', 4), ('color', 'f4', 4)])
                    self.indices = np.vstack((subentities[:, 0:3], subentities[:, [0, 2, 3]]))
                else:
                    self.vertex_data = np.empty(len(subentities) * 6,
                                                dtype=[('position', 'f4', 4), ('color', 'f4', 4)])
                    self.indices = np.arange(len(subentities) * 6, dtype=np.uint32)

            self.vertex_data['position'][:, 2] = 0
            self.vertex_data['position'][:, 3] = 0.5
            self.vertex_data['color'] = 1

            self.set_coordinates(coordinates)
            self.set(np.zeros(grid.size(codim)))
Ejemplo n.º 8
0
Archivo: gl.py Proyecto: prklVIP/pymor
        def __init__(self, parent, grid, vmin=None, vmax=None, bounding_box=([0, 0], [1, 1]), codim=2):
            assert grid.reference_element in (triangle, square)
            assert grid.dim == 2
            assert codim in (0, 2)
            super().__init__(parent)
            self.setMinimumSize(300, 300)
            self.setSizePolicy(QSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding))

            subentities, coordinates, entity_map = flatten_grid(grid)

            self.subentities = subentities
            self.entity_map = entity_map
            self.reference_element = grid.reference_element
            self.vmin = vmin
            self.vmax = vmax
            self.bounding_box = bounding_box
            self.codim = codim
            self.update_vbo = False
            bb = self.bounding_box
            self.size = np.array([bb[1][0] - bb[0][0], bb[1][1] - bb[0][1]])
            self.scale = 2 / self.size
            self.shift = - np.array(bb[0]) - self.size / 2

            # setup buffers
            if self.reference_element == triangle:
                if codim == 2:
                    self.vertex_data = np.empty(len(coordinates),
                                                dtype=[('position', 'f4', 2), ('color', 'f4', 1)])
                    self.indices = subentities
                else:
                    self.vertex_data = np.empty(len(subentities) * 3,
                                                dtype=[('position', 'f4', 2), ('color', 'f4', 1)])
                    self.indices = np.arange(len(subentities) * 3, dtype=np.uint32)
            else:
                if codim == 2:
                    self.vertex_data = np.empty(len(coordinates),
                                                dtype=[('position', 'f4', 2), ('color', 'f4', 1)])
                    self.indices = np.vstack((subentities[:, 0:3], subentities[:, [0, 2, 3]]))
                else:
                    self.vertex_data = np.empty(len(subentities) * 6,
                                                dtype=[('position', 'f4', 2), ('color', 'f4', 1)])
                    self.indices = np.arange(len(subentities) * 6, dtype=np.uint32)
            self.indices = np.ascontiguousarray(self.indices)

            self.vertex_data['color'] = 1

            self.set_coordinates(coordinates)
            self.set(np.zeros(grid.size(codim)))
Ejemplo n.º 9
0
        def __init__(self, parent, grid, bounding_box=None, vmin=None, vmax=None, codim=2, dpi=100):
            assert grid.reference_element in (triangle, square)
            assert grid.dim == 2
            assert codim in (0, 2)

            self.figure = Figure(dpi=dpi)
            super().__init__(self.figure)

            subentities, coordinates, entity_map = flatten_grid(grid)
            self.subentities = subentities if grid.reference_element is triangle \
                else np.vstack((subentities[:, 0:3], subentities[:, [2, 3, 0]]))
            self.coordinates = coordinates
            self.entity_map = entity_map
            self.reference_element = grid.reference_element
            self.vmin = vmin
            self.vmax = vmax
            self.codim = codim
            self.setParent(parent)
            self.setMinimumSize(300, 300)
            self.setSizePolicy(QSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding))
Ejemplo n.º 10
0
def write_vtk(grid,
              data,
              filename_base,
              codim=2,
              binary_vtk=True,
              last_step=None):
    """Output grid-associated data in (legacy) vtk format

    Parameters
    ----------
    grid
        a |Grid| with triangular or rectilinear reference element

    data
        VectorArrayInterface instance with either cell (ie one datapoint per codim 0 entity)
        or vertex (ie one datapoint per codim 2 entity) data in each array element

    filename_base
        common component for output files in timeseries

    last_step
        if set must be <= len(data) to restrict output of timeseries
    """
    if not HAVE_PYVTK:
        raise ImportError('could not import pyevtk')
    if grid.dim != 2 or grid.dim_outer != 2:
        raise NotImplementedError
    if codim not in (0, 2):
        raise NotImplementedError

    subentities, coordinates, entity_map = flatten_grid(grid)
    x, y, z = coordinates[:, 0].copy(), coordinates[:, 1].copy(), np.zeros(
        coordinates[:, 1].size)
    _write_vtu_series(grid,
                      coordinates=(x, y, z),
                      connectivity=subentities,
                      data=data.data,
                      filename_base=filename_base,
                      last_step=last_step,
                      is_cell_data=(codim == 0))