// ===========================================================================//
//                                                                            //
//  Parametrised Model for 3D Thermo-Fluid Modelling of FSW                   //
//                                                                            //
//  Description:                                                              //
//  ...                                                                       //
//                                                                            //
// ===========================================================================//
// -- GMSH parameters ----------------------------------------------------------
Mesh.Smoothing = 1;
Mesh.CharacteristicLengthExtendFromBoundary = 1;
//Mesh.Format = msh1;
//
// ---------------------------------------------------------------------------//
//   Model parameters                                                         //
// ---------------------------------------------------------------------------//
tool_diameter               = 0.100; 
tool_length1                = 0.050;
tool_length2                = 0.050;
shoulder_diameter           = 0.0254*0.9105;
probe_thread_inner_diameter_top = shoulder_diameter*0.38346;
probe_thread_outer_diameter_top = probe_thread_inner_diameter_top + 0.004;
probe_thread_inner_diameter_bottom = shoulder_diameter*0.24812;
probe_thread_outer_diameter_bottom = probe_thread_inner_diameter_bottom + 0.004;
probe_length                = 0.0254*0.2725;
shoulder_scroll_depth       = 0.001;
layer_thickness1            = shoulder_scroll_depth;
layer_thickness2            = 0.0006;
layer_thickness3            = 0.00044;
layer_thickness4            = 0.0006;
layer_thickness5            = 0.0012;
workpiece_thickness         = 0.0254/2.0; // 1/2"
workpiece_diameter          = 0.2500;
refined_mesh_extension      = 0.0050;
contact_layer_thickness     = 0.0005;
backplate_thickness         = 0.1000;
//
tool_radius               = tool_diameter/2.0; 
shoulder_radius           = shoulder_diameter/2.0;
probe_thread_inner_radius_top = probe_thread_inner_diameter_top/2.0;
probe_thread_outer_radius_top = probe_thread_outer_diameter_top/2.0;
probe_thread_inner_radius_bottom = probe_thread_inner_diameter_bottom/2.0;
probe_thread_outer_radius_bottom = probe_thread_outer_diameter_bottom/2.0;
workpiece_radius          = workpiece_diameter/2.0;
//
// ---------------------------------------------------------------------------//
//   Offset factors                                                           //
// ---------------------------------------------------------------------------//
offset_factor1 = 0.2;
offset1        = offset_factor1 * layer_thickness2;
offset_factor2 = 0.6;
offset2        = offset_factor2 * layer_thickness3;
offset_factor3 = 0.2;
offset3        = offset_factor3 * layer_thickness3;
offset_factor4 = 0.2;
offset4        = offset_factor4 * layer_thickness4;
offset_on_axis_factor = 0.2;
offset_on_axis = probe_thread_inner_radius_top * offset_on_axis_factor;

// -- Other --------------------------------------------------------------------
h = 0.0001;
//
// ---------------------------------------------------------------------------//
//   Coordinates                                                              //
// ---------------------------------------------------------------------------//
// -- X ------------------------------------------------------------------------
x0  = 0.0;
xa =  x0 + offset_on_axis;
x1  = x0 + probe_thread_inner_radius_top;
x2  = x0 + probe_thread_outer_radius_top;
x3  = x1 + layer_thickness3;
x4  = x0 + probe_thread_inner_radius_bottom - layer_thickness3;
x5  = x0 + shoulder_radius;
x6  = tool_radius;
x7  = workpiece_radius;
x8  = x5 + layer_thickness1;
x9  = x5 + layer_thickness2;
x10 = x5 - layer_thickness2;
x11 = shoulder_radius + refined_mesh_extension;
x12 = probe_thread_outer_radius_top + refined_mesh_extension;
x13 = x3 + offset2;
x14 = x9 - offset1;
x15 = x3 - offset3;
x16 = x0 + probe_thread_inner_radius_bottom;
x17 = x0 + probe_thread_outer_radius_bottom;
// - intermediate -
d1 = probe_thread_inner_radius_top;
d3 = probe_thread_inner_radius_bottom;
d2 = probe_thread_outer_radius_top;
d4 = probe_thread_outer_radius_bottom;
p  = probe_length;
//
//
// -- Y ------------------------------------------------------------------------
y0  = 0.0;
y1  = y0  - workpiece_thickness;
y2  = y0  - probe_length;
y3  = y1  - contact_layer_thickness;
y4  = y3  - backplate_thickness;
y5  = y0  + tool_length1;
y6  = y5  + tool_length2;
y7  = y0  - layer_thickness2;
y8  = y0  - layer_thickness1;
y9  = y2  + layer_thickness4;
y10 = y2  - layer_thickness4;
y11 = y2  - layer_thickness5;
y12 = y7  + offset1;
y13 = y10 + offset4;
//
x18 = d3*(-y8)/p+d1*(p-(-y8))/p;  
x19 = d3*(-y9)/p+d1*(p-(-y9))/p;  
x20 = d4*(-y7)/p+d2*(p-(-y7))/p;  
x21 = d4*(-y8)/p+d2*(p-(-y8))/p;  
x22 = x18 + layer_thickness3;
x23 = x19 + layer_thickness3;  
x24 = x16 + layer_thickness3; 
x25 = d3*(-y7)/p+d1*(p-(-y7))/p + layer_thickness3 + offset2;  
x26 = d3*(-y10)/p+d1*(p-(-y10))/p; // p38
x27 = d3*(-y13)/p+d1*(p-(-y13))/p + layer_thickness3 - offset3; // p37
x28 = d3*(-y11)/p+d1*(p-(-y11))/p; // p22
//
// -- Z ------------------------------------------------------------------------
z0  = 0.0;
//
// ---------------------------------------------------------------------------//
//   Points                                                                   //
// ---------------------------------------------------------------------------//
Point(1)  = { xa,  y6,  z0, h };
Point(2)  = { x6,  y6,  z0, h };
Point(3)  = { x6,  y5,  z0, h };
Point(4)  = { x5,  y5,  z0, h };
Point(5)  = { x5,  y0,  z0, h };
Point(6)  = { x1,  y0,  z0, h };
Point(7)  = { x16, y2,  z0, h };
Point(8)  = { xa,  y2,  z0, h };
Point(18) = { x2,  y0,  z0, h };
Point(20) = { x18, y8,  z0, h };
Point(30) = { x10, y0,  z0, h };
Point(36) = { x19, y9,  z0, h };
Point(40) = { x4,  y2,  z0, h };
//
// ---------------------------------------------------------------------------//
//   Lines                                                                    //
// ---------------------------------------------------------------------------//
Line(1)     = {  1,  2 };
Line(2)     = {  2,  3 };
Line(3)     = {  3,  4 };
Line(4)     = {  4,  5 };
Line(17)    = {  1,  8 };
Line(26)    = {  5, 30 };
Line(27)    = { 30, 18 };
Line(28)    = { 18,  6 };
Line(29)    = {  6, 20 };
Line(30)    = { 20, 36 };
Line(31)    = { 36,  7 };
Line(32)    = {  7, 40 };
Line(33)    = { 40,  8 };
//
// ---------------------------------------------------------------------------//
//   Surfaces                                                                 //
// ---------------------------------------------------------------------------//
Line Loop(61)      = { 3, 4, 26, 27, 28, 29, 30, 31, 32, 33, -17, 1, 2 };
Plane Surface(62)  = { 61 };
