Main Content

assempde

(Not recommended) Assemble finite element matrices and solve elliptic PDE

assempde is not recommended. Use solvepde instead.

Description

u = assempde(model,c,a,f) solves the PDE

(cu)+au=f

with geometry, boundary conditions, and finite element mesh in model, and coefficients c, a, and f. If the PDE is a system of equations (model.PDESystemSize > 1), then assempde solves the system of equations

(cu)+au=f

example

u = assempde(b,p,e,t,c,a,f) solves the PDE with boundary conditions b, and finite element mesh (p,e,t).

example

[Kc,Fc,B,ud] = assempde(___), for any of the previous input syntaxes, assembles finite element matrices using the reduced linear system form, which eliminates any Dirichlet boundary conditions from the system of linear equations. You can calculate the solution u at node points by the command u = B*(Kc\Fc) + ud. See Reduced Linear System.

example

[Ks,Fs] = assempde(___) assembles finite element matrices that represent any Dirichlet boundary conditions using a stiff-spring approximation. You can calculate the solution u at node points by the command u = Ks\Fs. See Stiff-Spring Approximation.

example

[K,M,F,Q,G,H,R] = assempde(___) assembles finite element matrices that represent the PDE problem. This syntax returns all the matrices involved in converting the problem to finite element form. See Algorithms.

example

[K,M,F,Q,G,H,R] = assempde(___,[],sdl) restricts the finite element matrices to those that include the subdomain specified by the subdomain labels in sdl. The empty argument is required in this syntax for historic and compatibility reasons.

u = assempde(K,M,F,Q,G,H,R) returns the solution u based on the full collection of finite element matrices.

example

[Ks,Fs] = assempde(K,M,F,Q,G,H,R) returns finite element matrices that approximate Dirichlet boundary conditions using the stiff-spring approximation. See Algorithms.

[Kc,Fc,B,ud] = assempde(K,M,F,Q,G,H,R) returns finite element matrices that eliminate any Dirichlet boundary conditions from the system of linear equations. See Algorithms.

Examples

collapse all

Solve an elliptic PDE on an L-shaped region.

Create a scalar PDE model. Incorporate the geometry of an L-shaped region.

model = createpde;
geometryFromEdges(model,@lshapeg);

Apply zero Dirichlet boundary conditions to all edges.

applyBoundaryCondition(model,Edge=1:model.Geometry.NumEdges, ...
                       u=0,InternalBC=true);

Generate a finite element mesh.

generateMesh(model,GeometricOrder="linear");

Solve the PDE -(cu)+au=f with parameters c = 1, a = 0, and f = 5.

c = 1;
a = 0;
f = 5;
u = assempde(model,c,a,f);

Plot the solution.

pdeplot(model,XYData=u)
axis equal

Figure contains an axes object. The axes object contains an object of type patch.

Solve a 3-D elliptic PDE using a PDE model.

Create a PDE model container, import a 3-D geometry description, and view the geometry.

model = createpde;
importGeometry(model,'Block.stl');
pdegplot(model,FaceAlpha=0.5, ...
               FaceLabels="on")

Figure contains an axes object. The axes object contains 6 objects of type quiver, text, patch, line.

Set zero Dirichlet conditions on faces 1 through 4 (the edges). Set Neumann conditions with g = -1 on face 6 and g = 1 on face 5.

applyBoundaryCondition(model,Face=1:4, ...
                             u=0);
applyBoundaryCondition(model,Face=6, ...
                             g=-1);
applyBoundaryCondition(model,Face=5, ...
                             g=1);

Set coefficients c = 1, a = 0, and f = 0.1.

c = 1;
a = 0;
f = 0.1;

Create a mesh and solve the problem.

msh = generateMesh(model);
u = assempde(model,c,a,f);

Plot the solution on the surface.

pdeplot3D(msh,ColorMapData=u)

Figure contains an axes object. The hidden axes object contains 5 objects of type patch, quiver, text.

