Difference between revisions of "Contrib/SwiftBlock"

From OpenFOAMWiki
m (Introduction: 2.6x, with x<3)
 
(14 intermediate revisions by 3 users not shown)
Line 1: Line 1:
 +
''An unstructured approach to block structured meshing.''
 +
 +
= Note =
 +
This page describes the original version of SwiftBlock for Blender 2.7 series. New upgraded version for Blender 2.8 series is at https://github.com/tkeskita/swiftBlock with upgraded documentation and tutorial example.
  
 
= Introduction =
 
= Introduction =
 
While <tt>blockMesh</tt> is a rather sophisticated mesher, it remains largely inaccessible unless users script the creation of the input file, <tt>blockMeshDict</tt>. Such scripts tend however to be problem specific, and general tools have not shown up publicly to date. The add-on provided here tries to remedy this by letting the user create the desired hexahedral block structure as a mesh object within Blender 3D. Then, using a graph theory based method<ref>A. Gaither, An Efficient Block Detection Algorithm For Structured Grid Generation.
 
While <tt>blockMesh</tt> is a rather sophisticated mesher, it remains largely inaccessible unless users script the creation of the input file, <tt>blockMeshDict</tt>. Such scripts tend however to be problem specific, and general tools have not shown up publicly to date. The add-on provided here tries to remedy this by letting the user create the desired hexahedral block structure as a mesh object within Blender 3D. Then, using a graph theory based method<ref>A. Gaither, An Efficient Block Detection Algorithm For Structured Grid Generation.
Proc. 5th Int. Conf. Num. Grid Generation in Comp. Field Simulations, pp. 443-451 (1996)</ref>, the discrete blocks in the users mesh object are identified, and the vertices and block entries for <tt>blockMeshDict</tt> are generated. The add-on also allows the user to set block's edges by specifying a separate Blender object in-which a shortest path algorithm<ref>E. W. Dijkstra, A note on two problems in connexion with graphs. Numerische Mathematik 1, pp. 269–271 (1959)</ref> is used to find the connection between the two vertices for the edge. Lastly, the addon uses Blender materials environment to allow the user to specify patch types and names. Spatial resolution of the generated mesh is set to match a user given resolution.
+
Proc. 5th Int. Conf. Num. Grid Generation in Comp. Field Simulations, pp. 443-451 (1996)</ref>, the discrete blocks in the users mesh object are identified, and the vertices and block entries for <tt>blockMeshDict</tt> are generated. The add-on also allows the user to set block's edges by specifying a separate Blender object in-which a shortest path algorithm is used to find the connection between the two vertices for the edge. Lastly, the addon uses Blender materials environment to allow the user to specify patch types and names. Spatial resolution of the generated mesh is set to match a user given resolution. The user may however override this on selected edges, if needed. The user may also define edge grading, as well as naming of blocks (to create cellZones/Sets).
 +
 
 +
The files are hosted at a git repository: https://github.com/nogenmyr/swiftBlock.git
  
;The file that has this plug-in, as well as user guide on how to use it: [[Media:Swiftblock.tar.gz|Swiftblock.tar.gz]]
+
Another fork is available at: https://github.com/flowkersma/swiftBlock - which provides additional the features listed [http://www.cfd-online.com/Forums/openfoam-meshing/100604-swiftsnap-swiftblock-guis-openfoams-meshers-11.html#post562184 here].
  
;Compatible Blender versions: v2.6x, with x<3. (Possibly also for 2.5x, but surely not for earlier).
+
;Compatible Blender version: v2.66a. Unlikely to work without errors in other versions.
  
 
;Example cases: [[Media:SwiftBlockExample.tar|Structural part]],  [[Media:Pipeblock.tar‎|T-junction pipe]]
 
;Example cases: [[Media:SwiftBlockExample.tar|Structural part]],  [[Media:Pipeblock.tar‎|T-junction pipe]]
  
