# Documentation

### This is machine translation

Translated by
Mouse over text to see original. Click the button below to return to the English verison of the page.

# assemb

Assemble boundary condition contributions

assemb is not recommended. Use assembleFEMatrices instead.

## Syntax

• [Q,G,H,R] = assemb(model)
example
• [Q,G,H,R] = assemb(b,p,e)
example
• [Q,G,H,R] = assemb(___,[],sdl)

## Description

example

[Q,G,H,R] = assemb(model) assembles the matrices Q and H, and the vectors G and R. Q should be added to the system matrix and contains contributions from mixed boundary conditions.

example

[Q,G,H,R] = assemb(b,p,e) assembles the matrices based on the boundary conditions specified in b and the mesh data in p and e.
[Q,G,H,R] = assemb(___,[],sdl), for any of the previous input arguments, 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.

## Examples

collapse all

Assemble the boundary condition matrices for an elliptic PDE.

The PDE is Poisson's equation,

 

Partial Differential Equation Toolbox™ solves equations of the form

 

So, represent Poisson's equation in toolbox syntax by setting c = 1, a = 0, and f = 1.

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

Create a PDE model container. Import the ForearmLink.stl file into the model and examine the geometry.

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

Set zero Dirichlet boundary conditions on the narrow faces (numbered 1 through 4).

applyBoundaryCondition(model,'Face',1:4,'u',0); 

Set a Neumann condition with g = -1 on face 6, and g = 1 on face 5.

applyBoundaryCondition(model,'Face',6,'g',-1); applyBoundaryCondition(model,'Face',5,'g',1); 

Create a mesh for the model.

generateMesh(model); 

Create the boundary condition matrices for the model.

[Q,G,H,R] = assemb(model); 

The H matrix is quite sparse. The Q matrix has no nonzero entries.

disp(['Fraction of nonzero entries in H is ',num2str(nnz(H)/numel(H))]) disp(['Number of nonzero entries in Q is ',num2str(nnz(Q))]) 
Fraction of nonzero entries in H is 3.4709e-05 Number of nonzero entries in Q is 0 

Assemble boundary condition matrices for the 2-D L-shaped region with Dirichlet boundary conditions, using the [p,e,t] mesh representation.

Define the geometry and boundary conditions using functions included in your software.

g = @lshapeg; b = @lshapeb; 

Create a mesh for the geometry.

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

Create the boundary matrices.

[Q,G,H,R] = assemb(b,p,e); 

Only one of the resulting matrices is nonzero, namely H. The H matrix is quite sparse.

disp(['Fraction of nonzero entries in H is ',num2str(nnz(H)/numel(H))]) 
Fraction of nonzero entries in H is 0.0066667 

## Input Arguments

collapse all

PDE model, specified as a PDEModel object.

Example: model = createpde(1)

Boundary conditions, specified as a boundary matrix or boundary file. Pass a boundary file as a function handle or as a file name.

Example: b = 'circleb1' or equivalently b = @circleb1

Data Types: double | char | 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.

Typically, you use the p, e, and t data exported from the PDE 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.

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

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

Data Types: double

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

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 assempde.

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

Typically, you use R in a subsequent call to assempde.

collapse all

### Algorithms

As explained in Elliptic Equations, the finite element matrices and vectors correspond to the reduced linear system and are the following.

• Q is the integral of the q boundary condition against the basis functions.

• G is the integral of the g boundary condition against the basis functions.

• H is the Dirichlet condition matrix representing hu = r.

• R is the Dirichlet condition vector for Hu = R.

For more information on the reduced linear system form of the finite element matrices, see the assempde Definitions section, and the linear algebra approach detailed in Systems of PDEs.