clc; close all;

save_figures = 1;

n_dt = 8;
t_vect = 0:(n_dt * dt):T;

% (x,y) = (100,0)
values_rho_R = rho_boundary_R(1:n_dt:end);
values_u_R = u_boundary_R(1:n_dt:end);
values_v_R = v_boundary_R(1:n_dt:end);
values_p_R = p_boundary_R(1:n_dt:end);


t_step_exact = 0.05;
t_vect_exact = 0:t_step_exact:T;
n = length(t_vect_exact);
values_rho_exact_R = zeros(1,n);
values_u_exact_R = zeros(1,n);
values_v_exact_R = zeros(1,n);
values_p_exact_R = zeros(1,n);

x_boundary_R = 100; y_boundary_R = 0;
tic;
for i = 1:n
    [rho_point,u_point,v_point,p_point] = ExactSolution(x_boundary_R,y_boundary_R,t_vect_exact(i));
    values_rho_exact_R(i) = rho_point; 
    values_u_exact_R(i) = u_point; 
    values_v_exact_R(i) = v_point; 
    values_p_exact_R(i) = p_point; 
end
toc;

% vykresleni numerickeho reseni bodove
fig_rho_R = figure;
plot(t_vect_exact,values_rho_exact_R,'Color','red','LineWidth',2); hold on;
plot(t_vect,values_rho_R,'*');
legend('analytical','numerical','Location','NorthEast');
xlim([0,T]);
ylim([-0.01,0.18]);
xlabel('t'); ylabel('\rho''');

fig_u_R = figure;
plot(t_vect_exact,values_u_exact_R,'Color','red','LineWidth',2); hold on;
plot(t_vect,values_u_R,'*');
legend('analytical','numerical','Location','NorthEast');
xlim([0,T]);
ylim([-0.04,0.08]);
xlabel('t'); ylabel('u''');

fig_v_R = figure;
plot(t_vect_exact,values_v_exact_R,'Color','red','LineWidth',2); hold on;
plot(t_vect,values_v_R,'*');
legend('analytical','numerical','Location','NorthEast');
xlim([0,T]);
ylim([-0.12,0.12]);
xlabel('t'); ylabel('v''');

fig_p_R = figure;
plot(t_vect_exact,values_p_exact_R,'Color','red','LineWidth',2); hold on;
plot(t_vect,values_p_R,'*');
legend('analytical','numerical','Location','NorthEast');
xlim([0,T]);
ylim([-0.04,0.08]);
xlabel('t'); ylabel('p''');

if save_figures == 1
    mesh_size_string = sprintf('%0.2f',mesh_size_parametr);
    mesh_size_string = strrep(mesh_size_string,'.',',');
    
    filename_string = ['CAA_Workshop1_Category3_Problem1_rho_solution_on_boundary_x=100_y=0_for_h=',mesh_size_string,',_N=',num2str(N)];
    saveas(fig_rho_R,filename_string,'pdf');
    saveas(fig_rho_R,filename_string,'png');
    
    filename_string = ['CAA_Workshop1_Category3_Problem1_u_solution_on_boundary_x=100_y=0_for_h=',mesh_size_string,',_N=',num2str(N)];
    saveas(fig_u_R,filename_string,'pdf');
    saveas(fig_u_R,filename_string,'png');
    
    filename_string = ['CAA_Workshop1_Category3_Problem1_v_solution_on_boundary_x=100_y=0_for_h=',mesh_size_string,',_N=',num2str(N)];
    saveas(fig_v_R,filename_string,'pdf');
    saveas(fig_v_R,filename_string,'png');
    
    filename_string = ['CAA_Workshop1_Category3_Problem1_p_solution_on_boundary_x=100_y=0_for_h=',mesh_size_string,',_N=',num2str(N)];
    saveas(fig_p_R,filename_string,'pdf');
    saveas(fig_p_R,filename_string,'png');
end


% (x,y) = (0,100)
values_rho_T = rho_boundary_T(1:n_dt:end);
values_u_T = u_boundary_T(1:n_dt:end);
values_v_T = v_boundary_T(1:n_dt:end);
values_p_T = p_boundary_T(1:n_dt:end);


t_step_exact = 0.05;
t_vect_exact = 0:t_step_exact:T;
n = length(t_vect_exact);
values_rho_exact_T = zeros(1,n);
values_u_exact_T = zeros(1,n);
values_v_exact_T = zeros(1,n);
values_p_exact_T = zeros(1,n);

x_boundary_T = 0; y_boundary_T = 100;
tic;
for i = 1:n
    [rho_point,u_point,v_point,p_point] = ExactSolution(x_boundary_T,y_boundary_T,t_vect_exact(i));
    values_rho_exact_T(i) = rho_point; 
    values_u_exact_T(i) = u_point; 
    values_v_exact_T(i) = v_point; 
    values_p_exact_T(i) = p_point; 
end
toc;

% vykresleni numerickeho reseni bodove
fig_rho_T = figure;
plot(t_vect_exact,values_rho_exact_T,'Color','red','LineWidth',2); hold on;
plot(t_vect,values_rho_T,'*');
legend('analytical','numerical','Location','NorthEast');
xlim([0,T]);
ylim([-0.03,0.06]);
xlabel('t'); ylabel('\rho''');

fig_u_T = figure;
plot(t_vect_exact,values_u_exact_T,'Color','red','LineWidth',2); hold on;
plot(t_vect,values_u_T,'*');
legend('analytical','numerical','Location','NorthEast');
xlim([0,T]);
ylim([-0.03,0.015]);
xlabel('t'); ylabel('u''');

