PDE的前向和后向集成

问题描述 投票:0回答:1

我具有以下PDE,其最终条件和边界条件如下所示

PDE Equaton

我正在尝试及时向后集成此pde,但是解决方案似乎破灭了。我已经使用有限差分方案离散化了PDE,并尝试了以下MATLAB代码。但是,解决方案似乎破灭了。任何人都可以指出我尝试实现的代码中的错误或解决方案似乎崩溃的任何其他原因。我试图及时整合它,似乎效果很好。但是,我有必要将其及时向后集成。

%clear all 
clc

%% Defining the variables
v_max = 4;

%%%--- Space Domain----%%%
x_min = 0;     
x_max = 1;      
steps_space=10; %% No of discretization points in space
dx =(x_max-x_min)/steps_space;
x =0:dx:x_max;
x = x(1:end-1);

%%----Time Domain ----%%%
t=0;
t_max=2;
dt = dx/v_max; % To ensure CFL condition
steps_time = int64(t_max/dt); 


%%---- Initial Influx (Input)---%%        
lambda = 2*ones(steps_time,1);

%%%--- Initializing the Density ----%%%

row_final = 1*ones(steps_space,1);%final_con;
row1 = zeros(steps_time,steps_space);
row1(end,:) =[row_final];

%%-- Initial Velocity--%%%
v_final = v_max/(1+trapz(dx,row_final));
v = zeros(steps_time,1);
v(end) = v_final;    

for n= (steps_time-1) :-1:1

    %%% Using the First Order Upwind  

for(i=1:1:steps_space)


    if (i==1)
    %%% Boundary conditoin
    row1(n,i) = row1(n+1,i)+(dt/dx)*((v(n+1)*row1(n+1,i))-lambda(n+1));

    else
    %%% Forward PDE
    row1(n,i) = row1(n+1,i)+(v(n+1)*(dt/dx))*(row1(n+1,i)-row1(n+1,i-1));

    end

end
%%--- Updating the velocity ----%%%
v(n,:) = v_max/(1+trapz(dx,row1(n,:)));

%%--- Updating the outflux ---%%%
outflux1(n) =v(n)*row1(n,end);    


end
matlab integration numerical-methods pde
1个回答
0
投票

尝试这种差异方案enter image description hereenter image description here

for n = (steps_time-1) :-1:1
    %%% Using the First Order Upwind
    for i = 1:steps_space-1
        row1(n,i) = (row1(n+1,i)*dx+row1(n,i+1)*dt*v(n+1))/(dx+v(n+1)*dt);
    end
    surf(row1)
    pause(0.5)
    %%--- Updating the velocity ----%%%
    v(n,:) = v_max/(1+trapz(x,row1(n,:)));

    %%--- Updating the outflux ---%%%
    outflux1(n) =v(n)*row1(n,end);
end
© www.soinside.com 2019 - 2024. All rights reserved.