//plik 2
//definiowanie palcow i wsadu
//wyciaganie ich zdna

Include "t1.par";
Include "t1.m";
Include "t1.v_s";
Include "t1_1_dno2.geo";
SetFactory("OpenCASCADE");


/*                                  
For m In {4:15:5}
  Printf("indeks, e1 %g, %g ", m, v1d_e1[m]);
  //Printf("indeks, e2 %g, %g ", m, vp_e1[m]);

EndFor
*/
  
//  Printf (" surface %g, %g, %g ",v1d_e1[22],v1d_e1[28],v1d_e1[34] );

//wyciaganie wsadu i dna na wysokosc palcow
//mesh
//layers

//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
//problem
//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

vp_e1[]= Extrude {0,hndpd_p,0} {Surface{ 
/* 
 below in first section is set of cone surfaces to extrude 
 which cause the problem
 if you comment it is OK
 */
 
 // /*

                                         v1d_e1[4],v1d_e1[9],v1d_e1[15],
                                         v1d_e2[4],v1d_e2[9],v1d_e2[15],
                                         v1d_e3[4],v1d_e3[9],v1d_e3[15],                                       
                                         v1d_e4[4],v1d_e4[9],v1d_e4[15],
                                         v1d_e5[4],v1d_e5[9],v1d_e5[15],
                                                                               
//  */                                       
                                         v1d_e1[22],v1d_e1[28],v1d_e1[34],
                                         v1d_e2[22],v1d_e2[28],v1d_e2[34],
                                         v1d_e3[22],v1d_e3[28],v1d_e3[34],
                                         v1d_e4[22],v1d_e4[28],v1d_e4[34],
                                         v1d_e5[22],v1d_e5[28],v1d_e5[34] 
                                         
                                         };
                                         
                                         Layers {mwpa-1};};
                                         
                                        
