// mesh file for 2D j density test

// parameters
da = 0.03;
db = 0.05;
barre_len = 2.;
barre_height = 0.16;
block_height = 0.4;
block_len = 1.425;
freeze = 0.01;
anode_length = 1.4;
anode_height = 0.56;
metal_height = 0.19;
bath_height = 0.23;
acd = 0.05;

gr_pos = 0.2;
gr_diam = 0.1;
gr_w = 0.5;
gr_height = 0.3;
gr_depth = 0.15;
stub_height= 0.2;
cl = 0.022;


//
// barre
//
Point(1) = { db + barre_len, 0, -block_height, cl };
Point(2) = { db + barre_len, 0, -block_height + barre_height, cl };
Point(3) = { db, 0, -block_height, cl };
Point(4) = { db, 0, -block_height + barre_height, cl };
Point(5) = { block_len, 0, -block_height+barre_height, cl };

Line(1) = { 1, 2 };
Line(2) = { 2, 5 };
Line(3) = { 4, 3 };
Line(4) = { 3, 1 };
Line(5) = { 5, 4 };

Line Loop(1) = { 1, 2, 5, 3, 4 };

Plane Surface(1) = { 1 };


//
// bloc cathodique
//
Point(6) = { block_len, 0, 0, cl };
Point(7) = { block_len - freeze, 0, 0, cl };
Point(8) = { 0, 0, 0, cl };
Point(9) = { 0, 0, -block_height, cl };

Line(6) = { 6, 5 };
Line(7) = { 7, 6 };
Line(8) = { 8, 7 };
Line(9) = { 9, 8 };
Line(10) = { 3, 9 };

Line Loop(2) = { 6, 5, 3, 10, 9, 8, 7 };

Plane Surface(2) = { 2 };

//
// metal
//
Point(10) = { 0, 0, metal_height, cl/2 };
Point(11) = { da + anode_length +0.2, 0, metal_height, cl/2 };

Line(11) = { 7, 11};
Line(12) = { 11, 10 };
Line(13) = { 10, 8 };

Line Loop(3) = { 8, 11, 12, 13 };

Plane Surface(3) = { 3 };

//
// bain
//
Point(14) = { da + anode_length, 0, metal_height + bath_height, cl };
Point(15) = { anode_length + da, 0, metal_height + acd, cl/2 };
Point(16) = { da, 0, metal_height + acd, cl/2 };
Point(17) = { da, 0, metal_height + bath_height, cl };
Point(18) = { 0, 0, metal_height + bath_height, cl };
p12[] = Translate { 0.05, 0, 0.14 } { Duplicata{ Point{11}; } };
p13[] = Translate { 0.05, 0, 0 } { Duplicata{ Point{14}; }};

Line(20) = { 10, 18 };
Line(19) = { 18, 17 };
Line(18) = { 17, 16 };
Line(17) = { 16, 15 };
Line(16) = { 15, 14 };
Line(15) = { 14, p13[0] };
Spline(14) = { p13[0], p12[0], 11 };
//Line(21) = { p12[0], 11 };

Line Loop(4) = { 12, 20, 19, 18, 17, 16, 15, 14 };

Plane Surface(4) = { 4 };

//
// anode
//
h = metal_height + acd + anode_height;
x = anode_length - gr_pos - 2*gr_w;
Point(201) = { da + anode_length, 0, h, cl };
Point(21) = { da + anode_length - x + gr_diam/2, 0, h, cl };
Point(22) = { da + anode_length - x + gr_diam/2, 0, h-gr_depth, cl };
Point(23) = { da + anode_length - x - gr_diam/2, 0, h-gr_depth, cl };
Point(24) = { da + anode_length - x - gr_diam/2, 0, h, cl };

