Fluid Simulation
FluxRender.physics.FluidSandbox
FluidSandbox(domain_x_range: Sequence[float] = (-5.0, 5.0), domain_y_range: Sequence[float] = (-5.0, 5.0), resolution: Sequence[int] = (512, 512), fluid_viscosity: float = 0.005, friction_factor: float = 0.0, left_boundary: BoundaryConfiguration = None, right_boundary: BoundaryConfiguration = None, top_boundary: BoundaryConfiguration = None, bottom_boundary: BoundaryConfiguration = None, steps_per_frame: int = 5, spinup_steps: int = 0, smagorinsky_constant: float = 0.15, colliders: list = [])
The core 2D fluid dynamics solver using the Lattice Boltzmann Method (D2Q9).
It manages the main simulation domain, computes fluid physics, and handles interactions with defined boundary conditions and colliders.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
domain_x_range
|
Sequence[float]
|
The (min, max) mathematical coordinates mapping the spatial boundaries of the simulation domain along the X-axis. |
(-5.0, 5.0)
|
domain_y_range
|
Sequence[float]
|
The (min, max) mathematical coordinates mapping the spatial boundaries of the simulation domain along the Y-axis. |
(-5.0, 5.0)
|
resolution
|
Sequence[int]
|
The internal grid resolution (width, height) of the LBM solver. Higher values yield more accurate physics and smaller vortices, but demand exponentially more GPU VRAM and processing power. |
(512, 512)
|
fluid_viscosity
|
float
|
The kinematic viscosity of the fluid. Lower values create chaotic, highly turbulent airflows (high Reynolds number), while higher values result in thick, syrupy, laminar flows. |
0.005
|
friction_factor
|
float
|
Artificial global damping applied directly to the macroscopic velocity field. Useful for simulating shallow water floor friction or artificially calming the simulation domain. |
0.0
|
left_boundary
|
BoundaryConfiguration
|
The physical behavior of the left wall edge. Defaults to a standard solid wall. |
None
|
right_boundary
|
BoundaryConfiguration
|
The physical behavior of the right wall edge. Defaults to a standard solid wall. |
None
|
top_boundary
|
BoundaryConfiguration
|
The physical behavior of the top wall edge. Defaults to a standard solid wall. |
None
|
bottom_boundary
|
BoundaryConfiguration
|
The physical behavior of the bottom wall edge. Defaults to a standard solid wall. |
None
|
steps_per_frame
|
int
|
The number of internal physics collision/streaming iterations calculated before passing the state to the visual renderer. Higher values artificially speed up the flow of time relative to frame rate. |
5
|
spinup_steps
|
int
|
The number of initial simulation steps performed before rendering begins. This allows the simulation to reach the desired state more quickly. |
0
|
smagorinsky_constant
|
float
|
The sub-grid scale constant for the Smagorinsky turbulence model. It dynamically injects artificial eddy viscosity into high-shear regions to prevent mathematical domain explosions. Set to 0.0 to completely disable damping (requires extreme caution with viscosity values). |
0.15
|
colliders
|
list
|
A list of initial |
[]
|
Example
Creating an aerodynamic wind tunnel with a spherical obstacle using a context manager:
import FluxRender as fr
scene = fr.create_workspace(resolution=(1600, 950))
# 1. Set up the boundary conditions for the fluid domain.
# The fluid enters from the left and exits freely on the right.
inflow = fr.BoundaryConfiguration(fr.BoundaryType.INFLOW)
outflow = fr.BoundaryConfiguration(fr.BoundaryType.OPEN_OUTFLOW)
# 2. Initialize the fluid simulation environment.
# Using a context manager automatically links defined colliders to this sandbox.
with fr.FluidSandbox(
domain_y_range=(-8, 8),
domain_x_range=(-20, 30),
resolution=(1000, 400),
fluid_viscosity=0.001,
left_boundary=inflow,
right_boundary=outflow,
) as sandbox:
# 3. Define physical obstacles inside the context manager.
fr.EquationCollider(equation_function=lambda x, y: (x**2 + y**2) <= 1.0)
# 4. Create a particle system that visualizes the fluid flow.
fr.ParticleSystem(vec_function=sandbox, count=10000)
# 5. Start the engine and render the scene.
scene.run()
Source code in FluxRender/physics.py
479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 | |
add_collider
Adds one or more colliders to the simulation sandbox.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*colliders
|
Collider
|
One or more instances of the Collider class to be added to the sandbox. |
()
|
Source code in FluxRender/physics.py
load_state
Loads a microscopic fluid distribution from a binary NumPy file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filepath
|
str
|
The path to the .npy file. |
required |
Source code in FluxRender/physics.py
save_state
Saves the current microscopic fluid distribution to a binary NumPy file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filepath
|
str
|
The destination file path (must end with .npy). |
required |