The text below is an ''improved'' transcript of the document already inside the [[Media:Swiftblock.tar.gz|Swiftblock.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!
+
Please note that the instructions below assumes 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]
Line 17: Line 23:
  
 
= Getting Started =
 
= Getting Started =
 +
Under your Blender installation directory locate the /scripts/addons directory. There create directory swiftBlock. Put the *.py files in there. In Blender's User Preferences, enable 'Community' addons, and locate SwiftBlock under the OpenFOAM category. Click to enable and return to 3D view.
  
Untar files into your Blender add-on directory. Then start up Blender.
+
Select an object which will represent your block structure. For example, this could be the Blender default box. Under the object tab in the Properties window, you should now find an entry called SwiftBlock, expand it and click the button to enable SwiftBlock for the selected object. The SwiftBlock entry will now expand. (See right side in the figure below).
 +
Blender will also switch to Edit mode. You may at any time switch between Edit and Object mode by pressing Tab key while having the mouse pointer in the 3D view pane.  
  
In Blender's User Preferences, enable 'Community' addons, and locate <tt>SwiftBlock</tt> under the <tt>OpenFOAM</tt> category. Click to enable and return to <tt>3D view</tt>.
 
  
Select an object which will represent your block structure. This could be the Blender default box. Under the object tab in the <tt>Properties</tt> window, you should now find an entry called <tt>SwiftBlock</tt>, expand it and click the button to enable <tt>SwiftBlock</tt> for the selected object.
+
Buttons / settings:
  
The <tt>SwiftBlock</tt> entry will now expand. (See right side in the figure below).  
+
'''Write''' - Generates and writes out the blockMeshDict. Be patient while the algorithm identifies the blocks, as this may take some time for large structures. The number of cells in the mesh is written in the Info Window.
  
Blender will also switch to <tt>Edit mode</tt>. You may at any time switch between <tt>Edit</tt> and <tt>Object mode</tt> by pressing <tt>Tab</tt> key while having the mouse pointer in the 3D view pane.
+
'''Preview''' - Generates a surface mesh corresponding to the mesh blockMesh would generate with the current state of your block structure. If you in Edit mode have selected just a subset of vertices, only blocks formed by them will be previewed. Please note that any modifications made to the preview mesh does not affect the mesh later generated by blockMesh. This is strictly preview. The total number of cells in the mesh is written in the Info Window.
  
Buttons / settings:
+
'''Diagnose''' - Pressing this button, the blocks present will be identified, and any edges in your structure, which does not contribute to forming blocks will be selected. These typically indicate some problem with the structure.
;Write: Generates and writes out the <tt>blockMeshDict</tt>. Be patient while the algorithm identifies the blocks, as this may take seveal minutes for large structures.
+
  
;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 1 mm, set this value to 0.001.  
  
;Resolution: This is the desired resolution you wish for the generated block mesh. As many edges usually are inter-dependent, a mean resolution is sought for.  
+
'''Resolution''' - This is the desired resolution you wish for the generated block mesh. As many edges usually are inter-dependent, a mean resolution is sought for.  
  
;Set edges: When clicked, type in the name the object from which edges will be fetched. If an edge in your block structure has both vertices co-located with vertices from the typed object, <tt>SwiftBlock</tt> will find out the closest path in the mesh of the object, and use this path as a <tt>polyLine</tt> in the <tt>blockMeshDict</tt>. By this way, you can fit your block structure to more general geometries. Be aware though, that <tt>SwiftBlock</tt> may find unexpected paths, and sometimes you might need to do some cutting in the <tt>Geometry</tt> object and/or add straight lines to it. Also note that <tt>blockMesh</tt> does not currently allow the user to specify the shape of surfaces. This implies some limits on which shapes that could be meshed. Sometimes, the user may circumvent it by dividing the block structure into more blocks.
+
'''Set edges''' - When clicked, type in the name of the (polyLine) object from which curved edges will be fetched. If an edge in your block structure has both it's vertices snapped to a vertex or an edge from the polyLine object, SwiftBlock will find out the closest path in the mesh of the object, and use this path as a polyLine in the blockMeshDict. By this way, you can fit your block structure to more general geometries. Be aware though, that SwiftBlock may find unexpected paths. You can also tell an edge in your block structure explicitly not follow the path found in the polyLine object by selecting it and press '''Straight'''. (Undo by pressing '''Curved'''). To snap a vertex onto another vertex or edge, use the magnetic tool in Blender. Note that blockMesh does not currently allow the user to specify the shape of surfaces. This implies some limits on which shapes that could be meshed. Sometimes, the user may circumvent it by dividing the block structure into more blocks.  
  
;Patch name: 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. Defined patches appear at the bottom of the Patch settings box. Click the color box if a different color is wanted. Click the text to select faces belonging to the patch. If a Blender face is missing in your wire frame block structure, select the four vertices defining the face and hit <tt>F</tt>.
+
'''# cells / Force resolution''' - In Edit mode and edge selection mode (Ctrl-Tab) you can force a certain resolution onto selected edge(s). The code will force inter-dependent edges to the same resolution, so for instance in a 2D-mesh it is enough to set just one of the edges in the non-calculated direction to 1, and all coupled blocks will have just one cell in that direction. Setting a forced edge to 0 disables the forcing, and the resolution is determined as by default.  
  
;Patch type: When setting at patch, you may define it's type here.
+
'''Grading / Flip edge / Set grading / Coarse | Fine''' - In Edit mode and edge selection mode (Ctrl-Tab) you can specify grading to edges. First find out orientation of each edge by selecting and pressing Ctrl-Alt-Space. If you specified a grading larger than 1, cells will become coarser in the edge's z-direction. You can set several edges at one time. If you feel that an edge is pointing in the wrong direction you can flip that edge with the Flip edge button. Else you can specify an inverted grading just for that edge. Choice is yours, the resulting mesh is the same. You can also choose which cells on the graded edge that should meet the target resolution; select Fine or Coarse before pressing "Set grading".
  
;Set name: Sets the selected faces according to the name and type given above.
+
'''Edge settings''' - Allows you to see/edit settings for an individual edge.
 +
 
 +
'''Patch name''' - In Edit Mode and face selection mode(Ctrl-Tab), 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. Defined patches appear at the bottom of the Patch settings box. Click the color box if a different color is wanted. Click the text to select faces belonging to the patch. If a Blender face is missing in your wire frame block structure, select the four vertices defining the face and hit F.
 +
 
 +
'''Patch type''' - When setting at patch, you may define it's type here.
 +
 
 +
'''Set name''' Sets the selected faces according to the name and type given above.
 +
 
 +
'''Repair''' When clicked you will be asked if internal (Blender) faces should be removed and if missing (Blender) patch faces should be created. You can also chose which patch the newly created faces should belong to.
 +
 
 +
'''Block's name settings''' - This is simply an interface to Blenders Vertex Group also found under the "Object Data" tab. If all vertices in a block are members of the same Vertex Group, the block will be named as the group (and blockMesh will create cellZones/Sets). If all vertices are members of several groups, the name from the group appearing first in the list will be used. Vertex groups are sometimes used by experienced Blender users to create objects. To allow for such usage, SwiftBlock will ignore groups whose name starts with an under score "_". If all vertices belongs to a group named "disabled", that block will not be present in the blockMeshDict (or preview mesh). This is particulary useful when meshing, for instance, annualar pipes. See the structural part example.
 +
 
 +
'''Invisible feature''' Press space and write "Insert smoother" when you have selected two or more edges in your block structure. This will add a smooth line to the geometry object for each edge. This is particulary useful for stretching the center block in a O-block structure. Note that the mouse pointer has to be in the 3D View port when pressing the space button.
 +
 
 +
Now use your Blender skills to create your block structure. Be aware that Blender may sometimes drop internal edges in your block structure (after all, it is a surface modelling tool). Recreate edges by selecting two vertices and press F.  
  
Now use your Blender skills to create your block structure. Be aware that Blender may sometimes drop internal edges in your block structure (after all, it is a surface modelling tool). Recreate edges by selecting two vertices and press <tt>F</tt>.
 
  
 
== General notes ==
 
== General notes ==
<tt>SwiftBlock</tt> does not support:  
+
'''
 +
SwiftBlock does not support:'''
 +
 
 
* Creation of wedges, only strictly hexahedral blocks are handled  
 
* Creation of wedges, only strictly hexahedral blocks are handled  
* Edge grading
+
* Other types of edge definitions except polyLine and straight lines
* Other types of edge definitions except <tt>polyLine</tt>
+
* More complete description of patches than name and type
* More complete description of patches than name and type  
+
* mergePatches feature (though you can easily add it yourself in the Dict)
  
If your block structure fails, for instance finding more or less blocks than expected, there are some help files generated:
+
'''Trouble shooting'''
* <tt>log.swiftblock</tt> will give you some more detailed output of the block detection.
+
* The <tt>facesFound.obj</tt> file can be opened in ParaView and shows all the quad-faces that were found (the algorithm first finds loops of 4 connected vertices, then using these 'faces' it finds hexahedral blocks consisting of 6 such 'faces'). As of OpenFOAM 2.0.0, you can use ParaView to open the <tt>openInParaview.blockMesh</tt> file. When placed in your <tt>$FOAM_CASE</tt> directory, it will use ParaView to graphically represent the content in the <tt>blockMeshDict</tt> file. This is of great value when debugging <tt>blockMeshDict</tt>s.
+
  
  '''Side note''': From the command line, one can view the <tt>blockMeshDict</tt> in ParaView by running: <code>paraFoam -block</code>
+
* First use the diagnose button to see if your block structure is OK. Double vertices and edges are generally not recommended, but may sometimes be useful for creating internal baffles.
  But keep in mind that this requires that OpenFOAM's official plug-ins are properly compiled.
+
* Does the preview mesh looks fine?
 +
* A frequent problem is that collected polyLines where not as expected. If you collect polyLines from an object which was generated by full revolution of Blenders spin function, note that the first and last vertices are not connected. Use remove doubles on that object to resolve this.
 +
* You can see where each polyLine comes by selecting the polyLine object and entering Edit mode. Select the two vertices that marks the start and end of the polyLine, and then chose '''Vertex Path''' from the '''Select''' menu. This executes the same code as used in swiftBlock.
 +
* If you collect polyLines from object named, for instance, "geom", make sure that no other object is called "geom.001".
 +
* At Write, log.swiftblock can give you some more detailed output of the block detection. To enable logging, tick the "log" box in the Write dialogue.
 +
* The facesFound.obj file (also written at logging) can be opened in ParaView and shows all the quad-faces that were found (the algorithm first finds loops of 4 connected vertices, then using these 'faces' it finds hexahedral blocks consisting of 6 such 'faces').
 +
* From the command line, one can view the blockMeshDict in ParaView by running: "paraFoam -block". Keep in mind that this requires that OpenFOAM's official plug-ins are properly compiled.
  
<br>
 
Some block structures are tricky. For instance, the classical way of block meshing a cylinder is to divide it into 5 blocks. One center and four outer blocks. However, a hexa-block finding algorithm will find 8 formal blocks in that structure! Except the 5 wanted/obvious, there is one flat block structure at either end of the cylinder, and one block is defined by the outermost egdes in the structure. The <tt>SwiftBlock</tt> code does several steps to detect and rule out such spurious blocks. As the code is rather new though, this filtering might cause some unexpected behaviour.
 
  
To co-locate a block vertex with a vertex of a <tt>Geometry</tt> object (to allow for non-straight block edges), use Blender's snapping magnet in vertex mode.  
+
Some block structures are tricky. For instance, the classical way of block meshing a cylinder is to divide it into 5 blocks. One center and four outer blocks. However, a hexa-block finding algorithm will find 8 formal blocks in that structure! Except the 5 wanted/obvious, there is one flat block structure at either end of the cylinder, and one block is defined by the outermost egdes in the structure. The SwiftBlock code does several steps to detect and rule out such spurious blocks. As the code is rather new though, this filtering might cause some unexpected behaviour.  
  
Be careful when creating your block structure not to have two co-located vertices. To avoid this <tt>SwiftBlock</tt> by default enables <tt>AutoMerge</tt> editing. You can also select your whole block structure and use the <tt>Remove Doubles</tt> tool to handle this (in <tt>Edit Mode</tt>).
+
To co-locate a block vertex with a vertex of a Geometry object (to allow for non-straight block edges), use Blender's snapping magnet in vertex mode.  
  
It is convenient to set view mode as wireframe, as you then can see through faces. Using the <tt>Z</tt> key you can also switch to <tt>Viewport mode</tt>.
+
Be careful when creating your block structure not to have two co-located vertices. To avoid this SwiftBlock by default enables AutoMerge editing. You can also select your whole block structure and use the Remove Doubles tool to handle this (in Edit Mode).  
  
You do not have to create outer faces in your block structure. The block finding algorithm does not consider Blender's faces. Blender faces are only used for setting up patches, and if absent, <tt>blockMesh</tt> will push non-defined patches into <tt>defaultPatches</tt>.
+
It is convenient to set view mode as wireframe, as you then can see through faces. Using the Z key you can also switch to Viewport mode.
 +
You do not have to create outer faces in your block structure. The block finding algorithm does not consider Blender's faces. Blender faces are only used for setting up patches, and if absent, blockMesh will push non-defined patches into the defaultFaces patch.  
  
When working with <tt>SwiftBlock</tt>, keep in mind to only use mesh objects as block structure and <tt>Geometry</tt> object. There is no support for <tt>NURBS</tt>.
+
When working with SwiftBlock, keep in mind to only use mesh objects as block structure and Geometry object. There is no support for NURBS.  
  
= Example =
+
 
 +
= Examples =
 
== Meshing a cylinder ==
 
== Meshing a cylinder ==
  
 
[[File:SwiftBlock Example Cylinder.jpg|thumb|450px|center]]
 
[[File:SwiftBlock Example Cylinder.jpg|thumb|450px|center]]
  
The highlighted (yellow glow) object has the block structure of a typical cylinder mesh. Its corner vertices are co-located with the vertices of another Blender object, “Cylinder”, seens as a black wire frame. As “Set edges” is enabled and the name “Cylinder” was given, blockMeshDict will now contain entries for setting the block edges. Three patches are defined (defaultName has no users here), inlet, outlet, and wall. As the Viewport is in transparent Edit Mode, the patches's colors are not seen.  
+
The highlighted (yellow glow) object has the block structure of a typical cylinder mesh. Its corner vertices are co-located with the vertices of another Blender object, “Cylinder”, seens as a black wire frame. As “Set edges” is enabled and the name “Cylinder” was given, blockMeshDict will now contain entries for setting the block edges. Three patches are defined (defaultName has no users here), inlet, outlet, and wall. As the Viewport is in transparent Edit Mode, the patches's colors are not seen.
 +
 
 +
== Using new features that are available in OpenFOAM 2.4.0 ==
 +
 
 +
Complete details provided at this post: [http://www.cfd-online.com/Forums/openfoam-meshing/100604-swiftsnap-swiftblock-guis-openfoams-meshers-11.html#post562184 SwiftSnap and SwiftBlock, GUIs for OpenFOAM's meshers - post #213]
 +
 
 +
In summary:
 +
* Short example video which shows how to use the multi-grading and copy to parallel edges: https://www.youtube.com/watch?v=bwrfuQVQ7gI
 +
* Another video which shows how to mesh bended pipe with o-grid http://youtu.be/ZY7WDP6w7YA
  
 +
Both videos require the source code provided in this fork of SwiftBlock: https://github.com/flowkersma/swiftBlock
  
 
= Final Notes =
 
= Final Notes =
Line 87: Line 121:
 
= References =
 
= References =
 
<references/>
 
<references/>
 +
 +
= Older versions =
 +
Here is a list of files of older versions of <tt>SwiftBlock</tt>:
 +
{| 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:Swiftblock.tar.gz|Swiftblock.tar.gz]] <br> Note: has the original user guide.
 +
|}
  
 
[[Category:Blender]]
 
