function demoMP
%DEMO8 medium-scale problem, mesh refinement + optimisation.
%[MP] adapted from DEMO8 and DEMO9 

    filename = mfilename('fullpath');
    filepath = fileparts( filename );

    meshfile = ...
        [filepath,'/poly-data/square.msh'];

   [node,edge] = triread( meshfile );
   
%---------------------------------------------- do mesh-gen.
   hfun = @hfun9 ;
   
   [vert,etri, ...
    tria,tnum] = refine2(node,edge,[],[],hfun);
        
%---------------------------------------------- do mesh-opt.
   [vert,etri, ...
    tria,tnum] = smooth2(vert,etri,tria,tnum) ;
    
    figure;
    patch('faces',tria(:,1:3),'vertices',vert , ...
        'facecolor','w', ...
        'edgecolor','k') ;
    hold on; axis image off;
    title(['MESH-OPT.: KIND=DELFRONT, |TRIA|=', ...
        num2str(size(tria,1))]) ;
    pause;
    %%%%%%%%%%%%%%%%%%%% produce file in ACF format for 2d mesh
    %% uncomment to see the conversion in action 
    %% mesh2acf(vert,tria);
           
end

function [hfun] = hfun9(test)
%HFUN9 user-defined mesh-size function for DEMO9.
%[MP] see hfun6 to see how to modify this 
    hmax = 0.1 ;
    
    hfun = hmax + zeros(size(test(:,1)));
end
