SOLPSxport.py
def calcPsiVals(self, plotit = False):
        """
        Call b2plot to get the locations of each grid cell in psin space

        Saves the values to dictionaries in self.data['solpsData']
        """
        from scipy import interpolate

        """
        Find grid corners first:
          0: lower left
          1: lower right
          2: upper left
          3: upper right

        Average location of cells 0 and 2 for middle of 'top' surface, 
        which is the top looking at outboard midplane
        Don't average over whole cell, dR << dZ at outboard midplane 
        and surface has curvature, so psin will be low

        jxa = poloidal cell index for the outer midplane
        crx = radial coordinate corner of grid [m]
        cry = vertical coordinate corner of grid [m]
        writ = write b2plot.write file
        f.y = plot against y
        """
        wdir = self.data['workdir']

        dsa, crLowerLeft = sut.B2pl('0 crx writ jxa f.y', wdir = wdir)
        # dummy, crLowerRight = B2pl('1 crx writ jxa f.y', wdir = wdir)
        # Only 2 unique psi values per cell, grab 0 and 2
        dummy, crUpperLeft = sut.B2pl('2 crx writ jxa f.y', wdir = wdir)  # all x inds are the same
        dummy, czLowerLeft = sut.B2pl('0 cry writ jxa f.y', wdir = wdir)
        dummy, czUpperLeft = sut.B2pl('2 cry writ jxa f.y', wdir = wdir)
        ncells = len(dummy)

        g = sut.loadg(self.data['gfile_loc'])
        psiN = (g['psirz'] - g['simag']) / (g['sibry'] - g['simag'])

        dR = g['rdim'] / (g['nw'] - 1)
        dZ = g['zdim'] / (g['nh'] - 1)

        gR = []
        for i in range(g['nw']):
            gR.append(g['rleft'] + i * dR)

        gZ = []
        for i in range(g['nh']):
            gZ.append(g['zmid'] - 0.5 * g['zdim'] + i * dZ)

        gR = np.array(gR)
        gZ = np.array(gZ)

        R_solps_top = 0.5 * (np.array(crLowerLeft) + np.array(crUpperLeft))
        Z_solps_top = 0.5 * (np.array(czLowerLeft) + np.array(czUpperLeft))

        psiNinterp = interpolate.interp2d(gR, gZ, psiN, kind = 'cubic')

        psi_solps = np.zeros(ncells)
        for i in range(ncells):
            psi_solps_LL = psiNinterp(crLowerLeft[i], czLowerLeft[i])
            psi_solps_UL = psiNinterp(crUpperLeft[i], czUpperLeft[i])
            psi_solps[i] = np.mean([psi_solps_LL,psi_solps_UL])

        self.data['solpsData']['crLowerLeft'] = np.array(crLowerLeft)
        self.data['solpsData']['czLowerLeft'] = np.array(czLowerLeft)
        self.data['solpsData']['dsa'] = np.array(dsa)
        self.data['solpsData']['psiSOLPS'] = np.array(psi_solps)

        if plotit:
            psiN_copy = psiN.copy()
            psiN_copy[psiN > 1.01] = np.nan
            psin_masked = np.ma.masked_invalid(psiN_copy)

            plt.figure()
            plt.pcolormesh(gR, gZ, psin_masked, cmap = 'inferno')
            plt.colorbar()
            plt.plot(g['rlim'], g['zlim'], 'k', lw = 2)
            plt.contour(gR, gZ, psiN, [1], colors = 'k')
            plt.title('$\psi_N$ from g file')
            plt.axis('equal')
            plt.xlim([np.min(gR), np.max(gR)])
            plt.ylim([np.min(gZ), np.max(gZ)])
            plt.plot(R_solps_top, Z_solps_top, 'g', lw = 3)

            plt.figure()
            plt.plot(R_solps_top, psi_solps, 'k', lw = 2)
            plt.xlabel('R at midplane (m)')
            plt.ylabel('$\psi_N$')

            plt.show(block = False)

        Call b2plot to get the locations of each grid cell in psin space

        Saves the values to dictionaries in self.data['solpsData']
        
