
SetFactory("OpenCASCADE");

//--------------------------------
ri=0.1115;
re=0.1575;
rcat=0.0248;
rgrafite=0.095;
rceramic=0.175;
rsphere = 0.10;
ds=0.007;
rbox=0.20;
dbox=0.25;
inter=0.5;
larm=1;
Rarm=0.04;
Teta=45;   // Rotation around Y
Psi = 0;   // Rotation around z
Beta=90;   // Panel rotation
TetaFF=30; // Far Field rotation
Hsat=3.0;
Wsat=1.4;
Dsat=1.0;
Zthrust=-0.5;

Lpanel=4;
Hpanel=2;
Xpanel=3;
Zpanel=Hsat/2.0-0.50;

Rff=4.0;
Lff = Xpanel+Lpanel-Rff/2.0;

Teta = Teta*Pi/180.0;
Psi = Psi*Pi/180.0;
Beta = Beta*Pi/180.0;
TetaFF = TetaFF*Pi/180.0;
//--------------------------------


Merge "spline.geo";

Transfinite Curve {10, 11} = 13 Using Progression 1;

nl=newl;

Circle(nl  ) = {-0, -inter/2, 0, rcat, 0, 2*Pi};
Circle(nl+1) = {-0, -inter/2, 0, rgrafite, 0, 2*Pi};
Circle(nl+2) = {-0, -inter/2, 0, ri-ds, 0, 2*Pi};
Circle(nl+3) = {-0, -inter/2, 0, ri, 0, 2*Pi};
Circle(nl+4) = {-0, -inter/2, 0, re, 0, 2*Pi};
Circle(nl+5) = {-0, -inter/2, 0, re+ds, 0, 2*Pi};
Circle(nl+6) = {-0, -inter/2, 0, rceramic, 0, 2*Pi};

Rotate {{0, 1, 0}, {0, 0, 0}, Pi/2} {Curve{nl:nl+6};}

Translate {-ds, 0, 0} {
  Curve{nl+3}; Curve{nl+4}; 
}

ll=newll;
ns = news;

Curve Loop(ll) = {nl};
Curve Loop(ll+1) = {nl+1};
Curve Loop(ll+2) = {nl+2};
Curve Loop(ll+3) = {nl+3};
Curve Loop(ll+4) = {nl+4};
Curve Loop(ll+5) = {nl+5};
Curve Loop(ll+6) = {nl+6};

Plane Surface(ns) = {ll};
Plane Surface(ns+1) = {ll+1, ll};
Plane Surface(ns+2) = {ll+2, ll+1};
Plane Surface(ns+3) = {ll+4, ll+3};
Plane Surface(ns+4) = {ll+6, ll+5};

a() = Ruled ThruSections{ll+3,ll+2};
a() = Ruled ThruSections{ll+5,ll+4};

nl=newl;

Circle(nl  ) = {-0, inter/2, 0, rcat, 0, 2*Pi};
Circle(nl+1) = {-0, inter/2, 0, rgrafite, 0, 2*Pi};
Circle(nl+2) = {-0, inter/2, 0, ri-ds, 0, 2*Pi};
Circle(nl+3) = {-0, inter/2, 0, ri, 0, 2*Pi};
Circle(nl+4) = {-0, inter/2, 0, re, 0, 2*Pi};
Circle(nl+5) = {-0, inter/2, 0, re+ds, 0, 2*Pi};
Circle(nl+6) = {-0, inter/2, 0, rceramic, 0, 2*Pi};

Rotate {{0, 1, 0}, {0, 0, 0}, Pi/2} {Curve{nl:nl+6};}

Translate {-ds, 0, 0} {
  Curve{nl+3}; Curve{nl+4}; 
}

ll=newll;
ns = news;

Curve Loop(ll) = {nl};
Curve Loop(ll+1) = {nl+1};
Curve Loop(ll+2) = {nl+2};
Curve Loop(ll+3) = {nl+3};
Curve Loop(ll+4) = {nl+4};
Curve Loop(ll+5) = {nl+5};
Curve Loop(ll+6) = {nl+6};

