admin管理员组

文章数量:1289528

I have a problem with the code below, I want to generate the triangular mesh only in the rectangular area, inside the circle, I don't want any mesh. How can I do this?

//Flow with obstacle

Mesh.MshFileVersion = 2.2;

// Size of the mesh
lc = 0.25;

// Points
Point(1) = {0, 0, 0, lc}; 
Point(2) = {8, 0, 0, lc}; 
Point(3) = {8, 2, 0, lc}; 
Point(4) = {0, 2, 0, lc};

// Circle
xc = 4; // Coord x 
yc = 1; // Coord y   
r = 0.2; // radius of the circle

Point(5) = {xc, yc + r, 0, lc}; // Point top
Point(6) = {xc, yc, 0, lc};     // Point central
Point(7) = {xc, yc - r, 0, lc}; // Point bottom

// Lines of the rectangle  
Line(1) = {1, 2}; 
Line(2) = {2, 3}; 
Line(3) = {3, 4}; 
Line(4) = {4, 1};

// Circle
Circle(5) = {7, 6, 5}; 
Circle(6) = {5, 6, 7}; 


// Surface of the rectangle 
Curve Loop(1) = {1, 2, 3, 4}; 
Plane Surface(1) = {1};

// Surface of the circle
Curve Loop(2) = {5, 6, 7}; 
Plane Surface(2) = {2};

// Setting the mesh
Transfinite Surface {1};

// Subtract the circle from the rectangle
BooleanDifference{ Plane Surface{1}; Delete; }{ Plane Surface{2}};

The code was generated in the GMSH software.

I have a problem with the code below, I want to generate the triangular mesh only in the rectangular area, inside the circle, I don't want any mesh. How can I do this?

//Flow with obstacle

Mesh.MshFileVersion = 2.2;

// Size of the mesh
lc = 0.25;

// Points
Point(1) = {0, 0, 0, lc}; 
Point(2) = {8, 0, 0, lc}; 
Point(3) = {8, 2, 0, lc}; 
Point(4) = {0, 2, 0, lc};

// Circle
xc = 4; // Coord x 
yc = 1; // Coord y   
r = 0.2; // radius of the circle

Point(5) = {xc, yc + r, 0, lc}; // Point top
Point(6) = {xc, yc, 0, lc};     // Point central
Point(7) = {xc, yc - r, 0, lc}; // Point bottom

// Lines of the rectangle  
Line(1) = {1, 2}; 
Line(2) = {2, 3}; 
Line(3) = {3, 4}; 
Line(4) = {4, 1};

// Circle
Circle(5) = {7, 6, 5}; 
Circle(6) = {5, 6, 7}; 


// Surface of the rectangle 
Curve Loop(1) = {1, 2, 3, 4}; 
Plane Surface(1) = {1};

// Surface of the circle
Curve Loop(2) = {5, 6, 7}; 
Plane Surface(2) = {2};

// Setting the mesh
Transfinite Surface {1};

// Subtract the circle from the rectangle
BooleanDifference{ Plane Surface{1}; Delete; }{ Plane Surface{2}};

The code was generated in the GMSH software.

Share Improve this question asked Feb 20 at 13:57 Afrânio AugustoAfrânio Augusto 211 silver badge1 bronze badge
Add a comment  | 

1 Answer 1

Reset to default 0

Correct code is as following:

Mesh.MshFileVersion = 2.2;

// Size of the mesh
lc = 0.25;

// Points
Point(1) = {0, 0, 0, lc}; 
Point(2) = {8, 0, 0, lc}; 
Point(3) = {8, 2, 0, lc}; 
Point(4) = {0, 2, 0, lc};

// Circle
xc = 4; // Coord x 
yc = 1; // Coord y   
r = 0.2; // radius of the circle

Point(5) = {xc, yc + r, 0, lc}; // Point top
Point(6) = {xc, yc, 0, lc};     // Point central
Point(7) = {xc, yc - r, 0, lc}; // Point bottom

// Lines of the rectangle  
Line(1) = {1, 2}; 
Line(2) = {2, 3}; 
Line(3) = {3, 4}; 
Line(4) = {4, 1};

// Circle
Circle(5) = {7, 6, 5}; 
Circle(6) = {5, 6, 7}; 

// Surface of the rectangle 
Curve Loop(1) = {1, 2, 3, 4}; 
//Plane Surface(1) = {1};

// Surface of the circle
Curve Loop(2) = {5, 6}; 
//Plane Surface(2) = {2};

Plane Surface(1) = {1,2};

// Setting the mesh
//Transfinite Surface {1};

// Subtract the circle from the rectangle
//BooleanDifference{ Plane Surface{1}; Delete; }{ Plane Surface{2}};

Curve Loop(2) = {5, 6, 7}; is changed to Curve Loop(2) = {5, 6}; - curve 7 does not exist. Plane Surface(1) = {1,2} is used to create a surface with a hole. Transfinite Surface {1} has a sense only if all curves in the surface are also transfinite.

A use of BooleanDifference is also possible, however it requires SetFactory("OpenCASCADE"); in the beginning :

SetFactory("OpenCASCADE");

Mesh.MshFileVersion = 2.2;

// Size of the mesh
lc = 0.25;

// Points
Point(1) = {0, 0, 0, lc}; 
Point(2) = {8, 0, 0, lc}; 
Point(3) = {8, 2, 0, lc}; 
Point(4) = {0, 2, 0, lc};

// Circle
xc = 4; // Coord x 
yc = 1; // Coord y   
r = 0.2; // radius of the circle

Point(5) = {xc, yc + r, 0, lc}; // Point top
Point(6) = {xc, yc, 0, lc};     // Point central
Point(7) = {xc, yc - r, 0, lc}; // Point bottom

// Lines of the rectangle  
Line(1) = {1, 2}; 
Line(2) = {2, 3}; 
Line(3) = {3, 4}; 
Line(4) = {4, 1};

// Circle
Circle(5) = {7, 6, 5}; 
Circle(6) = {5, 6, 7}; 

// Surface of the rectangle 
Curve Loop(1) = {1, 2, 3, 4}; 
Plane Surface(1) = {1};

// Surface of the circle
Curve Loop(2) = {5, 6}; 
Plane Surface(2) = {2};

// Subtract the circle from the rectangle
BooleanDifference{ Surface{1}; Delete; }{ Surface{2};Delete;}

本文标签: GMSH with the obstacleStack Overflow