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
[01:52:34 PM] INFO     Extruding shape 0 from mask 'footprint' with name 'base' by 10 at z=0                                                               builder.py:2695
              INFO     Creating new physical group with name 'base_bottom'                                                                                 builder.py:2482
              INFO     Creating new physical group with name 'base_side'                                                                                   builder.py:2482
              INFO     Creating new physical group with name 'base_top'                                                                                    builder.py:2482
              INFO     Creating new physical group with name 'base'                                                                                        builder.py:2482
[01:52:35 PM] INFO     Setting z-coordinate to 10                                                                                                           builder.py:849
              INFO     Saving /home/hiro/Documents/org/roam/code/qtcad_flake/qtcad/packages/builder/examples/operations/figs/periodic_model.svg            builder.py:1863

<qtcad.builder.builder.Builder object at 0x7f026ead34d0>

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

Builder.set_periodic(master: str | list[str] | Callable[[PhysicalGroup], bool], match: str | list[str] | Callable[[PhysicalGroup], bool], 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
[01:52:36 PM] INFO     Setting periodicity in dimension 2 between master [Physical Group 'base_bottom' of dimension 2] and match [Physical Group           builder.py:1664
                       'base_top' of dimension 2] with translation [ 0.  0. 10.] and rotation
                       [[1. 0. 0.]
                        [0. 1. 0.]
                        [0. 0. 1.]]
              INFO     Preparing to mesh                                                                                                                   builder.py:1502
              INFO     Detecting appropriate random factor                                                                                                 builder.py:3608
              INFO     Random factor is now appropriate                                                                                                    builder.py:3632
              INFO     Meshing                                                                                                                             builder.py:1518
              INFO     Saving /home/hiro/Documents/org/roam/code/qtcad_flake/qtcad/packages/builder/examples/operations/figs/periodic_model_side.svg       builder.py:1863

<qtcad.builder.builder.Builder object at 0x7f026ead34d0>

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
[01:52:38 PM] INFO     Saving /home/hiro/Documents/org/roam/code/qtcad_flake/qtcad/packages/builder/examples/operations/figs/periodic_mesh.svg             builder.py:1863

<qtcad.builder.builder.Builder object at 0x7f026ead34d0>

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

Gallery generated by Sphinx-Gallery