barbagroup / CFDPython

A sequence of Jupyter notebooks featuring the "12 Steps to Navier-Stokes" http://lorenabarba.com/
Other
3.43k stars 1.19k forks source link

Initialization error in Step 9 #78

Open Bob-McCrory opened 4 years ago

Bob-McCrory commented 4 years ago

In the fourth code cell in 12_Step_9.ipynb, dy is set to 2 / (ny - 1). To be consistent with the y array, this should be 1 / (ny - 1).

Correcting this has several effects. First, convergence slows. With the current version, laplace2d() stops iterating at 1,133 steps; after applying the correction, it takes 2,043 steps. Second, the revision affects how close laplace2d() comes to the analytic solution. I use sum(p) as a rough comparison among different results from laplace2d(). The current version (2/(ny - 1)) produces a sum of 231.8 when iteration stops at 1,133 steps. The corrected initialization (1/(ny - 1)) produces 220.2 at 2,043 steps. Compare these with the analytic solution sum of 240.25.

I'm translating to Julia as I work through the Steps. My Julia versions of Step 9 come up with the same results as the revised Python version. In addition, it shows that if you iterate the Julia version of laplace2d() for 5,000 steps, you come up pretty close the analytic solution (sum of 239.5 vs. the 240.25 noted above).

Hope this helps. Thanks again for all your work on this. In addition, thank you for keeping it current.

On to Step 10!

piyueh commented 4 years ago

@Bob-McCrory yeah, that looks like a bug.

In fact, if we assess errors using norms (like l1, l2, etc.), without changing other settings, we can immediately see using correct dy gives smaller errors.