Accelerating the pace of engineering and science

# assemb

Assemble boundary condition contributions

## Syntax

```[Q,G,H,R] = assemb(b,p,e)
[Q,G,H,R] = assemb(b,p,e,u0)
[Q,G,H,R] = assemb(b,p,e,u0,time)
[Q,G,H,R] = assemb(b,p,e,u0,time,sdl)
[Q,G,H,R] = assemb(b,p,e,time)
[Q,G,H,R] = assemb(b,p,e,time,sdl)
```

## Description

[Q,G,H,R] = assemb(b,p,e) 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. G should be added to the right side and contains contributions from generalized Neumann and mixed boundary conditions. The equation H*u = R represents the Dirichlet type boundary conditions.

The input parameters p, e, u0, time, and sdl have the same meaning as in assempde.

b describes the boundary conditions of the PDE problem. For the recommended way of specifying boundary conditions, see Steps to Specify a Boundary Conditions Object. For all methods of specifying boundary conditions, see Boundary Condition Specification.

The format of the Boundary Condition matrix is described further in this section.

Partial Differential Equation Toolbox™ software treats the following boundary condition types:

• On a generalized Neumann boundary segment, q and g are related to the normal derivative value by:

$n\text{\hspace{0.17em}}·\text{\hspace{0.17em}}\left(c\otimes \nabla u\right)+qu=g$

• On a Dirichlet boundary segment, hu = r.

The software can also handle systems of partial differential equations over the domain Ω. Let the number of variables in the system be N. The general boundary condition is hu = r.

$n\text{\hspace{0.17em}}·\text{\hspace{0.17em}}\left(c\otimes \nabla u\right)+qu=g+{h}^{\prime }\mu .$

The notation $n\text{\hspace{0.17em}}·\text{\hspace{0.17em}}\left(c\otimes \nabla u\right)$ indicates that the N by 1 matrix with (i,1)-component

$\sum _{j=1}^{N}\left(\mathrm{cos}\left(\alpha \right){c}_{i,j,1,1}\frac{\partial }{\partial x}+\mathrm{cos}\left(\alpha \right){c}_{i,j,1,2}\frac{\partial }{\partial y}+\mathrm{sin}\left(\alpha \right){c}_{i,j,2,1}\frac{\partial }{\partial x}+\mathrm{sin}\left(\alpha \right){c}_{i,j,2,2}\frac{\partial }{\partial y}\right)\text{\hspace{0.17em}}u$

where α is the angle of the normal vector of the boundary, pointing in the direction out from Ω, the domain.

The Boundary Condition matrix is created internally in the PDE app (actually a function called by the PDE app) and then used from the function assemb for assembling the contributions from the boundary to the matrices Q, G, H, and R. The Boundary Condition matrix can also be saved onto a file as a boundary file for later use with the wbound function.

For each column in the Decomposed Geometry matrix there must be a corresponding column in the Boundary Condition matrix. The format of each column is according to the following list:

• Row one contains the dimension N of the system.

• Row two contains the number M of Dirichlet boundary conditions.

• Row three to 3 + N2 – 1 contain the lengths for the strings representing q. The lengths are stored in column-wise order with respect to q.

• Row 3 + N2 to 3 + N2 +N – 1 contain the lengths for the strings representing g.

• Row 3 + N2 + N to 3 + N2 + N + MN – 1 contain the lengths for the strings representing h. The lengths are stored in columnwise order with respect to h.

• Row 3 + N2 + N + MN to 3 + N2 + N + MN + M – 1 contain the lengths for the strings representing r.

The following rows contain text expressions representing the actual boundary condition functions. The text strings have the lengths according to above. The MATLAB® text expressions are stored in columnwise order with respect to matrices h and q. There are no separation characters between the strings. You can insert MATLAB expressions containing the following variables:

• The 2-D coordinates x and y.

• A boundary segment parameter s, proportional to arc length. s is 0 at the start of the boundary segment and increases to 1 along the boundary segment in the direction indicated by the arrow.

• The outward normal vector components nx and ny. If you need the tangential vector, it can be expressed using nx and ny since tx = –ny and ty = nx.

• The solution u (only if the input argument u has been specified).

• The time t (only if the input argument time has been specified).

It is not possible to explicitly refer to the time derivative of the solution in the boundary conditions.

## Examples

### Example 1

The following examples describe the format of the boundary condition matrix for one column of the Decomposed Geometry matrix. For a boundary in a scalar PDE (N = 1) with Neumann boundary condition (M = 0)

