def createFromFoamFolder(cls, pathname, xViewBasis, yViewBasis=None, viewAnchor=(0, 0, 0), time=0.0, names=[]): ''' This function creates a TriSurfaceContainer for an OpenFOAM sampled surface folder (e.g./postProcessing/surfaces/0/planeXY/) and loads all the fields. Arguments: *pathname*: string. Path ot the surface (e.g:/postProcessing/surfaces/0/planeXY/) *xViewBasis*: list or numpy.array of shape=3. x direction of the surface defined in the OpenFOAM coordinate system. *yViewBasis*: list or numpy.array of shape=3. y direction of the surface defined in the OpenFOAM coordinate system.Automatically cacluated with the normal of the surface if set to None. Default=None *viewAnchor*: list or numpy.array of shape=3. Anchor location of the surface defined in the OpenFOAM coordinate system. Default=(0,0,0) *time* float. timeStep of the surface. Default=0 *names*: python list List of surface to load in the container. Returns: *tsc*: pyflowStat.TriSurfaceContainer object ''' pointsFile = os.path.join(pathname, 'points') facesFile = os.path.join(pathname, 'faces') tsm = TriSurfaceMesh.readFromFoamFile(pointsFile=pointsFile, facesFile=facesFile, viewAnchor=viewAnchor, xViewBasis=xViewBasis, yViewBasis=yViewBasis) c = cls(triSurfaceMesh=tsm) c.data['name'] = os.path.basename(pathname) c.data['pathname'] = pathname c.addFieldFromFoamFolder(names=names, time=time) return c
def createFromHdf5(cls, hdf5Parser, xViewBasis, yViewBasis=None, viewAnchor=(0, 0, 0), srcBasisSrc=[[1, 0, 0], [0, 1, 0], [0, 0, 1]]): ''' ''' tsm = TriSurfaceMesh.readFromHdf5(hdf5Parser=hdf5Parser, xViewBasis=xViewBasis, yViewBasis=yViewBasis, viewAnchor=viewAnchor, srcBasisSrc=srcBasisSrc) return cls(triSurfaceMesh=tsm)
def createFromFoamFolder(cls, pathname, xViewBasis, yViewBasis=None, viewAnchor=(0, 0, 0), time=0.0, names=[]): """ This function creates a TriSurfaceContainer for an OpenFOAM sampled surface folder (e.g./postProcessing/surfaces/0/planeXY/) and loads all the fields. Arguments: *pathname*: string. Path ot the surface (e.g:/postProcessing/surfaces/0/planeXY/) *xViewBasis*: list or numpy.array of shape=3. x direction of the surface defined in the OpenFOAM coordinate system. *yViewBasis*: list or numpy.array of shape=3. y direction of the surface defined in the OpenFOAM coordinate system.Automatically cacluated with the normal of the surface if set to None. Default=None *viewAnchor*: list or numpy.array of shape=3. Anchor location of the surface defined in the OpenFOAM coordinate system. Default=(0,0,0) *time* float. timeStep of the surface. Default=0 *names*: python list List of surface to load in the container. Returns: *tsc*: pyflowStat.TriSurfaceContainer object """ pointsFile = os.path.join(pathname, "points") facesFile = os.path.join(pathname, "faces") tsm = TriSurfaceMesh.readFromFoamFile( pointsFile=pointsFile, facesFile=facesFile, viewAnchor=viewAnchor, xViewBasis=xViewBasis, yViewBasis=yViewBasis, ) c = cls(triSurfaceMesh=tsm) c.data["name"] = os.path.basename(pathname) c.data["pathname"] = pathname c.addFieldFromFoamFolder(names=names, time=time) return c
def createFromHdf5( cls, hdf5Parser, xViewBasis, yViewBasis=None, viewAnchor=(0, 0, 0), srcBasisSrc=[[1, 0, 0], [0, 1, 0], [0, 0, 1]], ): """ """ tsm = TriSurfaceMesh.readFromHdf5( hdf5Parser=hdf5Parser, xViewBasis=xViewBasis, yViewBasis=yViewBasis, viewAnchor=viewAnchor, srcBasisSrc=srcBasisSrc, ) return cls(triSurfaceMesh=tsm)
def readReStressFromFoamFile(self, varsFile, pointsFile, facesFile, viewAnchor=(0,0,0), xViewBasis=(1,0,0), yViewBasis=(0,1,0), dx=None, dy=None, interpolationMethod='cubic', kind='min_E'): ''' ''' tsm = TriSurfaceMesh.readFromFoamFile(pointsFile=pointsFile, facesFile=facesFile, viewAnchor=viewAnchor, xViewBasis=xViewBasis, yViewBasis=yViewBasis) tsst = TriSurfaceSymmTensor.readFromFoamFile(varsFile=varsFile, triSurfaceMesh=tsm, time=0, projectedField=False) points = np.vstack((tsst.x,tsst.y)).T #if not hasattr(self,'data'): if not self.data.has_key('dx') or self.data.has_key('dy'): print 'keys dx and dy does not exist' if dx==None: dxlist=[a for a in np.abs(np.diff(points[:,0])) if a>0] dx=np.min(dxlist) if dy==None: dylist=[a for a in np.abs(np.diff(points[:,1])) if a>0] dy=np.min(dylist) MaxX=np.max(points[:,0]) MinX=np.min(points[:,0]) MaxY=np.max(points[:,1]) MinY=np.min(points[:,1]) extent=[MinX,MaxX,MinY,MaxY] #print MinX,MaxX,MinY,MaxY cellsX=int((MaxX-MinX)/dx) cellsY=int((MaxY-MinY)/dy) #print cellsX,cellsY grid_y, grid_x = np.mgrid[MinY:MaxY:np.complex(0,cellsY),MinX:MaxX:np.complex(0,cellsX)] triang = tsst.triangulation uu_bar=self.interpolateField(tsst.txx, grid_x, grid_y, triang, method=interpolationMethod, kind=kind) uv_bar=self.interpolateField(tsst.txy, grid_x, grid_y, triang, method=interpolationMethod, kind=kind) uw_bar=self.interpolateField(tsst.tyy, grid_x, grid_y, triang, method=interpolationMethod, kind=kind) vv_bar=self.interpolateField(tsst.tyy, grid_x, grid_y, triang, method=interpolationMethod, kind=kind) vw_bar=self.interpolateField(tsst.tyz, grid_x, grid_y, triang, method=interpolationMethod, kind=kind) ww_bar=self.interpolateField(tsst.tzz, grid_x, grid_y, triang, method=interpolationMethod, kind=kind) vx_i=np.empty(uu_bar.shape) vy_i=np.empty(uu_bar.shape) vz_i=np.empty(uu_bar.shape) vx_i[:]=np.NAN vy_i[:]=np.NAN vz_i[:]=np.NAN self.vx=np.flipud(vx_i) self.vy=np.flipud(vy_i) self.vz=np.flipud(vz_i) self.extent=extent self.dx=dx self.dy=dy self.minX=MinX self.maxX=MaxX self.minY=MinY self.maxY=MaxY self.createDataDict() print 'adding Tensor' self.data['uu_bar']=np.flipud(uu_bar) self.data['uv_bar']=np.flipud(uv_bar) self.data['uw_bar']=np.flipud(uw_bar) self.data['vv_bar']=np.flipud(vv_bar) self.data['vw_bar']=np.flipud(vw_bar) self.data['ww_bar']=np.flipud(ww_bar) self.data['TKE_bar']=0.5*(self.data['uu_bar']+self.data['vv_bar']+self.data['ww_bar']) else: print 'dict exists' MaxX=self.maxX MinX=self.minX MaxY=self.maxY MinY=self.minY cellsX=int((MaxX-MinX)/self.dx) cellsY=int((MaxY-MinY)/self.dy) #print cellsX,cellsY grid_y, grid_x = np.mgrid[MinY:MaxY:np.complex(0,cellsY),MinX:MaxX:np.complex(0,cellsX)] triang = tsst.triangulation uu_bar=self.interpolateField(tsst.txx, grid_x, grid_y, triang, method=interpolationMethod, kind=kind) uv_bar=self.interpolateField(tsst.txy, grid_x, grid_y, triang, method=interpolationMethod, kind=kind) uw_bar=self.interpolateField(tsst.tyy, grid_x, grid_y, triang, method=interpolationMethod, kind=kind) vv_bar=self.interpolateField(tsst.tyy, grid_x, grid_y, triang, method=interpolationMethod, kind=kind) vw_bar=self.interpolateField(tsst.tyz, grid_x, grid_y, triang, method=interpolationMethod, kind=kind) ww_bar=self.interpolateField(tsst.tzz, grid_x, grid_y, triang, method=interpolationMethod, kind=kind) print 'adding Tensor' self.data['uu_bar']=np.flipud(uu_bar) self.data['uv_bar']=np.flipud(uv_bar) self.data['uw_bar']=np.flipud(uw_bar) self.data['vv_bar']=np.flipud(vv_bar) self.data['vw_bar']=np.flipud(vw_bar) self.data['ww_bar']=np.flipud(ww_bar) self.data['TKE_bar']=0.5*(self.data['uu_bar']+self.data['vv_bar']+self.data['ww_bar'])
def readScalarFromFoamFile(self, varsFile, pointsFile, facesFile, viewAnchor=(0,0,0), xViewBasis=(1,0,0), yViewBasis=(0,1,0), dx=None, dy=None, interpolationMethod='cubic', kind='min_E'): ''' ''' varName=os.path.basename(varsFile) tsm = TriSurfaceMesh.readFromFoamFile(pointsFile=pointsFile, facesFile=facesFile, viewAnchor=viewAnchor, xViewBasis=xViewBasis, yViewBasis=yViewBasis) tss = TriSurfaceScalar.readFromFoamFile(varsFile=varsFile, triSurfaceMesh=tsm, time=0, projectedField=False) points = np.vstack((tss.x,tss.y)).T #if not hasattr(self,'data'): #print 'dict does not exists' if not self.data.has_key('dx') or self.data.has_key('dy'): print 'keys dx and dy does not exist' if dx==None: dxlist=[a for a in np.abs(np.diff(points[:,0])) if a>0] dx=np.min(dxlist) if dy==None: dylist=[a for a in np.abs(np.diff(points[:,1])) if a>0] dy=np.min(dylist) MaxX=np.max(points[:,0]) MinX=np.min(points[:,0]) MaxY=np.max(points[:,1]) MinY=np.min(points[:,1]) extent=[MinX,MaxX,MinY,MaxY] #print MinX,MaxX,MinY,MaxY cellsX=int((MaxX-MinX)/dx) cellsY=int((MaxY-MinY)/dy) #print cellsX,cellsY grid_y, grid_x = np.mgrid[MinY:MaxY:np.complex(0,cellsY),MinX:MaxX:np.complex(0,cellsX)] triang = tss.triangulation # scalar_i=doInterp(triang,tss.s,grid_x, grid_y) scalar_i=self.interpolateField(tss.s,grid_x, grid_y, triang, method=interpolationMethod, kind=kind) vx_i=np.empty(scalar_i.shape) vy_i=np.empty(scalar_i.shape) vz_i=np.empty(scalar_i.shape) vx_i[:]=np.NAN vy_i[:]=np.NAN vz_i[:]=np.NAN self.vx=np.flipud(vx_i) self.vy=np.flipud(vy_i) self.vz=np.flipud(vz_i) self.extent=extent self.minX=MinX self.maxX=MaxX self.minY=MinY self.maxY=MaxY self.dx=dx self.dy=dy self.createDataDict() self.data[varName]=np.flipud(scalar_i) else: print 'dict exists' MaxX=self.extent[1] MinX=self.extent[0] MaxY=self.extent[3] MinY=self.extent[2] cellsX=int((MaxX-MinX)/self.dx) cellsY=int((MaxY-MinY)/self.dy) #print cellsX,cellsY grid_y, grid_x = np.mgrid[MinY:MaxY:np.complex(0,cellsY),MinX:MaxX:np.complex(0,cellsX)] triang = tss.triangulation scalar_i=self.interpolateField(tss.s,grid_x, grid_y, triang, method=interpolationMethod, kind=kind) print 'adding scalar',varName self.data[varName]=np.flipud(scalar_i)
def readVelFromFoamFile(self, varsFile, pointsFile, facesFile, viewAnchor=(0,0,0), xViewBasis=(1,0,0), yViewBasis=(0,1,0), dx=None, dy=None, interpolationMethod='cubic', kind='min_E'): ''' ''' tsm = TriSurfaceMesh.readFromFoamFile(pointsFile=pointsFile, facesFile=facesFile, viewAnchor=viewAnchor, xViewBasis=xViewBasis, yViewBasis=yViewBasis) tsv = TriSurfaceVector.readFromFoamFile(varsFile=varsFile, triSurfaceMesh=tsm, time=0, projectedField=False) points = np.vstack((tsv.x,tsv.y)).T print 'Creating Grid and Interpolator' if dx==None: dxlist=[a for a in np.abs(np.diff(points[:,0])) if a>0] dx=np.min(dxlist) if dy==None: dylist=[a for a in np.abs(np.diff(points[:,1])) if a>0] dy=np.min(dylist) MaxX=np.max(points[:,0]) MinX=np.min(points[:,0]) MaxY=np.max(points[:,1]) MinY=np.min(points[:,1]) extent=[MinX-dx/2,MaxX+dx/2,MinY-dy/2,MaxY+dy/2] cellsX=int((MaxX-MinX)/dx)+1 cellsY=int((MaxY-MinY)/dy)+1 grid_y, grid_x = np.mgrid[MinY:MaxY:np.complex(0,cellsY),MinX:MaxX:np.complex(0,cellsX)] triang = tsv.triangulation vx_i=self.interpolateField(tsv.vx,grid_x, grid_y, triang, method=interpolationMethod, kind=kind) vy_i=self.interpolateField(tsv.vx,grid_x, grid_y, triang, method=interpolationMethod, kind=kind) vz_i=self.interpolateField(tsv.vx,grid_x, grid_y, triang, method=interpolationMethod, kind=kind) self.vx=np.flipud(vx_i) self.vy=np.flipud(vy_i) self.vz=np.flipud(vz_i) self.dx=dx self.dy=dy self.minX=MinX self.maxX=MaxX self.minY=MinY self.maxY=MaxY self.createDataDict() self.extent=extent
def readFromFoamFile(self, pointsFile, facesFile, velFile, scalarFileList=[], symTensorFileList=[], viewAnchor=(0,0,0), xViewBasis=(1,0,0), yViewBasis=(0,1,0), dx=None, dy=None, interpolationMethod='cubic', kind='min_E'): ''' Read an OpenFOAM surface (triangulated grid) in the current Surface object (cartesian grid). As the "grid" change (tri to cartesian), the value must be interpolated. Arguments: *pointFile*: python string. Point file generate by OpenFOAM. This is the grid point coordinates. *facesFile*: python string. Face file generate by OpenFOAM. It is a list of triangles, which compose the grid. *velFile*: python string. Vector file generate by OpenFOAM. This is the data associated with each grid point. *scalarFileList*: python list. *symTensorFileList*: python list. *dx*: python float. Physical size of a pixel in the Surface class (x discretisation). Must be given in mm. *dy*: python float. Physical size of a pixel in the Surface class (y discretisation). Must be given in mm. *interpolationMethod*: python string. Interpolation method used to interpolate from the triangulated grid to the cartesian grid. "cubic" or "linear". Default="cubic" *kind*: python string. Defines the algorithm used for the cubic interpolation. Choices: "min_E" or "geom". "min_E" should be the more accurate, but it is also the most time time consuming. Returns: none ''' print 'Reading Velocity' tsm = TriSurfaceMesh.readFromFoamFile(pointsFile=pointsFile, facesFile=facesFile, viewAnchor=viewAnchor, xViewBasis=xViewBasis, yViewBasis=yViewBasis) tsv = TriSurfaceVector.readFromFoamFile(varsFile=velFile, triSurfaceMesh=tsm, time=0, projectedField=False) points = np.vstack((tsv.x,tsv.y)).T print 'Creating Grid and Interpolator' if dx==None: dxlist=[a for a in np.abs(np.diff(points[:,0])) if a>0] dx=np.min(dxlist) if dy==None: dylist=[a for a in np.abs(np.diff(points[:,1])) if a>0] dy=np.min(dylist) MaxX=np.max(points[:,0]) MinX=np.min(points[:,0]) MaxY=np.max(points[:,1]) MinY=np.min(points[:,1]) extent=[MinX-dx/2,MaxX+dx/2,MinY-dy/2,MaxY+dy/2] cellsX=int((MaxX-MinX)/dx)+1 cellsY=int((MaxY-MinY)/dy)+1 grid_y, grid_x = np.mgrid[MinY:MaxY:np.complex(0,cellsY),MinX:MaxX:np.complex(0,cellsX)] triang = tsv.triangulation print 'Interpolating Velocity' vx_i=self.interpolateField(tsv.vx,grid_x, grid_y, triang, method=interpolationMethod, kind=kind) vy_i=self.interpolateField(tsv.vy,grid_x, grid_y, triang, method=interpolationMethod, kind=kind) vz_i=self.interpolateField(tsv.vz,grid_x, grid_y, triang, method=interpolationMethod, kind=kind) self.vx=np.flipud(vx_i) self.vy=np.flipud(vy_i) self.vz=np.flipud(vz_i) self.dx=dx self.dy=dy self.minX=MinX self.maxX=MaxX self.minY=MinY self.maxY=MaxY self.extent=extent self.createDataDict() for scalarFile in scalarFileList: varName=os.path.basename(scalarFile) print 'Reading Scalar',varName tsv.addFieldFromFoamFile(fieldFile=scalarFile,fieldname=varName) scalar_i=self.interpolateField(tsv[varName],grid_x, grid_y, triang, method=interpolationMethod, kind=kind) self.data[varName]=np.flipud(scalar_i) for symTensorFile in symTensorFileList: varName=os.path.basename(symTensorFile) print 'Reading Tenstor',varName tsv.addFieldFromFoamFile(fieldFile=symTensorFile,fieldname=varName) tensor_11=self.interpolateField(tsv[varName][:,0],grid_x, grid_y, triang, method=interpolationMethod, kind=kind) tensor_12=self.interpolateField(tsv[varName][:,1],grid_x, grid_y, triang, method=interpolationMethod, kind=kind) tensor_13=self.interpolateField(tsv[varName][:,2],grid_x, grid_y, triang, method=interpolationMethod, kind=kind) tensor_22=self.interpolateField(tsv[varName][:,3],grid_x, grid_y, triang, method=interpolationMethod, kind=kind) tensor_23=self.interpolateField(tsv[varName][:,4],grid_x, grid_y, triang, method=interpolationMethod, kind=kind) tensor_33=self.interpolateField(tsv[varName][:,5],grid_x, grid_y, triang, method=interpolationMethod, kind=kind) tensor_11=np.flipud(tensor_11) tensor_12=np.flipud(tensor_12) tensor_13=np.flipud(tensor_13) tensor_22=np.flipud(tensor_22) tensor_23=np.flipud(tensor_23) tensor_33=np.flipud(tensor_33) if varName=='UPrime2Mean': print 'Adding UPrime2Mean' self.data['uu_bar']=tensor_11 self.data['uv_bar']=tensor_12 self.data['uw_bar']=tensor_13 self.data['vv_bar']=tensor_22 self.data['vw_bar']=tensor_23 self.data['ww_bar']=tensor_33 self.data['TKE_bar']=0.5*(self.data['uu_bar']+self.data['vv_bar']+self.data['ww_bar']) else: print 'Adding symTensor',varName self.data[varName+'_ii']=[tensor_11,tensor_12,tensor_13,tensor_22,tensor_23,tensor_33]