4

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?

vcx34178
  • 145
  • 1
  • 5

1 Answers1

6

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.

Tyler Olsen
  • 1,522
  • 1
  • 10
  • 12
  • Can you further elaborate your last paragraph? I am not sure I quite understand it. – vcx34178 Dec 02 '17 at 23:55
  • 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. – Tyler Olsen Dec 03 '17 at 00:06
  • 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. – Tyler Olsen Dec 03 '17 at 00:32
  • Thanks. It would be helpful if you can refer to some implementations or references. – vcx34178 Dec 03 '17 at 02:25
  • This is the implementation in Deal.II (well-commented): https://www.dealii.org/8.4.0/doxygen/deal.II/matrix__tools_8cc_source.html

    And another one in my own project (not commented, but look to function starting on line 28): https://github.com/tjolsen/YAFEL/blob/master/src/boundary_conditions/DirichletBC.cpp#L28

    In either case, it is helpful for you to be familiar with typical sparse matrix storage schemes, since they operate directly on the internals of the matrix (i.e. it's not a simple double "for" loop over the rows and columns)

    – Tyler Olsen Dec 03 '17 at 02:38
  • I think the global $K$ matrix does not remain symmetric when arranged as you showed in your first equation, is that right? – vcx34178 Dec 03 '17 at 16:09
  • 2
    @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: http://www.math.colostate.edu/~bangerth/videos.html – Wolfgang Bangerth Dec 03 '17 at 17:06
  • Those are the videos I watched to get a good grasp of the issue, so I'll vouch for their usefulness! (Also, thanks for putting them up!) – Tyler Olsen Dec 03 '17 at 20:52