HArD::Core2D
Hybrid Arbitrary Degree::Core 2D - Library to implement 2D schemes with edge and cell polynomials as unknowns
Loading...
Searching...
No Matches
Functions | Variables
generate_cartesian_mesh.m File Reference

Functions

 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)
 

Variables

function generate_cartesian_mesh(domain, N, M) % GENERATE_CARTESIAN_MESH - Generate cartesian mesh for rectangular domain % % INPUTS xmax = domain(2)
 
 ymin = domain(3)
 
 ymax = domain(4)
 
Create grid points x = linspace(xmin, xmax, N+1)
 
 y = linspace(ymin, ymax, M+1)
 
Generate vertices vertices = []
 
 vertex_map = zeros(N+1, M+1)
 
for j
 
 cell_centers = []
 
 v1
 
 v2
 
 v3
 
 v4
 
Cell center center_x = (x(i) + x(i+1)) / 2
 
 center_y = (y(j) + y(j+1)) / 2
 
end end Create filename filename = sprintf('cart%dx%d.typ2', N, M)
 
Write to typ2 file fid = fopen(filename, 'w')
 
for i
 
Plot the mesh figure
 
hold on
 
Set axis properties axis equal
 
Set axis limits with small margin margin_x = (xmax - xmin) * 0.05
 
 margin_y = (ymax - ymin) * 0.05
 
hold off
 
end Example usage
 
end Example Unit square
 

Function Documentation

◆ cells() [1/2]

id cells ( )
virtual

◆ cells() [2/2]

end end Generate cells ( quadrilaterals  )

◆ fclose()

end fclose ( fid  )

◆ fprintf() [1/8]

fprintf ( 'Mesh successfully generated and saved as %s\n'  ,
filename   
)

◆ fprintf() [2/8]

fprintf ( 'Number of cells:%d\n'  ,
size(cells, 1)   
)

◆ fprintf() [3/8]

fprintf ( 'Number of vertices:%d\n'  ,
size(vertices, 1)   
)

◆ fprintf() [4/8]

fprintf ( fid  ,
'%8d\n'  ,
size(cells, 1)   
)

◆ fprintf() [5/8]

fprintf ( fid  ,
'%8d\n'  ,
size(vertices, 1)   
)

◆ fprintf() [6/8]

end Write cells section fprintf ( fid  ,
'cells\n'   
)

◆ fprintf() [7/8]

end Write centers section fprintf ( fid  ,
'centers\n'   
)

◆ fprintf() [8/8]

end Write vertices section fprintf ( fid  ,
'Vertices\n'   
)

◆ generate_cartesian_mesh() [1/2]

Rectangle[0, 2] mesh generate_cartesian_mesh ( ,
 
)

◆ generate_cartesian_mesh() [2/2]

end Example Unit mesh generate_cartesian_mesh ( 10  ,
 
)

◆ legend()

legend ( 'Mesh lines'  ,
'Vertices'  ,
'Cell centers'  ,
'Location'  ,
'best'   
)

◆ Map()

Map ( i  ,
j   
)
pure virtual

◆ plot() [1/2]

Plot cell centers as blue dots plot ( cell_centers(:, 1)  ,
cell_centers(:, 2)  ,
'bo'  ,
'MarkerSize'  ,
,
'MarkerFaceColor'  ,
'blue'   
)

◆ plot() [2/2]

end Plot vertices as red dots plot ( vertices(:, 1)  ,
vertices(:, 2)  ,
'ro'  ,
'MarkerSize'  ,
,
'MarkerFaceColor'  ,
'red'   
)

◆ title()

title ( sprintf( 'Cartesian Mesh %dx%d on Domain[%.2f,%.2f] x[%.2f,%.2f]',... N, M, xmin, xmax, ymin, ymax )

◆ vertex_map()

vertex_map ( i  ,
j   
)

◆ x()

x ( i  )

◆ xlabel()

xlabel ( 'X'  )

◆ xlim()

xlim ( )

◆ y()

y ( j  )

◆ ylabel()

ylabel ( 'Y'  )

◆ ylim()

ylim ( )

Variable Documentation

◆ cell_centers

cell_centers = []

◆ center_x

center_x = (x(i) + x(i+1)) / 2

◆ center_y

center_y = (y(j) + y(j+1)) / 2

◆ equal

Set axis properties axis equal

◆ fid

if fid = fopen(filename, 'w')

◆ figure

Plot the mesh figure

◆ filename

end end Create filename filename = sprintf('cart%dx%d.typ2', N, M)

◆ i

Plot mesh lines for i
Initial value:
= 1:size(vertices, 1)
fprintf(fid, '%20.16f %20.16f \n', vertices(i, 1), vertices(i, 2))
Generate vertices vertices
Definition generate_cartesian_mesh.m:26
Write to typ2 file fid
Definition generate_cartesian_mesh.m:63
for i
Definition generate_cartesian_mesh.m:71
end Write vertices section fprintf(fid, 'Vertices\n')

◆ j

end for j
Initial value:
= 1:M+1
for i = 1:N+1
vertex_count = vertex_count + 1

◆ margin_x

Set axis limits with small margin margin_x = (xmax - xmin) * 0.05

◆ margin_y

margin_y = (ymax - ymin) * 0.05

◆ off

hold off

◆ on

grid on

◆ square

end Example Unit square

◆ usage

end Example usage

◆ v1

v1

◆ v2

v2

◆ v3

v3

◆ v4

v4

◆ vertex_map

i j vertex_map = zeros(N+1, M+1)

◆ vertices

vertices = []

◆ x

Square [-1,1] x[-1, 1] = linspace(xmin, xmax, N+1)

◆ xmax

function generate_cartesian_mesh (domain, N, M) % GENERATE_CARTESIAN_MESH - Generate cartesian mesh for rectangular domain % % INPUTS xmax = domain(2)

◆ y

y = linspace(ymin, ymax, M+1)

◆ ymax

ymax = domain(4)

◆ ymin

ymin = domain(3)