예제 #1
0
파일: test_FSA.py 프로젝트: lda16/Aurora
import scipy, sys, os
import time
from scipy.interpolate import interp1d

# Make sure that package home is added to sys.path
sys.path.append('../')
import aurora

# read in default Aurora namelist
namelist = aurora.default_nml.load_default_namelist()
kp = namelist['kin_profs']

# Use gfile and statefile in local directory:
examples_dir = os.path.dirname(os.path.abspath(__file__))
geqdsk = omfit_eqdsk.OMFITgeqdsk(examples_dir + '/example.gfile')
inputgacode = omfit_gapy.OMFITgacode(examples_dir + '/example.input.gacode')

# transform rho_phi (=sqrt toroidal flux) into rho_psi (=sqrt poloidal flux) and save kinetic profiles
rhop = kp['Te']['rhop'] = kp['ne']['rhop'] = np.sqrt(
    inputgacode['polflux'] / inputgacode['polflux'][-1])
kp['ne']['vals'] = inputgacode['ne'][None, :] * 1e13  # 1e19 m^-3 --> cm^-3
kp['Te']['vals'] = inputgacode['Te'][None, :] * 1e3  # keV --> eV

# set impurity species and sources rate
imp = namelist['imp'] = 'Ar'
namelist['source_type'] = 'const'
namelist['Phi0'] = 1e24

