Friday, 30 January 2009

Ordered 3-D mesh with Gmsh, no extrusion, hexahedra


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

// Bottom surface; extrude from here, up.=========================NODES
Point(1) = { 0, h, 0, 1}; // bottom, rear right corner.
Point(2) = { l, h, 0, 1}; // bottom, front right corner.
Point(3) = { 0, 0, 0, 1}; // bottom, rear right corner.
Point(4) = { l, 0, 0, 1}; // bottom, front right corner.

Point(5) = { 0, h, w, 1}; // bottom, rear right corner.
Point(6) = { l, h, w*2, 1}; // bottom, front right corner.
Point(7) = { 0, 0, w, 1}; // bottom, rear right corner.
Point(8) = { l, 0, w*2, 1}; // bottom, front right corner.


// Cube-ish creation. Duct. ==============================================
Line(1) = {1, 2};
Line(2) = {2, 4};
Line(3) = {4, 3};
Line(4) = {3, 1};
Line(5) = {5, 6};
Line(6) = {6, 8};
Line(7) = {8, 7};
Line(8) = {7, 5};
Line(9) = {1, 5};
Line(10) = {2, 6};
Line(11) = {3, 7};
Line(12) = {4, 8};




// 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(1) = {1,2,3,4};
Plane Surface(2) = {1};
Line Loop(3) = {5,6,7,8};
Plane Surface(4) = {3};
Line Loop(5) = {9,-8,-11,4};
Plane Surface(6) = {5};
Line Loop(7) = {10,6,-12,-2};
Plane Surface(8) = {7};
Line Loop(9) = {1,10,-5,-9};
Plane Surface(10) = {9};
Line Loop(11) = {3,11,-7,-12};
Plane Surface(12) = {11};


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


// 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{2} = {1, 2, 3, 4};
Transfinite Surface{4} = {5, 6, 7, 8};
Transfinite Surface{6} = {1, 5, 3, 7};
Transfinite Surface{8} = {6, 2, 8, 4};
Transfinite Surface{10} = {2, 6, 1, 5};
Transfinite Surface{12} = {8, 4, 7, 3};

// Without the following recombine, the elements are tri primative.
// Duct.
Recombine Surface{2, 4, 6, 8, 10, 12};


// 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 {
// 2
// };
// Layers{mz}; Recombine;
// };
// Can't extrude, as I want to change the thickness in that direction.
// New nodes, instead.


// Now, define a volume.
Surface Loop(13) = {4,10,2,8,12,6};
Volume(14) = {13};

// And define as transfinite. The points were selected, clockwise for both
// faces, looking in the same direction.
Transfinite Volume{14} = {5,6,8,7,1,2,4,3};

No comments:

Post a Comment