From OpenFOAMWiki
< Contrib
Revision as of 13:37, 12 September 2012 by Akidess (Talk | contribs)

1 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[2] 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 file that has this plug-in

The files have since August 25:th moved to a git repository

Compatible Blender versions
v2.6x, with x<4. (Possibly also for 2.5x, but surely not for earlier).
Example cases
Structural part, T-junction pipe

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

The text below is an improved transcript of the document already inside the 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!

For questions, problems, and similar, use the dedicated thread at the 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' 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. 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:

Generates and writes out the blockMeshDict. 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 1 mm, set this value to 0.001.
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, 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, and sometimes you might need to do some cutting in the Geometry object and/or add straight lines to it. Also 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 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. 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.

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.

2.1 General notes

SwiftBlock does not support:

  • Creation of wedges, only strictly hexahedral blocks are handled
  • Edge grading
  • Other types of edge definitions except polyLine
  • More complete description of patches than name and type

If your block structure fails, for instance finding more or less blocks than expected, there are some help files generated:

  • log.swiftblock will give you some more detailed output of the block detection.
  • The facesFound.obj 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 openInParaview.blockMesh file. When placed in your $FOAM_CASE directory, it will use ParaView to graphically represent the content in the blockMeshDict file. This is of great value when debugging blockMeshDicts.
 Side note: From the command line, one can view the blockMeshDict in ParaView by running: paraFoam -block 
 But 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 defaultPatches.

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

3 Example

3.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 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 forum: SwiftSnap and SwiftBlock, GUIs for OpenFOAM's meshers

5 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)
  2. E. W. Dijkstra, A note on two problems in connexion with graphs. Numerische Mathematik 1, pp. 269–271 (1959)

6 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).
Note: has the original user guide.