/*
For m In {0:40:1}
  Printf("indeks, pow gorne %g, %g ", m, vp_e1[m]);

EndFor

     

//mesh
//layers                                       
vp_e2[]= Extrude {0,gd_p,0} {Surface{ vp_e1[0],  vp_e1[6],  vp_e1[12],
                                      vp_e1[18], vp_e1[24], vp_e1[30],
                                      vp_e1[36], vp_e1[42], vp_e1[48],
                                      vp_e1[54], vp_e1[60], vp_e1[66],
                                      vp_e1[72], vp_e1[78], vp_e1[84] };};
                                    
                                    

//zrobione ca³e palce
//======================                                    


For m In {1:84:6}
  Printf("indeks, pow gorne %g, %g ", m, vp_e1[m]);

EndFor                                       
                                                                           

//++++++++++++++++++++++
//definicja objêtosci i powierzchni dla palcow
//objetosci

//miedz
Physical Volume(palce)={ vp_e1[1],  vp_e1[7],  vp_e1[13],
                         vp_e1[19], vp_e1[25], vp_e1[31],
                         vp_e1[37], vp_e1[43], vp_e1[49],
                         vp_e1[55], vp_e1[61], vp_e1[67],
                         vp_e1[73], vp_e1[79], vp_e1[85] };


//powietrze
Physical Volume(szcz_dna)={  v1d_e1[12], v1d_e5[12]};
Physical Volume(szcz_dna_z)={v1d_e1[36], v1d_e5[36],
                             v1d_e1[42], v1d_e5[42],
                             v1d_e1[48], v1d_e5[48],
                             v1d_e1[54], v1d_e5[54],
                             v1d_e1[60], v1d_e5[60]};

//powierzchnie przednie z=0 i tylne dna

Physical Surface(s_dno_p)={v1d1_s1,v1d1_s2,v1d1_s3,
                           v1d12_e4[13],v1d12_e4[17],v1d12_e4[21],v1d12_e4[25],v1d12_e4[29] };                             
Physical Surface(s_dno_t)={v1d_e5[0],v1d_e5[5],v1d_e5[11], 
                           v1d_e5[35],v1d_e5[41],v1d_e5[47],v1d_e5[53],v1d_e5[59]};


//objetosci palca w dnie
//miedz                                                      
Physical Volume(palce_dno)={            v1d_e2[18],v1d_e3[18], v1d_e4[18],      
                                        v1d_e2[24],v1d_e3[24], v1d_e4[24],                                         
                                        v1d_e2[30],v1d_e3[30], v1d_e4[30]};

//powietrze
Physical Volume(szcz_palcow_dno)={ v1d_e1[18], v1d_e5[18],                                        
                                   v1d_e1[24], v1d_e5[24],
                                   v1d_e1[30], v1d_e5[30]};

//powierzchnie przednie z=0 i tylne palcow w dnie

Physical Surface(s_palce_dno_p)={ v1d12_e4[1],v1d12_e4[5],v1d12_e4[9]};
Physical Surface(s_palce_dno_t)={ v1d_e5[17],v1d_e5[23],v1d_e5[29] };
                                  
//++++++++++++++++++++++


//mesh

//po promieniu

//wnetrze




// punkty zewnetrznej linii podstawy dna
//v1d11
v1d11_p1=newp; Point(v1d11_p1)={0,0,0,ms};
v1d11_p2=newp; Point(v1d11_p2)={x_d-xzapas_d,0,0,ms};
v1d11_p3=newp; Point(v1d11_p3)={x_d-xnac_d,0,0,ms};
v1d11_p4=newp; Point(v1d11_p4)={x_d,0,0,ms};
v1d11_p5=newp; Point(v1d11_p5)={x_d+gs_p,0,0,ms};
v1d11_p6=newp; Point(v1d11_p6)={x_d+xz_p-gs_p,0,0,ms};
v1d11_p7=newp; Point(v1d11_p7)={x_d+xz_p,0,0,ms};
//to powyzej by³o z palcami
// to poni¿ej poza palcami czyli wzbudnik
v1d11_p8=newp; Point(v1d11_p8)={xw_i,0,0,ms};
v1d11_p9=newp; Point(v1d11_p9)={xw_i+gs_i,0,0,ms};
v1d11_p10=newp; Point(v1d11_p10)={xzm_i-gs_i,0,0,ms};
v1d11_p11=newp; Point(v1d11_p11)={xzm_i,0,0,ms};
v1d11_p12=newp; Point(v1d11_p12)={xdt_d,0,0,ms};



//linie w podstawie
v1d11_l1=newreg; Line(v1d11_l1) = {v1d11_p1,v1d11_p2};
v1d11_l2=newreg; Line(v1d11_l2) = {v1d11_p2,v1d11_p3};
v1d11_l3=newreg; Line(v1d11_l3) = {v1d11_p3,v1d11_p4};
v1d11_l4=newreg; Line(v1d11_l4) = {v1d11_p4,v1d11_p5};
v1d11_l5=newreg; Line(v1d11_l5) = {v1d11_p5,v1d11_p6};
v1d11_l6=newreg; Line(v1d11_l6) = {v1d11_p6,v1d11_p7};
//to powyzej to linie z palcami
// to poni¿ej to linie poza palcami czyli wzbudnik i reszta
v1d11_l7=newreg; Line(v1d11_l7) = {v1d11_p7,v1d11_p8};
v1d11_l8=newreg; Line(v1d11_l8) = {v1d11_p8,v1d11_p9};
v1d11_l9=newreg; Line(v1d11_l9) = {v1d11_p9,v1d11_p10};
v1d11_l10=newreg; Line(v1d11_l10) = {v1d11_p10,v1d11_p11};
v1d11_l11=newreg; Line(v1d11_l11) = {v1d11_p11,v1d11_p12};


//wyciaganie w pionie

v1d12_e1[]= Extrude  {0,ys_d,0} {Point{v1d11_p1};};
v1d12_e2[]= Extrude  {0,yzapas_d,0} {Point{v1d11_p2};};
v1d12_e3[]= Extrude  {0,ynac_d,0} {Point{v1d11_p3};};

//x[]=Boundary{Line{v1d12_e1[0]  };};
//Printf("punkty !!! %g , %g,  %g, %g,%g , %g,  %g, %g" , x[0],x[1],x[2],x[3],x[4],x[5],x[6],x[7]);


//wyciaganie w górê reszty dna o sta³ej wysokosci y
//mesh
//layers
v1d12_e4[]= Extrude  {0,yz_d,0} 
            {Line{v1d11_l4, v1d11_l5, v1d11_l6, v1d11_l7, v1d11_l8,v1d11_l9, v1d11_l10, v1d11_l11 };
             Layers {md12b-1};Recombine;};


//linie po wyciagnieciu czyli przod (pierwsza warstwa) 
//  powyzej czyli (dno rzeczywstego tygla)
//czesc o nierownej wysokosci

p[]=Boundary{Line{v1d12_e1[0], v1d12_e2[0], v1d12_e3[0],v1d12_e4[2] };};

//Printf("punkty !!! %g , %g,  %g, %g,%g , %g,  %g, %g" , p[0],p[1],p[2],p[3],p[4],p[5],p[6],p[7]);

v1d21_l1=newreg; Line(v1d21_l1) = {p[1],p[3]};
v1d21_l2=newreg; Line(v1d21_l2) = {p[3],p[5]};
v1d21_l3=newreg; Line(v1d21_l3) = {p[5],p[7]};

//boczne pow. o nierównym wymiarze y
v1d1_L1=newreg; Line Loop (v1d1_L1) = { v1d11_l1, v1d12_e2[0], -v1d21_l1, - v1d12_e1[0]  };
v1d1_s1  = newreg; Plane Surface (v1d1_s1) = {v1d1_L1};
v1d1_L2=newreg; Line Loop (v1d1_L2) = { v1d11_l2, v1d12_e3[0], -v1d21_l2, - v1d12_e2[0]  };
v1d1_s2  = newreg; Plane Surface (v1d1_s2) = {v1d1_L2};
v1d1_L3=newreg; Line Loop (v1d1_L3) = { v1d11_l3, v1d12_e4[2]  , -v1d21_l3, - v1d12_e3[0]  };
v1d1_s3  = newreg; Plane Surface (v1d1_s3) = {v1d1_L3};



v1d_e1[] = Extrude{ {0,1,0}, {0,0,0}, fi1_x_d} 
           {Surface{ v1d1_s1,
                     v1d1_s2, v1d1_s3, v1d12_e4[1], v1d12_e4[5],v1d12_e4[9], 
                     v1d12_e4[13], v1d12_e4[17], v1d12_e4[21],v1d12_e4[25], v1d12_e4[29]  };
                     Layers{md1a}; Recombine; };

//grubosc scianki wzbudnika                     

//Printf("elementy %g , %g,  %g, %g,%g , %g,  %g, %g, %g" , v1d_e1[0],v1d_e1[1],v1d_e1[2],v1d_e1[3],v1d_e1[4],v1d_e1[5],v1d_e1[6],v1d_e1[7],v1d_e1[8]);

v1d_e2[] = Extrude{ {0,1,0}, {0,0,0}, fi2_x_d} 
           {Surface{ v1d_e1[0],
                     v1d_e1[5],v1d_e1[11],v1d_e1[17],v1d_e1[23],
                     v1d_e1[29],v1d_e1[35],v1d_e1[41],v1d_e1[47],v1d_e1[53],v1d_e1[59] };
                     Layers{md1b}; Recombine; };              


v1d_e3[] = Extrude{ {0,1,0}, {0,0,0}, alfa-(fi2_x_d+fi1_x_d)} 
           {Surface{ v1d_e2[0],
                     v1d_e2[5],v1d_e2[11],v1d_e2[17],v1d_e2[23],
                     v1d_e2[29],v1d_e2[35],v1d_e2[41],v1d_e2[47],v1d_e2[53],v1d_e2[59] };
                     Layers{md1c}; Recombine; };              
v1d_e4[] = Extrude{ {0,1,0}, {0,0,0}, fi2_x_d} 
           {Surface{ v1d_e3[0],
                     v1d_e3[5],v1d_e3[11],v1d_e3[17],v1d_e3[23],
                     v1d_e3[29],v1d_e3[35],v1d_e3[41],v1d_e3[47],v1d_e3[53],v1d_e3[59] };
                     Layers{md1b}; Recombine; };                     

v1d_e5[] = Extrude{ {0,1,0}, {0,0,0}, fi1_x_d} 
           {Surface{ v1d_e4[0],
                     v1d_e4[5],v1d_e4[11],v1d_e4[17],v1d_e4[23],
                     v1d_e4[29],v1d_e4[35],v1d_e4[41],v1d_e4[47],v1d_e4[53],v1d_e4[59] };
                     Layers{md1a}; Recombine; };         


//zrobione ca³e dno
//======================

//++++++++++++++++++++++
//definicja objêtosci i powierzchni
//objetosci

//miedz
Physical Volume(dno_tygla)={ v1d_e1[1], v1d_e2[1],v1d_e3[1], v1d_e4[1], v1d_e5[1],
                             v1d_e1[6], v1d_e2[6],v1d_e3[6], v1d_e4[6], v1d_e5[6],
                                        v1d_e2[12],v1d_e3[12], v1d_e4[12],      
                                        v1d_e2[36],v1d_e3[36], v1d_e4[36],                                         
                                        v1d_e2[42],v1d_e3[42], v1d_e4[42],
                                        v1d_e2[48],v1d_e3[48], v1d_e4[48],
                                        v1d_e2[54],v1d_e3[54], v1d_e4[54],
                                        v1d_e2[60],v1d_e3[60], v1d_e4[60]   };
//powietrze
Physical Volume(szcz_dna)={  v1d_e1[12], v1d_e5[12]};
Physical Volume(szcz_dna_z)={v1d_e1[36], v1d_e5[36],
                             v1d_e1[42], v1d_e5[42],
                             v1d_e1[48], v1d_e5[48],
                             v1d_e1[54], v1d_e5[54],
                             v1d_e1[60], v1d_e5[60]};

//powierzchnie przednie z=0 i tylne dna

Physical Surface(s_dno_p)={v1d1_s1,v1d1_s2,v1d1_s3,
                           v1d12_e4[13],v1d12_e4[17],v1d12_e4[21],v1d12_e4[25],v1d12_e4[29] };                             
Physical Surface(s_dno_t)={v1d_e5[0],v1d_e5[5],v1d_e5[11], 
                           v1d_e5[35],v1d_e5[41],v1d_e5[47],v1d_e5[53],v1d_e5[59]};


//objetosci palca w dnie
//miedz                                                      
Physical Volume(palce_dno)={            v1d_e2[18],v1d_e3[18], v1d_e4[18],      
                                        v1d_e2[24],v1d_e3[24], v1d_e4[24],                                         
                                        v1d_e2[30],v1d_e3[30], v1d_e4[30]};

//powietrze
Physical Volume(szcz_palcow_dno)={ v1d_e1[18], v1d_e5[18],                                        
                                   v1d_e1[24], v1d_e5[24],
                                   v1d_e1[30], v1d_e5[30]};

//powierzchnie przednie z=0 i tylne palcow w dnie

Physical Surface(s_palce_dno_p)={ v1d12_e4[1],v1d12_e4[5],v1d12_e4[9]};
Physical Surface(s_palce_dno_t)={ v1d_e5[17],v1d_e5[23],v1d_e5[29] };
                                  
//++++++++++++++++++++++


//mesh

//po promieniu

//wnetrze
Transfinite Line{ v1d11_l1} = md1d;
Transfinite Line{ v1d21_l1} = md1d;
l[]=Boundary{Surface{v1d_e1[0],v1d_e2[0],v1d_e3[0],v1d_e4[0],v1d_e5[0]};};
For m In {0:18:4}
  Transfinite Line{ l[m]} = md1d;
EndFor  
For m In {2:18:4}
  Transfinite Line{ -l[m]} = md1d;
EndFor

//zapas
Transfinite Line{ v1d11_l2} = md1e;
Transfinite Line{ v1d21_l2} = md1e;
l[]=Boundary{Surface{v1d_e1[5],v1d_e2[5],v1d_e3[5],v1d_e4[5],v1d_e5[5]};};
For m In {0:18:4}
  Transfinite Line{ l[m]} = md1e;
EndFor
For m In {2:18:4}
  Transfinite Line{ -l[m]} = md1e;
EndFor

//naciecie
Transfinite Line{ v1d11_l3} = md1f;
Transfinite Line{ v1d21_l3} = md1f;
l[]=Boundary{Surface{v1d_e1[11],v1d_e2[11],v1d_e3[11],v1d_e4[11],v1d_e5[11]};};
For m In {0:18:4}
  Transfinite Line{ l[m]} = md1f;
EndFor
For m In {2:18:4}
  Transfinite Line{ -l[m]} = md1f;
EndFor

//przod palca
Transfinite Line{ v1d11_l4} = md1g;
Transfinite Line{ v1d12_e4[0]} = md1g;
l[]=Boundary{Surface{v1d_e1[17],v1d_e2[17],v1d_e3[17],v1d_e4[17],v1d_e5[17]};};
For m In {1:19:4}
  Transfinite Line{ l[m]} = md1g;
EndFor
For m In {3:19:4}
  Transfinite Line{ -l[m]} = md1g;
EndFor

//srodek palca
Transfinite Line{ v1d11_l5} = md1h;
Transfinite Line{ v1d12_e4[4]} = md1h;
l[]=Boundary{Surface{v1d_e1[23],v1d_e2[23],v1d_e3[23],v1d_e4[23],v1d_e5[23]};};
For m In {1:19:4}
  Transfinite Line{ l[m]} = md1h;
EndFor
For m In {3:19:4}
  Transfinite Line{ -l[m]} = md1h;
EndFor

//tyl palca
Transfinite Line{ v1d11_l6} = md1g;
Transfinite Line{ v1d12_e4[8]} = md1g;
l[]=Boundary{Surface{v1d_e1[29],v1d_e2[29],v1d_e3[29],v1d_e4[29],v1d_e5[29]};};
For m In {1:19:4}
  Transfinite Line{ l[m]} = md1g;
EndFor
For m In {3:19:4}
  Transfinite Line{ -l[m]} = md1g;
EndFor

//szczelina palec wzbudnik 
Transfinite Line{ v1d11_l7} = md1i;
Transfinite Line{ v1d12_e4[12]} = md1i;
l[]=Boundary{Surface{v1d_e1[35],v1d_e2[35],v1d_e3[35],v1d_e4[35],v1d_e5[35]};};
For m In {1:19:4}
  Transfinite Line{ l[m]} = md1i;
EndFor
For m In {3:19:4}
  Transfinite Line{ -l[m]} = md1i;
EndFor

//scianka  wzbudnika  wewnetrzna 
Transfinite Line{ v1d11_l8} = md1j;
Transfinite Line{ v1d12_e4[16]} = md1j;
l[]=Boundary{Surface{v1d_e1[41],v1d_e2[41],v1d_e3[41],v1d_e4[41],v1d_e5[41]};};
For m In {1:19:4}
  Transfinite Line{ l[m]} = md1j;
EndFor
For m In {3:19:4}
  Transfinite Line{ -l[m]} = md1j;
EndFor

//otwor wzbudnika
Transfinite Line{ v1d11_l9} = md1k;
Transfinite Line{ v1d12_e4[20]} = md1k;
l[]=Boundary{Surface{v1d_e1[47],v1d_e2[47],v1d_e3[47],v1d_e4[47],v1d_e5[47]};};
For m In {1:19:4}
  Transfinite Line{ l[m]} = md1k;
EndFor
For m In {3:19:4}
  Transfinite Line{ -l[m]} = md1k;
EndFor

//scianka wzbudnika zewnetrzna
Transfinite Line{ v1d11_l10} = md1j;
Transfinite Line{ v1d12_e4[24]} = md1j;
l[]=Boundary{Surface{v1d_e1[53],v1d_e2[53],v1d_e3[53],v1d_e4[53],v1d_e5[53]};};
For m In {1:19:4}
  Transfinite Line{ l[m]} = md1j;
EndFor
For m In {3:19:4}
  Transfinite Line{ -l[m]} = md1j;
EndFor

//do konca dna
Transfinite Line{ v1d11_l11} = md1l;
Transfinite Line{ v1d12_e4[28]} = md1l;
l[]=Boundary{Surface{v1d_e1[59],v1d_e2[59],v1d_e3[59],v1d_e4[59],v1d_e5[59]};};
For m In {1:19:4}
//  Printf("line %g ",l[m]);
  Transfinite Line{ l[m]} = md1l;
EndFor
For m In {3:19:4}
//  Printf("line %g ",l[m]);
  Transfinite Line{ -l[m]} = md1l;
EndFor
//koniec podzialow po x

//po wysokosci
Transfinite Line{v1d12_e1[0]}=md12a;
Transfinite Line{v1d12_e2[0],v1d12_e3[0] } = md12b;
//(reszta jest zrobiona na pocz¹tku w extrude)

//prostokat od srodka dna
Recombine Surface{v1d1_s1};

// 2 nastepny
Transfinite Surface{v1d1_s2,v1d1_s3};

//pozostale s¹ wyci¹gniête po wysokosci
//uwaga wyci¹gniecie = zwykly podzial -1 !!! 
*/

