Week 8 - Simulation of a backward facing step in OpenFOAM
Simulation of a backward facing step in OpenFOAM
n this challenge, you are going to simulate an incompressible-laminar-viscous flow through the backward facing step geometry. You should perform a transient simulation. The solver can be chosen based on the described physics of the flow. You need to explain the entire simulation procedure (how you set up the case). You should also provide explanations to every change you make inside the reference case files obtained from OpenFOAM tutorials. You can choose the inlet velocity shuch that the flow is laminar.
After that, you will perform 2 case studies as described below and compare the results.
Case 1 - Simulate the flow without using any grading factor (i.e., GF = 1)
Case 2 - Simulate the flow with grading factor of 0.2. The cells should be finer near the walls (includig the step wall).
You can use the following mesh parameters but you can feel free to modify these values.
Mesh specification
- Number of cells along the x direction (longer dimension) = 200
- Number of cells along the longer y direction = 20;
Boundary condition specification
The domain specifications are provided in the following figure.
Desired output
- Measure the velocity profile at 0.085 m from the inlet of the geometry for both case studies and compare. You can use the plot over line tool for this.
- Explain why Grading/Growth factor is essential for meshing.
Procedure :
-
Setting Up Simulation Environment:
- Create a new folder called "run" within the OpenFOAM directory to run our simulations.
- Duplicate the "cavity" folder and place it inside the "run" folder. This duplicate will be used for making changes without affecting the original files.
-
Modifying Configuration Files:
- Inside the duplicated "cavity" folder, edit the "blockMeshDict," "controlDict," and velocity/pressure files to customize the simulation setup.
-
Defining Geometry and Mesh:
- In the "blockMeshDict" file, define 21 vertices and 5 blocks for the simulation geometry.
- Specify the number of mesh points needed along the x, y, and z-directions, applying grading along the boundaries for mesh quality.
-
Assigning Boundary Conditions:
- Define boundary conditions for different faces (patches) in the simulation domain.
- Classify faces into types like inlet, outlet, front, back, top, and bottom.
- Set conditions like fixed velocity at the inlet, zero gradient for pressure at the outlet, empty conditions for front/back faces, and no-slip conditions at top/bottom.
-
Adjusting Transport Properties:
- Modify the "transportProperties" file to adjust fluid properties like viscosity (nu), aiming for a lower Courant number for stability.
-
Configuring Simulation Parameters:
- In the "controlDict" file, set the simulation time and time step so that the Courant number remains below 0.5 for stability.
-
Running the Simulation:
- Generate the mesh using the configured block mesh settings.
- Run the simulation using the appropriate solver selected for the simulation type.
-
Post-Simulation Analysis:
- After the simulation is complete, open ParaView using "paraFoam" command.
- Visualize and analyze simulation results, such as velocity profiles and other relevant data.
Block Mesh specification:
Number of blocks = 5
Arrangement of blocks is as follow:
To begin the simulation, open the terminal on your Linux OS using either Ctrl+Alt+T or the right-click menu by selecting "Open Terminal."
This will display the command-line interface in the terminal window.
We're ready to simulate our problem in OpenFOAM using its tutorials. Simply enter 'tut' to access the OpenFOAM tutorial directory.
To see the available tutorials, type 'ls'.
We need to solve a simulation for this problem with incompressible flow. To do this, go to the incompressible directory by typing 'cd incompressible'.
Then, type 'ls' to see what folders are inside the incompressible directory.
In the picture above, you'll notice many solver folders. For our specific simulation, we require a solver that handles laminar, viscous flow. This is where we opt for 'icoFoam'.
'icoFoam' serves as a solver in openFoam, designed specifically for transient simulations involving incompressible, laminar flow of fluids that follow Newtonian behavior.
(Quick clarification: Newtonian fluids exhibit a linear relationship between the stress caused by their flow at any given point and the rate of deformation change at that
point - essentially, how quickly they change shape over time. Newtonian fluids provide a basic mathematical framework for understanding fluid viscosity.)
To proceed, navigate to the 'icoFoam' folder by typing 'cd icoFoam', and then use 'ls' to investigate its contents within the terminal.
Now, you have two options: 'cavity' and 'elbow'. Both fall under the 'icoFoam' solver category. The 'cavity' section is used to set up the necessary simulation domain and create a
block mesh. Go ahead and choose the 'cavity' folder for our current purpose.
Inside the 'cavity' folder, you'll find another 'cavity' subfolder. Here, we set up our fluid domain and generate a block mesh. However, it's important to note that we won't be
making any changes in this tutorial section. OpenFOAM doesn't allow modifications to their official tutorials to prevent potential issues, and altering them could even cause
OpenFOAM to malfunction, requiring a reinstallation.
To proceed, let's duplicate this 'cavity' folder. You can do this by using the command 'cp -r cavity' and then paste it into your OpenFOAM 'run' folder with 'cp -r cavity $FOAM_RUN/cavity_test'.
After that, navigate to the 'run' folder with 'cd $FOAM_RUN', and you'll find the 'cavity_test' folder there.
Now, you have the 'cavity_test' folder where you can freely make changes without affecting the official OpenFOAM files. When you open the 'cavity_test' folder, you'll see a 'system' folder.
Inside this 'system' folder, you can provide specifications for your block mesh.
In the picture above, you'll notice four script files in the 'system' folder. To create the domain and set up the block mesh, you can open the 'blockMeshDict' file. Just type 'gedit blockMeshDict' to
open and edit this file.
Let's make some changes to the 'blockMeshDict' script file. This file holds all the details about the geometry.
OpenFoam Code for creating given geometry using BlockMesh
/*--------------------------------*- C++ -*----------------------------------*
========= |
\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\ / O peration | Website: https://openfoam.org
\ / A nd | Version: 8
\/ M anipulation |
*---------------------------------------------------------------------------*/
FoamFile
{
version 2.0;
format ascii;
class dictionary;
object blockMeshDict;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
convertToMeters 1;
vertices
(
(0 0 0) //0
(0.08 0 0) //1
(0.08 0.005 0) //2
(0 0.005 0) //3
(0.08 0.01 0) //4
(0 0.01 0) //5
(0.2 0.01 0) //6
(0.2 0.005 0) //7
(0.2 0 0) //8
(0.2 -0.01 0) //9
(0.08 -0.01 0) //10
(0 0 0.001) //11
(0.08 0 0.001) //12
(0.08 0.005 0.001) //13
(0 0.005 0.001) //14
(0.08 0.01 0.001) //15
(0 0.01 0.001) //16
(0.2 0.01 0.001) //17
(0.2 0.005 0.001) //18
(0.2 0 0.001) //19
(0.2 -0.01 0.001) //20
(0.08 -0.01 0.001) // 21
);
blocks
(
hex (0 1 2 3 11 12 13 14) (80 5 1) simpleGrading (0.2 5 1)
hex (3 2 4 5 14 13 15 16) (80 5 1) simpleGrading (0.2 0.2 1)
hex (2 7 6 4 13 18 17 15) (120 5 1) simpleGrading (5 0.2 1)
hex (1 8 7 2 12 19 18 13) (120 5 1) simpleGrading (5 5 1)
hex (10 9 8 1 21 20 19 12) (120 10 1) simpleGrading (5 5 1)
);
edges
(
);
boundary
(
inlet
{
type patch;
faces
(
(0 11 14 3)
(3 14 16 5)
);
}
outlet
{
type patch;
faces
(
(9 8 19 20)
(8 7 18 19)
(7 6 17 18)
);
}
upperwalls
{
type wall;
faces
(
(5 16 15 4)
(4 15 17 6)
);
}
lowerwalls
{
type wall;
faces
(
(0 1 12 11)
(10 9 20 21)
(10 21 12 1)
);
}
frontAndBack
{
type empty;
faces
(
(3 2 1 0)
(5 4 2 3)
(4 6 7 2)
(2 7 8 1)
(1 8 9 10)
(11 12 13 14)
(14 13 15 16)
(13 18 17 15)
(12 19 18 13)
(21 20 19 12)
);
}
);
mergePatchPairs
(
);
// ************************************************************************* //
After you're done editing the 'blockMeshDict' file, save and close it. Next, let's work on the 'controlDict' file. This file helps us set the time limits, like when to start and end
the simulation, as well as the time steps (deltat). It's important to choose a CFL value for deltat that's below 1 to avoid forced stops or divergence during convergence.
Let's make the necessary changes in the 'controlDict' file.
Time Step Definition :
"We'll define the time-step for our simulation as follows:
- Total run time: 50 seconds
- Time-step size: 0.0005 seconds"
/*--------------------------------*- C++ -*----------------------------------*
========= |
\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\ / O peration | Website: https://openfoam.org
\ / A nd | Version: 8
\/ M anipulation |
*---------------------------------------------------------------------------*/
FoamFile
{
version 2.0;
format ascii;
class dictionary;
location "system";
object controlDict;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
application icoFoam;
startFrom startTime;
startTime 0;
stopAt endTime;
endTime 0.5;
deltaT 0.0005;
writeControl timeStep;
writeInterval 20;
purgeWrite 0;
writeFormat ascii;
writePrecision 6;
writeCompression off;
timeFormat general;
timePrecision 6;
runTimeModifiable true;
// *************************************************************************
"Next, we need to set the initial values for pressure and velocity. To do this, go back to the 'cavity_copy' directory using the command 'cd ..',
then enter the folder named '0'. This folder contains the initial values for pressure and velocity."
"In this situation, we need to establish the initial boundary conditions for pressure and velocity on each face. Additionally, we must ensure that the boundary names
match the changes we made to the inlet and outlet names in the 'blockMeshDict' script file. Here's how you can update the code accordingly:"
/*--------------------------------*- C++ -*----------------------------------*
========= |
\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\ / O peration | Website: https://openfoam.org
\ / A nd | Version: 8
\/ M anipulation |
*---------------------------------------------------------------------------*/
FoamFile
{
version 2.0;
format ascii;
class volVectorField;
object U;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
dimensions [0 1 -1 0 0 0 0];
internalField uniform (0 0 0);
boundaryField
{
inlet
{
type fixedValue;
value uniform (1 0 0);
}
outlet
{
type zeroGradient;
}
fixedWalls
{
type noSlip;
value uniform (0 0 0);
}
frontAndBack
{
type empty;
}
}
// ************************************************************************* //
Initial setting for Pressure
/*--------------------------------*- C++ -*----------------------------------*
========= |
\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\ / O peration | Website: https://openfoam.org
\ / A nd | Version: 8
\/ M anipulation |
*---------------------------------------------------------------------------*/
FoamFile
{
version 2.0;
format ascii;
class volScalarField;
object p;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
dimensions [0 2 -2 0 0 0 0];
internalField uniform 0;
boundaryField
{
inlet
{
type zeroGradient;
}
outlet
{
type fixedValue;
value uniform 0;
}
fixedWalls
{
type zeroGradient;
}
frontAndBack
{
type empty;
}
}
// ************************************************************************
"Now that we have configured our problem settings, we can move forward. First, let's generate the mesh by running the 'blockMesh' command. After that
we should use the 'checkMesh' command to identify any potential issues with our mesh."
blockMesh
CheckMesh
"After examining the mesh, we receive the following confirmation."
"Now we're set to run the simulation using the chosen solver, which is 'icoFoam'. Simply enter the command 'icoFoam' to initiate the simulation."
"Mesh Grading Factor (MGF)
It's a way to stretch the mesh in a specific direction. In this case, we're using 0.2, 0.5, and 0.8 as our grading factors."
OpenFoam Code for creating the mesh with MGF =0.2
blocks
(
hex (0 1 2 3 11 12 13 14) (80 5 1) simpleGrading (0.2 5 1)
hex (3 2 4 5 14 13 15 16) (80 5 1) simpleGrading (0.2 0.2 1)
hex (2 7 6 4 13 18 17 15) (120 5 1) simpleGrading (5 0.2 1)
hex (1 8 7 2 12 19 18 13) (120 5 1) simpleGrading (5 5 1)
hex (10 9 8 1 21 20 19 12) (120 10 1) simpleGrading (5 5 1)
);
The geometry after meshing,
Results
Without assigning any grading factor the block mesh is as shown below.
Velocity At MGF =1
Velocity Distribution along the domain area:-
Velocity At MGF =0.2
Velocity Distribution along the domain area:-
Velocity profile for MGF =0.2
Pressure At MGF =0.2
Pressure Distribution along the domain area:-
Case 1 - Simulation without Grading Factor (GF = 1):
In this scenario, where no mesh grading factor was applied, the simulation revealed certain flow patterns and characteristics. The lack of mesh grading resulted
in a relatively uniform cell distribution across the domain. As a consequence, the accuracy of capturing fine-scale details near the walls and step region was compromised.
This led to a limited ability to accurately capture flow separation, recirculation zones, and other boundary layer phenomena. The results obtained from this case may not
fully represent the intricacies of the flow physics due to the absence of localized refinement in critical regions.
Case 2 - Simulation with Grading Factor (GF = 0.2):
In contrast, applying a grading factor of 0.2 in this case resulted in a more refined mesh near the walls and the step. The cells were significantly smaller in these regions,
allowing for a more accurate representation of boundary layer behavior, flow separation, and other flow phenomena. This refinement enabled the simulation to capture
fine-scale details that were previously underrepresented in Case 1. As a result, the flow characteristics, including velocity profiles, pressure distributions, and recirculation
zones, were more faithfully reproduced.
Comparison and Insights:
Comparing the two cases, it is evident that the use of a grading factor plays a pivotal role in enhancing the accuracy of the simulation. The second case, with its localized
mesh refinement, demonstrated a closer agreement with expected flow behavior and theoretical predictions. This underscores the significance of mesh quality in capturing
intricate flow phenomena accurately. The simulation outcomes clearly highlight the importance of mesh grading factors, particularly in scenarios involving complex geometries
and boundary layers.
In conclusion, the simulation results strongly advocate for the adoption of mesh grading factors to achieve accurate representations of flow behavior. The findings emphasize
that mesh refinement in critical regions significantly enhances the simulation's predictive capabilities. This insight underscores the need for careful consideration of mesh parameters
and the application of appropriate grading factors when simulating fluid flow through complex geometries, especially in scenarios where fine-scale flow details are of interest.