%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%   CHOIX DE LA METHODE
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%     me   : type de schema
%
%            0 - solution analytique
%            1 - shema FTCS
%            2 - schema de Lax-Wendroff (2 pas)
%            3 - schema explicite decentre a 4 points
%            4 - schema Crank-Nicolson (difference fini) delta=0 et q=0 CN-FDM
%            4 - schema Crank-Nicolson (elts finis) delta=1/6 et q=0 CN-FEM
%            4 - schema Crank-Nicolson (mass oper.) delta=0.12 et q=0 CN-MO
%            4 - schema Crank-Nicolson (df 4pt upwind) delta=0 et q=0.5 CN-4PU
%            5 - schema Crank-Nicolson generalise + dissipation 

me=3;




%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%   CHOIX DES PARAMETRES DU MODEL
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
model.nPt=21;           %nombre maximum de points (spatial)
model.ntemps=20;        %nombre maximum de pas en temps
model.xmax=2;           %borne du domaine
model.ad=0;             %dissipation artificielle (nua)
model.courant=0.25;     %nombre de Courant de reference (fixe dt par dt=c*dx)
model.viscosite=0.2;    %viscosite physique
model.q=0.5;              %parametre q du schema decentre
model.delta=0;             %delta parametre pour l'operateur de masse




%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%   RESOLUTION NUMERIQUE
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
switch me
    case 0
        method='Analytique';
        [x,res,t] = Burger_analytique(model);
    case 1
        method='Explicite simple';
        [x,res,t] = Burger_FTCS(model);
    case 2
        method='Explicite LaxWendroff';
        [x,res,t] = Burger_LaxWendroff(model);
    case 3
        method='Explicite decentre 4 points';
        [x,res,t] = Burger_decentre4pt(model);
    case {4,5}
        method='Implicite Crank-Nicolson';
        [x,res,t] = Burger_CrankNicolson(model);
end

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%   CALCUL RMS AVEC SOLUTION ANALYTIQUE
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

[x,res_analytique]=Burger_analytique(model);
rms=sqrt(sum((res_analytique-res).^2,2))/sqrt(model.nPt-2);

% rms=0*t;
% for i=1:model.ntemps
%     u=Burger_analytique(x, model.viscosite, t(i));
%     rms(i)=norm(u-res(i,:))/sqrt(model.nPt-2);
% end

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%   AFFICHAGE DE L'ANIMATION
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
plotAnim(x,res,method);

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%   AFFICHAGE DU RMS (a decommenter si besoin)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% figure; plot(t,rms);xlabel('temps');ylabel('RMS');grid on
% title(method)
      



