Skip to content

Tutorial 2 - Workpiece 2

Goal

The goal of this tutorial is to partition workpiece2 into meshable blocks and generate a structured hexahedral mesh.

You will use HexaMSH to partition the CAD model and generate the mesh.

Before you begin

Download the CAD file here.

Open it from a prompt in a Python environment that contains HexaMSH:

hexamsh workpiece2.stp

Gmsh opens with the CAD model:

tuto_2_intro

The aim is to partition the CAD model into meshable sub-volumes:

tuto_2_intro_end

CAD partitioning

There are several ways to obtain this partitioning. This tutorial presents one possible workflow.

Create the first blocks

Use Split a volume by a point loop (L).

Select the points that define the loop, then double-click to finish the selection:

tuto_2_split_point_loop_1

The operation splits the geometry and creates a new surface:

tuto_2_split_point_loop_1_done

Repeat the same command on the next four points. This creates the first meshable block, shown in green:

tuto_2_split_point_loop_2

Use Add a volume between two surfaces (D). Select the lower surface first, then the upper surface:

tuto_2_add_volume_1

The command creates a new volume between the selected surfaces:

tuto_2_add_volume_1_done

How is the volume created?

Three connecting surfaces already exist between the selected volumes. HexaMSH only needs to create the remaining surface, which produces a new sub-volume.

Repeat the command on the next two surfaces:

tuto_2_add_volume_2

This creates another volume between the selected surfaces:

tuto_2_add_volume_2_done

Separate the CAD with Split a volume by a point loop, selecting the four points shown below:

tuto_2_split_point_loop_3

The operation splits the geometry and creates a new surface:

tuto_2_split_point_loop_3_done

Repeat the operation on the upper points. First create two new points with Project a point on a curve (P):

tuto_2_click_projection_point

Then project the second point:

tuto_2_click_projection_point_2

Finally, split the volume with a point loop:

tuto_2_split_point_loop_4

The operation splits the geometry and creates a new surface:

tuto_2_split_point_loop_4_done

Project the point onto the curve shown below:

tuto_2_click_projection_point_3

Now split the CAD into two parts with Split all volumes by a plane (3 points) (M). Select three points:

tuto_2_split_3_points

The result is:

tuto_2_split_3_points_done

Add a new volume with Add a volume between two surfaces:

tuto_2_add_volume_3

The command directly creates three new meshable sub-volumes:

tuto_2_add_volume_3_done

Repeat the same command three times to create the remaining volumes:

tuto_2_add_volume_4

The result is:

tuto_2_add_volume_4_done

Use Merge two surfaces (V) to simplify the CAD:

tuto_2_merge_2_surfaces

Create a new volume in two steps:

  1. Project points onto curves:
tuto_2_click_projection_point_4
  1. Split the volume with a point loop:
tuto_2_split_4_points_done

The last operation creates a wedge, which cannot be meshed with the transfinite methods.

Use Split a wedge volume (I) and select the two triangular faces:

tuto_2_split_wedge

This generates meshable sub-volumes inside the wedge:

tuto_2_split_wedge_done

Add a volume between the two surfaces shown below:

tuto_2_add_volume_5

The result is:

tuto_2_add_volume_5_done

Finally, use the same feature to split the remaining orange volume in that region:

tuto_2_add_volume_6

The result is:

tuto_2_add_volume_6_done

Propagate the four surfaces vertically down to the CAD ground:

tuto_2_add_volume_7

The result is:

tuto_2_add_volume_7_done

Play with views and geometry display

At any time, we can hide/show the green and orange volumes using the view options in the left pannel:

view_pannel

We can also use the Gmsh options to hide/show surfaces (alt + S), curves (alt + L) and points (alt + P) for a better visibility.

Partition the other side

Repeat the same strategy for the matching shape on the other side of the CAD model:

tuto_2_other_part

Follow the same sequence:

  1. Split vertically to create a wedge:
tuto_2_other_part_1
  1. Split the wedge:
tuto_2_other_part_2
  1. Add volumes to create meshable blocks.

A projection can create an unwanted split

Projecting points can sometimes create unwanted points when geometries intersect:

tuto_2_other_part_2_warning

Instead, use Add a point on a curve. Adjust the ratio, select the curves to split, and double-click to finish the selection. Adjust the ratio again if needed, then press E to validate the split.

tuto_2_other_part_2_split_curve

Then split the volume with a point loop. This produces a cleaner, meshable split:

tuto_2_other_part_2_split_point_loop

Undo an unexpected operation

Use Back to previous CAD to revert an operation. The keyboard shortcut is Ctrl + Z.

The partitioned model should now look like this:

tuto_2_other_part_3

Partition around the hole

Split the CAD around the hole:

tuto_2_split_propostion

Use the following commands in sequence to create this partition:

  1. Project a point on a curve.
  2. Split a volume by a point loop.
  3. Add a volume between two surfaces.
tuto_2_split_5_points_done

Combine features to complete the partitioning

HexaMSH often requires a combination of features. For the result above, use Add a volume between two surfaces for most operations. For the final split, use Add a point on a curve:

tuto_2_other_part_2_split_curve_2

Then split the volume with a point loop.

Project the point onto the curve shown below:

tuto_2_click_projection_point_5

Split the CAD with an infinite plane by selecting three points:

tuto_2_split_3_points_2

Propagate the pocket

Propagate the pocket down to the ground:

tuto_2_pocket_propagation

Use Project surface onto surface (S) to generate a new volume. Select the upper surface first, then the ground surface:

tuto_2_pocket_propagation_done

Split the CAD by projecting points onto curves and then using Split a volume by a point loop:

tuto_2_split_propostion_2

The result is:

tuto_2_split_propostion_2_done

A point loop can contain more than four points

Some point loops contain five points here. Select all five points to split the CAD correctly.

Create the next split to force surfaces with four curves:

tuto_2_split_propostion_3

Partition this part:

tuto_2_split_propostion_4

The result is:

tuto_2_split_propostion_4_done

Split the volume at the location shown below:

tuto_2_split_propostion_5

The result is:

tuto_2_split_propostion_5_done

Split the next volume at the location shown below:

tuto_2_split_propostion_6

The result is:

tuto_2_split_propostion_6_done

Finally, split the full CAD with an infinite plane defined by three points:

tuto_2_split_3_points_3

Split the pocket at the location shown below:

tuto_2_split_propostion_7

The result is:

tuto_2_split_propostion_7_done

Remove the orange surface created by the infinite-plane split with Remove surfaces (R), double-click to finish the selection:

tuto_2_split_remove_surface

Change the surface view

Press Alt + T to switch to the solid surface view:

tuto_2_solid_surface
The wireframe view is more suitable for editing the CAD. Press Alt + T again to return to it.

The model is now fully meshable: all volumes appear green.

Mesh generation

Click Mesh CAD at the bottom of the left panel to generate a structured hexahedral mesh:

tuto_2_mesh_cad

By default, five nodes are assigned to every edge. To use three nodes on selected edges, use Set number of nodes on edges:

tuto_2_set_3_nodes

To assign n nodes to a group of wider edges, use Set number of nodes on all edges. Set the number, select the edges, and double-click to finish the selection.

You only need to select one edge. HexaMSH automatically applies the same number of nodes to the opposite edges, which appear green. The mesh updates immediately:

tuto_2_new_mesh

Once the node counts are correct, close the Gmsh window. HexaMSH writes the result to a .msh file.