コード例 #1
1
ファイル: mesh.py プロジェクト: LeiDai/sfepy
    def __init__(self, name='mesh', filename=None,
                 prefix_dir=None, **kwargs):
        """Create a Mesh.

        Parameters
        ----------
        name : str
            Object name.
        filename : str
            Loads a mesh from the specified file, if not None.
        prefix_dir : str
            If not None, the filename is relative to that directory.
        """
        Struct.__init__(self, name=name, **kwargs)
        self.nodal_bcs = {}

        if filename is None:
            self.io = None
            self.setup_done = 0

        else:
            io = MeshIO.any_from_filename(filename, prefix_dir=prefix_dir)
            output('reading mesh (%s)...' % (io.filename))
            tt = time.clock()
            io.read(self)
            output('...done in %.2f s' % (time.clock() - tt))
            self._set_shape_info()
コード例 #2
1
ファイル: mesh.py プロジェクト: olivierverdier/sfepy
    def from_file(filename=None, io='auto', prefix_dir=None):
        """
        Read a mesh from a file.

        Parameters
        ----------
        filename : string like
            The filename.

        io : *MeshIO instance
            Passing *MeshIO instance has precedence over filename.

        prefix_dir : str
            If not None, the filename is relative to that directory.
        """
        if io == 'auto':
            if filename is None:
                output( 'filename or io must be specified!' )
                raise ValueError
            else:
                io = MeshIO.any_from_filename(filename, prefix_dir=prefix_dir)

        output('reading mesh (%s)...' % (io.filename))
        tt = time.clock()

        trunk = io.get_filename_trunk()
        mesh = Mesh(trunk)
        mesh = io.read(mesh)

        output('...done in %.2f s' % (time.clock() - tt))

        mesh._set_shape_info()

        return mesh
コード例 #3
0
    def read(self, debug, interpolate):
        """
    Read finite-element mesh and store in Sieve mesh object.

    @returns PETSc mesh object containing finite-element mesh
    """
        from pylith.mpi.Communicator import mpi_comm_world
        comm = mpi_comm_world()
        if 0 == comm.rank:
            self._info.log("Reading finite-element mesh")

        # Set flags
        self.debug(debug)
        self.interpolate(interpolate)

        # Initialize coordinate system
        if self.coordsys is None:
            raise ValueError, "Coordinate system for mesh is unknown."

        from pylith.mpi.Communicator import petsc_comm_world
        from pylith.topology.Mesh import Mesh
        mesh = Mesh(dim=self.coordsys.spaceDim(), comm=petsc_comm_world())
        mesh.coordsys(self.coordsys)

        # Read mesh
        ModuleMeshIO.read(self, mesh)
        return mesh
コード例 #4
0
ファイル: MeshIOObj.py プロジェクト: geodynamics/pylith
  def read(self, debug, interpolate):
    """
    Read finite-element mesh and store in Sieve mesh object.

    @returns PETSc mesh object containing finite-element mesh
    """
    from pylith.mpi.Communicator import mpi_comm_world
    comm = mpi_comm_world()
    if 0 == comm.rank:
      self._info.log("Reading finite-element mesh")

    # Set flags
    self.debug(debug)
    self.interpolate(interpolate)

    # Initialize coordinate system
    if self.coordsys is None:
      raise ValueError, "Coordinate system for mesh is unknown."

    from pylith.mpi.Communicator import petsc_comm_world
    from pylith.topology.Mesh import Mesh    
    mesh = Mesh(dim=self.coordsys.spaceDim(), comm=petsc_comm_world())
    mesh.coordsys(self.coordsys)

    # Read mesh
    ModuleMeshIO.read(self, mesh)
    return mesh
コード例 #5
0
ファイル: MeshIOObj.py プロジェクト: geodynamics/pylith
  def write(self, mesh):
    """
    Write finite-element mesh.stored in Sieve mesh object.

    @param mesh PETSc mesh object containing finite-element mesh
    """
    from pylith.mpi.Communicator import mpi_comm_world
    comm = mpi_comm_world()
    if 0 == comm.rank:
      self._info.log("Writing finite-element mesh")
    ModuleMeshIO.write(self, mesh)
    return
コード例 #6
0
    def write(self, mesh):
        """
    Write finite-element mesh.stored in Sieve mesh object.

    @param mesh PETSc mesh object containing finite-element mesh
    """
        from pylith.mpi.Communicator import mpi_comm_world
        comm = mpi_comm_world()
        if 0 == comm.rank:
            self._info.log("Writing finite-element mesh")
        ModuleMeshIO.write(self, mesh)
        return
コード例 #7
0
    def __init__(self, name='mesh', filename=None, prefix_dir=None, **kwargs):
        """Create a Mesh.

        Parameters
        ----------
        name : str
            Object name.
        filename : str
            Loads a mesh from the specified file, if not None.
        prefix_dir : str
            If not None, the filename is relative to that directory.
        """
        Struct.__init__(self, name=name, **kwargs)

        if filename is None:
            self.io = None
            self.setup_done = 0

        else:
            io = MeshIO.any_from_filename(filename, prefix_dir=prefix_dir)
            output('reading mesh (%s)...' % (io.filename))
            tt = time.clock()
            io.read(self)
            output('...done in %.2f s' % (time.clock() - tt))
            self._set_shape_info()
コード例 #8
0
ファイル: dicom2fem.py プロジェクト: galerkin/dicom2fem
    def saveMesh(self, event=None, filename=None):
        if self.mesh_data is not None:
            self.statusBar().showMessage('Saving mesh...')
            QApplication.processEvents()

            if filename is None:
                file_ext = inv_supported_formats[self.mesh_out_format]
                filename = \
                    str(QFileDialog.getSaveFileName(self, 'Save MESH file',
                                                    filter='Files (*%s)'\
                                                        % file_ext))

            if len(filename) > 0:

                io = MeshIO.for_format(filename, format=self.mesh_out_format,
                                       writable=True)
                io.write(filename, self.mesh_data)

                self.statusBar().showMessage('Ready')

            else:
                self.statusBar().showMessage('No output file specified!')

        else:
            self.statusBar().showMessage('No mesh data!')
コード例 #9
0
ファイル: mesh.py プロジェクト: certik/sfepy
    def write( self, filename = None, io = None,
               coors = None, igs = None, out = None, float_format = None,
               **kwargs ):
        """Write mesh + optional results in 'out'.

        'io' == 'auto' respects the extension of 'filename'
        'coors' can be used instead of mesh coordinates,
        providing 'igs' filters some groups only"""
        if filename is None:
            filename = self.name + '.mesh'

        if io is None:
            io = self.io
        else:
            if io == 'auto':
                io = MeshIO.any_from_filename( filename )

        if coors is None:
            coors = self.nod0

        if igs is None:
            igs = range( len( self.conns ) )

        aux_mesh = Mesh.from_data( self.name, coors,
                                 self.conns, self.mat_ids, self.descs, igs )
        io.set_float_format( float_format )
        io.write( filename, aux_mesh, out, **kwargs )
コード例 #10
0
ファイル: dicom2fem.py プロジェクト: 00liujj/dicom2fem
    def saveMesh(self, event=None, filename=None):
        if self.mesh_data is not None:
            self.statusBar().showMessage('Saving mesh...')
            QApplication.processEvents()

            if filename is None:
                file_ext = inv_supported_formats[self.mesh_out_format]
                filename = \
                    str(QFileDialog.getSaveFileName(self, 'Save MESH file',
                                                    filter='Files (*%s)'\
                                                        % file_ext))

            if len(filename) > 0:

                io = MeshIO.for_format(filename,
                                       format=self.mesh_out_format,
                                       writable=True)
                io.write(filename, self.mesh_data)

                self.statusBar().showMessage('Ready')

            else:
                self.statusBar().showMessage('No output file specified!')

        else:
            self.statusBar().showMessage('No mesh data!')
