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 for Diffusion Problems¶
Diffusion problems are the simplest ones to start with in order to understand how the finite volume method (FVM) works. In this document we will show step by step how to solve a 1D diffusion problem in a bar using the finite volume method.
This document is based on the book An Introduction to Computational Fluid Dynamics THE FINITE VOLUME METHOD by Versteeg – Malalasekera (2nd edition).
Consider a wall whose ends have the properties $\phi_A$ and $\phi_B$ (these properties will later be the temperatures at each end). To apply the finite volume method, we must divide the thickness into small, equal segments. For example, in the image below the thickness has been divided into 6 spaces with 5 internal points. We will compute the property $\phi$ at each internal point, which we call $P$, with neighboring points W (west) and E (east). Note that the distance between A and W, as well as the distance between B and its preceding point, is half the internal spacing.
For this problem, consider steady-state one-dimensional (1D) diffusion of a property $\phi$, whose equation is defined by:
Where $\Gamma$ is the diffusion coefficient and $S$ is the source term. The values of $\phi$ at points A and B are the boundary conditions for this case.
1. Mesh Generation¶
If we analyze point $P$ in the previous figure, we see that its neighbors W and E (uppercase) are the points adjacent to $P$. To generate the mesh we must also define intermediate points between $WP$ and $PE$, which are the points $w$ and $e$ (lowercase), as shown in the following image.
In this way we must analyze all the points across the wall thickness; that is, points $W$ and $E$ will in turn become $P$ points during the calculation. For the case in the previous image, the mesh element size (control volume) is $\Delta$X.
2. Discretization¶
Discretization consists of converting a differential equation into an algebraic equation that can be solved. In this case the finite volume method is used. Integrating equation (1) over a control volume gives the following:
Where $A$ is the cross-sectional area of the control volume face, $\Delta$V is the control volume and $\overline{S}$ is the average source over the control volume.
If we apply central differencing for the diffusion coefficient $\Gamma$, we obtain the following equivalences on our one-dimensional mesh, according to the previous image.
Equation (2.2) can be rewritten as follows:
We can also approximate the source term (an approximation based on the book by Versteeg-Malalasekera) with the following equality:
Substituting equations (4.1), (4.2) and (5) into equation (2.2) we have:
Factoring $\phi_P$, $\phi_W$ and $\phi_E$ we obtain the following:
The previous equation can be simplified and expressed as follows:
Where the values of $a_P, a_W$ and $a_E$ are:
| $a_W$ | $a_E$ | $a_P$ |
|---|---|---|
| $ \frac{\Gamma_w}{\delta X_{WP}} A_w $ | $ \frac{\Gamma_e}{\delta X_{PE}} A_e $ | $a_W+a_E-S_P$ |
3. Solution of Steady 1D Diffusion¶
The diffusion equation (thermal conduction) is similar to equation (1); in this case we simply substitute the variables needed for heat transfer, giving the following equation:
Where $k$ is the thermal conductivity and $T$ is the temperature.
3.1 Worked Example¶
We have a 0.5 m long bar, fully insulated (adiabatic process), with a temperature at point A of $T_A=100 °C$ and a temperature at point B of $T_B=500°C$. The thermal conductivity is $k=1000W/m.°K$ and the cross-sectional area is $A=10×10^{-3}m^2$
We generate the mesh by creating 5 points along the bar, as shown in the following figure. Note that the distance between points is $\delta X$, while the distance between the first and last points and the ends of the bar is $\delta X/2$.
In this exercise the thermal conductivities $k_e$ and $k_w$ are equal, since the bar is made of a single material. Likewise, the areas $A_P$, $A_W$ and $A_E$ are equal, because the cross-section of the bar is uniform along its entire length.
Now we will analyze each node, starting with node 1 (see the previous figure).
Node 1¶
From equation (9), substituting values, we can write the equation for node 1 as:
Note that for Node 1 we must use the neighboring points 2 (East) and A (left end), where the distance between point A and point 1 is $\delta x/2$.
If we factor the temperatures following the form of equation (7), we obtain:
Comparing equations (7) and (11), we see that the $W$ term does not exist, because the left neighbor we use as a reference is point $A$ (this only happens at the ends, Point 1 and Point 5). For this reason, at Node 1 we can write:
Where
| $a_W$ | $a_E$ | $a_P$ | $S_P$ | $S_u$ |
|---|---|---|---|---|
| $0$ | $ \frac{k}{\delta x} A $ | $a_W+a_E -S_P$ | $ -\frac{2k}{\delta x} A $ | $ \frac{2kA}{\delta x} T_A $ |
Nodes 2, 3 and 4¶
For the intermediate nodes it is simpler, and the equation is:
Therefore we can use the values of $a_W$, $a_E$ and $a_P$ shown in the following table, noting also that there is no heat generation source ($S$) at these points:
| $a_W$ | $a_E$ | $a_P$ |
|---|---|---|
| $ \frac{k}{\delta x} A $ | $ \frac{k}{\delta x} A $ | $a_W+a_E$ |
Node 5¶
Similarly to Node 1, for Node 5 we obtain the following:
| $a_W$ | $a_E$ | $a_P$ | $S_P$ | $S_u$ |
|---|---|---|---|---|
| $ \frac{k}{\delta x} A $ | $0$ | $a_W+a_E -S_P$ | $ -\frac{2k}{\delta x} A $ | $ \frac{2kA}{\delta x} T_B $ |
System of linear equations¶
Substituting the values of the exercise, we obtain the following linear equations in terms of the temperatures along the bar:
| Nodes | $a_W$ | $a_E$ | $S_u$ | $S_P$ | $a_P=a_W+a_E-S_P$ |
|---|---|---|---|---|---|
| $1$ | $0$ | $100$ | $200T_A$ | $-200$ | $300$ |
| $2$ | $100$ | $100$ | $ 0 $ | $ 0 $ | $200$ |
| $3$ | $100$ | $100$ | $ 0 $ | $ 0 $ | $200$ |
| $4$ | $100$ | $100$ | $ 0 $ | $ 0 $ | $200$ |
| $5$ | $100$ | $0$ | $200T_B$ | $-200$ | $300$ |
Assembling the matrix of the system of linear equations:
The temperatures $T_A$ and $T_B$ are given in the problem, so substituting them we have:
# Solving the exercise
import numpy as np
import matplotlib.pyplot as plt
Ta = 100 #Temperature at the left end [°C]
Tb = 500 #Temperature at the right end [°C]
k = 1000 #Thermal conductivity [W/m°K]
A = 10e3 #Cross-sectional area of the bar [m2]
L = 0.5 #Length of the bar [m]
l = 0.1 #Mesh element size [m]
# Points to compute along the bar (mesh)
x = np.arange(l/2,0.5,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)
#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([[300,-100,0,0,0],[-100,200,-100,0,0],[0,-100,200,-100,0],[0,0,-100,200,-100],[0,0,0,-100,300]])
Matriz2 = np.matrix([[200*Ta],[0],[0],[0],[200*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)
plt.plot(x,T,"ob--")
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)
[0. 0.05 0.15 0.25 0.35 0.45 0.5 ] [100. 140. 220. 300. 380. 460. 500.]