コード例 #1
0
def power_loss_fraction(path, upstream_index=0, tind=-1):
    """
    The fraction of internal energy lost between an upstream
    index and the end of the domain.
    
    This takes the input power from BOUT.inp as the upstream
    power flux.

    
    """
    
    # Read the energy exchange with neutrals and radiation
    try:
        E = collect("E", path=path, yind=[upstream_index,-1], tind=tind).flatten()
    except:
        print("Energy loss rate 'E' not found")
        E = 0.0
    try:
        R = collect("R", path=path, yind=[upstream_index,-1], tind=tind).flatten()
    except:
        print("Radiation rate 'R' not found")
        R = 0.0
    
    # Compression term P * Div_par(Vi)
    n = collect("Ne", path=path, yguards=True, tind=tind).flatten()
    nvi = collect("NVi", path=path, yguards=True, tind=tind).flatten()
    vi = nvi / n
    J = collect("J", path=path, yguards=True).flatten()
    dy = collect("dy", path=path, yguards=True).flatten()
    g_22 = collect("g_22", path=path, yguards=True).flatten()
    
    # Parallel divergence
    Jv = J*vi
    div_par_v = (Jv[2:] - Jv[:-2])/(2.*dy[1:-1]*np.sqrt(g_22[1:-1])*J[1:-1])
    div_par_v = div_par_v[1:-1] # Remove guard cells
    div_par_v = div_par_v[upstream_index:]
    
    p = collect("P", path=path, yind=[upstream_index,-1], tind=tind).flatten()
    compression = p*div_par_v

    # Need to integrate along length, so get cell spacing
    dy = collect("dy", path=path, yind=[upstream_index,-1]).flatten()
    g_22 = collect("g_22", path=path, yind=[upstream_index,-1]).flatten()
    # Jacobian to calculate cell volume
    J = collect("J", path=path, yind=[upstream_index,-1]).flatten()
    # Get the energy flux
    data = BoutData(path)
    power_flux = data["options"]["p"]["powerflux"] # in W/m^2
    
    # Normalisations
    nnorm = collect("Nnorm", path=path)
    tnorm = collect("Tnorm", path=path)
    pnorm = nnorm*tnorm*1.602e-19 # Converts p to Pascals
    cs0 = collect("Cs0", path=path)
    
    # Normalise, converting from SI to SD1D units
    power_flux_normalised = power_flux / (pnorm * cs0)
    
    return np.sum( (E+R+compression) * J * dy ) / (J[0] * power_flux_normalised / np.sqrt(g_22[0]))
コード例 #2
0
    def __init__(self, path, parent=None):
        self.label = path

        self.parent = parent
        self.children = []

        # List the directory
        ls = os.listdir(path)

        for name in ls:
            fullname = os.path.join(path, name)
            if os.path.isdir(fullname):
                try:
                    c = BoutDataSource(fullname, parent=self)
                    self.children.append(c)
                except:
                    print("No data in directory " + fullname)

        self.label = path
        self.dimensions = {}
        self.varNames = []
        self.variables = {}
        try:
            self.data = BoutData(path)

            self.varNames = self.data.varNames
            for i, v in enumerate(self.varNames):
                try:
                    # This is for Python 2.x. Python 3.x will raise a NameError
                    # since unicode -> str and str -> bytes
                    if isinstance(v, unicode):
                        v = v.encode("utf-8")
                    v = str(v).translate(None, "\0")
                except NameError:
                    if isinstance(v, str):
                        v = v.encode("utf-8")

                self.varNames[i] = v
        except:
            # No data in path. Check if any children
            if len(self.children) == 0:
                raise
コード例 #3
0
ファイル: boutsource.py プロジェクト: bendudson/pyxpad
    def __init__(self, path, parent=None):
        self.label = path

        self.parent = parent
        self.children = []
        
        # List the directory
        ls = os.listdir(path)
        
        for name in ls:
            fullname = os.path.join(path, name)
            if os.path.isdir(fullname):
                try:
                    c = BoutDataSource(fullname, parent=self)
                    self.children.append(c)
                except:
                    print("No data in directory "+fullname)

        self.label=path
        self.dimensions = {}
        self.varNames = []
        self.variables  = {}
        try:
            self.data = BoutData(path)
            
            self.varNames   = self.data.varNames
            for i,v in enumerate(self.varNames):
                try:
                    # This is for Python 2.x. Python 3.x will raise a NameError
                    # since unicode -> str and str -> bytes
                    if isinstance(v, unicode):
                        v = v.encode('utf-8')
                    v = str(v).translate(None, '\0')
                except NameError:
                    pass
                 
                self.varNames[i] = v
        except:
            # No data in path. Check if any children
            if len(self.children) == 0:
                raise
