资源简介
计算流体力学当中对一维欧拉激波管问题的upwind迎风格式数值算法matlab代码
代码片段和文件信息
%常数参数
gamma = 1.4;
CFL = 0.5;
Time = 0.4; %时间
a = 0; %横坐标范围
b = 1;
r=0.1; %网格比
dx = 0.005; %距离间隔
dt = dx*r;
x = a:dx:b;
t = linspace(0Time39);
maxn = (b-a)/dx+1;
nc = 2:maxn-1;
%初始时刻的值,密度(rho)、速度(u)、压强(p)、能量(E)
rho0 = 1.*(x<0.5)+0.125.*(x>=0.5);
u0 = 0.*(x<0.5)+0.*(x>=0.5);
p0 = 1.*(x<0.5)+0.1.*(x>=0.5);
m0 = u0.*rho0;
E0 = p0./((gamma-1).*rho0)+u0.^2/2;
w0 = [rho0; m0; E0];
f0 = [u0.*w0(1:) ; u0.*w0(2:) ;u0.*w0(3:)] + [u0-u0 ; p0 ; p0.*u0];
U0=[rho0 ;u0 ;p0];
U = U0;
for i = 1:Time/dt
Up = U;
Un(1:1)=Up(11);Un(2:1)=Up(21);Un(3:1)=Up(31);
for j = 2:maxn-1
A1 = U2A_sgn(Up j -1);%非正特征值对应的矩阵A-
A2 = U2A_sgn(Up j 1); %非负特征值对应的矩阵A+ A=A1 + A2
U( : j) = Up( : j) - r * (A1*(Up( : j+1)-Up( : j))...
+A2*(Up(:j)-Up(:j-1)));%一阶迎风格式
Un(1ji)=U(1j);Un(2ji)=U(2j);Un(3ji)=U(3j);
end
Un(:maxni)=U(:maxn);
end
%0.14S之后的参数值
rho = U(1:);
u = U(2:);
p = U(3:);
m = rho.*u;
E = p/(gamma-1)+0.5*rho.*u.^2;
%画图
figure(1);
subplot(511)%密度rho
plot(xrho0‘b-‘)
hold on
plot(xrho‘ro--‘)
set(gca‘YLim‘[-0.2 1.2])
set(gca‘XLim‘[a b])
%set(gca ‘YTick‘ [0 1])
hold off
title([‘dx=‘num2str(dx)‘ CFL=‘num2str(CFL)‘ t=‘num2str(Time)]);
xlabel(‘长度x‘);
ylabel(‘密度rho‘);
subplot(512)%速度u
plot(xu0‘b-‘)
hold on
plot(xu‘ro--‘)
set(gca‘YLim‘[-0.2 1.2])
set(gca‘XLim‘[a b])
%set(gca ‘YTick‘ [0 1])
hold off
xlabel(‘长度x‘);
ylabel(‘速度u‘);
subplot(513)%压力p
plot(xp0‘b-‘)
hold on
plot(xp‘ro--‘)
set(gca‘YLim‘[-0.2 1.2])
set(gca‘XLim‘[a b])
%set(gca ‘YTick‘ [0 1])
hold off
xlabel(‘长度x‘);
ylabel(‘压力p‘);
subplot(514)%质量流m
plot(xm0‘b-‘)
hold on
plot(xm‘ro--‘)
set(gca‘YLim‘[-0.5 2.5])
set(gca‘XLim‘[a b])
%set(gca ‘YTick‘ [0 1])
hold off
xlabel(‘长度x‘);
ylabel(‘质量流m‘);
subplot(515)%能量E
plot(xE0‘b--‘)
hold on
plot(xE‘ro--‘)
set(gca‘XLim‘[a b])
hold off
xl
- 上一篇:MATLAB中图像背景噪声去除
- 下一篇:基于matlab的电力系统谐波仿真
评论
共有 条评论