def runNE(args, EOverEcTot=None, nD0=1e20, nD1=0, nAr=0, nNe=0):
    """
    Run DREAM for the specified values of electric field and ion density.
    
    Returns the avalanche growth rate (both numerical and analytic).
    """

    ds = gensettings(EOverEcTot=EOverEcTot, nD0=nD0, nD1=nD1, nAr=nAr, nNe=nNe)
    do = DREAM.runiface(ds, quiet=True)

    GammaNumFull = do.other.fluid.runawayRate[:, 0] / do.eqsys.n_re[1:, 0]
    GammaNum = GammaNumFull[-1]

    pMax = do.grid.hottail.p1_f[-1]
    pCrit = do.other.fluid.pCrit[0, 0]
    pMaxOverPCrit = pMax / pCrit
    pMaxOverPCritCutOff = 3
    if args['verbose']:
        print('pMax/pCrit = {:.2f} (pMax = {:.2f}, pCrit = {:.2f}).'.format(
            pMaxOverPCrit, pMax, pCrit))
        var = abs(GammaNumFull[-1] / GammaNumFull[-2] - 1)
        if var > 1e-2:
            print('WARNING: growth rate may not be converged in time.')
            print('Variation in last two time steps: {:.2f}%'.format(100 *
                                                                     var))
            if args['plot']:
                plotDiagnostics(do, GammaNumFull)
    if pMaxOverPCrit < pMaxOverPCritCutOff:
        print('WARNING: pMax/pCrit smaller than {:.3f}'.format(
            pMaxOverPCritCutOff))
        print('pMax/pCrit = {:.3f}.'.format(pMaxOverPCrit))
    '''
    Run two trivial fluid simulations in order to generate  
    growth rate data with the two different avalanche formulas
    '''
    ds.hottailgrid.setEnabled(False)
    ds.timestep.setNt(2)
    ds.solver.setType(Solver.LINEAR_IMPLICIT)

    ds.eqsys.n_re.setAvalanche(avalanche=Runaways.AVALANCHE_MODE_FLUID)
    do = DREAM.runiface(ds, quiet=True)
    GammaAn1Full = do.other.fluid.GammaAva[:, 0]
    GammaAn1 = GammaAn1Full[-1]

    ds.eqsys.n_re.setAvalanche(avalanche=Runaways.AVALANCHE_MODE_FLUID_HESSLOW)
    do = DREAM.runiface(ds, quiet=True)
    GammaAn2Full = do.other.fluid.GammaAva[:, 0]
    GammaAn2 = GammaAn2Full[-1]

    return GammaNum, GammaNumFull, GammaAn1, GammaAn2
示例#2
0
def run(args):
    """
    Run the test.
    """
    #testrun()
    #return True


    QUIET = True
    TOLERANCE = 100*sys.float_info.epsilon

    output_const, output_adapt = None, None
    # Save output?
    if args['save']:
        output_const = 'output_ts_adaptive_const.h5'
        output_adapt = 'output_ts_adaptive_adapt.h5'

    # Run with constant time step
    ds_const = genSettings(False)
    if args['save']:
        ds_const.save('settings_ts_adaptive_const.h5')
    do_const = DREAM.runiface(ds_const, output_const, quiet=QUIET)

    ds_adapt = genSettings(True)
    if args['save']:
        ds_adapt.save('settings_ts_adaptive_adapt.h5')
    do_adapt = DREAM.runiface(ds_adapt, output_adapt, quiet=QUIET)

    # Compare results
    err_f = np.abs(do_const.eqsys.f_hot[-1,:] / do_adapt.eqsys.f_hot[-1,:] - 1)
    err_j = np.abs(do_const.eqsys.j_hot[-1,:] / do_adapt.eqsys.j_hot[-1,:] - 1)

    eps_f = np.amax(err_f)
    eps_j = np.amax(err_j)

    success = True
    if eps_f > TOLERANCE:
        dreamtests.print_error("f_hot is too different. eps_f = {:.8e}".format(eps_f))
        success = False
    if eps_j > TOLERANCE:
        dreamtests.print_error("j_hot is too different. eps_j = {:.8e}".format(eps_j))
        success = False

    if success:
        dreamtests.print_ok("Solution from adaptive time stepper agrees exactly with solution from the constant time stepper.")

    return success
示例#3
0
def testrun():
    """
    Simple test run to make sure everything works.
    """
    ds = genSettings(True)
    do = DREAM.runiface(ds)

    do.eqsys.f_hot.plot(t=[0,2,4,5])
    plt.show()
示例#4
0
def runT(T):
    """
    Run DREAM for the specified values of temperature and ion charge.
    """
    global R0

    ds = gensettings(T=T, Z=300)
    #ds.save('settings_trapping_conductivity.h5')
    do = DREAM.runiface(ds, quiet=True)
    jKinetic = do.eqsys.j_ohm[-1,:]

    ds.hottailgrid.setEnabled(False)
    do = DREAM.runiface(ds,quiet=True)
    jFluid = do.eqsys.j_ohm[-1,:]

    eps = do.grid.r[:] / R0

    return jKinetic, jFluid, eps
示例#5
0
def runB(B, pBump):
    """
    Run DREAM for the specified magnetic field strength.
    """
    ds = gensettings(B=B,pMax = min(56,2.5*pBump))
    do = DREAM.runiface(ds, quiet=True)

    # Locate synchrotron bump
    bumpP = findBump(do)

    return bumpP
