def create_source(self): """ Create a VTK source from data in a SfePy-supported file. Notes ----- All data need to be set here, otherwise time stepping will not work properly - data added by user later will be thrown away on time step change. """ if self.io is None: self.read_common(self.filename) dataset = self.create_dataset() try: out = self.io.read_data(self.step) except ValueError: out = None if out is not None: self.add_data_to_dataset(dataset, out) if self.mat_id_name is not None: mat_id = nm.concatenate(self.mesh.mat_ids) if self.single_color: rm = mat_id.min(), mat_id.max() mat_id[mat_id > rm[0]] = rm[1] dm = DatasetManager(dataset=dataset) dm.add_array(mat_id, self.mat_id_name, 'cell') src = VTKDataSource(data=dataset) # src.print_traits() # debug() return src
def create_source(self): """ Create a VTK source from data in a SfePy-supported file. Notes ----- All data need to be set here, otherwise time stepping will not work properly - data added by user later will be thrown away on time step change. """ if self.io is None: self.read_common(self.filename) dataset = self.create_dataset() try: out = self.io.read_data(self.step) except ValueError: out = None if out is not None: self.add_data_to_dataset(dataset, out) if self.mat_id_name is not None: mat_id = self.mesh.cmesh.cell_groups if self.single_color: rm = mat_id.min(), mat_id.max() mat_id[mat_id > rm[0]] = rm[1] dm = DatasetManager(dataset=dataset) dm.add_array(mat_id, self.mat_id_name, 'cell') src = VTKDataSource(data=dataset) # src.print_traits() # debug() return src
def add_data_to_dataset(self, dataset, data): """Add point and cell data to the dataset.""" dim = self.dim sym = (dim + 1) * dim / 2 dm = DatasetManager(dataset=dataset) for key, val in data.iteritems(): vd = val.data ## print vd.shape if val.mode == 'vertex': if vd.shape[1] == 1: aux = vd.reshape((vd.shape[0],)) elif vd.shape[1] == 2: zz = nm.zeros((vd.shape[0], 1), dtype=vd.dtype) aux = nm.c_[vd, zz] elif vd.shape[1] == 3: aux = vd else: raise ValueError('unknown vertex data format! (%s)'\ % vd.shape) dm.add_array(aux, key, 'point') elif val.mode == 'cell': ne, aux, nr, nc = vd.shape if (nr == 1) and (nc == 1): aux = vd.reshape((ne,)) elif (nr == dim) and (nc == 1): if dim == 3: aux = vd.reshape((ne, dim)) else: zz = nm.zeros((vd.shape[0], 1), dtype=vd.dtype); aux = nm.c_[vd.squeeze(), zz] elif (((nr == sym) or (nr == (dim * dim))) and (nc == 1)) \ or ((nr == dim) and (nc == dim)): vd = vd.squeeze() if dim == 3: if nr == sym: aux = vd[:,[0,3,4,3,1,5,4,5,2]] elif nr == (dim * dim): aux = vd[:,[0,3,4,6,1,5,7,8,2]] else: aux = vd.reshape((vd.shape[0], dim*dim)) else: zz = nm.zeros((vd.shape[0], 1), dtype=vd.dtype); if nr == sym: aux = nm.c_[vd[:,[0,2]], zz, vd[:,[2,1]], zz, zz, zz, zz] elif nr == (dim * dim): aux = nm.c_[vd[:,[0,2]], zz, vd[:,[3,1]], zz, zz, zz, zz] else: aux = nm.c_[vd[:,0,[0,1]], zz, vd[:,1,[0,1]], zz, zz, zz, zz] dm.add_array(aux, key, 'cell')