// Gmsh project created on Mon Jun 25 18:58:22 2018
SetFactory("OpenCASCADE");

//Inputs
x_cube = 2;
y_cube = 2;
z_cube = 2;
r_curv = 0.4;

x_dom = 10;
y_dom = 10;
z_dom = 10;

//Position cube in domain (centred)

x0 = (x_dom-x_cube)/2;
y0 = (y_dom-y_cube)/2;
z0 = (z_dom-z_cube)/2;

//Outer cube (domain)
Box(1) = {0, 0, 0, x_dom, y_dom, z_dom};

//Inner cube
Box(2) = {x0, y0, z0, x_cube, y_cube, z_cube};
Fillet{2}{13,14,15,16,17,18,19,20}{r_curv}
Delete { Volume{2}; }

//Connect inner and outer cube

Line(41) = {22, 5};
Line(42) = {18, 5};
Line(43) = {14, 1};
Line(44) = {10, 1};
Line(45) = {12, 3};
Line(46) = {16, 3};
Line(47) = {20, 7};
Line(48) = {24, 7};
Line(49) = {21, 6};
Line(50) = {17, 6};
Line(51) = {13, 2};
Line(52) = {9, 2};
Line(53) = {11, 4};
Line(54) = {15, 4};
Line(55) = {19, 8};
Line(56) = {23, 8};

//define surfaces

Line Loop(21) = {46, 12, -47, -30}; Plane Surface(21) = {21};
Line Loop(22) = {47, -48, 39};Plane Surface(22) = {22};
Line Loop(23) = {48, -6, -41, 38};Plane Surface(23) = {23};
Line Loop(24) = {41, -42, -35};Plane Surface(24) = {24};
Line Loop(25) = {42, -10, -43, 27};Plane Surface(25) = {25};
Line Loop(26) = {43, -44, 19};Plane Surface(26) = {26};
Line Loop(27) = {44, 2, -45, -15};Plane Surface(27) = {27};
Line Loop(28) = {45, -46, -23};Plane Surface(28) = {28};

Line Loop(29) = {54, 11, -55, -28};Plane Surface(29) = {29};
Line Loop(30) = {54, -53, 21};Plane Surface(30) = {30};
Line Loop(31) = {53, -4, -52, 14};Plane Surface(31) = {31};
Line Loop(32) = {52, -51, -17};Plane Surface(32) = {32};
Line Loop(33) = {51, 9, -50, -25};Plane Surface(33) = {33};
Line Loop(34) = {50, -49, 33};Plane Surface(34) = {34};
Line Loop(35) = {49, 8, -56, -36};Plane Surface(35) = {35};
Line Loop(36) = {56, -55, -37};Plane Surface(36) = {36};


//+
Line Loop(37) = {43, 2, -46, -22};Plane Surface(37) = {37};
//+
Line Loop(38) = {42, 6, -47, -31};Plane Surface(38) = {38};
//+
Line Loop(39) = {54, -4, -51, 20};Plane Surface(39) = {39};
//+
Line Loop(40) = {29, 55, -8, -50};Plane Surface(40) = {40};


//+
Line Loop(42) = {48, -7, -56, 40};Plane Surface(41) = {42};
Line Loop(43) = {47, -7, -55, 32};Plane Surface(42) = {43};
Line Loop(44) = {24, 46, -3, -54};Plane Surface(43) = {44};
Line Loop(46) = {45, -3, -53, 16};Plane Surface(44) = {46};
Line Loop(47) = {13, 44, -1, -52};Plane Surface(45) = {47};
Line Loop(48) = {43, -1, -51, 18};Plane Surface(46) = {48};
Line Loop(49) = {50, 5, -42, -26};Plane Surface(47) = {49};
Line Loop(50) = {41, -5, -49, 34};Plane Surface(48) = {50};

//Connection volumes
//Empiezo por caras achaflanadas

//Cara 1

Surface Loop(3) = {38, 23, 24, 22, 18};Volume(3) = {3};
Surface Loop(4) = {23, 2, 35, 20, 48, 41};Volume(4) = {4};
Surface Loop(5) = {34,35,36,17,40};Volume(5) = {5};
Surface Loop(6) = {19, 42, 41, 22, 36};Volume(6) = {6};
Surface Loop(7) = {16, 47, 48, 24, 34};Volume(7) = {7};

//Cara 2
Surface Loop(8) = {10, 37, 27, 26, 28};Volume(8) = {8};
Surface Loop(9) = {7, 27, 1, 44, 45, 31};Volume(9) = {9};
Surface Loop(10) = {9, 31, 39, 30, 32};Volume(10) = {10};
Surface Loop(11) = {8, 46, 45, 26, 32};Volume(11) = {11};
Surface Loop(12) = {44, 43, 11, 28, 30};Volume(12) = {12};

//Troncos de piramide correspondientes a las otras caras
Surface Loop(13) = {13, 33, 5, 29, 39, 40};Volume(13) = {13};
Surface Loop(14) = {21, 14, 25, 38, 37, 6};Volume(14) = {14};
Surface Loop(15) = {12, 25, 46, 33, 47, 3};Volume(15) = {15};
Surface Loop(16) = {15, 21, 29, 42, 43, 4};Volume(16) = {16};

//Define transfinite mesh
Transfinite Line {41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56} = 10 Using Bump 1; //aristas creadas para conectar volumenes (16)
Transfinite Line {15, 16, 14, 13, 19, 23, 32, 21, 17, 18, 22, 20, 24, 26, 31, 29, 33, 38, 35, 39, 40, 34, 36, 37, 27, 25, 30, 28, 9, 1, 10, 2, 12, 6, 3, 7, 11, 8, 5, 4} = 10 Using Bump 1; //aristas del cubo exterior y cubo interior redondeado
Delete { Volume{1}; }

Transfinite Surface {1,2,3,4,5,6,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,7,8,9,10,11,12,13,14,15,16,17,18,19,20};
Recombine Surface {1,2,3,4,5,6,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,7,8,9,10,11,12,13,14,15,16,17,18,19,20};
//Transfinite Volume "*"; //First attempt, volumes 3,5,6,7,8,10,11,12 not meshed
Transfinite Volume {4,9,13,14,15,16};


Physical Volume("int_vol") = {5, 10, 3, 7, 6, 8, 12, 11, 4, 13, 15, 9, 14, 16};
Physical Surface("cube_wall") = {49,50,51,52,53,54,55,56,57,58,59,60,61,62};
Physical Surface("inlet") = {1};
Physical Surface("outlet") = {2};
Physical Surface("back") = {4};
Physical Surface("front") = {3};
Physical Surface("top") = {6};
Physical Surface("bottom") = {5};
