0
$\begingroup$

I need help to know, how can I convert an unstructured 2d mesh for structured mesh? (Software Gmsh version 4.9.3).

This is my script in Gmsh.

Mesh.MshFileVersion = 2.2; 

// Geometry

//Points
Point(1) = {0, 1, 0, 0.3};
Point(2) = {0, 2, 0, 0.3};
Point(3) = {7, 2, 0, 0.3};
Point(4) = {7, 0, 0, 0.3};
Point(5) = {1, 1, 0, 0.3};
Point(6) = {1, 0, 0, 0.3};

// Lines

Line(1) = {5, 1};
Line(2) = {1, 2};
Line(3) = {2, 3};
Line(4) = {3, 4};
Line(5) = {4, 6};
Line(6) = {6, 5};

Curve Loop(1) = {1, 2, 3, 4, 5, 6};
Plane Surface(1) = {1};
Transfinite Surface {1};
$\endgroup$
2
  • 3
    $\begingroup$ I don't think that you can convert an unstructured mesh to a structured one, in general. What's the rationale behind wanting to do this? $\endgroup$
    – nicoguaro
    Commented Jan 31, 2022 at 15:39
  • 1
    $\begingroup$ in Gmsh the option Transfinite works only for planes with four corner points, here your plane has six corners so Gmsh throws an error. $\endgroup$
    – Masa
    Commented Feb 2, 2022 at 10:37

1 Answer 1

2
$\begingroup$

in Gmsh only planes that have four corner points could be meshed with structured meshes using Trasnfinite option. In your file, the plane is constituted from six points and Gmsh can't mesh it structured. In such cases, you should partition the problem geometry into distinct rectangles (planes with four corner points) so the Trasnfinite option could be applied to them. In the following code, the geometry is modeled using three rectangles:

lc = 0.3;
//Points
Point(1) = {0, 1, 0, lc};
Point(2) = {0, 2, 0, lc};
Point(3) = {7, 2, 0, lc};
Point(4) = {7, 0, 0, lc};
Point(5) = {1, 1, 0, lc};
Point(6) = {1, 0, 0, lc};
Point(7) = {1, 2, 0, lc};
Point(8) = {7, 1, 0, lc};
//Lines
Line(1) = {1,5};
Line(2) = {5,6};
Line(3) = {6,4};
Line(4) = {4,8};
Line(5) = {8,3};
Line(6) = {3,7};
Line(7) = {7,2};
Line(8) = {2,1};
Line(9) = {5,7};
Line(10) = {5,8};
//Curves
Curve Loop(1) = {3,4,-10,2};
Plane Surface(1) = {1};
Curve Loop(2) = {10,5,6,-9};
Plane Surface(2) = {2};
Curve Loop(3) = {1,9,7,8};
Plane Surface(3) = {3};
//
n1 = 4;
n2 = 4;
n3 = n1*5-1;
Transfinite Curve {1,7} = n1;
Transfinite Curve {2,4,5,8,9} = n2;
Transfinite Curve {3,6,10} = n3;
Transfinite Surface {1,2,3};

here are the resulting structured triangular and rectangular (using Recombine 2D option) meshes: enter image description here

$\endgroup$
2
  • $\begingroup$ Thank you very much,I did not know! DO you know how can I export this mesh for python (jupyter notebook, vscode)? $\endgroup$ Commented Feb 3, 2022 at 16:40
  • $\begingroup$ You're welcome. in the GUI you can export the mesh via File->Export (Ctrl+E), or by adding the line Save "fileName.ext"; at the end of the .geo script file. Details of different export mesh file formats (and other things about using Gmsh ) are explained in Gmsh documentation. You could accept this as the correct answer if your problem is solved. $\endgroup$
    – Masa
    Commented Feb 4, 2022 at 6:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.