/********************************************************************************************
*
*	MINIMAL NOT WORKING EXAMPLE
*	Trial using:
*			-Embed line on a Compound Surface,
*			-Boolean operator on a Compound Surface.
*
*	Description: Design of a cylinder with patch on its surface and a stripe embedded on
*			the cylinder surface by one of its edges.
*
*	Created by clement.blanchard@univ-nantes.fr on 09/25/2017.
*
********************************************************************************************/

SetFactory("OpenCASCADE");

//*** Mesh parameter ***
Mesh.ElementOrder=2 ;
Mesh.SecondOrderIncomplete=1 ;
Mesh.CharacteristicLengthMin=0.1 ;
Mesh.CharacteristicLengthMax=1 ;
Mesh.CharacteristicLengthFactor=2 ;
Mesh.SubdivisionAlgorithm=0 ;  // 1: None ; 1: All quadrangles ; 2: All Hexahedras

//*** Display control ***
Mesh.Points=0 ;
Mesh.Lines=0 ;
Mesh.SurfaceFaces=0 ;
Mesh.SurfaceEdges=0 ;
Mesh.SurfaceFaces=0 ;
Mesh.VolumeEdges=0 ;
Mesh.VolumeFaces=0 ;

//*** Cylinder ***
p00=newp ; Point(p00)={0,0,0} ;
p1=newp ; Point(p1)={1,0,0} ;
p2=newp ; p2=Rotate{{0,0,1}, {0,0,0}, 2*Pi/3 }{Duplicata{Point{p1};}};
p3=newp ; p3=Rotate{{0,0,1}, {0,0,0}, -2*Pi/3 }{Duplicata{Point{p1};}};

l1=newl ; Circle(l1)={p1,p00,p2} ;
l2=newl ; Circle(l2)={p2,p00,p3} ;
l3=newl ; Circle(l3)={p3,p00,p1} ;

ll1=newl ; Line Loop(ll1)={l1,l2,l3} ;

s1=news ; Surface(s1)={ll1} ;

cylinder[]=Extrude{0,0,3}{Surface{s1};} ;

s01=news ; Compound Surface(s01)={cylinder[2],cylinder[3],cylinder[4]} ;

//*** Patch ***
p4=newp ; p4=Rotate{{0,0,1}, {0,0,0}, Pi/3}{Translate{0,0,1}{Duplicata{Point{p1};}}} ;
p5=newp ; p5=Translate{0,0,1}{Duplicata{Point{p4};}} ;
l4=newl ; Line(l4)={p4,p5} ;
Line{l4} In Surface{s01} ;

cut[]=Extrude{{0,0,1},{0,0,0},Pi}{Line{l4};} ;
s4=news ; BooleanDifference(s4)={Surface{s01};}{Surface{cut[1]};} ;

//*** Stripe ***
out[]=Extrude{Cos(Pi/3),Sin(Pi/3),0}{Line{l4};} ;

//*** Physicals ***
Printf("*** Cylinder ***") ;
Printf("s1 : %g",s1) ;
Printf("cylinder[0] : %g",cylinder[0]) ;
Printf("cut[1] : %g",cut[1]) ;
Printf("s4 : %g",s4) ;
Printf("*** Patch ***") ;
Printf("cut[1] : %g",cut[1]) ;
Printf("*** Patch ***") ;
Printf("out[1] : %g",out[1]) ;

Physical Surface("Cylinder")={s1,cylinder[0],cut[1],s4} ;
Physical Surface("Patch")={cut[1]} ;
Physical Surface("Stripe")={out[1]} ;

//*** Mesh ***
Mesh 2 ;

