<p>Compare it with someone else's software. Run some standardized test and find out if you get roughly the same answer as others. If you get the same answer, than the probability of having your code right is quite high.</p>

<p>Some tests:</p>

<ol>
<li><p>Flow past cylinder. In 2d take rectangular domain, cylinder in the middle, inflow on the left, outflow on the fight and calculate the force on the cylinder. Here is <a href="http://www.karlin.mff.cuni.cz/~hron/NMMO403/dfg_benchmark_results.pdf" rel="nofollow">benchmark</a> comparing handful of codes.</p></li>
<li><p>Buoyancy flow. Closed box, hot plate on bottom, cold plate on top, hot fluid starts to rise due to the buoyancy force. Here is <a href="http://www.karlin.mff.cuni.cz/~hron/NMMO403/mit_bench.pdf" rel="nofollow">benchmark</a>.</p></li>
<li><p>Rising bubble, <a href="http://www.karlin.mff.cuni.cz/~hron/NMMO403/1934_ftp.pdf" rel="nofollow">benchmark</a>.</p></li>
</ol>

<p>But unfortunately it might be quite difficult to compare your code to scientific codes in those benchmarks. I guess you implemented something as SPH or stable fluids which are not made for accuracy but for stability. </p>

<p>Take for example the flow past a cylinder. I would start the test with very small Reynolds number and then measure the force on cylinder as you increase accuracy of your simulation(lower time step, increase subdivision or increase number of particles). Does the force converges to some number? If no, than you have a problem, if yes, than have a look at the benchmark paper and compare your result with others.</p>

<hr>

<p>This method is very similar technique to one I use for testing my raytracer. I just render test scene with someone else's renderer and compare it with my result. Do they converge to the same result? If yes than I have it right, if no, than I have it wrong.</p>

CC BY-SA 3.0
2015-09-22T13:11:06.700Z
Instead of software to test against yest against known real world measurements and fluid dynamics bechmarks. Otherwise your error is tainted. I saw the same question posted elsewhere on the stackexhange network btw
joojaa
CC BY-SA 3.0
2015-09-22T13:32:19.240Z
I think that testing against real world measurement is good for testing if you have the physics right. If you only want to debug you program, than testing against others code is better idea. Plus in computer simulation you can measure anything without affecting the experiment. For example measuring fluid speed at any point is just impossible in real world experiment, but trivial in computer simulation.
tom
CC BY-SA 3.0
2015-09-22T14:30:26.947Z
Yes but you also inherit problems of their solvers. I admit i did do this a few times developing a multibody simulator and checking against results form MSC Adams but in hindsight that wasn't really stellarly useful
joojaa
CC BY-SA 3.0
2015-09-22T15:12:51.850Z
Checking against real world experiment was any better? I doubt it, but I might be wrong. The situation with multibody physics is quite different to fluid physics. Even something as simple as billiard has chaotic behavior. Moreover rigid body dynamics with contacts is not even well posed mathematical problem, do you know Painlevé paradox? So doing numerical simulation of multibody physics is doomed to fail in general. Some references: https://plus.maths.org/content/chaos-billiard-table https://en.wikipedia.org/wiki/Painlev%C3%A9_paradox
tom
CC BY-SA 3.0
2015-09-22T15:16:46.017Z
The situation with fluids is quite different. You know that numerical solution converges to weak solution of Navier-Stokes eq. So every solver, if it is consistent, has to converge to the same answer. But you have to do it for small Reynolds numbers, so no turbulence occur.
tom
CC BY-SA 3.0
2015-09-22T15:18:55.793Z
Yes i am aware of how multi body dynamics work, i kind of teach it (and briefly researched it for a year or two). But no checking against known analytical solutions was easier. But a real fluid is similarly chaotic as a multi body dynamic. So one should be able to check against laminar flow situations etc. Friction is a bitch though.
joojaa
CC BY-SA 3.0
2015-09-22T11:30:06.133Z
2015-09-22T11:30:06.133Z
tom
<p>I wrote a particle based fluid simulating program. It's hard to tell if I get the right result. The visualized result seems reasonable, but some part of it looks weird. I don't know wether it's a feature of fluid. Is there some accurate method to verify if my program is right?</p>

<p>Amending some details：</p>

<p>My program is a 2D particle-based simulating program. The fluid is compressible. The implementation is almost based on a classical paper:</p>

<blockquote>
  <p>Müller, Matthias, David Charypar, and Markus Gross. "Particle-based fluid simulation for interactive applications." Proceedings of the 2003 ACM SIGGRAPH</p>
</blockquote>

<p>I solved the Navier-Stokes equation with iteration method. It only considered pressure, gravity, viscosity and surface tension.</p>

<p><img src="https://latex.codecogs.com/gif.latex?%5Crho&space;(%5Cfrac%7B%5Cmathbf%7B%5Cpartial&space;v%7D%7D%7B%5Cpartial&space;t%7D&space;&plus;&space;%5Cmathbf%7Bv%7D&space;%5Ccdot&space;%5Cbigtriangledown&space;%5Cmathbf%7Bv%7D)&space;=&space;-%5Cbigtriangledown&space;p&space;&plus;&space;%5Crho%5Cmathbf%7Bg%7D&space;&plus;&space;%5Cmu&space;%5Cbigtriangledown%5E2&space;%5Cmathbf%7Bv%7D" title="\rho (\frac{\mathbf{\partial v}}{\partial t} + \mathbf{v} \cdot \bigtriangledown \mathbf{v}) = -\bigtriangledown p + \rho\mathbf{g} + \mu \bigtriangledown^2 \mathbf{v}" /></p>

