2D Geometry with subdomains

Download Im2mesh package https://www.mathworks.com/matlabcentral/fileexchange/71772

Im2mesh package require Matlab Mapping toolbox

Before we start, please set folder "Im2mesh_Matlab" as your current folder of MATLAB.

clearvars

Function bounds2mesh use a mesh generator called MESH2D (developed by Darren Engwirda). We can use the following command to add the folder 'mesh2d-master' to the path of MATLAB.

addpath(genpath('mesh2d-master'))

Create polyshape

% square1
vertex1 = 12*[ 0 0; 1 0; 1 1; 0 1 ];
psSq1 = polyshape(vertex1);

% square2
vertex2 = [ 1 2; 3 2; 2 4; 3 6; 2 8; 3 10; 1 10; 1 2];
psSq2 = polyshape(vertex2);

figure
hold on; axis equal
plot(psSq1);
plot(psSq2);
hold off

Remove overlap

psSq1 = subtract(psSq1, psSq2);

figure
hold on; axis equal
plot(psSq1);
plot(psSq2);
hold off

Convert to a nested cell array of polygons

psCell = {psSq1; psSq2};

bounds = polyshape2bound(psCell);
tol_intersect = 1e-6;
bounds = addIntersectPnts( bounds, tol_intersect );

% plot boundaries and show all vertices
plotBounds(bounds,false,'ko-')

Generate mesh

hmax = 2;
grad_limit = 0.25;
opt = [];
opt.disp = inf;     % silence verbosity

[vert,tria,tnum,vert2,tria2] = bounds2mesh( bounds, hmax, grad_limit, opt );
plotMeshes(vert,tria,tnum);

Create matlab pde model object

% linear model
model_linear = createpde();
geometryFromMesh( model_linear, vert', tria', tnum' );

% qudratic model
model_quad = createpde();
geometryFromMesh( model_quad, vert2', tria2', tnum' );

show geometry

pdegplot(model_quad, 'EdgeLabels','on','VertexLabels','on', 'FaceLabels','on' )

Show mesh

pdemesh( model_quad )

end