Esempio n. 1
0
 def addFoamScalarField(self, fieldpath, name, time, projectedField=False):
     """
     """
     tSurf = TriSurfaceScalar.readFromFoamFile(
         fieldpath, self.triSurfaceMesh, time=time, projectedField=projectedField
     )
     self.fields[name] = tSurf
 def addFoamScalarField(self, fieldpath, name, time, projectedField=False):
     '''
     '''
     tSurf = TriSurfaceScalar.readFromFoamFile(
         fieldpath,
         self.triSurfaceMesh,
         time=time,
         projectedField=projectedField)
     self.fields[name] = tSurf
Esempio n. 3
0
    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)