ansys ansys cfd ansys cfx ansys cfx centrifugal pump ansys cfx in Spanish ansys cfx impeller ansys designmodeler ansys design modeler ansys in Spanish ANSYS FLUENT ansys fluent centrifugal pump ansys fluent in Spanish ansys fluent heat transfer ansys fluent heat transfer ansys mesh ansys meshing ansys tutorial bluecfd cavity openfoam cfd design modeler elbow tutorial FVM install ansys install openfoam install openfoam on Windows install salome fluid mechanics mesh finite volume method turbulence models naca 2412 openfoam openfoam cavitation openfoam in Spanish openfoam tutorial openfoam vs ansys cfx openfoam water channel salome salome in Spanish salome mesh salome openfoam heat transfer tutorial ansys fluent finite volumes
-
Generate a Mesh from a Photograph

Learn how to generate a CFD mesh from any photograph using the Gmsh mesher.
-
Finite Volume Method – Source Term

In this tutorial we will solve the same exercise, but adding a heat generation source, and we will …
-
Finite Volume Method

Diffusion problems are the simplest ones to start with in order to understand how the finite volume method (FVM) works.
-
Navier–Stokes Equations

They are a set of mathematical equations that describe the motion of viscous fluids. They are one of the most important tools in …
-
Reynolds Number

