%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Main function %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

clear, close all;

global y depth width height thick gap space
tic;

%% Define variables
% All dimensions are given in meters
nb_pts = 1;
depth = 20e-2;
width = 3.76e-3;
height = 2.6e-3;
thick = 5e-5;
gap = 3e-3;
space = 1.32e-3;
%d = linspace(height+gap-thick/10,height+thick+thick/10,nb_pts);
d = height+thick+width/2;
scrsz = get(0,'ScreenSize');
c = [1;0;0;1];
%aviobj = avifile('electron.avi');

%% Processing
for i=1:nb_pts
    figure('Name','Simualtion Window','Position', [1 scrsz(4) scrsz(3)/2 scrsz(4)]);
    y = d; 
    [u,p,e,t] = adaptmeshing('geom','geomb',c,0,'geomf','maxt', 3e5,'tripick','pdeadworst', 'Par',1e-3,'Ngen',10);
    [ux,uy] = pdegrad(p,t,u);
    flowt = -1*[sign(ux).*log(abs(ux)+1);sign(uy).*log(abs(uy)+1)];
    flow = -1*[ux;uy];
    pdeploth(p,e,t,'xydata',u,'flowdata',flowt,'flowstyle','arrow','mesh','off','colormap','jet');
    axis([-width width 0 height+gap])
    %caxis([0 1e5]);
    %M(i) = getframe;
    %aviobj = addframe(aviobj,M(i));
end
toc
