|
wx_BGI_Graphics
Classic BGI-compatible graphics API with modern OpenGL extension API
|
wx_bgi_graphics does not turn OpenLB into a built-in GUI toolkit. Instead, it provides a practical way to use wx_bgi as the interactive viewer shell around an OpenLB simulation.
OpenLB remains the simulation owner:
wx_bgi renders those snapshots live in a wx-backed window.OpenLB is an open-source C++ framework for Lattice Boltzmann Method (LBM) simulation. It is aimed at Computational Fluid Dynamics (CFD) and related transport problems, involving multiple physics(physical) systems, with strong emphasis on:
OpenLB itself is primarily a simulation framework, not a live interactive windowing system. That is where wx_bgi_graphics fits in.
The shared library now includes an optional OpenLB-oriented live-view path with these parts:
Declared in src/wx_bgi_ext.h:
wxbgi_field_draw_scalar_grid(...)wxbgi_field_draw_vector_grid(...)wxbgi_field_draw_scalar_legend(...)These are generic solver-view helpers, not OpenLB-only APIs. They are intended for live rendering of:
Declared in src/wx_bgi_openlb.h:
wxbgi_openlb_begin_session(...)wxbgi_openlb_pump()wxbgi_openlb_present()wxbgi_openlb_classify_point_material(...)wxbgi_openlb_sample_materials_2d(...)wxbgi_openlb_materialize_super_geometry_2d(...) *(C++ helper template)*wxbgi_openlb_materialize_super_geometry_3d(...) *(C++ helper template)*These wrappers support an OpenLB-style non-blocking main loop where the simulation remains in charge and wx_bgi only handles rendering and event pumping.
The two material-query functions form the current DDS-to-OpenLB bridge MVP:
wxbgi_openlb_classify_point_material(...) classifies one world-space sample point against the retained DDS scene and returns the resolved material idwxbgi_openlb_sample_materials_2d(...) samples a regular 2D grid of world points and writes one material id per sampleThe bridge reads generic DDS metadata from externalAttributes rather than hard-coding OpenLB-only fields into the core DDS type.
The C++ helper templates wxbgi_openlb_materialize_super_geometry_2d(...) and wxbgi_openlb_materialize_super_geometry_3d(...) keep OpenLB-specific types out of the stable C ABI while still letting OpenLB-side code stamp DDS-authored materials directly onto OpenLB SuperGeometry<T,2> and SuperGeometry<T,3> instances.
The repository now includes:
examples/cpp/wxbgi_openlb_live_demo.cppexamples/cpp/wxbgi_openlb_material_preview_demo.cppexamples/cpp/wxbgi_openlb_coupled_smoke.cppexamples/cpp/openlb-demo/wxbgi_openlb_pipe_3d_demo.cppexamples/cpp/openlb-demo/run_openlb_pipe_3d_demo.shexamples/cpp/openlb-demo/run_openlb_pipe_3d_demo_macos.shwxbgi_openlb_live_demo.cpp uses a mock live field, but it demonstrates the intended integration pattern for a real OpenLB solver:
wxbgi_openlb_material_preview_demo.cpp demonstrates the authoring side of the workflow:
openlb.materialwxbgi_field_draw_scalar_gridwxbgi_openlb_coupled_smoke.cpp demonstrates the fully coupled 2D Linux path:
openlb.material=5SuperGeometry<T,2>wxbgi_field_*examples/cpp/openlb-demo/wxbgi_openlb_pipe_3d_demo.cpp demonstrates a fully coupled 3D DDS/OpenLB duct case:
SuperGeometry<T,3>--wireframe, --flat, and --smooth from the keyboard with 1, 2, and 3--vtk (default 100 iterations) or --vtk-iterations N--sieve-hole-mm N; the demo scales the sieve row/column count from that request and then snaps the effective hole size to a lattice-safe value--flow-velocity-ms N (default 0.06)Esc or closes the windowexamples/cpp/openlb-demo/run_openlb_pipe_3d_demo.sh bootstraps the same demo on Debian, Ubuntu, and Debian/Ubuntu-based WSL2 environments. It can install the needed packages, clone the latest public OpenLB release tree into /tmp, configure a temporary OpenLB-enabled build, and then run either the interactive demo or the demo's short --test mode.
examples/cpp/openlb-demo/run_openlb_pipe_3d_demo_macos.sh does the same job on macOS, using Homebrew-provided wxwidgets and glfw instead of FetchContent for the windowing dependencies.
examples/cpp/openlb-demo/wxbgi_openlb_pipe_3d_wx_slider_demo.cpp is a wxWidgets variant of the same 3D pipe demo. It embeds the BGI renderer inside a custom wxFrame, adds a narrow left control panel, and uses a vertical slider to change the requested inflow velocity live while the solver is running. OpenLB supports this pattern for the demo because the inlet boundary is recomputed each simulation tick from the current requested physical velocity instead of being hard-wired at startup.
OpenLB support is opt-in:
For the latest public OpenLB version, clone the public GitLab release tree and point OPENLB_ROOT at that checkout:
When enabled, the build adds:
OPENLB_ROOT\src\olb.h must exist)openlb_bridge_package targetThat staging target collects the current shared library, headers, and demo into build/openlb_bridge so they can be referenced from an OpenLB checkout or demo workflow.
For the one-command Linux bootstrap path, run:
For a short build-and-smoke-check instead of the indefinite interactive run:
On macOS, use:
Or the short validation mode:
For the wx slider variant, build and run the dedicated target directly:
Or use the matching bootstrap scripts:
Every DDS object now has a generic externalAttributes map that can store OpenLB-facing labels. The bridge currently uses these keys:
| Key | Meaning |
|---|---|
openlb.role | semantic role such as fluid, solid, or boundary |
openlb.material | explicit integer material id encoded as a string |
openlb.boundary | optional boundary name such as wall or inlet |
openlb.priority | integer tie-breaker when multiple solids overlap |
openlb.enabled | 0/1 style on-off switch for export |
Useful DDS metadata APIs:
wxbgi_dds_set_external_attr(id, key, value)wxbgi_dds_get_external_attr(id, key)wxbgi_dds_clear_external_attr(id, key)wxbgi_dds_external_attr_count(id)wxbgi_dds_get_external_attr_key_at(id, index)wxbgi_dds_get_external_attr_value_at(id, index)The current material-classification bridge supports retained:
Unsupported DDS object types are currently treated as non-exportable solver geometry rather than being approximated silently.
The current support intentionally does not do the following:
In other words: this repo currently provides the viewer/runtime bridge, not a full OpenLB binding layer.
wxWidgets is single-threaded for UI. If you create something like:
inside: • the frame constructor • a button handler • a slider handler • a timer handler • or anywhere in the main thread …then wxWidgets never gets CPU time to repaint the slider.
You have three correct options:
✔ Option 1 — Run OpenLB in a worker thread (recommended) Move your simulation loop into a std::thread :
Then your GUI stays responsive.
✔ Option 2 — Use a wxTimer to “tick” OpenLB This is the simplest approach.
This ensures: • GUI thread stays alive • Slider moves normally • OpenLB runs at ~60 FPS
✔ Option 3 — Yield to the GUI inside your simulation loop If you absolutely must run OpenLB in the main thread:
(!) This is a last resort. It works, but can cause reentrancy issues. Upon return from the YIELD, make sure to redirect to the control where you left off in your simulation loop.
Use wx_bgi as the interactive visualization frontend:
openlb.* metadatawxbgi_openlb_materialize_super_geometry_2d(...) or wxbgi_openlb_materialize_super_geometry_3d(...)wxbgi_field_* helperswxbgi_openlb_pump() / wxbgi_openlb_present()If you only need offline classification rather than direct SuperGeometry materialization, the lower-level C bridge functions wxbgi_openlb_classify_point_material(...) and wxbgi_openlb_sample_materials_2d(...) remain available.
This matches the current wx rendering model well:
wxIMPLEMENT_APP-managed application loop is requiredThe latest public OpenLB GitLab release tree now builds successfully with the OpenLB-facing helper layer and the real coupled smoke demo on Linux in this repository.
Focused validation currently covers:
test_dds_external_attrstest_openlb_bridge_materialize_2dwxbgi_openlb_material_preview_demowxbgi_openlb_coupled_smokewxbgi_openlb_pipe_3d_demoLocal validation now includes a real OpenLB checkout at:
C:\Users\hamma\AppData\Local\Temp\openlb-release
An older checkout was also tested at:
C:\Users\hamma\AppData\Local\Temp\openlb-release-1.6.0
That is sufficient for OPENLB_ROOT, and the repository now wires a local OpenLB-coupled smoke target when WXBGI_ENABLE_OPENLB=ON. However, the current public OpenLB release still does not compile cleanly under native Windows/MSVC in this environment. The observed failures are in OpenLB headers and templates, not in the DDS bridge or viewer code in this repository.
Observed results so far:
1.9.0 fails early on native MSVC because the current release assumes compiler builtins and feature detection that do not map cleanly to this toolchain1.6.0 gets much further, and this repository now includes both external/tinyxml and external/tinyxml2 in the optional OpenLB include path so older releases are wired correctly1.6.0 still fails under native MSVC because OpenLB itself directly includes Unix-only headers such as unistd.hPractical consequence:
examples/cpp/wxbgi_openlb_live_demo.cpp

The demo shows the current viewer pattern: a live false-colour scalar field, decimated vector arrows, and a scalar legend rendered in real time inside the wx-backed wx_bgi window.
examples/cpp/openlb-demo/wxbgi_openlb_pipe_3d_demo.cppexamples/cpp/openlb-demo/run_openlb_pipe_3d_demo.sh- BASH script to build and run itexamples/cpp/openlb-demo/run_openlb_pipe_3d_demo_macos.sh- BASH script for macOS

The demo shows the GLFW (WXBGI_SYSTEM_GLFW=ON) based Frames from wx_bgi_graphics being setup and used with OpenLB driving C/C++ program.
examples/cpp/openlb-demo/wxbgi_openlb_pipe_3d_wx_slider_demo.cppexamples/cpp/openlb-demo/run_openlb_pipe_3d_wx_slider_demo.sh- BASH script to build and run itexamples/cpp/openlb-demo/run_openlb_pipe_3d_wx_slider_demo_macos.sh- BASH script for macOS

The demo shows the wxWidgets based Frames from wx_bgi_graphics being setup and used with OpenLB driving C/C++ program. Plus it introduces a Slider to live-control flow velocity during simulation.