コード例 #11
0
ファイル: mesh.py プロジェクト: uberstig/sfepy
    def write(self, filename=None, io=None, out=None, float_format=None,
              **kwargs):
        """
        Write mesh + optional results in `out` to a file.

        Parameters
        ----------
        filename : str, optional
            The file name. If None, the mesh name is used instead.
        io : MeshIO instance or 'auto', optional
            Passing 'auto' respects the extension of `filename`.
        out : dict, optional
            The output data attached to the mesh vertices and/or cells.
        float_format : str, optional
            The format string used to print floats in case of a text file
            format.
        **kwargs : dict, optional
            Additional arguments that can be passed to the `MeshIO` instance.
        """
        if filename is None:
            filename = self.name + '.mesh'

        if io is None:
            io = self.io
            if io is None:
                io = 'auto'

        if io == 'auto':
            io = MeshIO.any_from_filename(filename)

        io.set_float_format(float_format)
        io.write(filename, self, out, **kwargs)
コード例 #12
0
    def write(self,
              filename=None,
              io=None,
              coors=None,
              igs=None,
              out=None,
              float_format=None,
              **kwargs):
        """
        Write mesh + optional results in `out` to a file.

        Parameters
        ----------
        filename : str, optional
            The file name. If None, the mesh name is used instead.
        io : MeshIO instance or 'auto', optional
            Passing 'auto' respects the extension of `filename`.
        coors : array, optional
            The coordinates that can be used instead of the mesh coordinates.
        igs : array_like, optional
            Passing a list of group ids selects only those groups for writing.
        out : dict, optional
            The output data attached to the mesh vertices and/or cells.
        float_format : str, optional
            The format string used to print floats in case of a text file
            format.
        **kwargs : dict, optional
            Additional arguments that can be passed to the `MeshIO` instance.
        """
        if filename is None:
            filename = self.name + '.mesh'

        if io is None:
            io = self.io
            if io is None:
                io = 'auto'

        if io == 'auto':
            io = MeshIO.any_from_filename(filename)

        if coors is None:
            coors = self.coors

        if igs is None:
            igs = range(len(self.conns))

        aux_mesh = Mesh.from_data(self.name,
                                  coors,
                                  self.ngroups,
                                  self.conns,
                                  self.mat_ids,
                                  self.descs,
                                  igs=igs,
                                  nodal_bcs=self.nodal_bcs)
        io.set_float_format(float_format)
        io.write(filename, aux_mesh, out, **kwargs)
コード例 #13
0
ファイル: mesh.py プロジェクト: LeiDai/sfepy
    def write(self, filename=None, io=None,
              coors=None, igs=None, out=None, float_format=None, **kwargs):
        """
        Write mesh + optional results in `out` to a file.

        Parameters
        ----------
        filename : str, optional
            The file name. If None, the mesh name is used instead.
        io : MeshIO instance or 'auto', optional
            Passing 'auto' respects the extension of `filename`.
        coors : array, optional
            The coordinates that can be used instead of the mesh coordinates.
        igs : array_like, optional
            Passing a list of group ids selects only those groups for writing.
        out : dict, optional
            The output data attached to the mesh vertices and/or cells.
        float_format : str, optional
            The format string used to print floats in case of a text file
            format.
        **kwargs : dict, optional
            Additional arguments that can be passed to the `MeshIO` instance.
        """
        if filename is None:
            filename = self.name + '.mesh'

        if io is None:
            io = self.io
            if io is None:
                io = 'auto'

        if io == 'auto':
            io = MeshIO.any_from_filename(filename)

        if coors is None:
            coors = self.coors

        if igs is None:
            igs = range(len(self.conns))

        aux_mesh = Mesh.from_data(self.name, coors, self.ngroups,
                                  self.conns, self.mat_ids, self.descs,
                                  igs=igs, nodal_bcs=self.nodal_bcs)
        io.set_float_format(float_format)
        io.write(filename, aux_mesh, out, **kwargs)
