# Thermodynamics Simulation

## Heat Transfer and Fluid Flow

After reading this article you will understand how easy it is to carry out a fluid flow simulation accounting for thermodynamical processes like heat transfer. To get to the bottom of this, you need a basic understanding of thermodynamics and computational fluid dynamics (CFD). No worries – I’ve got you covered!

In addition, we will demonstrate how simple it is to extend the Smoothed Particle Hydrodynamics (SPH) method to model thermodynamics effects.

If you feel confident in your knowledge on some topics just use the outline to jump to the different sections of the article.

### Efficiency of Machines and Basics of Heat Transfer

Every machine has a certain efficiency which is defined as the ratio of the energy that we put into it, and the energy we get out. Talking about an e-motor, we put in a certain amount of electrical energy and we get some kinetic energy out. If both energies match, the machine has an efficiency of 100 %. Spoiler alert: this is literally never the case.

Although engineers try to get the efficiency of all machines as close to 100% as possible (for example by reducing the churning losses – learn more in our article about gearbox lubrication), there will always be a slight loss of energy. Precisely speaking, this energy is not lost but instead it is converted to internal energy – heat. Unfortunately, this excess heat leads to problems. A lot of problems. Sticking to our example of an e-motor, some issues caused by high temperature come to mind:

- Decreased fatigue life of components, reducing the durability of the machine
- Permanent magnets in an e-motor risk demagnetization, which leads to reduced efficiency
- Performance of coolant reduced by local overheating

To sum it up: keeping track of the thermal situation in a machine like an e-motor is crucial to ensure that it is working reliably and efficiently.

In general, there are three mechanisms of heat transfer:

Conduction is heat transfer inside a single medium, that is heat distributing inside a solid material or a fluid. Every material is characterized by its thermal conductivity which dictates how well the heat can spread. You probably know that something like copper is a very good conductor, while material like mineral wool is a very bad one – an insulator.

Convection is heat transfer between a solid body and fluid. Imagine a hot pizza coming out of the oven. The pizza will probably cool a lot faster when the air around it is in motion. Like this example, all convective processes are highly dependent on the air flow around them and the shape of the surrounding solid body.¹ Convection can be quantified by the heat transfer coefficient (HTC). This parameter is a proportionality constant of heat flux and temperature difference between solid and fluid and determines the intensity of heat transfer along a boundary. These HTCs can differ by magnitudes depending on the process of interest.

Radiation is contactless heat transfer between two solid bodies due to electromagnetic waves. If you think about a campfire, the concept of radiation will make more sense to you. Air around a campfire will not heat up significantly, as air is a bad conductor and hot air rises. Nevertheless, you feel warm standing close to a campfire – this is due to radiation. This effect is negligible for most engineering problems due to the dominance of conduction and convection.

### Relevance of CFD for Heat Transfer Processes

Coming back to our example of an e-motor, we can clearly see that this use case is dominated by both conductive and convective effects. The coil windings of an e-motor are made from conductive materials such as copper. If heat is generated locally, it will distribute quickly throughout the whole component due to conduction. However, the generated heat cannot leave the solid components through conduction alone.

This is where convection comes into play: An e-motor can be cooled with the help of fluid flow, which removes heat from the solid bodies. This can be achieved with a cold oil jet impinging onto the hot coil windings. Of course, there are also different ways of cooling an e-motor, but all methods make use of convection in some form.

While the conductive processes in the solid bodies can be understood best using structural analysis tools like the FEM method, computational fluid dynamics is needed to fully describe and quantify the convective processes. A high-fidelity CFD simulation can help to estimate HTCs for such a process, as this quantity can be computed from the temperature field of the fluid.² An average HTC can then be used as an input for simpler models to understand the heat transfer of the complete system.

### Thermodynamics from a Mathematical Perspective

I know, you crave for the SPH insights. But before we have to establish a common mathematical ground. We have already learned which mechanisms are involved in heat transfer, but how does this transfer into a mathematical formulation?

To find an equation that describes the heat transfer in fluids, we start with the first law of thermodynamics:

**The total energy of an isolated system is constant; energy can be transformed from one form to another but can be neither created nor destroyed.**

