CyprienBosserelle / BG_Flood

Numerical model for simulating shallow water hydrodynamics on the GPU using an Adaptive Mesh Refinment type grid. The model was designed with the goal of simulating inundation (River, Storm surge or tsunami). The model uses a Block Uniform Quadtree approach that runs on the GPU but the adaptive/multi-resolution/AMR is being implemented and not yet operational. The core SWE engine and adaptivity has been inspired and taken from St Venant solver from Basilisk and the CUDA GPU memory model has been inspired by the work from Vacondio _et al._2017)
GNU General Public License v3.0
34 stars 15 forks source link

Optimise gradient #67

Closed CyprienBosserelle closed 1 year ago

CyprienBosserelle commented 2 years ago

Optimising gradient and gradient-halo

There is a new test to confirm the validity of the new gradient and gradient halo the speed gain. The new scheme is about 1.8x faster than original which should make the whole simulation 1.15x faster

This makes the model 22% faster than the current dev branch

CyprienBosserelle commented 1 year ago

There is a new test to confirm the validity of the new gradient and the speed gain. The new scheme is about 1.8x faster than original which should make the whole simulation 1.15x faster

CyprienBosserelle commented 1 year ago

Need to write a new test for the halo to verify where the bug is and once fixed whether this new scheme is worth it

CyprienBosserelle commented 1 year ago

The new halo scheme does not work and I'm not too sure why. a day of work didn't get me very far. I think I'm happy to drop that part and merge what I have done to move this along and possibly move on to more important problems.

CyprienBosserelle commented 1 year ago

Fixed another issue caused by my last commit. Although a bit unexpected.

Conserve elevation now works as expected.

Barycentric interpolation for the prolongation halo is necessary for checking whether neighbours are wet. Even if the halo value is re-calculated later when applying refine_linear.

CyprienBosserelle commented 1 year ago

There is another thing that could be done here but i'm not sure the consequence.

All of the instabilities (when not using Conserve Elevation) are because of the wet/dry front and varying resolution don't mix well. The solution to that issue in "Conserve elevation" uses a direct injection of values from the coarse wet cell for the halo rather than what come from refine linear. while "Conserv elevation" also does other things maybe we can use that prolongation even when not requesting conserve elevation. that would in effect only affect the cells at the wet/dry interface. The only issue would be that those cells do not conserve volume. does it mater so much?

CyprienBosserelle commented 1 year ago

Revert prolongation from conserve elevation when cells are fully wet?

Straight injection from Prolongation when neighbouring cell is dry affects the value of h, zs and zb. Also this action doesn't affect dzbdx. is that ok? The changes to zb should probably reverted at the end of the step. no?

On the other end, appling zb and h changes only to cells with wet neighbours sounds good but is a very inefficient action (50% slower!) so that should not be implemented.

This seems to slow the code down a bit on the GPU (5-10%)

I wonder if we can reduce that so it does't try tp do anything on the GPU when blocks only have neighbour of the same level

CyprienBosserelle commented 1 year ago

should dhdx[halo] = T(0.0); in Conserve elevation?

Preformed a test to see the influence/impact of switching on/off the : dhdx[halo] = T(0.0); dzsdx[halo] = T(0.0);

in ProlongationElevationGH. This seem to have little effect.

CyprienBosserelle commented 1 year ago

Important note

Why is the calculation of dzbdx and dzbdy for GPU produced different result than CPU? The GPU side was replaced by a straight copy from CPU.

CyprienBosserelle commented 1 year ago

This merge request does a lot of different things to gradient, halo and Conserve elevation.

2 full scale test are needed to compare Dev branch and this branch

Once we are happy with the difference it will be ready to merge!

CyprienBosserelle commented 1 year ago

Waikanae Mass conservation test

Waikanae topo with cst rain at 50mm/h for 1 h. using the rainbnd option and wall bnd on all side. Results are undestinguishable from each other and after 1 hr the model has 100.48% of the theoretical volume of water in both with and without the wetdryfix.

For comparison the current Dev branch has 100.19% of the theoretical volume. While this is somehow better it does not really undermine the new branch (i.e. the dev branch might get closer to the theory for the wrong raisons), the bugfixes and instability improvement of this branch are totally justified.

results % of theoretical volume runtime
Wetdry fix 100.48% 97s
NO Wetdryfix 100.48% 96s
Development 100.18% 116s
CyprienBosserelle commented 1 year ago

Tsumani test results

The impact of the wet/dry fix should be much more obvious in tsunami simulation but here conserve elevation should be used in most tsunami cases.

No wetdryfix

switching off the wetdryfix causes instability that really have an impact on tsunami wave. Here the instability are clearly visible in the map and in the comparison are seen as 0.01 m waves before the tsunami wave arrive.

image

Wetdryfix

When using the wetdryfix the instabilities disappear and the solution is smoother.

image

Comparison

The instabilities are more obvious when we look at a transect diagonally from the plot above. These instabilities have a notable affect the height of the tsunami wave... a lot! This justifies that we should have the wetdryfix switched on by default.

image

Conserve Elevation

When running tsunami/storm surge simulation without rivers or rain then the conserve elevation should be switched on. This doesn't make a considerable impact on the tsunami wave (see transect above the red and blue line are indistinguishable) I'm not sure why the difference is so small but there is a difference. Below is the difference between the wetdryfix and conservelevation routine. it produces a difference of O(10-5).

image