Creating Periodic Lines in the Gmsh Python API Using Affine Transformations
Автор: vlogommentary
Загружено: 2025-12-19
Просмотров: 0
Описание:
Learn how to correctly set up periodic boundary conditions on lines in Gmsh using the Python API with affine transformations for meshing periodic geometries.
---
This video is based on the question https://stackoverflow.com/q/79466893/ asked by the user 'Albacete' ( https://stackoverflow.com/u/19925891/ ) and on the answer https://stackoverflow.com/a/79470985/ provided by the user 'Michael Ermakov' ( https://stackoverflow.com/u/27846293/ ) at 'Stack Overflow' website. Thanks to these great users and Stackexchange community for their contributions.
Visit these links for original content and any more details, such as alternate solutions, latest updates/developments on topic, comments, revision history etc. For example, the original title of the Question was: Periodic Line in Gmsh Python api: affineTransform needed?
Also, Content (except music) licensed under CC BY-SA https://meta.stackexchange.com/help/l...
The original Question post is licensed under the 'CC BY-SA 4.0' ( https://creativecommons.org/licenses/... ) license, and the original Answer post is licensed under the 'CC BY-SA 4.0' ( https://creativecommons.org/licenses/... ) license.
If anything seems off to you, please feel free to drop me a comment under this video.
---
Introduction
When meshing geometries with periodic boundaries—such as matching opposite edges of a rectangular surface—Gmsh’s .geo scripting language provides a straightforward syntax using Periodic Line definitions. However, the equivalent operation in the Gmsh Python API requires an explicit affine transformation matrix as part of gmsh.model.mesh.setPeriodic(), which can confuse new users.
The Challenge
In .geo scripts, periodic lines are defined simply like this:
[[See Video to Reveal this Text or Code Snippet]]
This automatically maps one boundary curve to another without specifying transformation parameters.
In the Python API though, the setPeriodic() method requires:
The dimension of the entity (e.g., 1 for lines),
A list of 'slave' entity tags,
A list of corresponding 'master' entity tags,
An affine transformation matrix (a 4x4 matrix flattened to 16 elements) describing how the master’s coordinates map to the slave’s.
Without providing this transform, an error occurs, unlike .geo where Gmsh infers it.
Setting Up Periodic Lines in Python
To replicate .geo periodic lines in Python, you must:
Build your geometry using OpenCASCADE and synchronize:
[[See Video to Reveal this Text or Code Snippet]]
Define the affine transformations explicitly:
The affine transform is a 4x4 matrix written in row-major order.
For example, to map the top line to the bottom line, or right to left, you typically need translation and possibly reflection.
Example for periodicity between opposite lines:
[[See Video to Reveal this Text or Code Snippet]]
Generate mesh and launch GUI:
[[See Video to Reveal this Text or Code Snippet]]
Key Points
You must synchronize the OpenCASCADE model with gmsh.model.occ.synchronize() before setting periodic entities.
The affine transform matrix must be 4x4 and encode any translation, rotation, or reflection to relate master and slave lines.
Geometry from .geo scripts hides these transforms, but Python requires explicit input for clarity and flexibility.
Summary
Using periodic boundary conditions in the Gmsh Python API requires an explicit affine transformation. While .geo scripting auto-infers this for simple cases, Python needs a 4x4 matrix defining how two geometry entities correspond. With careful setup of points, lines, and appropriate affine transforms, you can achieve periodic meshing just as seamlessly.
This explicit control also enables more complex periodic setups beyond rectangular cases.
References:
Gmsh Python API Documentation
Gmsh periodic meshes example
Повторяем попытку...
Доступные форматы для скачивания:
Скачать видео
-
Информация по загрузке: