I am writing a code for steady state heat transfer on a rectangular domain. I am specifying temperature on the edges - nonzero Dirichlet boundary condition. The equations can be written in form of

$$KT=Q$$ $K$ is conductivity matrix, $T$ is unknown nodal temperature vector, and $Q$ is thermal load vector consisting of internal heat generation. For example, the system can look like

$$\begin {bmatrix} K_{11} & K_{12} & K_{13} & \dots & K_{1N}\\ K_{21} & K_{22} & K_{23} & \dots & K_{2N}\\ \vdots\\ K_{N1} & K_{N2} & K_{N3} & \dots & K_{NN} \end{bmatrix} \begin {bmatrix} 100\\ 200\\ \vdots\\ T_N \end{bmatrix} = \begin {bmatrix} Q_1\\ Q_2\\ \vdots\\ Q_N \end{bmatrix} $$

Non zero temperatures are applied on the edges of the rectangular domain (non-homogeneous Dirichlet boundary condition). How can I handle computationally non-zero Dirichlet boundary condition to solve for unknown temperature vector?


Consider the fact that your linear system can be broken up into two parts: the equations that correspond to the known Dirichlet dofs, and the equations that correspond to the unknown dofs. For the sake of convenience, let's say that your unknown vector is broken up so the first $k$ values of $T$ are known, and the remainder are unknown. Let a "$u$" subscript denote the unknown indices of $T$, and let "$d$" denote the known (Dirichlet) indices in $T$. Then, the linear system can be written in the following way:

$$ \left[\begin{matrix} K_{dd} & K_{du} \\ K_{ud} & K_{uu} \end{matrix}\right] \left[ \begin{matrix} T_d \\ T_u \end{matrix}\right] = \left[\begin{matrix} Q_d \\ Q_u \end{matrix}\right] $$

Since the values of $T_d$ are known, we can immediately discard the equations in those rows, leading to this system:

$$ \left[\begin{matrix} K_{ud} & K_{uu} \end{matrix}\right] \left[ \begin{matrix} T_d \\ T_u \end{matrix}\right] = \left[\begin{matrix} Q_u \end{matrix}\right] $$

And then move your known values over to the right-hand side of the linear system:

$$ K_{uu}T_u = Q_u - K_{ud}T_d $$

Solve this reduced set of linear equations, and you've got your unknowns. Another technique to avoid mucking around with the original $K$ matrix too much is to zero out $K_{du}$ and $K_{ud}$, set $K_{dd}$ to the Identity matrix, and set $Q_d = T_d$. You still need to modify the entries of $Q_u$ in the same way as described above, but this removes the need to actually re-create the sparse matrix to only include the $K_{uu}$ block while still preserving the symmetry of the linear system.

It's worth mentioning that these techniques are still appropriate, even when the index sets "$d$" and "$u$" are non-contiguous. There's a slightly higher bookkeeping burden for you, but it's conceptually identical.

  • $\begingroup$ Can you further elaborate your last paragraph? I am not sure I quite understand it. $\endgroup$
    – vcx34178
    Dec 2 '17 at 23:55
  • $\begingroup$ I just mean that even if the dirichlet nodes are nodes 1,3,5,7 and the unknowns are nodes 2,4,6,8, you could always re-arrange the indices so that the dirichlet nodes are 1-4 and unknowns are 5-8. In practice, this is not necessary, you can (using the trick in the 2nd-to-last paragraph) modify the sparse linear system in-place without explicitly re-naming the nodes. $\endgroup$ Dec 3 '17 at 0:06
  • $\begingroup$ Beyond that, I'd say just try to understand what the above example is doing (try considering each component in $T_d$ separately) and how you might generalize the procedure for when the dirichlet nodes are not the first $k$ entries of $T$. If you need, I can point you to a couple of implementations of this, but they're probably less clear than this explanation since they're probably written for speed rather than clarity. $\endgroup$ Dec 3 '17 at 0:32
  • $\begingroup$ Thanks. It would be helpful if you can refer to some implementations or references. $\endgroup$
    – vcx34178
    Dec 3 '17 at 2:25
  • 2
    $\begingroup$ @TylerOlsen's answer is excellent. I have a lengthy explanation of this issue (far beyond what the deal.II function linked to above documents) in lectures 21.6 and 21.65 here: math.colostate.edu/~bangerth/videos.html $\endgroup$ Dec 3 '17 at 17:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.