Fluid velocity at defined point #203
-
Dear users, how to get the fluid velocity as a vector(xyz) at a defined point in main setup when the coordinates of point are known? Nearest velocity or average velocity would be also fine. How to get access to one of them in "setup.cpp": from "kernel.cpp" lbm.u??????? Many thanks for your help |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
Hi @pk-guest, all the functions in Here is how to get one 3D velocity vector at specific 3D space + time coordinates in the const uint probe_x = 25u;
const uint probe_y = 36u;
const uint probe_z = 47u;
const ulong probe_t = 123ull;
float3 probe_u; // velocity to be read at x/y/z/t
lbm.run(probe_t); // run probe_t time steps
lbm.u.read_from_device(); // copy velocity field from device memory (GPU VRAM) to host memory (CPU RAM)
const ulong probe_index = lbm.index(probe_x, probe_y, probe_z); // convert x/y/z coordinates to linear index suitable for array access
probe_u = float3(lbm.u.x[probe_index], lbm.u.y[probe_index], lbm.u.z[probe_index]); // copy x/y/z components of velocity from CPU RAM to probe_u variable
print_info("velocity at probe point = "+to_string(probe_u.x)+", "+to_string(probe_u.y)+", "+to_string(probe_u.z));
wait(); // so that console doesn't immediately close on Windows Kind regards, |
Beta Was this translation helpful? Give feedback.
-
Hello Moritz, many thanks for your answer, it helped a lot. Regards, |
Beta Was this translation helpful? Give feedback.
Hi @pk-guest,
all the functions in
src/kernel.cpp
are OpenCL C code that runs on the GPU. This code is compeltely separate from C++ host code, yet mostly compatible so it's possible to port functions over. But here you don't need this, it's much simpler.Here is how to get one 3D velocity vector at specific 3D space + time coordinates in the
main_setup()
function: