Finite difference stencils in 2D with mixed orders

If you run your tests in global scope, your need to interpolate the variables to avoid measuring the compilation time, e.g. (see the $ symbols),

@benchmark FixedSecondDerivative($uxx1, $u)

Also, to avoid creation of temporary arrays, when you take the slice of an array, it useful to take its view instead, e.g.

cache[i,j] = @views stencil1(u[i,j:j+2]) + stencil2(u[i:i+2,j])
@views FixedSecondDerivative_Order2(cache[ix,:],U[ix+1,:])

It will greatly increase the speed.

1 Like