fig_v_T = figure;
plot(t_vect_exact,values_v_exact_T,'Color','red','LineWidth',2); hold on;
plot(t_vect,values_v_T,'*');
legend('analytical','numerical','Location','NorthEast');
xlim([0,T]);
ylim([-0.03,0.05]);
xlabel('t'); ylabel('v''');

fig_p_T = figure;
plot(t_vect_exact,values_p_exact_T,'Color','red','LineWidth',2); hold on;
plot(t_vect,values_p_T,'*');
legend('analytical','numerical','Location','NorthEast');
xlim([0,T]);
ylim([-0.03,0.06]);
xlabel('t'); ylabel('p''');

if save_figures == 1
    mesh_size_string = sprintf('%0.2f',mesh_size_parametr);
    mesh_size_string = strrep(mesh_size_string,'.',',');
    
    filename_string = ['CAA_Workshop1_Category3_Problem1_rho_solution_on_boundary_x=0_y=100_for_h=',mesh_size_string,',_N=',num2str(N)];
    saveas(fig_rho_T,filename_string,'pdf');
    saveas(fig_rho_T,filename_string,'png');
    
    filename_string = ['CAA_Workshop1_Category3_Problem1_u_solution_on_boundary_x=0_y=100_for_h=',mesh_size_string,',_N=',num2str(N)];
    saveas(fig_u_T,filename_string,'pdf');
    saveas(fig_u_T,filename_string,'png');
    
    filename_string = ['CAA_Workshop1_Category3_Problem1_v_solution_on_boundary_x=0_y=100_for_h=',mesh_size_string,',_N=',num2str(N)];
    saveas(fig_v_T,filename_string,'pdf');
    saveas(fig_v_T,filename_string,'png');
    
    filename_string = ['CAA_Workshop1_Category3_Problem1_p_solution_on_boundary_x=0_y=100_for_h=',mesh_size_string,',_N=',num2str(N)];
    saveas(fig_p_T,filename_string,'pdf');
    saveas(fig_p_T,filename_string,'png');
end


% (x,y) = (-100,0)
values_rho_L = rho_boundary_L(1:n_dt:end);
values_u_L = u_boundary_L(1:n_dt:end);
values_v_L = v_boundary_L(1:n_dt:end);
values_p_L = p_boundary_L(1:n_dt:end);


t_step_exact = 0.05;
t_vect_exact = 0:t_step_exact:T;
n = length(t_vect_exact);
values_rho_exact_L = zeros(1,n);
values_u_exact_L = zeros(1,n);
values_v_exact_L = zeros(1,n);
values_p_exact_L = zeros(1,n);

x_boundary_L = -100; y_boundary_L = 0;
tic;
for i = 1:n
    [rho_point,u_point,v_point,p_point] = ExactSolution(x_boundary_L,y_boundary_L,t_vect_exact(i));
    values_rho_exact_L(i) = rho_point; 
    values_u_exact_L(i) = u_point; 
    values_v_exact_L(i) = v_point; 
    values_p_exact_L(i) = p_point; 
end
toc;

% vykresleni numerickeho reseni bodove
fig_rho_L = figure;
plot(t_vect_exact,values_rho_exact_L,'Color','red','LineWidth',2); hold on;
plot(t_vect,values_rho_L,'*');
legend('analytical','numerical','Location','NorthEast');
xlim([0,T]);
ylim([-0.02,0.05]);
xlabel('t'); ylabel('\rho');

fig_u_L = figure;
plot(t_vect_exact,values_u_exact_L,'Color','red','LineWidth',2); hold on;
plot(t_vect,values_u_L,'*');
legend('analytical','numerical','Location','NorthEast');
xlim([0,T]);
ylim([-0.05,0.03]);
xlabel('t'); ylabel('u');

fig_v_L = figure;
plot(t_vect_exact,values_v_exact_L,'Color','red','LineWidth',2); hold on;
plot(t_vect,values_v_L,'*');
legend('analytical','numerical','Location','NorthEast');
xlim([0,T]);
% ylim([-0.05,0.03]); % vazne zde ma byt stale nula???
xlabel('t'); ylabel('v');

fig_p_L = figure;
plot(t_vect_exact,values_p_exact_L,'Color','red','LineWidth',2); hold on;
plot(t_vect,values_p_L,'*');
legend('analytical','numerical','Location','NorthEast');
xlim([0,T]);
ylim([-0.02,0.05]);
xlabel('t'); ylabel('p');

if save_figures == 1
    mesh_size_string = sprintf('%0.2f',mesh_size_parametr);
    mesh_size_string = strrep(mesh_size_string,'.',',');
    
    filename_string = ['CAA_Workshop1_Category3_Problem1_rho_solution_on_boundary_x=-100_y=0_for_h=',mesh_size_string,',_N=',num2str(N)];
    saveas(fig_rho_L,filename_string,'pdf');
    saveas(fig_rho_L,filename_string,'png');
    
    filename_string = ['CAA_Workshop1_Category3_Problem1_u_solution_on_boundary_x=-100_y=0_for_h=',mesh_size_string,',_N=',num2str(N)];
    saveas(fig_u_L,filename_string,'pdf');
    saveas(fig_u_L,filename_string,'png');
    
    filename_string = ['CAA_Workshop1_Category3_Problem1_v_solution_on_boundary_x=-100_y=0_for_h=',mesh_size_string,',_N=',num2str(N)];
    saveas(fig_v_L,filename_string,'pdf');
    saveas(fig_v_L,filename_string,'png');
    
    filename_string = ['CAA_Workshop1_Category3_Problem1_p_solution_on_boundary_x=-100_y=0_for_h=',mesh_size_string,',_N=',num2str(N)];
    saveas(fig_p_L,filename_string,'pdf');
    saveas(fig_p_L,filename_string,'png');
end