Created
October 28, 2022 18:50
-
-
Save RedBlaze42/d2eb429f208b60c90de2ad5b754341f6 to your computer and use it in GitHub Desktop.
Rotating rocker FluidX3D
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
std::atomic_bool revoxelizing = false; | |
void revoxelize(LBM* lbm, Mesh* mesh) { // voxelize new frames in detached thread in parallel while LBM is running | |
for(uint n=0u; n<lbm->get_N(); n++) lbm->flags[n] &= ~TYPE_S; // clear flags | |
const float3x3 rotation = float3x3(float3(0.0f, 1.0f, 0.0f), radians(0.8f)); // create rotation matrix to rotate mesh | |
mesh->rotate(rotation); // rotate mesh | |
voxelize_mesh_hull(*lbm, mesh, TYPE_S); // voxelize rotated mesh in lbm.flags | |
revoxelizing = false; // indicate new voxelizer thread has finished | |
} | |
void main_setup() { // Rotating rocket | |
// ######################################################### define simulation box size, viscosity and volume force ############################################################################ | |
const uint L = 560u; | |
const float kmh = 180.0f; | |
const float si_u = kmh/3.6f; | |
const float si_x = 2.0f; | |
const float si_rho = 1.225f; | |
const float si_nu = 1.48E-5f; | |
const float u = 0.125f; | |
const float Re = units.si_Re(si_x, si_u, si_nu); | |
LBM lbm(L, 2u*L, L/2u, si_nu); | |
// ############################################################################################################################################################################################# | |
const float size = 1.5f*(float)L; | |
const float3 center = float3(lbm.center().x, 32.0f+0.5f*size, lbm.center().z); | |
const float3x3 rotation = float3x3(float3(1, 0, 0), radians(90.0f)); | |
Mesh* mesh = read_stl(get_exe_path()+"../stl/Rocket.stl", lbm.size(), center, rotation, size); // https://www.thingiverse.com/thing:2919109/files | |
voxelize_mesh_hull(lbm, mesh, TYPE_S); | |
const uint N=lbm.get_N(), Nx=lbm.get_Nx(), Ny=lbm.get_Ny(), Nz=lbm.get_Nz(); for(uint n=0u, x=0u, y=0u, z=0u; n<N; n++, lbm.coordinates(n, x, y, z)) { | |
// ########################################################################### define geometry ############################################################################################# | |
if(lbm.flags[n]!=TYPE_S) lbm.u.y[n] = u; | |
if(x==0u||x==Nx-1u||y==0u||y==Ny-1u||z==0u||z==Nz-1u) lbm.flags[n] = TYPE_E; // all non periodic | |
} // ######################################################################################################################################################################################### | |
key_4 = true; | |
//Clock clock; | |
lbm.run(0u); | |
while(lbm.get_t()<50000u) { | |
lbm.graphics.set_camera_free(float3(1.0f*(float)Nx, -0.5f*(float)Ny, 2.0f*(float)Nz), -33.0f, 42.0f, 68.0f); | |
lbm.graphics.write_frame_png(get_exe_path()+"export/t/"); | |
lbm.graphics.set_camera_free(float3(0.5f*(float)Nx, -0.35f*(float)Ny, -0.7f*(float)Nz), -35.0f, -35.0f, 100.0f); | |
lbm.graphics.write_frame_png(get_exe_path()+"export/b/"); | |
lbm.graphics.set_camera_free(float3(0.0f*(float)Nx, 0.51f*(float)Ny, 0.75f*(float)Nz), 90.0f, 28.0f, 80.0f); | |
lbm.graphics.write_frame_png(get_exe_path()+"export/f/"); | |
lbm.graphics.set_camera_free(float3(0.6f*(float)Nx, -0.15f*(float)Ny, 0.06f*(float)Nz), 0.0f, 0.0f, 100.0f); | |
lbm.graphics.write_frame_png(get_exe_path()+"export/s/"); | |
lbm.graphics.set_camera_centered((float) (lbm.get_t()/60), 45.0f, 100.0f, 0.95f); | |
lbm.graphics.write_frame_png(get_exe_path()+"export/rotation/"); | |
while(revoxelizing.load()) sleep(0.01f); // wait for voxelizer thread to finish | |
lbm.flags.write_to_device(); // lbm.flags on host is finished, write to device now | |
revoxelizing = true; // indicate new voxelizer thread is starting | |
thread voxelizer(revoxelize, &lbm, mesh); // start new voxelizer thread | |
voxelizer.detach(); // detatch voxelizer thread so LBM can run in parallel | |
lbm.run(28u); // run LBM in parallel while CPU is voxelizing the next frame | |
} | |
//write_file(get_exe_path()+"time.txt", print_time(clock.stop())); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment