/////////////////////
/// GMSH GEOMETRY ///
/////////////////////

/// FILE: dynamic2DHFormulation.geo
/// AUTHOR: Frederic Trillaud <ftrillaudp@gmail.com>
/// UNIVERSITY: UNAM
/// INSTITUTE: IINGEN
/// DATE (english): 02/19/2015
/// UNITS: SI otherwise indicated

/// INTRODUCTION: automatic generation of the geometry to be meshed. Case of the simulation of a solenoid magnet using axial symmetry.


///////////////////////////
/// EXTERNAL PARAMETERS ///
///////////////////////////

Include "parameters.par";


/////////////
/// PRINT ///
/////////////

Printf("tape thickness [m]: %g", tapeThickness);
Printf("tape width [m]: %g", tapeWidth);
Printf("tape surface [m^2]: %g", tapeSurface);


//////////////////
/// GEOMETRIES ///
//////////////////

/// Geometry options:
Geometry.Color.Lines = Black;
Geometry.LineWidth = 1;
Geometry.PointSize = 1;

/// Remove duplicate elementary entities allowing to assemble Line Loop() by merging the points defined separately at a same location. To be used upon labelling philosophy.
Coherence;

/// Origin ///
x_0 = 0.; y_0 = 0.; z_0 = 0.;

/// Tape ///
x_1 = (-1)*0.5*tapeWidth; y_1 = (-1)*0.5*tapeThickness;
x_2 = 0.5*tapeWidth;      y_2 = (-1)*0.5*tapeThickness;
x_3 = 0.5*tapeWidth;      y_3 = 0.5*tapeThickness;
x_4 = (-1)*0.5*tapeWidth; y_4 = 0.5*tapeThickness;

/// Surroundings of the tape ///
x_5 = infiniteBoundaryInnerRadius;      y_5 = 0.;
x_6 = 0.;                               y_6 = infiniteBoundaryInnerRadius;
x_7 = (-1)*infiniteBoundaryInnerRadius; y_7 = 0.;
x_8 = 0.;                               y_8 = (-1)*infiniteBoundaryInnerRadius;

/// Infinite region ///
x_9 = infiniteBoundaryOuterRadius;       y_9 = 0.;
x_10 = 0.;                               y_10 = infiniteBoundaryOuterRadius;
x_11 = (-1)*infiniteBoundaryOuterRadius; y_11 = 0.;
x_12 = 0.;                               y_12 = (-1)*infiniteBoundaryOuterRadius;

For i In {1:12}
 z~{i} = 0.;
EndFor

/// List of coordinates:
For i In {0:12}
 x[] += {x~{i}};
 y[] += {y~{i}};
 z[] += {z~{i}};
 n[] += {n~{i}}; // Local length for meshing
EndFor

/// Points ///
For i In {0:12}
 Point(i) = {x[i], y[i], z[i], n[i]};
EndFor

/// Tape ///
Line(1) = {1, 2};
Line(2) = {2, 3};
Line(3) = {3, 4};
Line(4) = {4, 1};
Line Loop(1) = {1, 2, 3, 4};
Plane Surface(1) = {1};
Physical Surface(tapeID) = {1};

/// Surroundings of the tape ///
Circle(5) = {5, 0, 6};
Circle(6) = {6, 0, 7};
Circle(7) = {7, 0, 8};
Circle(8) = {8, 0, 5};
Line Loop(2) = {5, 6, 7, 8};
Plane Surface(2) = {2, 1};
Physical Surface(surroundingID) = {2};

/// Modeling of infinite region ///
Circle(9) = {9, 0, 10};
Circle(10) = {10, 0, 11};
Circle(11) = {11, 0, 12};
Circle(12) = {12, 0, 9};
Line Loop(3) = {9, 10, 11, 12};
Plane Surface(3) = {3, 2};
Physical Surface(electromagneticBoundaryShellID) = {3};


////////////////
/// BOUNDARY ///
////////////////

/// Boundary line on which the boundary condition is applied:
Physical Line(electromagneticBoundaryLineID) = {9, 10, 11, 12};


///////////////
/// MESHING ///
///////////////

/// Quad mesh ///
If (ifQuadMeshWanted == 1)
 Transfinite Line{1, 3} = numberOfNodes_1;
 Transfinite Line{2, 4} = numberOfNodes_2;
 Transfinite Surface{1} = {1, 2, 3, 4};
 Recombine Surface {1};
EndIf


/// Color of meshes:
Color Black {Surface {1};} // tape
Color Green {Surface {2};} // surroundings
Color DarkGrey {Surface {3};} // Infinite boundary


/// Remove duplicate nodes of the mesh ///
//Coherence Mesh;

// Save mesh as binary file ///
Mesh.Binary = 1;
