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
[15:24:11] INFO     Selected shapes: [Polygon 0 'base']              builder.py:854
           INFO     Extruding shape 0 from mask 'footprint' with    builder.py:2794
                    name 'base' by 10 at z=0
           INFO     Creating new physical group with name           builder.py:2580
                    'base_bottom'
           INFO     Creating new physical group with name           builder.py:2580
                    'base_side'
           INFO     Creating new physical group with name           builder.py:2580
                    'base_top'
           INFO     Creating new physical group with name           builder.py:2580
                    'base_hull'
           INFO     Creating new physical group with name 'base'    builder.py:2580
           INFO     Setting z-coordinate to 10                       builder.py:903
           INFO     Saving figure                                   builder.py:1926

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

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
[15:24:12] INFO     Setting periodicity in dimension 2 between      builder.py:1725
                    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:1561
           INFO     Detecting appropriate random factor             builder.py:3681
           INFO     Random factor is now appropriate                builder.py:3705
           INFO     Meshing                                         builder.py:1577
           INFO     Saving figure                                   builder.py:1926

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

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
[15:24:13] INFO     Saving figure                                   builder.py:1926

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

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

Gallery generated by Sphinx-Gallery