CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM Meshing & Mesh Conversion (https://www.cfd-online.com/Forums/openfoam-meshing/)
-   -   [CAD formats] beginners how to convert binarySTL to asciiSTL with regions (good for SHM tutorial) (https://www.cfd-online.com/Forums/openfoam-meshing/99037-beginners-how-convert-binarystl-asciistl-regions-good-shm-tutorial.html)

soonic March 24, 2012 16:29

beginners how to convert binarySTL to asciiSTL with regions (good for SHM tutorial)
 
Since I would like to try this tutorial,
http://www.cfd-online.com/Forums/ope...e-stlfile.html

my problem is to start this tutorial, since I do not have asciiSTL of my geometry. It also has to be divided into regions. I found the way, I would like to share how to do this. Maybe it will be useful to kind of beginner like me. Solution combines using Freecad + enGrid.


FreeCAD part of solution (how to export model to STL)
I create my model (a pipe) in FreeCAD. (maybe there is a way, how to name faces of the model and export them to asciiSTL too, but I do not know nowadays). After making a model consisting of several parts I use boolean operations to make one fusion of them all.

choose one to create mesh of the surface:
  • apply: menu > Meshes > create mesh form shape (test the parameter max. edge lenght not to deform your domain significantly) on Fusion you have made. This way will triangulate the surface.
  • select Fusion in Tree view and apply: menu > Meshes > Create mesh from geometry. This will mesh your surface with basic triangualtion only.

Now you can export mesh as STL. FreeCAD can export both binary and ascii STL. Ascii STL have the file extension .ast (just rename it to stl then). You will do it by selecting Mesh in Tree view and menu > Meshes > Export mesh where you choose Binary STL and save the mesh.
Since I will use enGrid (ver. 1.3beta) later, it is necessary the STL to be saved in binary format. I have a problem with enGrid to open ascii STL. No mesh will import. So that is the point.


enGrid part
(dividing mesh into several regions / patches)
I use enGrid ver.1.3beta. Run one and
  • import STL you created before: menu > Import >STL
  • if you are not very familiar with enGrid you have imported surface as one boundary code. Each patch/region/face should have "a number"-boundary code. It is the identification of surface for meshing or setting the name or switching visibility...
  • enGrid has nice keyboard shortcuts (could have more). Press V to see boundary codes (like layers in CAD apps). You probably have all surfaces in one boundary code. You can switch on or off visibility of boundary. I have a pipe with inlet, outlet and wall surface. Now all of them are in one boundary - code 999. Exit this window now.
  • when you point mouse cursor on a surface and press P, you will choose the cell under the cursor. A red dot and a box over a domain will appear. In status bar you can find info about selected cell, on the end of line, there is also code=<number> of the cell.
  • we will set several boundary codes to all of surfaces (my pipe case has three). First point the cursor on the chosen surface (inlet) press P and press S. Set boundary code window will appear. Since my edges are not sharp (?) I can use Feature angle 45 deg. Boundary code box is the future number/code of the patch/boundary. I start numbering them with 1. Radio-buttons allows you to choose how this action will affect other cells. I use *Process all cells. (try others too, no damage will be done). This will apply the boundary code to cells around the one you have chosen (the one with red dot) , until the edge of Feature angle is detected. In my case the inlet surface was set to boundary code 1. Selecting outlet surface cell by pointing cursor and press P, press S, set boundary code 2 and OK.. then wall as well.
  • now, when you press V you should see your mesh divided into several boundary codes / layers. Check if it follows your opinions visually by turning on only one of the boundary.
  • when you press E, edit boundary conditions window will appear. You can change the name of boundaries there. BC-name will be the name appearing in V window (after exporting to OpenFoam, it will use these names for boundaries)
  • save, if you want .)
Now you have the mesh loaded in egGrid, and you can turn on and off several faces / boundaries. The tricky part will come. Hope you do not have a plenty of boundaries. To save "file opening time", let's run one more enGrid session. One engrid keeps opened with your mesh which is now divided into boundaries you want to save as separated regions in asciiSTL. The second one you will use for repeating two steps: open a file and export to asciiST.


Loop this for all of boundaries you want to save as separated asciiSTL files:

  • activate the enGrid with your model. Press V and select the (first) boundary visible only (checkbox). In this window press Save selection as grid. It will create selection.vtu file (probably in the dir where you saved this case)
  • activate the second enGrid. File > Open and filter "legacy grid files" not "enGrid case files". Look for selection.vtu and Open it.
  • you should have opened only the one surface, a part of your model
  • menu > Export it as asciiSTL. Name it e.g. like a boundary name.
  • repeat this "Choosing surface in first enGrid" and "saving the selection as grid " (it overwrites the selection.vtu) and opening that file to export this surface to asciiSTL. To speed up finding when opening the next selection.vtu file, you can use menu > File > Open recent. It is the first in the list.


Now I have files needed to start this tutorial with snappyHexMesh (Hope not to stuck.)
http://www.cfd-online.com/Forums/ope...e-stlfile.html




If there is a simplier way, I will appreceate you to share.

lovecraft22 March 24, 2012 18:42

I think I'll try this the day after tomorrow but something is not clear to me…
In the first part you explain how to save a geometry as an ASCII .stl, something you could also do with paraview, meshlab (check this out if you don't know it yet!) and a lot of other free softwares…

What's the engrid part for? Does it let you save a .stl file which would contains some "sub-surfaces"? Something like the motorbike tutorial, in which you have the motorbike.stl file that keeps all the nammings of the componing parts, such as the wheels, the scree and so on…

Is that your aim? If that's the case this would be really great! I've been looking for a way to do this without expensive softwares for over a year!

soonic March 24, 2012 19:25

For me the aim is to create hexa-mesh to run my case, since my solution diverges on tet-mesh. And I do not know where exactly the problem is. Testing tutorial case with hex works, when I remeshed the geometry to tets, works not anymore. My case either. So I started to learn snappyHexMesh.

So backwards. I found a snappyHexMesh tutorial, where as a first step was "to have geometry splitted into so many region as different refinement levels are required.." following with editation of ascii STL to flag regions with names. I did not have such stl and do not know, what application to use to split a model to sub-surfaces, name them and save as stl. I used only FreeCAD where I created the geometry and basic mesh saved as stl. When you already have stl surface, just skip to enGrid part.
I wanted to allow to somebody who will stuck on the question how to make stl geometry an idea / one of possibilities. There were times I didnt know too.
I was trying several mesh applications (icl. MeshLab, gmsh) but none of them found perfect for my purpose.


So I followed to enGrid which can save the loaded mesh as an aciiSTL. Task was how to load only a part of the complex mesh to be exported as separate stl, what was done using enGrid. That way you can split the whole geometry to several surface partialy.
You wanted more, than enGrid does. The attached tutorial describes the way, how to combine several asciiSTL to one STL manualy, naming each region manualy. But some simple script would do that for you.

BUT there are problems with enGrid in complex geometries where finding non-sharp edge or dividing one surface into two. It can not split surface into two subsurfaces. When you will have in your CAD model an edge, where you want to split the surface later, I think the basic stl triangulation will keep this edge, so splitting later will be possible. I am not sure if automatic-way (feature angle detection).
You can pick cells separatly by one. When you have only basic surface triangulation it could work.
EnGrid cant work with baffles when meshing, but I think in that phase of work with enGrid it should not be problem.

And post-knowledge, check an asciiSTL exported from enGrid for decimal-point notation. I had to manually replace commas to dots. Maybe it is only my localization issue...


If that is a solution what helps you, I am glad. Thank enGits too:)

lovecraft22 March 25, 2012 04:17

Thank you!

lovecraft22 March 26, 2012 16:13

Ok, tried that. So, you are saving multiple files with different names, not the same file with different surfaces in it. You can still use an editor to concatenate this file though. That's rather interesting to me… don't know if paraview can do the same…

By the way: any way in engrid to select some triangles only? For sure you can do that in meshlab and then export the selected triangles as a .stl…

soonic March 27, 2012 04:01

in enGrid, you can pick one cell and set it a boundary code. When setting the boundary code, you can choose what will be set to that boundary code. See the six radiobuttons. There are options like *Only picked cell, *Only picked cell and neighbours. The option I use the most is *Process only visible cells what set the boundary code to the (visible) surface containing picked cell until the edge defined by Feature angle.

I must have a better look at meshLab

sincerely
Peter

lovecraft22 March 27, 2012 04:09

With meshlab you can do that. You can select cells within a rectangular region. Use ctrl, alt and shift as key modifiers when using this function.

elvis March 27, 2012 04:30

Hi,

I think that this STL´s with multiple named faces is something that only few programs offer! If I am not wrong ANSA and icon FOAMpro have that capabilaty.

Even if you take Catia you need a Script as a work around!

But maybe in the future an other way is easier, as OBJ-files are sufficient for SHM as well as Bruno mentions.

lovecraft22 March 27, 2012 04:39

Also 3Matic offers that functionality. Anyway, once you've saved the .stl files it should be pretty easy to write a script that picks all these files, reads their names and concatenates them into a single file in which every subpart has the name of the generating file…

sail March 27, 2012 10:05

Quote:

Originally Posted by elvis (Post 351671)
Hi,

I think that this STL´s with multiple named faces is something that only few programs offer! If I am not wrong ANSA and icon FOAMpro have that capabilaty.

Even if you take Catia you need a Script as a work around!

But maybe in the future an other way is easier, as OBJ-files are sufficient for SHM as well as Bruno mentions.

Mmm... What i actually do is to export different faces as saparate stl files, replace for every file the OBJECT name with the patch name (vi) and then just cat them toghether:

Cat 1.stl 2.stl 3.stl > final.stl

Althougth i must beware you that the stl file created with this method won't work for extracting the edges. I still need the unmodified whole geometry file to do that. If somebody knows a nice way to export nurbs or splines to a sHM-readable edges i'd love to hear it.

EhsanR June 12, 2013 15:30

Soonic, your post was very helpful.
Thanks,
Ehsan

viraj20feb July 28, 2017 15:46

How do we start engrid in Ubuntu 16.04?


Quote:

Originally Posted by soonic (Post 351265)
Since I would like to try this tutorial,
http://www.cfd-online.com/Forums/ope...e-stlfile.html

my problem is to start this tutorial, since I do not have asciiSTL of my geometry. It also has to be divided into regions. I found the way, I would like to share how to do this. Maybe it will be useful to kind of beginner like me. Solution combines using Freecad + enGrid.


FreeCAD part of solution (how to export model to STL)
I create my model (a pipe) in FreeCAD. (maybe there is a way, how to name faces of the model and export them to asciiSTL too, but I do not know nowadays). After making a model consisting of several parts I use boolean operations to make one fusion of them all.

choose one to create mesh of the surface:
  • apply: menu > Meshes > create mesh form shape (test the parameter max. edge lenght not to deform your domain significantly) on Fusion you have made. This way will triangulate the surface.
  • select Fusion in Tree view and apply: menu > Meshes > Create mesh from geometry. This will mesh your surface with basic triangualtion only.

Now you can export mesh as STL. FreeCAD can export both binary and ascii STL. Ascii STL have the file extension .ast (just rename it to stl then). You will do it by selecting Mesh in Tree view and menu > Meshes > Export mesh where you choose Binary STL and save the mesh.
Since I will use enGrid (ver. 1.3beta) later, it is necessary the STL to be saved in binary format. I have a problem with enGrid to open ascii STL. No mesh will import. So that is the point.


enGrid part
(dividing mesh into several regions / patches)
I use enGrid ver.1.3beta. Run one and
  • import STL you created before: menu > Import >STL
  • if you are not very familiar with enGrid you have imported surface as one boundary code. Each patch/region/face should have "a number"-boundary code. It is the identification of surface for meshing or setting the name or switching visibility...
  • enGrid has nice keyboard shortcuts (could have more). Press V to see boundary codes (like layers in CAD apps). You probably have all surfaces in one boundary code. You can switch on or off visibility of boundary. I have a pipe with inlet, outlet and wall surface. Now all of them are in one boundary - code 999. Exit this window now.
  • when you point mouse cursor on a surface and press P, you will choose the cell under the cursor. A red dot and a box over a domain will appear. In status bar you can find info about selected cell, on the end of line, there is also code=<number> of the cell.
  • we will set several boundary codes to all of surfaces (my pipe case has three). First point the cursor on the chosen surface (inlet) press P and press S. Set boundary code window will appear. Since my edges are not sharp (?) I can use Feature angle 45 deg. Boundary code box is the future number/code of the patch/boundary. I start numbering them with 1. Radio-buttons allows you to choose how this action will affect other cells. I use *Process all cells. (try others too, no damage will be done). This will apply the boundary code to cells around the one you have chosen (the one with red dot) , until the edge of Feature angle is detected. In my case the inlet surface was set to boundary code 1. Selecting outlet surface cell by pointing cursor and press P, press S, set boundary code 2 and OK.. then wall as well.
  • now, when you press V you should see your mesh divided into several boundary codes / layers. Check if it follows your opinions visually by turning on only one of the boundary.
  • when you press E, edit boundary conditions window will appear. You can change the name of boundaries there. BC-name will be the name appearing in V window (after exporting to OpenFoam, it will use these names for boundaries)
  • save, if you want .)
