This project simulates fluid dynamics using Jos Stam's stable fluid solver in 3D, incorporating dynamic events such as adding density sources and applying forces at specified timesteps. The events are generated using a Python script and read by the C++ simulation.
This code was developed as the base code for the project of Parallel Computing at the University of Minho, 2024/2025.
├── README.md # This file
├── events.txt # Example event file (can be generated by Python script)
├── fluid_solver.h # Header for fluid solver functions
├── fluid_solver.cpp # Implementation of the fluid solver
├── EventManager.h # Header for managing events (sources and forces)
├── EventManager.cpp # Implementation for reading and applying events
├── main.cpp # Main simulation logic that uses the fluid solver and EventManager
├── generate_events.py # Python script to generate events for the simulation
└── Makefile # Makefile to compile the C++ simulation
- C++ Compiler: The C++ code relies on the standard C++ library.
- Python: The Python script is used to generate event data for the fluid simulation.
- Python
- Standard C++ libraries for compilation (e.g.,
g++
orclang++
).
-
Clone the repository:
git clone https://github.com/jgbarbosa/3dfluid.git cd 3dfluid
-
Compile the C++ Simulation: Use the included
Makefile
to build the C++ simulation.make
This will generate an executable named
fluid_sim
.
The Python script generate_events.py
generates a file (events.txt
) that specifies density sources and forces applied during specific timesteps. All events are generated with normalized vectors, and the simulation will apply them at the correct timestep.
-
Run the Python script:
python generate_events.py
This will create an
events.txt
file with 1000 timesteps, where sources are density values, and forces are applied in positive directions along the X, Y, or Z axes. -
Customize the Event Generation: You can modify the script to generate different events by changing the number of events, the range of timesteps, or the magnitude of forces and densities.
Once you've generated the events.txt
file, you can run the fluid simulation, which will read the events and apply them over the course of the simulation.
-
Run the simulation:
./fluid_sim
The simulation will read the
events.txt
file, apply the specified sources and forces at the correct timesteps, and calculate the fluid dynamics. -
Simulation Output: At the end of the simulation, the total density in the fluid field will be printed.
Example output:
Total density after 1000 timesteps: 3456.789000
Here’s an example of how you can use the Python script to generate a file of events (events.txt
):
python generate_events.py
This will generate an event file like the following:
1000
source 10 50
force 1 0 0 200
source 5 150
force 0 1 0 400
source 8 900
If you are experiencing problems with the generator there is a events.txt file as an example in the root folder of the project.
Use the file and contact the teaching staff to get help.
Once events.txt
is generated, you can run the fluid simulation using:
./fluid_sim
The simulation will dynamically apply the sources and forces defined in events.txt
, simulate the fluid behavior, and print the total density after 1000 timesteps.
This code was developed as the base code for the Parallel Computing project at the University of Minho, 2024/2025.
Authors:
- João Luis Sobral
- João Barbosa
- Andre Pereira
- Rui Silva
- Miguel Braga