Contrib/SwiftBlock

From OpenFOAMWiki

An unstructured approach to block structured meshing.

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

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


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


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


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 www.cfd-online.com 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)

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