I would like to numerically solve a hyperbolic PDE of the form


$\frac{\partial\theta\_t}{\partial t}(x,y)+\frac{\partial\left[\theta\_t \gamma\_t^x\right]}{\partial x}(x,y)+\frac{\partial\left[\theta\_t \gamma\_t^y\right]}{\partial y}(x,y)=0,$


which is very similar to the 2D advection equation, except that the partial derivatives w.r.t $x$ and $y$ are products of my dependent variable $\theta\_t(x,y)$ with another function $\gamma\_t^x(x,y)$ or $\gamma\_t^y(x,y)$.


Since I can calculate the $\gamma\_t^x(x,y)$ and $\gamma\_t^y(x,y)$ functions and their derivatives exactly, I don't need to approximate these and can just use the product rule to expand the terms with these in. My PDE is therefore of the form 


$\frac{\partial\theta\_t}{\partial t}(x,y)+\gamma\_t^x(x,y)\frac{\partial\theta\_t}{\partial x}(x,y)+\gamma\_t^y(x,y)\frac{\partial \theta\_t}{\partial y}(x,y)
+\theta\_t(x,y)\frac{\partial\gamma\_t^x}{\partial x}(x,y)+\theta\_t(x,y)\frac{\partial \gamma\_t^x}{\partial y}(x,y)
=0,$


I need to use a numeric scheme to approximate the derivatives with $\theta\_t(x,y)$ in them. Numeric schemes which work for solving a 2D advection equation (where the gammas are absent and the partial derivatives are simply multiplied by a constant) do not seem to work for me. I have tried several (upwind, downwind, adaptive, etc.), but can't find one which yields conservation of mass for $\theta\_{t}$. 


Any advice would be greatly appreciated. 



Advice on numerical solution for 2D hyperbolic PDE with zero flux boundary conditions
The reason you don't get conservation is that you've **used the product rule before discretizing**, so conservation would require an exact cancellation of truncation errors in the different product terms (which generally won't happen). 


Instead, you should **directly discretize the conservative form of the equation**. Using the usual notation for finite differences and setting $(\gamma^x,\gamma^y)=(u,v)$, this would be something like:


$$\theta^{n+1}\_{i,j} = \theta^{n-1}\_{i,j} - \frac{\Delta t}{\Delta x}(\theta^n\_{i+1,j}u^n\_{i+1,j} - \theta^n\_{i-1,j}u^n\_{i-1,j}) - \frac{\Delta t}{\Delta y}(\theta^n\_{i,j+1}v^n\_{i-1,j+1} - \theta^n\_{i,j}u^n\_{i-1,j}).$$


It's easy to check that if you sum $\theta^{n+1}$ over the whole grid, all of the fluxes cancel out except for those at the boundaries. Here I've used centered differences in time and space. This will be fine if your initial data is smooth and well-resolved, and if second-order accuracy (in $\Delta t$ and $\Delta x$) is sufficient. For more complicated or demanding situations, you might refer to (for instance) [Randall LeVeque's *Finite Volume Methods for Hyperbolic Problems*](http://depts.washington.edu/clawpack/book.html) and the [Clawpack software](http://www.clawpack.org).


Note: In the literature I'm familiar with, the conservation law you've written **is** referred to as the 2D advection equation. The non-conservative version is sometimes given the same name, or may be referred to as the **color equation**.