[[Category:Blender]]
 +
[[Category:Mesh generation utilities]]

Latest revision as of 09:16, 28 April 2019

An unstructured approach to block structured meshing.

1 Note

This page describes the original version of SwiftBlock for Blender 2.7 series. New upgraded version for Blender 2.8 series is at https://github.com/tkeskita/swiftBlock with upgraded documentation and tutorial example.

2 Introduction

While blockMesh is a rather sophisticated mesher, it remains largely inaccessible unless users script the creation of the input file, blockMeshDict. Such scripts tend however to be problem specific, and general tools have not shown up publicly to date. The add-on provided here tries to remedy this by letting the user create the desired hexahedral block structure as a mesh object within Blender 3D. Then, using a graph theory based method[1], the discrete blocks in the users mesh object are identified, and the vertices and block entries for blockMeshDict are generated. The add-on also allows the user to set block's edges by specifying a separate Blender object in-which a shortest path algorithm is used to find the connection between the two vertices for the edge. Lastly, the addon uses Blender materials environment to allow the user to specify patch types and names. Spatial resolution of the generated mesh is set to match a user given resolution. The user may however override this on selected edges, if needed. The user may also define edge grading, as well as naming of blocks (to create cellZones/Sets).

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

Another fork is available at: https://github.com/flowkersma/swiftBlock - which provides additional the features listed here.