Plane Surface(ns) = {ll};
Plane Surface(ns+1) = {ll+1, ll};
Plane Surface(ns+2) = {ll+2, ll+1};
Plane Surface(ns+3) = {ll+4, ll+3};
Plane Surface(ns+4) = {ll+6, ll+5};

a() = Ruled ThruSections{ll+3,ll+2};
a() = Ruled ThruSections{ll+5,ll+4};

Extrude {-dbox, 0, 0} {Curve{1}; Curve{2};}

ll = newll;

Curve Loop(ll+1) = {1, 2};
Curve Loop(ll+2) = {9};
Curve Loop(ll+3) = {25};
Plane Surface(35) = {ll+1, ll+2, ll+3};

Cylinder(1) = {-dbox-0.10, 0, 0, 0.1, 0, 0, rsphere, 2*Pi};
Sphere(2) = {-dbox-0.1, 0, 0, rsphere, -Pi/2, Pi/2, 2*Pi};

BooleanUnion{ Volume{2}; Delete; }{ Volume{1}; Delete; }

Delete {Volume{1};}
Delete {Surface{38};}

Curve Loop(44) = {30, 31};
Curve Loop(45) = {37};
Plane Surface(38) = {44, 45};

Surface Loop(2) = {36, 37, 38, 33, 34, 35, 14, 16, 13, 15, 12, 11, 10, 30, 32, 29, 31, 28, 27, 26};
Volume(1) = {2};

Delete {
  Point{2:74}; 
}

//// ROTATIONS ///////////////////////////////////////

Point(9999)={-ds, inter/2.0,   0.00000, 1.0};

/// ROTATE AROUND Y

Rotate {{0, 1, 0}, {-dbox-0.1, 0, 0}, Teta} {Volume{1};Point{9999};}

/// ROTATE AROUND Z

Rotate {{0, 0, 1}, {-dbox-0.1, 0, 0}, Psi} {Volume{1};Point{9999};}

//////////////////////////////////////////////////////


// Spacecraft Box -------------------------------------

Box(2) = {-Wsat/2, -Dsat/2, -Hsat/2, Wsat, Dsat, Hsat};

//-----------------------------------------------------

// Thrusters in place ---------------------------------

Translate {larm+Wsat/2+0.1+dbox, 0, Zthrust} {Volume{1};Point{9999}; }

//-----------------------------------------------------

Cylinder(3) = {Wsat/2-0.01, 0, Zthrust, larm+0.01, 0, 0, Rarm, 2*Pi};

BooleanUnion{ Volume{2}; Delete; }{ Volume{3}; Delete; }
BooleanFragments{ Volume{2}; Delete; }{ Volume{1}; }
Delete {Volume{3};}
Delete {Surface{55}; Surface{56};}
Delete {Curve{89}; Curve{88};}

BooleanUnion{ Volume{2}; Delete; }{ Volume{1}; Delete; }

//Box(2) = {Xpanel, -0.01, Zpanel-Hpanel/2.0, Lpanel, 0.02, Hpanel};

/// ROTATE PANEL

//Rotate {{1, 0, 0}, {Xpanel, 0.0, Zpanel}, Beta} {Volume{2}; }

/// FAR FIELD

nv=newv;

Cylinder(nv+1) = {-Wsat/2+Rff/2, 0, 0, Lff+Wsat/2-Rff/2, 0, 0, 4, 2*Pi};
Sphere(nv+2) = {Lff, 0, 0, Rff, -Pi/2, Pi/2, 2*Pi};
Sphere(nv+3) = {-Wsat/2+Rff/2, 0, 0, Rff, -Pi/2, Pi/2, 2*Pi};

BooleanUnion{ Volume{nv+1}; Delete; }{ Volume{nv+2}; Delete; }
BooleanUnion{ Volume{nv+4}; Delete; }{ Volume{nv+3}; Delete; }

/// BACKGROUND ------------

Merge "background.geo";
//Merge "background_b.geo";

/// VOLUME ----------------
