Skip to content

Commit bce444c

Browse files
committed
Fixed runtime estimation printed in console for simulations with multiple lbm.run(...) calls
1 parent 6bb3853 commit bce444c

File tree

8 files changed

+111
-90
lines changed

8 files changed

+111
-90
lines changed

DOCUMENTATION.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -302,15 +302,15 @@
302302
```c
303303
lbm.graphics.visualization_modes = VIS_FLAG_LATTICE|VIS_Q_CRITERION; // set visualization modes, see all available visualization mode macros (VIZ_...) in defines.hpp
304304
const uint lbm_T = 10000u; // number of LBM time steps to simulate
305-
lbm.run(0u); // initialize simulation
305+
lbm.run(0u, lbm_T); // initialize simulation
306306
while(lbm.get_t()<lbm_T) { // main simulation loop
307307
if(lbm.graphics.next_frame(lbm_T, 25.0f)) { // render enough frames for 25 seconds of 60fps video
308308
lbm.graphics.set_camera_free(float3(2.5f*(float)Nx, 0.0f*(float)Ny, 0.0f*(float)Nz), 0.0f, 0.0f, 50.0f); // set camera to position 1
309309
lbm.graphics.write_frame(get_exe_path()+"export/camera_1/"); // export image from camera position 1
310310
lbm.graphics.set_camera_centered(-40.0f, 20.0f, 78.0f, 1.25f); // set camera to position 2
311311
lbm.graphics.write_frame(get_exe_path()+"export/camera_2/"); // export image from camera position 2
312312
}
313-
lbm.run(1u); // run 1 LBM time step
313+
lbm.run(1u, lbm_T); // run 1 LBM time step
314314
}
315315
```
316316
- To find suitable camera placement, run the simulation at low resolution in [`INTERACTIVE_GRAPHICS`](src/defines.hpp) mode, rotate/move the camera to the desired position, click the <kbd>Mouse</kbd> to disable mouse rotation, and press <kbd>G</kbd> to print the current camera settings as a copy-paste command in the console. <kbd>Alt</kbd>+<kbd>Tab</kbd> to the console and copy the camera placement command by selecting it with the mouse and right-clicking, then paste it into the [`main_setup()`](src/setup.cpp) function.
@@ -431,10 +431,11 @@ By now you're already familiar with the [additional boundary types](#initial-and
431431
```
432432
- Then, in [initialization](#initial-and-boundary-conditions), make a loop over all particles (outside of the initialization loop that iterates over all grid cells):
433433
```c
434+
uint seed = 42u;
434435
for(ulong n=0ull; n<lbm.particles->length(); n++) {
435-
lbm.particles->x[n] = random_symmetric(0.5f*lbm.size().x); // this will palce the particles randomly anywhere in the simulation box
436-
lbm.particles->y[n] = random_symmetric(0.5f*lbm.size().y);
437-
lbm.particles->z[n] = random_symmetric(0.5f*lbm.size().z);
436+
lbm.particles->x[n] = random_symmetric(seed, 0.5f*lbm.size().x); // this will palce the particles randomly anywhere in the simulation box
437+
lbm.particles->y[n] = random_symmetric(seed, 0.5f*lbm.size().y);
438+
lbm.particles->z[n] = random_symmetric(seed, 0.5f*lbm.size().z);
438439
}
439440
```
440441
- Note that the position (`0`|`0`|`0`) for particles corresponds to the simulation box center.

src/info.cpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,15 @@ void Info::initialize(LBM* lbm) {
2121
gpu_mem_required = lbm->lbm_domain[0]->get_device().info.memory_used;
2222
print_info("Allocating memory. This may take a few seconds.");
2323
}
24-
void Info::append(const ulong steps, const ulong t) {
25-
this->steps = steps; // has to be executed before info.print_initialize()
26-
this->steps_last = t; // reset last step count if multiple run() commands are executed consecutively
27-
this->runtime_lbm_last = runtime_lbm; // reset last runtime if multiple run() commands are executed consecutively
28-
this->runtime_total = clock.stop();
24+
void Info::append(const ulong steps, const ulong total_steps, const ulong t) {
25+
if(total_steps==max_ulong) { // total_steps is not provided/used
26+
this->steps = steps; // has to be executed before info.print_initialize()
27+
this->steps_last = t; // reset last step count if multiple run() commands are executed consecutively
28+
this->runtime_lbm_last = runtime_lbm; // reset last runtime if multiple run() commands are executed consecutively
29+
this->runtime_total = clock.stop();
30+
} else { // total_steps has been specified
31+
this->steps = total_steps; // has to be executed before info.print_initialize()
32+
}
2933
}
3034
void Info::update(const double dt) {
3135
this->runtime_lbm_timestep_last = dt; // exact dt
@@ -55,7 +59,7 @@ void Info::print_logo() const {
5559
print("| "); print("\\ \\ / /", c); print(" |\n");
5660
print("| "); print("\\ ' /", c); print(" |\n");
5761
print("| "); print("\\ /", c); print(" |\n");
58-
print("| "); print("\\ /", c); print(" FluidX3D Version 2.17 |\n");
62+
print("| "); print("\\ /", c); print(" FluidX3D Version 2.18 |\n");
5963
print("| "); print( "'", c); print(" Copyright (c) Dr. Moritz Lehmann |\n");
6064
print("|-----------------------------------------------------------------------------|\n");
6165
}

src/info.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ struct Info { // contains redundant information for console printing
1414
uint cpu_mem_required=0u, gpu_mem_required=0u; // all in MB
1515
string collision = "";
1616
void initialize(LBM* lbm);
17-
void append(const ulong steps, const ulong t);
17+
void append(const ulong steps, const ulong total_steps, const ulong t);
1818
void update(const double dt);
1919
double time() const; // returns either elapsed time or remaining time
2020
void print_logo() const;

src/lbm.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -868,8 +868,8 @@ void LBM::do_time_step() { // call kernel_stream_collide to perform one LBM time
868868
for(uint d=0u; d<get_D(); d++) lbm_domain[d]->increment_time_step();
869869
}
870870

871-
void LBM::run(const ulong steps) { // initializes the LBM simulation (copies data to device and runs initialize kernel), then runs LBM
872-
info.append(steps, get_t());
871+
void LBM::run(const ulong steps, const ulong total_steps) { // initializes the LBM simulation (copies data to device and runs initialize kernel), then runs LBM
872+
info.append(steps, total_steps, get_t()); // total_steps parameter is just for runtime estimation
873873
if(!initialized) {
874874
initialize();
875875
info.print_initialize(); // only print setup info if the setup is new (run() was not called before)

src/lbm.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,7 @@ class LBM {
413413
LBM(const uint3 N, const float nu, const float fx, const float fy, const float fz, const uint particles_N, const float particles_rho=1.0f); // compiles OpenCL C code and allocates memory
414414
~LBM();
415415

416-
void run(const ulong steps=max_ulong); // initializes the LBM simulation (copies data to device and runs initialize kernel), then runs LBM
416+
void run(const ulong steps=max_ulong, const ulong total_steps=max_ulong); // initializes the LBM simulation (copies data to device and runs initialize kernel), then runs LBM
417417
void update_fields(); // update fields (rho, u, T) manually
418418
void reset(); // reset simulation (takes effect in following run() call)
419419
#ifdef FORCE_FIELD

src/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ void main_label(const double frametime) {
7777
draw_label(ox, oy+i, "Steps " +alignr(31u, /************************************/ alignr(10u, info.lbm->get_t())+" ("+alignr(5, to_uint(1.0/info.runtime_lbm_timestep_smooth))+" Steps/s)"), c); i+=FONT_HEIGHT;
7878
draw_label(ox, oy+i, "FPS " +alignr(33u, /************************************************************/ alignr(4u, to_uint(1.0/frametime))+" ("+alignr(5u, camera.fps_limit)+" fps max)"), c);
7979
}
80-
draw_label(2, camera.height-1*(FONT_HEIGHT)-1, "FluidX3D v2.17 Copyright (c) Dr. Moritz Lehmann", c);
80+
draw_label(2, camera.height-1*(FONT_HEIGHT)-1, "FluidX3D v2.18 Copyright (c) Dr. Moritz Lehmann", c);
8181
if(!key_H) {
8282
draw_label(camera.width-16*(FONT_WIDTH)-1, 2, "Press H for Help", c);
8383
} else {

src/resource.rc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ BEGIN
2424
VALUE "LegalCopyright", "(c) Dr. Moritz Lehmann"
2525
VALUE "OriginalFilename", "FluidX3D.exe"
2626
VALUE "ProductName", "FluidX3D"
27-
VALUE "ProductVersion", "v2.17"
27+
VALUE "ProductVersion", "v2.18"
2828
END
2929
END
3030
BLOCK "VarFileInfo"

0 commit comments

Comments
 (0)