Skip to content

Commit

Permalink
Coloring can now be switched between velocity/density/temperature, sl…
Browse files Browse the repository at this point in the history
…ice mode for field visualization now draws fully filled-in slices
  • Loading branch information
ProjectPhysX committed Mar 3, 2024
1 parent f3fa55b commit b15cbbe
Show file tree
Hide file tree
Showing 13 changed files with 649 additions and 287 deletions.
1 change: 1 addition & 0 deletions DOCUMENTATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ git clone https://github.com/ProjectPhysX/FluidX3D.git
| <kbd>6</kbd> | raytraced free surface |
| <kbd>7</kbd> | particles |
| <kbd>T</kbd> | toggle slice visualization mode |
| <kbd>Z</kbd> | toggle field visualization mode |
| <kbd>Q</kbd> <kbd>E</kbd> | move slice in slice visualization mode |

<br>
Expand Down
2 changes: 1 addition & 1 deletion LICENSE.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Copyright (c) 2022-2024 Dr. Moritz Lehmann

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files, to use this software for public research, education or personal use, and to alter it and redistribute it freely, subject to the following restrictions:

1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
1. The [origin of this software](https://github.com/ProjectPhysX/FluidX3D) must not be misrepresented; you must not claim that you wrote the original software. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
2. Commercial use is not allowed. You may not sell this software, altered source versions, any part thereof or any of the rights granted to you under the license. You may not provide to third parties, for a fee or other consideration (including without limitation fees for hosting or consulting/support services related to the software), a product or service whose value derives from the functionality of this software, altered source versions or any part thereof, unless explicit permission is granted to you by the copyright owner.
3. Military use is not allowed. You may not use this software, altered source versions or any part thereof for military research or any military or defense industry purposes, or within a military institution.
4. You may not train AI models on the source code of this software, altered source versions or any part thereof.
Expand Down
52 changes: 31 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,40 +8,40 @@ The fastest and most memory efficient lattice Boltzmann CFD software, running on

<details><summary>Update History</summary>

- v1.0 (04.08.2022)
- initial release
- v1.1 (29.09.2022)
- [v1.0](https://github.com/ProjectPhysX/FluidX3D/releases/tag/v1.0) (04.08.2022) [changes](https://github.com/ProjectPhysX/FluidX3D/commit/768073501af725e392a4b85885009e2fa6400e48) (public release)
- public release
- [v1.1](https://github.com/ProjectPhysX/FluidX3D/releases/tag/v1.1) (29.09.2022) [changes](https://github.com/ProjectPhysX/FluidX3D/compare/v1.0...v1.1) (GPU voxelization)
- added solid voxelization on GPU (slow algorithm)
- added tool to print current camera position (key <kbd>H</kbd>)
- added tool to print current camera position (key <kbd>G</kbd>)
- minor bug fix (workaround for Intel iGPU driver bug with triangle rendering)
- v1.2 (24.10.2022)
- [v1.2](https://github.com/ProjectPhysX/FluidX3D/releases/tag/v1.2) (24.10.2022) [changes](https://github.com/ProjectPhysX/FluidX3D/compare/v1.1...v1.2) (force/torque compuatation)
- added functions to compute force/torque on objects
- added function to translate Mesh
- added Stokes drag validation setup
- v1.3 (10.11.2022)
- [v1.3](https://github.com/ProjectPhysX/FluidX3D/releases/tag/v1.3) (10.11.2022) [changes](https://github.com/ProjectPhysX/FluidX3D/compare/v1.2...v1.3) (minor bug fixes)
- added unit conversion functions for torque
- `FORCE_FIELD` and `VOLUME_FORCE` can now be used independently
- minor bug fix (workaround for AMD legacy driver bug with binary number literals)
- v1.4 (14.12.2022)
- [v1.4](https://github.com/ProjectPhysX/FluidX3D/releases/tag/v1.4) (14.12.2022) [changes](https://github.com/ProjectPhysX/FluidX3D/compare/v1.3...v1.4) (Linux graphics)
- complete rewrite of C++ graphics library to minimize API dependencies
- added interactive graphics mode on Linux with X11
- fixed streamline visualization bug in 2D
- v2.0 (09.01.2023)
- [v2.0](https://github.com/ProjectPhysX/FluidX3D/releases/tag/v2.0) (09.01.2023) [changes](https://github.com/ProjectPhysX/FluidX3D/compare/v1.4...v2.0) (multi-GPU upgrade)
- added (cross-vendor) multi-GPU support on a single node (PC/laptop/server)
- v2.1 (15.01.2023)
- [v2.1](https://github.com/ProjectPhysX/FluidX3D/releases/tag/v2.1) (15.01.2023) [changes](https://github.com/ProjectPhysX/FluidX3D/compare/v2.0...v2.1) (fast voxelization)
- made solid voxelization on GPU lightning fast (new algorithm, from minutes to milliseconds)
- v2.2 (20.01.2023)
- [v2.2](https://github.com/ProjectPhysX/FluidX3D/releases/tag/v2.0) (20.01.2023) [changes](https://github.com/ProjectPhysX/FluidX3D/compare/v2.1...v2.2) (velocity voxelization)
- added option to voxelize moving/rotating geometry on GPU, with automatic velocity initialization for each grid point based on center of rotation, linear velocity and rotational velocity
- cells that are converted from solid->fluid during re-voxelization now have their DDFs properly initialized
- added option to not auto-scale mesh during `read_stl(...)`, with negative `size` parameter
- added kernel for solid boundary rendering with marching-cubes
- v2.3 (30.01.2023)
- [v2.3](https://github.com/ProjectPhysX/FluidX3D/releases/tag/v2.3) (30.01.2023) [changes](https://github.com/ProjectPhysX/FluidX3D/compare/v2.2...v2.3) (particles)
- added particles with immersed-boundary method (either passive or 2-way-coupled, only supported with single-GPU)
- minor optimization to GPU voxelization algorithm (workgroup threads outside mesh bounding-box return after ray-mesh intersections have been found)
- displayed GPU memory allocation size is now fully accurate
- fixed bug in `write_line()` function in `src/utilities.hpp`
- removed `.exe` file extension for Linux/macOS
- v2.4 (11.03.2023)
- [v2.4](https://github.com/ProjectPhysX/FluidX3D/releases/tag/v2.4) (11.03.2023) [changes](https://github.com/ProjectPhysX/FluidX3D/compare/v2.3...v2.4) (UI improvements)
- added a help menu with key <kbd>H</kbd> that shows keyboard/mouse controls, visualization settings and simulation stats
- improvements to keyboard/mouse control (<kbd>+</kbd>/<kbd>-</kbd> for zoom, <kbd>mouseclick</kbd> frees/locks cursor)
- added suggestion of largest possible grid resolution if resolution is set larger than memory allows
Expand All @@ -51,14 +51,14 @@ The fastest and most memory efficient lattice Boltzmann CFD software, running on
- fixed bug in make.sh where multi-GPU device IDs would not get forwarded to the executable
- minor bug fixes in graphics engine (free cursor not centered during rotation, labels in VR mode)
- fixed bug in `LBM::voxelize_stl()` size parameter standard initialization
- v2.5 (11.04.2023)
- [v2.5](https://github.com/ProjectPhysX/FluidX3D/releases/tag/v2.5) (11.04.2023) [changes](https://github.com/ProjectPhysX/FluidX3D/compare/v2.4...v2.5) (raytracing overhaul)
- implemented light absorption in fluid for raytracing graphics (no performance impact)
- improved raytracing framerate when camera is inside fluid
- fixed skybox pole flickering artifacts
- fixed bug where moving objects during re-voxelization would leave an erroneous trail of solid grid cells behind
- v2.6 (16.04.2023)
- [v2.6](https://github.com/ProjectPhysX/FluidX3D/releases/tag/v2.6) (16.04.2023) [changes](https://github.com/ProjectPhysX/FluidX3D/compare/v2.5...v2.6) (Intel Arc patch)
- patched OpenCL issues of Intel Arc GPUs: now VRAM allocations >4GB are possible and correct VRAM capacity is reported
- v2.7 (29.05.2023)
- [v2.7](https://github.com/ProjectPhysX/FluidX3D/releases/tag/v2.7) (29.05.2023) [changes](https://github.com/ProjectPhysX/FluidX3D/compare/v2.6...v2.7) (visualization upgrade)
- added slice visualization (key <kbd>2</kbd> / key <kbd>3</kbd> modes, then switch through slice modes with key <kbd>T</kbd>, move slice with keys <kbd>Q</kbd>/<kbd>E</kbd>)
- made flag wireframe / solid surface visualization kernels toggleable with key <kbd>1</kbd>
- added surface pressure visualization (key <kbd>1</kbd> when `FORCE_FIELD` is enabled and `lbm.calculate_force_on_boundaries();` is called)
Expand All @@ -69,7 +69,7 @@ The fastest and most memory efficient lattice Boltzmann CFD software, running on
- reverted back to separate `cl::Context` for each OpenCL device, as the shared Context otherwise would allocate extra VRAM on all other unused Nvidia GPUs
- removed Debug and x86 configurations from Visual Studio solution file (one less complication for compiling)
- fixed bug that particles could get too close to walls and get stuck, or leave the fluid phase (added boundary force)
- v2.8 (24.06.2023)
- [v2.8](https://github.com/ProjectPhysX/FluidX3D/releases/tag/v2.8) (24.06.2023) [changes](https://github.com/ProjectPhysX/FluidX3D/compare/v2.7...v2.8) (documentation + polish)
- finally added more [documentation](DOCUMENTATION.md)
- cleaned up all sample setups in `setup.cpp` for more beginner-friendliness, and added required extensions in `defines.hpp` as comments to all setups
- improved loading of composite `.stl` geometries, by adding an option to omit automatic mesh repositioning, added more functionality to `Mesh` struct in `utilities.hpp`
Expand All @@ -87,15 +87,15 @@ The fastest and most memory efficient lattice Boltzmann CFD software, running on
- fixed bug in Q-criterion rendering of halo data in multi-GPU mode, reduced gap width between domains
- removed shared memory optimization from mesh voxelization kernel, as it crashes on Nvidia GPUs with new GPU drivers and is incompatible with old OpenCL 1.0 GPUs
- fixed raytracing attenuation color when no surface is at the simulation box walls with periodic boundaries
- v2.9 (31.07.2023)
- [v2.9](https://github.com/ProjectPhysX/FluidX3D/releases/tag/v2.9) (31.07.2023) [changes](https://github.com/ProjectPhysX/FluidX3D/compare/v2.8...v2.9) (multithreading)
- added cross-platform `parallel_for` implementation in `utilities.hpp` using `std::threads`
- significantly (>4x) faster simulation startup with multithreaded geometry initialization and sanity checks
- faster `calculate_force_on_object()` and `calculate_torque_on_object()` functions with multithreading
- added total runtime and LBM runtime to `lbm.write_status()`
- fixed bug in voxelization ray direction for re-voxelizing rotating objects
- fixed bug in `Mesh::get_bounding_box_size()`
- fixed bug in `print_message()` function in `utilities.hpp`
- v2.10 (05.11.2023)
- [v2.10](https://github.com/ProjectPhysX/FluidX3D/releases/tag/v2.10) (05.11.2023) [changes](https://github.com/ProjectPhysX/FluidX3D/compare/v2.9...v2.10) (frustrum culling)
- improved rasterization performance via frustrum culling when only part of the simulation box is visible
- improved switching between centered/free camera mode
- refactored OpenCL rendering library
Expand All @@ -106,17 +106,17 @@ The fastest and most memory efficient lattice Boltzmann CFD software, running on
- replaced slow (in multithreading) `std::rand()` function with standard C99 LCG
- more robust correction of wrong VRAM capacity reporting on Intel Arc GPUs
- fixed some minor compiler warnings
- v2.11 (07.12.2023)
- [v2.11](https://github.com/ProjectPhysX/FluidX3D/releases/tag/v2.11) (07.12.2023) [changes](https://github.com/ProjectPhysX/FluidX3D/compare/v2.10...v2.11) (improved Linux graphics)
- interactive graphics on Linux are now in fullscreen mode too, fully matching Windows
- made CPU/GPU buffer initialization significantly faster with `std::fill` and `enqueueFillBuffer` (overall ~8% faster simulation startup)
- added operating system info to OpenCL device driver version printout
- fixed flickering with frustrum culling at very small field of view
- fixed bug where rendered/exported frame was not updated when `visualization_modes` changed
- v2.12 (18.01.2024)
- [v2.12](https://github.com/ProjectPhysX/FluidX3D/releases/tag/v2.12) (18.01.2024) [changes](https://github.com/ProjectPhysX/FluidX3D/compare/v2.11...v2.12) (faster startup)
- ~3x faster source code compiling on Linux using multiple CPU cores if [`make`](https://www.gnu.org/software/make/) is installed
- significantly faster simulation initialization (~40% single-GPU, ~15% multi-GPU)
- minor bug fix in `Memory_Container::reset()` function
- v2.13 (11.02.2024)
- [v2.13](https://github.com/ProjectPhysX/FluidX3D/releases/tag/v2.13) (11.02.2024) [changes](https://github.com/ProjectPhysX/FluidX3D/compare/v2.12...v2.13) (improved .vtk export)
- data in exported `.vtk` files is now automatically converted to SI units
- ~2x faster `.vtk` export with multithreading
- added unit conversion functions for `TEMPERATURE` extension
Expand All @@ -127,6 +127,16 @@ The fastest and most memory efficient lattice Boltzmann CFD software, running on
- fixed slow numeric drift issues caused by `-cl-fast-relaxed-math`
- fixed wrong Maximum Allocation Size reporting in `LBM::write_status()`
- fixed missing scaling of coordinates to SI units in `LBM::write_mesh_to_vtk()`
- [v2.14](https://github.com/ProjectPhysX/FluidX3D/releases/tag/v2.14) (03.03.2024) [changes](https://github.com/ProjectPhysX/FluidX3D/compare/v2.13...v2.14) (visualization upgrade)
- coloring can now be switched between velocity/density/temperature with key <kbd>Z</kbd>
- uniform improved color palettes for velocity/density/temperature visualization
- color scale with automatic unit conversion can now be shown with key <kbd>H</kbd>
- slice mode for field visualization now draws fully filled-in slices instead of only lines for velocity vectors
- shading in `VIS_FLAG_SURFACE` and `VIS_PHI_RASTERIZE` modes is smoother now
- `make.sh` now automatically detects operating system and X11 support on Linux and only runs FluidX3D if last compilation was successful
- fixed compiler warnings on Android
- fixed `make.sh` failing on some systems due to nonstandard interpreter path
- fixed that `make` would not compile with multiple cores on some systems

</details>

Expand Down
7 changes: 5 additions & 2 deletions src/defines.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,18 @@
#define GRAPHICS_FRAME_WIDTH 1920 // set frame width if only GRAPHICS is enabled
#define GRAPHICS_FRAME_HEIGHT 1080 // set frame height if only GRAPHICS is enabled
#define GRAPHICS_BACKGROUND_COLOR 0x000000 // set background color; black background (default) = 0x000000, white background = 0xFFFFFF
//#define GRAPHICS_TRANSPARENCY 0.7f // optional: comment/uncomment this line to disable/enable semi-transparent rendering (looks better but reduces framerate), number represents transparency (equal to 1-opacity) (default: 0.7f)
#define GRAPHICS_U_MAX 0.25f // maximum velocity for velocity coloring in units of LBM lattice speed of sound (c=1/sqrt(3)) (default: 0.25f)
#define GRAPHICS_RHO_DELTA 0.01f // coloring range for density rho will be [1.0f-GRAPHICS_RHO_DELTA, 1.0f+GRAPHICS_RHO_DELTA] (default: 0.01f)
#define GRAPHICS_T_DELTA 1.0f // coloring range for temperature T will be [1.0f-GRAPHICS_T_DELTA, 1.0f+GRAPHICS_T_DELTA] (default: 1.0f)
#define GRAPHICS_F_MAX 0.001f // maximum force in LBM units for visualization of forces on solid boundaries if VOLUME_FORCE is enabled and lbm.calculate_force_on_boundaries(); is called (default: 0.001f)
#define GRAPHICS_Q_CRITERION 0.0001f // Q-criterion value for Q-criterion isosurface visualization (default: 0.0001f)
#define GRAPHICS_F_MAX 0.002f // maximum force in LBM units for visualization of forces on solid boundaries if VOLUME_FORCE is enabled and lbm.calculate_force_on_boundaries(); is called (default: 0.002f)
#define GRAPHICS_STREAMLINE_SPARSE 4 // set how many streamlines there are every x lattice points
#define GRAPHICS_STREAMLINE_LENGTH 128 // set maximum length of streamlines
#define GRAPHICS_RAYTRACING_TRANSMITTANCE 0.25f // transmitted light fraction in raytracing graphics ("0.25f" = 1/4 of light is transmitted and 3/4 is absorbed along longest box side length, "1.0f" = no absorption)
#define GRAPHICS_RAYTRACING_COLOR 0x005F7F // absorption color of fluid in raytracing graphics

//#define GRAPHICS_TRANSPARENCY 0.7f // optional: comment/uncomment this line to disable/enable semi-transparent rendering (looks better but reduces framerate), number represents transparency (equal to 1-opacity) (default: 0.7f)



// #############################################################################################################
Expand Down
30 changes: 16 additions & 14 deletions src/graphics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,24 +67,15 @@ void set_light(const uint i, const float3& position) {
}
}
int shading(const int color, const float3& p, const float3& normal, const bool translucent=false) {
const float snb = sq(normal.x)+sq(normal.y)+sq(normal.z); // only one sqrt instead of two
const float nl2 = sq(normal.x)+sq(normal.y)+sq(normal.z); // only one sqrt instead of two
float br = 0.0f;
for(uint i=0u; i<light_sources_n; i++) {
const float3 d = light_sources[i]-p; // direction of light source
const float sdb = sq(d.x)+sq(d.y)+sq(d.z);
const float nbr = dot(d, normal)/sqrt(snb*sdb);
br = fmax(br, translucent ? abs(nbr) : nbr);
const float dl2 = sq(d.x)+sq(d.y)+sq(d.z);
const float bri = dot(d, normal)/sqrt(nl2*dl2);
br = fmax(br, translucent ? fabs(bri) : bri);
}
br = fmax(0.2f, br);
return ::color((int)(br*(float)red(color)), (int)(br*(float)green(color)), (int)(br*(float)blue(color)));
}
int color_mix_3(const int c0, const int c1, const int c2, const float w0, const float w1, const float w2) { // w0+w1+w2 = 1
const int r0=red(c0), g0=green(c0), b0=blue(c0);
const int r1=red(c1), g1=green(c1), b1=blue(c1);
const int r2=red(c2), g2=green(c2), b2=blue(c2);
const float3 fc0=float3((float)r0, (float)g0, (float)b0), fc1=float3((float)r1, (float)g1, (float)b1), fc2=float3((float)r2, (float)g2, (float)b2);
const float3 fcm = w0*fc0+(w1*fc1+(w2*fc2+float3(0.5f, 0.5f, 0.5f)));
return ::color((int)fcm.x, (int)fcm.y, (int)fcm.z);
return color_mul(color, fmax(1.25f*br, 0.3f));
}
ulong get_font_pixels(const int character) {
ulong pixels[224] = { // font data (my own 6x11 monospace font)
Expand Down Expand Up @@ -333,6 +324,17 @@ void draw_label(const int x, const int y, const string& s, const int color) {
}
}
}
void draw_line_label(const int x0, const int y0, const int x1, const int y1, const int color) {
draw_line(x0, y0, x1, y1, color);
if(camera.vr) {
if((x0+x1)/2-camera.width/2>0) {
draw_line(x0-(int)camera.width/2, y0, x1-(int)camera.width/2, y1, color);
}
if((x0+x1)/2+(int)camera.width/2<(int)camera.width) {
draw_line(x0+(int)camera.width/2, y0, x1+(int)camera.width/2, y1, color);
}
}
}
void draw_bitmap(const int* bitmap) {
std::copy(bitmap, bitmap+(int)camera.width*(int)camera.height, camera.bitmap);
}
Expand Down
6 changes: 6 additions & 0 deletions src/graphics.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,11 @@ class Camera {
R.xx = cosrx; R.xy = sinrx; R.xz = 0.0f;
R.yx = sinrx*sinry; R.yy = -cosrx*sinry; R.yz = cosry;
R.zx = -sinrx*cosry; R.zy = cosrx*cosry; R.zz = sinry;
if(!free) {
pos.x = R.zx*dis/zoom;
pos.y = R.zy*dis/zoom;
pos.z = R.zz*dis/zoom;
}
}
void set_key_state(const int key, const bool state) {
key_state[clamp(256+key, 0, 511)] = state;
Expand Down Expand Up @@ -329,6 +334,7 @@ void set_light(const uint i, const float3& p);

void draw_bitmap(const int* bitmap);
void draw_label(const int x, const int y, const string& s, const int color);
void draw_line_label(const int x0, const int y0, const int x1, const int y1, const int color);

void draw_pixel(const int x, const int y, const int color); // 2D drawing functions
void draw_circle(const int x, const int y, const int r, const int color);
Expand Down
Loading

0 comments on commit b15cbbe

Please sign in to comment.