Exemple #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))
Exemple #2
0
    def __init__(self, dim, coords, element_groups):
        self.coords = coords

        from pyvisfile.silo import IntVector
        self.ndims = dim
        self.nodelist = IntVector()
        self.shapetypes = IntVector()
        self.shapesizes = IntVector()
        self.shapecounts = IntVector()
        self.nzones = 0

        for nodelist_size_estimate, eg, ldis in element_groups:
            poly_count = 0
            poly_length = None
            self.nodelist.reserve(len(self.nodelist) + nodelist_size_estimate)
            for polygon in eg:
                prev_nodelist_len = len(self.nodelist)
                for i in polygon:
                    self.nodelist.append(int(i))
                poly_count += 1
                poly_length = len(self.nodelist) - prev_nodelist_len

            if poly_count:
                try:
                    from pyvisfile.silo import DB_ZONETYPE_TRIANGLE, DB_ZONETYPE_TET
                except ImportError:
                    pass
                else:
                    from hedge.mesh.element import Triangle, Tetrahedron
                    if ldis.geometry is Triangle:
                        self.shapetypes.append(DB_ZONETYPE_TRIANGLE)
                    elif ldis.geometry is Tetrahedron:
                        self.shapetypes.append(DB_ZONETYPE_TET)
                    else:
                        raise RuntimeError(
                                "unsupported element type: %s" % ldis.geometry)

                self.shapesizes.append(poly_length)
                self.shapecounts.append(poly_count)
                self.nzones += poly_count
Exemple #3
0
    def __init__(self, dim, coords, element_groups):
        self.coords = coords

        from pyvisfile.silo import IntVector
        self.ndims = dim
        self.nodelist = IntVector()
        self.shapetypes = IntVector()
        self.shapesizes = IntVector()
        self.shapecounts = IntVector()
        self.nzones = 0

        for nodelist_size_estimate, eg, ldis in element_groups:
            poly_count = 0
            poly_length = None
            self.nodelist.reserve(len(self.nodelist) + nodelist_size_estimate)
            for polygon in eg:
                prev_nodelist_len = len(self.nodelist)
                for i in polygon:
                    self.nodelist.append(int(i))
                poly_count += 1
                poly_length = len(self.nodelist) - prev_nodelist_len

            if poly_count:
                try:
                    from pyvisfile.silo import DB_ZONETYPE_TRIANGLE, DB_ZONETYPE_TET
                except ImportError:
                    pass
                else:
                    from hedge.mesh.element import Triangle, Tetrahedron
                    if ldis.geometry is Triangle:
                        self.shapetypes.append(DB_ZONETYPE_TRIANGLE)
                    elif ldis.geometry is Tetrahedron:
                        self.shapetypes.append(DB_ZONETYPE_TET)
                    else:
                        raise RuntimeError("unsupported element type: %s" %
                                           ldis.geometry)

                self.shapesizes.append(poly_length)
                self.shapecounts.append(poly_count)
                self.nzones += poly_count
Exemple #4
0
class SiloMeshData(object):
    def __init__(self, dim, coords, element_groups):
        self.coords = coords

        from pyvisfile.silo import IntVector
        self.ndims = dim
        self.nodelist = IntVector()
        self.shapetypes = IntVector()
        self.shapesizes = IntVector()
        self.shapecounts = IntVector()
        self.nzones = 0

        for nodelist_size_estimate, eg, ldis in element_groups:
            poly_count = 0
            poly_length = None
            self.nodelist.reserve(len(self.nodelist) + nodelist_size_estimate)
            for polygon in eg:
                prev_nodelist_len = len(self.nodelist)
                for i in polygon:
                    self.nodelist.append(int(i))
                poly_count += 1
                poly_length = len(self.nodelist) - prev_nodelist_len

            if poly_count:
                try:
                    from pyvisfile.silo import DB_ZONETYPE_TRIANGLE, DB_ZONETYPE_TET
                except ImportError:
                    pass
                else:
                    from hedge.mesh.element import Triangle, Tetrahedron
                    if ldis.geometry is Triangle:
                        self.shapetypes.append(DB_ZONETYPE_TRIANGLE)
                    elif ldis.geometry is Tetrahedron:
                        self.shapetypes.append(DB_ZONETYPE_TET)
                    else:
                        raise RuntimeError("unsupported element type: %s" % ldis.geometry)

                self.shapesizes.append(poly_length)
                self.shapecounts.append(poly_count)
                self.nzones += poly_count

    def put_mesh(self, silo, zonelist_name, mesh_name, mesh_opts):
        if self.shapetypes:
            assert len(self.shapetypes) == len(self.shapesizes)
            silo.put_zonelist_2(zonelist_name, self.nzones, self.ndims, self.nodelist,
                    0, 0, self.shapetypes, self.shapesizes, self.shapecounts)
        else:
            silo.put_zonelist(zonelist_name, self.nzones, self.ndims, self.nodelist,
                    self.shapesizes, self.shapecounts)

        silo.put_ucdmesh(mesh_name, [], self.coords, self.nzones,
                zonelist_name, None, mesh_opts)
Exemple #5
0
class SiloMeshData(object):
    def __init__(self, dim, coords, element_groups):
        self.coords = coords

        from pyvisfile.silo import IntVector
        self.ndims = dim
        self.nodelist = IntVector()
        self.shapetypes = IntVector()
        self.shapesizes = IntVector()
        self.shapecounts = IntVector()
        self.nzones = 0

        for nodelist_size_estimate, eg, ldis in element_groups:
            poly_count = 0
            poly_length = None
            self.nodelist.reserve(len(self.nodelist) + nodelist_size_estimate)
            for polygon in eg:
                prev_nodelist_len = len(self.nodelist)
                for i in polygon:
                    self.nodelist.append(int(i))
                poly_count += 1
                poly_length = len(self.nodelist) - prev_nodelist_len

            if poly_count:
                try:
                    from pyvisfile.silo import DB_ZONETYPE_TRIANGLE, DB_ZONETYPE_TET
                except ImportError:
                    pass
                else:
                    from hedge.mesh.element import Triangle, Tetrahedron
                    if ldis.geometry is Triangle:
                        self.shapetypes.append(DB_ZONETYPE_TRIANGLE)
                    elif ldis.geometry is Tetrahedron:
                        self.shapetypes.append(DB_ZONETYPE_TET)
                    else:
                        raise RuntimeError("unsupported element type: %s" %
                                           ldis.geometry)

                self.shapesizes.append(poly_length)
                self.shapecounts.append(poly_count)
                self.nzones += poly_count

    def put_mesh(self, silo, zonelist_name, mesh_name, mesh_opts):
        if self.shapetypes:
            assert len(self.shapetypes) == len(self.shapesizes)
            silo.put_zonelist_2(zonelist_name, self.nzones, self.ndims,
                                self.nodelist, 0, 0, self.shapetypes,
                                self.shapesizes, self.shapecounts)
        else:
            silo.put_zonelist(zonelist_name, self.nzones, self.ndims,
                              self.nodelist, self.shapesizes, self.shapecounts)

        silo.put_ucdmesh(mesh_name, [], self.coords, self.nzones,
                         zonelist_name, None, mesh_opts)
Exemple #6
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")