Skip to content

Commit b15cbbe

Browse files
committed
Coloring can now be switched between velocity/density/temperature, slice mode for field visualization now draws fully filled-in slices
1 parent f3fa55b commit b15cbbe

File tree

13 files changed

+649
-287
lines changed

13 files changed

+649
-287
lines changed

DOCUMENTATION.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ git clone https://github.com/ProjectPhysX/FluidX3D.git
7878
| <kbd>6</kbd> | raytraced free surface |
7979
| <kbd>7</kbd> | particles |
8080
| <kbd>T</kbd> | toggle slice visualization mode |
81+
| <kbd>Z</kbd> | toggle field visualization mode |
8182
| <kbd>Q</kbd> <kbd>E</kbd> | move slice in slice visualization mode |
8283

8384
<br>

LICENSE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ Copyright (c) 2022-2024 Dr. Moritz Lehmann
22

33
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:
44

5-
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.
5+
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.
66
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.
77
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.
88
4. You may not train AI models on the source code of this software, altered source versions or any part thereof.

README.md

Lines changed: 31 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,40 +8,40 @@ The fastest and most memory efficient lattice Boltzmann CFD software, running on
88

99
<details><summary>Update History</summary>
1010

11-
- v1.0 (04.08.2022)
12-
- initial release
13-
- v1.1 (29.09.2022)
11+
- [v1.0](https://github.com/ProjectPhysX/FluidX3D/releases/tag/v1.0) (04.08.2022) [changes](https://github.com/ProjectPhysX/FluidX3D/commit/768073501af725e392a4b85885009e2fa6400e48) (public release)
12+
- public release
13+
- [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)
1414
- added solid voxelization on GPU (slow algorithm)
15-
- added tool to print current camera position (key <kbd>H</kbd>)
15+
- added tool to print current camera position (key <kbd>G</kbd>)
1616
- minor bug fix (workaround for Intel iGPU driver bug with triangle rendering)
17-
- v1.2 (24.10.2022)
17+
- [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)
1818
- added functions to compute force/torque on objects
1919
- added function to translate Mesh
2020
- added Stokes drag validation setup
21-
- v1.3 (10.11.2022)
21+
- [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)
2222
- added unit conversion functions for torque
2323
- `FORCE_FIELD` and `VOLUME_FORCE` can now be used independently
2424
- minor bug fix (workaround for AMD legacy driver bug with binary number literals)
25-
- v1.4 (14.12.2022)
25+
- [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)
2626
- complete rewrite of C++ graphics library to minimize API dependencies
2727
- added interactive graphics mode on Linux with X11
2828
- fixed streamline visualization bug in 2D
29-
- v2.0 (09.01.2023)
29+
- [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)
3030
- added (cross-vendor) multi-GPU support on a single node (PC/laptop/server)
31-
- v2.1 (15.01.2023)
31+
- [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)
3232
- made solid voxelization on GPU lightning fast (new algorithm, from minutes to milliseconds)
33-
- v2.2 (20.01.2023)
33+
- [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)
3434
- 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
3535
- cells that are converted from solid->fluid during re-voxelization now have their DDFs properly initialized
3636
- added option to not auto-scale mesh during `read_stl(...)`, with negative `size` parameter
3737
- added kernel for solid boundary rendering with marching-cubes
38-
- v2.3 (30.01.2023)
38+
- [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)
3939
- added particles with immersed-boundary method (either passive or 2-way-coupled, only supported with single-GPU)
4040
- minor optimization to GPU voxelization algorithm (workgroup threads outside mesh bounding-box return after ray-mesh intersections have been found)
4141
- displayed GPU memory allocation size is now fully accurate
4242
- fixed bug in `write_line()` function in `src/utilities.hpp`
4343
- removed `.exe` file extension for Linux/macOS
44-
- v2.4 (11.03.2023)
44+
- [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)
4545
- added a help menu with key <kbd>H</kbd> that shows keyboard/mouse controls, visualization settings and simulation stats
4646
- improvements to keyboard/mouse control (<kbd>+</kbd>/<kbd>-</kbd> for zoom, <kbd>mouseclick</kbd> frees/locks cursor)
4747
- added suggestion of largest possible grid resolution if resolution is set larger than memory allows
@@ -51,14 +51,14 @@ The fastest and most memory efficient lattice Boltzmann CFD software, running on
5151
- fixed bug in make.sh where multi-GPU device IDs would not get forwarded to the executable
5252
- minor bug fixes in graphics engine (free cursor not centered during rotation, labels in VR mode)
5353
- fixed bug in `LBM::voxelize_stl()` size parameter standard initialization
54-
- v2.5 (11.04.2023)
54+
- [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)
5555
- implemented light absorption in fluid for raytracing graphics (no performance impact)
5656
- improved raytracing framerate when camera is inside fluid
5757
- fixed skybox pole flickering artifacts
5858
- fixed bug where moving objects during re-voxelization would leave an erroneous trail of solid grid cells behind
59-
- v2.6 (16.04.2023)
59+
- [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)
6060
- patched OpenCL issues of Intel Arc GPUs: now VRAM allocations >4GB are possible and correct VRAM capacity is reported
61-
- v2.7 (29.05.2023)
61+
- [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)
6262
- 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>)
6363
- made flag wireframe / solid surface visualization kernels toggleable with key <kbd>1</kbd>
6464
- added surface pressure visualization (key <kbd>1</kbd> when `FORCE_FIELD` is enabled and `lbm.calculate_force_on_boundaries();` is called)
@@ -69,7 +69,7 @@ The fastest and most memory efficient lattice Boltzmann CFD software, running on
6969
- 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
7070
- removed Debug and x86 configurations from Visual Studio solution file (one less complication for compiling)
7171
- fixed bug that particles could get too close to walls and get stuck, or leave the fluid phase (added boundary force)
72-
- v2.8 (24.06.2023)
72+
- [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)
7373
- finally added more [documentation](DOCUMENTATION.md)
7474
- cleaned up all sample setups in `setup.cpp` for more beginner-friendliness, and added required extensions in `defines.hpp` as comments to all setups
7575
- improved loading of composite `.stl` geometries, by adding an option to omit automatic mesh repositioning, added more functionality to `Mesh` struct in `utilities.hpp`
@@ -87,15 +87,15 @@ The fastest and most memory efficient lattice Boltzmann CFD software, running on
8787
- fixed bug in Q-criterion rendering of halo data in multi-GPU mode, reduced gap width between domains
8888
- 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
8989
- fixed raytracing attenuation color when no surface is at the simulation box walls with periodic boundaries
90-
- v2.9 (31.07.2023)
90+
- [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)
9191
- added cross-platform `parallel_for` implementation in `utilities.hpp` using `std::threads`
9292
- significantly (>4x) faster simulation startup with multithreaded geometry initialization and sanity checks
9393
- faster `calculate_force_on_object()` and `calculate_torque_on_object()` functions with multithreading
9494
- added total runtime and LBM runtime to `lbm.write_status()`
9595
- fixed bug in voxelization ray direction for re-voxelizing rotating objects
9696
- fixed bug in `Mesh::get_bounding_box_size()`
9797
- fixed bug in `print_message()` function in `utilities.hpp`
98-
- v2.10 (05.11.2023)
98+
- [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)
9999
- improved rasterization performance via frustrum culling when only part of the simulation box is visible
100100
- improved switching between centered/free camera mode
101101
- refactored OpenCL rendering library
@@ -106,17 +106,17 @@ The fastest and most memory efficient lattice Boltzmann CFD software, running on
106106
- replaced slow (in multithreading) `std::rand()` function with standard C99 LCG
107107
- more robust correction of wrong VRAM capacity reporting on Intel Arc GPUs
108108
- fixed some minor compiler warnings
109-
- v2.11 (07.12.2023)
109+
- [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)
110110
- interactive graphics on Linux are now in fullscreen mode too, fully matching Windows
111111
- made CPU/GPU buffer initialization significantly faster with `std::fill` and `enqueueFillBuffer` (overall ~8% faster simulation startup)
112112
- added operating system info to OpenCL device driver version printout
113113
- fixed flickering with frustrum culling at very small field of view
114114
- fixed bug where rendered/exported frame was not updated when `visualization_modes` changed
115-
- v2.12 (18.01.2024)
115+
- [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)
116116
- ~3x faster source code compiling on Linux using multiple CPU cores if [`make`](https://www.gnu.org/software/make/) is installed
117117
- significantly faster simulation initialization (~40% single-GPU, ~15% multi-GPU)
118118
- minor bug fix in `Memory_Container::reset()` function
119-
- v2.13 (11.02.2024)
119+
- [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)
120120
- data in exported `.vtk` files is now automatically converted to SI units
121121
- ~2x faster `.vtk` export with multithreading
122122
- added unit conversion functions for `TEMPERATURE` extension
@@ -127,6 +127,16 @@ The fastest and most memory efficient lattice Boltzmann CFD software, running on
127127
- fixed slow numeric drift issues caused by `-cl-fast-relaxed-math`
128128
- fixed wrong Maximum Allocation Size reporting in `LBM::write_status()`
129129
- fixed missing scaling of coordinates to SI units in `LBM::write_mesh_to_vtk()`
130+
- [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)
131+
- coloring can now be switched between velocity/density/temperature with key <kbd>Z</kbd>
132+
- uniform improved color palettes for velocity/density/temperature visualization
133+
- color scale with automatic unit conversion can now be shown with key <kbd>H</kbd>
134+
- slice mode for field visualization now draws fully filled-in slices instead of only lines for velocity vectors
135+
- shading in `VIS_FLAG_SURFACE` and `VIS_PHI_RASTERIZE` modes is smoother now
136+
- `make.sh` now automatically detects operating system and X11 support on Linux and only runs FluidX3D if last compilation was successful
137+
- fixed compiler warnings on Android
138+
- fixed `make.sh` failing on some systems due to nonstandard interpreter path
139+
- fixed that `make` would not compile with multiple cores on some systems
130140

131141
</details>
132142

src/defines.hpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,18 @@
3131
#define GRAPHICS_FRAME_WIDTH 1920 // set frame width if only GRAPHICS is enabled
3232
#define GRAPHICS_FRAME_HEIGHT 1080 // set frame height if only GRAPHICS is enabled
3333
#define GRAPHICS_BACKGROUND_COLOR 0x000000 // set background color; black background (default) = 0x000000, white background = 0xFFFFFF
34-
//#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)
3534
#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)
35+
#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)
36+
#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)
37+
#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)
3638
#define GRAPHICS_Q_CRITERION 0.0001f // Q-criterion value for Q-criterion isosurface visualization (default: 0.0001f)
37-
#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)
3839
#define GRAPHICS_STREAMLINE_SPARSE 4 // set how many streamlines there are every x lattice points
3940
#define GRAPHICS_STREAMLINE_LENGTH 128 // set maximum length of streamlines
4041
#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)
4142
#define GRAPHICS_RAYTRACING_COLOR 0x005F7F // absorption color of fluid in raytracing graphics
4243

44+
//#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)
45+
4346

4447

4548
// #############################################################################################################

src/graphics.cpp

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -67,24 +67,15 @@ void set_light(const uint i, const float3& position) {
6767
}
6868
}
6969
int shading(const int color, const float3& p, const float3& normal, const bool translucent=false) {
70-
const float snb = sq(normal.x)+sq(normal.y)+sq(normal.z); // only one sqrt instead of two
70+
const float nl2 = sq(normal.x)+sq(normal.y)+sq(normal.z); // only one sqrt instead of two
7171
float br = 0.0f;
7272
for(uint i=0u; i<light_sources_n; i++) {
7373
const float3 d = light_sources[i]-p; // direction of light source
74-
const float sdb = sq(d.x)+sq(d.y)+sq(d.z);
75-
const float nbr = dot(d, normal)/sqrt(snb*sdb);
76-
br = fmax(br, translucent ? abs(nbr) : nbr);
74+
const float dl2 = sq(d.x)+sq(d.y)+sq(d.z);
75+
const float bri = dot(d, normal)/sqrt(nl2*dl2);
76+
br = fmax(br, translucent ? fabs(bri) : bri);
7777
}
78-
br = fmax(0.2f, br);
79-
return ::color((int)(br*(float)red(color)), (int)(br*(float)green(color)), (int)(br*(float)blue(color)));
80-
}
81-
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
82-
const int r0=red(c0), g0=green(c0), b0=blue(c0);
83-
const int r1=red(c1), g1=green(c1), b1=blue(c1);
84-
const int r2=red(c2), g2=green(c2), b2=blue(c2);
85-
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);
86-
const float3 fcm = w0*fc0+(w1*fc1+(w2*fc2+float3(0.5f, 0.5f, 0.5f)));
87-
return ::color((int)fcm.x, (int)fcm.y, (int)fcm.z);
78+
return color_mul(color, fmax(1.25f*br, 0.3f));
8879
}
8980
ulong get_font_pixels(const int character) {
9081
ulong pixels[224] = { // font data (my own 6x11 monospace font)
@@ -333,6 +324,17 @@ void draw_label(const int x, const int y, const string& s, const int color) {
333324
}
334325
}
335326
}
327+
void draw_line_label(const int x0, const int y0, const int x1, const int y1, const int color) {
328+
draw_line(x0, y0, x1, y1, color);
329+
if(camera.vr) {
330+
if((x0+x1)/2-camera.width/2>0) {
331+
draw_line(x0-(int)camera.width/2, y0, x1-(int)camera.width/2, y1, color);
332+
}
333+
if((x0+x1)/2+(int)camera.width/2<(int)camera.width) {
334+
draw_line(x0+(int)camera.width/2, y0, x1+(int)camera.width/2, y1, color);
335+
}
336+
}
337+
}
336338
void draw_bitmap(const int* bitmap) {
337339
std::copy(bitmap, bitmap+(int)camera.width*(int)camera.height, camera.bitmap);
338340
}

src/graphics.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,11 @@ class Camera {
7979
R.xx = cosrx; R.xy = sinrx; R.xz = 0.0f;
8080
R.yx = sinrx*sinry; R.yy = -cosrx*sinry; R.yz = cosry;
8181
R.zx = -sinrx*cosry; R.zy = cosrx*cosry; R.zz = sinry;
82+
if(!free) {
83+
pos.x = R.zx*dis/zoom;
84+
pos.y = R.zy*dis/zoom;
85+
pos.z = R.zz*dis/zoom;
86+
}
8287
}
8388
void set_key_state(const int key, const bool state) {
8489
key_state[clamp(256+key, 0, 511)] = state;
@@ -329,6 +334,7 @@ void set_light(const uint i, const float3& p);
329334

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

333339
void draw_pixel(const int x, const int y, const int color); // 2D drawing functions
334340
void draw_circle(const int x, const int y, const int r, const int color);

0 commit comments

Comments
 (0)