
SetFactory("OpenCASCADE");

////// Thruster box

box_length=0.10;
box_radius=0.10;

Cylinder(1) = {-box_length, 0, 0, box_length, 0, 0, box_radius, 2*Pi};

////// ErosionTargets 

target_size=0.10;
torad = Pi/180.0;

teta(1) = 35*torad;
teta(2) = 44*torad;
teta(3) = 53*torad;
teta(4) = 62*torad;
teta(5) = 71*torad;

For k In {1:5:1}

   Box(k+1) = {1.0, -target_size/2.0, -target_size/2.0, 0.02, target_size, target_size};

   x(k) = Cos(teta(k));
   z(k) = Sin(teta(k));

   Translate {x(k)-1, 0, z(k)} {
     Volume{k+1}; 
   }
   Rotate {{0, 1, 0}, {x(k), 0, z(k)}, -(4+k)*Pi/180.} {
     Volume{k+1}; 
   }

EndFor

////// SputterTarget

teta = 60*torad;

Box(7) = {0.0, -target_size/2.0, -target_size/2.0, 0.02, target_size, target_size};
Translate {Cos(teta),-Sin(teta),0.0} {
     Volume{k+1}; 
   }
   
Delete {
     Volume{7}; Volume{1}; Volume{2}; Volume{3}; Volume{4}; Volume{5}; Volume{6}; 
}

Delete {
  Surface{2}; 
}

////// Contamination target

ne = newreg;
Circle(ne)   = {0.5, -0.866025, 0.05, 0.5, 3*Pi/4, 5*Pi/4};
Circle(ne+1) = {0.5, -0.866025,-0.05, 0.5, 3*Pi/4, 5*Pi/4};
Circle(ne+2) = {0.5, -0.866025, 0.05, 0.52, 3*Pi/4, 5*Pi/4};
Circle(ne+3) = {0.5, -0.866025, -0.05, 0.52, 3*Pi/4, 5*Pi/4};

Line(80) = {56, 52};
Line(81) = {52, 54};
Line(82) = {54, 58};
Line(83) = {58, 56};
Line(84) = {55, 51};
Line(85) = {51, 53};
Line(86) = {53, 57};
Line(87) = {57, 55};

Curve Loop(40) = {76, 81, -77, -85};
Surface(40) = {40};
Curve Loop(42) = {83, -78, -87, 79};
Surface(41) = {42};
Curve Loop(44) = {80, 81, 82, 83};
Surface(42) = {44};
Curve Loop(46) = {84, 85, 86, 87};
Surface(43) = {46};
Curve Loop(48) = {76, -80, -78, 84};
Surface(44) = {48};
Curve Loop(50) = {82, -79, -86, 77};
Surface(45) = {50};

////// FarField

SetFactory("Built-in");
Coherence;
SyncModel;

r = 1.40;
np=newp;
nc = np+5;

Point(np)   = {0.0,   r, 0.0, 0.1};
Point(np+1) = {0.0, 0.0,   r, 0.1};
Point(np+2) = {0.0,  -r, 0.0, 0.1};
Point(np+3) = {0.0, 0.0,  -r, 0.1};
Point(np+4) = {  r, 0.0, 0.0, 0.1};
Point(np+5) = {0.0, 0.0, 0.0, 0.1};
Point(np+6) = {-0.5, 0.0, 0.0, 0.1};

ne = newreg;
Circle(ne)   = {np  , np+5, np+1};
Circle(ne+1) = {np+1, np+5, np+2};
Circle(ne+2) = {np+2, np+5, np+3};
Circle(ne+3) = {np+3, np+5,   np};

Circle(ne+4) = {np+1, np+5, np+4};
Circle(ne+5) = {np+4, np+5, np+3};
Circle(ne+6) = {  np, np+5, np+4};
Circle(ne+7) = {np+4, np+5, np+2};

Ellipse(ne+8) = {np, np+5, np+2, np+6};
Ellipse(ne+9) = {np+2, np+5, np, np+6};
Ellipse(ne+10) = {np+1, np+5, np+3, np+6};
Ellipse(ne+11) = {np+3, np+5, np+1, np+6};

Curve Loop(52) = {92, 95, -89};
Surface(46) = {52};
Curve Loop(53) = {92, -94, 88};
Surface(47) = {53};
Curve Loop(54) = {94, 93, 91};
Surface(48) = {54};
Curve Loop(55) = {93, -90, -95};
Surface(49) = {55};
Curve Loop(56) = {88, 98, -96};
Surface(50) = {56};
Curve Loop(57) = {89, 97, -98};
Surface(51) = {57};
Curve Loop(58) = {97, -99, -90};
Surface(52) = {58};
Curve Loop(59) = {99, -96, -91};
Surface(53) = {59};

