Accelerating the pace of engineering and science

# pdebound

Write custom function for defining boundary conditions

## Syntax

```[qmatrix,gmatrix,hmatrix,rmatrix] = pdebound(p,e,u,time)
```

## Description

The Boundary file specifies the boundary conditions of a PDE problem.

The most general form of boundary conditions that we can handle is

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

By the notation $n\text{\hspace{0.17em}}·\text{\hspace{0.17em}}\left(c\otimes \nabla u\right)$ we mean the N-by-1 matrix, where N is the dimension of the system, 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}_{j,}$

where the outward normal vector of the boundary $n=\left(\mathrm{cos}\left(\alpha \right),\mathrm{sin}\left(\alpha \right)\right)$. There are M Dirichlet conditions and the h-matrix is M-by-N, M ≥ 0. The generalized Neumann condition contains a source ${h}^{\prime }\mu$ where the Lagrange multipliers µ is computed such that the Dirichlet conditions become satisfied.

The data that you specify is q, g, h, and r.

For M = 0 we say that we have a generalized Neumann boundary condition, for M = N a Dirichlet boundary condition, and for 0 < M < N a mixed boundary condition.

The Boundary file [qmatrix,gmatrix,hmatrix,rmatrix] = pdebound(p,e,u,time) computes the values of q, g, h, and r, on the a set of edges e.

The matrices p and e are mesh data. e needs only to be a subset of the edges in the mesh. Details on the mesh data representation can be found in the entry on initmesh.

The input arguments u and time are used for the nonlinear solver and time stepping algorithms, respectively. u and time are empty matrices if the corresponding parameter is not passed to assemb. If time is NaN and any of the function q, g, h, and r depends on time, pdebound must return a matrix of correct size, containing NaNs in all positions, in the corresponding output argument. It is not possible to explicitly refer to the time derivative of the solution in the boundary conditions.

Similarly, if an output argument depends on u, then the output argument must return a matrix of NaN of the correct size if the input u is NaN. This requirement signals to the solver, such a parabolic or hyperbolic, that the argument depends on time or the solution u.

The solution u is represented by the solution vector u. Details on the representation can be found in the entry on assempde.

qmatrix and gmatrix must contain the value of q and g on the midpoint of each boundary. Thus we have size(qmatrix) = [N^2 ne], where N is the dimension of the system, and ne the number of edges in e, and size(gmatrix) = [N ne]. For the Dirichlet case, the corresponding values must be zeros.

hmatrix and rmatrix must contain the values of h and r at the first point on each edge followed by the value at the second point on each edge. Thus we have size(hmatrix) = [N^2 2*ne], where N is the dimension of the system, and ne the number of edges in e, and size(rmatrix) = [N 2*ne]. When M < N, h and r must be padded with NM rows of zeros.

The elements of the matrices q and h are stored in column-wise ordering in the MATLAB® matrices qmatrix and hmatrix.

## Examples

For the boundary conditions

$\begin{array}{c}\left(\begin{array}{cc}1& -1\end{array}\right)u=2\\ n\text{\hspace{0.17em}}\cdot \text{\hspace{0.17em}}\left(c\otimes \nabla u\right)+\left(\begin{array}{cc}1& 2\\ 2& 0\end{array}\right)u=\left(\begin{array}{c}3\\ 4\end{array}\right)+{h}^{\prime }\mu \end{array}$

the following values should be stored in qmatrix, gmatrix, hmatrix, and rmatrix

```                1
qmatrix = [ ... 2 ... ]
2
0

gmatrix = [ ... 3 ... ]
4

1     1
hmatrix = [ ... 0 ... 0 ... ]
-1    -1
0     0

rmatrix = [ ... 2 ... 2 ... ]
0     0```