Skip to content

pixelfung/3dfluid

 
 

Repository files navigation

Fluid Simulation with Event Manager

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.

Table of Contents

  1. Project Structure
  2. Requirements
  3. Installation
  4. Usage
  5. Example
  6. Credits

Project Structure

├── 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

Requirements

  • 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.

Libraries and Tools

  • Python
  • Standard C++ libraries for compilation (e.g., g++ or clang++).

Installation

  1. Clone the repository:

    git clone https://github.com/jgbarbosa/3dfluid.git
    cd 3dfluid
  2. Compile the C++ Simulation: Use the included Makefile to build the C++ simulation.

    make

    This will generate an executable named fluid_sim.

Usage

Generating Event Data

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.

  1. 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.

  2. 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.

Running the Fluid Simulation

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.

  1. 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.

  2. 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
    

Example

Generating Events

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

Problems with the generator

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.

Running the Simulation

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.

Credits

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

About

Joe Stam's build solver

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C++ 84.9%
  • Python 10.5%
  • C 2.2%
  • CMake 1.4%
  • Makefile 1.0%