Save a STL file with multi-regions

A subforum specific to the development of the OpenFoam-based workbenches ( Cfd https://github.com/qingfengxia/Cfd and CfdOF https://github.com/jaheyns/CfdOF )

Moderator: oliveroxtoby

thayerov
Posts: 3
Joined: Sun Jul 21, 2013 11:51 am

Save a STL file with multi-regions

Post by thayerov »

Hello!

Is there any possibility to export geometry to STL file with names of some surfaces - for a cylinder (bottom-->inlet, top-->outlet)? And how to add this into a such script?

Code: Select all

import FreeCAD
import Part
from FreeCAD import Base
cylinder = Part.makeCylinder(1.0,6.0,Base.Vector(0,0,0),Base.Vector(1,0,0))
cylinder.exportStl("/home/cylinder.stl")
Regards.
User avatar
NormandC
Veteran
Posts: 18589
Joined: Sat Feb 06, 2010 9:52 pm
Location: Québec, Canada

Re: Save a STL file with multi-regions

Post by NormandC »

I don't think the STL format supports this.
thayerov
Posts: 3
Joined: Sun Jul 21, 2013 11:51 am

Re: Save a STL file with multi-regions

Post by thayerov »

Yes, it is possible, but my problem is I don't know how to create a STL file that contains only surface, like a circle or a rectangular. The STL is saved in this way:

Code: Select all

solid name1 
facet normal 0.99 -0.05 0
    outer loop
      vertex 0.5 0 6
      vertex 0.49 -0.05 5.71
      vertex 0.5 0 5.71
    endloop
  endfacet
...
...
...
endsolid name1

solid name2
facet normal 0.99 -0.055 0
    outer loop
      vertex 0.5 0 6
      vertex 0.49 -0.05 5.71
      vertex 0.5 0 5.72
    endloop
  endfacet
...
...
...
endsolid name2
and names used within the file could be used for manipulation on a given region with snappyHexMesh mesher. The command:

Code: Select all

import FreeCAD
import Part
from FreeCAD import Base
circle = Part.makeCircle(2.0)
circle.exportStl("/home/circle.stl")
gives only

Code: Select all

solid
endsolid
the same is with creating a cylinder with 0mm of height. So can I save the geometry created in sketcher in STL?
User avatar
NormandC
Veteran
Posts: 18589
Joined: Sat Feb 06, 2010 9:52 pm
Location: Québec, Canada

Re: Save a STL file with multi-regions

Post by NormandC »

Geometry created in Sketcher contains only edges, there is no face to export to STL. You need to convert the sketcher geometry to faces. Then it will work.
thayerov
Posts: 3
Joined: Sun Jul 21, 2013 11:51 am

Re: Save a STL file with multi-regions

Post by thayerov »

Could you give me a hint how to create a face from edges in the sketcher using a macro?
wmayer
Founder
Posts: 20309
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: Save a STL file with multi-regions

Post by wmayer »

Edges are curves and faces are surfaces. Thus it's not possible to create a valid mesh from your model because you would create degenerated triangles which is treated as an error by most applications.
cfdfoundation
Posts: 4
Joined: Sat Jan 10, 2015 4:12 pm

Re: Save a STL file with multi-regions

Post by cfdfoundation »

This post addresses a very important topic for people using FreeCAD for engineering simulation, specifically computational fluid dynamics (CFD) with OpenFOAM.

CFD requires a computational mesh. The mesh can be generated within OpenFOAM using snappyHexMesh. snappyHexMesh uses geometry input in the form of triangulated surface files in either STL or OBJ format. Ascii STL and OBJ support "regions", or "patches". Call it what you like, it just means that triangles can be collected together under a particular name.

In the cylinder example, the triangles that make up one circular end could be labelled "inlet", the other circular end could be "outlet", and the curved part of the cylinder could be "wall". When the inside of this surface is meshed with snappyHexMesh, the resulting mesh will have boundary patches "inlet", "outlet" and "wall" on which flow boundary conditions can be applied for a CFD simulation of flow along a cylinder (pipe).

So the piece of functionality in FreeCAD that would be hugely beneficial to CFD/OpenFOAM users would be the ability to name regions of part surfaces, and the inclusion of those names with triangulated surface export. It is the ONE piece of functionality that today (Jan 2015) would make FreeCAD very attractive as a geometry generator for CFD with OpenFOAM. It would be much appreciated if the FreeCAD developers could comment on the viability/ease of such a development. (The functionality already seems to exist to highlight geometry faces, e.g. 1 of 6 faces of a box, in the GUI)
jrt
Posts: 9
Joined: Sat Aug 20, 2016 8:13 pm

Re: Save a STL file with multi-regions

Post by jrt »

I agree 100% with cfdfoundation. Anything new on this?
User avatar
DeepSOIC
Veteran
Posts: 7896
Joined: Fri Aug 29, 2014 12:45 am
Location: used to be Saint-Petersburg, Russia

Re: Save a STL file with multi-regions

Post by DeepSOIC »

jrt wrote:I agree 100% with cfdfoundation. Anything new on this?
I guess not much. One can make face from sketch - there is an entry for that in Part workbench menu.

STL format looks easy enough to make a macro to export an STL in custom manner (that is, write your own STL as a raw file, via python). (but don't take this as a promise I'm going to do that :P - that's unlikely)
User avatar
NormandC
Veteran
Posts: 18589
Joined: Sat Feb 06, 2010 9:52 pm
Location: Québec, Canada

Re: Save a STL file with multi-regions

Post by NormandC »

The FreeCAD developers are very few, and they work freely in their spare time. Consequently they mostly work on things that interest them. Currently there is much work on FEM. Most of FreeCAD's focus is on mechanical and architectural design.

Quite frankly, unless a new developer with interest in CFD comes in and starts contributing to FreeCAD, nothing will change.
Post Reply