def __init__ (self) : self.problemname = "" self.p_s = blob.spline() self.Psi_s = blob.spline() self.dPsi_s = blob.spline() self.l1_s = blob.spline() self.l2_s = blob.spline() self.Rmin = 0.0 self.Rmax = 0.0 self.axis = 0.0 self.Rin = 0.0 self.Rout = 0.0 self.Zin = 0.0 self.Zout = 0.0 self.NR = 0 self.NZ = 0 self.data = [] self.datalist = []
def lcfs_points( self, a, i, j ) : """ Find the interpolated points for the LCFS. """ Rin = self.Rin Rout = self.Rout Zin = self.Zin Zout = self.Zout NR = self.NR NZ = self.NZ r_coor = self.r_coor z_coor = self.z_coor p = [] s = blob.spline() # offset for guessing LCFS position #dR = 1.5 * ( Rout - Rin ) / NR #dZ = 1.5 * ( Zout - Zin ) / NZ dR = 0.0 dZ = 0.0 def ss( RR ) : """ Wrapper function for the spline evaluation. This is used to catch out-of-bounds guesses from the numerical root finder. Note that this function uses the spline objects, so beware of side effects. """ if RR >= s.R[0] and RR <= s.R[-1] : try : ZZ = s.get_Z_for_R( RR ) except blob.SplineError, e : # print e return 1.0 if type(ZZ) == float : return ZZ else : return 1.0 else :
def __init__ (self) : self.Rhat = -1 self.root = -1 self.spline = blob.spline()
for i in rr : try : xi = integrate.quad(a, Rmin, i, full_output=1)[0] except integrate.quadpack.error, e : print " ", e print " Arguments ::> Rhat =", r, "R =", R return 0.0 xixi.append(xi) s = blob.spline() s.build( rr, xixi ) return s def psi_solver( self, R1, Z1, RhGuess='none', xi_bucket='none' ) : """ Return the value of psi for a given point { R1, Z1 }, given splined plasma boundary l_s. We require two l_s splines; l_s1 in the usual coordinates, and l_s2 in coordinates rotated -90 degrees. This is to allow us to avoid solving for differences of quantities tending toward infinity. """
def __init__ (self) : self.problemname = "" # radial quantities self.p_s = blob.spline() self.dp_s = blob.spline() self.Psi_s = blob.spline() self.Psi_ss = blob.spline() self.dPsi_s = blob.spline() self.q_s = blob.spline() self.F_s = blob.spline() self.Bt_s = blob.spline() self.Bp_s = blob.spline() self.beta_s = blob.spline() self.betaP_s = blob.spline() self.modB_s = blob.spline() # flux boundary curves self.l1_s = blob.spline() self.l2_s = blob.spline() # scalars self.Rmin = 0.0 self.Rmax = 0.0 self.axis = 0.0 self.Rin = 0.0 self.Rout = 0.0 self.Zin = 0.0 self.Zout = 0.0 self.NR = 0 self.NZ = 0 self.data = [] self.datalist = [] # memoizatized quantities for for G_s self.G_s_last_i = 0 self.G_s_last_j = 0 self.G_s_K = [] # mapping function vars self.Rh_cached = 0.0 self.R_cached = 0.0
def ImportCUBEdata( self, CUBEpath, problemname ) : """ Import a solution from CUBE data and initialize the problem information. """ self.problemname = problemname flux_path = CUBEpath + '/bin/flux.txt' radials_path = CUBEpath + '/bin/results.txt' input_path = CUBEpath + '/input.txt' # make sure we can read the CUBE result! if not access( flux_path, R_OK ) : raise DataImportError, 'Cannot read from ' + flux_path if not access( radials_path, R_OK ) : raise DataImportError, 'Cannot read from ' + radials_path if not access( input_path, R_OK ) : raise DataImportError, 'Cannot read from ' + input_path print " ::> Importing " + CUBEpath + " ..." # read flux data data = io.array_import.read_array( flux_path ) print " Imported " + str(len(data)) + "x" + \ str(len(data[0])) + " flux grid" # For various builds of CUBE, the format of results.txt # is different. Pierre occasionally adds columns to his # output. So, we must pay attention to the column labels! f = open( radials_path, 'r' ) labels = f.readline().split( "\t" ) f.close() labels.pop() # we don't want the "\n" at the end R_index = labels.index("R") p_index = labels.index("p") dpsi_index = labels.index("dpsi") F_index = labels.index("F") q_index = labels.index("q") Bt_index = labels.index("Btoro") Bp_index = labels.index("Bpolo") # read radial quantities a = io.array_import.read_array( radials_path ) R = a[1:,R_index] pZ = a[1:,p_index] dPsiZ = a[1:,dpsi_index] F = a[1:,F_index] q = a[1:,q_index] Bt = a[1:,Bt_index] Bp = a[1:,Bp_index] # some versions of CUBE don't output dp ! if labels.__contains__("dp") : dpZ = a[1:, labels.index("dp")] else : p = blob.spline() dp = blob.spline() p.build( R, pZ ) dp.build( R, map( p.get_dZ_for_R, R ) ) del( p ) dpZ = dp.Z print " Imported radial quantity arrays of length " + \ str(len(R)) # read grid coordinates f = open( input_path, 'r' ) s = "\n" while s != [''] : s = f.readline().split(',') if s[0] == 'lower_mesh_point' : Rin = float(s[1]) Zin = float(s[2]) if s[0] == 'upper_mesh_point' : Rout = float(s[1]) Zout = float(s[2]) f.close() print " Grid boundaries :" print " Rin : " + str(Rin) print " Rout : " + str(Rout) print " Zin : " + str(Zin) print " Zout : " + str(Zout) # initialize the problem self.Import( data, R, pZ, \ R, dpZ, \ R, dPsiZ, \ R, F, \ R, q, \ R, Bt, \ R, Bp, \ Rin, Rout, Zin, Zout ) print " :: Imported Problem_" + problemname self.make_beta() self.make_betaP() self.make_modB() print " :: Generated beta and |B| splines"