Depends on what you mean by that (since DG solutions are discontinuous across interfaces). If you just want the local gradients without neighbor coupling, you could write something like
mesh, equations, solver, cache = Trixi.mesh_equations_solver_cache(semi)
derivative_matrix = dg.basis.derivative_matrix
du_dx .= 0
for element in eachelement(dg, cache)
jacobian_factor = cache.elements.inverse_jacobian[element]
for j in eachnode(dg), i in eachnode(dg)
# x derivative
for ii in eachnode(dg)
u_node = get_node_vars(u, equations, dg, ii, j, element)
multiply_add_to_node_vars!(du_dx, jacobian_factor * derivative_matrix[i, ii], u_node, equations, dg, i, j, element)
end
# same in y
end
end
Note that this uses internal API extensively and I didn’t test it. See