Exemplo n.º 1
0
def cj_cond(fuel, ash):
    """Calculate Cj velocity from Helmholtz Eos calculation
    fits density for a set temperature

    Args:
        fuel (trojan): [[pressure, eint], [rho], [temp], [abar], [zbar]]
        ash (trojan): [[pressure, eint], [rho], [temp], [abar], [zbar]]

    """
    tol = 1e-8
    itmax = 30
    comprho = 1e10
    for it in range(itmax):
        # res = adiabat(fuel, ash, q)
        res = helmholtz.helmeos(*ash[1:])
        res.den = fuel[1][0] * (1.0 + (res.ptot - fuel[0][0]) /
                                (res.gam1 * res.ptot))
        # print res.den, type(res.den[0])
        dden = res.den[0] - comprho

        if abs(dden) < tol * res.den:
            return res
        elif res == -1:
            return -1
        else:
            ash[1][0] = res.den
            comprho = res.den
    return -1
Exemplo n.º 2
0
def getPres(rhos, temps, xmasses, species, returnObj=False):
    trojan = wrapVector(rhos, temps, xmasses, species)
    sol = helmholtz.helmeos(*trojan)
    if returnObj:
        return sol
    else:
        return sol.ptot
Exemplo n.º 3
0
def setBC(dens, temp=1e7, abar=4.0, zbar=2.0, start=1e4):
    """starting point for solver."""
    helmobj = hh.helmeos(dens, temp, abar, zbar)
    # intial conditions: first cell's mass, and central pressure
    con1 = 4.0e0 * np.pi
    ms0 = con1 * start**3 * dens
    ps0 = helmobj.ptot[0] - 0.5e0 * con1 * G * start**2 * dens**2
    return [ms0, ps0]
Exemplo n.º 4
0
Arquivo: test.py Projeto: msbc/helmeos
def test_code(nrand=100, vars_to_test=None, silent=False, tol=1e-12):
    if vars_to_test is None:
        vars_to_test = ['etot', 'ptot', 'cs', 'sele']

    ht = HelmTable()

    # density
    dlo, dhi = tab.dens_log_min, tab.dens_log_max
    dens = np.arange(dlo, dhi + 1)
    dens = 10**np.concatenate((dens,  (dhi - dlo) * np.random.random(nrand) + dlo))
    # temperature
    tlo, thi = tab.temp_log_min, tab.temp_log_max
    temp = np.arange(tlo, thi + 1)
    temp = 10**np.concatenate((temp,  (thi - tlo) * np.random.random(nrand) + tlo))

    rho_in = np.zeros(dens.size * temp.size)
    temp_in = np.zeros(dens.size * temp.size)

    # make 1D array of all combinations of dens, temp
    ind = 0
    for i in dens:
        for j in temp:
            rho_in[ind] = i
            temp_in[ind] = j
            ind += 1

    print("Loading tables.")
    # our method
    ours = ht.eos_DT(rho_in, temp_in, 1.0, 1.0)
    # their method
    theirs = helmholtz.helmeos(rho_in, temp_in, 1.0, 1.0)

    if not silent:
        print("Showing max relative error for a few variables.")
        print("var, rel_err")

    pass_test = True
    for var in vars_to_test:
        a, b = ours[var], getattr(theirs, var)
        dif = np.abs((a - b) / b)
        i = dif.argmax()
        if dif[i] > tol:
            pass_test = False
        if not silent:
            print(var, dif[i])

    if not pass_test:
        raise RuntimeError
    return pass_test
Exemplo n.º 5
0
def invert_helm(pres, deng=4e6, abar=4.0, zbar=2.0, temp=1e7):
    """find the density and dpdd from a guess and a pressure."""
    # local variables
    steptol = 1.0e-6
    maxiter = 50
    deni = deng
    for i in range(maxiter):
        helmobj = hh.helmeos(deni, temp, abar, zbar)
        presi, dpd = helmobj.ptot[0], helmobj.dpd[0]
        z = abs((pres - presi) / pres)
        if z < steptol:
            return deni, dpd
        else:
            f = presi / pres - 1.0
            df = dpd / pres
            ratio = f / df
            deni = deni - ratio
    print("Reached max iterations ({:d})".format(maxiter))
    return deni, dpd
Exemplo n.º 6
0
def adiabat(fuel, ash, q):
    """Hack-feeding data to helmholtz:
    fuel/ash = [[pressure, eint], [rho], [temp], [abar], [zbar]]
    
    fits a temperature to a hugoniot curve
    """
    # q value -- we need the change in molar fractions
    # call ener_gener_rate(eos_state_ash % xn(:)/aion(:) - eos_state_fuel % xn(:)/aion(:), q_burn)
    tol = 1e-8
    itmax = 30
    for it in range(itmax):
        res = helmholtz.helmeos(*ash[1:])
        aux = (1.0/fuel[1][0] - 1.0/res.den)
        f = fuel[0][1] + q - res.etot + 0.5*(fuel[0][0]+res.ptot)*aux
        dfdT = -res.det + 0.5*res.dpt*aux
        dT = -f/dfdT
        if abs(dT)<tol*res.temp:
            return res
        else:
            ash[2][0] = ash[2][0] + dT[0]
    return -1
Exemplo n.º 7
0
def helm(dens, abar=4.0, zbar=2.0, temp=1e7):
    """get pressure and total energy from a target density."""
    helmobj = hh.helmeos(dens, temp, abar, zbar)
    return helmobj.ptot[0], helmobj.dpd[0], helmobj.etot[0], helmobj.ded[0]
Exemplo n.º 8
0
import numpy as np
import matplotlib.pyplot as plt

import helmholtz

d = np.logspace(-3, 11, 512)
t = np.logspace(3, 9, 512)

# fig, axs = plt.subplots(3)

# for t in zip(ts):

# f = helmholtz.eosfxt(dens=d, temp=t, abar=1.0, zbar=1.0)
h = helmholtz.helmeos(dens=d, temp=t, abar=1.0, zbar=1.0)
print(len(h.etot), len(t), 512**2)
# ax.plot(d, np.abs((h.ptot - f.ptot)/f.ptot))
# ax.set_xlabel(r'$\rho$ (g/cc)')
# ax.set_ylabel(r'fractional difference')
# ax.set_xscale('log')
# ax.set_yscale('log')
# ax.set_ylim(1e-12, 1e0)

# logT = int(np.log10(t))
# ax.text(1e-2, 3e-6, '$T = 10^{{{}}}$ K'.format(logT))

# fig.suptitle('Pressure difference (Timmes vs Helmholtz)')
# fig.set_size_inches(6,6)
# fig.savefig('fig1.png', dpi=150)
Exemplo n.º 9
0
import pandas as pd

import helmholtz

n = 20
den = 5e13  #np.logspace(13, 14, n)
temps = np.logspace(10, 11, n)  #p.logspace(10, 11, n)
a = 55  #np.linspace(55, 65, n)
z = 28  #*= 28
ye = z / a

data = pd.DataFrame(columns=list('DTYE'))

i = 0
j = 0
for temp in temps:
    j += 1
    print("{} out of {}".format(j, n))
    en = int(helmholtz.helmeos(den, temp, a, z).etot)
    data.loc[i] = [den, temp, ye, en]
    i += 1
    #for temp in temps:
    #for a in a_s:
    #   en = int(helmholtz.helmeos(den, temp, a, 28).etot)
    #   data.loc[i] = [den, temp, z_s[0]/a, en]
    #   i += 1

data.to_csv(r'Temp_resolution{}_{}.csv'.format('10-11', n),
            index=None,
            header=True)