Have you ever wondered how long it takes for your favorite drink to cool down in the fridge? While intuition might suggest that smaller bottles cool faster or that turning up the fridge temperature helps, we can actually quantify the cooling process mathematically. This post delves into approximating the cooling time using partial differential equations (PDEs) to model heat transfer.
This article assumes you have a basic understanding of PDEs, including what they represent and how they describe changes in physical systems. If you're unfamiliar with these concepts, you might want to explore an introduction to PDEs first, as we'll be diving straight into applying the heat transfer equation in cylindrical coordinates.
The inspiration for this post comes from a recent course I took on numerical methods, where I discovered how elegant and fascinating such approximations can be. Here, we'll approximate the drink as a homogeneous, cylindrical object, focusing on radial heat transfer and ignoring the effects along the height (z-direction) for simplicity. Let's dive into the mathematics behind cooling your drink!
The Heat Transfer Equation
To model the cooling process, we use the heat equation, which describes how heat diffuses through a material. In cylindrical coordinates (), the equation can be written as:
Here, is the temperature, is time, is the radial distance, is the angular position, is the height, and is the thermal diffusivity of the material. For our simplified model, we assume:
- The drink is radially symmetric, so,
- The height is negligible, so,
With these assumptions, the equation simplifies to:
This reduced form focuses solely on radial heat transfer.
Our Specific Problem
To model the problem we want to solve, namely the time it will take our drink to cool down in the fridge, we need to define a few things:
- The type of liquid
- The initial and boundary conditions
The Liquid
Let’s say we want to figure out how long it will take a glass of water to cool down in the fridge. For this, we will need to define the thermal diffusivity, , for water.
Thermal diffusivity can be calculated with:
where, is the thermal conductivity, is the density, and is the specific heat capacity at constant pressure. We’ll use SI units for everything.
For water, these values are:
Therefore, the thermal diffusivity is:
Initial and Boundary Conditions
In order to solve the PDE, we need initial and boundary condtions:
- Initial Condition: To start, the water is at room temperature,
- Boundary Condition: Suddenly, when placed in the fridge, the edge of the cup () is at the fridge temperature,
- Boundary Condition: At the centre of the cup, there is no heat flux, thus,
Solving
Solving this PDE might be possible analytically, however, it is likely quite difficult. For our purposes, solving this numerically will be easier.
To solve this PDE numerically, we’ll implement a technique called the Method of Lines.
The Method of Lines (MOL) is a technique that transforms our PDE into a system of ordinary differential equations (ODEs) by discretizing the spatial derivatives while keeping time continuous. This allows us to use well-established ODE solvers to find our solution. Let's break down how we'll apply this method to our cooling problem.
- Discretizing the spatial derivative
- Creating our system of ODEs
- Solving with established ODE solvers
Step 1: Discretizing
To discretize our spatial derivatives, we’ll apply something called Finite Differences.
First, we'll divide our spatial domain (the radius of our cup) into N equally spaced points. At each point, we'll approximate our spatial derivatives using central differences. For the first derivative with respect to r, we use:
And for the second derivative:
Step 2: System of ODEs
From this, we can transform our original PDE into a discretized system of ODEs:
As you can see, each of the values have a subscript which means we can represent these as a matrix in code.
The represents the spacing between our values and is the value at that given index.
The represents our system of ODEs which we can solve to find our solution of values for any given time (in the specified solving time range).
Step 2.2: Resolving Issues
You may have noticed a problem with this when it comes to actually creating the system in code. We reference, in a few places. However, when , this point will be undefined. Similarly, when , the point will be undefined. Therefore, we need to handle these cases separately.
For the case, it is quite simple. We won’t solve for the last point because, if you recall, we defined one of the boundary conditions at as a constant value. The temperature at which occurs at will always be the same, .
For , we can recall our second boundary condition:
Therefore, at , our finite difference for the first derivative becomes:
From this, we can derive our expression for the ODE at
Step 3: Solving
We can use established ODE solvers to solve this system of ODEs. For the purpose of this article, I will use Python and solve_ivp function from SciPy.
For the specifics of this problem, let’s say the radius of our cup is
Implementation
I will break down the Python implementation into bite-sized parts, however, I will also provide the entire code file at the end of the post.
Constants and Imports
To start, let’s define our constants and imports:
Defining the System
The solve_ivp function takes three required arguments:
- fun(t,y): a function that describes the RHS of the system. The time derivative of the state y, at time t where y can be an array (system).
- t_span: a two member sequence (array, tuple, etc. containing two values) which represents the interval of integration (t0, tf). i.e. the start and end time for our solution
- y0: The initial state of y. i.e. the initial condition.
To start, let’s define the system (fun(t,y)):
We start by handling the special case of , after that we populate the rest of our ODE system. We only go until because, as mentioned previously, the temperature is fixed at the outer boundary, hence the change over time of the temperature, , remains zero.
Solving
Now, we are ready to solve. We need to define the start and end times for our solution. We’ll start by solving for one hour (). We also need to define our initial state. Our vector is all initially at except for the last value which is at :
From this, we can call solve_ivp
Visualizing Results
Finally, we need to actually find the answer to our problem. We can do this through visualizing the results. We’ll plot the temperature as a function of radius for various times. To start, we’ll plot the distribution every 10 minutes to see how the temperature is changing.
As we can see, the temperature is gradually getting closer and closer to the the fridge temperature. I will consider the drink cooled down when the centre of the drink has also reached . Currently, even after 1 hour, the centre of the drink is still at around . This means we need to leave it in the fridge for longer. Let’s run the solver for 2 hours now and see what happens:
At 2 hours (120 min), we can see that the temperature distribution is a flat line around . This means that it takes 2 hours for the entire drink to fully cool down in the fridge. Pretty neat, right?
Animation
For fun, I also created an animation showing how the temperature changes over time. I won’t include the code for this as it would make this article unnecessarily long, however, I think it’s pretty cool.
Conclusion
In this article, we explored how to use partial differential equations and numerical methods to model the cooling of a drink in a fridge. Through our implementation in Python, we were able to determine that it takes approximately 2 hours for a room temperature drink to fully cool down to fridge temperature. This mathematical approach not only satisfies our curiosity but also demonstrates the power of PDEs in solving real-world problems. So, next time you come across someone saying “when am I going to use this complex math in real life?”, you can show them this article!