コード例 #4
0
    # Area expansion factor
    f_R = J[-1] / J[0]  # B_u / B_t = A_t / A_u

    print("\n\n------------------------------------\n")
    print("Integrated momentum loss fraction: %e" % f_mom)
    print("Integrated internal energy loss fraction: %e [WRONG]" % f_pwr)

    print("Area expansion factor = %e" % f_R)

    p_u *= pnorm  # Convert to SI [Pascals]

    print("Upstream pressure = %e Pa" % p_u)

    # Get the energy flux from input options
    data = BoutData(path)
    power_flux = data["options"]["p"]["powerflux"]  # in W/m^2

    print("Upstream power flux = %e W/m^2" % power_flux)

    # Sheath heat transmission coefficient
    sheath_gamma = data["options"]["sd1d"]["sheath_gamma"]

    print("Sheath heat transmission gamma = %e" % sheath_gamma)

    m_i = 2. * 1.67e-27  # Ion mass [kg]

    # Power into the sheath
    sheath_power = sheath_gamma * 1.602e-19 * n_target * te_target * np.sqrt(
        2. * 1.602e-19 * te_target / m_i)
    print("Sheath power flux = %e W/m^2" % sheath_power)
コード例 #5
0
ファイル: boutsource.py プロジェクト: bendudson/pyxpad
class BoutDataSource:
    """
    
    Functions
      read( name, shot )   Input variable name (string)
                     Output is an XPadDataItem object or None
      
      size( name )   Returns variable size as a list. [] for scalar

    Attributes
      
      label         A short string to describe the source
      dimensions    A dictionary of XPadDataDim objects
      varNames      A list of variable names
      variables     A dictionary of XPadDataItem objects with empty data
      
    """
    def __init__(self, path, parent=None):
        self.label = path

        self.parent = parent
        self.children = []
        
        # List the directory
        ls = os.listdir(path)
        
        for name in ls:
            fullname = os.path.join(path, name)
            if os.path.isdir(fullname):
                try:
                    c = BoutDataSource(fullname, parent=self)
                    self.children.append(c)
                except:
                    print("No data in directory "+fullname)

        self.label=path
        self.dimensions = {}
        self.varNames = []
        self.variables  = {}
        try:
            self.data = BoutData(path)
            
            self.varNames   = self.data.varNames
            for i,v in enumerate(self.varNames):
                try:
                    # This is for Python 2.x. Python 3.x will raise a NameError
                    # since unicode -> str and str -> bytes
                    if isinstance(v, unicode):
                        v = v.encode('utf-8')
                    v = str(v).translate(None, '\0')
                except NameError:
                    pass
                 
                self.varNames[i] = v
        except:
            # No data in path. Check if any children
            if len(self.children) == 0:
                raise
            
    def read(self, name, shot):
        try:
            if isinstance(name, unicode):
                name = name.encode('utf-8')
        name = str(name).translate(None, '\0')
        
        item = self.data.read(name)
        
        return XPadDataItem(item)
コード例 #6
0
class BoutDataSource:
    """

    Functions
      read( name, shot )   Input variable name (string)
                     Output is an XPadDataItem object or None

      size( name )   Returns variable size as a list. [] for scalar

    Attributes

      label         A short string to describe the source
      dimensions    A dictionary of XPadDataDim objects
      varNames      A list of variable names
      variables     A dictionary of XPadDataItem objects with empty data

    """
    def __init__(self, path, parent=None):
        self.label = path

        self.parent = parent
        self.children = []

        # List the directory
        ls = os.listdir(path)

        for name in ls:
            fullname = os.path.join(path, name)
            if os.path.isdir(fullname):
                try:
                    c = BoutDataSource(fullname, parent=self)
                    self.children.append(c)
                except:
                    print("No data in directory " + fullname)

        self.label = path
        self.dimensions = {}
        self.varNames = []
        self.variables = {}
        try:
            self.data = BoutData(path)

            self.varNames = self.data.varNames
            for i, v in enumerate(self.varNames):
                try:
                    # This is for Python 2.x. Python 3.x will raise a NameError
                    # since unicode -> str and str -> bytes
                    if isinstance(v, unicode):
                        v = v.encode("utf-8")
                    v = str(v).translate(None, "\0")
                except NameError:
                    if isinstance(v, str):
                        v = v.encode("utf-8")

                self.varNames[i] = v
        except:
            # No data in path. Check if any children
            if len(self.children) == 0:
                raise

    def read(self, name, shot):
        try:
            if isinstance(name, unicode):
                name = name.encode("utf-8")
        except NameError:
            pass
        name = str(name).translate(None, "\0")

        item = self.data.read(name)

        return XPadDataItem(item)