|
[Sponsors] |
May 23, 2018, 07:02 |
Compressible 1D Euler Equation
|
#1 |
New Member
thecampusgirl
Join Date: Jan 2018
Posts: 11
Rep Power: 8 |
Hello Im trying to write a matlab code for 1d Euler Equation I have tried different codding types. Lastly I have showed 2D code and I have tried to write it in 1d with Local Lax Friedrich method but I thing my result does not converge cause it doesnt show in figure.
Can u help me to find the mistake in my code ? gamma = 1.4; CFL = 0.5; tMax = 0.75; nx = 11; dx = 1/(nx-1); r = zeros(nx,1); u = zeros(nx,1); E = zeros(nx,1); p = zeros(nx,1); x = zeros(nx,1); Q = zeros(nx,3); Qnew = zeros(nx,3); F = zeros(nx,3); Fh = zeros(nx-1,3); c = zeros(nx,1); ah1 = zeros(nx,1); for i=1:nx x(i) = (i-1)*dx; end for i=1:nx if (x(i) < 0.0 ) p(i) = 1.0; r(i) = 1.0; u(i) = 0.0; elseif (x(i) > 0.0 ) p(i) = 0.1; r(i) = 0.125; u(i) = 0.0; end c(i) = sqrt((gamma*p(i))/r(i)); end Eig1 = abs(u) + c; dt = CFL*dx./max(Eig1(: ); nt = floor(tMax/dt); for k=1:nt for i=1:nx E(i) = p(i)./(gamma-1) + (0.5*r(i))*(u(i).^2 ); Q(i,1) = r(i); Q(i,2) = r(i).*u(i); Q(i,3) = E(i); F(i,1) = r(i).*u(i); F(i,2) = r(i).*u(i).^2 + p(i); F(i,3) = u(i).*(E(i) + p(i)); end for i=1:nx-1 ah1(i) = max(abs(u(i)) + c(i), abs(u(i+1)) + c(i+1)); Fh(i,: ) = 0.5*(F(i+1,: ) + F(i,: ) - ah1(i).*(Q(i+1,: ) - Q(i,: ))); end Qnew(1,: ) = Qnew(2,: ); Qnew(nx,: ) = Qnew(nx-1,: ); for i=2:nx-1 Qnew(i,= Q(i,: ) - (dt/dx)*(Fh(i,: ) - Fh(i-1,: )); end Q = Qnew; r = Qnew(:,1); u = Qnew(:,2)./Qnew(:,1); E = Qnew(:,3); p = (gamma-1)*(E - (0.5*Qnew(:,1)).*(u.^2)); end |
|
May 23, 2018, 11:16 |
1D Euler
|
#2 |
Senior Member
Selig
Join Date: Jul 2016
Posts: 213
Rep Power: 11 |
You will have to be more specific, but this code looks like the I posted some time ago . Your getting NaN solution correct? Try placing the boundary conditions AFTER you have solver for the interior and that should do the trick.
EDIT: Also tMax should be 0.15 or so for Sod's shock tube. EDIT 2: Also the way you calculate dt is not complete as you still need more conditions. For now just use a fixed time step when debugging. |
|
May 23, 2018, 11:27 |
|
#3 | |
New Member
thecampusgirl
Join Date: Jan 2018
Posts: 11
Rep Power: 8 |
Quote:
Yes I get Nan solution I will try your advices thank u so much |
||
May 23, 2018, 12:37 |
1D Euler
|
#4 |
Member
Moshe De Leon
Join Date: Nov 2017
Location: Portugal
Posts: 31
Rep Power: 8 |
This is just personal suggestion, but I think in terms of learning you should attempt things on your own. For me it has generated me to ask many questions, but I think its good to first try it on your own.
|
|
May 23, 2018, 12:48 |
|
#5 | |
New Member
thecampusgirl
Join Date: Jan 2018
Posts: 11
Rep Power: 8 |
Quote:
I also try to write different type of codes for this problem. You are right, I agree everything you write. I dont know how to use Python so I use matlab for now. |
||
May 23, 2018, 13:10 |
|
#6 |
Member
Refik
Join Date: Dec 2014
Location: Turkey
Posts: 58
Rep Power: 11 |
Well, i solved this problem couple of years ago with FVM, utilizing ROE Flux splitting methodology.
Reviewing the code, I seem to choose my dt as 0.001 with tmax = 1.2. I remember getting many NaN values in my solution due to my incorrect formulation of eigenvalues and eigenvectors. In MATLAB, usually the reason for NaN is because a dominator in formulation is assigned or calculated as 0 somehow, which was my case anyway. I usually add isreal function in between the calculations to see where it goes sideways. Because i remember solution vector becomes complex too with NaN values. Regards. Alper |
|
May 28, 2018, 14:29 |
Decrease dx, provide boundary conditions
|
#7 |
New Member
Aranya Dan
Join Date: Oct 2017
Posts: 19
Rep Power: 9 |
gamma = 1.4;
CFL = 0.5; tMax = 0.2; nx = 101; dx = 1/(nx-1) ; r = zeros(nx,1) ; u = zeros(nx,1) ; p = zeros(nx,1) ; Q = zeros(nx,3) ; F = zeros(nx,3) ; x=linspace(0,1,nx) ; half=uint8(nx/2); p(1:half)=1.0; r(1:half)=1.0; u(: )=0.0; p(half+1:end)=0.1; r(half+1:end)=0.125; c=sqrt(gamma*p./r); Eig1 = abs(u) + c; dt = CFL*dx/max(Eig1(: )); nt = floor(tMax/dt); for k=1:nt E = p/(gamma-1) + (0.5.*r.*(u.^2)); Q(:,1) = r(: ); Q(:,2) = r(: ).*u(: ); Q(:,3) = E(: ); F(:,1) = r(: ).*u(: ); F(:,2) = r(: ).*u(: ).^2 + p(: ); F(:,3) = u(: ).*(E(: ) + p(: )); ah1=max(abs(u+c),abs(circshift(u,-1)+circshift(c,-1))); ah2=repmat(ah1,[1,3]); Fh = 0.5*( F+circshift(F,-1) - ah2.*(circshift(Q,-1)-Q) ); Qnew = Q - (dt/dx)*(Fh-circshift(Fh,1)); Qnew(1,: ) = Qnew(2,: ); Qnew(nx,: ) = Qnew(nx-1,: ); Q = Qnew; r = Qnew(:,1); u = Qnew(:,2)./Qnew(:,1); E = Qnew(:,3); p = (gamma-1)*(E - (0.5*Qnew(:,1)).*(u.^2)); plot(x,r); pause(0.1); end cheers. Here circshift is used to provide periodic boundary conditions. Also, learn the difference between .* and * Last edited by crazyshock; May 28, 2018 at 14:30. Reason: who wanted smileys?? |
|
August 25, 2022, 05:20 |
|
#8 |
New Member
javeria
Join Date: Aug 2022
Posts: 21
Rep Power: 4 |
hello can you post your codes
|
|
August 25, 2022, 05:23 |
|
#9 |
New Member
javeria
Join Date: Aug 2022
Posts: 21
Rep Power: 4 |
i need ur codes can u post it please
|
|
August 25, 2022, 06:25 |
|
#10 |
New Member
Poly T
Join Date: May 2022
Posts: 24
Rep Power: 3 |
na, go so the work yourself.
|
|
August 25, 2022, 15:49 |
|
#11 |
New Member
javeria
Join Date: Aug 2022
Posts: 21
Rep Power: 4 |
please I m stuck
|
|
August 25, 2022, 17:28 |
|
#12 |
New Member
Poly T
Join Date: May 2022
Posts: 24
Rep Power: 3 |
Where are you stuck at?
|
|
August 25, 2022, 17:51 |
|
#13 |
New Member
javeria
Join Date: Aug 2022
Posts: 21
Rep Power: 4 |
I used laxwendroff and macckormack schemes , approximately reimann solver..... but now I need some other scheme any high resolution scheme to complete my research ... so I m stuck now
|
|
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Energy equation for compressible flow | majkl | OpenFOAM Running, Solving & CFD | 5 | February 10, 2021 16:17 |
Turbulent frequency equation for compressible kOmegaSST turbulence model | Bojan | OpenFOAM Programming & Development | 1 | September 6, 2013 07:45 |
Pressure equation & compressible flow | sasanghomi | OpenFOAM | 2 | July 30, 2013 05:59 |
Jacobian of 1D Euler Equation of Gas Dynamics | Simplicity. | Main CFD Forum | 3 | September 6, 2011 15:12 |
Euler & N-S EQUATIONS from Boltzmann EQUATION | Yogesh Talekar | Main CFD Forum | 10 | September 13, 1999 10:00 |