h = 0.002;
delta = h/0.38;
shock_to_VG = 18*delta;

cl_MR = h/50;
cl_inlet = 2*h;
cl_outlet = 2*h;

height = 30*h;
width = 30*h;
inlet_to_VG = 75*h;
length = 250*h;

shock_angle = 0.732116; // for 10 deg ramp
// shock_angle = 0.756102; // for 12 deg ramp

shock_to_expansion = 5*delta;

// Build points Vortex generator

p_aft_bottom = newp;
Point(p_aft_bottom) = {7.5*h*Cos(24*Pi/180),0,0,cl_MR};

p_aft_upper = newp;
Point(p_aft_upper) = {7.5*h*Cos(24*Pi/180),0,h,cl_MR};

p_nose_front = newp;
Point(p_nose_front) = {0,-7.5*h*Sin(24*Pi/180),0,cl_MR};

p_nose_back = newp;
Point(p_nose_back) = {0,7.5*h*Sin(24*Pi/180),0,cl_MR};

l_MR_bottom_front = newl;
Line(l_MR_bottom_front) = {p_nose_front,p_aft_bottom};

l_MR_bottom_back = newl;
Line(l_MR_bottom_back) = {p_nose_back,p_aft_bottom};

l_nose = newl;
Line(l_nose) = {p_nose_front,p_nose_back};

l_vertical = newl;
Line(l_vertical) = {p_aft_bottom,p_aft_upper};

l_MR_diag_front = newl;
Line(l_MR_diag_front) = {p_nose_front,p_aft_upper};

l_MR_diag_back = newl;
Line(l_MR_diag_back) = {p_nose_back,p_aft_upper};

lineloop = newl;
s_front = news;
Line Loop(lineloop) = {l_MR_bottom_front,l_vertical,-l_MR_diag_front};
Plane Surface(s_front) = {lineloop};

lineloop = newl;
s_back = news;
Line Loop(lineloop) = {l_MR_bottom_back,l_vertical,-l_MR_diag_back};
Plane Surface(s_back) = {lineloop};

// No need to define the bottom surface -> if it is defined it will be meshed!
//lineloop = newl;
//s_bottom = news;
//Line Loop(lineloop) = {l_nose,l_MR_bottom_back,-l_MR_bottom_front};
//Plane Surface(s_bottom) = {lineloop};

lineloop = newl;
s_upper = news;
Line Loop(lineloop) = {l_MR_diag_front,-l_MR_diag_back,-l_nose};
Plane Surface(s_upper) = {lineloop};

// Domain is defined

p_inlet_bottom_back = newp;
Point(p_inlet_bottom_back) = {-inlet_to_VG,width/2,0,cl_inlet};

p_inlet_bottom_front = newp;
Point(p_inlet_bottom_front) = {-inlet_to_VG,-width/2,0,cl_inlet};

p_inlet_upper_back = newp;
Point(p_inlet_upper_back) = {-inlet_to_VG,width/2,height,cl_inlet};

p_inlet_upper_front = newp;
Point(p_inlet_upper_front) = {-inlet_to_VG,-width/2,height,cl_inlet};

p_outlet_bottom_back = newp;
Point(p_outlet_bottom_back) = {length-inlet_to_VG,width/2,0,cl_outlet};

p_outlet_bottom_front = newp;
Point(p_outlet_bottom_front) = {length-inlet_to_VG,-width/2,0,cl_outlet};

p_outlet_upper_back = newp;
Point(p_outlet_upper_back) = {length-inlet_to_VG,width/2,height,cl_outlet};

p_outlet_upper_front = newp;
Point(p_outlet_upper_front) = {length-inlet_to_VG,-width/2,height,cl_outlet};

l_inlet_bottom = newl;
Line(l_inlet_bottom) = {p_inlet_bottom_front,p_inlet_bottom_back};

l_inlet_back = newl;
Line(l_inlet_back) = {p_inlet_bottom_back,p_inlet_upper_back};

l_inlet_upper = newl;
Line(l_inlet_upper) = {p_inlet_upper_back,p_inlet_upper_front};

l_inlet_front = newl;
Line(l_inlet_front) = {p_inlet_upper_front,p_inlet_bottom_front};

lineloop = newl;
s_inlet = news;
Line Loop(lineloop) = {l_inlet_bottom,l_inlet_back,l_inlet_upper,l_inlet_front};
Plane Surface(s_inlet) = {lineloop};

l_outlet_bottom = newl;
Line(l_outlet_bottom) = {p_outlet_bottom_front,p_outlet_bottom_back};

