Shallow water dam break problem for a 1D matlab model

It may also be helpful to run your code line by line in the command window to see where the problem may be occurring.
  • #1
blizzard12345
14
0
i am trying to spproximate a PDE in the form below using the lax wendroff 2 step method in MATLAB coding:

[h ; hu ] = [ hu ; hu^2 + 1/2gh^2] = [0; -ghbz] (where bz will equal zero)

i believe this is then the case

d(h)/dt + d(hu)/dx = 0

and

d(hu)/dt + d(hu^2 + 1/2gh^2)/dx = 0

as the st venant equation was formed by depth deriving the 1D continuity equation

however i have attempted to program this and i keep produced a column matrix full of "NaN" could some one try to point out where i have been going wrong? thanks kyle

code for matlab:

%%%%%%%%%%%%%%%% function compare close all clc clear all

%intial values ntime = 1000000; dt=0.00050; nx=100; time = 0; a=2;output=0.24; %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 beginning and %end depending which value of A is used u_int(nx,2) =1; u_int(1,1) = 1;

%loop for the two directions needed for vec = 1:2 % %lax_wendroff [H] = lax_wendroff_2(nx,a,output, dt, ntime, time,u_int, vec,dx); figure(vec) H plot(H(:,vec),'r*');grid on;legend('centered'); hold on end end

function [H] = lax_wendroff_2(nx,a,output, dt, ntime, time,u_int, vec,dx); %compute original size matracies g = 9.81; uh=zeros(nx,2); update = uh ; H = uh; Hy = uh; UH = uh; if vec == 1; %for i = 1:nx u_int(nx-2:nx,2) = 1; u_int(1:3,1) = 1; %end for i = 1:nx UH(i,vec)=u_int(i,vec); Hy(i,vec)=u_int(i,vec); uh(i,vec)=u_int(i,vec); H(i,vec)=u_int(i,vec); A=a; end else uh(nx,vec)=u_int(nx,vec); h(nx,vec)=u_int(nx,vec); A=-a; end for p = 1:ntime; if(time + dt>output); dt=output-time; end % calculate coefficent coeff=dt/dx; %calculate interim steps for i = 1:(nx-1) % first derivative Hy(i+1,vec)= ((H(i+1,vec)+H(i,vec))/2) - ((coeff*A/2)*((uh(i+1,vec) - uh(i,vec))));

UH(i+1,vec)=((uh(i,vec)+uh(i+1,vec))/2) ;
-coeff*A*(((uh(i+1,vec)^2)/(H(i+1,vec)+g/2*H(i+1,vec)^2)) - ((uh(i,vec)^2)/(H(i,vec)+g/2*H(i,vec)^2)));
end
%calculate full time steps
for i = 2:(nx-1)
update_h(i+1,vec) = H(i,vec) - coeff*A*(UH(i+1,vec) - UH(i,vec));%%%% check i notation and convention may be wrong way
update_uh(i+1,vec) = (uh(i,vec)) - (coeff*A*(((UH(i+1,vec)^2)/(Hy(i+1,vec)+g/2*Hy(i+1,vec)^2))- ((UH(i,vec)^2)/(Hy(i,vec)+g/2*Hy(i,vec)^2))));
end
for i = 3:(nx-1)
H(i,vec) = update_h(i,vec);
uh(i,vec) = update_uh(i,vec);
end
time = time + dt;
if time==output
break
end
end end %%%%%%%%%%%%%%%%%
 
Physics news on Phys.org
  • #2
%%%%%%%%%%%%%%%%%%%%The problem is likely due to an issue with the syntax of your code. For example, in the lax_wendroff_2 function, you have several lines of code that are missing a closing bracket. Additionally, you have several lines that are missing a semicolon at the end. I would suggest double-checking your syntax and ensuring that all brackets and semicolons are in the correct places.
 

Related to Shallow water dam break problem for a 1D matlab model

1. What is a shallow water dam break problem?

A shallow water dam break problem refers to a scenario in which a dam holding back a body of water suddenly breaks, causing a rapid and intense release of water downstream. This can lead to flooding and significant changes in the water flow and depth.

2. What is a 1D matlab model?

A 1D matlab model is a mathematical representation of a physical system that is limited to one dimension. In the case of a shallow water dam break problem, the model would simulate the flow of water along a single line, typically representing the direction of the river or stream.

3. How does the matlab model simulate the shallow water dam break problem?

The matlab model uses a set of equations and parameters to simulate the behavior of the water flow after a dam break. These equations take into account factors such as the initial water depth, the shape of the river bed, and the speed and direction of the water release.

4. What are the benefits of using a matlab model for this problem?

Using a matlab model allows scientists to study and predict the behavior of a shallow water dam break problem without having to conduct expensive and time-consuming physical experiments. The model can also be adjusted and refined to simulate different scenarios and test potential solutions to mitigate the effects of a dam break.

5. Are there any limitations to the 1D matlab model for shallow water dam break problems?

While a 1D matlab model can provide valuable insights into the behavior of a shallow water dam break problem, it is important to note that it is a simplified representation of a complex real-world situation. The model may not accurately capture all the variables and dynamics at play, so its predictions should be interpreted with caution and validated with other methods.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
5K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
963
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
3K
Replies
1
Views
1K
  • Programming and Computer Science
Replies
1
Views
987
Replies
4
Views
1K
Replies
61
Views
1K
  • Linear and Abstract Algebra
Replies
1
Views
974
  • MATLAB, Maple, Mathematica, LaTeX
Replies
8
Views
2K
Back
Top