Ejemplo n.º 1
0
    def __init__(self, discr, pcontext=None, basename=None, compressor=None):
        hedge.tools.Closable.__init__(self)

        from pytools import assert_not_a_file

        if basename is not None:
            self.pvd_name = basename+".pvd"
            assert_not_a_file(self.pvd_name)
        else:
            self.pvd_name = None

        self.pcontext = pcontext
        self.compressor = compressor

        if self.pcontext is None or self.pcontext.is_head_rank:
            self.timestep_to_pathnames = {}
        else:
            self.timestep_to_pathnames = None

        from pyvisfile.vtk import UnstructuredGrid, DataArray, \
                VTK_LINE, VTK_TRIANGLE, VTK_TETRA, VF_LIST_OF_VECTORS
        from hedge.mesh.element import Interval, Triangle, Tetrahedron

        # For now, we use IntVector here because the Python allocator
        # is somewhat reluctant to return allocated chunks of memory
        # to the OS.
        from hedge._internal import IntVector
        cells = IntVector()
        cell_types = IntVector()

        for eg in discr.element_groups:
            ldis = eg.local_discretization
            smi = ldis.get_submesh_indices()

            cells.reserve(len(cells)+len(smi)*len(eg.members))
            for el, el_slice in zip(eg.members, eg.ranges):
                for element in smi:
                    for j in element:
                        cells.append(el_slice.start+j)

            if ldis.geometry is Interval:
                vtk_eltype = VTK_LINE
            elif ldis.geometry is Triangle:
                vtk_eltype = VTK_TRIANGLE
            elif ldis.geometry is Tetrahedron:
                vtk_eltype = VTK_TETRA
            else:
                raise RuntimeError("unsupported element type: %s"
                        % ldis.geometry)

            cell_types.extend([vtk_eltype] * len(smi) * len(eg.members))

        self.grid = UnstructuredGrid(
                (len(discr),
                    DataArray("points", discr.nodes, vector_format=VF_LIST_OF_VECTORS)),
                numpy.asarray(cells),
                cell_types=numpy.asarray(cell_types, dtype=numpy.uint8))
Ejemplo n.º 2
0
def _cp(src, dest):
    from pytools import assert_not_a_file
    assert_not_a_file(dest)

    inf = open(src, "rb")
    try:
        outf = open(dest, "wb")
        try:
            outf.write(inf.read())
        finally:
            outf.close()
    finally:
        inf.close()
Ejemplo n.º 3
0
    def do_close(self):
        from pytools import assert_not_a_file
        assert_not_a_file(self.pathname)

        outf = file(self.pathname, "w")

        from pyvisfile.vtk import AppendedDataXMLGenerator
        AppendedDataXMLGenerator(self.compressor)(self.grid).write(outf)

        #from pyvisfile.vtk import InlineXMLGenerator
        #InlineXMLGenerator(self.compressor)(self.grid).write(outf)

        outf.close()
Ejemplo n.º 4
0
    def do_close(self):
        from pytools import assert_not_a_file
        assert_not_a_file(self.pathname)

        outf = file(self.pathname, "w")

        from pyvisfile.vtk import AppendedDataXMLGenerator
        AppendedDataXMLGenerator(self.compressor)(self.grid).write(outf)

        #from pyvisfile.vtk import InlineXMLGenerator
        #InlineXMLGenerator(self.compressor)(self.grid).write(outf)

        outf.close()
Ejemplo n.º 5
0
    def __init__(self, discr, pcontext=None, basename=None, compressor=None):
        logger.info("init vtk visualizer: start")

        hedge.tools.Closable.__init__(self)

        from pytools import assert_not_a_file

        if basename is not None:
            self.pvd_name = basename + ".pvd"
            assert_not_a_file(self.pvd_name)
        else:
            self.pvd_name = None

        self.pcontext = pcontext
        self.compressor = compressor

        if self.pcontext is None or self.pcontext.is_head_rank:
            self.timestep_to_pathnames = {}
        else:
            self.timestep_to_pathnames = None

        from pyvisfile.vtk import UnstructuredGrid, DataArray, \
                VTK_LINE, VTK_TRIANGLE, VTK_TETRA, VF_LIST_OF_VECTORS
        from hedge.mesh.element import Interval, Triangle, Tetrahedron

        # For now, we use IntVector here because the Python allocator
        # is somewhat reluctant to return allocated chunks of memory
        # to the OS.
        from hedge._internal import IntVector
        cells = IntVector()
        cell_types = IntVector()

        for eg in discr.element_groups:
            ldis = eg.local_discretization
            smi = ldis.get_submesh_indices()

            cells.reserve(len(cells) + len(smi) * len(eg.members))
            for el, el_slice in zip(eg.members, eg.ranges):
                for element in smi:
                    for j in element:
                        cells.append(el_slice.start + j)

            if ldis.geometry is Interval:
                vtk_eltype = VTK_LINE
            elif ldis.geometry is Triangle:
                vtk_eltype = VTK_TRIANGLE
            elif ldis.geometry is Tetrahedron:
                vtk_eltype = VTK_TETRA
            else:
                raise RuntimeError("unsupported element type: %s" %
                                   ldis.geometry)

            cell_types.extend([vtk_eltype] * len(smi) * len(eg.members))

        self.grid = UnstructuredGrid(
            (len(discr),
             DataArray("points", discr.nodes,
                       vector_format=VF_LIST_OF_VECTORS)),
            np.asarray(cells),
            cell_types=np.asarray(cell_types, dtype=np.uint8))

        logger.info("init vtk visualizer: done")