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
[14:50:22] INFO     Selected shapes: [Polygon 0 'base']             _builder.py:880
           INFO     Extruding shape 0 from mask 'footprint' with   _builder.py:2895
                    name 'base' by 10 at z=0
           INFO     Creating new physical group of dimension 2     _builder.py:2679
                    with name 'base_bottom'
           INFO     Creating new physical group of dimension 2     _builder.py:2679
                    with name 'base_side'
           INFO     Creating new physical group of dimension 2     _builder.py:2679
                    with name 'base_top'
           INFO     Creating new physical group of dimension 3     _builder.py:2679
                    with name 'base'
           INFO     Setting z-coordinate to 10                      _builder.py:929
           INFO     Saving figure                                  _builder.py:1994

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

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
           INFO     Setting periodicity in dimension 2 between     _builder.py:1787
                    master [Physical Group 'base_bottom' of
                    dimension 2] and match [Physical Group
                    '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:1587
           INFO     Detecting appropriate random factor            _builder.py:3867
           INFO     Random factor is now appropriate               _builder.py:3891
           INFO     Meshing                                        _builder.py:1603
           INFO     Saving figure                                  _builder.py:1994

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

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
[14:50:23] INFO     Saving figure                                  _builder.py:1994

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

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

Gallery generated by Sphinx-Gallery