|
| | Map (i, j) to vertex number vertex_count=0 |
| |
| | x (i) |
| |
| | y (j)] |
| |
| | vertex_map (i, j) |
| |
| end end Generate | cells (quadrilaterals) cells |
| |
| id | cells () |
| |
| end Write vertices section | fprintf (fid, 'Vertices\n') |
| |
| | fprintf (fid, '%8d\n', size(vertices, 1)) |
| |
| end Write cells section | fprintf (fid, 'cells\n') |
| |
| | fprintf (fid, '%8d\n', size(cells, 1)) |
| |
| end Write centers section | fprintf (fid, 'centers\n') |
| |
| end | fclose (fid) |
| |
| end Plot vertices as red dots | plot (vertices(:, 1), vertices(:, 2), 'ro', 'MarkerSize', 4, 'MarkerFaceColor', 'red') |
| |
| Plot cell centers as blue dots | plot (cell_centers(:, 1), cell_centers(:, 2), 'bo', 'MarkerSize', 3, 'MarkerFaceColor', 'blue') |
| |
| | xlabel ('X') |
| |
| | ylabel ('Y') |
| |
| | title (sprintf('Cartesian Mesh %dx%d on Domain[%.2f,%.2f] x[%.2f,%.2f]',... N, M, xmin, xmax, ymin, ymax)) |
| |
| | legend ('Mesh lines', 'Vertices', 'Cell centers', 'Location', 'best') |
| |
| | xlim ([xmin - margin_x, xmax+margin_x]) |
| |
| | ylim ([ymin - margin_y, ymax+margin_y]) |
| |
| | fprintf ('Mesh successfully generated and saved as %s\n', filename) |
| |
| | fprintf ('Number of vertices:%d\n', size(vertices, 1)) |
| |
| | fprintf ('Number of cells:%d\n', size(cells, 1)) |
| |
| end Example Unit mesh | generate_cartesian_mesh ([0, 2, 0, 1], 10, 5) |
| |
| Rectangle[0, 2] mesh | generate_cartesian_mesh ([-1, 1, -1, 1], 4, 4) |
| |