%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function plot_int(e_spa,I,nel,ndim,is);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% plot of internal variables on spatial configuration %%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%figure(1)   
%clf
%set(gcf, 'renderer', 'zbuffer');
%hold on;
%view(83,-40);

light;
lightangle(83,-10)
lighting phong;
material metal;
      
colormap('default')
[nel,nod]=size(e_spa);
nod = nod/ndim;
   
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% plot internal variable in its representative area for all elements
if ndim == 2 

hold off;figure(1);clf;set(gcf,'renderer','zbuffer');hold on;view(2);

for ie = 1:nel
  x   = e_spa(ie, 1:2:end);          y   = e_spa(ie, 2:2:end);
  
  x(5)=(x(1)+x(2))/2;                y(5)=(y(1)+y(2))/2;
  x(6)=(x(2)+x(3))/2;                y(6)=(y(2)+y(3))/2;
  x(7)=(x(3)+x(4))/2;                y(7)=(y(3)+y(4))/2;
  x(8)=(x(4)+x(1))/2;                y(8)=(y(4)+y(1))/2;
  x(9)=(x(1)+x(2)+x(3)+x(4))/4;      y(9)=(y(1)+y(2)+y(3)+y(4))/4;

  xip(1,:)=[x(1),x(5),x(9),x(8)];    yip(1,:)=[y(1),y(5),y(9),y(8)]; 
  xip(2,:)=[x(5),x(2),x(6),x(9)];    yip(2,:)=[y(5),y(2),y(6),y(9)]; 
  xip(3,:)=[x(8),x(9),x(7),x(4)];    yip(3,:)=[y(8),y(9),y(7),y(4)];  
  xip(4,:)=[x(9),x(6),x(3),x(7)];    yip(4,:)=[y(9),y(6),y(3),y(7)]; 

  for ip = 1:4			               
    [i_var]  = I(ie,ip);   
    hh= fill(xip(ip,:)', yip(ip,:)', i_var');
    set(hh, 'EdgeColor', 'black');
  end
end
end
% plot internal variable in its representative area for all elements
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% plot internal variable in its representative area for all elements
if ((ndim == 3)&&(nod == 4))

hold off;figure(1);clf;set(gcf,'renderer','zbuffer');hold on;view(3);
   
for ie = 1:nel
  x = e_spa(ie,1:3:end);         
  y = e_spa(ie,2:3:end);   
  z = e_spa(ie,3:3:end);   

  i1 = [1,2,3];
  i2 = [2,3,4];
  i3 = [3,4,1];
  i4 = [4,1,2];
  
  fx1 = x(i1);    fy1 = y(i1);   fz1 = z(i1);
  fx2 = x(i2);    fy2 = y(i2);   fz2 = z(i2);
  fx3 = x(i3);    fy3 = y(i3);   fz3 = z(i3);
  fx4 = x(i4);    fy4 = y(i4);   fz4 = z(i4);

 [i_var]  = I(ie,1);  
  hh  = fill3(fx1', fy1', fz1', i_var);
  hh  = fill3(fx2', fy2', fz2', i_var);
  hh  = fill3(fx3', fy3', fz3', i_var);
  hh  = fill3(fx4', fy4', fz4', i_var);

  set(hh, 'EdgeColor', 'black');
end
end
% plot internal variable in its representative area for all elements
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% plot internal variable in its representative area for all elements
if ((ndim == 3)&&(nod == 8))
    
hold off;figure(1);clf;set(gcf,'renderer','zbuffer');hold on;view(3);

[nel,niv]=size(I);
for ie = 1:nel

x = e_spa(ie,1:3:end);         
y = e_spa(ie,2:3:end);  
z = e_spa(ie,3:3:end);  
  
i1 = [1,4,3,2];
i2 = [5,6,7,8];
i3 = [1,2,6,5];
i4 = [4,8,7,3];
i5 = [1,5,8,4];
i6 = [2,3,7,6];
  
fx1 = x(i1);    fy1 = y(i1);   fz1 = z(i1);
fx2 = x(i2);    fy2 = y(i2);   fz2 = z(i2);
fx3 = x(i3);    fy3 = y(i3);   fz3 = z(i3);
fx4 = x(i4);    fy4 = y(i4);   fz4 = z(i4);
fx5 = x(i5);    fy5 = y(i5);   fz5 = z(i5);
fx6 = x(i6);    fy6 = y(i6);   fz6 = z(i6);

var = (I(ie,1) + I(ie,2) + I(ie,3) + I(ie,4) ...
	  +I(ie,5) + I(ie,6) + I(ie,7) + I(ie,8))/8;    

hh  = fill3(fx1', fy1', fz1', var, 'LineWidth', 0.5);
hh  = fill3(fx2', fy2', fz2', var, 'LineWidth', 0.5);
hh  = fill3(fx3', fy3', fz3', var, 'LineWidth', 0.5);
hh  = fill3(fx4', fy4', fz4', var, 'LineWidth', 0.5);
hh  = fill3(fx5', fy5', fz5', var, 'LineWidth', 0.5);
hh  = fill3(fx6', fy6', fz6', var, 'LineWidth', 0.5);

end
end
% plot internal variable in its representative area for all elements
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

light;
lightangle(83,-10)
lighting phong;
material metal;

%caxis([-1.0 -0.1])
%caxis([0.8 1.5])
colorbar;

axis equal;
axis off;
   
print('-dtiff', '-r200', ...
      ['plot_', num2str(is,['%',num2str(5),'.',num2str(5),'d'])])
%print('-depsc', '-r100', ...
%     ['plot_', num2str(is,['%',num2str(5),'.',num2str(5),'d'])])
hold off;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
