SALOME for multiregion meshing

Context

If you’re creating a multiregion mesh and you found this article you probably already know what SALOME , OpenFOAM, snappyHexMesh and chtMultiRegionFoam mean. In case you dont’ here’s a quick explanation:

  • OpenFOAM is your favourite open-source CFD package,
  • chtMultiRegionFoam is the OpenFOAM solver for conjugate heat transfer simulations,
  • conjugate heat transfer analysis calculates heat flow between solid and fluid regions of the problem,
  • SALOME is a tool for prepairing geometry for snappyHexMesh (fun fact, it has nothing to do with Oscar Wilde – it means Simulation numérique par Architecture Logicielle en Open source et à Méthodologie d’Évolution ),
  • snappyHexMesh is the OpenFOAM’s meshing tool,
  • multiregion mesh is what should come our of snappyHexMesh but almost never does and
  • humans share about 50% of DNA with bananas.

The Usual Way

Suppose you get the model you’d like to analyse in a STEP assembly. You can’t just convert every part of it to STL because interfaces between regions (that is, parts) must match perfectly triangle-by-triangle. You have to go through all these steps:

  1. Import the STEP assembly model to SALOME Geometry module. The result is usually a compound.
  2. Explode the compound to separate solids.
  3. Create a box for the domain, if needed (depends on your meshing setup later in the process)
  4. Make a partition of all the parts in steps 2 and 3. This is the step that creates extra surfaces/edges where different parts/domains meet.
  5. Explode the partition back to solids.
    Alternatively, instead of creating more solids, one could create face groups. Then, instead of creating submeshes in step 7 one would use those groups to create separate STL files for each domain. However, in my experience this did not work on complex domains. In particular, some of the faces were unexplicably missing from groups.
  6. Create a 2D mesh on the partition.
  7. Create submeshes on solids from step 5.
  8. Export submeshes.
  9. Prepare surfaceFeatureExtractDict for every domain, blockMeshDict and snappyHexMeshDict.
  10. Finally, run snappyHexMesh to get your multiregion mesh.

Obviously, there is a lot of clicking involved. It takes forever even for cases with low number of domains. Let alone all the errors we humans are happy to make along the way.

The Quicker Way

How about this:

  1. Import settings.py
  2. Import create_groups.py
  3. Import create_stl.py
  4. Start meshing.

An Example

Model

I have prepared a simple model of a weird transformer. Suppose we’d like to do some cooling analysis on it. The model looks like this:

Model for chtMultiRegionFoam

It has:

  1. aluminium housing,
  2. iron transformer core,
  3. two copper windings,
  4. plastic lid with cooling slots
  5. and a button (which we’d rather not include in our simulation).

You simply export the whole model as a single STEP file to the model/ directory.

Settings

Next, you open settings.py file. Edit paths of input and output directories and path to your model. The create_domain option creates and triangulates the outside but you don’t really need that because you can do it with blockMesh. Set that to False and ignore the next three settings (box, box_tr and bg_mesh_size).

The list names regions should match your names in model. Each list entry contains object_name, a regular expression matching all step parts in your input assembly and group_name, a string naming your final STL file.

The list exclude_objects contains regular expressions for models you don’t want to include. In our case, that’s the button since it makes no difference and no sense anyway.

SALOME

Now open SALOME and click File > Load Script... or press Ctrl+T. Load settings.py and nothing will show up. This just adds the variables into memory. Then, import create_groups.py. This will be more verbose.

If you activate the geometry module you’ll see all the created objects. Notice the partition and its child objects – their surfaces are split where the models touch each other.

Before you import the last script, create_stl.py, it may be a good time to edit meshing settings. Depending on the size and complexity of your models you should choose MEFISTO or NETGEN algorithm and set max and min size of 2D elements. On import, the script will make a master mesh on partition and go through created partitioned objects, creating submeshes. It will export STL files to output directory in settings and let you know if it was successful.

Multiregion STL mesh.
The final STL multiregion mesh. Notice how all points on different regions coincide.

Notes

This was written in SALOME 9.+, where I encountered two bugs:

  • STL format: if you’re using decimal comma instead of dot, STL will be written with commas, thus unreadable to other programs. A simple search/replace would do but be very careful. Text editors usually don’t like huge files (I use Visual Studio Code which worked fine on whatever I needed so far).
  • Saving failed: You can only do the above procedure once, then you have to restart SALOME. STL files somehow get locked and are not re-writable unless SALOME is closed.

SALOME also exports STL files without naming of regions (patches). You don’t need those for chtMultiRegionFoam (unless you do). Just to maintain consistency of snappyHexMeshDict files, I still name STL regions, even if there’s always only one. The convert_stl.py file does that. It’s just a copied script from these shortcuts.

All these scripts could probably be automated entirely and run from a console. But of course it’s never that simple – SALOME modules are not among your local Python libraries so I guess it needs quite a bit of wrestling to get the job done. However, I didn’t bother with that because I still want to see the results before starting meshing.

I also bothered to write scripts that write surfaceFeatureExtractDict and snappyHexMeshDict files with all regions and their respective refinements, fvOptions files with heat dissipation, blockMeshDict and even boundary conditions. My advice would be: don’t do that unless you’re expecting a great number of similar simulations. It’s easier and faster to set up a case by hand because most of the settings stay the same. In the end you spend more time debugging the so-called automated scripts instead of focusing on important stuff.

Your Files

are here: salome-multiregion.zip. Enjoy!

3 Comments

  1. Hello
    I am very impressed by your skills using Salome.
    I try to follow your procedure but I am not very familiar with python files etc.

    I am using Salome 9.5 on Windows 10. I am stuck at the first step! where I have to define the pathes in the settings.py file. Can you help me please?

    I write for the os:

    • study_dir = “C:\Users\julien\Desktop\Salome96\salome9.5\salome-multiregion/”
      input_file = “C:\Users\julien\Desktop\Salome96\salome9.5\salome-multiregion\model/model.step”
      output_dir = “C:\Users\julien\Desktop\Salome96\salome9.5\salome-multiregion/geometry”

      I have the error in Salome:

      exec(open(“C:/Users/julien/Desktop/Salome96/salome9.5/salome-multiregion/settings.py”, “rb”).read())
      Traceback (most recent call last):
      File “”, line 1, in
      File “”, line 3
      SyntaxError: (unicode error) ‘unicodeescape’ codec can’t decode bytes in position 2-3: truncated \UXXXXXXXX escape

Leave a Reply