Compatible Blender version
v2.66a. Unlikely to work without errors in other versions.
Example cases
Structural part, T-junction pipe

Please note that the instructions below assumes 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 www.cfd-online.com forum: SwiftSnap and SwiftBlock, GUIs for OpenFOAM's meshers


3 Getting Started

Under your Blender installation directory locate the /scripts/addons directory. There create directory swiftBlock. Put the *.py files in there. In Blender's User Preferences, enable 'Community' addons, and locate SwiftBlock under the OpenFOAM category. Click to enable and return to 3D view.

Select an object which will represent your block structure. For example, this could be the Blender default box. Under the object tab in the Properties window, you should now find an entry called SwiftBlock, expand it and click the button to enable SwiftBlock for the selected object. The SwiftBlock entry will now expand. (See right side in the figure below). Blender will also switch to Edit mode. You may at any time switch between Edit and Object mode by pressing Tab key while having the mouse pointer in the 3D view pane.


Buttons / settings:

Write - Generates and writes out the blockMeshDict. Be patient while the algorithm identifies the blocks, as this may take some time for large structures. The number of cells in the mesh is written in the Info Window.

Preview - Generates a surface mesh corresponding to the mesh blockMesh would generate with the current state of your block structure. If you in Edit mode have selected just a subset of vertices, only blocks formed by them will be previewed. Please note that any modifications made to the preview mesh does not affect the mesh later generated by blockMesh. This is strictly preview. The total number of cells in the mesh is written in the Info Window.