# Setup aurora sim to efficiently setup atomic rates and profiles over radius
asim = aurora.core.aurora_sim(namelist, geqdsk=geqdsk)
예제 #2
0
def Helike_emiss_metrics(imp='Ca', cs_den=None, rhop=None,
                         plot_individual_contributions=False, axs = None):
    ''' Obtain R(Te) and G(ne) from ratios of w,z,x,y He-like lines for an ion 
    '''
    
    # Use gfile and statefile in local directory:
    geqdsk = omfit_eqdsk.OMFITgeqdsk('/home/sciortino/Aurora/examples/example.gfile')
    inputgacode = omfit_gapy.OMFITgacode('/home/sciortino/Aurora/examples/example.input.gacode')
    
    # save kinetic profiles on a rhop (sqrt of norm. pol. flux) grid

    rhop_kp = np.sqrt(inputgacode['polflux']/inputgacode['polflux'][-1])
    ne = inputgacode['ne']*1e13 # 1e19 m^-3 --> cm^-3
    Te = inputgacode['Te']*1e3  # keV --> eV

    # get charge state distributions from ionization equilibrium
    atom_data = aurora.atomic.get_atom_data(imp,['scd','acd'])
    logTe, fz, rates = aurora.get_frac_abundances(atom_data, ne, Te, rho=rhop_kp)

    if cs_den is None:
        # use ionization equilibrium fractional abundances as densities
        cs_den = fz
        rhop = rhop_kp
    else:
        # use provided charge state densities, given on rhop grid
        if rhop is None:
            raise ValueError('Which rhop grid were cs_dens arrays given on??')
        ne = interp1d(rhop_kp, ne, bounds_error=False, fill_value='extrapolate')(rhop)
        Te = interp1d(rhop_kp, Te, bounds_error=False, fill_value='extrapolate')(rhop)

        # normalize cs_den to match He-like density on axis
        cs_den /= cs_den[0,-3]/fz[0,-1]
        
    imp_Z = cs_den.shape[1] -1 

    # limit to core/pedestal
    ridx = np.argmin(np.abs(rhop - 0.99))
    ne = ne[:ridx]
    Te = Te[:ridx]
    rhop = rhop[:ridx]
    cs_den = cs_den[:ridx]

    # get w,z,x,y rate components
    out = compute_Helike_rates(imp_Z, ne, Te/1e3)   # Te input must be keV
    w_comps, z_comps, x_comps, y_comps = out

    # wavelengths for each line:
    w_lam = 3.1773e-10
    z_lam = 3.2111e-10 
    x_lam = 3.1892e-10
    y_lam = 3.1928e-10

    # conversion to frequency
    f_E_lam = lambda lam: h*c/(lam)

    n_H = cs_den[:,-2]
    n_He = cs_den[:,-3]
    n_Li = cs_den[:,-4]
    
    # compute line rates in phot/s/cm^3
    nw =  n_Li*w_comps[0] + n_He*w_comps[1] + n_H*w_comps[2]
    nz= n_Li*z_comps[0] + n_He*z_comps[1] + n_H*z_comps[2]
    nx = n_He*x_comps[0] + n_H*x_comps[1] + nz*x_comps[2]
    ny = n_He*y_comps[0] + n_H*y_comps[1] + nz*y_comps[2]

    # convert rates to J/s/cm^3
    w = f_E_lam(w_lam) * nw
    z = f_E_lam(z_lam) * nz
    x = f_E_lam(x_lam) * nx
    y = f_E_lam(y_lam) * ny

    # compute atomic plasma diagnostics only in the plasma core/pedestal
    R_ne = z / (x+y)
    G_Te = (z + x + y)/w

    # plot each line emissivity

    if axs is not None:
        ax0,ax1 = axs[0]
        ax2 = axs[1]
        ax3 = axs[2]
        ls='--'
    else:

        if plot_individual_contributions:
            # make use of extra side space for labels
            fig = plt.figure(figsize=(11,7))    
            ax0 = plt.subplot2grid((5,5),(0,0), rowspan = 5, colspan=4)
            ax1 = plt.subplot2grid((5,5),(0,4), rowspan = 5, colspan=1, sharex=ax0)
        else:
            fig, ax0 = plt.subplots()
            ax1=None #dummy

        fig,ax2 = plt.subplots()
        fig,ax3 = plt.subplots()
        ls='-'

    lw=None

    # emissivity profiles
    ax0.plot(rhop, w, c='b', label='w', ls=ls, lw=lw)
    ax0.plot(rhop, z, c='r', label='z', ls=ls, lw=lw)
    ax0.plot(rhop, x, c='g', label='x', ls=ls, lw=lw)
    ax0.plot(rhop, y, c='m', label='y', ls=ls, lw=lw)
    ax0.set_xlabel(r'$\rho_p$')
    ax0.set_ylabel('IE emissivity [A.U.]')

    if plot_individual_contributions:
        ax0.plot(rhop, f_E_lam(w_lam) *n_Li*w_comps[0], ls='--', c='b', label='ionization')
        ax0.plot(rhop, f_E_lam(w_lam) *n_He*w_comps[1], ls=':', c='b', label='excitation', lw=lw)
        ax0.plot(rhop, f_E_lam(w_lam) *n_H*w_comps[2], ls='-.', c='b', label='recombination')
        
        ax0.plot(rhop, f_E_lam(z_lam) *n_Li*z_comps[0], ls='--', c='r', label='ionization')
        ax0.plot(rhop, f_E_lam(z_lam) *n_He*z_comps[1], ls=':', c='r', label='excitation', lw=lw)
        ax0.plot(rhop, f_E_lam(z_lam) *n_H*z_comps[2], ls='-.', c='r', label='recombination')
        
        ax0.plot(rhop, f_E_lam(x_lam) *n_He*x_comps[0], ls=':', c='g', label='excitation', lw=lw)
        ax0.plot(rhop, f_E_lam(x_lam) *n_H*x_comps[1], ls='-.', c='g', label='recombination')
        ax0.plot(rhop, f_E_lam(x_lam) *nz*x_comps[2], marker='*', c='g', label='z-prop')
        
        ax0.plot(rhop, f_E_lam(y_lam) *n_He*y_comps[0], ls=':', c='m', label='excitation', lw=lw)
        ax0.plot(rhop, f_E_lam(y_lam) *n_H*y_comps[1], ls='-.', c='m', label='recombination')
        ax0.plot(rhop, f_E_lam(y_lam) *nz * y_comps[2], marker='*', c='m', label='z-prop')
        

    if axs is None: # if axes were given, no need to re-plot labels
        if plot_individual_contributions:    
            
            # basic labels for each line
            ax1.plot([],[], c='b', label='w')
            ax1.plot([],[], c='r', label='z')
            ax1.plot([],[], c='g', label='x')
            ax1.plot([],[], c='m', label='y')

            # show labels for each contribution
            ax1.plot([],[], c='w', label=' ') #empty to separate colors and line styles
            ax1.plot([],[], ls='--', c='k', label='ionization', lw=lw)
            ax1.plot([],[], ls=':', c='k', label='excitation', lw=lw)
            ax1.plot([],[], ls='-.', c='k', label='recombination', lw=lw)
            ax1.plot([],[], marker='*', c='k', label='z cascade', lw=lw)
            
            leg = ax1.legend(loc='center left').set_draggable(True)
            ax1.axis('off')
        else:
            leg = ax0.legend().set_draggable(True)

    plt.tight_layout()

    # plot line ratios to w
    ax2.plot(rhop, w/w, label='w', ls=ls, c='b')
    ax2.plot(rhop, z/w, label='z', ls=ls, c='r')
    ax2.plot(rhop, x/w, label='x', ls=ls, c='g')
    ax2.plot(rhop, y/w, label='y', ls=ls, c='m')
    ax2.set_yscale('log')
    if axs is None: # if axes were given, no need to re-plot labels
        ax2.legend().set_draggable(True)
        ax2.set_xlabel(r'$\rho_p$')
        ax2.set_ylabel('Line ratios to w')
        
        # set good tick frequency on log-scale for comparison (a bit ad-hoc..)
        ax2.set_yticks([0.1,0.3, 1.0, 3.0, 6.0])
        ax2.get_yaxis().set_major_formatter(mpl.ticker.ScalarFormatter())
    plt.tight_layout()

    # plot atomic plasma diagnostics
    ax3.plot(rhop, R_ne, label=r'R($n_e$)', ls=ls, c='b')
    ax3.plot(rhop, G_Te, label=r'G($T_e$)', ls=ls, c='r')
    if axs is None:
        leg = ax3.legend().set_draggable(True)
        ax3.set_xlabel(r'$\rho_p$')

        # set good tick frequency on log-scale for comparison (a bit ad-hoc..)
        ax3.set_yticks([0.1,0.3, 1.0, 3.0, 6.0])
        ax3.get_yaxis().set_major_formatter(mpl.ticker.ScalarFormatter())

    plt.tight_layout()

    return [ax0,ax1], ax2, ax3