Point(25) = { da + anode_length - x - gr_w + gr_diam/2, 0, h, cl };
Point(26) = { da + anode_length - x - gr_w + gr_diam/2, 0, h-gr_depth, cl };
Point(27) = { da + anode_length - x - gr_w - gr_diam/2, 0, h-gr_depth, cl };
Point(28) = { da + anode_length - x - gr_w - gr_diam/2, 0, h, cl };

Point(29) = { da + anode_length - x - 2*gr_w + gr_diam/2, 0, h, cl };
Point(30) = { da + anode_length - x - 2*gr_w + gr_diam/2, 0, h-gr_depth, cl };
Point(31) = { da + anode_length - x - 2*gr_w - gr_diam/2, 0, h-gr_depth, cl };
Point(32) = { da + anode_length - x - 2*gr_w - gr_diam/2, 0, h, cl };

Point(33) = { da, 0, h, cl };

Line(21) = { 14, 201 };
Line(22) = { 201, 21 };
Line(23) = { 21, 22 };
Line(24) = { 22, 23 };
Line(25) = { 23, 24 };
Line(26) = { 24, 25 };
Line(27) = { 25, 26 };
Line(28) = { 26, 27 };
Line(29) = { 27, 28 };
Line(30) = { 28, 29 };
Line(31) = { 29, 30 };
Line(32) = { 30, 31 };
Line(33) = { 31, 32 };
Line(34) = { 32, 33 };
Line(35) = { 33, 17 };

Line Loop(5) = { 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 18, 17, 16 };

Plane Surface(5) = { 5 };


//
// griffe
//
h = h + gr_height - gr_depth + gr_diam/2;
Point(34) = { da + anode_length - x + gr_diam/2, 0, h, cl };
Point(35) = { da + anode_length - x - gr_w + gr_diam/2, 0, h, cl };
Point(36) = { da + anode_length - x - gr_w + gr_diam/2, 0, h + stub_height, cl };
Point(37) = { da + anode_length - x - gr_w - gr_diam/2, 0, h + stub_height, cl };
Point(38) = { da + anode_length - x - gr_w - gr_diam/2, 0, h, cl };
Point(39) = { da + anode_length - x - 2*gr_w - gr_diam/2, 0, h, cl };

h = h - gr_diam;
Point(40) = { da + anode_length - x - 2*gr_w + gr_diam/2, 0, h, cl };
Point(41) = { da + anode_length - x - gr_w - gr_diam/2, 0, h, cl };
Point(42) = { da + anode_length - x - gr_w + gr_diam/2, 0, h, cl };
Point(43) = { da + anode_length - x - gr_diam/2, 0, h, cl };

Line(36) = { 24, 43 };
Line(37) = { 43, 42 };
Line(38) = { 42, 25 };
Line(39) = { 28, 41 };
Line(40) = { 41, 40 };
Line(41) = { 40, 29 };
Line(42) = { 32, 39 };
Line(43) = { 39, 38 };
Line(44) = { 38, 37 };
Line(45) = { 37, 36 };
Line(46) = { 36, 35 };
Line(47) = { 35, 34 };
Line(48) = { 34, 21 };

Line Loop(6) = { 23, 24, 25, 36, 37, 38, 27, 28, 29, 39, 40, 41, 31, 32, 33, 42, 43,44,45,46,47,48 };

Plane Surface(6) = { 6 }; 

//
// create 3d slice
//

v1[] = Extrude { 0,0.1,0 } { Surface{1}; };
v2[] = Extrude { 0,0.1,0 } { Surface{2}; };
v3[] = Extrude { 0,0.1,0 } { Surface{3}; };
v4[] = Extrude { 0,0.1,0 } { Surface{4}; };
v5[] = Extrude { 0,0.1,0 } { Surface{5}; };
v6[] = Extrude { 0,0.1,0 } { Surface{6}; };


Physical Volume(1) = { v1[1] };
Physical Volume(2) = { v2[1] };
Physical Volume(3) = { v3[1] };
Physical Volume(4) = { v4[1] };
Physical Volume(5) = { v5[1] };
Physical Volume(6) = { v6[1] };
