# Discrete time and space heat equation for simulating the evolution of the temperature of atomic bodies

For my master thesis in computer science, I am programming a climate simulator but I struggle for some physics.

Basically I am trying to find how to simulate the evolution of the temperature of two touching atomic bodies (in this case, water), given their weight, volume, surface of contact, and time scale.*

I thought about averaging the temperature of the two bodies, and increase the temperature of the coldest one by half that amount, and decrease the other by half that amount too, but this cannot happen instantaneously, so I am looking for a formula that will compute more or less accurately the heat exchanged between those two bodies over (discreet) time, by closing the temperature gap between the two bodies iteratively with a configurable delta_time.

The goal here is not really to have something perfectly realistic in term of physics, but I need something more realistic than changing the temperature of the bodies by the difference multiplied by the number of steps per seconds, because once that time scale factor exceeds 1, the temperature will increase indefinitely (50-52 -> 52.1-49.9 -> 49.8-52.2 -> ...)

• By atomic, I mean they will be considered as one uniform block, so there will be no convection taking place. Also while we are at it, since I am asking for the heat exchange between those two blocks, I am not taking into consideration both bodies radiating energy away or to eachother. I'm really looking for the pure heat transfer by contact
• Are the 'atomic bodies' touching?
– Gert
Commented Nov 9, 2021 at 18:22
• @Gert Yes, I will update my question to highlight that Commented Nov 9, 2021 at 18:29

Firstly, your 'no convection' statement can only be true if the outside surfaces are perfectly well insulated.

We could then have two bodies, e.g. cubic in shape, of the same size and touching through one of their sides (think two dice, squeezed together)

The only mode of heat transfer between the two is then heat conduction.

This is governed by Fourier's heat equation, here in three Cartesian coordinates:

$$\frac{\partial T}{\partial t}=\alpha \left(\frac{\partial^2 T}{\partial x^2}+\frac{\partial^2 T}{\partial y^2}+\frac{\partial^2 T}{\partial z^2}\right)$$

It is very difficult to solve here, exept in the case where both cubes are actually identical. For all other situations, an analytical solution is extremely difficult to obtain, because of the coupling.

The method you propose won't work because it won't give you a time scale, which in the Fourier equation is introduced by $$\frac{\partial T}{\partial t}$$ and $$\alpha$$.

Another, simpler (and less accurate) approach:

Two objects, different in mass, size and shape are in contact through a simple interface of area $$A$$. The specific heat capacities $$c_{p,i}$$ are also differing.

The surfaces of the objects are insulated so as to prohibit convection and radiation losses.

We'll assume (wrongly!) that the temperature $$T_1$$ inside object $$1$$ is always homogeneous in space. So is it also for $$T_2$$.

Now we apply Newton's Law of Cooling. This assumes the heat energy flux from the hotter (say $$1$$) to the cooler object (say $$2$$) is given by:

$$\dot{Q}=kA\left[T_1(t)-T_2(t)\right]\tag{1}$$

Note that due to Conservation of Energy:

$$m_1c_{p,1}\mathrm{d}T_1(t)=-m_2c_{p,2}\mathrm{d}T_2(t)$$

Integrating gives:

$$m_1c_{p,1}T_1(t)=-m_2c_{p,2}T_2(t)+C\tag{2}$$

If at $$t=0$$:

$$T_1(0)=T_{1,0}$$ $$T_2(0)=T_{2,0}$$

Then:

$$C=m_1c_{p,1}T_{1,0}+m_2c_{p,2}T_{2,0}$$

Also:

$$m_1c_{p,1}\frac{\mathrm{d}T_1(t)}{\mathrm{d}t}=-m_2c_{p,2}\frac{\mathrm{d}T_2(t)}{\mathrm{d}t}=\dot{Q}$$

$$(2)$$ reworked slightly gives:

$$T_1(t)=-\frac{m_2c_{p,2}}{m_1c_{p,1}}T_2(t)+\frac{C}{m_1c_{p,1}}\tag{3}$$

Write it as:

$$T_1(t)=\alpha T_2(t)+\beta\tag{4}$$

Insert $$(3)$$ into $$(1)$$:

$$\dot{Q}=kA\left[\alpha T_2(t)+\beta-T_2(t)\right]$$

Or:

$$-m_2c_{p,2}\frac{\mathrm{d}T_2(t)}{\mathrm{d}t}=kA\left[\alpha T_2(t)+\beta-T_2(t)\right]\tag{5}$$

Introduce a new variable:

$$u(t)=\alpha T_2(t)+\beta-T_2(t)$$

Then $$(5)$$ becomes:

$$-m_2c_{p,2}\frac{\mathrm{d}u(t)}{\mathrm{d}t}=kAu(t)\tag{6}$$

$$(6)$$ then solves easily for $$u(t)$$ by integration. Back-substituting then gives the time evolution for $$T_2$$.

This method would also lend itself for the OP's proposed method, by transforming $$(6)$$ into a difference equation:

$$\boxed{-m_2c_{p,2}\frac{\Delta u(t)}{\Delta t}=kAu(t)}\tag{7}$$

• Yes that's the equation I found, but I haven't found a way to discretize it, I mean this will give a full function for the heat in 3 spatial dimension over time, but I don't need that much precision. Actually what I would need is simply the temperature of the next step, and not the whole function. I'm not sure if that's really clear, but picture it as a computer simulation, I will show the evolution of all the points in space over time by increments of let's say 0.5 seconds Commented Nov 9, 2021 at 21:37
• I can picture it in any framework you want but the problem remains: apart from the Fourier approach none factor in time coordinate. I do have an idea for something simple and I'll try and post it.
– Gert
Commented Nov 9, 2021 at 21:53
• A long edit has been made. Ta.
– Gert
Commented Nov 9, 2021 at 23:57
• Thanks a lot for your detailed explanation, I think this is what I need, and if not, it gave me a lot of information to look further ! Commented Nov 10, 2021 at 23:39