Now you have the mesh loaded in egGrid, and you can turn on and off several faces / boundaries. The tricky part will come. Hope you do not have a plenty of boundaries. To save "file opening time", let's run one more enGrid session. One engrid keeps opened with your mesh which is now divided into boundaries you want to save as separated regions in asciiSTL. The second one you will use for repeating two steps: open a file and export to asciiST.


Loop this for all of boundaries you want to save as separated asciiSTL files:

  • activate the enGrid with your model. Press V and select the (first) boundary visible only (checkbox). In this window press Save selection as grid. It will create selection.vtu file (probably in the dir where you saved this case)
  • activate the second enGrid. File > Open and filter "legacy grid files" not "enGrid case files". Look for selection.vtu and Open it.
  • you should have opened only the one surface, a part of your model
  • menu > Export it as asciiSTL. Name it e.g. like a boundary name.
  • repeat this "Choosing surface in first enGrid" and "saving the selection as grid " (it overwrites the selection.vtu) and opening that file to export this surface to asciiSTL. To speed up finding when opening the next selection.vtu file, you can use menu > File > Open recent. It is the first in the list.


Now I have files needed to start this tutorial with snappyHexMesh (Hope not to stuck.)
http://www.cfd-online.com/Forums/ope...e-stlfile.html




If there is a simplier way, I will appreceate you to share.



All times are GMT -4. The time now is 12:58.