def FVc_test(qh_py, dX, dt, fvSolver): SOURCES = fvSolver.S is not None TIME = fvSolver.time_rec NV = fvSolver.NV NDIM = fvSolver.NDIM MP = fvSolver.pars mask = None if not SOURCES: shape = qh_py.shape newShape = shape[:NDIM] + (1,) + shape[NDIM:] qh_py = qh_py.reshape(newShape) nX = array(qh_py.shape[:NDIM]) ncell = prod(nX) mask = ones(ncell, dtype=bool) FVc_py = zeros(list(nX - 2) + [NV]) FVc_cp = zeros(FVc_py.size) if NDIM == 1: GPRpy.solvers.fv.centers1(FVc_cp, qh_py.ravel(), nX[0] - 2, dt, dX[0], SOURCES, TIME, MP, mask) elif NDIM == 2: GPRpy.solvers.fv.centers2(FVc_cp, qh_py.ravel(), nX[0] - 2, nX[1] - 2, dt, dX[0], dX[1], SOURCES, TIME, MP, mask) fvSolver.centers(FVc_py, qh_py, dX, mask) FVc_py *= dt FVc_cp = FVc_cp.reshape(FVc_py.shape) print("FVc ", check(FVc_cp, FVc_py)) return FVc_cp, FVc_py
def rhs_test(u, dX, dt, wenoSolver, dgSolver): N = wenoSolver.N NV = wenoSolver.NV NDIM = wenoSolver.NDIM wh = wenoSolver.solve(u) if NDIM == 1: Q = wh[0] elif NDIM == 2: Q = wh[0, 0] Q_py = array([Q] * N).reshape([N**(NDIM + 1), NV]) Q_cp = Q_py[:, :NV] w = Q.reshape([N**NDIM, NV]) Ww_py = dot(dgSolver.DG_W, w) Ww_cp = Ww_py[:, :NV] rhs_py = dgSolver.rhs(Q_py, Ww_py, dt, dX) if NDIM == 1: rhs_cp = GPRpy.solvers.dg.rhs1(Q_cp, Ww_cp, dt, dX[0], dgSolver.pars) else: rhs_cp = GPRpy.solvers.dg.rhs2(Q_cp, Ww_cp, dt, dX[0], dX[1], dgSolver.pars) print("RHS ", check(rhs_cp, rhs_py)) return rhs_cp, rhs_py
def obj_test(u, dX, dt, wenoSolver, dgSolver): N = wenoSolver.N NV = wenoSolver.NV NDIM = wenoSolver.NDIM nx, ny = u.shape[:2] wh = wenoSolver.solve(u) if NDIM == 1: Q = wh[int(nx / 2)] elif NDIM == 2: Q = wh[int(nx / 2), int(ny / 2)] Q_py = array([Q] * N).reshape([N**(NDIM + 1), NV]) Q_cp = Q_py[:, :NV] Ww_py = rand(N**(NDIM + 1), NV) Ww_py[:, -1] = 0 Ww_cp = Ww_py[:, :NV] rhs_py = dgSolver.rhs(Q_py, Ww_py, dt, dX) if NDIM == 1: obj_cp = GPRpy.solvers.dg.obj1(Q_cp.ravel(), Ww_cp, dt, dX[0], dgSolver.pars) else: obj_cp = GPRpy.solvers.dg.obj2(Q_cp.ravel(), Ww_cp, dt, dX[0], dX[1], dgSolver.pars) obj_cp = obj_cp.reshape([N**(NDIM + 1), NV]) obj_py = rhs_py - dot(dgSolver.DG_U, Q_py) print("obj ", check(obj_cp, obj_py)) return obj_cp, obj_py
def lgmres_test(): A = rand(30, 30) b = rand(30) lgmres_cp = GPRpy.scipy.lgmres_wrapper(A, b) lgmres_py = lgmres(A, b)[0] print("LGMRES", check(lgmres_cp, lgmres_py)) return lgmres_cp, lgmres_py
def ode_test(dt, MP): ode_py = generate_vector(MP) ode_cp = ode_py.copy() GPRpy.solvers.split.ode_launcher(ode_cp, dt, MP) ode_solver_cons(ode_py, dt, MP) print("ODEs ", check(ode_cp, ode_py)) return ode_cp, ode_py
def M_test(d, MP): Q = generate_vector(MP) M_cp = GPRpy.system.system_matrix(Q, d, MP) M_py = M_cons(Q, d, MP) print("M ", check(M_cp, M_py)) return M_cp, M_py
def F_test(d, MP): Q = generate_vector(MP) NV = len(Q) F_cp = zeros(NV) GPRpy.system.flux(F_cp, Q, d, MP) F_py = F_cons(Q, d, MP) print("F ", check(F_cp, F_py)) return F_cp, F_py
def S_test(d, MP): Q = generate_vector(MP) NV = len(Q) S_cp = zeros(NV) GPRpy.system.source(S_cp, Q, MP) S_py = S_cons(Q, MP) print("S ", check(S_cp, S_py)) return S_cp, S_py
def D_OSH_test(d, fvSolver): MP = fvSolver.pars Q1 = generate_vector(MP) Q2 = generate_vector(MP) D_OSH_cp = GPRpy.solvers.fv.D_OSH(Q1, Q2, d, MP) D_OSH_py = D_OSH(fvSolver, Q1, Q2, d) print("D_OSH ", check(D_OSH_cp, D_OSH_py)) return D_OSH_cp, D_OSH_py
def Bint_test(d, fvSolver): MP = fvSolver.pars Q1 = generate_vector(MP) Q2 = generate_vector(MP) Bint_cp = GPRpy.solvers.fv.Bint(Q1, Q2, d, MP) Bint_py = B_INT(fvSolver, Q1, Q2, d) print("Bint ", check(Bint_cp, Bint_py)) return Bint_cp, Bint_py
def TAT_test(d, MP): Q = generate_vector(MP) P = State(Q, MP) Ξ1 = Xi1(P, d, MP) Ξ2 = Xi2(P, d, MP) TAT_py = dot(Ξ1, Ξ2) TAT_cp = GPRpy.system.thermo_acoustic_tensor(Q, d, MP) print("TAT ", check(TAT_cp, TAT_py)) return TAT_cp, TAT_py
def midstepper_test(u, dX, dt, wenoSolver, splitSolver): mid_py = wenoSolver.solve(u) mid_cp = mid_py.copy().ravel() splitSolver.weno_midstepper(mid_py, dt, dX) ncell = prod(mid_py.shape[:u.ndim - 1]) GPRpy.solvers.split.midstepper(mid_cp, dt, array(dX), splitSolver.pars, ones(ncell, dtype=bool)) mid_cp = mid_cp.reshape(mid_py.shape) print("Step ", check(mid_cp, mid_py)) return mid_cp, mid_py
def B_test(d, MP): Q = generate_vector(MP) NV = len(Q) x = rand(NV) Bx_cp = zeros(NV) Bx_py = zeros(NV) GPRpy.system.Bdot(Bx_cp, Q, x, d, MP) B_py = B_cons(Q, d, MP) Bx_py = dot(B_py, x) print("Bdot ", check(Bx_cp, Bx_py)) return Bx_cp, Bx_py
def weno_test(wenoSolver): N = wenoSolver.N NV = wenoSolver.NV NDIM = wenoSolver.NDIM nX = 20 * ones(NDIM, dtype=int32) uBCpy = rand(*nX + 2 * N, NV) uBCcp = uBCpy.ravel() wh_py = wenoSolver.solve(uBCpy) wh_cp = zeros(prod(nX + 2) * N**NDIM * NV) GPRpy.solvers.weno.weno_launcher(wh_cp, uBCcp, nX) wh_cp = wh_cp.reshape(wh_py.shape) print("WENO ", check(wh_cp, wh_py)) return wh_cp, wh_py
def FV_test(qh_py, dX, dt, fvSolver): SOURCES = fvSolver.S is not None TIME = fvSolver.time_rec FLUX = convert_fluxes[fvSolver.D_FUN] NDIM = fvSolver.NDIM MP = fvSolver.pars nX = array(qh_py.shape[:NDIM], dtype=int32) ncell = prod(nX) mask = ones(ncell, dtype=bool) FV_py = fvSolver.solve(qh_py, dt, dX) FV_cp = zeros(FV_py.size) GPRpy.solvers.fv.fv_launcher(FV_cp, qh_py.ravel(), nX - 2, dt, array(dX), SOURCES, TIME, FLUX, MP, mask) FV_cp = FV_cp.reshape(FV_py.shape) print("FV ", check(FV_cp, FV_py)) return FV_cp, FV_py
def dg_test(u, dX, dt, wenoSolver, dgSolver): ndim = u.ndim - 1 stiff_guess = dgSolver.initial_guess == stiff_initial_guess N = wenoSolver.N wh_py = wenoSolver.solve(u) wh_cp = wh_py.ravel() qh_py = dgSolver.solve(wh_py, dt, dX) qh_cp = zeros(len(wh_cp) * N) ncell = prod(wh_py.shape[:ndim]) mask = ones(ncell, dtype=bool) GPRpy.solvers.dg.predictor(qh_cp, wh_cp, dt, array(dX), dgSolver.stiff, stiff_guess, dgSolver.pars, mask) qh_cp = qh_cp.reshape(qh_py.shape) print("DG ", check(qh_cp, qh_py)) return qh_cp, qh_py
def FVi_test(qh_py, dX, dt, fvSolver): SOURCES = fvSolver.S is not None TIME = fvSolver.time_rec NV = fvSolver.NV NDIM = fvSolver.NDIM MP = fvSolver.pars FLUX = convert_fluxes[fvSolver.D_FUN] ENDVALS = fvSolver.ENDVALS mask = None if not SOURCES: shape = qh_py.shape newShape = shape[:NDIM] + (1,) + shape[NDIM:] qh_py = qh_py.reshape(newShape) qEnd = endpoints(qh_py, NDIM, ENDVALS) nX = array(qh_py.shape[:NDIM]) ncell = prod(nX) mask = ones(ncell, dtype=bool) FVi_py = zeros(list(nX - 2) + [NV]) FVi_cp = zeros(FVi_py.size) if NDIM == 1: GPRpy.solvers.fv.interfs1(FVi_cp, qh_py.ravel(), nX[0] - 2, dt, dX[0], TIME, FLUX, MP, mask) elif NDIM == 2: GPRpy.solvers.fv.interfs2(FVi_cp, qh_py.ravel(), nX[0] - 2, nX[1] - 2, dt, dX[0], dX[1], TIME, FLUX, MP, mask) fvSolver.interfaces(FVi_py, qEnd, dX, mask) FVi_py *= dt FVi_cp = FVi_cp.reshape(FVi_py.shape) print("FVi ", check(FVi_cp, FVi_py)) return FVi_cp, FVi_py
def newton_krylov_test(u, dt, dX, wenoSolver, dgSolver): with catch_warnings(): simplefilter("ignore") N = wenoSolver.N NV = wenoSolver.NV NDIM = wenoSolver.NDIM NT = N**(NDIM + 1) nx, ny = u.shape[:2] wh = wenoSolver.solve(u) if NDIM == 1: w = wh[int(nx / 2)].reshape([N**NDIM, NV]) elif NDIM == 2: w = wh[int(nx / 2), int(ny / 2)].reshape([N**NDIM, NV]) Ww = dot(dgSolver.DG_W, w) q = dgSolver.initial_guess(dgSolver, w, dt, dX) def obj(X): return dot(dgSolver.DG_U, X) - dgSolver.rhs(X, Ww, dt, dX) def obj_cp(X): X2 = X.reshape([NT, NV]) ret = obj(X2) return ret.ravel() nk_cp = GPRpy.scipy.newton_krylov(obj_cp, q.copy().ravel(), f_tol=dgSolver.tol) nk_py = newton_krylov(obj, q, f_tol=dgSolver.tol).ravel() print("N-K ", check(nk_cp, nk_py)) return nk_cp, nk_py