// Gmsh project created on Sun Apr 21 21:12:12 2019
SetFactory("OpenCASCADE");
Geometry.OCCTargetUnit = 'M';
Merge "msfr_gmsh.stp";

//Remove duplicate entities from CAD model
Coherence;

//Define Physical Volumes
Physical Volume("core", 10001) = {1, 5, 7, 9, 10};
Physical Volume("pump", 10002) = {6};
Physical Volume("heat_exchanger", 10003) = {8};
Physical Volume("blanket", 20001) = {3};
Physical Volume("reflectors", 20003) = {4, 2};
//Define Physical Surfaces
allVolumes[] = Volume{:};
total_bnd[]=CombinedBoundary{Volume{allVolumes[]};};
refl_bnd[] = {80,91,84,74,81,88,87,85};
Physical Surface("adiabatic_void", 996)={total_bnd[]}; Physical Surface("adiabatic_void", 996)-={refl_bnd[]};
Physical Surface("symmetry_reflective", 995) = {refl_bnd[]};


//Setting the mesh size. Use Fields: nice and tunable. Based on tutorial 10
l_max = 0.07;
l_hx = 0.05;
l_legs = 0.035;

Mesh.CharacteristicLengthMax=l_max; //This is the max allowed mesh size, anywhere

// Field to get a smooth mesh transition towards the legs
Field[1] = Distance;
Field[1].NodesList = {95,96,102,103};
Field[2] = Threshold;
Field[2].IField = 1;
Field[2].LcMin = l_legs;
Field[2].LcMax = l_max;
Field[2].DistMin = 0.2;
Field[2].DistMax = 0.5;

// Field to be able to tune the mesh size in the heat exchanger
Field[3] = Box;
Field[3].VIn = l_hx;
Field[3].VOut = l_max;
Field[3].XMin = -0.76;
Field[3].XMax = 0.0;
Field[3].YMin = 1.68;
Field[3].YMax = 2.215;
Field[3].ZMin = -0.85;
Field[3].ZMax = 0.85;

// Fields to be able to tune the mesh size in the legs
// Inlet leg
Field[4] = Box;
Field[4].VIn = l_legs;
Field[4].VOut = l_max;
Field[4].XMin = -0.54;
Field[4].XMax = 0.0;
Field[4].YMin = 1.302;
Field[4].YMax = 2.011;
Field[4].ZMin = 0.85;
Field[4].ZMax = 1.3;
// Outlet leg
Field[5] = Box;
Field[5].VIn = l_legs;
Field[5].VOut = l_max;
Field[5].XMin = -0.54;
Field[5].XMax = 0.0;
Field[5].YMin = 1.302;
Field[5].YMax = 2.011;
Field[5].ZMin = -1.3;
Field[5].ZMax = -0.85;

// Take the minimum of all fields
Field[6] = Min;
Field[6].FieldsList = {2, 3, 4, 5};
Background Field = 6;



// Try to recombine into hexahedra (from tutorial 11)
Mesh.RecombineAll = 1;
Mesh.RecombinationAlgorithm = 2;

//Set some meshing options
Mesh.Algorithm = 1;
Coherence Mesh; // Removes duplicate mesh nodes