// create a helix by "Extrude a circle surface Using Wire"
// we want to apply periodic boundary condition using affine transform matrix
// tested in Gmsh 3.0.6

SetFactory("OpenCASCADE");// since we want to use boolean operation in our final application
npts = 100;// number of points in wire
R=20;//radius of the centreline of the helix
a=1;//radius of the circular cross-section of the helix
Angle=20/180*Pi;//helix lay angle
L=2*Pi*R/(Tan(Angle));//helix step in z direction (axial direction of helix)
lc=0.05;

/////////////////////////////////////////
//  circular cross-section definition
//////////////////////////////////////////

// Point definition 
Point(1) = {R,0,0,lc}; //central point
Point(11) = {R+a, 0, 0, lc};
Point(12) = {R, a, 0, lc};
Point(13) = {R-a, 0, 0, lc};
Point(14) = {R, -a, 0, lc};

// Line definition
Circle(1) = {11,1,12};
Circle(2) = {12,1,13};
Circle(3) = {13,1,14};
Circle(4) = {14,1,11};

// Surface definition
Line Loop (1) = {1,2,3,4}; 
Plane Surface (1) = {1};
Rotate {{1, 0, 0}, {R, 0, 0}, -Angle} { Surface{1}; } 

//////////////////////////////////////////
// define the centerline of the helix
// which is the wire used for extrusion
//////////////////////////////////////////

theta1=0;//start point 
theta2=Pi/20;//end point
dtheta=theta2-theta1;//difference in angle between the start and end points
dz=dtheta/2/Pi*L;//difference in z direction

For i In {1:npts} //centerline of helix
  theta = (i-1) * (theta2-theta1)/(npts-1)+theta1;
  Point(i+100) = {R * Cos(theta), R * Sin(theta), theta/2/Pi*L,lc};
EndFor
Spline(100) = {101:100+npts};
Wire(101)={100};

/////////////////////////////////////////////
// extrude the cross-section
// and apply the periodic boundary condition
/////////////////////////////////////////////
Extrude { Surface{1};} Using Wire {101} 
Periodic Surface{7}={1}Affine{Cos(dtheta),-Sin(dtheta),0,0,Sin(dtheta),Cos(dtheta),0,0,0,0,1,dz,0,0,0,1};//doesn't work

