# Finite Difference or general Numerical Scheme for $2D$ First-Order PDE

Consider a First-order PDE in $2D$, i.e. find a function $u : \Omega \subset \mathbb{R}^2 \rightarrow \mathbb{R}$ such that $u_x = p$ and $u_y = q$ for some functions $p, q: \Omega \rightarrow \mathbb{R}$

What kind of numerical scheme might one use to solve this PDE, if we only have grid functions $p^h, q^h$ on some discretization $\Omega^h$ of $\Omega$? What kind of boundary conditions can we apply?

Although this setup seems to me like the easiest multidimensional PDE, most scripts about PDE or numerics for PDE in $2D$ start with some $5$-point star for $\Delta u = 0$, a second order PDE. I have not been able to find a simple go-to scheme to solve first order PDEs.

Here is a simple approach, for the case where $\Omega$ is a rectangle. There is only a solution if $p_y = q_x$. The value of $u$ must be specified at some specific point $(x_0,y_0)$. The value of $u$ at any other point can be computed by integrating: $u(x,y) = u(x_0,y_0) + \int_{x_0}^x u_x(s,y_0) ds + \int_{y_0}^y u_y(x,t) dt$. These integrals can be approximated numerically.
I'm kind of thinking you already have all the pieces of the puzzle you need and just have to assemble them into a solution. You have $$\vec\nabla u(x,y)=p(x,y)\hat i+q(x,y)\hat j$$ So first off, as littleO explained $$\vec\nabla\times\vec\nabla u=\vec0=\left(\frac{\partial q}{\partial x}-\frac{\partial p}{\partial y}\right)\hat k$$ Assuming your data $p(x,y)$ and $q(x,y)$ pass this test we can now evaluate $$\vec\nabla\cdot\vec\nabla u=\nabla^2u=\frac{\partial p}{\partial x}+\frac{\partial q}{\partial y}$$ You know that \begin{align}\nabla^2u(x,y)&=\frac{u(x+h,y)+u(x,y+h)+u(x-h,y)+u(x,y-h)-4u(x,y)}{h^2}+O(h^2)\\ \frac{\partial p}{\partial x}&=\frac{p(x+h)-p(x-h)}{2h}+O(h^2)\\ \frac{\partial q}{\partial y}&=\frac{q(y+h)-q(y-h)}{2h}+O(h^2)\end{align} And we are given Neumann boundary conditions: $$\hat n\cdot\vec\nabla u(x,y)=\hat n\cdot(p(x,y)\hat i+q(x,y)\hat j)$$ Which I am assuming you already know how to discretize.