Lax Wendroff and SWE

조회 수: 2 (최근 30일)
kyle lyth
kyle lyth 2012년 2월 16일
Hi i am looking to appoximat a depth derived 1d continuity equation to model the break of a dam at different points in time, i have been told to use the lax wendroff scheme, i belive i have programmed this okay but as to using it to solve the 1d continuity equation im not sure what to do?
The equation for the continuity that i have come up with is [h ;uh] + [uh; hu^2++1/2gh^2] = [0; -ghB] (i was actually moe lucky to stumble across it than work it out)
any help would be appreciated, preferable just a few pointers, i would like to try and do it myself :)
thanks kyle
the lax wendrof code im using is as below:
function lax
close all clc clear all
%intial values
ntime = 50; dt=0.00050; nx=100; time = 0; a=2;output=0.05;
%step size calculation dx= (1/nx);
%create size of u_int vector
u_int = zeros(nx,2);
%create little u_int vector for the initial values of height begining and %end depending which val
ue of A is used
u_int(nx,2) = 1;
u_int(1,1) = 1;
%loop for the two directions needed
for vec = 1:2
%centered
U=zeros(nx,1);%initial size of matracies
F=U;
update = U;
%determine which vector of u_int to use and wether A is posative or %negative
if vec == 1;
U(1,vec)=u_int(1,vec);
A=a;
else
U(nx,vec)=u_int(nx,vec);
A=-a;
end
%main calculation loop for specified time
for p = 1:ntime;
if(time + dt>output); dt=output-time;%if to jump out of time loop at given time
end
coeff = (dt/dx);%calculate coeff
for i = 1:(nx-1)%int calcs for next step (lax step<<<)
F(i+1,vec) = A*((U(i,vec) + U(i+1,vec))/2);
end
for i = 2:(nx-1)%true calcs back at step 2 find step 1 ect...
update(i,vec) = U(i,vec) - coeff*(F(i+1,vec)-F(i,vec));
end
for i = 2:(nx-1)
U(i,vec) = update(i,vec);
end
time = time + dt;
if time == output
break
end
end
figure(vec) plot(U(:,vec),'r');grid on;legend('centered') hold on end
end

답변 (0개)

카테고리

Help CenterFile Exchange에서 Startup and Shutdown에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by