Thursday 29 January 2009

Ordered 3-D mesh with Gmsh. Extrude 2-D surface.


// Gmsh project created on Tue Aug 5 18:29:53 2008
l = 0.02; // length
h = 0.01; // duct height
w = 0.001; // duct width
mx = 20; // mesh along the length.
my = 12; // y mesh. Divisible by 4
mz = 1; // mesh density across width.

// Tranfinite surfaces have 3 or 4 points, so can't lump the square face.
// Split it, then, into 4 sections.

Point(1) = { 0, h, h, 1}; // left wall, top to bottom.
Point(2) = { 0, h * 0.75, h, 1}; // ...
Point(3) = { 0, h * 0.5, h, 1}; // ...
Point(4) = { 0, h * 0.25, h, 1}; // ...
Point(5) = { 0, h * 0, h, 1}; // ...

Point(6) = { l, h, h, 1}; // right wall, top to bottom.
Point(7) = { l, h * 0.75, h, 1}; // ...
Point(8) = { l, h * 0.5, h, 1}; // ...
Point(9) = { l, h * 0.25, h, 1}; // ...
Point(10) = { l, h * 0.00, h, 1}; // ...

Point(11) = { l + h/4, h * 0.75, h, 1}; // inner square nodes
Point(12) = { l + h/4, h * 0.5, h, 1}; // ...
Point(13) = { l + h/4, h * 0.25, h, 1}; // ...

Point(14) = { l + 0.707 * h/2 , h/2 + 0.707 * h/2, h, 1}; // Curve.
Point(15) = { l + 1.000 * h/2 , h/2 + 0.000 * h/2, h, 1}; // Curve.
Point(16) = { l + 0.707 * h/2 , h/2 - 0.707 * h/2, h, 1}; // Curve.


// Square creation. Duct. ==============================================Squares
Line(1) = {1, 2}; // left side
Line(2) = {2, 3}; // ...
Line(3) = {3, 4}; // ...
Line(4) = {4, 5}; // ...

Line(5) = {6, 7}; // right side
Line(6) = {7, 8}; // ...
Line(7) = {8, 9}; // ...
Line(8) = {9, 10}; // ...

Line(9) = {14, 11}; // inner square, vertical
Line(10) = {11, 12}; // ...
Line(11) = {12, 13}; // ...
Line(12) = {13, 16}; // ...

Circle(13) = {6, 8, 14}; // curved end
Circle(14) = {14, 8, 15}; // ...
Circle(15) = {15, 8, 16}; // ...
Circle(16) = {16, 8, 10}; // ...

Line(17) = {1, 6}; // horizontal lines, left to right.
Line(18) = {2, 7}; // ...
Line(19) = {7, 11}; // ...
Line(20) = {3, 8}; // ...
Line(21) = {8, 12}; // ...
Line(22) = {12, 15}; // square to circle
Line(23) = {4, 9}; // ...
Line(24) = {9, 13}; // ...
Line(25) = {5, 10}; // ...


// Define closed loops and planes for the shapes just created. These were
// selected in GMSH, rather than in the script as the negative values control
// the direction of the path. ============================================Planes
// Duct.
Line Loop(26) = {17,5,-18,-1};
Plane Surface(27) = {26};
Line Loop(28) = {18,6,-20,-2};
Plane Surface(29) = {28};
Line Loop(30) = {20,7,-23,-3};
Plane Surface(31) = {30};
Line Loop(32) = {23,8,-25,-4};
Plane Surface(33) = {32};
Line Loop(34) = {13,9,-19,-5};
Plane Surface(35) = {34};
Line Loop(36) = {19,10,-21,-6};
Plane Surface(37) = {36};
Line Loop(38) = {21,11,-24,-7};
Plane Surface(39) = {38};
Line Loop(40) = {24,12,16,-8};
Plane Surface(41) = {40};
Line Loop(42) = {14,-22,-10,-9};
Plane Surface(43) = {42};
Line Loop(44) = {22,15,-12,-11};
Plane Surface(45) = {44};


// The following code is required to make the mesh ordered =====================
// Set the lines above, as 'transfinite'. These are line numbers
Transfinite Line{1, 2, 3, 4, 5, 6, 7, 8, 10, 11} = 0.25*my Using Progression 1.0; // vertical lines

Transfinite Line{17, 18, 20, 23, 25} = mx Using Progression 1.0; // horizontal lines
Transfinite Line{19, 21, 24} = 0.25*my Using Progression 1.0; // horizontal lines
Transfinite Line{9, 22, 12} = 0.25*my Using Progression 1.0; // diagonal lines
Transfinite Line{13, 14, 15, 16} = 0.25*my Using Progression 1.0; // Circle portions.

// Create new, 'transfinite' surfaces. Matching plane surface numbers above and
// referencing same node numbers. Had to inspect
// these from gmsh. Note, curly brackets, not parentheses.
// {surface} = {nodes}
Transfinite Surface{27} = {1, 2, 6, 7}; // duct, left side, top to bottom.
Transfinite Surface{29} = {2, 7, 3, 8}; // ...
Transfinite Surface{31} = {3, 8, 4, 9}; // ...
Transfinite Surface{33} = {4, 9, 5, 10}; // ...

Transfinite Surface{35} = {6, 14, 7, 11}; // duct, middle, top to bottom.
Transfinite Surface{37} = {7, 11, 8, 12}; // ...
Transfinite Surface{39} = {8, 12, 9, 13}; // ...
Transfinite Surface{41} = {9, 13, 10, 16}; // ...

Transfinite Surface{43} = {11, 14, 12, 15}; // last two of circle,top to bottom.
Transfinite Surface{45} = {12, 15, 13, 16}; // ...


// Without the following recombine, the elements are tri primative.
// Duct.
Recombine Surface{27, 29, 31, 33, 35, 37, 39, 41, 43, 45};
// End of extra code to get ordered mesh =======================================


// Extrude {vector} { Surface{n}; Layers{mz} ; Recombine; }
// with surface number(s) n extruded, mesh density mz1.
// Assign result to var[], to allow further work with the new surface, in var[0]
// Entries 0 to 5 are returned for these extruded faces, so steps of 6 to
// get the faces for different volumes appended to the list.
//
// Extrude to form duct width: -------------------------
//
num[] = Extrude { 0, 0, -w} {
Surface {
27 , 29, 31, 33, 35, 37, 39, 41, 43, 45
};
Layers{mz}; Recombine;
};

No comments:

Post a Comment