It is a dimensionless parameter in fluid mechanics that describes the ratio between inertial forces and viscous forces in a moving fluid.
Finite Volume Method – Source Term¶
In the previous tutorial we learned how the finite volume method works for the steady 1D diffusion equation. In this tutorial we will solve the same exercise, adding a heat generation source, and compare the numerical result with the analytical solution.
Exercise¶
We have a wall whose end faces $A$ and $B$ are at temperatures of 100°C and 200°C, respectively. The wall thickness is $L = 2 cm$, the thermal conductivity is $k = 0.5 W/m.°K$ and there is a uniform heat generation of $q = 1000 kW/m^3$. Calculate the temperature distribution across the wall thickness.
Solution¶
As in the previous case, we must generate a mesh and discretize the heat diffusion equation (1)
For nodes 2, 3 and 4¶
To discretize the diffusion equation, we first integrate between the intermediate points $w$ and $e$ (lowercase)
Factoring the temperatures, we can rearrange the equation as follows:
Then we can simplify the equation with the following expression:
In our case, since there is a single material, $k_e$ and $k_w$ are equal, so we obtain the following equalities for equation (5)
| $a_W$ | $a_E$ | $a_P$ | $S_P$ | $S_u$ |
|---|---|---|---|---|
| $\frac{kA}{\delta x}$ | $\frac{kA}{\delta x}$ | $a_W + a_E – S_P$ | $0$ | $qA\delta x$ |
Equation (6) and the previous table are valid for nodes 2, 3 and 4, because at those nodes we have information from the neighboring points $E$ and $W$
For nodes 1 and 5, the discretized equations are different because they lie on the boundaries of the wall.
For Node 1¶
Based on equation (2) and discretizing the corresponding values, we have:
Since it is the same material, the thermal conductivity values are equal: $k_e = k_A = k$. The areas also remain the same across the whole wall thickness.
Factoring the temperatures we obtain the following form:
Equation (9) can be matched to the form of equation (6), giving the following new table with the values of each coefficient:
| $a_W$ | $a_E$ | $a_P$ | $S_P$ | $S_u$ |
|---|---|---|---|---|
| $0$ | $\frac{kA}{\delta x}$ | $a_W + a_E – S_P$ | $-\frac{2kA}{dx}$ | $qA\delta x + \frac{2kA}{dx} T_A$ |
Node 5¶
Similarly, for node 5 we can write the discretized equation as:
Where the table of coefficients is:
| $a_W$ | $a_E$ | $a_P$ | $S_P$ | $S_u$ |
|---|---|---|---|---|
| $\frac{kA}{\delta x}$ | $0$ | $a_W + a_E – S_P$ | $-\frac{2kA}{dx}$ | $qA\delta x + \frac{2kA}{dx} T_B$ |
Substituting Values for Each Node¶
Substituting the values from the previous tables for each node, we can build the following table:
| $Nodo$ | $a_W$ | $a_E$ | $a_P$ | $S_P$ | $S_u$ | |
|---|---|---|---|---|---|---|
| $1$ | $0$ | $125$ | $375$ | $-250$ | $4000+250T_A$ | |
| $2$ | $125$ | $125$ | $250$ | $0$ | $4000$ | |
| $3$ | $125$ | $125$ | $250$ | $0$ | $4000$ | |
| $4$ | $125$ | $125$ | $250$ | $0$ | $4000$ | |
| $5$ | $125$ | $0$ | $375$ | $-250$ | $4000+250T_B$ |
This system of linear equations can be solved using matrices, as follows:
Where the values of $T_A$ and $T_B$ are 100°C and 200°C, respectively, as stated in the problem.
Solving this matrix system (for example, with the inverse matrix) we obtain the following results:
Comparison of the Analytical and Numerical Solutions¶
The analytical (exact) solution for this problem is given by the following equation:
Where x is the distance along the wall thickness:
| $Nodo$ | $1$ | $2$ | $3$ | $4$ | $5$ | |
|---|---|---|---|---|---|---|
| $x(m)$ | $0.002$ | $0.006$ | $0.010$ | $0.014$ | $0.018$ | |
| $Solución$ $Numérica$ | $150$ | $218$ | $254$ | $258$ | $230$ | |
| $Solución$ $Analítica$ | $146$ | $214$ | $250$ | $254$ | $226$ | |
| $Porcentaje$ $de$ $Error$ | $2.73$ | $1.86$ | $1.60$ | $1.57$ | $1.76$ |
Solving the Exercises in Python¶
Using the code from the previous tutorial as a base, we have adapted it for this exercise and compared the numerical result with the analytical (exact) one. As the plot shows, there is a small difference (percentage error), which may be due to the mesh element size; if we refine the mesh while correctly discretizing the diffusion equation, we will obtain a result closer to the exact one.
# Solving the exercise
import numpy as np
import matplotlib.pyplot as plt
Ta = 100 #Temperature at the left end [°C]
Tb = 200 #Temperature at the right end [°C]
k = 0.5 #Thermal conductivity [W/m°K]
A = 1 #Cross-sectional area of the bar [m2] (we use a value of 1, since it does not affect the calculation: it cancels out of every term of the equation)
L = 0.02 #Length of the bar [m]
l = 0.004 #Mesh element size [m]
q = 1000000 #Heat source [W/m3]
# Points to compute along the bar (mesh)
x = np.arange(l/2,L,l) #Creating the mesh
x = np.append(x, L) #Appending a value at the end
x = np.insert(x,0,0) #Inserting a value at the beginning
print(x)
# NUMERICAL SOLUTION
#From the equations obtained for nodes 1, 2, 3, 4 and 5 we get the following system of linear equations in matrix form
Matriz1 = np.matrix([[375,-125,0,0,0],[-125,250,-125,0,0],[0,-125,250,-125,0],[0,0,-125,250,-125],[0,0,0,-125,375]])
Matriz2 = np.matrix([[1000000*0.004+250*Ta],[4000],[4000],[4000],[1000000*0.004+250*Tb]])
#Solving the matrix system
T = (Matriz1**(-1))*Matriz2
T = np.transpose(T)
T = np.array(T)
T = np.ravel(T)
T = np.append(T, Tb) #Appending a value at the end
T = np.insert(T,0,100) #Inserting a value at the beginning
print(T)
# ANALYTICAL SOLUTION
Texacto = ((Tb-Ta)/L+q/(2*k)*(L-x))*x+Ta
print(Texacto)
#Plot
plt.plot(x,T,"ob--")
plt.plot(x,Texacto, "o-", color='green')
plt.title('Temperature variation along the bar')
plt.xlabel('Length of the bar [m]')
plt.ylabel('Temperature [°C]')
plt.grid(color='r', linestyle='dotted', linewidth=1)
plt.legend(['Numerical Solution','Analytical Solution']);
[0. 0.002 0.006 0.01 0.014 0.018 0.02 ] [100. 150. 218. 254. 258. 230. 200.] [100. 146. 214. 250. 254. 226. 200.]