# Implementing convective boundary conditions for 1-dimensional finite difference computation of heat equation

I am simulating heat transfer through a 1-dimensional wall with convection on both sides. For the wall, I implemented a finite difference model like this:

$$u(x, t + ∆t) ≈ u(x, t) + c [u(x + ∆x, t) − 2u(x, t) + u(x − ∆x, t)]$$

where $$c = α \frac{∆t}{(∆x)^2}$$ and $$α$$ is the thermal diffusivity. The implementation of this model works fine if I look at only the wall and assume that the temperatures on both ends of the wall are known at all times. Now I would like to extend the model to include convection on both sides of the wall. It looks like the best way to do it is to use convective boundary conditions, as shown here:

$$T_{\infty}$$ and $$h$$ are known on both sides, but variable over time. $$k$$ is known and constant.

I am struggling to find a starting point for the implementation of these boundary conditions as an extension of the above model. Anything that helps me get started will be highly appreciated!

Intuitively, I would guess that for $$x = 0$$, the above equation would have to look something like this:

$$u(0, t + ∆t) ≈ u(0, t) + c [u(0 + ∆x, t) − 2u(0, t)] + a * T_{\infty}$$

where $$a$$ is a function of $$h$$ and $$∆t$$. And for $$x = L$$, an analogous equation will have to be used. Could that be right?

• What real values do you have to test your simulation results against? How will you know that the simulations are valid? Sep 1 at 13:45
• @SolarMike I have temperature data of the gas on both sides of the wall and of both surfaces.
– Dave
Sep 1 at 14:00

Let us assume that you divide the space into $$n$$ equal partitions, such that $$\Delta x=\frac{L}{n}$$. There are $$n+1$$ nodes, denoted by $$x_i$$, where $$i=(0,1,....n)$$. The target is to find $$u_i=u(x_i)$$ at each time. Let $$u_i^j$$ represent the temperature value at $$x_i$$ at time step $$j$$. You don't mention the initial condition, so I will assume that initially everything is at ambient $$T_{\infty}$$, such that $$u_i^0=T_{\infty} \forall i$$. The target is to develop a time march scheme to get $$u^{j+1}_i$$ given $$u_i^j$$. Let us observe the BC on the left end. We have $$\frac{\partial u}{\partial x}(x=0)=-b(T_{\infty}-u(x=0))$$. Discretising it, we get $$u_{1}^j-u_{-1}^j=-b(T_{\infty}-u_0^j)$$. Note that I have absorbed $$\Delta x$$ in $$b$$. Here $$u_{-1}$$ corresponds to a ghost point, a point in space which does not exist, but is assumed for mathematical convenience (remember the left edge is $$x_0$$). Similarly, you can write a discretised equation for the right wall. Let us look at your time stepping scheme now

$$u_i^{j+1}=u_i^j+c(u_{i+1}^j-2u_i^j+u_{-1}^j)$$

Start at $$j=0$$. You know the right hand side for $$j=0$$ (our initial condition), when i=1,2.....(n-1). Thus you get $$u_i^{1}$$ when $$i=1,2,3...(n-1)$$.

When $$i=0$$, you end up needing $$u_{-1}^0$$, which is not given by the initial condition (note that $$u_{-1}^0\neq T_{\infty}$$, this equality is only valid for physical points and not ghost points), but it can be easily obtained from the BC! Notice that $$u_{-1}^0=u_1^0+b(T_{\infty}-u_0^0)$$.

You will have to repeat this procedure again for $$i=n$$, where you will need another ghost point $$u_{n+1}$$ whose value can be obtained in terms of physical points by using the right wall BC.

Now you know $$u^1_i \forall i \in (0,n)$$.

Repeat for as many time steps as needed

• Thanks! So it's only about figuring out the value of $b$ now. I did as follows: From conversion of energy comes $-k A \frac{u_{1}^j-u_{-1}^j}{2\Delta x}=h A (T_\infty-u_0^j)$ where $k$ is the thermal conductivity, $A$ is the surface area, and $h$ is the convective heat transfer coefficient. Comparing to your discretization of the BC yields $b=\frac{2 \Delta x \cdot h}{k}$. Is that right?
– Dave
Sep 4 at 12:37
• That is correct Sep 4 at 13:28