def addFoamVectorField(self, fieldpath, name, time, projectedField=False): """ """ tSurf = TriSurfaceVector.readFromFoamFile( fieldpath, self.triSurfaceMesh, time=time, projectedField=projectedField ) self.fields[name] = tSurf
def addFoamVectorField(self, fieldpath, name, time, projectedField=False): ''' ''' tSurf = TriSurfaceVector.readFromFoamFile( fieldpath, self.triSurfaceMesh, time=time, projectedField=projectedField) self.fields[name] = tSurf
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]