%% Analytical solution from Chanson 2006 plus Kroon 2009 for the 1D Dam Break Wet Bed Test
% Tim Leijnse
% Made for 1D Dam Break Wet Bed Test to give the analytical solution

function [x,h] = analytical_1Dwetbed(dx, t_end, dtout)
%%
h0 = 1; 
h1 = 1;
h3 = 0.1;
h4 = 0.1;
u3 = 0;
g = 9.81;
c00 = sqrt(g * h0);
c0 = sqrt(g * (h0-h4)); 

x = (-50):dx:(50);
t = 0:dtout:t_end+dtout; 

h = zeros(length(t)+1,length(x));
h2 = zeros(length(t),length(x));

for j=1:length(t) 
    for i=1:length(x)
        h2(j,i) = h0 * (2/3 - x(i)/(3*(t(j)-1)*c00))^2;
        c3 = sqrt(g*((h3)));

        h3 = 1/g * ( -1/3 * ( u3 - c3 ) + 2/3*c0)^2; %+ h4;
        u3 = sqrt(g * h3/h4 *(h3+h4)/2);

        h(j,i) = h2(j,i);
        if x(i) > 1/3*(u3-c3)*(t(j))  
             h(j,i) = h3+h4;   
        end
        if x(i) > (u3)*t(j)
             h(j,i) = h4; 
        end
        if x(i)< -1*c00*(t(j)-1)
            h(j,i) = h1;
        end
   
    end
end
%%
x = x+50;

h = h(end-1,:); 