Solve a 2-D PDE using the older syntax for mesh.

Create a circle geometry.

g = @circleg;

Set zero Dirichlet boundary conditions.

b = @circleb1;

Create a mesh for the geometry.

[p,e,t] = initmesh(g);

Solve the PDE -(cu)+au=f with parameters c = 1, a = 0, and f = sin(x).

c = 1;
a = 0;
f = 'sin(x)';
u = assempde(b,p,e,t,c,a,f);

Plot the solution.

pdeplot(p,e,t,XYData=u)
axis equal

Figure contains an axes object. The axes object contains an object of type patch.

Obtain the finite-element matrices that represent the problem using a reduced linear algebra representation of Dirichlet boundary conditions.

Create a scalar PDE model. Import a simple 3-D geometry.

model = createpde;
importGeometry(model,"Block.stl");

Set zero Dirichlet boundary conditions on all the geometry faces.

applyBoundaryCondition(model,"dirichlet", ...
                             Face=1:model.Geometry.NumFaces, ...
                             u=0);

Generate a mesh for the geometry.

generateMesh(model);

Obtain finite element matrices K, F, B, and ud that represent the equation -(cu)+au=f with parameters c=1, a=0, and f=log(1+x+y1+z).

c = 1;
a = 0;
f = 'log(1+x+y./(1+z))';
[K,F,B,ud] = assempde(model,c,a,f);

You can obtain the solution u of the PDE at mesh nodes by executing the command

u = B*(K\F) + ud;

Generally, this solution is slightly more accurate than the stiff-spring solution, as calculated in the next example.

Obtain the stiff-spring approximation of finite element matrices.

Create a scalar PDE model. Import a simple 3-D geometry.

model = createpde;
importGeometry(model,"Block.stl");

Set zero Dirichlet boundary conditions on all the geometry faces.

applyBoundaryCondition(model,Face=1:model.Geometry.NumFaces,u=0);

Generate a mesh for the geometry.

generateMesh(model);

Obtain finite element matrices Ks and Fs that represent the equation -(cu)+au=f with parameters c=1, a=0, and f=log(1+x+y1+z).

c = 1;
a = 0;
f = "log(1+x+y./(1+z))";
[Ks,Fs] = assempde(model,c,a,f);

You can obtain the solution u of the PDE at mesh nodes by executing the command

u = Ks\Fs;

Generally, this solution is slightly less accurate than the reduced linear algebra solution, as calculated in the previous example.

Obtain the full collection of finite element matrices for an elliptic problem.

Import geometry and set up an elliptic problem with Dirichlet boundary conditions. The Torus.stl geometry has only one face, so you need set only one boundary condition.

model = createpde();
importGeometry(model,"Torus.stl");
applyBoundaryCondition(model,Face=1,u=0);
c = 1;
a = 0;
f = 1;
generateMesh(model);

Create the finite element matrices that represent this problem.

[K,M,F,Q,G,H,R] = ...
assempde(model,c,a,f);

Most of the resulting matrices are quite sparse. G, M, Q, and R are all zero sparse matrices.

howsparse = @(x)nnz(x)/numel(x);
disp(['Maximum fraction of nonzero' ...
      ' entries in K or H is ',...
      num2str(max(howsparse(K),howsparse(H)))])
Maximum fraction of nonzero entries in K or H is 0.0019281

To find the solution to the PDE, call assempde again.

u = assempde(K,M,F,Q,G,H,R);

Input Arguments

collapse all

PDE model, specified as a PDEModel object.

Example: model = createpde

PDE coefficient, specified as a scalar, matrix, character vector, character array, string scalar, string vector, or coefficient function. c represents the c coefficient in the scalar PDE

(cu)+au=f

or in the system of PDEs

(cu)+au=f

Example: 'cosh(x+y.^2)'

Data Types: double | char | string | function_handle
Complex Number Support: Yes

PDE coefficient, specified as a scalar, matrix, character vector, character array, string scalar, string vector, or coefficient function. a represents the a coefficient in the scalar PDE

