def writeVTKSeriesAsBlock(self,outputdir='.',prefix=None,Umean=None,step=1):# {{{ """ Write out a 3D block wherein the x-coordinate is time """ if not prefix: prefix = self.prefix import os if not os.path.isdir(outputdir): print 'Creating output dir :',outputdir os.makedirs(outputdir) if Umean is None: Umean = self.Umean # scale fluctuations Nt = self.N / step up = np.zeros((self.NY,self.NZ,Nt)); up[:,:,:] = self.V[0,:,:,:Nt*step:step] vp = np.zeros((self.NY,self.NZ,Nt)); vp[:,:,:] = self.V[1,:,:,:Nt*step:step] wp = np.zeros((self.NY,self.NZ,Nt)); wp[:,:,:] = self.V[2,:,:,:Nt*step:step] for iz in range(self.NZ): up[:,iz,:] *= self.scaling[0,iz] vp[:,iz,:] *= self.scaling[1,iz] wp[:,iz,:] *= self.scaling[2,iz] # write out VTK import os fname = outputdir + os.sep + prefix + '_block.vtk' VTKwriter.vtk_write_structured_points( open(fname,'wb'), #binary mode Nt, self.NY, self.NZ, [ up,vp,wp ], datatype=['vector'], dx=step*Umean*self.dt, dy=self.dy, dz=self.dz, dataname=['u\''], #['fluctuations'], #dataname=['TurbSim_velocity'], origin=[0.,self.y[0],self.z[0]], indexorder='jki') print 'Wrote',fname
def writeVTK(self,fname,itime=None,output_time=None,stdout='verbose'):# {{{ """ Write out binary VTK file with a single vector field. Can specify time index or output time. """ if not self.meanProfilesSet: self.setMeanProfiles() if output_time: itime = int(output_time / self.dt) if itime is None: print 'Need to specify itime or output_time' return if stdout=='overwrite': sys.stdout.write('\rWriting time step {:d} : t= {:f}'.format(itime,self.t[itime])) else: #if stdout=='verbose': print 'Writing out VTK for time step',itime,': t=',self.t[itime] # scale fluctuations up = np.zeros((1,self.NY,self.NZ)); up[0,:,:] = self.V[0,:,:,itime] vp = np.zeros((1,self.NY,self.NZ)); vp[0,:,:] = self.V[1,:,:,itime] wp = np.zeros((1,self.NY,self.NZ)); wp[0,:,:] = self.V[2,:,:,itime] for iz in range(self.NZ): up[0,:,iz] *= self.scaling[0,iz] vp[0,:,iz] *= self.scaling[1,iz] wp[0,:,iz] *= self.scaling[2,iz] # calculate instantaneous velocity U = up.copy() V = vp.copy() W = wp.copy() for iz in range(self.NZ): U[0,:,iz] += self.Uinlet[iz,0] V[0,:,iz] += self.Uinlet[iz,1] W[0,:,iz] += self.Uinlet[iz,2] # write out VTK VTKwriter.vtk_write_structured_points( open(fname,'wb'), #binary mode 1, self.NY, self.NZ, [ U,V,W, up,vp,wp ], datatype=['vector','vector'], dx=1.0, dy=self.dy, dz=self.dz, dataname=['U','u\''], #['fluctuations'], #dataname=['TurbSim_velocity'], origin=[0.,self.y[0],self.z[0]], indexorder='ijk')
def writeVTK(self,fname,itime=None,output_time=None): """ Write out binary VTK file with a single vector field. Can specify time index or output time. Note: VTKwriter expects velocity arrays of form u[NY,NX,NZ] """ if output_time: itime = int(output_time / self.dt) if not itime: print 'Need to specify itime or output_time' return print 'Writing out time step',itime,': t=',self.t[itime] u = np.zeros((self.NY,1,self.NZ)); u[:,0,:] = np.flipud(self.field['u'][itime,:,:]).T v = np.zeros((self.NY,1,self.NZ)); v[:,0,:] = np.flipud(self.field['v'][itime,:,:]).T w = np.zeros((self.NY,1,self.NZ)); w[:,0,:] = np.flipud(self.field['w'][itime,:,:]).T VTKwriter.vtk_write_structured_points( open(fname,'wb'), #binary mode 1,self.NY,self.NZ, [u,v,w], datatype=['vector'], dx=1.0,dy=self.dy,dz=self.dz, dataname=['TurbSim_velocity'], origin=[0.,self.y[0],self.z[0]] )