def __init__(self, mesh_in, index_key): t0=time.time() tm=time.time() if isinstance(mesh_in, str or unicode): try: self.mesh=iMesh.Mesh() self.mesh.load(mesh_in) except Exception as ex: raise ex elif isinstance(mesh_in, iMesh.Mesh): self.mesh=mesh_in else: raise TypeError('mesh_in is of unknown type: {0}'.format(type(mesh_in))) print 'Loaded mesh \'{0}\' in {1:.1f} ms'.format(self.mesh, ((time.time()-tm)*1000)) # print 'mesh: %s' % self.mesh if isinstance(index_key, str or unicode): from ConfigParser import SafeConfigParser parser=SafeConfigParser() parser.read('dataset_out.config') hindexing=eval(parser.get(index_key, 'base_indexing')) if not isinstance(hindexing, dict): raise TypeError('type of option {0} in dataset_out.config[base_indexing] is invalid: {1}'.format(index_key, type(hindexing))) else: raise TypeError('index_key is of unsupported type: {0}'.format(type(index_key))) # Get Time Tags t_tag=self.mesh.getTagHandle('T0') time_topo_set=iMesh.EntitySet(t_tag[self.mesh.rootSet], self.mesh) self._t_verts=time_topo_set.getEntities(type=0) print 'num_times: %s' % len(self._t_verts) self.tshp=(len(self._t_verts),) self.parameters=OrderedDict() self.indexing={} # for i in xrange(4): # topo_name='S{0}'.format(i) # self.indexing[topo_name] = {} for topo_key in hindexing: try: tag=self.mesh.getTagHandle(topo_key) except iBase.TagNotFoundError: continue ents=utils.getEntitiesByTag(self.mesh, tag) print '#_ents for topo_key {0}: {1}'.format(topo_key, len(ents)) self.indexing[topo_key]={'NATURAL':(self.tshp+(len(ents),)), 'GRID':(self.tshp+hindexing[topo_key])} if len(ents) > 0: tags=self.mesh.getAllTags(self._t_verts[0]) dtags=[dt for dt in tags if dt.name.startswith('DATA_{0}_'.format(topo_key))] print 'tags on {0}: {1}'.format(topo_key, [t.name for t in dtags]) for tag in dtags: p=Parameter(self, tag, ents) print '\t%s\t%s\t%s' % (tag.name, p.name, len(ents)) self.parameters[p.name] = p print 'Initialized Structure in {:.1f} ms'.format(((time.time()-t0)*1000))
t1_tag=mesh.createTag('T1',1,iMesh.EntitySet) t1_tag[mesh.rootSet] = t1_set ## Process each timestep for ti in xrange(ntimes): print '>>> Processing Timestep: {0}'.format(ti) # Get the vertex for this timestep tsvert=t_verts[ti] # # Reference the topology for this timestep # ttopo_tag[tsvert]=s2_set tab='\t' indent=' ' for topo_key in param_map: try: topo_len=len(utils.getEntitiesByTag(mesh, topo_key)) except iBase.TagNotFoundError: print '<!!> Could not find tag for {0}'.format(topo_key) continue print '{2}Topology: {0} ({1})'.format(topo_key, topo_len, tab) slice_=(ti,) + param_map[topo_key]['slice_'] for varn in param_map[topo_key]['params']: var=ds.variables[varn] print '{3}{0}:\n{4}shp={1}\n{4}slice_={2}'.format(varn, var.shape, slice_, tab+indent, tab+(indent*2)) try: tag=mesh.getTagHandle(pack_data_tag_name(varn, var.dtype.char, topo_key)) except Exception as ex: print "No tag found for variable '%s'" % varn continue var.set_auto_maskandscale(False)