(cu)+au=f

or in the system of PDEs

(cu)+au=f

Example: 2*eye(3)

Data Types: double | char | string | function_handle
Complex Number Support: Yes

PDE coefficient, specified as a scalar, matrix, character vector, character array, string scalar, string vector, or coefficient function. f represents the f coefficient in the scalar PDE

(cu)+au=f

or in the system of PDEs

(cu)+au=f

Example: char('sin(x)';'cos(y)';'tan(z)')

Data Types: double | char | string | function_handle
Complex Number Support: Yes

Boundary conditions, specified as a boundary matrix or boundary file. Pass a boundary file as a function handle or as a file name. A boundary matrix is generally an export from the PDE Modeler app.

Example: b = 'circleb1', b = "circleb1", or b = @circleb1

Data Types: double | char | string | function_handle

Mesh points, specified as a 2-by-Np matrix of points, where Np is the number of points in the mesh. For a description of the (p,e,t) matrices, see Mesh Data as [p,e,t] Triples.

Typically, you use the p, e, and t data exported from the PDE Modeler app, or generated by initmesh or refinemesh.

Example: [p,e,t] = initmesh(gd)

Data Types: double

Mesh edges, specified as a 7-by-Ne matrix of edges, where Ne is the number of edges in the mesh. For a description of the (p,e,t) matrices, see Mesh Data as [p,e,t] Triples.

Typically, you use the p, e, and t data exported from the PDE Modeler app, or generated by initmesh or refinemesh.

Example: [p,e,t] = initmesh(gd)

Data Types: double

Mesh triangles, specified as a 4-by-Nt matrix of triangles, where Nt is the number of triangles in the mesh. For a description of the (p,e,t) matrices, see Mesh Data as [p,e,t] Triples.

Typically, you use the p, e, and t data exported from the PDE Modeler app, or generated by initmesh or refinemesh.

Example: [p,e,t] = initmesh(gd)

Data Types: double

Stiffness matrix, specified as a sparse matrix or full matrix. Generally, you obtain K from a previous call to assema or assempde. For the meaning of stiffness matrix, see Elliptic Equations.

Example: [K,M,F,Q,G,H,R] = assempde(model,c,a,f)

Data Types: double
Complex Number Support: Yes

Mass matrix, specified as a sparse matrix or full matrix. Generally, you obtain M from a previous call to assema or assempde. For the meaning of mass matrix, see Elliptic Equations.

Example: [K,M,F,Q,G,H,R] = assempde(model,c,a,f)

Data Types: double
Complex Number Support: Yes

Finite element f representation, specified as a vector. Generally, you obtain F from a previous call to assema or assempde. For the meaning of this representation, see Elliptic Equations.

Example: [K,M,F,Q,G,H,R] = assempde(model,c,a,f)

Data Types: double
Complex Number Support: Yes

Neumann boundary condition matrix, specified as a sparse matrix or full matrix. Generally, you obtain Q from a previous call to assemb or assempde. For the meaning of this matrix, see Elliptic Equations.

Example: [K,M,F,Q,G,H,R] = assempde(model,c,a,f)

Data Types: double
Complex Number Support: Yes

Neumann boundary condition vector, specified as a sparse vector or full vector. Generally, you obtain G from a previous call to assemb or assempde. For the meaning of this vector, see Elliptic Equations.

Example: [K,M,F,Q,G,H,R] = assempde(model,c,a,f)

Data Types: double
Complex Number Support: Yes

Dirichlet boundary condition matrix, specified as a sparse matrix or full matrix. Generally, you obtain H from a previous call to assemb or assempde. For the meaning of this matrix, see Algorithms.

Example: [K,M,F,Q,G,H,R] = assempde(model,c,a,f)

Data Types: double
Complex Number Support: Yes

Dirichlet boundary condition vector, specified as a sparse vector or full vector. Generally, you obtain R from a previous call to assemb or assempde. For the meaning of this vector, see Algorithms.

