Difference between revisions of "Contrib/SwiftSnap"

From OpenFOAMWiki
m (Added mesh generation category)
Line 5: Line 5:
 
The files have since August 25:th moved to a git repository  https://github.com/nogenmyr/swiftSnap.git
 
The files have since August 25:th moved to a git repository  https://github.com/nogenmyr/swiftSnap.git
  
;Compatible Blender versions: v2.6x, with x<3. (Possibly also for 2.5x, but surely not for earlier)
+
;Compatible Blender versions: v2.64
  
 
;Example case: [[Media:PipeExampleSnap.tar|PipeExampleSnap.tar]]‎
 
;Example case: [[Media:PipeExampleSnap.tar|PipeExampleSnap.tar]]‎
  
 
'''Note''': For older versions, check the chapter [[#Older versions|Older versions]].
 
'''Note''': For older versions, check the chapter [[#Older versions|Older versions]].
 
The text below is an ''improved'' transcript of the document already inside the original [[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!
 
  
 
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]

Revision as of 13:26, 14 October 2012

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.

The file that has this plug-in
SwiftSnap.tar‎

The files have since August 25:th moved to a git repository https://github.com/nogenmyr/swiftSnap.git

Compatible Blender versions
v2.64
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.

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. 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.
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.
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

Here is a list of files of older versions of SwiftSnap:

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.