Hello everyone.
Welcome back to the CFD using Openfoam beginner to intermediate course.
This is our class seven.
In this class we are going to see refinement box feature in snappy x mesh.
Our tutorial is on external aerodynamics which is the classic motorbike case.
We are also going to plot force coefficients which are drag coefficient, lift coefficient, CD seal
and so on using new plot.
And we will also be exporting the Post-processed data to Excel.
To plot this.
So we are going to see how to include a refinement region inside the entire snap x mesh.
So as you can see, this is uh, snap mesh file screenshot.
We are defining the motorbike dot obj.
And that is the geometry here.
And we are assigning it to the group motorbike.
And we are defining something called refinement box under the geometry function, which means apart
from motorbike dot obj, we are also having a new set of refinement box.
So this refinement box is treated as a new geometry under which there will be refinement.
Okay.
So the refinement box is defined in such a way that you just need two points to define an entire box.
So you just need the minimum point and the maximum point to define a box.
So the minimum point would be minus one -0.70.
So if you take a cuboid uh and draw the major diagonal it will have two points.
One would be minimum.
One would be maximum.
So that is what this refinement box defines.
We just want to imagine it better try to plot it in a 3D and you would know, uh, using Python or any
programming software you are comfortable with.
Sorry, programming language you are comfortable with.
Then you have the Geometry of Refinement box now.
So what you are going to do is you are going to use a function called refinement region, under which
you are assigning the refinement box as the location where you want a refinement, and you are going
to say move inside, which means you are trying to refine it.
Inside this box you can also do the negative, but mostly it is used only for refinement inside the
box.
So we will stick with more inside.
And we can also set the levels which is 115 for uh for refinements.
So the 115 is a standard value which you might have to use and four is the number of refinement levels.
So we will also see the file and see how this is getting implemented.
So I will go to the case file.
We have zero constant system and paraview under system we have snappy hex mesh dict as usual.
So I am going inside this.
And you can see that we have refinement box And this refinement box is referenced when you go below
and you have refinement surfaces.
This is one such area.
And similarly we also have refinement regions.
So this is the one which you saw in the PPT.
Generally if you don't want the refinement region all you can do is just select this, put it in a comment
and this would be fine.
So this should work even without a refinement box.
But you can't remove this function entirely, so you just have to remove the values and, uh, make
the function stay.
In this case, we want a refinement box.
So I will have it.
So we are just going to generate the snappy mesh now.
So if you remember the process the first process is to generate the block mesh.
It is throwing an error.
Okay, I am not inside the motorbike region so I have to enter the folder.
So this is the mistake you should not make.
Always type less and make sure that you have the zero constant and system.
Okay, now I am going to run the blog mesh.
Okay, now the second thing is our face feature extract.
Now that is also done.
Okay.
Now we just have to run this snappy hex mesh dict.
But before that we are going to see the compose product file.
Now I have eight cores.
So I put eight and the method is scotch.
So what I'm going to do is I'm going to decompose power.
And I'm going to run snappy Higgs mesh in parallel.
So I'll get back to you once this is over.
Now the snappy hex mesh is done so I can reconstruct it now.
So I'll do reconstruct per mesh if and constant.
Okay.
Now I can safely remove all the processor files because it's not needed anymore.
Okay, I will open the paraview file and show you the mesh which we just generated.
Okay.
Because I did not give a initiative on what the geometry actually is.
As you can see, we have a big mesh.
This is our fluid domain and we have a bike inside a nice bike.
Okay, so we are just going to see the bike now.
I'll click on motor bike group.
Turn off incompressible sorry internal mesh.
And I'll choose surface with edges.
So this meshing took a lot of time.
Okay.
You can see it took like 28.24 seconds.
Okay.
So it took really a lot of time.
So when that's why we have a bad mesh.
Uh, but still we have a bad mesh.
So if you are going to refine it further, it's going to take still more time.
So for demonstration purpose, I just kept it low.
Okay.
So this is the bike and we are going to do the external aerodynamic analysis on this.
This is not the best mesh someone could use.
But for demonstration this would be just fine because we are just learning and we want to learn faster.
Okay.
Now we will see what is uh, external aerodynamics in terms of openfoam.
So first we run the block mesh and we ran surface feature extract.
Then we did decompose power.
And also we did the snappy x mesh parallel over right now.
And then we reconstructed power also.
So we have reconstructed everything related to mesh.
But now we have to start decomposing and running the case.
Right.
But you can see when I try to decompose it won't be getting all the files properly because we have something
called zero dot original.
When you copy a case from tutorials, it is going to come like this.
In most cases it's going to be like zero dot original.
When it is like this, Openfoam can't realize that this is the zero file, and it won't put it inside
the constant folder of each processor.
So Openfoam can't realize that this is the actual zero file and decompose it properly.
So we have to copy this original and put it in a normal zero file.
This is there because if you are wanting to make any changes to the boundary conditions boundary files,
uh, you should not mess up with the original file.
So that's why we have this.
So what we can do is either you just copy paste it here and rename it to zero works fine, no problem.
But if you want to do it the cool way, you can do CP hyphen, r zero dot original and zero.
That would still do the same thing but through the terminal.
Okay, now we will see the boundary files.
So you can see that there is something called include file include folder which we have not encountered
till now.
So I'll explain it what it what it means.
So if I go to include we have three files initial conditions print backup or patches and then fix it
inlet.
Just remember these names.
Now I will go inside the you file.
Since Openfoam works with C plus plus we can call in another file and use the functions inside it.
So we are including the file called initial conditions.
And uh, from initial conditions we are taking in the value of inlet.
Okay.
So we have initial conditions file here.
I'll just open it so you understand it better.
Okay.
The initial conditions is saying the flow velocity is this pressure, is this turbulence.
Kinetic energy is this and turbulent omega is this.
Now when I go to you file you can see we don't have any inlet patch because for that we have fixed inlet
patch here.
See we have the inlet patch here.
We are just referencing it here, this location so it can get the function from there.
And we also include the set constraint types function which is from include etc..
So this is mandatory to include this so that Openfoam can understand that these references are getting
uh referenced properly.
Then we are referencing front and back upper batches also.
So it need not be like this.
You can just copy and paste this here, but the purpose of having this is when you are just mentioning
include initial condition.
Instead of mentioning all of the values in different files, you just put it here and whatever is necessary
it would be referenced.
So I will open.
Let's say I will open k file because we have k file that we are referencing initial condition.
We are including the fixed inlet so we don't have to type it one by one in all the files.
Now, if you are, uh, wanting to change just the fixed inlet value instead of changing the value in
every file, all you have to do is change it in the one file and it will get referenced to all the files.
So that is the, uh, only motive of doing this.
I will open a different backupper patches now.
It says upper wall slip front and back is also slip.
So when we are seeing any file, all you have to do is reference the upper back, uh, friend patch.
And it would take it as lip.
So it happens with all the files you see.
So that is the, uh, use of having this kind of include folder.
Otherwise these files are just normal thing.
And you can play with the values if you want.
In this case we have, uh, set the initial condition as 20m/s in X direction.
Okay.
Now we will see what is there in the constant folder.
We have the tri surface where we have put the motor vector obj instead of SDL.
We used obj file.
We already saw this.
So uh we have the transport properties We are using a Newtonian model with kinematic viscosity of 1.5
into ten power minus five.
And we have turbulence properties where we are using k omega SST because it works well with waltz.
We are trying to do an external aerodynamics.
So k omega SST is one of the best.
So we already saw how to do k in the previous class, but we did not see K Omega.
So that's why we are seeing this kind of thing.
So you also understand K omega better.
So to do k omega the essential files are k omega obviously and new t okay.
Now we go to the system as usual we have block mesh decompose predict.
And we have a scheme for solution mesh quality snappy and uh surface feature extract.
Everything is fine.
But we also have a new file called force coefficients.
If I go inside force coefficient, you will see that there is a function which says that I pass force
coefficient.
It is referencing a library called forces.
Right.
Control is saying time step and the time interval is one.
This is all intuitively understandable.
And the log is saying yes, uh, to plot it in logarithmic scale.
If you have not got what this file means is it is just going to, uh, take the values from here.
So that's why we are plotting it in log.
And we are trying to get the data from the patch motorbike group.
If you see the mesh, I have plotted only the motorbike group here.
So on all these mesh points the calculation will be done for CDC, LCR and so on.
So we have to define the reference values like density.
In this case the density is taken as one.
For simplification you can work with original uh exact values of density if you want.
Then we want to define the lift direction.
So if you see this geometry the lift direction would be positive z axis.
That's what we have mentioned.
And the drag direction would be positive x.
So that's what we have mentioned again.
And the coefficient of uh sorry c of r which is like the center of rotation not the coefficient.
I'm so sorry.
It is center of rotation.
That would be 0.72 comma zero comma zero.
Where did this value come from?
I will turn on that axis grid.
You can see that this point is kind of the center of this entire geometry.
So 0.72 makes sense right.
So that is why we took 0.72.
And we want the pitch axis.
So uh in which axis it is going to pitch for drag and lift.
So that is why, Because, uh, the if you take the normal or perpendicular, it's going to be y.
So this will, uh, pitch along the y direction.
So we are mentioning y and magnitude of u infinite, which is the free stream velocity in this case
is 20.
And we also have to do the length reference and the area reference values so that the CDC values are
getting calculated properly because we need reference values Openfoam can't take these values from the
geometry, so we have to define it.
But just calling this, uh, putting this folder in system directory is not going to make it work.
Right.
If you understood openfoam by now, it's not going to make it work.
We have to reference it somewhere.
So the way to reference it is in control.
You open control dict.
At the end, you just open a new function called functions, and inside that you just put this function,
call the force coefficient and it will reference to the function of functions in force coefficient one
function.
So we are having this include force coefficient.
So it is going to take a reference from there.
And it will plot all of these.
But if you don't want to do this then you can just copy the entire thing.
Then just replace it under functions in Openfoam.
It will, sorry, controlled it.
It will just still work fine, but it's not going to be a nice way to keep your control dict.
It's going to be messy when you are going to work with a lot of functions later.
So it's always fine and better to have things in different files and referencing it.
That's how C plus plus works.
So we got how to set up the force coefficients also.
So I would advise you to download some geometry from Grabcad like a car model.
You know how to set up snappy hex mesh now.
So set up a car case.
Try to do this case in car instead of just this bike.
Okay.
So I have given this bike, uh, geometry already, but it doesn't come with the tutorials directly.
We have to find it inside the under tutorials we have resources folder.
Under resources we have geometries.
Under geometry.
You will have this uh motorbike geometry which you have to download a copy and paste it in the constant
folder so you will understand it better when you see uh, and understand all run files.
So for now you just don't worry.
You can download and do a machine using snappy hex mesh for any geometry and work with it.
Okay, now we will see what we have to do next.
Now we have set up everything so we can decompose power and run this case.
Right?
Yes.
So I will do decompose power.
It's going to decompose the case.
I hope it doesn't throw an error.
Yeah, it didn't throw any error.
Okay.
All I have to do is initiate this case.
So this case is, uh, I'll go to control dict.
It's a simple form case.
It's a steady state case.
So I'm just going to do mpirun NP eight.
Simple form.
Parallel and it enter.
So it is going to take a bit of time.
I'll get back to you after it is over, but you can notice something different here.
It is also giving you the values of CD and the.
Vectors of CD.
And we have CL and vectors of CL also.
So we also have like.
Coefficient of moment for pitch, roll and yaw and all.
Mostly we just use CNNs here.
So I'll get back to you once the simulation is over the simulation is over, but still the solution
is not converged.
As you can see.
Uh, but I stopped it at the time of 500 because it's taking so much time.
It's already four seconds.
But if you want to run it completely, you can run it.
But, uh, for demonstration purpose, this would just be fine.
Okay?
We can take the latest time step and work with it.
So, uh, I have run the decomposed case, as you can see.
Now, I have to reconstruct it.
So if you remember the command to reconstruct it faster.
Yeah, I have it.
Okay, now the reconstruction is done.
I can safely delete all the processor files, though.
It is going to take a lot of time.
Can just go here and click on refresh.
So it is going to load all the files.
This is needed for us.
So I'll go to Internal mesh.
Click on apply.
And I will take a.
Sliced plane.
So I want it y normal.
Okay.
Don't worry about this.
We'll go to normal.
This is the pressure fields.
We'll go to Velocity Field at the last time step.
So as you can see, we have the motorbike case.
And you can see the velocity profile here.
If you want to plot the streamlines of course you can.
But this tutorial is not about this, right?
This is about plotting force coefficients.
So let's look at how to do that.
Okay so we have done all of these.
Now we also saw how to set up the function and what everything in the function means.
Since we now know how to set up the case and set up the function to get the force coefficients, you
can now see how to post process this data.
So to do that you can go to your working directory and you will see a folder called post-processing
just got created.
If you go here you will see the function name which is force coefficients one in our case.
Under that you will have the zero folder.
Under that you have the force or coefficient dot that if you open it, it is just long list of files
with just generated and stored the values of Cdecl and their vectors or components of cdecl and coefficient
of moment, and so on.
So you can basically import this into Python also and post-process it for uh, plotting.
But Openfoam gives you a easy way which is called foam monitor.
So we are going to do that now.
So what we are going to do is we are going to create a plot of the coefficient things.
So the command is foam monitor space hyphen.
This hyphen s l is for log.
So if you don't want a log plot you don't have to include that hyphen L.
We will also do that.
So the location of that file is post processing force coefficients one.
Under that we have zero.
Under that we have coefficient on that.
So what it means is we are calling the application form monitor which is based on Gnuplot.
Actually.
Then we want to log plot, then the location or the path to the coefficient of that file.
Then you just hit enter and you will be able to see the graph.
So you can see we have the legends here.
So the CD is less than one.
And you see we have CL.
So that is also less than one.
We have all this.
So this is a log plot as you can see from the y axis.
But if you don't want the log plot let's just assume that you don't want a log plot.
And when you close the application of new block, just hit Ctrl C.
Otherwise it's going to respawn and come again.
Okay now I will remove that hyphen L.
You can see we just got a normal plot where everything is less than one and close to zero.
So we are not going to see much from this graph.
If you want to zoom and all you can actually do zoom and things like that.
Yeah, it all happens here.
So it just works.
Same as Gnuplot.
I'll close this and hit Ctrl C, otherwise it's going to respawn again and again.
Okay, now we are going to export this post-process data to Excel, and we will try to plot the force
coefficients values using Excel.
Okay, now I will open Excel.
I'll open a blank sheet.
Okay.
If you are just working with LibreOffice it is still fine.
Okay.
What I'm going to do is I'm going to copy this entire thing.
Instead of doing that, I'll go here and probably hold shift and click on this and then.
Just copy till here.
So this would copy everything control C and control V.
You can also import if you want.
I just find it easier when I do this.
So since this is a steady state case, first few iteration would be totally, uh, senseless like these
things.
Also, we don't want the components of cdecl, so I will remove all of these.
We don't want the coefficient of moment at all.
So I will delete all of these.
We just need coefficient of drag and lift against time.
We just want to see how it got converged against time.
So I will also delete first 9 or 10 data.
Okay now if you just know how to plot in Excel is the same go here and select data.
Okay now we have got the CDC plots.
So you can work on beautifying this graph.
Uh using Excel you can add chart title and so on.
So I just told you how to plot it using Excel, how to import it and all.
Okay.
If you have any questions regarding the content in this video, you can feel free to contact me.
See you in the next class.
Thank you.