OpenFOAM-version-9/C3/Simulating-Natural-Convection-in-a-Cavity/English

From Script | Spoken-Tutorial
Revision as of 09:58, 28 January 2025 by Evan (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Title of the script: Simulating Natural Convection in a Cavity

Author: Divyesh Variya

Keywords: OpenFOAM, ParaView, CFD, computational fluid dynamics, blockMesh, buoyancy driven flow, heat transfer, natural convection, buoyantSimpleFoam, thermophysical properties, FOSSEE, spoken tutorial, video tutorial.


Visual Cue Narration
Slide:

Opening Slide

Welcome to the spoken tutorial on Simulating Natural Convection in a Cavity.
Slide:

Learning Objective

In this tutorial, we will learn to:
  • Set up a case of heat transfer in OpenFOAM
  • Simulate a buoyancy-driven flow, and
  • Set up thermophysical properties in OpenFOAM
Slide:

System Specifications

To record this tutorial, I am using,
  • Ubuntu Linux OS version 22.04
  • OpenFOAM version 9
  • ParaView version 5.6.0, and
  • gedit Text editor

However, you may use any other editor of your choice.

Slide:

Prerequisites


As a prerequisite:
  • You should have basic knowledge of convective heat transfer.
  • You should be familiar with setting up a case in OpenFOAM.
  • If not, please go through the prerequisite OpenFOAM tutorial on this website.


Slide:

Code Files

  • The files used in this tutorial are available in the Code Files link on this tutorial page
  • Please download and extract them
  • Make a copy and then use them while practising


Slide:

Natural Convection in a Cavity

We will be solving a 2D flow in a square cavity.


All 4 walls of the cavity are fixed.

Slide:

Natural Convection in a Cavity

  • The bottom wall is maintained at a higher temperature compared to the top wall.
  • The side walls are adiabatic.


Slide:

Natural Convection in a Cavity

  • The gravity is acting downwards, in the negative y-direction.
  • Inside the cavity, the fluid close to the hot wall at the bottom is lighter.
  • The fluid close to the cold wall on top is heavier.
  • This difference in density causes a continuous circulation in the cavity.


Only Narration Let’s simulate this problem in OpenFOAM.
CTRL + ALT + T Open the terminal by pressing Ctrl, Alt and T keys.
[Terminal] Type:

cd $FOAM_RUN

Type the following command and press Enter to move into the run directory.
Only Narration Please remember to press the Enter key after typing each command in the terminal.
[Terminal] Type: cp -r ~/Downloads/cavityConvection . Let’s copy the case folder that is downloaded and extracted into the run directory.
[Terminal] Type:

cd cavityConvection

Let’s change the directory to cavityConvection using the cd command.
Slide:

Geometry

In this simulation, we consider a square cavity with an edge length of 1 m.
Slide:

Boundaries

The computational domain has 4 boundaries, namely top, bottom, left, and right.


All 4 boundaries are fixed walls.

[Terminal] Type:

gedit system/blockMeshDict

Type the following command to open the blockMeshDict file in a text editor.
[gedit blockMeshDict]:

Only Narration

We have a cubical geometry with a single block and four walls.
[Terminal] Type:

Ctrl + Q

Close this file by pressing Ctrl + Q
Slide: Boundary Conditions Let’s look at the boundary conditions in this simulation.
  • The bottom hot wall is maintained at 1 K.
  • The top cold wall is maintained at 0 K.
  • The left and the right walls are adiabatic.
  • Therefore, they have zero gradient temperature boundary conditions.


Slide:

Boundary Conditions

The boundary conditions used in the simulation are as shown in the table.
[Terminal] Type:

ls 0

The boundary conditions are defined in the 0 folder.


Let’s view its contents.

[Terminal] Highlight:

p p_rgh T U

You will see two pressure files along with the temperature and the velocity files.


One is the pressure file, p and the other is the modified pressure file, p_rgh.

Slide:

p_rgh

  • In solvers involving external forces, such as gravity, a modified pressure is used.
  • In this case, a pressure without the hydrostatic pressure is used.

Highlight >> p_rgh = p – rho*g*h

  • It is numerically convenient to solve for this modified pressure term, p_rgh
  • The pressure, p is calculated from the p_rgh pressure


  • In solvers involving body forces, such as gravity, a modified pressure is used.
  • In this case, a pressure without hydrostatic pressure is used.
  • This modified pressure, p_rgh is defined as:


p_rgh = p - rho*g*h

  • It is numerically convenient to solve for this modified pressure term, p_rgh
  • The pressure, p is calculated from the p_rgh pressure


[Terminal] Type: gedit 0/T Let’s first open the temperature file, T.
[gedit - T] Highlight:

internalField uniform 1

The domain is initialized with 1 K.
[gedit - T] Highlight:

bottom boundary condition

The bottom wall is maintained at a constant temperature of 1 K.
[gedit - T] Highlight:

top boundary condition

The top wall is maintained at a temperature of 0 K.
[gedit - T] Highlight:

left & right boundary condition

The left and right walls have zero gradient temperature boundary condition.
[gedit - T] Close the window Close the temperature file.
[Terminal] Type: gedit 0/p_rgh Let’s open the p_rgh file.
[gedit - p_rgh] Highlight:

all walls boundary condition

All 4 walls have been assigned the fixedFluxPressure boundary condition.
Slide:

fixedFluxPressure

The fixedFluxPressure boundary condition is:
  • Analogous to the zeroGradient pressure boundary condition
  • Used when body forces such as gravity and surface tension are present
  • It adjusts the pressure gradient at the wall based on the body forces


[gedit - p_rgh] Highlight:

all walls boundary condition

Our simulation takes gravitational force into consideration.


Therefore, we will use the fixedFluxPressure condition at the walls.

[gedit - p_rgh] Close the window Close the p_rgh file.
[Terminal] Type: gedit 0/p Let’s open the pressure file, p.
[gedit - p] Highlight:

all walls boundary condition

The pressure values at the boundaries are calculated from the p_rgh values.


Therefore, all 4 walls have been assigned the calculated boundary condition.

[gedit - p] Highlight:

value $internalField;

The value has been specified to be the same as the internalField.
[gedit - p] Close the window Close the p file.
[Terminal] Type:

ls constant

Let’s now see the contents of the constant folder using the ls command.
[Terminal] Highlight:

g momentumTransport thermophysicalProperties

We see that there are 3 files in the constant folder.
[Terminal] Type: gedit constant/g Let’s open the g file.
[gedit - g] Highlight:

dimensions [0 1 -2 0 0 0 0]

The dimension of g is m/s2.
[gedit - g] Highlight:


value (0 -10 0)

The magnitude of g is 10 m/s2.
[gedit - g] Close the window Close the g file.
[Terminal] Type: gedit constant/momentumTransport Let’s open the momentumTransport file.
[gedit - momentumTransport] Highlight: simulationType laminar Our simulation will be a laminar one.
[gedit - momentumTransport] Close the window Close the momentumTransport file.
[Terminal] Type: gedit constant/thermophysicalProperties Next, let’s open the thermophysicalProperties file.
[gedit - thermophysicalProperties]:

Only Narration

In this file, the properties of the fluid used in our simulation are specified.


We’ll be simulating the flow inside the cavity.

[gedit - thermophysicalProperties] Highlight: thermoType field OpenFOAM contains various thermophysical modelling packages.


The thermoType assembles the various thermophysical modelling packages.

Only Narration The additional reading material has more details on the thermophysical modelling packages.


Please refer to it.

Slide:

Fluid Properties

The various properties used in this simulation are shown in the table.
[gedit - thermophysicalProperties] Highlight: equationOfState Boussinesq We’ll be using the Boussinesq approximation for the equation of state.
Slide: Boussinesq Approximation


Higlight: equation from slide in 3rd point

The Boussinesq approximation is:
  • Used in buoyancy-driven flows.
  • It acts as an equation of state while solving the governing equations
  • Mathematically, it defines the density field as shown in the equation


Slide:

Boussinesq Approximation

Where, the reference density and coefficient of volumetric expansion are properties of fluid.
Slide:

Reference Temperature

The reference temperature is taken to be the average of hot and cold wall temperatures.


Therefore, the reference temperature for our simulation is 0.5 K.

Only Narration The additional reading material has more details on the Boussinesq approximation.


Please refer to it.

[gedit - thermophysicalProperties] Highlight: molWeight 28.9 The molecular weight of the fluid is specified as 28.9 g/mol.
[gedit - thermophysicalProperties] Highlight: rho0 1;

T0 0.5;

For the fluid in our simulation, the reference density is specified to be 1 kg/m3.


This is the reference density at a reference temperature of 0.5 K.

[gedit - thermophysicalProperties] Highlight: beta 3.4e-02 The coefficient of volumetric expansion is 3.4X10-2 K-1.
[gedit - thermophysicalProperties] Highlight: Cp 1000 The specific heat at constant pressure is taken to be 1000 kJ/kg-K.
[gedit - thermophysicalProperties] Highlight: Hf 0 Since no phase change is considered in this simulation, the heat of fusion is 0.
[gedit - thermophysicalProperties] Highlight: transport

{

mu 4.91e-03;

Pr 0.71;

}

For transport properties, dynamic viscosity and Prandtl number are to be specified.


They are specified as shown here.

[gedit - thermophysicalProperties] Close the window Close the thermophysicalProperties file.
[Terminal] Type: Ctrl + L Clear the screen by pressing Ctrl and L keys together.
[Terminal] Type: blockMesh Let’s mesh the geometry using the blockMesh command.
Slide:

buoyantSimpleFoam

We will be using the buoyantSimpleFoam solver in this simulation.
  • It is a steady-state compressible flow solver for buoyant and turbulent flows.
  • It solves the mass, momentum and energy equations along with an equation of state.
  • The equation of state we have considered is based on the Boussinesq approximation.


[Terminal] Type: buoyantSimpleFoam Let’s start the simulation using the following command.
Only Narration The simulation may take some time to complete.
[Terminal] Highlight: End The simulation is now complete.
[Terminal] Type: paraFoam Let’s view the simulated results in ParaView.
[ParaView] Properties Tab


Click on Apply

Click on the Apply button to view the geometry.
[ParaView] Active Variable Controls


Click on vtkBlockColors >> Click on U

Let’s view the velocity contours for the simulation.


Click on the vtkBlockColors dropdown in the Active Variable Controls and select U.

[ParaView] VCR Controls


Click on Last Frame

Let’s view the contours at the end of the simulation.


Click on the Last Frame button in the VCR Controls.

[ParaView]


Click on Rescale to Visible Data Range

Click on the Rescale to Visible Data Range.
[ParaView] Layout Window


Point to Circulation

We can see the steady-state circulation in the cavity.


This is an example of the Rayleigh-Benard convection.

[ParaView] Close ParaView Close the ParaView window.
Only Narration We have come to the end of the tutorial.


Let’s summarize.

Slide:

Summary

In this tutorial, we have learnt to:
  • Set up a case of heat transfer in OpenFOAM
  • Simulate a buoyancy-driven flow, and
  • Set up thermophysical properties in OpenFOAM


Slide: Assignment As an assignment:* Increase the length of the cavity in the x-direction to 2 m
  • Keep all the other parameters unaltered in your simulation
  • Simulate the flow in this rectangular cavity
  • View the steady-state velocity contours


Slide: About the Spoken Tutorial Project The video at the following link summarises the Spoken Tutorial project.


Please download and watch it.

Slide: Spoken Tutorial Workshops We conduct workshops using Spoken Tutorials and give certificates.


Please contact us.

Slide: Spoken Tutorial Forum Please post your timed queries in this forum.
Slide: FOSSEE Forum * Do you have any general/technical questions?
  • Please visit the forum given in the link.


Slide: FOSSEE Case Study Project * The FOSSEE team coordinates solving feasible CFD problems of reasonable complexity using OpenFOAM.
  • We give honorarium and certificates to those who do this.
  • For more details, please visit these sites.


Slide: Acknowledgements The Spoken Tutorial project was established by the Ministry of Education, Govt. of India.
Only Narration This tutorial is contributed by Diveysh variya, Aabhushan Regmi, Biraj Khadka, and Payel Mukharjee.


Thanks for joining.

Contributors and Content Editors

Evan