def setTemperature(self, T, psi=None): """ Sets the temperature profile Parameters ---------- T - temperature in eV Can be: 1. A function taking normalised psi and returning density ne = T(psinorm) 2. An array of values on psi grid (uniform between 0 and 1 if not) 3. A constant psi - Optional array of normalised psi values """ # Check if we can call it to get a value try: val = T(0.5) Tfunc = T # Use this new function except: # Not a function type # Check if it's an array type try: val = T[0] p = psi if p == None: p = linspace(0.0, 1.0, num=len(T), endpoint=False) Tfunc = interp1d(p, T) except: # Should be a constant val = T Tfunc = lambda x: T # val should now contain a number if size(val) > 1: raise ValueError("T argument doesn't yield a single value") try: test = 2. * val + val * val except: raise ValueError("T argument must give a numerical value") # Checks passed, so can set the density function self.temp = Tfunc # Set density function to use the temperature self.dens = lambda x: self.pressure(x) / (2. * 1.602e-19 * self.temp(x) )
def setTemperature(self, T, psi=None): """ Sets the temperature profile Parameters ---------- T - temperature in eV Can be: 1. A function taking normalised psi and returning density ne = T(psinorm) 2. An array of values on psi grid (uniform between 0 and 1 if not) 3. A constant psi - Optional array of normalised psi values """ # Check if we can call it to get a value try: val = T(0.5) Tfunc = T # Use this new function except: # Not a function type # Check if it's an array type try: val = T[0] p = psi if p == None: p = linspace(0.0, 1.0, num=len(T), endpoint=False) Tfunc = interp1d(p, T) except: # Should be a constant val = T Tfunc = lambda x: T # val should now contain a number if size(val) > 1: raise ValueError("T argument doesn't yield a single value") try: test = 2.0 * val + val * val except: raise ValueError("T argument must give a numerical value") # Checks passed, so can set the density function self.temp = Tfunc # Set density function to use the temperature self.dens = lambda x: self.pressure(x) / (2.0 * 1.602e-19 * self.temp(x))
def setDensity(self, dens, psi=None): """ Sets the density profile Parameters ---------- dens - Density in m^-3 Can be: 1. A function taking normalised psi and returning density ne = dens(psinorm) 2. An array of values on psi grid (uniform between 0 and 1 if not) 3. A constant psi - Optional array of normalised psi values """ # Check if we can call it to get a value try: val = dens(0.5); densfunc = dens; # Use this new function except: # Not a function type # Check if it's an array type try: val = dens[0] p = psi if p == None: p = linspace(0.0, 1.0, num=len(dens), endpoint=False) densfunc = interp1d(p, dens) except: # Should be a constant val = dens densfunc = lambda x: dens # val should now contain a number if size(val) > 1: raise ValueError("dens argument doesn't yield a single value") try: test = 2.*val + val*val except: raise ValueError("dens argument must give a numerical value") # Checks passed, so can set the density function self.dens = densfunc # Set temperature function to use the density, assuming Ti = Te self.temp = lambda x: self.pressure(x) / (2. * 1.602e-19 * self.dens(x) )
def __init__(self, fix=None): """ Construct an Equilibrium object Parameters ---------- If no inputs are given, an empty equilibrium is created which can be added to afterwards fix = Dictionary of values describing fixed-boundary solution on flux surfaces. Assumed to contain the following keys: 'npsi' Number of points in poloidal flux psi 'npol' Number of poloidal points 'psi' Poloidal flux """ if fix != None: # Check that fix has the required keys required = ['npsi', 'npol', 'psi', 'f(psi)', 'p', 'R', 'Z', 'Bp'] for r in required: if not fix.has_key(r): raise ValueError("Missing key: " + r) if not fix.has_key("psinorm"): # Add normalised psi, assuming core to edge psi = fix['psi'] fix['psinorm'] = (psi - psi[0]) / (psi[-1] - psi[0]) # Make a deep copy of the data so it can't be modified afterwards # in unpredictable ways self.fix = deepcopy(fix) # Create a function to return the pressure self.pressure = interp1d(self.fix['psinorm'], self.fix['p'], copy=False) # See if density, temperature profiles also set if fix.has_key("ne"): self.setDensity(self.fix["ne"]) else: self.fix = None
def __init__(self, fix=None): """ Construct an Equilibrium object Parameters ---------- If no inputs are given, an empty equilibrium is created which can be added to afterwards fix = Dictionary of values describing fixed-boundary solution on flux surfaces. Assumed to contain the following keys: 'npsi' Number of points in poloidal flux psi 'npol' Number of poloidal points 'psi' Poloidal flux """ if fix != None: # Check that fix has the required keys required = ["npsi", "npol", "psi", "f(psi)", "p", "R", "Z", "Bp"] for r in required: if not fix.has_key(r): raise ValueError("Missing key: " + r) if not fix.has_key("psinorm"): # Add normalised psi, assuming core to edge psi = fix["psi"] fix["psinorm"] = (psi - psi[0]) / (psi[-1] - psi[0]) # Make a deep copy of the data so it can't be modified afterwards # in unpredictable ways self.fix = deepcopy(fix) # Create a function to return the pressure self.pressure = interp1d(self.fix["psinorm"], self.fix["p"], copy=False) # See if density, temperature profiles also set if fix.has_key("ne"): self.setDensity(self.fix["ne"]) else: self.fix = None