Closed trparry closed 1 year ago
I think I know what's going on here. There is this lbm.F
data field that stores the 3D force per volume for each grid point. This is used for 2 things:
lbm.F
is set unequal to 0 on a fluid node, it is applied as a local force per volume in every time step via Gui forcing. This allows to set inhomogeneous forces depending on the position, i.e. like the gravitational field of a planet.lbm.calculate_force_on_boundaries()
computes and sets lbm.F
(on the GPU side) is for all solid boundary node. These don't do the Gui forcing as they are not computed.
Put 1. and 2. together and you get the crash: lbm.F
is set on a boundary node by lbm.calculate_force_on_boundaries()
, then the mesh is moved and re-voxelized and the boundary node turns into a fluid node, and suddenly the (large) boundary force is read as a local force per volume on the fluid and the simulation blows up.Solution: Reset lbm.F
to 0 before re-voxelization, so call lbm.F.reset(); lbm.F.write:to:device();
.
A faster way would be to reset lbm.F
directly on the GPU side without slow PCIe memory transfer. I might add a short kernel for this later on.
Alternative solution (more elegant, but please test if this works I'm not sure): Comment out src/defines.hpp
line 73. This let's you enable FORCE_FIELD
but keep Guo forcing on the fluid disabled.
I just tested the alternative solution (it works), and updated the repository. FORCE_FIELD
and VOLUME_FORCE
can now be used independently.
@ProjectPhysX yep it works, extremely helpful thank you!
Based on my testing, lbm.calculate_force_on_boundaries only works on a stationary mesh. With the default D3Q19 velocity set, I moved a mesh with mesh->rotate or mesh->translate, then I revoxelize and flag with type S and run for 50 LBM timesteps. Then I call lbm.calculate_force_on_boundaries. I do this repeatedly in a while loop as shown. The simulation diverges after 3 cycles of the while loop where the forces are NaN, and the flow field disappears (I think it might be NaN).
I can remove lbm.calculate_force_on_boundaries and the simulation runs without issues.
When I rotate less per loop (ex: radians(0.01f)) I'm able to do 5-6 while loops but then I still diverge. I think its probably the mid-grid bounce back BC where a large movement of the mesh causes issues with lbm.calculate_force_on_boundaries. However, this BC is obviously working without calculating the forces, so why would calculating the forces break it?
Any idea what's going on? It's strange that if I calculate the forces after the while loop its fine, but when this command is inside the while loop problems occur.
I also tried FP16C, and lbm.calculate_force_on_boundaries works fine for each loop, but the fluid domain looks "unphysical" where the entire domain is turbulence.
You can try this on any mesh: