Exemplo n.º 1
0
def Pvec(Q, MP):
    """ Vector of primitive variables
        NOTE: Uses atypical ordering
    """
    P = State(Q, MP)
    ret = Q.copy()

    ret[1] = P.p()
    ret[2:5] /= P.ρ

    if THERMAL:
        ret[14:17] /= P.ρ

    return ret
Exemplo n.º 2
0
def F_cons(Q, d, MP):

    ret = zeros(NV)

    P = State(Q, MP)

    ρ = P.ρ
    p = P.p()
    E = P.E
    v = P.v

    vd = v[d]
    ρvd = ρ * vd

    ret[0] = ρvd

    ret[1] = ρvd * E + p * vd
    ret[2:5] = ρvd * v
    ret[2 + d] += p

    if VISCOUS:

        A = P.A
        σ = P.σ()

        σd = σ[d]
        ret[1] -= dot(σd, v)
        ret[2:5] -= σd

        Av = dot(A, v)
        ret[5 + d] = Av[0]
        ret[8 + d] = Av[1]
        ret[11 + d] = Av[2]

    if THERMAL:

        J = P.J
        T = P.T()
        q = P.q()

        ret[1] += q[d]
        ret[14:17] = ρvd * J
        ret[14 + d] += T

    if MULTI:
        λ = P.λ
        ret[17] = ρvd * λ

    return ret
Exemplo n.º 3
0
def M_prim(Q, d, MP):
    """ The system jacobian of the primitive system
        NOTE: Uses typical ordering
    """
    P = State(Q, MP)

    ρ = P.ρ
    p = P.p()
    A = P.A
    v = P.v

    c0 = c_0(ρ, p, A, MP)

    ret = v[d] * eye(NV)
    ret[0, 2 + d] = ρ
    ret[1, 2 + d] = ρ * c0**2
    ret[2 + d, 1] = 1 / ρ

    if VISCOUS:

        σ = P.σ()
        dσdρ = P.dσdρ()
        dσdA = P.dσdA()

        ret[1, 2:5] += σ[d] - ρ * dσdρ[d]
        ret[2:5, 0] = -1 / ρ * dσdρ[d]
        ret[2:5, 5:14] = -1 / ρ * dσdA[d].reshape([3, 9])

        ret[5 + d, 2:5] = A[0]
        ret[8 + d, 2:5] = A[1]
        ret[11 + d, 2:5] = A[2]

    if THERMAL:

        dTdρ = P.dTdρ()
        dTdp = P.dTdp()
        T = P.T()
        ch = c_h(ρ, T, MP)

        ret[1, 14 + d] = ρ * ch**2 / dTdp
        ret[14 + d, 0] = dTdρ / ρ
        ret[14 + d, 1] = dTdp / ρ

    return ret
Exemplo n.º 4
0
def gauge_plot(uList, MPs):

    dt = 5e-6 / 100

    x = [0.0018125 + 0.006 + 0.003625 * i for i in range(5)]

    n = len(uList)
    nx, ny = uList[0].shape[:2]
    x_ = linspace(0, 5e-6, n)

    vy = zeros([5, n])
    py = zeros([5, n])
    ρy = zeros([5, n])
    Σy = zeros([5, n])

    # j0 = int(ny / 2)
    j0 = 0
    for j in range(n):
        for i in range(5):
            i0 = int(x[i] / 0.03 * nx)
            Q = uList[j][i0, j0]
            P = State(Q, MPs[1])
            vy[i, j] = P.v[0]
            py[i, j] = P.p()
            ρy[i, j] = P.ρ
            Σy[i, j] = P.Σ()[0, 0]
            x[i] += P.v[0] * dt

    figure(1)
    for i in range(5):
        plot(x_, vy[i])

    figure(2)
    for i in range(5):
        plot(x_, py[i])

    figure(3)
    for i in range(5):
        plot(x_, ρy[i])

    figure(4)
    for i in range(5):
        plot(x_, -Σy[i])
Exemplo n.º 5
0
Arquivo: euler.py Projeto: pinebai/phd
def exact_euler(n, t, x0, QL, QR, MPL, MPR):
    """ Returns the exact solution to the Euler equations at (x,t),
        given initial states PL for x<x0 and PR for x>x0
    """
    ret = zeros([n, len(QL)])
    PL = State(QL, MPL)
    PR = State(QR, MPR)

    ρL = PL.ρ
    ρR = PR.ρ
    uL = PL.v[0]
    uR = PR.v[0]
    pL = PL.p()
    pR = PR.p()
    c0L = c_0(ρL, pL, eye(3), MPL)
    c0R = c_0(ρR, pR, eye(3), MPR)

    p_ = p_star(PL, PR, MPL, MPR)
    u_ = u_star(p_, PL, PR, MPL, MPR)

    print('Interface:', u_ * t + x0)

    for i in range(n):
        x = (i + 0.5) / n
        S = (x - x0) / t

        if (S < u_):

            if (p_ < pL):  # Left fan
                if (S < uL - c0L):
                    ret[i] = QL
                else:
                    STL = u_ - c0_star(p_, PL, MPL)
                    if (S < STL):
                        ret[i] = Wfan(S, PL, MPL, c0L)
                    else:
                        r_ = r_star_fan(p_, PL, MPL)
                        v_ = array([u_, 0, 0])
                        ret[i] = Cvec(r_, p_, v_, MPL)

            else:  # Left shock
                SL = uL - Q(p_, PL, MPL) / ρL
                if (S < SL):
                    ret[i] = QL
                else:
                    r_ = r_star_shock(p_, PL, MPL)
                    v_ = array([u_, 0, 0])
                    ret[i] = Cvec(r_, p_, v_, MPL)

            ret[i, -1] = -1

        else:

            if (p_ < pR):  # Right fan
                if (uR + c0R < S):
                    ret[i] = QR
                else:
                    STR = u_ + c0_star(p_, PR, MPR)
                    if (STR < S):
                        ret[i] = Wfan(S, PR, MPR, -c0R)
                    else:
                        r_ = r_star_fan(p_, PR, MPR)
                        v_ = array([u_, 0, 0])
                        ret[i] = Cvec(r_, p_, v_, MPR)

            else:  # Right shock
                SR = uR + Q(p_, PR, MPR) / ρR
                if (SR < S):
                    ret[i] = QR
                else:
                    r_ = r_star_shock(p_, PR, MPR)
                    v_ = array([u_, 0, 0])
                    ret[i] = Cvec(r_, p_, v_, MPR)

            ret[i, -1] = 1

    return ret