////// Thruster

ri = 0.0525;
re = 0.0735;

np=newp;
Point(np+1)   = {0.0,   ri, 0.0, 0.1};
Point(np+2)   = {0.0,  0.0,  ri, 0.1};
Point(np+3)   = {0.0,  -ri, 0.0, 0.1};
Point(np+4)   = {0.0,  0.0, -ri, 0.1};

Point(np+5)   = {0.0,   re, 0.0, 0.1};
Point(np+6)   = {0.0,  0.0,  re, 0.1};
Point(np+7)   = {0.0,  -re, 0.0, 0.1};
Point(np+8)   = {0.0,  0.0, -re, 0.1};

ne = newreg;
Circle(ne+1)   = {np+1, nc, np+2};
Circle(ne+2)   = {np+2, nc, np+3};
Circle(ne+3)   = {np+3, nc, np+4};
Circle(ne+4)   = {np+4, nc, np+1};

ne = newreg;
Circle(ne+1)   = {np+5, nc, np+6};
Circle(ne+2)   = {np+6, nc, np+7};
Circle(ne+3)   = {np+7, nc, np+8};
Circle(ne+4)   = {np+8, nc, np+5};

Curve Loop(60) = {101, 102, 103, 104};
Plane Surface(54) = {60};
Curve Loop(61) = {1};
Curve Loop(62) = {106, 107, 108, 109};
Plane Surface(55) = {61, 62};
Plane Surface(56) = {60, 62};


Transfinite Curve {5, 6, 7, 4, 17, 18, 19, 16, 29, 28, 31, 30, 43, 40, 41, 42, 53, 54, 55, 52} = 11 Using Progression 1;
Transfinite Curve {57, 58, 59, 56, 45, 46, 47, 44, 33, 34, 35, 32, 21, 22, 23, 20, 9, 10, 11, 8} = 8 Using Progression 1;
Transfinite Curve {69, 70, 71, 68} = 8 Using Progression 1;
Transfinite Curve {65, 66, 67, 64} = 11 Using Progression 1;
Transfinite Curve {76, 77} = 31 Using Progression 1;
Transfinite Curve {81, 85} = 7 Using Progression 1;
Transfinite Curve {78, 79} = 21 Using Progression 1;
Transfinite Curve {83, 87} = 7 Using Progression 1;

Transfinite Curve {101, 102, 103, 104} = 7 Using Progression 1;
Transfinite Curve {107, 108, 109, 106} = 10 Using Progression 1;
Transfinite Curve {1} = 33 Using Progression 1;
Transfinite Curve {3} = 25 Using Progression 1;

Merge "attractor_TestCase.geo";
Mesh.CharacteristicLengthExtendFromBoundary = 0;

Surface Loop(8) = {50, 47, 46, 49, 48, 53, 52, 51};
Surface Loop(9) = {29, 30, 32, 28, 33, 31};
Surface Loop(10) = {23, 24, 26, 22, 27, 25};
Surface Loop(11) = {17, 18, 20, 16, 21, 19};
Surface Loop(12) = {11, 12, 14, 10, 15, 13};
Surface Loop(13) = {4, 6, 8, 7, 5, 9};
Surface Loop(14) = {1, 55, 56, 54, 3};
Surface Loop(15) = {35, 36, 38, 34, 39, 37};
Surface Loop(16) = {40, 43, 41, 45, 42, 44};

Volume(1) = {8, 9, 10, 11, 12, 13, 14, 15, 16};

////// Physical Groups

Physical Surface("Far Field", 110) = {51, 52, 53, 49, 48, 47, 50, 46};

Physical Surface("Thruster Box", 1001) = {3, 1, 54, 55};

Physical Surface("Erosion Sample #1", 1002) = {4};

Physical Surface("Erosion Sample #2", 1003) = {10};

Physical Surface("Erosion Sample #3", 1004) = {16};

Physical Surface("Erosion Sample #4", 1005) = {22};

Physical Surface("Erosion Sample #5", 1006) = {28};

Physical Surface("Erosion Samples back", 1007) = {5, 9, 6, 8, 7, 15, 13, 14, 12, 11, 17, 21, 18, 20, 19, 27, 24, 26, 25, 23, 33, 30, 32, 29, 31};

Physical Surface("Sputter Target", 1008) = {34};

Physical Surface("Sputter Target back", 1009) = {35, 39, 37, 38, 36};

Physical Surface("Contamination Target", 1010) = {40};

Physical Surface("Contamination Target back", 1011) = {41, 42, 43, 44, 45};

Physical Surface("Thruster", 1012) = {56};