l_outlet_back = newl;
Line(l_outlet_back) = {p_outlet_bottom_back,p_outlet_upper_back};

l_outlet_upper = newl;
Line(l_outlet_upper) = {p_outlet_upper_back,p_outlet_upper_front};

l_outlet_front = newl;
Line(l_outlet_front) = {p_outlet_upper_front,p_outlet_bottom_front};

lineloop = newl;
s_outlet = news;
Line Loop(lineloop) = {l_outlet_bottom,l_outlet_back,l_outlet_upper,l_outlet_front};
Plane Surface(s_outlet) = {lineloop};

l_bottom_back = newl;
Line(l_bottom_back) = {p_inlet_bottom_back,p_outlet_bottom_back};

l_bottom_front = newl;
Line(l_bottom_front) = {p_inlet_bottom_front,p_outlet_bottom_front};

l_upper_back = newl;
Line(l_upper_back) = {p_inlet_upper_back,p_outlet_upper_back};

l_upper_front = newl;
Line(l_upper_front) = {p_inlet_upper_front,p_outlet_upper_front};

lineloop = newll;
s_box_bottom = news;
Line Loop(lineloop) = {l_inlet_bottom,l_bottom_back,-l_outlet_bottom,-l_bottom_front};
lineloop2 = newll;
Line Loop(lineloop2) = {l_nose,l_MR_bottom_back,-l_MR_bottom_front};
Plane Surface(s_box_bottom) = {lineloop,lineloop2};

s_box_back = news;
lineloop3 = newll ;
Line Loop(lineloop3) = {l_upper_back,-l_outlet_back,-l_bottom_back,l_inlet_back};
Plane Surface(s_box_back) = {lineloop3};

s_box_front = news;
lineloop4 = newll ;
Line Loop(lineloop4) = {-l_upper_front,-l_outlet_front,l_bottom_front,l_inlet_front};
Plane Surface(s_box_front) = {lineloop4};

s_top = news;
lineloop5 = newll;
Line Loop(lineloop5) = {-l_upper_back,-l_outlet_upper,l_upper_front,l_inlet_upper};
Plane Surface(s_top) = {lineloop5};

sloop = newsl;
Surface Loop(sloop) = {-s_top,-s_box_front,-s_box_back,-s_box_bottom,-s_outlet,-s_inlet,s_front,s_back,s_upper};

vol = newv;
Volume(vol) = {sloop};

Transfinite Line {l_outlet_bottom,l_outlet_back,l_outlet_upper,l_outlet_front,l_inlet_bottom,l_inlet_back,l_inlet_upper,l_inlet_front} = 32;
Transfinite Surface {s_outlet} = {p_outlet_upper_front,p_outlet_bottom_front,p_outlet_upper_back,p_outlet_bottom_back} Alternate;
Transfinite Surface {s_inlet} = {p_inlet_upper_front,p_inlet_bottom_front,p_inlet_upper_back,p_inlet_bottom_back} Alternate;

Transfinite Line {l_upper_front,l_upper_back,l_bottom_front,l_bottom_back} = 256;
Transfinite Surface {s_box_front} = {p_inlet_upper_front,p_inlet_bottom_front,p_outlet_upper_front,p_outlet_bottom_front} Alternate;
Transfinite Surface {s_box_back} = {p_inlet_upper_back,p_inlet_bottom_back,p_outlet_upper_back,p_outlet_bottom_back} Alternate;
Transfinite Surface {s_top} = {p_inlet_upper_back,p_inlet_upper_front,p_outlet_upper_back,p_outlet_upper_front} Alternate;

Periodic Surface s_outlet {l_outlet_bottom,l_outlet_back,l_outlet_upper,l_outlet_front} = s_inlet {l_inlet_bottom,l_inlet_back,l_inlet_upper,l_inlet_front};
Periodic Surface s_box_front {l_upper_front,l_bottom_front,l_inlet_front,l_outlet_front} = s_box_back {l_upper_back,l_bottom_back,l_inlet_back,l_outlet_back};

Coherence Mesh;

Physical Surface("microramp") = {s_front,s_back,s_upper};
Physical Surface("inlet") = {s_inlet};
Physical Surface("outlet") = {s_outlet};
Physical Surface("top") = {s_top};
Physical Surface("bottom") = {s_box_bottom};
Physical Surface("back") = {s_box_back};
Physical Surface("front") = {s_box_front};

Physical Volume("volume") = {vol};

Mesh.Optimize=1;
Mesh.OptimizeNetgen=1;
