Hello everyone!
Welcome to the CFD using Openfoam Beginner to Intermediate course.
This will be the first class in this class.
We will be looking at the introduction to Openfoam, installation and setup of the software basic file
structure and basic commands which is used in Openfoam.
First, what is Openfoam?
Openfoam stands for Open Field Operation and Manipulation.
It is an open source software used for computational fluid dynamics, commonly known as CFD.
It is designed for solving continuum mechanics problem including fluid flow, heat transfer, and chemical
reactions.
Initially, it was developed by open CFD limited, a company, a division of the ESI Group, first released
in the year 2004.
Since then continuously enhanced and maintained by the Openfoam Foundation and an active user community.
So we generally say.com and.org.
Version or it is also known as foundation and community version.
So in this course we will be using the community version which is the essay version.
So what happens is the org or foundation version they release in the format of version one.
Version two and the latest one is version 11.
So it is mostly like V9V ten v 11.
And uh, when this course is published the latest is v 11.
But ESA they do it in a slightly different format.
So they release uh two versions every year, one in the month of June and one in the month of December.
So you see the latest version, which is released as of this course recording is, uh, 231, two.
So version two, three one to what it means is it is released in the year 23, which is 2023.
And the one two means the 12th month of the year, which is December.
So the previous release was version 2306.
So it was in the June.
So 2306.
And previous to that it is obviously 2 to 1 two.
And it goes on.
And uh, as of this course, it is recorded in June 2024.
So we are expecting 20 406 soon.
We will be using 2312 for this course.
Uh, features and capabilities of Openfoam wide range of solvers is present for incompressible compressible
flow solvers.
We also have solvers for multiphase heat transfer, combustion, chemical reaction, and everything.
It is also highly customizable since it is an open source software.
You can modify create your own custom solver, edit the source code.
You can play around the coding as much as you want and there is no restriction and it is absolutely
free.
Also, there are extensive libraries for physical models and numerical methods even if it is not coming
in the installation, you can download it from external websites.
Contributors from GitHub.
It is called form extend version.
You can write your own solvers if you need, or you can use solvers written by other people in terms
of openfoam.
So it is highly customizable and its pre-processing and post-processing utilities are highly powerful,
like the tools for mesh generation and manipulation comes within the installation, and data analysis
and visualization tools can be done using a software called Paraview, which is also open source.
And it comes along with the installation of Openfoam.
And we can also do complex geometries and dynamic meshing where the mesh moves with respect to time.
So it is also possible in Openfoam it supports structured as well as unstructured meshes capable of
handling moving boundaries and mesh deformation, and also rotating meshes in many cases.
So we will see how to do the installation and setup for installation.
Uh, we need WSL which is called Windows Subsystem Linux.
Openfoam works only in Linux system and not in windows system.
But that doesn't mean we have to get a computer which is entirely booted with Linux.
That is why we have something called WSL or Windows Subsystem Linux, where we get the terminal window
of the Linux inside windows so that we can use a Linux subsystem within the windows.
So to install that, all you have to do is open your command prompt or run as administrator.
Or you can also open your PowerShell and run this command.
WSL space.
Hyphen hyphen install space.
Hyphen D where d means the distribution version and space.
You can type ubuntu with capital U.
Hyphen 22.04.
So what this will do is it will install the Windows Subsystem Linux along with the ubuntu version of
Linux, which is 22.04 along with the installation.
And you will get ubuntu inside your system.
But if you know how to do a second boot second OS inside your system, then you are free to do a Linux
boot up.
Or if you have a spare laptop and you can afford to remove windows OS and put in Linux completely,
you can also do that.
So once you enter this command and hit enter, the process will start.
Now wait for the process to finish.
Since I have already installed it, uh, I am not installing it again, so you can just run this command
now.
After it is over, it will prompt you to restart your PC.
Now restart your PC and wait.
So you just do the next slide also.
Watch the next slide and then do this process.
That's what I recommend.
After restarting a window named ubuntu will open.
Wait till it asks you to enter your username and password.
So this username and password will be your login details for your Linux system which is in Windows Subsystem.
If the ubuntu terminal does not open automatically, you can also open from the search bar.
You can just open your search bar and search for ubuntu and a terminal window can be opened.
Note when you are typing username, you can see the username, but when you are typing the password,
the password won't be visible.
So you might be wondering, I am typing something but it is not visible on the screen.
It won't even show the stars like how we generally do when we type a password.
It will show stars, but in this case it won't show.
So instead what it will do is it will keep a blank space.
So when you are typing the password, type it very carefully.
It need not be very highly secure.
It is just for a small security purpose.
It's not going to affect your overall security of your system.
So keep it as simple as possible.
It need not, uh, involve anything like numbers, special characters.
There is nothing mandatory like that.
You can keep it as simple as you want.
So make sure you are typing it very carefully and hit enter.
Then the installation will be done for ubuntu.
Now there is a quick tip since we are talking about installation now, I would recommend you to either
install Notepad Plus Plus or Visual Studio Code.
Since Openfoam is open source, we will be modifying the codes to run the simulation.
There is no specific graphical user interface or GUI for this.
Any notepad word or any text editor for that matter would work just fine.
But some specialized Ides can make your work easier and comfortable, so I recommend you to install
either Notepad Plus Plus or VSCode.
I would personally use VSCode because it has amazing user interface and it will help me with autofill
sometimes.
So if you want to follow along, same as mine, you can go with VSCode.
But if you just want to settle down with notepad Plus plus it's your personal preference.
Okay.
now we have the XL.
If you faced any issues, please do, uh, contact me or you can search on the web.
There is various resources to, uh, help you on how to install WSL.
It will be very easy.
Now we will do the installation and setup of Openfoam version 2312.
In my system I already have the 2212 version, but now I want to install the Openfoam 2312 version.
So I will do that along with you so that you can also follow along.
So for that we have to visit the website uh https and so on.
What is there on the screen.
You can also simply search Openfoam install V2312.
The first link will do just fine.
So what we have to do is we have to open our terminal or it is also the ubuntu terminal.
So I will tell you two methods.
One is click on your windows button or open the search bar and search for ubuntu.
This thing will appear.
You can hit enter and it will open a terminal.
Just wait for it to load.
Now it is loaded.
This is also fine.
Okay, but if it is not opening or if it is throwing an error, there is another method.
You can press windows key plus R and this run window will open.
You can type in W cell and hit enter.
Now this will open.
Even if this doesn't work you can do the windows Plus R type in cmd.
This will open your command prompt.
Or you can also search command prompt from here and open it.
No problem.
You don't have to run it as administrator, just normal command prompt is fine.
And then you can type cell and hit enter.
Now this will load the cell for you.
Okay now I got the cell.
How do I know I have the lab?
Uh, my username at the device name.
And we will see something like slash mnt slash the, uh, directory of this.
So this is what we call the directory.
The location from the base where we are working is called directory.
I will use this word very often.
If you are comfortable with terminal you would already know this.
So the first command which will be knowing is clear.
So you type clear hit enter.
It will clear it okay.
Now what we are going to do is um, we are going to type in these commands and we are going to run it.
It will install the, uh, openfoam.
But you can also go to the website which I just mentioned, and you can copy paste this entire code,
but I'm going to, uh, type this out.
Okay.
Now what I'm going to do is I will type CD.
Now, you don't have to understand what I'm doing, uh, or what these commands mean, but CD is change
directory.
Now it will take me to the home directory.
Now we are in the home just after dollar.
If we don't see anything, that is the home.
Again, I will clear it.
Now I will type this command whatever is there on the screen.
SQL space https
dll.openfoam.com/r hyphen Debian hyphen repo dot s h space state bar.
I don't know what is that space sudo space space bash.
I'll hit enter.
Now it is asking me for the password.
So I will type the password and it is running.
This is the only place where we will be needing the password we just set.
So it is doing apt get update which is updating what is available already and it will see if there are
any updates for the system.
So wait for some time.
Make sure your internet is stable, only then it will be done faster.
Then we can do the second command.
So by the way, whatever is there after the hash, it is not needed.
It is just a comment.
Now we can do the second command which is sudo apt get update.
Now this is also going to update whatever is done.
So this is getting the update.
And uh then we will install whatever update is there.
It will be done automatically.
You don't have to worry.
Now this is the command which will actually install openfoam.
It is sudo apt get install openfoam 2312.
Hyphen default.
So there are many methods to install.
Default is going to install everything that is there.
Now this is case sensitive so don't make anything capital.
Everything is small here.
Hit enter.
Now it is going to ask you whether do you want to continue.
Now you can just type why this is not case sensitive.
You can type capital Y or small Y.
Doesn't matter.
Type Y and hit enter and keep your internet stable.
This is going to take a while and it will install Openfoam for you.
Now let us wait till it is over and I'll get back to you.
Now the installation is over.
As you can see, it is asking us to do something.
It is asking us to set up Openfoam through a command called source from bashrc file dot space and this
thing.
Okay, so this is what is going to tell the Linux to, uh, locate Openfoam.
So whenever we are calling Openfoam it has to know where Openfoam is installed.
So this is the location where it is installed.
So we have to source that.
It's called sourcing.
Before that we will check whether Openfoam is installed properly or not.
So to do that you can type in the next command on the slide.
It says Openfoam 2312 and hit enter.
Now if you see this then your installation is done.
Well okay.
Now now, uh, you have to see your username dollar and, uh, blinking thing.
It will also say open form two, three, one, two here.
If it is saying that, then your installation is great.
If you are facing any problem, do ask me.
Uh, you can contact me or there are again, various, uh, resources available on the internet to sort
out any issue which you are getting an installation.
Most probably someone has got that before you, so you can always check it out.
Now we are going to do the sourcing thing to to come out of this terminal.
You can click here and probably control C or control D will work for me.
Control D works.
So then I am going to do something called just CD.
Okay.
Just to ensure that I'm in the home directory.
now we are going to type explorer dot e x e space dot.
Don't miss the space dot and hit enter.
Okay now this window will pop up where you will be able to see something called Dot bash RC, which
is the file Openfoam was talking about dot bashrc file.
So just open that it will ask for permission.
You can open it using VSCode.
I am using VSCode to open it.
Go all the way down to the last line.
Actually, you won't be seeing any of these so just forget it.
You will.
This will be your last line.
This file will be your last line.
So, uh, don't mind any of this, okay?
Pretend that it doesn't exist here.
So what you are going to do is you are going to copy paste this entire thing.
Okay.
I'm just going to copy go to VS code.
And in the last line of your bashrc file you are going to paste it in.
In your case it will be after the.
If I go to the new line and paste it.
Now you are going to do something called sauce.
Okay.
So this will work for you.
So what you have to do is you have to type sauce.
Then you have to type this then save it.
And then you can open a new terminal.
Uh, I will be preferring to use Windows plus R and then we'll see.
Now you should not get any errors here.
If you are getting any error, it means that your sourcing is gone wrong somewhere.
Uh, you can safely close the previous terminal.
It is fine now.
Only the new terminal will work with the source.
Okay, so if you are, uh, if you have done it perfectly, it will not show any error.
Otherwise it will show some command that it is not sourced or something.
So I will also explain what I have done here.
Uh, whenever you want some shortcut, let's say that I want to go to a specific area in my PC, some
directory.
Now it is in main slash c slash user slash Harris Jayaraj.
This is my home directory.
This is the directory where I am at the terminal.
But if I want to go to a specific directory, say, Udemy Openfoam course.
So if I want to go there, then the command is actually CD space, then the location of that folder.
Then I if I just type that, let's say I'm typing specifically that.
So I'll go to my home directory.
Now I am typing series slash empty slash d slash openfoam V2212.
Uh, Udemy Openfoam course, if I am typing, you can see that I am entering that location.
But if I don't want to do that, let's say I am going to use this folder very often.
Then what I can do is I will create something called alias.
So if I want to enter that location, all I have to do is enter the home directory by typing in CD.
Then I will type Udemy.
Hit enter and it will take me there directly.
So it is an alias to do specific commands.
Now if you have multiple, uh, versions of Openfoam, or if you also want to do something like this,
then what you can do is you can put this entire thing within a single quotations.
Then after the quotation, you just type a dot.
So it has to be like dot space, then the, uh, location instead of source space.
Then I am going to type alias space.
Then you can give whatever word you want.
I am going to use of two, three, one, two for this.
So whenever I type of 2312.
This file or this location will be sourced.
So let's say I want to use Openfoam 2 to 1 to some time.
Then I can type f 2 to 1 two in my terminal.
Okay.
Now.
If I type that then my terminal is taking me to openfoam 2 to 1 to location wherever it is installed.
But if I want to work with Openfoam 231 to say I will type Openfoam 2312.
Now you see it is taking me to Openfoam 2312.
So that is what we are trying to do.
Okay, that is what we are trying to source here.
If I type F23, one two it will take me to the log.
It will source it automatically.
Uh sorry it is not available as of now, so I have to restart and it will work.
So this is what alias Dot does.
Okay, so this is what I have done here as well.
Now this is what is going to work here as well.
So I hope you understood.
Till there.
Now the next thing okay.
Now we have typed in CD clear and we have also sourced this.
So this is what we did till now.
If you want to go through the slides you can go through.
Now uh, we are going to do something called make directory.
Okay.
For this I will open a new terminal.
Now I will source open form 2312.
Now I have sourced Openfoam 2312, which is the new version which I have just installed.
So whenever you have multiple versions you might have to source it manually, but if you just did the
source space slash your user, then you don't have to do this line.
You will find me doing this command throughout this course very often, so you can choose to do it or
skip it whenever you want.
So what we are going to do is create a directory mkdir space hyphen p dollar form underscore run and
hit enter.
What this is going to do is just like how we created alias.
It is open form has its own method of creating alias.
That is this.
Now if I type just run it will take me to a location.
Um.
um, where it has created a run directory.
Usually this is the place where we will be doing all the simulations.
And this is generally is what is considered as a run directory.
But I will suggest you to do something else, which I will tell in the next class.
Okay.
We will be creating our own run directory.
Okay.
So uh, this is what we had to do then what you can do is uh, I is instead of running, just run there.
You can also run CD dollar form underscore run.
Okay.
Now after that, open form offers us set of tutorials which we can copy and use it whenever we want.
So whenever we are working with open form, we don't set up anything from scratch.
We will copy paste some of the tutorials and modify it to cater our needs.
So to do that we have to type in this command and it is CP hyphen r dollar form underscore tutorials.
Slash incompressible slash.
Simple form.
Make sure that f is capital.
It is case sensitive, so make sure everything is set properly.
It's.
Daley.
Space dot and hit enter.
Okay.
Now previously when I typed LHS, we did not see anything like here.
But now when I type LHS, you can see that we have something called pits daily.
This is what we just copied.
So CP is copy command hyphen R is copy recursively.
So it means that whatever file is there inside pits daily.
Copy that also.
Now we have copied that also.
But now uh I will ask you to do something like CP hyphen r dollar form underscore to Tory else space
dot.
Don't miss this dot.
Then hit enter.
It is going to take a while.
Now if you type ls you can also see something called tutorials.
Now this tutorials is uh main folder which I was telling you Like we have various solvers here.
We will be using these tutorials to set up our cases.
We won't set up it, set it up from scratch.
We will just use this.
Okay.
So we have a, uh, created something called the Pitch Daily here.
This is the way to check whether your installation is done properly or not.
Now we are going to enter the Pitch Daily folder.
It is the command CD space pitch daily.
Make sure that this is capital.
Hit enter now if you want to see what is there inside, you can type ls.
You have zero constant and system.
You don't have to worry what these things mean as of now.
Now the command which you have to run next is block mesh.
So I am just following whatever is there in the PPT.
Okay.
Now block mash.
Hit enter.
You have to see something called end.
Here it will you.
You don't have to.
You should not see any warning word here.
It will be ending smoothly with end.
Then the next command is simple form.
Hit enter.
Now.
Wait till this is over.
It will take a bit of time, but it will be over soon.
Okay, now again you are seeing something called N.
Now this is over.
What we have done is we have just simulated a backward facing step case.
Okay?
And we will be typing something called para form.
This is the way to do the post-processing.
This might or might not work for you.
Like it did not work for me, right?
Because it might or might not work for some people.
So you don't have to worry about that.
So what we will be doing is we will be installing something called Paraview.
So what is Paraview?
Paraview is the open source data analysis and visualization tool.
It is developed by a company called Kitware and various institutions in collaboration.
So the key features is it handles a large data sets.
It can be used for any sort of scientific computation, not just Openfoam and CFD.
It has an interactive 3D visualization platform and it is scriptable via Python.
If you want to automate things or if you want to make it customizable, you can do it using Python and
using Paraview along with Openfoam.
It is very powerful to post-process all our data.
We can perform operations like slicing, contour plots, stream line.
If you want to do a graph over specific line on the geometry, you can do that.
If you want to export the data within some cells in the mesh, you can do that.
It has a wide variety of capabilities.
So we are going to install Paraview.
So the method to do it is we will be going to this website paraview.org.
And you can download the latest version.
You can install it install the software in your C drive in the default location.
Now we are going to do something.
I will type ls.
As you can see we have zero 100 202 81.
These are the time steps.
Now we have to run a command called touch space para dot phone hit enter.
Now what this essentially does is it created a file called para dot phone.
This is the para view file.
Now I have installed para view already.
So what I'm going to do is I'm going to type explorer dot x space dot hit enter.
It will take me to the location where these files are existing.
Now we will be seeing this.
So just right click open with choose another app.
Then you can click on Choose app on your PC.
If you scroll down you will be able to see this paraview whatever you wherever you have installed so
you will be able to see Paraview.
So this is my previous version.
This is my new version.
So I am double double clicking the new version.
So whatever you have installed you will be able to see that double click inside bin.
If you just scroll down you will be able to see Paraview and application file.
See this is an application file.
So click on this.
Click on open and make sure to give always.
Now this will load us the case files.
It will take a bit of time for the first time.
So once I clicked the green apply here you might be able to see something like this in terms of geometry,
but the colors might be different.
Okay, so the color map might be different, but as long as it looks similar it is fine.
So if you go here you will be able to choose between velocity pressure or k epsilon nu t.
We will be seeing what these are and how these got generated later, But for now you are just going
to check whether the installation works fine or not.
And this is the interface where we will be changing the times.
As you can see, we have 100 to 100 and 281 since this is a steady state case.
So we are interested only in the last time step where it got converged.
Okay.
So this is the pressure data.
We have the velocity data.
So if you click this button it is going to uh take all the data within this window.
And uh set the minimum and maximum to the color map accordingly.
So I'll this is called rescale to visible data range.
I have selected that.
So this is what we have just simulated.
This is a backward facing step case.
If I click here it will run me through the time step.
But this is a steady state simulation so it doesn't matter.
Now I can close this.
If I go back to the terminal it will be uh, just like how we left it.
Okay, now we will see what is left.
We have done this.
Your color might look something like this.
I have changed the color map for my preference.
Okay, now we will see what is the file structure and basic commands in Openfoam.
So we have a case okay.
A case is the setup which we will be using to run any simulation.
So the case has three different parts.
One is time directories.
Then there is a folder called constant which will store all the constant values or properties related
to the simulation.
And then we have a folder called system, which will store all the control related things, which is
related to the simulation.
Under time directories will be having zero, uh, and after that it will progress as the time step.
If your time step is 0.1, then after zero we will have 0.1, 0.10.20.3.
If a time step is 0.001, then it will be 00.0.001, 0.002, and so on.
So you get the point.
So all these zero files will have corresponding velocity pressure temperature uh and uh pressure minus
the hydrostatic forces.
So all these files will be there.
And in the constant folder Generally we have the mesh here which is stored in the format called poly
mesh.
We will be having a folder called poly mesh under which we will be having the point cell faces boundary
details.
After that we will have various properties like turbulence properties, transport properties which will
have the uh fluids, kinematic viscosity and turbulence model.
Turbulence properties will have the turbulence details like whether it is laminar or Reynolds averaged
simulation or whatever it is.
Under system we will be having the control dict which will be controlling the application, which will
be using all the solver which we will be using.
Any external function, user defined function to plot any data or if you want to change the time step,
uh, start time, end time.
Anything anything related to simulation or setup we will be doing through the control dict.
If we scheme and if we solution correspond to the numerical schemes which will be using to generate
the data.
So we have various CFD numerical schemes.
And we will be setting up those through those two files.
Block mesh dict is a file which will be useful in generating mesh basic mesh snap A hex mesh can be
used for generating complex meshes.
So these are the general files under these folders.
But usually there will be more files which is not uh generic.
So we are not plotting it in this chart.
So some of the useful commands are uh, these I will demonstrate by typing it okay.
So first is LHS.
LHS will do list.
So it will list whatever um folder is there in that specific directory.
Let's say I want to then the second command is CD space the name of the folder.
So that is what I am going to do CD space.
Now here I have Openfoam as one of my folders.
So if you want to autofill, you just type first 1 or 2 letters and hit tab.
It will auto fill for you.
Hit enter.
Now you can see that I am inside Openfoam.
Now if I want to go back, what I will do is I will do CD space dot dot.
It will take me back.
Now for demonstration.
I'll go back inside.
Now, as you can see, I have four folders here.
Uh, let's say I want to go into the fourth file.
Now it's asking me to choose the one.
I am choosing it and hitting enter.
Okay, now under this I have run.
Now, let's say if I want to go back to the home again, either I can do CD and hit enter.
It will always take me to home, or else if I want to do let's say I am like very further into this.
Okay.
Now I just want to go back to folders.
I will do CD space dot dot slash dot dot for coming out of two folders.
And if I want to come out of three folders what I will do is CD space dot dot dot dot slash dot dot.
It will take me back by three folders.
Okay, I'll clear it.
Now touch is a command which will create files.
So generally we will use it to create paraview files.
Let's say I have these three okay I will go back to my home.
We have only open form now okay.
Now I will create the paraview file here touch base para dot form I'll hit enter and search.
What is there?
You can see I have parrot form file.
Okay.
Now if you want to create.
This is for creating a file.
Now if you want to create a folder then you can use mkdir which basically means make directory.
And I can type in the folder name let's say folder.
Okay.
Now when I type ls you can see we have two folders open form and folder which we just created.
Now if you want to enter folder yeah I will enter.
Now let's say I want to remove the folder okay.
The folder which I just created it is r m hyphen r.
Then I will type the folder name hit enter.
Now if I search the folder is not there.
If I want to remove the paraview file, I'll just do rm and it is also gone.
So generally for folders we will be using hyphen.
Ah.
But um we will not be using it to delete files.
Now explorer dot exe will generally open just your Windows Explorer okay.
But if we want to open it in the specific location let's say I am inside Openfoam.
Here I am in version 2212.
And this I am under, uh, tutorials.
Okay, I am under run.
Okay.
Now if I see there is nothing inside.
But I just want to open this location.
What I'm going to do is explorer dot x space dot.
So that space dot means open it in this location.
So dot means this location.
It's a second parameter input I'll hit enter and as you can see it is exactly opening that location.
So that is how that command is useful.
So these are the basic commands which we will use very often.
Apart from this we are not going to use much uh, which is related to Linux directly.
So these are Linux commands.
We will be using more commands which is related to openfoam which we will learn as the course progresses.
So that's it for this video.
If you have any questions, feel free to contact me.
Um, there is a big openfoam community online.
If you have any doubts, first try to check it online so you will be learning more than what you just
need because you will be seeing, uh, problems from other people also.
So you will learn more.
Thank you.
See you in the next class.