示例#6
0
def genSettings(adaptive=False):
    """
    Generate the baseline DREAMSettings object.
    """
    ds = DREAM.DREAMSettings()

    a    = 0.5
    B0   = 5
    E    = 10
    Nr   = 1
    Np   = 50
    Nt   = 5
    Nxi  = 3
    pMax = 0.1
    tMax = 1e-3
    T    = 50

    ds.collisions.collfreq_mode = Collisions.COLLFREQ_MODE_FULL

    ds.radialgrid.setB0(B0)
    ds.radialgrid.setNr(Nr)
    ds.radialgrid.setMinorRadius(a)
    ds.radialgrid.setWallRadius(a)

    ds.timestep.setTmax(tMax)

    if adaptive:
        ds.timestep.setType(TimeStepper.TYPE_ADAPTIVE)
        ds.timestep.setDt(tMax / Nt)
        ds.timestep.setConstantStep(True)
    else:
        ds.timestep.setType(TimeStepper.TYPE_CONSTANT)
        ds.timestep.setNt(Nt)

    ds.eqsys.n_i.addIon(name='D', Z=1, iontype=Ions.IONS_PRESCRIBED_FULLY_IONIZED, n=1e20)
    ds.eqsys.E_field.setPrescribedData(E)
    ds.eqsys.T_cold.setPrescribedData(T)

    ds.hottailgrid.setEnabled(True)
    ds.hottailgrid.setNxi(Nxi)
    ds.hottailgrid.setNp(Np)
    ds.hottailgrid.setPmax(pMax)

    ds.runawaygrid.setEnabled(False)
    
    nfree_initial, rn0 = ds.eqsys.n_i.getFreeElectronDensity()
    ds.eqsys.f_hot.setInitialProfiles(rn0=rn0, n0=nfree_initial, rT0=0, T0=T)
    ds.eqsys.f_hot.setBoundaryCondition(bc=FHot.BC_F_0)
    ds.eqsys.f_hot.setParticleSource(particleSource=FHot.PARTICLE_SOURCE_IMPLICIT)

    ds.solver.setType(Solver.LINEAR_IMPLICIT)
    ds.solver.setLinearSolver(linsolv=Solver.LINEAR_SOLVER_LU)

    return ds
def runTZ(T, Z):
    """
    Run DREAM for the specified values of temperature and ion charge.
    """
    ds = gensettings(T=T, Z=Z)
    E = ds.eqsys.E_field[0, 0]

    do = DREAM.runiface(ds, quiet=True)
    j = do.eqsys.f_hot.currentDensity(t=-1)[0, 0]
    sigma = j / E

    return sigma
示例#8
0
def runTE(T, E):
    """
    Run DREAM for the specified values of temperature and ion charge.
    """
    ds = gensettings(T=T, E=E)
    ds.save('settings.h5')

    do = DREAM.runiface(ds, quiet=True)

    rrFull = do.other.fluid.runawayRate[:, 0]
    rr = rrFull[-1]
    # Connor-Hastie runaway rate
    rrCH = do.other.fluid.gammaDreicer[-1, 0]

    return rr, rrFull, rrCH
def Cmatch():
    aa, App, Bpp = DREAM.Nucl()
    #TopCmds.MSG(str(aa)+"\n"+str(App)+"\n"+str(Bpp))
    SUM = 0
    for val in App:
        SUM = SUM + val
    AvgA = SUM / len(App)
    #TopCmds.MSG(str(AvgA))

    SUM = 0
    for val in Bpp:
        SUM = SUM + val
    AvgB = SUM / len(Bpp)
    #TopCmds.MSG(str(AvgB))

    return math.fabs(AvgA - AvgB)
示例#10
0
def runSimulation(analyticB):
    """
    Run a simulation and return the resulting value of the
    conductivity.
    """
    global ROOT

    t = 'analytical' if analyticB else 'numerical'

    ds = generateSettings(analyticB)
    ds.save('{}/settings_{}.h5'.format(ROOT, t))

    do = DREAM.runiface(ds, quiet=True)
    j = do.eqsys.f_hot.currentDensity(t=-1)[0, :]
    sigma = j / do.eqsys.E_field[-1, :]

    return sigma
示例#11
0
DREAM match condition is 0.5*wr=W1
"""
import sys
from sys import argv
sys.path.append(root.UtilPath.getTopspinHome() +
                '/exp/stan/nmr/py/BioPY/modules/')

import DREAM
import Setup, Help
import TS_Version as Ver

cmds = argv
WdB = "W"
if Ver.get()[1] == "2": WdB = "dB"
quiet = "Loud"

########################
#  Read in preferences #
########################

for cmd in cmds:
    if cmd.find('-dB') >= 0 or cmd.find('-DB') >= 0 or cmd.find('-db') >= 0:
        WdB = "dB"
    if cmd.find('-qt') >= 0 or cmd.find('-QT') >= 0 or cmd.find('-Qt') >= 0:
        quiet = "Quiet"
    if cmd.find('-help') >= 0:
        Help.CP()
        EXIT()

if quiet == "Loud": DREAM.LoadFromData('13C', 'oCdrm', WdB)
DREAM.CC(WdB)