# Is it possible to simulate fluid dynamics in a time-based and deterministic manner?

The Problem Domain

I have a number of network-connected PCs. I want to be able to simulate and replicate the same simple fluid dynamics simulation (E.g. Navier-Stokes), in real-time, between them. That is to say, the same body of fluid will be simulated at the same time in isolation on each PC. They will all have the same starting conditions.

Simple so far I hope. Now, each PC with its own simulation can independently add input into the simulation. For example, one PC may add/subtract some fluid at $xyz$ at time $t$ of its own simulation. I need to be able to replicate that input to all other PCs and simulations so they each stay in sync with each other.

I suppose to summarize in other words - I would like to run a single fluid dynamics simulation across a number of network-connected PCs in real-time. I cannot simply replicate the resulting simulation data to all other PCs as the latency and bandwidth requirements would be too great and all other PCs would lag behind. They each need to be in sync as much as possible.

The Question

My question here is in regards to the fluid dynamics equation: Is it possible to simulate fluid dynamics that can take input at time $t$, that may be in the past by the time the simulation gets the input, and take that into account?

Note: When I say input I mean a change in the simulation environment be it a change to the container the fluid is held in, a change in forces or a change in fluid volume.

My current assumptions for this question is that it is possible to run simple fluid dynamics in real-time (See Jos Stams implementation).

• I believe what you're referring to is a particular instance of what is called data assimilation. In general, adding one observation in the past requires complete recalculation of all subsequent time steps. I don't think this can be done easily in real time if you have lots of variables and/or time steps. Of course, I'm no expert at this. – Paul May 7 '14 at 22:50
• @Paul It does sound like its on the right track. Has anyone applied this to fluid simulation though? – S.Richmond May 7 '14 at 23:02
• They do this a lot in weather predictions, but they usually obtain and assimilate sensor data dynamically. I don't think they typically add sensor data retroactively, as you pose in your question. What exactly are you trying to model? You question is a bit vague and I don't think you'll get much help without more details about your specific problem. – Paul May 8 '14 at 0:12
• A full NS solver in real time for something such as gaming over a network is likely infeasible and overkill. If you can come up with an acceptable fluid model that utilizes parabolic PDE's, you would be able to limit the relative area that needs to be recalculated based on how far in the past the event was. – Godric Seer May 8 '14 at 0:13
• @Paul I am trying to create a fluid simulation in a multiplayer video game. I'm trying to find an efficient way to keep the simulation in sync between peers. Hope that helps add some context. – S.Richmond May 8 '14 at 0:56

This is a very interesting problem. If I understand right, you are simulating a body of water in several PCs at the same time. They all start at the same time and if left alone they should get the same result after some time. However, your user will create a disturbance (associated with your game I presume) in one of the PCs and then that should be transmitted to the other PCs so they can see the disturbance too. Due to the lag in the transmission of info, the other computers will be out of sync if they use the disturbance when they receive it instead of at the time it was created in the original PC.

Your idea is that maybe the data from the PC that caused the disturbance can be weaved into the results of the other PCs to correct the result for the present. A potential implementation of that could be:

You need to run your predictive model faster than real time but then you show the results in real time. So you have one process in the background that runs the next 10 second in 1 second for instance. Then when something happens in one PC you send the info to the others with the real time stamp. The other computers will get this info and run the predictive model starting just before the time stamp from the disturbance (which is before the current time). Since you're running this 10 or more times faster you can actually know the result at the current time including the disturbance data from the other PCs and show that to the player.

Is this the kind of solution your looking for?

• Not a bad idea. However would you need to simulate ahead of time? Wouldn't it be better to keep a history of the simulation past and when you get disturbance request from another PC you add it to you simulation at the right time in the past and then re-perform the sim from that point on. The outcome I think might in reality look bad as the resulting water surface in harshly 'snap' to a new simulation. But I think that can be smoothed locally. Thoughts? – S.Richmond Jul 9 '14 at 6:42
• You're right, you don't need to simulate ahead. I was suggesting that so you can have a "simulating" process and a "showing" process that are asynchronous. The key though is that the simulation needs to be a lot faster (10x at least) than real time. And yes, you will suffer a 'snap' that will be bigger or smaller depending on the lag that you will need to smooth locally. I think the most complex (albeit interesting :)) problem is how to deal with the variability of the lags and what decision to make accordingly to present the new information without interfering with the playability. – Rusty30 Jul 9 '14 at 12:26
• I think the best solution, and the one I'm hoping to find, is a fluid simulation that can be run in variable time steps. So if I need to go back 200ms to rerun the sim with new disturbance info I can just ask the sim to do so with the stored historical data and skip any sim steps between 200ms ago and now that didn't have any additional interaction with the fluid. I do not know, mathematically, if such a fluid sim exists. – S.Richmond Jul 9 '14 at 23:49
• No, that kind of solution that can jump very long in time (compared to the time and spatial resolution of the problem you're solving) doesn't exist with the exception of very simplified problems and domains (which are probably not your case). That is why you need a very fast solver that can run the 200 ms in 2 ms, which is absolutely doable given the computer horsepower of today. – Rusty30 Jul 11 '14 at 1:19
• Hrm interesting. So anything that interacts with the sim and moves in the game will need to store a historical buffer of its movement. That shouldn't be too hard. – S.Richmond Jul 11 '14 at 6:38