Call b2plot to get the locations of each grid cell in psin space
Saves the values to dictionaries in self.data['solpsData']
Call b2plot to get the locations of each grid cell in psin space Saves the values to dictionaries in self . data [ ' solpsData ' ]
def calcPsiVals(self, plotit = False):
        from scipy import interpolate
        wdir = self.data['workdir']
        dsa, crLowerLeft = sut.B2pl('0 crx writ jxa f.y', wdir = wdir)
        dummy, crUpperLeft = sut.B2pl('2 crx writ jxa f.y', wdir = wdir)  
        dummy, czLowerLeft = sut.B2pl('0 cry writ jxa f.y', wdir = wdir)
        dummy, czUpperLeft = sut.B2pl('2 cry writ jxa f.y', wdir = wdir)
        ncells = len(dummy)
        g = sut.loadg(self.data['gfile_loc'])
        psiN = (g['psirz'] - g['simag']) / (g['sibry'] - g['simag'])
        dR = g['rdim'] / (g['nw'] - 1)
        dZ = g['zdim'] / (g['nh'] - 1)
        gR = []
        for i in range(g['nw']):
            gR.append(g['rleft'] + i * dR)
        gZ = []
        for i in range(g['nh']):
            gZ.append(g['zmid'] - 0.5 * g['zdim'] + i * dZ)
        gR = np.array(gR)
        gZ = np.array(gZ)
        R_solps_top = 0.5 * (np.array(crLowerLeft) + np.array(crUpperLeft))
        Z_solps_top = 0.5 * (np.array(czLowerLeft) + np.array(czUpperLeft))
        psiNinterp = interpolate.interp2d(gR, gZ, psiN, kind = 'cubic')
        psi_solps = np.zeros(ncells)
        for i in range(ncells):
            psi_solps_LL = psiNinterp(crLowerLeft[i], czLowerLeft[i])
            psi_solps_UL = psiNinterp(crUpperLeft[i], czUpperLeft[i])
            psi_solps[i] = np.mean([psi_solps_LL,psi_solps_UL])
        self.data['solpsData']['crLowerLeft'] = np.array(crLowerLeft)
        self.data['solpsData']['czLowerLeft'] = np.array(czLowerLeft)
        self.data['solpsData']['dsa'] = np.array(dsa)
        self.data['solpsData']['psiSOLPS'] = np.array(psi_solps)
        if plotit:
            psiN_copy = psiN.copy()
            psiN_copy[psiN > 1.01] = np.nan
            psin_masked = np.ma.masked_invalid(psiN_copy)
            plt.figure()
            plt.pcolormesh(gR, gZ, psin_masked, cmap = 'inferno')
            plt.colorbar()
            plt.plot(g['rlim'], g['zlim'], 'k', lw = 2)
            plt.contour(gR, gZ, psiN, [1], colors = 'k')
            plt.title('$\psi_N$ from g file')
            plt.axis('equal')
            plt.xlim([np.min(gR), np.max(gR)])
            plt.ylim([np.min(gZ), np.max(gZ)])
            plt.plot(R_solps_top, Z_solps_top, 'g', lw = 3)
            plt.figure()
            plt.plot(R_solps_top, psi_solps, 'k', lw = 2)
            plt.xlabel('R at midplane (m)')
            plt.ylabel('$\psi_N$')
            plt.show(block = False)