예제 #3
0
'''
import numpy as np
import matplotlib.pyplot as plt
plt.ion()
import omfit_gapy
import scipy, sys, os
import time
from scipy.interpolate import interp1d

# Make sure that package home is added to sys.path
import sys
sys.path.append('../')
import aurora

# read in some kinetic profiles
inputgacode = omfit_gapy.OMFITgacode('example.input.gacode')

# transform rho_phi (=sqrt toroidal flux) into rho_psi (=sqrt poloidal flux) and save kinetic profiles
rhop = np.sqrt(inputgacode['polflux'] / inputgacode['polflux'][-1])
ne_vals = inputgacode['ne'] * 1e13  # 1e19 m^-3 --> cm^-3
Te_vals = inputgacode['Te'] * 1e3  # keV --> eV

# get charge state distributions from ionization equilibrium for Ca
atom_data = aurora.atomic.get_atom_data('Ca', ['scd', 'acd'])

# get fractional abundances on ne (cm^-3) and Te (eV) grid
logTe, fz, rates = aurora.atomic.get_frac_abundances(atom_data,
                                                     ne_vals,
                                                     Te_vals,
                                                     rho=rhop)
예제 #4
0
import numpy as np
import matplotlib.pyplot as plt
plt.ion()
import omfit_eqdsk, omfit_gapy
import sys
from scipy.interpolate import interp1d
import aurora

# read in default Aurora namelist
namelist = aurora.default_nml.load_default_namelist()

# Use gfile and statefile in local directory:
geqdsk = omfit_eqdsk.OMFITgeqdsk(
    '/home/sciortino/Aurora/examples/example.gfile')
inputgacode = omfit_gapy.OMFITgacode(
    '/home/sciortino/Aurora/examples/example.input.gacode')

# save kinetic profiles on a rhop (sqrt of norm. pol. flux) grid
kp = namelist['kin_profs']
kp['Te']['rhop'] = kp['ne']['rhop'] = np.sqrt(inputgacode['polflux'] /
                                              inputgacode['polflux'][-1])
kp['ne']['vals'] = inputgacode['ne'] * 1e13  # 1e19 m^-3 --> cm^-3
kp['Te']['vals'] = inputgacode['Te'] * 1e3  # keV --> eV

# set impurity species and sources rate
imp = namelist['imp'] = 'Ar'
namelist['source_type'] = 'const'
namelist['source_rate'] = 2e20  # particles/s

# Now get aurora setup
asim = aurora.core.aurora_sim(namelist, geqdsk=geqdsk)