% Copyright (c) 2015, Lennon O'Naraigh
% All rights reserved.
% 
% Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
% 
% 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
% 
% 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer 
% in the documentation and/or other materials provided with the distribution.
% 
% THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 
% INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 
% IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, 
% OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 
% OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 
% OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 
% EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.



function [u_vec1,ddu_vec1,u_vec21,ddu_vec21]=get_u()

global m
global n_height
global Re
global A1
global A2
global a1
global a2

%**************************************************************************
%  Physical parameters

[n_height,Re,m,~,N_1,N_21]=fix_all_parameters();
[~,~,~,~,~,~,A1,A2,a1,a2]=get_u_laminar();

%**************************************************************************
%  Collocation grids

kk_1=1:(N_1-3);
eta_1=cos((pi/(N_1-2))*kk_1);

kk_21=1:(N_21-3);
eta_21=cos((pi/(N_21-2))*kk_21);

%**************************************************************************
% derive velocity profile in liquid

u_vec1=0*eta_1;
ddu_vec1=0*eta_1;

for i=1:(N_1-3)     
        z=(eta_1(i)-1)*(1/2);
        % z_vec1(i)=z;
        u_vec1(i)=U_1(z);
        ddu_vec1(i)=d2U_1(z);
end

%**************************************************************************
% derive velocity profile in gas

u_vec21=0*eta_21;
ddu_vec21=0*eta_21;

for i=1:(N_21-3)            
        z = (eta_21(i)+1)*(n_height/2);
        % z_vec21(i)=z;
        u_vec21(i)=U_21(z);
        ddu_vec21(i)=d2U_21(z);
end

%**************************************************************************

end

%**************************************************************************
%**************************************************************************
%**************************************************************************
%**************************************************************************

function u = U_1(z1)

global A1
global a1

u=A1*(z1^2)+a1*z1+1;

end

%**************************************************************************

function du = dU_1(z1)

global A1
global a1

du=2*A1*z1+a1;

end

%**************************************************************************

function d2u = d2U_1(~)

global A1

d2u=2*A1;

end

%**************************************************************************
%**************************************************************************

function u = U_21(z2)

global A2
global a2

u=A2*(z2^2)+a2*z2+1;
    
end

%**************************************************************************

function du = dU_21(z2)

global A2
global a2

du=2*A2*z2+a2;
    
end

%**************************************************************************

function d2u = d2U_21(~)

global A2

d2u=2*A2;
    
end