Example: [K,M,F,Q,G,H,R] = assempde(model,c,a,f)

Data Types: double
Complex Number Support: Yes

Subdomain labels, specified as a vector of positive integers. For 2-D geometry only. View the subdomain labels in your geometry using the command

pdegplot(g,'SubdomainLabels','on')

Example: sdl = [1,3:5];

Data Types: double

Output Arguments

collapse all

PDE solution, returned as a vector.

  • If the PDE is scalar, meaning only one equation, then u is a column vector representing the solution u at each node in the mesh. u(i) is the solution at the ith column of model.Mesh.Nodes or the ith column of p.

  • If the PDE is a system of N > 1 equations, then u is a column vector with N*Np elements, where Np is the number of nodes in the mesh. The first Np elements of u represent the solution of equation 1, then next Np elements represent the solution of equation 2, etc.

To obtain the solution at an arbitrary point in the geometry, use pdeInterpolant.

Stiffness matrix, returned as a sparse matrix. See Elliptic Equations.

u1 = Kc\Fc returns the solution on the non-Dirichlet points. To obtain the solution u at the nodes of the mesh,

u = B*(Kc\Fc) + ud

Generally, Kc, Fc, B, and ud make a slower but more accurate solution than Ks and Fs.

Load vector, returned as a vector. See Elliptic Equations.

u = B*(Kc\Fc) + ud

Generally, Kc, Fc, B, and ud make a slower but more accurate solution than Ks and Fs.

Dirichlet nullspace, returned as a sparse matrix. See Algorithms.

u = B*(Kc\Fc) + ud

Generally, Kc, Fc, B, and ud make a slower but more accurate solution than Ks and Fs.

Dirichlet vector, returned as a vector. See Algorithms.

u = B*(Kc\Fc) + ud

Generally, Kc, Fc, B, and ud make a slower but more accurate solution than Ks and Fs.

Finite element matrix for stiff-spring approximation, returned as a sparse matrix. See Algorithms.

To obtain the solution u at the nodes of the mesh,

u = Ks\Fs.

Generally, Ks and Fs make a quicker but less accurate solution than Kc, Fc, B, and ud.

Load vector corresponding to the stiff-spring approximation for Dirichlet boundary condition, returned as a vector. See Algorithms.

To obtain the solution u at the nodes of the mesh,

u = Ks\Fs.

Generally, Ks and Fs make a quicker but less accurate solution than Kc, Fc, B, and ud.

Stiffness matrix, returned as a sparse matrix. See Elliptic Equations.

K represents the stiffness matrix alone, unlike Kc or Ks, which are stiffness matrices combined with other terms to enable immediate solution of a PDE.

Typically, you use K in a subsequent call to a solver such as assempde or hyperbolic.

Mass matrix. returned as a sparse matrix. See Elliptic Equations.

Typically, you use M in a subsequent call to a solver such as assempde or hyperbolic.

Load vector, returned as a vector. See Elliptic Equations.

F represents the load vector alone, unlike Fc or Fs, which are load vectors combined with other terms to enable immediate solution of a PDE.

Typically, you use F in a subsequent call to a solver such as assempde or hyperbolic.

Neumann boundary condition matrix, returned as a sparse matrix. See Elliptic Equations.

Typically, you use Q in a subsequent call to a solver such as assempde or hyperbolic.

Neumann boundary condition vector, returned as a sparse vector. See Elliptic Equations.

Typically, you use G in a subsequent call to a solver such as assempde or hyperbolic.

Dirichlet matrix, returned as a sparse matrix. See Algorithms.

Typically, you use H in a subsequent call to a solver such as assempde or hyperbolic.

Dirichlet vector, returned as a sparse vector. See Algorithms.

Typically, you use R in a subsequent call to a solver such as assempde or hyperbolic.

More About

collapse all

Algorithms

collapse all

Version History

Introduced before R2006a

collapse all