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

User avatar
wandererfan
Veteran
Posts: 6324
Joined: Tue Nov 06, 2012 5:42 pm
Contact:

Re: Save a STL file with multi-regions

Post by wandererfan »

User avatar
virengos
Posts: 8
Joined: Fri Oct 14, 2016 9:56 am
Location: Germany
Contact:

Re: Save a STL file with multi-regions

Post by virengos »

I just came across this topic, and would like to contribute my own thoughts on the matter.
One other possibility is to export all the single regions to separate files and merge it outside of FreeCAD by using the 'cat' command in terminal (when using Linux) or the 'type' command (when using Windows).

cat obj1.stl ob2.stl obj3.stl > all_obj.stl

That's my approach, and it works for me when dealing with Open FOAM, meshing and CFD.

OS: Windows 7
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.16.6706 (Git)
Build type: Release
Branch: releases/FreeCAD-0-16
Hash: f86a4e411ff7848dea98d7242f43b7774bee8fa0
Python version: 2.7.8
Qt version: 4.8.7
Coin version: 4.0.0a
OCC version: 6.8.0.oce-0.17
fynn
Posts: 1
Joined: Tue Jan 24, 2017 12:23 pm

Re: Save a STL file with multi-regions

Post by fynn »

Hi,

I am facing the same issue as many cfd-people in this forum: For flow simulations in OpenFoam I need to be able to export the surfaces of my geometry individually as either .stl or .obj files, since the different surfaces will be assigned to different boundary conditions. As virengos suggests, the files can then be collected or imported to OpenFoam individually.
The big advantage of freeCad for cfd applications would be the treatment of geometry surfaces as part objects allowing their individual export.
This is the one reason why I tested freeCad. Until now, only the cad editor of Comsol Multiphysics allows me to do just that.
jbi
Posts: 118
Joined: Sun Apr 24, 2016 3:28 pm

Re: Save a STL file with multi-regions

Post by jbi »

Hi,

I just stumbled across this thread. If I understand it right, only a Export of each single face of a shape is needed. This can be done with a macro.

Code: Select all

# Purpose:     export each face of a selected shape to .stl file

#paste the import statements first:
import FreeCADGui
from FreeCAD import Base, Console
import FreeCAD
import Part
import DraftGeomUtils
import Draft
import time
import math
import os

#pre work: just create a folder tmp in FreeCAD 0.15 folder, single faces will be saved here

#first: select the shape for exporting and paste this 2 lines into the console and hit enter
sw = FreeCADGui.Selection.getSelectionEx()[0]
obj = sw.Object.Shape

#second: paste following lines into the console
for face in obj.Faces:
	unique=str(time.time())
	hash=str(face.hashCode())
	#edit your filename here
	filename='D:\\Anwenderprogramme\\FreeCAD 0.15\\tmp\\001_TIME_'+unique+'_Hash_'+hash+'.stl' #create unique filename
	face.exportStl(filename,0.3) 
	"""
	parameters for stl export can be found here: search "exportSTL"
	at https://github.com/FreeCAD/FreeCAD/blob/4664e5bb483404b064e8de59ce0ca3161482e9a1/src/Mod/Part/App/TopoShapePyImp.cpp
	"""

#single file for each face is created in D:\\Anwenderprogramme\\FreeCAD 0.15\\tmp folder

####################################################################
####################################################################

#single faces can be selected too, just select the face of interest:
sf = FreeCADGui.Selection.getSelectionEx()[0]
face=sf.SubObjects[0]	#sf.Object.Shape

unique=str(time.time())
hash=str(face.hashCode())
#edit your filename here
filename='D:\\Anwenderprogramme\\FreeCAD 0.15\\tmp\\001_TIME_'+unique+'_Hash_'+hash+'.stl' #create unique filename
face.exportStl(filename,0.3) 

You can also create a macro and add a button to the gui. A lot of Information how this can be done can be found here and https://www.freecadweb.org/wiki/Online_Help_Toc here.

I hope this helps.
johan
Posts: 14
Joined: Tue Nov 29, 2016 8:37 pm

Re: Save a STL file with multi-regions

Post by johan »

The new CFD WB might provide some help in this regard: https://forum.freecadweb.org/viewtopic. ... 6&start=40

It creates a multi-element stl instead of exporting separate stl files for the faces. This ensures a watertight geometry and allows for feature edge extraction.
User avatar
bernd
Veteran
Posts: 12851
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland
Contact:

Re: Save a STL file with multi-regions

Post by bernd »

this is may be interesting in the regard of this topic ... https://forum.freecadweb.org/viewtopic.php?f=3&t=16855
mmohaqeqf
Posts: 4
Joined: Sun Dec 13, 2020 4:25 am

Re: Save a STL file with multi-regions

Post by mmohaqeqf »

johan wrote: Thu Jun 01, 2017 9:14 am The new CFD WB might provide some help in this regard: https://forum.freecadweb.org/viewtopic. ... 6&start=40

It creates a multi-element stl instead of exporting separate stl files for the faces. This ensures a watertight geometry and allows for feature edge extraction.
Does anybody know how this thing works?
julieng
Posts: 106
Joined: Sun Nov 25, 2018 8:57 pm

Re: Save a STL file with multi-regions

Post by julieng »

Hello,

I am looking for a (quite simple) procedure via FreeCAD generating STL files and surface/ Volume patches to mesh multibodies geometry using snappyHexMesh.
Is there something already existing?
I found a lot of solutions on cfdonline but I am a little bit lost..

Best regards

Julien
amuzeshi
Posts: 13
Joined: Tue Jan 14, 2020 7:08 pm

Re: Save a STL file with multi-regions

Post by amuzeshi »

cfdfoundation wrote: Sat Jan 10, 2015 4:39 pm 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)
Not sure if it is still an issue. But if you want to convert a single STL to a multi-region STL, simply use

Code: Select all

surfaceAutoPatch
in OpenFOAM.
Post Reply