Actually in this post we will solve only the right hand side the equation:
∂2p∂x2+∂2p∂y2=0
We already seen how we discretize this - the central difference scheme:
pni+1,j−2pni,j+pni−1,jΔx2+pni,j+1−2pni,j+pni,j−1Δy2=0
This equation is a little different from diffusion only in that there is no time derivative; therefore this equation will give an equilibrium for given boundary conditions. Of course equilibrium will be reached after many iterations but a convergence criterion can be used to stop the solver.
After some arrangements we can take out the equation for the scheme as follows:
pni,j=Δy2(pni+1,j+pni−1,j)+Δx2(pni,j+1+pni,j−1)2(Δx2+Δy2)
For this equation to be solved, we need to provide initial and boundary conditions. We will consider a uniform p=0 everywhere; using the same domain as in the other posts, we put the following BCs:
p = 0 at x = 0
p = y at x = 2
Let's see a representation of these boundaries and explain them:
The domain is initialized with zeros everywhere; the x axis is the right hand side axis; for x = 0 the pressure will always be zero; for x = 2, the pressure will be given by the value of y (hence the diagonal distribution); the last BC actually says that the values of p must be equal in the direction of y axis at y = 0 and y = 1, not to each other, but with the neighboring cells.
This was solved using two approaches: the loop method and function call method; here I will show only the loop method (which is actually not show in Prof. Barba's blog); the second approach can be seen on the GitHub page.
The code for looping method is the following:
A norm of 0.01 is applied as convergence criterion; after the solving is finished the following solution is plotted:
As it was expected, the boundary conditions are kept as defined.
If you want to access the codes for this problem check out my GitHub page; if you have any problems setting this up leave a comment below.
0 comments:
Post a Comment