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

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

/// INTRODUCTION: 3D meshing


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

Include "parameters.par";


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

Printf("wire width [m]: %g", wireWidth);
Printf("wire thickness [m^2]: %g", wireThickness);


//////////////////
/// 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.;

/// Wire ///
x_1 = (-1)*0.5*wireWidth; y_1 = (-1)*0.5*wireThickness;
x_2 = (-1)*x_1;           y_2 = y_1;
x_3 = (-1)*x_1;           y_3 = (-1)*y_1;
x_4 = x_1;                y_4 = (-1)*y_1;

/// Surroundings of the wire ///
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;

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

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

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

/// Wire ///
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("Wire surface", wireSurfaceID) = {1};
tmpVolume_1[] = Extrude {0, 0, modelThickness} {Surface{1}; Layers{4}; Recombine;};
Physical Volume("Wire volume", wireVolumeID) = {tmpVolume_1[1]};
Physical Surface("Nodal to edge surface", nodalEdgeBoundarySurfaceID) = {tmpVolume_1[2], tmpVolume_1[3], tmpVolume_1[4], tmpVolume_1[5]};

/// Surroundings of the wire ///
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("Surrounding surface", surroundingSurfaceID) = {2};
tmpVolume_2[] = Extrude {0, 0, modelThickness} {Surface{2}; Layers{4};};
Physical Volume("Surrounding volume", surroundingVolumeID) = {tmpVolume_2[1]};


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

If (isQuadMeshWanted == 1)
 Transfinite Line{1, 3} = nQuad_1;
 Transfinite Line{2, 4} = nQuad_2;
 Transfinite Surface{1} = {1, 2, 3, 4}; // Left: surface id , right: list of points at corners of the surface
 Recombine Surface {1}; // just quad, surface id
EndIf

/// Color of meshes:
Color Red {Volume {1};} // wire
Color Blue {Volume {2};} // surroundings

/// Remove duplicate nodes of the mesh ///
Coherence Mesh;
/// Optimize mesh:
Mesh.Optimize = 1;

/// Cohomology computation (split the mesh, 1 =  dimension of the splitting object with id = surroundingID+1):
Cohomology(1){surroundingVolumeID, {}};

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

General.ExpertMode = 1;