Diagnose - Pressing this button, the blocks present will be identified, and any edges in your structure, which does not contribute to forming blocks will be selected. These typically indicate some problem with the structure.

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.

Resolution - This is the desired resolution you wish for the generated block mesh. As many edges usually are inter-dependent, a mean resolution is sought for.

Set edges - When clicked, type in the name of the (polyLine) object from which curved edges will be fetched. If an edge in your block structure has both it's vertices snapped to a vertex or an edge from the polyLine object, SwiftBlock will find out the closest path in the mesh of the object, and use this path as a polyLine in the blockMeshDict. By this way, you can fit your block structure to more general geometries. Be aware though, that SwiftBlock may find unexpected paths. You can also tell an edge in your block structure explicitly not follow the path found in the polyLine object by selecting it and press Straight. (Undo by pressing Curved). To snap a vertex onto another vertex or edge, use the magnetic tool in Blender. Note that blockMesh does not currently allow the user to specify the shape of surfaces. This implies some limits on which shapes that could be meshed. Sometimes, the user may circumvent it by dividing the block structure into more blocks.

# cells / Force resolution - In Edit mode and edge selection mode (Ctrl-Tab) you can force a certain resolution onto selected edge(s). The code will force inter-dependent edges to the same resolution, so for instance in a 2D-mesh it is enough to set just one of the edges in the non-calculated direction to 1, and all coupled blocks will have just one cell in that direction. Setting a forced edge to 0 disables the forcing, and the resolution is determined as by default.

