Using the explanations from step1 and step3, we can discretize this differential
in the following form:
And after solving for the unknown, we get the scheme to be coded in Python.
This time we will not use the same problem setup as before. The initial conditions for the velocities are created using these functions:
The boundary conditions imply periodicity and are given by:
For the problem stated like this there is an analytical solution:
The initial conditions are created using SymPy which is a symbolic math module (similar with Mathematica or MathCad).
In the end of the code, the numerical solution is compared with the analytical solution.
The Python code for solving this problem is given below:
Python code for solving the Burgers' Equation [lines 1-43] |
Python code for solving the Burgers' Equation [lines 33-76] |
Initial condition - saw tooth function |
Comparison between analytical and numerical solutions |
The code and plots can be downloaded from my personal repository on GitHub.
Next time we will make the jump to the 2D dimension and will be solving the linear convection.
If you have any observations or questions do not hesitate to leave a comment below.
0 comments:
Post a Comment