def sym_wave(dim, sym_phi): """Return symbolic expressions for the wave equation system given a desired solution. (Note: In order to support manufactured solutions, we modify the wave equation to add a source term (f). If the solution is exact, this term should be 0.) """ sym_c = pmbl.var("c") sym_coords = prim.make_sym_vector("x", dim) sym_t = pmbl.var("t") # f = phi_tt - c^2 * div(grad(phi)) sym_f = sym.diff(sym_t)(sym.diff(sym_t)(sym_phi)) - sym_c**2\ * sym.div(sym.grad(dim, sym_phi)) # u = phi_t sym_u = sym.diff(sym_t)(sym_phi) # v = c*grad(phi) sym_v = [sym_c * sym.diff(sym_coords[i])(sym_phi) for i in range(dim)] # rhs(u part) = c*div(v) + f # rhs(v part) = c*grad(u) sym_rhs = flat_obj_array(sym_c * sym.div(sym_v) + sym_f, make_obj_array([sym_c]) * sym.grad(dim, sym_u)) return sym_u, sym_v, sym_f, sym_rhs
def test_symbolic_div(): """ Compute the symbolic divergence of a vector expression and compare it to an expected result. """ # (Equivalent to make_obj_array([pmbl.var("x")[i] for i in range(3)])) sym_coords = pmbl.make_sym_vector("x", 3) sym_x = sym_coords[0] sym_y = sym_coords[1] sym_f = make_obj_array([sym_x, sym_x * sym_y, sym_y]) sym_div_f = sym.div(sym_f) expected_sym_div_f = 1 + sym_x + 0 assert sym_div_f == expected_sym_div_f
def sym_diffusion(dim, sym_alpha, sym_u): """Return a symbolic expression for the diffusion operator applied to a function. """ return sym.div([sym_alpha * grad_i for grad_i in sym.grad(dim, sym_u)])
def sym_diffusion(dim, alpha, sym_u): """Return a symbolic expression for the diffusion operator applied to a function. """ return alpha * sym.div(sym.grad(dim, sym_u))