Grading / Flip edge / Set grading / Coarse | Fine - In Edit mode and edge selection mode (Ctrl-Tab) you can specify grading to edges. First find out orientation of each edge by selecting and pressing Ctrl-Alt-Space. If you specified a grading larger than 1, cells will become coarser in the edge's z-direction. You can set several edges at one time. If you feel that an edge is pointing in the wrong direction you can flip that edge with the Flip edge button. Else you can specify an inverted grading just for that edge. Choice is yours, the resulting mesh is the same. You can also choose which cells on the graded edge that should meet the target resolution; select Fine or Coarse before pressing "Set grading".

Edge settings - Allows you to see/edit settings for an individual edge.

Patch name - In Edit Mode and face selection mode(Ctrl-Tab), 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. Defined patches appear at the bottom of the Patch settings box. Click the color box if a different color is wanted. Click the text to select faces belonging to the patch. If a Blender face is missing in your wire frame block structure, select the four vertices defining the face and hit F.

Patch type - When setting at patch, you may define it's type here.

Set name Sets the selected faces according to the name and type given above.

Repair When clicked you will be asked if internal (Blender) faces should be removed and if missing (Blender) patch faces should be created. You can also chose which patch the newly created faces should belong to.

Block's name settings - This is simply an interface to Blenders Vertex Group also found under the "Object Data" tab. If all vertices in a block are members of the same Vertex Group, the block will be named as the group (and blockMesh will create cellZones/Sets). If all vertices are members of several groups, the name from the group appearing first in the list will be used. Vertex groups are sometimes used by experienced Blender users to create objects. To allow for such usage, SwiftBlock will ignore groups whose name starts with an under score "_". If all vertices belongs to a group named "disabled", that block will not be present in the blockMeshDict (or preview mesh). This is particulary useful when meshing, for instance, annualar pipes. See the structural part example.

