Esempio n. 1
0
def limit(q, limiter):
    if limiter == "weno":
        ql, qr = weno(5, q)
    elif limiter == "vanleer":
        ql, qr = vanleer(q)
    elif limiter == "donor":
        ql = q.copy()
        qr = q.copy()
    return ql, qr
Esempio n. 2
0
def setguess(q, dt, dx, flux, guesstype, r):
    c1 = 1.0 - 2.0 / r
    c2 = 1.0 - 1.0 / r
    if guesstype == "FE":
        # This initial guess is only good for r=8; need to generalize
        # But it doesn't seem to help anyway.
        y1guess = q.copy()
        y1guess[1:] = y1guess[1:] - c1 * dt / dx * (flux(y1guess[1:]) - flux(y1guess[:-1]))
        y2guess = q.copy()
        y2guess[1:] = y2guess[1:] - c2 * dt / dx * (flux(y2guess[1:]) - flux(y2guess[:-1]))
        guess = np.hstack([y1guess, y2guess])
    elif guesstype == "BE":
        myweno = lambda (y): be(q, c1 * dt, dx, y, flux)
        y1guess = fsolve(myweno, q)
        myweno = lambda (y): be(y1guess, dt / r, dx, y, flux)
        y2guess = fsolve(myweno, y1guess)
        guess = np.hstack([y1guess, y2guess])
    elif guesstype == "BE_fine":
        yy = q.copy()
        for i in range(int(2 * r) - 2):
            myweno = lambda (y): be(yy, dt / r / 2.0, dx, y, flux)
            yy = fsolve(myweno, yy)
        y1guess = yy
        myweno = lambda (y): be(y1guess, dt / r, dx, y, flux)
        y2guess = fsolve(myweno, y1guess)
        guess = np.hstack([y1guess, y2guess])
    elif guesstype == "itrap":
        myweno = lambda (y): itrap_solve(q, c1 * dt, dx, y, flux)
        y1 = fsolve(myweno, q)
        y1hat = np.empty([1, len(y1)])
        y1hat[0, :] = y1
        ql, qr = weno(5, y1hat)
        y1guess = q.copy()
        y1guess[1:] = y1guess[1:] - dt / dx * (flux(qr[0, 1:]) - flux(qr[0, :-1]))
        y1guess[0] = y1guess[0] - dt / dx * (flux(qr[0, 0]) - flux(qr[0, -1]))
        myweno = lambda (y): be(y1guess, dt / r, dx, y, flux)
        y2guess = fsolve(myweno, y1guess)
        guess = np.hstack([y1guess, y2guess])
    else:
        guess = np.hstack([q, q])

    return guess