Difference between revisions of "Contrib/SwiftSnap"

From OpenFOAMWiki
m (Final Notes)
(Older versions: Changed wording as it set me on the wrong foot in the previous wording)
 
(17 intermediate revisions by 4 users not shown)
Line 1: Line 1:
 
= Introduction =
 
= Introduction =
This is a plug-in which turns Blender 3D into a graphical user interface for <tt>snappyHexMesh</tt>.
+
<tt>snappyHexMesh</tt> has developed into a very capable mesher. However, each setup of snappyHexMesh requires some manual work on writing the dictionary and preparing the files. Many people already today employ Blender 3D for generation of the input geometry files for <tt>snappyHexMesh</tt>. The step is hence not very large to write an add-on for Blender which automatically generates the dictionary and relevant files. The add-on provided here does that, as well as lets the user have full control over how and which feature lines are provided to snappyHexMesh. Further, the addon utilises Blender materials to let the user specify patches’ names, resolution settings, and mesh wall layers. Compatible with snappyHexMesh in OpenFOAM 2.1.
  
;The file that has this plug-in, as well as user guide on how to use it: [[Media:Swiftsnap.tar.gz‎|Swiftsnap.tar.gz‎]]
+
The files are hosted at a git repository  https://github.com/nogenmyr/swiftSnap.git
  
;Compatible Blender versions: v2.5 and above.
+
;Compatible Blender version: v2.66 - v2.68. Unlikely to work without errors in other versions.
  
The text below is an ''improved'' transcript of the document already inside the [[Media:Swiftsnap.tar.gz‎|Swiftsnap.tar.gz‎]] tarball. These instructions also assume that the reader will get familiar with Blender on his/her own. Feel free to contribute to both this page and to the plug-in as well!
+
;Example case: [[Media:PipeExampleSnap.tar|PipeExampleSnap.tar]]
 +
 
 +
