Periodic meshes

This example demonstrates how to create periodic boundary conditions.

from qtcad.builder import Builder
from qtcad.builder import Mask, Polygon


footprint = Polygon.box(10, 10, name="base").centered()

example_mask = Mask("footprint")
example_mask.add_shape(footprint)
Polygon(name='base', id=0, hull=[(-5, -5), (-5, 5), (5, 5), (5, -5)], holes=[])

First, we create a simple box as the base of our device and extrude it.

builder = Builder()


extrude_height = 10
(
    builder.add_mask(example_mask)
    .use_shape("base")
    .set_mesh_size(1)
    .extrude(extrude_height)
    .view(
        True,
        surfaces=True,
        surface_labels=True,
        orthographic=False,
        save="figs/periodic_model.svg",
        angles=(-45, 0, 40),
        zoom=0.8,
        label_type=0,
    )
)
periodic
<qtcad.builder.builder.Builder object at 0x7f873659e510>

Next, we declare the top and bottom surfaces as equivalent using:

Builder.set_periodic(master: GroupSpecifier, match: GroupSpecifier, translation: Iterable[float] | None = None, rotation: ndarray | None = None) Self

[⚡ Utility] Set a periodicity constraint between the entities in groups master and match. The periodicity is defined by an affine transformation that maps entities in master to entities in match consisting of an optional rotation (3x3 matrix) and an optional translation (3-vector). If not provided, no rotation and no translation is assumed.

See the Gmsh documentation for more information.

Parameters:
  • master – The group(s) of the master entities. (See get_group().)

  • match – The group(s) of the matching entities.

  • translation – The translation vector of the affine transformation.

  • rotation – The rotation matrix of the affine transformation.

Above, we provided the label_type=0 argument to qtcad.builder.Builder.view method to show the surface tags as well as the physical groups they belong to. We could use these tags in qtcad.builder.Builder.set_periodic, but in this case it is more convenient to obtain the entity tags using qtcad.builder.Builder.get_group.

(
    builder.set_periodic(
        "base_bottom",
        "base_top",
        translation=[0, 0, extrude_height],
    )
    .mesh(2)
    .view(
        True,
        surfaces=True,
        surface_labels=False,
        orthographic=False,
        save="figs/periodic_model_side.svg",
        angles=(-45, 0, 45),
        zoom=0.8,
    )
)
periodic
<qtcad.builder.builder.Builder object at 0x7f873659e510>

Using the orthographic view, we can see that the top and bottom surfaces are now equivalent.

builder.view(
    surfaces=True,
    orthographic=True,
    show=False,
    save="figs/periodic_mesh.svg",
    angles=(0, 0, 0),
)
periodic
<qtcad.builder.builder.Builder object at 0x7f873659e510>

Total running time of the script: (0 minutes 8.909 seconds)

Gallery generated by Sphinx-Gallery