コード例 #14
0
    def from_file(filename=None,
                  io='auto',
                  prefix_dir=None,
                  omit_facets=False):
        """
        Read a mesh from a file.

        Parameters
        ----------
        filename : string or function or MeshIO instance or Mesh instance
            The name of file to read the mesh from. For convenience, a
            mesh creation function or a MeshIO instance or directly a Mesh
            instance can be passed in place of the file name.
        io : *MeshIO instance
            Passing *MeshIO instance has precedence over filename.
        prefix_dir : str
            If not None, the filename is relative to that directory.
        omit_facets : bool
            If True, do not read cells of lower dimension than the space
            dimension (faces and/or edges). Only some MeshIO subclasses
            support this!
        """
        if isinstance(filename, Mesh):
            return filename

        if io == 'auto':
            if filename is None:
                output('filename or io must be specified!')
                raise ValueError
            else:
                io = MeshIO.any_from_filename(filename, prefix_dir=prefix_dir)

        cell_types = ', '.join(supported_cell_types[io.format])
        output('reading mesh [%s] (%s)...' % (cell_types, io.filename))
        tt = time.clock()

        trunk = io.get_filename_trunk()
        mesh = Mesh(trunk)
        mesh = io.read(mesh, omit_facets=omit_facets)

        output('...done in %.2f s' % (time.clock() - tt))

        mesh._set_shape_info()

        return mesh
コード例 #15
0
ファイル: mesh.py プロジェクト: LeiDai/sfepy
    def from_file(filename=None, io='auto', prefix_dir=None,
                  omit_facets=False):
        """
        Read a mesh from a file.

        Parameters
        ----------
        filename : string or function or MeshIO instance or Mesh instance
            The name of file to read the mesh from. For convenience, a
            mesh creation function or a MeshIO instance or directly a Mesh
            instance can be passed in place of the file name.
        io : *MeshIO instance
            Passing *MeshIO instance has precedence over filename.
        prefix_dir : str
            If not None, the filename is relative to that directory.
        omit_facets : bool
            If True, do not read cells of lower dimension than the space
            dimension (faces and/or edges). Only some MeshIO subclasses
            support this!
        """
        if isinstance(filename, Mesh):
            return filename

        if io == 'auto':
            if filename is None:
                output('filename or io must be specified!')
                raise ValueError
            else:
                io = MeshIO.any_from_filename(filename, prefix_dir=prefix_dir)

        cell_types = ', '.join(supported_cell_types[io.format])
        output('reading mesh [%s] (%s)...' % (cell_types, io.filename))
        tt = time.clock()

        trunk = io.get_filename_trunk()
        mesh = Mesh(trunk)
        mesh = io.read(mesh, omit_facets=omit_facets)

        output('...done in %.2f s' % (time.clock() - tt))

        mesh._set_shape_info()

        return mesh
コード例 #16
0
ファイル: mesh.py プロジェクト: certik/sfepy
    def from_file( filename = None, io = 'auto' ):
        """passing *MeshIO instance has precedence over filename"""
        if io == 'auto':
            if filename is None:
                output( 'filename or io must be specified!' )
                raise ValueError
            else:
                io = MeshIO.any_from_filename( filename )
                if isinstance( filename, file ):
                    trunk = 'from_descriptor'
                else:
                    trunk = op.splitext( filename )[0]
        else:
            trunk = io.filename

        output( 'reading mesh (%s)...' % (filename) )
        tt = time.clock()
        mesh = Mesh( trunk )
        mesh = io.read( mesh )
        output( '...done in %.2f s' % (time.clock() - tt) )
        mesh._set_shape_info()
        return mesh