Assemble boundary condition contributions
[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) [Q,G,H,R] = assemb(model,___)
[Q,G,H,R] = assemb(b,p,e) assembles
H, and the
be added to the system matrix and contains contributions from mixed
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
sdl have the same meaning as in
You cannot include an
sdl argument in a model with
You can substitute
model, a meshed
PDEModel object, for the (
b describes the boundary conditions of the
PDE problem. For the recommended way of specifying boundary conditions,
see Specify Boundary Conditions Objects. For all methods
of specifying boundary conditions, see Forms of 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:
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.
The notation indicates that the N by 1 matrix with (i,1)-component
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
assemb for assembling the contributions
from the boundary to the matrices
R. The Boundary Condition matrix can also be
saved onto a file as a boundary file for later use with the
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
A boundary segment parameter
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
If you need the tangential vector, it can be expressed using
ny since tx =
–ny and ty = nx.
u (only if the input
u has been specified).
t (only if the input argument
It is not possible to explicitly refer to the time derivative of the solution in the boundary conditions.
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)
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 = x2 – y2
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):
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 ...
lq21, . .
. denote lengths of the MATLAB text expressions, and
. . . 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.
The following example shows you how to find the boundary condition matrices for the Dirichlet boundary condition on the boundary of a circular disk.
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
Create a second function in your working folder that
finds the boundary condition matrices,
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)
Run the function
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
G are all zero sparse
matrices because the problem has only Dirichlet boundary conditions
and neither generalized Neumann nor mixed boundary conditions apply.