$n\text{\hspace{0.17em}}·\text{\hspace{0.17em}}\left(c\nabla u\right)=-{x}^{2}$

the boundary condition would be represented by the column vector

`[1 0 1 5 '0' '-x.^2']' `

No lengths are stored for h or r.

Also for a scalar PDE, the Dirichlet boundary condition

u = x2y2

is stored in the column vector

`[1 1 1 1 1 9 '0' '0' '1' 'x.^2-y.^2']' `

For a system (N = 2) with mixed boundary conditions (M = 1):

$\begin{array}{c}\left(\begin{array}{cc}{h}_{11}& {h}_{12}\end{array}\right)u={r}_{1}\\ n\text{\hspace{0.17em}}·\text{\hspace{0.17em}}\left(c\otimes \nabla u\right)+\left(\begin{array}{cc}{q}_{11}& {q}_{12}\\ {q}_{21}& {q}_{22}\end{array}\right)u=\left(\begin{array}{c}{g}_{1}\\ {g}_{2}\end{array}\right)+s\end{array}$

the column appears similar to the following example:

```2
1
lq11
lq21
lq12
lq22
lg1
lg2
lh11
lh12
lr1
q11 ...
q21 ...
q12 ...
q22 ...
g1 ...
g2 ...
h11 ...
h12 ...
r1 ...```

Where lq11, lq21, . . . denote lengths of the MATLAB text expressions, and q11, q21, . . . denote the actual expressions.

You can easily create your own examples by trying out the PDE app. Enter boundary conditions by double-clicking on boundaries in boundary mode, and then export the Boundary Condition matrix to the MATLAB workspace by selecting the Export Decomposed Geometry, Boundary Cond's option from the Boundary menu.

### Example 2

The following example shows you how to find the boundary condition matrices for the Dirichlet boundary condition $u={x}^{2}-{y}^{2}$ on the boundary of a circular disk.

1. Create the following function in your working folder:

```function [x,y] = circ_geom(bs,s)
%CIRC_GEOM Creates a geometry file for a unit circle.

% Number of boundary segments
nbs = 4;

if nargin == 0 % Number of boundary segments
x = nbs;
elseif nargin == 1 % Create 4 boundary segments
dl = [0     pi/2  pi      3*pi/2
pi/2  pi    3*pi/2  2*pi
1     1     1       1
0     0     0       0];
x = dl(:,bs);

else % Coordinates of edge segment points
z = exp(i*s);
x = real(z);
y = imag(z);
end```
2. Create a second function in your working folder that finds the boundary condition matrices, Q, G, H, and R:

```function assemb_example
% Use ASSEMB to find the boundary condition matrices.

% Describe the geometry using four boundary segments
figure(1)
pdegplot('circ_geom')
axis equal

% Initialize the mesh
[p,e,t] = initmesh('circ_geom','Hmax',0.4);
figure(2)

% Plot the mesh
pdemesh(p,e,t)
axis equal

% Define the boundary condition vector, b,
% for the boundary condition u = x^2-y^2.
% For each boundary segment, the boundary
% condition vector is
b = [1 1 1 1 1 9 '0' '0' '1' 'x.^2-y.^2']';

% Create a boundary condition matrix that
% represents all of the boundary segments.
b = repmat(b,1,4);

% Use ASSEMB to find the boundary condition
% matrices. Since there are only Dirichlet
% boundary conditions, Q and G are empty.
[Q,G,H,R] = assemb(b,p,e)```
3. Run the function assemb_example.m.

The function returns the four boundary condition matrices.

```Q =

All zero sparse: 41-by-41

G =

All zero sparse: 41-by-1

H =

(1,1)        1
(2,2)        1
(3,3)        1
(4,4)        1
(5,5)        1
(6,6)        1
(7,7)        1
(8,8)        1
(9,9)        1
(10,10)       1
(11,11)       1
(12,12)       1
(13,13)       1
(14,14)       1
(15,15)       1
(16,16)       1

R =

(1,1)       1.0000
(2,1)      -1.0000
(3,1)       1.0000
(4,1)      -1.0000
(5,1)       0.0000
(6,1)      -0.0000
(7,1)       0.0000
(8,1)      -0.0000
(9,1)       0.7071
(10,1)      -0.7071
(11,1)      -0.7071
(12,1)       0.7071
(13,1)       0.7071
(14,1)      -0.7071
(15,1)      -0.7071
(16,1)       0.7071```

Q and G are all zero sparse matrices because the problem has only Dirichlet boundary conditions and neither generalized Neumann nor mixed boundary conditions apply.

## See Also

Was this topic helpful?