Hello everyone.
Welcome back to the CFD using Openfoam course beginners to intermediate.
This is the third class.
In this class, we'll be seeing how to use Block mesh tool to generate further complicated mesh using
another tool called Snappy Hex Mesh.
So snappy hex mesh is dependent on block mesh.
So we have to use block mesh in certain way to use it for snappy x mesh that we will be looking, and
how to set up a snappy hex mesh and what actually snappy hex mesh is, and how to create complex meshes
using snappy hex mesh.
Then we will look at a command called check mesh to check the quality of our mesh.
Okay, so the block mesh is used to create the background mesh in case of uh, snappy hex mesh.
So what is background mesh?
We will look that.
So the mesh must consist purely of hexes like we should have a pure cube or pure cuboid, just like
how we created the rectangular cavity in the previous tutorial.
So the cell aspect ratio should be approximately one.
That is the ideal condition.
So it is good to maintain that and at least near the surfaces at which the subsequent snapping procedure
is applied, which if you did not understand now, you will understand later.
But if you are good with meshing in general, you will understand what snapping is so near the areas
where there will be snapping towards the surface.
We have to keep the cell aspect ratio as one and towards the convergence of the snapping.
If the procedure is slow, it could lead to the possibility of failure and we are not wanting to do
that.
So we have to make sure that the aspect ratio is one and there must be at least one interaction, sorry,
intersection of a cell edge with the cell surface that is, a mesh of one cell will not work.
So it has to intersect with some cell edges with the cell surface.
If everything till now goes through your head, don't worry, you will understand right when we get
into the presentation.
Okay, now let's assume that we have an STL surface okay.
This car is the STL.
We are interested in simulating flow over a car.
Okay.
Now the gray area is your fluid domain and we have the STL surface okay.
STL is basically surface geometry.
So we have it.
We are interested in mesh in the gray area, not the white area because we are interested in flow over
the car.
Okay, now the block mesh will act as the background mesh which will create the the outer box.
Like you see this black box.
The black mesh will create these blocks and it will have some subdivisions over there.
It also contains the boundary patch such as inlet, outlet and walls.
Let's say that this patch has to be inlet and this has to be outlet.
Then we will define that in the block mesh itself.
We are not going to do using snap hex mesh, because snap hex mesh is going to deal only with the surface.
Okay, then the block mesh will enclose the entire STL and can act as the fluid domain.
If the mesh is required around the model and inside the block mesh.
So what this means is that now we have created this black box is generated enclosing the STL surface.
So this block mesh has created a fluid domain which is the gray area which encloses the surface.
So this grey area is the fluid domain.
And this is essential only if we want to make a mesh which is outside the surface.
But if this is this surface is like a pipe, then it does not have to be this big.
It can just enclose the pipe and we can generate the mesh inside the pipe.
Then the SDL will act as the enclosure, not the block mesh.
Okay, so only when the, uh, mesh is, uh, required outside the surface, then we need block mesh
bigger than the STL and it will act as the fluid domain.
You will understand it when we actually do it.
Okay, then the purpose of Snappy Mesh is that it is advanced mesh generation tool for very complex
geometry like this aircraft.
So this is generated by, uh, fuzzy Lab, which is at IIT Bombay.
I used to work there.
So one of the, uh, research researchers generated this mesh for the Sukhoi 30 MKI Mach one aircraft.
So we were interested in simulating flow over the aircraft.
So this is just the surface mesh?
Actually, the mesh lies, uh, in the fluid domain, but we can view the surface mesh.
Okay, that's what this image is.
The point is, we can generate mesh for highly complicated surfaces, too.
That's what I wanted to say.
And the capabilities is it can handle complex geometries.
It can handle refinement features like if you want to refine just one region, you can't do that.
And mesh quality improvement can be done through an iterative process.
Snappy workflow is like follows.
First, we will be importing the STL file into a folder called Try surface, which will reside under
constant directory like how we have Polymesh adjacent to Polymesh.
We will create a new folder called try surface and put the necessary STL file inside that.
Then we will be extracting the surface feature using a feature called Surface Feature Extract or surface
feature extract is the command to extract the surfaces from the STL and save it into dot e mesh file,
which is openfoam understandable.
Then we will create a castellated mesh.
If you are good with meshing and the techniques used in it, you will understand what castellated mesh
is and we, the snap mesh will initially create a castellated mesh using snapping and refinement.
Then it will adjust the mesh to conform the surface geometry through further snapping.
And then if you want layer additions like boundary layers, five layers or six layers through layer
thickness for wireless, then you can add layers also.
So that can also be done in snaps mesh.
So now we will see how actually snap mesh works.
Now the blocks which you are seeing is generated by the block mesh.
That is the background mesh.
Then we have the car which is overlapping with the mesh, but we are interested in mesh outside the
car, not inside it.
Right.
So this is the first scenario where we have the setup.
We have a block mesh and we have an STL file.
Then the snap mesh process will start to split the cells near the surface.
Okay.
The feature edge is what we say for the surface.
So wherever there is a feature edge the snappy mesh solve, uh, algorithm will split the cells to refine
it so that we can capture it accurately.
It will do for all the feature edges.
So it will look something like this.
Okay.
It has, uh, divided the blocks into smaller blocks to capture the features.
Then it will remove whatever is residing inside the cell SDL surface.
We are not interested in that right?
We are interested only in the mesh outside it, so it will remove or delete all the cells inside the,
uh, SDL surface.
Then it will start snapping to surfaces.
As you can see, this is not very good.
The car wheel is circular, but we are getting mesh inside also, and it's not very nice.
So the process of snapping will start and it will confirm the mesh and it will snap to the surface,
and it will not have anything outside or inside the surface.
So it will be on the surface.
Exactly.
So this is what snapping does.
Uh, snapping does.
And we will start adding mesh layers wherever it is necessary so we can control the mesh layer where
it is necessary.
We can do that.
So this is the entire process of how snappy hex mesh works.
Now, for example, we will mesh a simple cylindrical pipe using a pipe geometry pipe.
Dostal.
You will have the STL file already in the resources so you can download and use it.
So first we will set up the file called surface feature extracted, because that is what is going to
extract the feature from STL and put it into r dot m s e mesh.
That's what Openfoam can understand.
Okay.
This is how the surface feature extract dict looks.
So I will open the file itself so you can understand it better.
Now I am in the terminal.
I will go to the class three.
We have the pipe external folder as the first tutorial.
So I will enter that.
Okay, we have constant perform and system.
We are not going to set up the case.
Run it so we don't have the zero file now okay now I will first run the block mesh okay.
We have the block mesh.
Now to open this exact location.
We can do this command explorer dot x space dot and hit enter.
It will open the exact location.
you can see C3 Won by Paxton.
I'll open the parameter file to view the mesh generated by block mesh.
Yeah, this is the mesh we have.
Okay.
This will act as the background mesh.
Now what we are going to do is we are going to mesh up pipe.
As I said under uh, constant folder, we have tri surface and we have pipe dot STL.
I'll click on okay and apply.
Now you can see this is the pipe we are going to work with.
I will put it in wireframe so you can see it better.
So this is the background mesh and this is the pipe.
Now we are interested in meshing around the pipe.
Please don't ask me why we are doing it.
We are just doing it for learning purpose.
So we are not going to run any simulation.
We are going to mesh around the pipe.
Okay, so by the block mesh we have inlet outlet upper and lower.
And we also have front and back.
This is what we have okay.
And I will close this.
I will go system under this.
We will be able to find the surface feature, extract it I will open that.
So you can see that we have sourced pipes.
So what is the location by the way.
You will not have this file when you get it.
So you will just have polymesh and tri surface.
The Polymesh will contain the mesh from block mesh and this dry surface will have only dot STL.
Okay, so we have this STL which we created using any CAD software I created using FreeCAD.
I have put it here so you will get it through the resources.
So it is inside dry surface.
And notice that's is capital.
Okay now we are sourcing that name pipe dot STL.
The extraction method is always extract from surface.
This include angle.
We are setting it to 150.
If it is zero it will select no h and if it is 180 it will select all h.
So h is basically triangulated surface.
So it also has edges.
And uh we are giving 150 to be okayish.
It will select everything in a cylinder.
For highly complex surface we might need 180 degrees and subset of features.
We will set non-manifold edges as no and open edges as yes.
It is always safe to keep it in this setting.
If you want to know more about this, you can read the documentation and you can explore.
Nothing wrong, but I always like to keep my non-manifold edges as no and open edges as yes.
And you have to set right obj as yes.
Okay, I will save this file.
And the next command which we have to do is extract sorry surface feature extract.
Notice that every other word has the first letter as capital I'll hit enter.
You should be seeing end without any error or warning.
Now what this will do is it will create this folder called Extended Feature Edge Mesh.
And it has written all these files.
So this is what write obj does.
Okay.
And um this is fine.
Now we also have the pipe dot extended feature edge mesh file.
But we're not interested in that.
If you go to try surface we pasted only dot stl file here.
But it also has dot image file.
That is what is needed actually.
Okay, now we are ready to do snappy hex mesh.
Okay.
So snappy hex mesh data.
It has these three parameters as the main thing.
So castellated mesh it has to be true.
Otherwise you are not going to get the mesh.
Snap has to be true.
Otherwise you are not going to get a smooth mesh.
Add layers.
It can be true or false.
It depends on what your necessity is, okay?
And by default we will be giving five dot style.
In this case, if you are having any other dot style, it has to match with the name under tri surface
folder.
So you are giving it here and the type will be tri surface mesh.
The name is pipe this pipe under name.
It is user defined.
You can keep anything that you want Okay.
It is not a syntax you can keep.
Whatever you want and feature will be given through file pipe dot image.
This is what the surface feature extract has uh generated.
And we are setting it to level six for very good refinement.
It can be three, four, five, six anything, but generally three is okayish okay.
And six will be very good.
You can also go above that.
There is no limit but generally six is very fine and three is coarse or a decent mesh.
And the next thing is refinement surfaces where we are selecting this pipe.
Right.
So this pipe is same as what you defined in here the name.
So it has to match okay the pipe and the level I have set it to 5 to 6 minimum and maximum refinement
level.
So it will see how the surface is and it will choose whether to do minimum or maximum.
So it can be same.
Also five five also be given six six can also be given and the patch info will be type pipe.
And in groups it is pipe.
So as we were seeing in Paraview we have empty patch as well as uh walls patch.
We can also do pipe.
We can give our own group.
If there are like many pipes.
In the same case, we can do pipes.
Okay, this will be in the patch info.
Then we have to give location and mesh.
So this is what is most important.
I will try to explain it through visualization.
So we have our block mesh here.
And I will also load the try surface here.
Our STL file.
Yeah we have it okay.
So if I want the mesh outside the surface I have to choose a point outside the surface.
But it has to be inside the block mesh.
You can turn on data access grid and see what are the points on x, y and z.
So the point if it lies outside the pipe, but inside the block mesh, it will generate the block mesh
as the fluid domain.
But if your point lies inside the surface of the pipe, uh, then the mesh will be inside the pipe.
The second tutorial will be on inside the pipe.
So for now we are doing outside the pipe.
So if you see the part we are choosing zero comma 0.5 comma zero uh, which is around in x, it is zero
y, it is 0.5.
And is it is it is zero.
So zero, 0.5 and zero.
It is slightly above the pipe.
It is almost same on the surface of the pipe, but uh, it is outside the pipe.
So it is going to generate the mesh outside the pipe and nothing inside.
So inside will be hollow.
Okay.
And the next feature is add layer controls.
If you set the initial conditions to false for add layers in this region, then you don't have to set
up anything under Add Layers control function.
But if you are setting it to true then you can add the end face layers.
You have to choose the name of the uh region, which in this case is pipe.
So now we will run snappy hex mesh.
So that commands to do it is first we will do block mesh, then the surface feature extract which two
we have already done.
Then we have to run the command snappy hex mesh uh hyphen override.
But before that we will look at the actual file instead of just screenshots.
So it is under snappy hex mesh dict If you go here we have the same file here.
Okay.
And we also have these things called maximum local cells set to 100,000.
Maximum global cells is set to 2 million.
So these are like limits.
You can play over it but pretty much you can leave it default in most cases.
And we have seen this I have set level three because level six is going to take a lot of time.
Uh, that's why I said two three.
But if you want to increase six then it's fine.
Then for uh, refinement levels.
Also, I said to three and four because it will do it faster and resolve angles.
This is very important.
Unlike, uh surface which are extracted, the more the angle the better the capturing.
But in this case, lesser the angle, better the capturing.
So it is to resolve sharp angles.
So usually 30 is fine.
It's not good to go like 10 or 5 in general.
So that is decent.
And we have refinement reasons.
We will cover this in a later tutorial.
So this is not getting used in our case.
Okay.
Uh, so you can pretend that this doesn't exist here.
And the location and meshes also set in the snap controls.
It has a lot of parameters, but pretty much you can leave it default in a beginner level or intermediate
level.
If you want to do very fine level of meshing, then you can maybe play with this and add layer controls.
Also has this expansion ratio, final layer thickness, minimum thickness and at what parameters it
has to grow.
So you can check these commands on what these parameters are actually.
So that is why these come commands exist.
You can read and understand what each of these parameters do, and you can play with the values accordingly.
Now we have something called mesh quality controls.
So it is including a file called mesh quality dict which is also in the systems folder.
You can always copy paste this mesh quality dict Mostly this is perfectly fine.
You don't have to change anything in this.
So we are going to leave it and after this it can be always default.
You don't have to change it.
Pretty much most of the time.
Okay.
Now we will run snappy hex mesh.
Okay.
So the command is snappy hex mesh and always do overwrite.
It is not mandatory to do this space hyphen override, but what this will do is since we are running
multiple iterations, right.
So you can see here we have refinement levels.
So for each refinement level it will try to write it in a new time step file.
We are not interested in doing that.
So we are writing the command overwrite.
So it will override the, uh, polymesh itself.
So we will have consistent mesh under Polymesh folder itself.
So I'll hit enter and it will start to do the meshing.
Now the mesh is over.
So now you can see that in the poly mesh we have more files not just boundary faces points and owner
and neighbour.
We have more.
We also got a new file called sets.
So if I go to boundary now we have five.
Like we also have pipe.
Previously we had only four.
Now we also have pipe.
This is what snappy hex mesh has added.
Now we will actually view the mesh.
I'll go here.
Hide the pipe with para dot form.
I'm going to give refresh.
You can see it has pipe in it.
Okay.
We have generated the mesh of the pipe.
So this is the background mesh.
It stays consistent.
It doesn't it doesn't change.
Now I can go here and select inlet outlet and pipe alone okay.
We have the inlet.
We have the outlet.
And we also have the pipe.
Yeah it is a decent enough mesh.
It's not good to run simulation, but to learn a meshing it is fine.
So as you can see, this is almost, uh, all quad, all hexahedral.
This is what snappy hex mesh does.
So the hex means hexahedral.
Mostly it is Hexahedral.
Sometimes it fails and makes tetra.
But 99% it is hexahedral.
Okay, we have this pipe if you want to see a slice of it, you can also do that.
I'll create a slice.
To create a slice you can click on this button and hide the show plane.
Apply.
So you can see we have the pipe only as a line because we have removed internal mesh I'll select internal
mesh.
And select the slice surface with edges.
As you can see, this is what we have got.
We have the layers also good amount of layers.
We have the mesh.
This is a very coarse mesh.
If you want to work on the refinement levels it's up to you.
But I am saying that when you once you start refining the mesh, it is going to take a lot of time.
So for tutorial purpose I have kept it very low.
You can go up to six seven refinements also.
Okay.
Now we have done the pipe meshing outside the pipe.
But what if we want to do inside the pipe.
The procedure remains literally the same.
Okay.
So I'm going to go to the internal pipe case.
We have the block mesh.
We have surface mixer extract snap x mesh.
And we will pretend that this doesn't exist already.
So initially, you will have only this.
Okay, so we have the try surface and inside that we have the pipe dot STL.
And we have these files also.
Now the method to do as you know already is go to the right location.
Check if it is the right location then run block mesh.
Get a good end and do surface feature extract.
Get a good end.
Ensure that it has created the extended feature edge mesh folder and the dot mesh.
And we already set up the snappy hex mesh.
But there is a slight change.
As I said, the location in mesh is going to change.
Previously it was zero comma 0.5 comma zero, but now it is one comma, 0.25 comma 0.25, because that
is going to reside inside the pipe and not on the block mesh.
So I will show you.
You can see the block mesh is exactly the same.
There is no change at all.
But the point which I have chosen, it lies inside the pipe somewhere in the middle.
It need not be exactly middle, it just has to reside inside the pipe.
Then the entire mesh is going to be inside the pipe and not on the block mesh.
Okay, but the problem is it is not going to do the inlet outlet and all.
It's going to be getting completely removed.
We will look how to do that also in a later tutorial, but for now this is fine.
Now the next thing is we run snappy hex mesh override.
If you want to play, uh, and learn what the command without uh, override does, then you can just
run snappy hex mesh and see what it does to the time step.
Apart from the zero time step, it will also have other time steps.
If you want to play around that, you are free to do.
Or the meshing is over very fast.
Go here and give refresh.
As you can see, this is our only mesh.
This is all that we have.
I'll close this and open it again so you can see the boundary conditions also properly.
You see we have one pipe here, nothing else.
This is what the inside the location will do.
Okay.
We have this mesh.
So this is the internal mesh.
So now you understood how to make snaps mesh outside as well as inside the geometry.
This works pretty much with every geometry, even if it is an aircraft or a ship.
It works.
Okay, so you can, uh, try to download some STL files from Grabcad or any online sources.
Or if you are good at designing, you can design your own STL files and try to do this.
Uh, so we will now do check mesh quality command.
So it will ensure the accuracy.
The, uh, it will check the accuracy of the mesh that is generated by this mesh or any mesh.
Even if you do just the block mesh, you can do this.
And it can be helpful in identifying potential problems in the mesh.
So the command is just check mesh.
So now since we have all the mesh we will do check mesh.
You see it has given all the necessary details right from at what time it has checked the number of
points or faces, number of cells and how many hexahedral is there?
How many prism is there?
How many wedge or pyramid is there?
What?
How many polyhedral is there?
And breakdown of the polyhedral number of faces like four face thing is 16 and six face thing is 118.
So all these data you get this is very highly informative.
And the topology like what are the patch names and what is the face?
Uh, how many faces it has, how many points it has and how is the surface like is it okay on the topology.
Is it closely seeing a closed singly connected.
So these are the things which are uh known from this check mesh command.
And it also gives us simply mesh okay or mesh problems.
If there is some problem it will say what problem it face like one error or two error.
Then you can check what problem it has.
It says okay for boundary openness.
It says okay for couple point location.
For maximum skewness it is saying okay non orthogonality check.
It is saying okay.
So you can see the cell volume is okay.
Phase area magnitude is okay.
If something is not okay it will say one error and you can go back and check which is not fine okay.
So this is the, uh, purpose of doing check mesh command and it will basically say skewness aspect
ratio non orthogonality and mesh consistency checks.
So it will give you an understanding on the common issue and their implication on the mesh and how it
will affect your uh final simulation result.
So tips for resolving common mesh is also found online.
You can check the documentation on how to resolve certain things.
Let's say if you are facing non orthogonality errors then you can uh, check the documentation and see
how to resolve it.
It is case by case thing.
So we can't generally say how it is.
So you have to learn by practicing snap x mesh and refining snap X mesh will generally resolve most
of the errors, but sometimes it also needs some.
personalized curation on the mesh and how it is generated on certain surfaces, and how much refined
it is.
So it all comes with practice and experience on how to make a better snappy hex mesh.
So this is how our final mesh looked.
And you have a task now.
So create a new mesh where the mesh is inside the pipe using the same STL.
But now you have to create, uh, how to say, uh, boundary layers inside the pipe.
So we did not have the boundary layers when we did this.
So you have to create boundary layers inside the pipe.
And that is your task.
You can practice it on your own.
Okay.
So if you have any questions feel free to contact me.
See you in the next video.
Thank you.