Main Content

poimesh

(Not recommended) Generate regular mesh on rectangular geometry

poimesh is not recommended. To solve Poisson's equations, use solvepde. For details, see Solve Problems Using PDEModel Objects.

Description

[p,e,t] = poimesh(g,nx,ny) constructs a regular mesh on the rectangular geometry by dividing the rectangle into nx pieces along the x-direction and ny pieces along the y-direction, thus resulting in (nx + 1)*(ny + 1) nodes in the domain. The x-direction is the direction along the edge that makes the smallest angle with the x-axis.

For best performance with poisolv, the larger of nx and ny must be a power of 2.

If g is not a rectangle, poimesh returns p as zero.

example

[p,e,t] = poimesh(g,n) divides each edge into n pieces, that is, nx = ny = n.

[p,e,t] = poimesh(g) uses the value nx = ny = n = 1.

Examples

collapse all

Solve the Poisson's equation -Δu=3x2 on a square domain with Dirichlet boundary conditions using the poisolv function.

Create a model object and include the square geometry created using the squareg function.

model = createpde;
g = @squareg;
geometryFromEdges(model,g);

Plot the geometry with the edge labels.

pdegplot(model,"EdgeLabels","on")
axis([-1.1 1.1 -1.1 1.1])

Apply the following Dirichlet boundary conditions. The solution is 0.2cos(πy/2) on the right boundary (edge 2) and zero on all other boundaries.

innerBC = @(region,state) 0.2*cos(pi/2*region.y);
applyBoundaryCondition(model,"Dirichlet","Edge",2,"u",innerBC);
applyBoundaryCondition(model,"Dirichlet","Edge",[1 3 4],"u",0);

The fast Poisson solver requires a regular rectangular grid. Use the poimesh function to generate a mesh meeting this requirement. Plot the mesh.

[p,e,t] = poimesh(g,16);
figure; 
pdemesh(p,e,t); 
axis equal

Specify the PDE coefficients.

c = 1;
a = 0;
f = '3*x.^2';

Solve the equation on different meshes using the poisolv function.

for n = [16 32 64 128 256 512]
    [p,e,t] = poimesh(g,n);
    tic;
      u = poisolv(model,p,e,t,f);
    tfast = toc;
    fprintf('%-5d|%15.5g\n',n,tfast);
end
16   |         1.4453
32   |        0.23712
64   |        0.21723
128  |        0.25723
256  |        0.64698
512  |        0.98339

Plot the solution on the finest mesh.

figure;
pdeplot(p,[],t,"XYData",u,"ZData",u)

Input Arguments

collapse all

Rectangular geometry, specified as a decomposed geometry matrix, a geometry function, or a handle to the geometry function. For details about a decomposed geometry matrix, see decsg. For details about geometry functions, see Parametrized Function for 2-D Geometry Creation.

A geometry function must return the same result for the same input arguments in every function call. Thus, it must not contain functions and expressions designed to return a variety of results, such as random number generators.

If g is not a rectangle, poimesh returns p as zero.

Data Types: double | char | string | function_handle

Number of divisions along the x-direction, specified as a positive integer.

Data Types: double

Number of divisions along the y-direction, specified as a positive integer.

Data Types: double

Number of divisions along both the x- and y-direction, specified as a positive integer. In this case, both the x- and y-edges are divided into the same number of pieces.

Data Types: double

Output Arguments

collapse all

Mesh points, returned as a 2-by-Np matrix of points, where Np is the number of points in the mesh. For details on the mesh data representation, see initmesh.

Data Types: double

Mesh edges, returned as a 7-by-Ne matrix of edges, where Ne is the number of edges in the mesh. For details on the mesh data representation, see initmesh.

Data Types: double

Mesh triangles, returned as a 4-by-Nt matrix of triangles, where Nt is the number of triangles in the mesh. For details on the mesh data representation, see initmesh.

Data Types: double

Version History

Introduced before R2006a

collapse all

R2016a: Not recommended

poimesh is not recommended. To solve Poisson's equations, use solvepde. For details, see Solve Problems Using PDEModel Objects. There are no plans to remove poimesh.