Make mixed second-derivative operators more correct - #1661
Conversation
Previously, D2DYDZ was using an explicit loop, doing 2nd order centred differences without taking into account whether yup/ydown should be used. Instead it should be OK to just use DDZ(DDY(f)) since the z-grid spacing is constant and the y-grid spacing does not depend on z, so the order of derivatives is not important.
|
Given that we're working towards (or at least thinking about) treating z the same as other directions (i.e. could be non-uniform etc.) is this introducing a "problem" we will have to fix? Could we switch the order of the derivatives at the expense of a communicate? |
|
I think we definitely have a "problem", but it's not being introduced here as such: I think in principle all the mixed derivatives should have 2 forms, e.g. The problem with
I don't know how generally we can apply a sensible boundary condition. If If/when we'd make z the same as other directions, the mixed z-derivatives would have the same problem as |
|
Mathematically |
|
I'd made a mistake about the non-uniform grids (see bottom). I think My mistake about the non-uniform grids was because I was doing some testing previously (the stuff in #1315) that I think I set up wrong. I was trying to test non-uniform grids, but was initializing fields to test using expressions, and put in a scaling factor for varying |
|
Was there a consensus on the correct thing to do here? |
|
Was talking to Ben about this yesterday. We think:
The conclusion is that I'll polish up this PR soon... -- |
In the mixed derivative, apply DDY before DDX (see PR #1661, mixed derivatives section in manual). Apply a boundary condition to dfdy before applying DDX. By default 'free_o3', can be changed with a new argument to D2DXDY.
Records discussion from PR #1661.
|
I've added to this PR:
|
Following the pattern recently adopted in D2DYDZ, take the x-derivative first, and then the z-derivative. z is periodic so DDZ does not require guard cells and we avoid needing communication or boundary conditions for the intermediate df/dx.
c28d537 to
4a93b37
Compare
In the mixed derivative, apply DDY before DDX (see PR #1661, mixed derivatives section in manual). Apply a boundary condition to dfdy before applying DDX. By default 'free_o3', can be changed with a new argument to D2DXDY.
Records discussion from PR #1661.
4a93b37 to
1e14412
Compare
It is correct to apply the boundary condition to all boundaries, even though y-boundaries are not needed. This avoids potential problems if the list of boundary regions changes, or is re-named, or is different in a new implementation of Mesh, etc.
|
Thanks @johnomotani, I love a PR that includes documentation updates! 😄 |
Previously, D2DYDZ was using an explicit loop, doing 2nd order centred differences without taking into account whether yup/ydown should be used. Instead it should be OK to just use DDZ(DDY(f)) since the z-grid spacing is constant and the y-grid spacing does not depend on z, so the order of derivatives is not important.