def calcPsiVals ( self , plotit = False ) : from scipy import interpolate """
        Find grid corners first:
          0: lower left
          1: lower right
          2: upper left
          3: upper right

        Average location of cells 0 and 2 for middle of 'top' surface, 
        which is the top looking at outboard midplane
        Don't average over whole cell, dR << dZ at outboard midplane 
        and surface has curvature, so psin will be low

        jxa = poloidal cell index for the outer midplane
        crx = radial coordinate corner of grid [m]
        cry = vertical coordinate corner of grid [m]
        writ = write b2plot.write file
        f.y = plot against y
        """ wdir = self . data [ 'workdir' ] dsa , crLowerLeft = sut . B2pl ( '0 crx writ jxa f.y' , wdir = wdir ) dummy , crUpperLeft = sut . B2pl ( '2 crx writ jxa f.y' , wdir = wdir ) dummy , czLowerLeft = sut . B2pl ( '0 cry writ jxa f.y' , wdir = wdir ) dummy , czUpperLeft = sut . B2pl ( '2 cry writ jxa f.y' , wdir = wdir ) ncells = len ( dummy ) g = sut . loadg ( self . data [ 'gfile_loc' ] ) psiN = ( g [ 'psirz' ] - g [ 'simag' ] ) / ( g [ 'sibry' ] - g [ 'simag' ] ) dR = g [ 'rdim' ] / ( g [ 'nw' ] - 1 ) dZ = g [ 'zdim' ] / ( g [ 'nh' ] - 1 ) gR = [ ] for i in range ( g [ 'nw' ] ) : gR . append ( g [ 'rleft' ] + i * dR ) gZ = [ ] for i in range ( g [ 'nh' ] ) : gZ . append ( g [ 'zmid' ] - 0.5 * g [ 'zdim' ] + i * dZ ) gR = np . array ( gR ) gZ = np . array ( gZ ) R_solps_top = 0.5 * ( np . array ( crLowerLeft ) + np . array ( crUpperLeft ) ) Z_solps_top = 0.5 * ( np . array ( czLowerLeft ) + np . array ( czUpperLeft ) ) psiNinterp = interpolate . interp2d ( gR , gZ , psiN , kind = 'cubic' ) psi_solps = np . zeros ( ncells ) for i in range ( ncells ) : psi_solps_LL = psiNinterp ( crLowerLeft [ i ] , czLowerLeft [ i ] ) psi_solps_UL = psiNinterp ( crUpperLeft [ i ] , czUpperLeft [ i ] ) psi_solps [ i ] = np . mean ( [ psi_solps_LL , psi_solps_UL ] ) self . data [ 'solpsData' ] [ 'crLowerLeft' ] = np . array ( crLowerLeft ) self . data [ 'solpsData' ] [ 'czLowerLeft' ] = np . array ( czLowerLeft ) self . data [ 'solpsData' ] [ 'dsa' ] = np . array ( dsa ) self . data [ 'solpsData' ] [ 'psiSOLPS' ] = np . array ( psi_solps ) if plotit : psiN_copy = psiN . copy ( ) psiN_copy [ psiN > 1.01 ] = np . nan psin_masked = np . ma . masked_invalid ( psiN_copy ) plt . figure ( ) plt . pcolormesh ( gR , gZ , psin_masked , cmap = 'inferno' ) plt . colorbar ( ) plt . plot ( g [ 'rlim' ] , g [ 'zlim' ] , 'k' , lw = 2 ) plt . contour ( gR , gZ , psiN , [ 1 ] , colors = 'k' ) plt . title ( '$\psi_N$ from g file' ) plt . axis ( 'equal' ) plt . xlim ( [ np . min ( gR ) , np . max ( gR ) ] ) plt . ylim ( [ np . min ( gZ ) , np . max ( gZ ) ] ) plt . plot ( R_solps_top , Z_solps_top , 'g' , lw = 3 ) plt . figure ( ) plt . plot ( R_solps_top , psi_solps , 'k' , lw = 2 ) plt . xlabel ( 'R at midplane (m)' ) plt . ylabel ( '$\psi_N$' ) plt . show ( block = False )
Call b2plot to get the locations of each grid cell in psin space
Saves the values to dictionaries in self.data['solpsData']
Call b2plot to get the locations of each grid cell in psin space Saves the values to dictionaries in self . data [ ' solpsData ' ]
"""
        Call b2plot to get the locations of each grid cell in psin space

        Saves the values to dictionaries in self.data['solpsData']
        """ """
        Find grid corners first:
          0: lower left
          1: lower right
          2: upper left
          3: upper right

        Average location of cells 0 and 2 for middle of 'top' surface, 
        which is the top looking at outboard midplane
        Don't average over whole cell, dR << dZ at outboard midplane 
        and surface has curvature, so psin will be low

        jxa = poloidal cell index for the outer midplane
        crx = radial coordinate corner of grid [m]
        cry = vertical coordinate corner of grid [m]
        writ = write b2plot.write file
        f.y = plot against y
        """ # dummy, crLowerRight = B2pl('1 crx writ jxa f.y', wdir = wdir) # Only 2 unique psi values per cell, grab 0 and 2 # all x inds are the same
self
plotit