# Create structured alternate volume mesh in gmsh

**URL:** <https://fenicsproject.discourse.group/t/create-structured-alternate-volume-mesh-in-gmsh/11371>\
**Category:** mesh\
**Created:** [June 1, 2023, 1:33pm UTC](https://fenicsproject.discourse.group/t/create-structured-alternate-volume-mesh-in-gmsh/11371 "2023-06-01T13:33:26Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![glimachaves](https://avatars.discourse-cdn.com/v4/letter/g/4af34b/32.png) [@glimachaves](https://fenicsproject.discourse.group/u/glimachaves)\
**Post date:** [June 1, 2023, 1:33pm UTC](https://fenicsproject.discourse.group/t/create-structured-alternate-volume-mesh-in-gmsh/11371/1 "2023-06-01T13:33:26Z")

</div>

Hi all, I’ve been trying to create a box mesh in gmsh with a structured and refined layer in the middle, here is the `.geo` code for it:

```auto
lc = 100.;
Mesh.CharacteristicLengthFromPoints = 1.;
Mesh.CharacteristicLengthExtendFromBoundary = 1.;
Mesh.CharacteristicLengthFromCurvature = 1.;
Mesh.CharacteristicLengthMin = 10.;
Mesh.CharacteristicLengthMax = lc;

Lbox = 100;
Hbox = 100;
Wbox = 100;

Wref = 12;

Point(1) = {0, 0, (Wbox - Wref)/2, 1.0};
Point(2) = {Lbox, 0, (Wbox - Wref)/2, 1.0};
Point(3) = {Lbox, Hbox, (Wbox - Wref)/2, 1.0};
Point(4) = {0, Hbox, (Wbox - Wref)/2, 1.0};

Line(1) = {2, 1};
Line(2) = {1, 4};
Line(3) = {4, 3};
Line(4) = {3, 2};
Curve Loop(1) = {4, 1, 2, 3};
Plane Surface(1) = {1};

size_el = 1.5;
n_el_big = Lbox/size_el + 1.;
n_el_small = Wref/size_el + 1.;

Extrude {0, 0, Wref} {
  Surface{1}; //Layers{n_el_small};
}

Transfinite Curve {2, 3, 4, 1, 8, 9, 6, 7} = n_el_big Using Progression 1;
Transfinite Curve {20, 11, 12, 16} = n_el_small Using Progression 1;
Transfinite Surface {1} Alternate;
Transfinite Surface {21} Alternate;
Transfinite Surface {26} Alternate;
Transfinite Surface {13} Alternate;
Transfinite Surface {25} Alternate;
Transfinite Surface {17} Alternate;

/*//Recombine Surface {1, 21, 26, 13, 25, 17}; Used to have hexahedron elements*/

Transfinite Volume{1} = {14, 10, 6, 5, 4, 1, 2, 3};

Point(15) = {0, 0, 0, 1.0};
Point(16) = {Lbox, 0, 0, 1.0};
Point(17) = {Lbox, Hbox, 0, 1.0};
Point(18) = {0, Hbox, 0, 1.0};
Point(19) = {0, 0, Wbox, 1.0};
Point(20) = {Lbox, 0, Wbox, 1.0};
Point(21) = {Lbox, Hbox, Wbox, 1.0};
Point(22) = {0, Hbox, Wbox, 1.0};
Line(21) = {14, 22};
Line(22) = {22, 21};
Line(23) = {21, 5};
Line(24) = {22, 19};
Line(25) = {19, 10};
Line(26) = {19, 20};
Line(27) = {20, 6};
Line(28) = {20, 21};
Line(29) = {2, 16};
Line(30) = {16, 17};
Line(31) = {17, 3};
Line(32) = {17, 18};
Line(33) = {18, 4};
Line(34) = {18, 15};
Line(35) = {15, 1};
Line(36) = {15, 16};

/*//+*/
Curve Loop(2) = {31, -3, -33, -32};
Plane Surface(27) = {2};
Curve Loop(3) = {33, -2, -35, -34};
Plane Surface(28) = {3};
Curve Loop(4) = {35, -1, 29, -36};
Plane Surface(29) = {4};
Curve Loop(5) = {30, 31, 4, 29};
Plane Surface(30) = {5};
Curve Loop(6) = {32, 34, 36, 30};
Plane Surface(31) = {6};
Curve Loop(7) = {23, 6, -27, 28};
Plane Surface(32) = {7};
Curve Loop(8) = {23, -9, 21, 22};
Plane Surface(33) = {8};
Curve Loop(9) = {27, 7, -25, 26};
Plane Surface(34) = {9};
Curve Loop(10) = {25, 8, 21, 24};
Plane Surface(35) = {10};
Curve Loop(11) = {26, 28, -22, 24};
Plane Surface(36) = {11};
Surface Loop(1) = {35, 34, 32, 33, 36, 26};
Volume(2) = {1};
Surface Loop(2) = {28, 27, 30, 31, 29, 1};
Volume(3) = {2};

Transfinite Curve {33, 35, 25, 31, 27, 23} = 6 Using Progression 0.6;
Transfinite Curve {29, 21} = 6 Using Progression 1.4;

```

The problem I’m having is that I wanted the 3D mesh in the refined layer to be alternated. As you can see in the figure below, the 2D mesh is alternated the way I want it to be:

 ![image](https://global.discourse-cdn.com/free1/uploads/fenicsproject1/original/2X/0/0fd2c3649459cdd367d1a6b615065c47c27282ae.png)

However, when I mesh it in 3D, the elements get converted to diagonal elements, as you can see in the figure below

 ![image](https://global.discourse-cdn.com/free1/uploads/fenicsproject1/original/2X/3/366280b4f71e504ab77cd0a08bb22c7f6103d98e.png)

Would there be a way to obtain 3D structured alternate elements in the middle layer?

Thanks in advance for your help!

---

<div class="post-metadata">

**Author:** ![dokken](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/dokken/32/1560_2.png) [@dokken](https://fenicsproject.discourse.group/u/dokken)\
**Post date:** [June 1, 2023, 7:07pm UTC](https://fenicsproject.discourse.group/t/create-structured-alternate-volume-mesh-in-gmsh/11371/2 "2023-06-01T19:07:30Z")

</div>

This is a Gmsh question, and I guess the best people to ask are the Gmsh developers:

[https://gmsh.info/#Documentation](https://gmsh.info/#Documentation)  
or

> **[gmsh / gmsh · GitLab](https://gitlab.onelab.info/gmsh/gmsh)**
>
> The main Gmsh project (https://gmsh.info)

---

<div class="post-metadata">

**Author:** ![glimachaves](https://avatars.discourse-cdn.com/v4/letter/g/4af34b/32.png) [@glimachaves](https://fenicsproject.discourse.group/u/glimachaves)\
**Post date:** [June 2, 2023, 7:10am UTC](https://fenicsproject.discourse.group/t/create-structured-alternate-volume-mesh-in-gmsh/11371/3 "2023-06-02T07:10:49Z")

</div>

Apparently, they don’t have a well-structured forum like the FEniCS discourse (at least I didn’t find it). That’s why I posed the question here since I saw other inquiries related to gmsh in this forum.
