/*********************************************************************
 *
 *********************************************************************/

//BEGIN(parameters)
 
// Height and Length

H = 1125.0;
L = 500.0;

// number of refined lines
N_ref = 2;

// Spacing between lines
ref_spacing = 32.0;


ref_width = 0.75;

a = 400.0;

// minimum and maximum mesh size

e_min = 0.125;
e_max = 37.5;

//END(parameters)

////////////////////////////////////////////////////////
////////////////////////////////////////////////////////
///	        		  Phase A 			    		 ///
////////////////////////////////////////////////////////
////////////////////////////////////////////////////////

////////////////////////////////////////////////////////
// bottom points

Point(1) = {0,0,0,e_max};
Point(2) = {L, 0, 0, e_max};

var_phys = {};

For i_count In {1 : N_ref}
	
	///////////////////////////////////////////////////////
	// y-position of of GP at begin and at intersection with interface

	y_start = H/2 - ((N_ref - 1)/2 - (i_count - 1)) * ref_spacing;
	
	////////////////////////////////
	// add refined line bottom points
	
	point_inc = (i_count-1)*4;

	Point(3+point_inc) = {0, y_start, 0, e_max};
	Point(4+point_inc) = {L, y_start, 0, e_max};

	////////////////////////////////
	// add refined line top points
	Point(5+point_inc) = {0, y_start, 0, e_max};
	Point(6+point_inc) = {L, y_start, 0, e_max};
	
	////////////////////////////////////////////////////////
	// Lines
	
	Line(1+point_inc) = {1+point_inc,2+point_inc};
	Line(2+point_inc) = {2+point_inc,4+point_inc};
	Line(3+point_inc) = {3+point_inc,4+point_inc};
	Line(4+point_inc) = {3+point_inc,1+point_inc};
	
	////////////////////////////////
	// surface creation
	
	Line Loop(i_count) = {1+point_inc,2+point_inc,-(3+point_inc),4+point_inc};
	Plane Surface(i_count) = {i_count};
	
	var_phys += {i_count};
	
EndFor

////////////////////////////////////////////////////////
// bottom points

point_inc = N_ref*4;

Point(3+point_inc) = {0, H, 0, e_max};
Point(4+point_inc) = {L, H, 0, e_max};

////////////////////////////////////////////////////////
// Lines

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

////////////////////////////////
// surface creation

Line Loop(N_ref+1) = {1+point_inc,2+point_inc,-(3+point_inc),4+point_inc};
Plane Surface(N_ref+1) = {N_ref+1};


////////////////////////////////////////////////////////
////////////////////////////////////////////////////////
///	         		 refinements	   		 		 ///
////////////////////////////////////////////////////////
////////////////////////////////////////////////////////

gp_lines = {};

// lines to set a max. to the element size between the glide planes

For i_count In {1 : N_ref}
	y_start = H/2 - ((N_ref - 1)/2 - (i_count - 1)) * ref_spacing;
	Point(1000+i_count) = {L, y_start, 0, e_max};
	Point(1100 + i_count) = {a, y_start, 0, e_max};
	Line(1100 + i_count) = {1100 + i_count,1000 + i_count};
	
	gp_lines += {1100 + i_count};
	
EndFor

gp_lines+= 6;
gp_lines+= 7;
gp_lines+= 3;
gp_lines+= 8;

// Set the points along the line at which the refinement is evaluated --> set distance between points half ref_width

Field[1] = Attractor;
Field[1].NNodesByEdge = 2*(L - a)/ref_width + 1;
Field[1].EdgesList = {gp_lines[]};

Field[2] = Threshold;
Field[2].IField = 1;
Field[2].LcMin = e_min;
Field[2].LcMax = e_max;
Field[2].DistMin = ref_width;
Field[2].DistMax = 1.5*e_max;

Background Field = 2;
