From OpenFOAMWiki
< Contrib
Revision as of 21:01, 23 September 2012 by Nogenmyr (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 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.

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

Compatible Blender versions
v2.63, daily build. The release from May 2012 contains a bug in the shortest path algorithm!
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 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.

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.

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

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

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.

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.
  • If you collect polyLines from object named, for instance, "geom", make sure that no other object is called "geom.001".
  • At Write, log.swiftblock will give you some more detailed output of the block detection.
  • The facesFound.obj file (also from Write) 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 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 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).
Note: has the original user guide.