Strange oscillating ripples in my shallow water implementation

為{幸葍}努か 提交于 2019-12-05 05:33:35

I fixed it myself! Though of it while driving to a friend. The problem is quite simple, what I do in the bugged code is for each cell (or grid-point) calculate the flux, then the height and then I go to the next cell. What I should do is first calculate the flux for all cells, then iterate a second time over all the cells and calculate their height. So the code becomes:

for (x=1 ; x <= N ; x++ ) {
    for (y=1 ; y <= N ; y++ ) {
        //
        // 3.2.1 Outflow Flux Computation
        // --------------------------------------------------------------
        ***
    }
}

for (x=1 ; x <= N ; x++ ) {
    for (y=1 ; y <= N ; y++ ) {
        //
        // 3.2.2 Water Surface
        // ---------------------------------------------------------------------------
        ***
    }
}
Helpers.Swap(ref _tempFlux, ref _flux);
Helpers.Swap(ref _tempHeight, ref _height);

(Of course *** becomes the corresponding code from the question above.)

Now I have a working water simulation.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!