'''Note''': For older versions, check the chapter [[#Older versions|Older versions]].
  
 
For questions, problems, and similar, use the dedicated thread at the [http://www.cfd-online.com www.cfd-online.com] forum: [http://www.cfd-online.com/Forums/openfoam-meshing/100604-swiftsnap-swiftblock-guis-openfoams-meshers.html SwiftSnap and SwiftBlock, GUIs for OpenFOAM's meshers]
 
For questions, problems, and similar, use the dedicated thread at the [http://www.cfd-online.com www.cfd-online.com] forum: [http://www.cfd-online.com/Forums/openfoam-meshing/100604-swiftsnap-swiftblock-guis-openfoams-meshers.html SwiftSnap and SwiftBlock, GUIs for OpenFOAM's meshers]
  
 
<br>
 
<br>
 +
 
= Getting Started =
 
= Getting Started =
 
Untar files into your Blender add-on directory. Then start up Blender  
 
Untar files into your Blender add-on directory. Then start up Blender  
Line 20: Line 23:
 
Select your geometry object. Under the object tab in the <tt>Properties</tt> window, you should now find an entry called <tt>SwiftSnap</tt>, expand it and click the button to enable <tt>SwiftSnap</tt> for the selected object.
 
Select your geometry object. Under the object tab in the <tt>Properties</tt> window, you should now find an entry called <tt>SwiftSnap</tt>, expand it and click the button to enable <tt>SwiftSnap</tt> for the selected object.
  
The <tt>SwiftSnap</tt> entry will now expand.
+
[[File:WhereIsSwiftSnap.png]]
 +
 
 +
The <tt>SwiftSnap</tt> entry will now expand (See right side in the figure below).
  
 
Buttons / settings:
 
Buttons / settings:
;Write: Click this button last when finished. When enabled, all files (stl, eMesh, Dict) are created. Saving the state of Blender for later work is done using Blenders native save option. Note that in the save file dialogue you can click <tt>Distribute</tt>. When clicked, the <tt>triSurface</tt> directory will be placed in <tt>constant/</tt> and <tt>blockMeshDict</tt> (if enabled) in <tt>constant/polyMesh</tt>.
+
;Write: Click this button last when finished. When engaged, all files (stl, eMesh, Dict) are created. (As an extra feature, an Engrid Blender file is also written in the same directory as <tt>snappyHexMeshDict</tt>). Saving the state of Blender for later work is done using Blenders native save option. Note that in the save file dialogue you can click <tt>Distribute</tt>. When clicked, the <tt>triSurface</tt> directory will be placed in <tt>../constant/</tt> and <tt>blockMeshDict</tt> (if enabled) in <tt>../constant/polyMesh</tt>.  
  
 
;Convert to Meters: This number converts Blender spatial dimension to meters in the written files. If you want 1 Blender unit to represent <tt>1 mm</tt>, set this value to <tt>0.001</tt>.
 
;Convert to Meters: This number converts Blender spatial dimension to meters in the written files. If you want 1 Blender unit to represent <tt>1 mm</tt>, set this value to <tt>0.001</tt>.
Line 32: Line 37:
  
 
;Set <tt>locationInMesh</tt>: Sets the corresponding entry in <tt>snappyHexMeshDict</tt> to the coordinate of Blender's 3D cursor.
 
;Set <tt>locationInMesh</tt>: Sets the corresponding entry in <tt>snappyHexMeshDict</tt> to the coordinate of Blender's 3D cursor.
 +
 +
;Implicit features: snappyHexMesh can detect features by itself. To use that, enable this. The angle below is used for finding features.
  
 
;Detect non-manifold: Blender has a function to detect non-manifold edges. It can be enabled here. Good for finding problems and/or features in meshes.
 
;Detect non-manifold: Blender has a function to detect non-manifold edges. It can be enabled here. Good for finding problems and/or features in meshes.
Line 45: Line 52:
 
;Unmark selected: Removes selected edges from the list of feature edges.  
 
;Unmark selected: Removes selected edges from the list of feature edges.  
  
;Patch name: Here the user can specify a patch name, which is used when the below button is clicked.
+
;Patch name: Here the user can specify a patch name, which is used when the button below is clicked.
 +
 
 +
;Patch type: Set the patch boundary type.
  
 
;Min/max level: Specifies which refinement levels to have for this patch.
 
;Min/max level: Specifies which refinement levels to have for this patch.
Line 51: Line 60:
 
;Layers (optional): Specifies how many layers to create at this patch.
 
;Layers (optional): Specifies how many layers to create at this patch.
  
;Set patch: In <tt>Edit Mode</tt>, selected faces will be marked as a patch with individual settings. Patches are internally tracked using Blender's materials, where each material represents a unique patch. At save-out, the object (a copy of it) is split by material, and each patch/material is saved as an STL file.<br> Defined patches are listed below. Click the color box if a different color is wanted. Click the text to select faces belonging to the patch.
+
;Set patch: In <tt>Edit Mode</tt>, selected faces will be marked as a patch with individual settings. Patches are internally tracked using Blender's materials, where each material represents a unique patch. At save-out, the object (a copy of it) is split by material, and each patch/material is saved as an ascii-STL file.<br> Defined patches are listed below. Click the color box if a different color is wanted. Click the text to select faces belonging to the patch.
  
;Refinement region: Refinement regions are defined as <tt>triSurfaceMesh</tt> in <tt>snappyHexMeshDict</tt>. Other Blender mesh objects can be used as such surfaces. Create them as separate objects (do not enable <tt>SwiftSnap</tt> for those objects), and return here and fill in their names. When a valid name is entered, the set button is enabled.
+
;Refinement region: Refinement regions are defined as <tt>triSurfaceMesh</tt> in <tt>snappyHexMeshDict</tt>. Other Blender mesh objects can be used as such surfaces. Create them as separate objects (do not enable <tt>SwiftSnap</tt> for those objects), and return here and fill in their names. When a valid name is entered, the set button is enabled. Be careful not to have these refinement objects hidden when you press the "Write" button, as Blender then will output empty STL-files. Such files will cause snappyHexMesh to crash.
  
 
;Level: Sets the refinement level to be used inside/outide of the refinement region.
 
;Level: Sets the refinement level to be used inside/outide of the refinement region.
Line 72: Line 81:
  
 
Blender cannot currently read typical CAD formats, but the user frequently has to import geometries to Blender as STL files. The user typically has to use some kind of CAD tool to strip complex drawings from unnecessary details before importing the geometry in Blender.
 
Blender cannot currently read typical CAD formats, but the user frequently has to import geometries to Blender as STL files. The user typically has to use some kind of CAD tool to strip complex drawings from unnecessary details before importing the geometry in Blender.
 +
 +
;Note: Obviously, the GUI does not give the user access to all the settings available for <tt>snappyHexMesh</tt>, but many are hard coded into the python code. These are however very easy to alter, just edit the <tt>utils.py</tt> file. If the user frequently uses different values for some default setting, it will not be too hard to add an entry in the GUI for that setting - just have a look in the code!
  
 
= Example =
 
= Example =
Line 78: Line 89:
 
[[File:SwiftSnap Example T-pipe bend.jpg|thumb|450px|center]]
 
[[File:SwiftSnap Example T-pipe bend.jpg|thumb|450px|center]]
  
A T-pipe bend modelled. The grey <tt>Cylinder</tt> is a refinement region. Yellow color is walls, which will have two layers of boundary cells. Red color is inlet which will be refined two times from the base mesh. The small pipe have an inlet called <tt>stream</tt> colored in blue. Outlet patch (not seen) is green. Not that due to <tt>snappyHexMesh</tt>'s patch naming convention and Blenders STL exported, final patch names will be like <tt>inlet_exportedfromblender</tt> a simple sed-script ran after <tt>snappyHexMesh</tt> would solve that problem.
+
A T-pipe bend modelled. The grey <tt>Cylinder</tt> is a refinement region. Yellow color is walls, which will have two layers of boundary cells. Red color is inlet which will be refined two times from the base mesh. The small pipe have an inlet called <tt>stream</tt> colored in blue. Outlet patch (not seen) is green. Not that due to <tt>snappyHexMesh</tt>'s patch naming convention and Blender's STL exporter, final patch names will be like <tt>inlet_Exportedfromblender</tt>. A simple sed run,
 +
<bash>sed -i 's/_Exportedfromblender//' /path/polyMesh/boundary </bash>
 +
executed after <tt>snappyHexMesh</tt> would solve that problem, though.
  
 
= Final Notes =
 
= Final Notes =
Line 84: Line 97:
  
 
For questions, problems, and similar, use the dedicated thread at the [http://www.cfd-online.com www.cfd-online.com] forum: [http://www.cfd-online.com/Forums/openfoam-meshing/100604-swiftsnap-swiftblock-guis-openfoams-meshers.html SwiftSnap and SwiftBlock, GUIs for OpenFOAM's meshers]
 
For questions, problems, and similar, use the dedicated thread at the [http://www.cfd-online.com www.cfd-online.com] forum: [http://www.cfd-online.com/Forums/openfoam-meshing/100604-swiftsnap-swiftblock-guis-openfoams-meshers.html SwiftSnap and SwiftBlock, GUIs for OpenFOAM's meshers]
 +
 +
= Older versions =
 +
The swiftSnap GitHUb contains the newest version, to work with the newest version of Blender. Older versions of swiftSnap, to work with older versions of Blender, can be found here:
 +
{| class="wikitable" style="text-align: center;"
 +
! Compatible Blender versions || File
 +
|-
 +
| v2.6x, with x<3. <br> (Possibly also for 2.5x, but surely not for earlier). || [[Media:Swiftsnap.tar.gz|Swiftsnap.tar.gz]] <br> Note: has the original user guide.
 +
|}
 +
 +
[[Category:Blender]]
 +
[[Category:Mesh generation utilities]]

Latest revision as of 08:25, 4 January 2014

1 Introduction

snappyHexMesh has developed into a very capable mesher. However, each setup of snappyHexMesh requires some manual work on writing the dictionary and preparing the files. Many people already today employ Blender 3D for generation of the input geometry files for snappyHexMesh. The step is hence not very large to write an add-on for Blender which automatically generates the dictionary and relevant files. The add-on provided here does that, as well as lets the user have full control over how and which feature lines are provided to snappyHexMesh. Further, the addon utilises Blender materials to let the user specify patches’ names, resolution settings, and mesh wall layers. Compatible with snappyHexMesh in OpenFOAM 2.1.

The files are hosted at a git repository https://github.com/nogenmyr/swiftSnap.git

Compatible Blender version
v2.66 - v2.68. Unlikely to work without errors in other versions.
Example case
PipeExampleSnap.tar

Note: For older versions, check the chapter Older versions.

For questions, problems, and similar, use the dedicated thread at the www.cfd-online.com forum: SwiftSnap and SwiftBlock, GUIs for OpenFOAM's meshers


2 Getting Started

Untar files into your Blender add-on directory. Then start up Blender

In Blender's User Preferences, enable 'Community' add-ons, and locate SwiftSnap under the OpenFOAM category. Click to enable. Locate STL file export/import and enable. Return to 3D view.

Import / create your geometry in Blender. Keep your geometry in one single object. Use Ctrl-J to join objects

Select your geometry object. Under the object tab in the Properties window, you should now find an entry called SwiftSnap, expand it and click the button to enable SwiftSnap for the selected object.

WhereIsSwiftSnap.png

The SwiftSnap entry will now expand (See right side in the figure below).

Buttons / settings:

Write
Click this button last when finished. When engaged, all files (stl, eMesh, Dict) are created. (As an extra feature, an Engrid Blender file is also written in the same directory as snappyHexMeshDict). Saving the state of Blender for later work is done using Blenders native save option. Note that in the save file dialogue you can click Distribute. When clicked, the triSurface directory will be placed in ../constant/ and blockMeshDict (if enabled) in ../constant/polyMesh.
Convert to Meters
This number converts Blender spatial dimension to meters in the written files. If you want 1 Blender unit to represent 1 mm, set this value to 0.001.
Make base mesh
Click to auto-generate a blockMeshDict for letting blockMesh create a base mesh for snappyHexMesh. This feature uses the objects bounding box, which can be seen in Object Mode using Bounding Box as Viewport shading. When enabled, the base resolution (in meters) should be specified.
Snap mesh / add layers
These two options enable / disable the corresponding settings in snappyHexMeshDict.
Set locationInMesh
Sets the corresponding entry in snappyHexMeshDict to the coordinate of Blender's 3D cursor.
Implicit features
snappyHexMesh can detect features by itself. To use that, enable this. The angle below is used for finding features.
Detect non-manifold
Blender has a function to detect non-manifold edges. It can be enabled here. Good for finding problems and/or features in meshes.
Feature angle
For use with the button below.
Detect features
Selects all edges in-between faces with an angle less than given above.
Feature refinement level
Sets refinement level for edges. For use with the button below.
Mark as level #
Marks selected edges as features to refine to the specified level. The collection of edges are fully determined by the user, but stem frequently from the selection generated with the Detect Features button. When edges are set, they will appear at the bottom of the Feature box, from there they can be selected and modified later. Note that it is important to mark edges as features, even if no extra resolution is wanted. Without feature lines defined, snappyHexMesh will not capture the sharpness of the edges.
Unmark selected
Removes selected edges from the list of feature edges.
Patch name
Here the user can specify a patch name, which is used when the button below is clicked.
Patch type
Set the patch boundary type.
Min/max level
Specifies which refinement levels to have for this patch.
Layers (optional)
Specifies how many layers to create at this patch.
Set patch
In Edit Mode, selected faces will be marked as a patch with individual settings. Patches are internally tracked using Blender's materials, where each material represents a unique patch. At save-out, the object (a copy of it) is split by material, and each patch/material is saved as an ascii-STL file.
Defined patches are listed below. Click the color box if a different color is wanted. Click the text to select faces belonging to the patch.
Refinement region
Refinement regions are defined as triSurfaceMesh in snappyHexMeshDict. Other Blender mesh objects can be used as such surfaces. Create them as separate objects (do not enable SwiftSnap for those objects), and return here and fill in their names. When a valid name is entered, the set button is enabled. Be careful not to have these refinement objects hidden when you press the "Write" button, as Blender then will output empty STL-files. Such files will cause snappyHexMesh to crash.
Level
Sets the refinement level to be used inside/outide of the refinement region.
Distance
Sets the distance from the surface, in which refinement to the level specified above is done. (snappyHexMesh allows for one surface to have several refinement levels at different distance. This is currently not supported by SwiftSnap.)
Refine inside
If clicked, refinement will take place inside the surface.
Set refinement region
When clicked the above given object will be used as a refinement triSurface object in snappyHexMesh with the given settings. If the object is found, it will be added to a list below the button. Click list items to remove them.

2.1 General notes

SwiftSnap frequently switches the users selection and view mode. This is because different operations require different such settings. The user is also likely to jump between Edit Mode and Object Mode (Tab key). In Edit Mode, manipulation on the mesh can be performed, while in Object Mode, manipulation on the object as a whole can be performed. In Edit Mode, the user have good use of switching between Vertex/Edge/Face selection mode (Ctrl-Tab). For instance, use edge selection to modify feature edges, or use face selection to specify patches.

Blender has some functions for making clever selections of mesh components. Refer to Blender's wiki about selection for how to work efficiently. For example:

Ctrl+NumPadPlus
select neighbours
Ctrl+Alt+Shift+F
select based on angle
Alt+RMB
edge loops

Blender cannot currently read typical CAD formats, but the user frequently has to import geometries to Blender as STL files. The user typically has to use some kind of CAD tool to strip complex drawings from unnecessary details before importing the geometry in Blender.

Note
Obviously, the GUI does not give the user access to all the settings available for snappyHexMesh, but many are hard coded into the python code. These are however very easy to alter, just edit the utils.py file. If the user frequently uses different values for some default setting, it will not be too hard to add an entry in the GUI for that setting - just have a look in the code!

3 Example

3.1 T-pipe bend

SwiftSnap Example T-pipe bend.jpg

A T-pipe bend modelled. The grey Cylinder is a refinement region. Yellow color is walls, which will have two layers of boundary cells. Red color is inlet which will be refined two times from the base mesh. The small pipe have an inlet called stream colored in blue. Outlet patch (not seen) is green. Not that due to snappyHexMesh's patch naming convention and Blender's STL exporter, final patch names will be like inlet_Exportedfromblender. A simple sed run,

sed -i 's/_Exportedfromblender//' /path/polyMesh/boundary

executed after snappyHexMesh would solve that problem, though.

4 Final Notes

Feel free to contribute to this page and improvements to the scripts!

For questions, problems, and similar, use the dedicated thread at the www.cfd-online.com forum: SwiftSnap and SwiftBlock, GUIs for OpenFOAM's meshers

5 Older versions

The swiftSnap GitHUb contains the newest version, to work with the newest version of Blender. Older versions of swiftSnap, to work with older versions of Blender, can be found here:

Compatible Blender versions File
v2.6x, with x<3.
(Possibly also for 2.5x, but surely not for earlier).
Swiftsnap.tar.gz
Note: has the original user guide.