Invisible feature Press space and write "Insert smoother" when you have selected two or more edges in your block structure. This will add a smooth line to the geometry object for each edge. This is particulary useful for stretching the center block in a O-block structure. Note that the mouse pointer has to be in the 3D View port when pressing the space button.

Now use your Blender skills to create your block structure. Be aware that Blender may sometimes drop internal edges in your block structure (after all, it is a surface modelling tool). Recreate edges by selecting two vertices and press F.


3.1 General notes

SwiftBlock does not support:

  • Creation of wedges, only strictly hexahedral blocks are handled
  • Other types of edge definitions except polyLine and straight lines
  • More complete description of patches than name and type
  • mergePatches feature (though you can easily add it yourself in the Dict)

Trouble shooting

  • First use the diagnose button to see if your block structure is OK. Double vertices and edges are generally not recommended, but may sometimes be useful for creating internal baffles.
  • Does the preview mesh looks fine?
  • A frequent problem is that collected polyLines where not as expected. If you collect polyLines from an object which was generated by full revolution of Blenders spin function, note that the first and last vertices are not connected. Use remove doubles on that object to resolve this.
  • You can see where each polyLine comes by selecting the polyLine object and entering Edit mode. Select the two vertices that marks the start and end of the polyLine, and then chose Vertex Path from the Select menu. This executes the same code as used in swiftBlock.
  • If you collect polyLines from object named, for instance, "geom", make sure that no other object is called "geom.001".
  • At Write, log.swiftblock can give you some more detailed output of the block detection. To enable logging, tick the "log" box in the Write dialogue.
  • The facesFound.obj file (also written at logging) can be opened in ParaView and shows all the quad-faces that were found (the algorithm first finds loops of 4 connected vertices, then using these 'faces' it finds hexahedral blocks consisting of 6 such 'faces').
  • From the command line, one can view the blockMeshDict in ParaView by running: "paraFoam -block". Keep in mind that this requires that OpenFOAM's official plug-ins are properly compiled.


Some block structures are tricky. For instance, the classical way of block meshing a cylinder is to divide it into 5 blocks. One center and four outer blocks. However, a hexa-block finding algorithm will find 8 formal blocks in that structure! Except the 5 wanted/obvious, there is one flat block structure at either end of the cylinder, and one block is defined by the outermost egdes in the structure. The SwiftBlock code does several steps to detect and rule out such spurious blocks. As the code is rather new though, this filtering might cause some unexpected behaviour.

To co-locate a block vertex with a vertex of a Geometry object (to allow for non-straight block edges), use Blender's snapping magnet in vertex mode.

Be careful when creating your block structure not to have two co-located vertices. To avoid this SwiftBlock by default enables AutoMerge editing. You can also select your whole block structure and use the Remove Doubles tool to handle this (in Edit Mode).

It is convenient to set view mode as wireframe, as you then can see through faces. Using the Z key you can also switch to Viewport mode. You do not have to create outer faces in your block structure. The block finding algorithm does not consider Blender's faces. Blender faces are only used for setting up patches, and if absent, blockMesh will push non-defined patches into the defaultFaces patch.

When working with SwiftBlock, keep in mind to only use mesh objects as block structure and Geometry object. There is no support for NURBS.


4 Examples

4.1 Meshing a cylinder

SwiftBlock Example Cylinder.jpg

The highlighted (yellow glow) object has the block structure of a typical cylinder mesh. Its corner vertices are co-located with the vertices of another Blender object, “Cylinder”, seens as a black wire frame. As “Set edges” is enabled and the name “Cylinder” was given, blockMeshDict will now contain entries for setting the block edges. Three patches are defined (defaultName has no users here), inlet, outlet, and wall. As the Viewport is in transparent Edit Mode, the patches's colors are not seen.

4.2 Using new features that are available in OpenFOAM 2.4.0

Complete details provided at this post: SwiftSnap and SwiftBlock, GUIs for OpenFOAM's meshers - post #213

In summary:

Both videos require the source code provided in this fork of SwiftBlock: https://github.com/flowkersma/swiftBlock

5 Final Notes

Happy swift blocking! 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

6 References

  1. A. Gaither, An Efficient Block Detection Algorithm For Structured Grid Generation. Proc. 5th Int. Conf. Num. Grid Generation in Comp. Field Simulations, pp. 443-451 (1996)

7 Older versions

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

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