Inspiration

As a friend group comprising of both engineers and computer scientists, the McGill Physics Hackathon proved to be the perfect event that combined all of our interests. Being driven by our interest in the aerospace industry, we had already been exposed multiple times to the complexity of fluid mechanics. In order to better understand this challenging topic, we wanted to create a realistic simulation using computational physics as we are all familiar with numerical analysis in python.

What it does.

Our Project simulates the flow of fluids of a user given kinematic viscosity under a variable number of independent changing force fields as well as the diffusion of these velocity vectors in the velocity field. The visualization of fluid flow can also be customized to suit the user’s aesthetic preference as the colors of the velocity vectors and the colormap of the fluid itself can be interchanged using the cmasher database. The contrasting colors represent the rotational direction of the velocity vectors, which are either clockwise or counterclockwise, while the intensity of the color represents the magnitude of velocity vectors in that certain area.

How we built it

For each time frame, we solve for the velocity field of the fluid based on the velocity field in the previous time frame using the Navier-Stokes equations. To do so, we solve the Navier-Stokes equations in 4 different steps (4 physical equations).

First, we add the forces from the force fields.

Second, we account for the advection of the fluid on itself. We compute this by using a technique for solving partial differential equations called the method of characteristics. In practice, it is implemented by a path tracer and a linear interpolator. We first trace back velocity vectors to their previous locations in the previous time frame and then use a linear interpolator.

Third, we account for the effect of the viscosity. We use an implicit method instead of an explicit one to ensure stability. We discretize the diffusion operator leading to a sparse linear system that we then solve for.

Fourth, we need to ensure that the velocity field is divergence free. We thus implemented a Poisson solver to solve the Poisson problem.

This solves the current time frame. We then update the previous velocity field to the current and similarly solve for the next time frame.

Challenges we ran into

Learning the theory of the differential equations behind fluid dynamics

Accomplishments that we're proud of

We made a beautiful and easily accessible project!

What we learned

Using Matplotlib to visualize simulations

The inner workings of fluid dynamics

What's next for Fluid Flow Simulation

Next up, we want to build a machine learning model able to perform video classification. Given a simulation, it would be able to predict the range of its viscosity. We will try different deep learning architectures using TensorFlow that combine CNN and RNN, where convolutional layers will analyze the video’s frames and the recurrent layers will analyze the temporal relations of a video.

Built With

Share this project:

Updates