/*********************************************************************
 *
 *  Gmsh tutorial 10
 *
 *  General mesh size fields
 *
 *********************************************************************/

// In addition to specifying target mesh sizes at the points of the
// geometry (see t1) or using a background mesh (see t7), you can use
// general mesh size "Fields".

// Let's create a simple rectangular geometry
lc = .15;
lc1=lc*2;
Point(1) = {0.0,0.0,0,lc1}; Point(2) = {1,0.0,0,lc1};
Point(3) = {1,1,0,lc1};     Point(4) = {0,1,0,lc1};
Point(5) = {0.2,.5,0,lc1};

Line(1) = {1,2}; Line(2) = {2,3}; Line(3) = {3,4}; Line(4) = {4,1};

Line Loop(5) = {1,2,3,4}; Plane Surface(6) = {5};
Transfinite Line {1:4} = 40;
// // Say we would like to obtain mesh elements with size lc/30 near line 1 and
// // point 5, and size lc elsewhere. To achieve this, we can use two fields:
// // "Attractor", and "Threshold". We first define an Attractor field (Field[1])
// // on points 5 and on line 1. This field returns the distance to point 5 and to
// // (100 equidistant points on) line 1.
Field[1] = Attractor;
Field[1].NodesList = {1};
//Field[1].NNodesByEdge = 12;
//Field[1].EdgesList = {1, 2, 3,4};
// 
// // We then define a Threshold field, which uses the return value of the
// // Attractor Field[1] in order to define a simple change in element size around
// // the attractors (i.e., around point 5 and line 1)
// //
// // LcMax -                         /------------------
// //                               /
// //                             /
// //                           /
// // LcMin -o----------------/
// //        |                |       |
// //     Attractor       DistMin   DistMax
Field[2] = Threshold;
Field[2].IField = 1;
Field[2].LcMin = lc / 30;
Field[2].LcMax = lc;
Field[2].DistMin = 0.0;
Field[2].DistMax = 0.2;
// 
// ////Background Field = 2;
// // Say we want to modulate the mesh element sizes using a mathematical function
// // of the spatial coordinates. We can do this with the MathEval field:
// 
// // Field[3] = MathEval;
//  //Field[3].F = "Cos(4*3.14*x) * Sin(4*3.14*y) / 10 + 0.101";
// // 
// // // We could also combine MathEval with values coming from other fields. For
// // // example, let's define an Attractor around point 1
//  Field[4] = Attractor;
//  Field[4].NodesList = {1};
// // 
// // // We can then create a MathEval field with a function that depends on the
// // // return value of the Attractr Field[4], i.e., depending on the distance to
// // // point 1 (here using a cubic law, with minumum element size = lc / 100)
//  Field[5] = MathEval;
//  Field[5].F = Sprintf("F4^3 + %g", lc / 100);
// // 
// // // We could also use a Box field to impose a step change in element sizes inside
// // a box
//  Field[6] = Box;
//  Field[6].VIn = lc / 2;
//  Field[6].VOut = lc1;
//  Field[6].XMin = 0 -0.2;
//  Field[6].XMax = 0+0.2;
//  Field[6].YMin = 0-0.2;
//  Field[6].YMax = 1+0.2;
// // 
// // // Many other types of fields are available: see the reference manual for a
// // // complete list. You can also create fields directly in the graphical user
// // // interface by selecting Define->Fields in the Mesh module.
// // 
// // // Finally, let's use the minimum of all the fields as the background mesh field
// //  Field[3] = BoundaryLayer;
// // Field[3].EdgesList = {1, 2};
// // //Field[3].NodesList = {1, 2, 3, 4};
// //  Field[3].hfar = 0.05;
// // // Field[3].hwall_n = 0.02;
// //  Field[3].hwall_t = 0.003;
// // // Field[3].ratio = 1.1;
// //  Field[3].thickness = 0.001;
// 
//   Field[8] = BoundaryLayer;
// Field[8].EdgesList = {1, 2, 3,4};
// //Field[3].NodesList = {1, 2, 3, 4};
//  Field[8].hfar = 2;
// Field[8].hwall_n = 0.02;
//  Field[8].hwall_t = 0.02;
// // Field[3].ratio = 1.1;
//  Field[8].thickness = 0.03;
// 
 Field[7] = Min;
 Field[7].FieldsList = {2};
//  Field[7].FieldsList = { 3,8, 5, 6};
// 
 Background Field = 7;
// 
// // If the boundary mesh size was too small, we could ask not to extend the
// // elements sizes from the boundary inside the domain:
//Mesh.CharacteristicLengthExtendFromBoundary = 0;
// Mesh  2;