<physics><simulation><fluid-sim>
How could I check the correctness of my result of fluid simulation?
Yyao
# How could I check the correctness of my result of fluid simulation?

(Asked by: username_0 on 2015-09-22)

I wrote a particle based fluid simulating program. It's hard to tell if I get the right result. The visualized result seems reasonable, but some part of it looks weird. I don't know wether it's a feature of fluid. Is there some accurate method to verify if my program is right?

Amending some details：

My program is a 2D particle-based simulating program. The fluid is compressible. The implementation is almost based on a classical paper:

> Müller, Matthias, David Charypar, and Markus Gross. "Particle-based fluid simulation for interactive applications." Proceedings of the 2003 ACM SIGGRAPH

I solved the Navier-Stokes equation with iteration method. It only considered pressure, gravity, viscosity and surface tension.

![](https://latex.codecogs.com/gif.latex?%5Crho&space;(%5Cfrac%7B%5Cmathbf%7B%5Cpartial&space;v%7D%7D%7B%5Cpartial&space;t%7D&space;&plus;&space;%5Cmathbf%7Bv%7D&space;%5Ccdot&space;%5Cbigtriangledown&space;%5Cmathbf%7Bv%7D)&space;=&space;-%5Cbigtriangledown&space;p&space;&plus;&space;%5Crho%5Cmathbf%7Bg%7D&space;&plus;&space;%5Cmu&space;%5Cbigtriangledown%5E2&space;%5Cmathbf%7Bv%7D "\rho (\frac{\mathbf{\partial v}}{\partial t} + \mathbf{v} \cdot \bigtriangledown \mathbf{v}) = -\bigtriangledown p + \rho\mathbf{g} + \mu \bigtriangledown^2 \mathbf{v}")

**Tags:** physics, simulation, fluid-sim


---

## 1 answers

### Answer by username_1 on 2015-09-22. Score: 2 | Accepted answer

Compare it with someone else's software. Run some standardized test and find out if you get roughly the same answer as others. If you get the same answer, than the probability of having your code right is quite high.

Some tests:

1. Flow past cylinder. In 2d take rectangular domain, cylinder in the middle, inflow on the left, outflow on the fight and calculate the force on the cylinder. Here is [benchmark](http://www.karlin.mff.cuni.cz/~hron/NMMO403/dfg_benchmark_results.pdf) comparing handful of codes.
2. Buoyancy flow. Closed box, hot plate on bottom, cold plate on top, hot fluid starts to rise due to the buoyancy force. Here is [benchmark](http://www.karlin.mff.cuni.cz/~hron/NMMO403/mit_bench.pdf).
3. Rising bubble, [benchmark](http://www.karlin.mff.cuni.cz/~hron/NMMO403/1934_ftp.pdf).

But unfortunately it might be quite difficult to compare your code to scientific codes in those benchmarks. I guess you implemented something as SPH or stable fluids which are not made for accuracy but for stability.

Take for example the flow past a cylinder. I would start the test with very small Reynolds number and then measure the force on cylinder as you increase accuracy of your simulation(lower time step, increase subdivision or increase number of particles). Does the force converges to some number? If no, than you have a problem, if yes, than have a look at the benchmark paper and compare your result with others.

---

This method is very similar technique to one I use for testing my raytracer. I just render test scene with someone else's renderer and compare it with my result. Do they converge to the same result? If yes than I have it right, if no, than I have it wrong.

> **Comments:**
> **username_2**: Instead of software to test against yest against known real world measurements and fluid dynamics bechmarks. Otherwise your error is tainted. I saw the same question posted elsewhere on the stackexhange network btw  
> **username_1**: I think that testing against real world measurement is good for testing if you have the physics right. If you only want to debug you program, than testing against others code is better idea. Plus in computer simulation you can measure anything without affecting the experiment. For example measuring fluid speed at any point is just impossible in real world experiment, but trivial in computer simulation.  
> **username_2**: Yes but you also inherit problems of their solvers. I admit i did do this a few times developing a multibody simulator and checking against results form MSC Adams but in hindsight that wasn't really stellarly useful  
> **username_1**: Checking against real world experiment was any better? I doubt it, but I might be wrong. The situation with multibody physics is quite different to fluid physics. Even something as simple as billiard has chaotic behavior. Moreover rigid body dynamics with contacts is not even well posed mathematical problem, do you know Painlevé paradox? So doing numerical simulation of multibody physics is doomed to fail in general. Some references: https://plus.maths.org/content/chaos-billiard-table https://en.wikipedia.org/wiki/Painlev%C3%A9_paradox  
> **username_1**: The situation with fluids is quite different. You know that numerical solution converges to weak solution of Navier-Stokes eq. So every solver, if it is consistent, has to converge to the same answer. But you have to do it for small Reynolds numbers, so no turbulence occur.  
> **username_2**: Yes i am aware of how multi body dynamics work, i kind of teach it (and briefly researched it for a year or two). But no checking against known analytical solutions was easier. But a real fluid is similarly chaotic as a multi body dynamic. So one should be able to check against laminar flow situations etc. Friction is a bitch though.  

---