Instead of looking at the total energy, we can also subdivide the energy into its different forms and just have a look at internal energy. As the SPH method is a Lagrangian method (learn what a Lagrangian method is in this article about CFD methods), we will also assume a Lagrangian frame of reference for now: Let’s say that we have many particles in space which move along with the flow. Each of these particles has a certain internal energy. The sum of these internal energies is the total internal energy of the system - and that's what we are interested in.

Given this scenario, we can come up with a differential equation on how the internal energy changes over time. This equation looks like this:

In Fig. 3 you can see a short explanation of all these effects. Assuming an ideal gas, we can even replace the internal energy with the temperature³, which makes the whole situation even easier to grasp.

The temperature changes due to diffusion. This effect is shown nicely in Fig. 3: If one spot is very hot it will cool down over time, while the colder spots will increase in temperature – temperature will diffuse over time.

The next mechanism of temperature increase can also be easily explained: Compressing a fluid by a lot leads to the generation of heat. Think of an air pump for your bicycle – you can feel that it gets warm when you compress the air inside of it.

The last mechanism is apparent in many technical applications: heat is generated due to dissipation – mechanical energy is converted into internal energy. One example is friction: think of rubbing your hands to keep them warm. This term is also the reason why there is no machine with perfect efficiency. There will always be some dissipation.

**Figure 3: **Examples for the three different means of change in internal energy: diffusion, compression and dissipation

To fully describe the fluid side of things in a thermodynamical system in a mathematical manner just two elements are missing:

- Initial condition: the fluid requires an initial temperature
- Boundary conditions: the solid walls need to have a thermodynamical state, e.g.:

Don’t forget: everything we did until now is completely general and can be employed for any CFD method. However, is this also as straightforward when using a meshless method, like the Smoothed Particle Hydrodynamics method? Let’s find out together.

### How to Do Thermodynamics with the SPH Method

Now that we have established a mathematical framework for the evolution of the internal energy inside a fluid, we can simply use the SPH method to discretize the equation shown in Fig. 2. I won’t go into detail here on how this is done, but if you are interested in the details you might find this article about the SPH method interesting.

In addition to solving the Navier-Stokes equations we are now also taking the conservation of energy into account. Each particle has an initial internal energy, which develops based on the equation we derived in the beginning. This internal energy can be related to the temperature of the respective particle.

Boundary conditions can be handled in different ways with SPH: either the fluid particles interact with other particles that represent the solid body, or they interact with segments of the shape of the actual solid body. In both variants, it is possible to prescribe temperatures or heat fluxes to the boundary. The heat transfer model is based on the interaction of the fluid particles with the wall.

To show how easy this all is, I want to present to you a minimal simulation I carried out with our own SPH solver. It is the traditional dam break scenario, where a block of water is set into a domain with an obstacle. Due to gravity, a wave will emerge, which breaks when hitting the obstacle. While the outer walls of the domain are adiabatic, the obstacle is at 50 °C, and the fluid is at 20 °C.

**Figure 5: **Animation of a dam break incorporating thermodynamical effects. Here, a wave of cold fluid is hitting a hot object and is heating up due to this⁴

We can clearly see that the water is heating up as soon as it hits the obstacle. This heat is also moving with the flow, which we can see by looking at the cool patterns emerging in the fluid field. When looking closely, we can also see the diffusive effect, as the heat slowly spreads through the fluid.

### What can we do with this?

If you now put one and one together you might see where we want to go with this. With the framework explained before, simulating something like an e-motor cooled by an impinging oil jet is straightforward.

For this, some puzzle pieces are missing, like ensuring sufficient resolution close to the boundary to compute precise HTCs. But I will not give away too much now, just stay tuned for some upcoming articles about advanced topics in thermodynamical modelling and the usage of such models for industrial applications.

Do you also have some interesting applications that would be well suited for the SPH method or are you interested in thermodynamics? Let us know in the comments or via our socials!

^{1 }The convective heat transfer also depends on the fluid used, but I assumed that there is air around your pizza.

^{2 }This requires a simulation that is well-resolved but let us assume that this is the case.

^{3 }To be precise, we cannot replace the internal energy with temperature, but we can assume that a change of internal energy is equivalent to a change in temperature times the specific heat capacity of the fluid.

^{4 }Note that I cranked up the conductivity of the water. Otherwise, we would not see too much, as the conduction takes some time. In addition, we neglect the generation of energy via compression or dissipation.