Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

05 - Functions: Heat Transfer

A common equation used in heat transfer is the empirical relation relating the convective heat transfer coefficient to the temperature difference between the object and the fluid to yield the amount of heat transferred. This equation is called Newton’s Law of Cooling and is given by:

Q˙=hAs(Ts−T∞)\dot{Q} = h A_s (T_s - T_\infty)

where Q˙\dot{Q} is the heat transfer rate, hh is the convective heat transfer coefficient, AsA_s is the surface area of the object, TsT_s is the surface temperature of the object, and T∞T_\infty is the temperature of the fluid.

Function Properties First

Prior to getting to our example, lets first show how variables within a function are not shared outside of the function. This is a key concept in programming and is known as variable scope.

---------------------------------------------------------------------------
UnboundLocalError                         Traceback (most recent call last)
Cell In[10], line 9
      6     x = 10 #setting a new value for x. This will yield an error.
      7     return newval
----> 9 print(f'The afunction value with an input of 43 is {afunction(43)}. The global x value is still {x}.')

Cell In[10], line 5, in afunction(input)
      4 def afunction(input):
----> 5     newval = input + x #using the x global variable inside the function.
      6     x = 10 #setting a new value for x. This will yield an error.
      7     return newval

UnboundLocalError: local variable 'x' referenced before assignment
---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
Cell In[11], line 8
      5     newval = input + avariable
      6     return newval
----> 8 print(f'The anotherfunction value with an input of 43 is {anotherfunction(43)}. The avariable value is {avariable} not available outside of the function.')

NameError: name 'avariable' is not defined

Example: External flow across a cylinder in crossflow

Suppose we have a heated rod with a fan blowing air across it. We’ll first estimate the heat transfer coefficient and then the total heat lost given some details about the scenario.

The heat transfer coefficient is often put in terms of the Nusselt number, NuNu, which is defined as:

Nu=hDkNu = \frac{h D}{k}

where DD is a characteristic length, kk is the thermal conductivity of the fluid, and hh is the convective heat transfer coefficient. The Nusselt number is a dimensionless number that is often correlated with the Reynolds number, ReRe, and the Prandtl number, PrPr, to yield the following equation for a rod in crossflow as reported on Page 210 of the NCEES FE Handbook:

Nu=CRenPr1/3Nu = C Re^n Pr^{1/3}

where CC, and nn are constants (given below for external flow of a cylinder in crossflow per Page 210 of the NCEES FE Handbook), ReRe is the Reynolds number, and PrPr is the Prandtl number.

ReCCnn
1 – 40.9890.330
4 – 400.9110.385
40 – 4,0000.6830.466
4,000 – 40,0000.1930.618
40,000 – 250,0000.02660.805

Method 1: Using Objects and Functions

Plot the heat lost from a rod as a function of the air velocity.

Now that we have our object and functions defined, lets plot the heat loss as a function of the air velocity assuming 20C air and a 100C surface temperature of }the 0.1m diameter and 1 foot long rod.

<Figure size 640x480 with 1 Axes>

Method 2: Not using Objects

Some may say

“I don’t want to use objects. I also don’t want to use a lot of functions. I know I need one for the Nusselt number correlation so I’ll start with that first. Otherwise I’ll just type everything in.”

<Figure size 640x480 with 1 Axes>

Method 2 appears to be simpler and more straight forward. However, there are advantages for using objects and embedded functions:

  • One common mistake is to use the wrong property data when calculating the Prandtl or Reynolds numbers. For example, using the thermal conductivity of the rod instead of the air when calculating the heat transfer coefficient. Including the Reynolds number and Prandtl number in the air object ensures that the correct property data is used.

  • If you were to do this for a more complicated problem, you would have to type in the same equations over and over again. This is where objects and functions can be very useful.

  • As the lines of code increase, it becomes more difficult to keep track of all the variables. Objects and functions make that easier and more succinct.

  • Professional programs are written using objects and functions. It is good practice to learn how to use them.