# MATLAB code for Computational Fluid Mechanics

Tags:
1. Nov 16, 2014

### airliner

Hello guys, I'm writing to get some help on an exercise I've been thinking but I can't get to solve.

I have to write the code for the Example 8.5 of the book White, Fluid Mechanics. Here is the problem and the solution I have to obtain.

It is about one duct that has three sections in which I have to obtain the value of the stream function in every node of the mesh. The PDE I have to solve is $\dfrac{\partial^{2}\psi}{\partial x^{2}} + \dfrac{\partial^{2}\psi}{\partial y^{2}} = 0$, I have approximated it using the finite element difference (2n order) and with $\Delta x = \Delta y = 0$ I have obtained the approximation: $\psi_{i,j} = \dfrac{1}{4} (\psi_{i+1,j} + \psi_{i-1,j} + \psi_{i,j+1} + \psi_{i,j-1})$, that is that I need the upper, lower, right and left values to obtain the $\psi_{i,j}$ value at any point of the mesh.

I know the boundary conditions which are:
Through the whole upper wall: $\psi = 10$
Through the whole lower wall: $\psi = 0$
Inlet: $\psi(1,j) = 2\cdot (j-6)$ from: $j=7$ to: $j=10$
Outlet: $\psi(16,j) = j-1$ from: $j=2$ to: $j=10$

Up to this point, everything is OK. But the problem is that I need to solve the mesh (inner nodes are unknown), and I only know boundary nodes. How can I compute the inner nodes values if I need 4 values (to solve: $\psi_{i,j} = \dfrac{1}{4} (\psi_{i+1,j} + \psi_{i-1,j} + \psi_{i,j+1} + \psi_{i,j-1})$) ?

I need to compile a program with Matlab, but my problem is not coding the program... It is that I don't know how can I do it to use the last equation to obtain the inner nodes values...

Does anyone know how to do it? Any help is useful.

Thank you very much. I hope you guys understand which is my problem with this exercise.

2. Nov 17, 2014

### Staff: Mentor

You'll probably have to write a program to handle this as MATLAB libraries from what I've resd online are limited in what they can do in fluid dynamics.

An alternative might be to look into Open Source Physics Java library which provides the tools and framework to do this kind of simulation. It will require you to learn Java programming and become proficient using the OSP ODE solvers to solve it.