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()
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
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()
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 )
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)
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)
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
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