// this file creates a model and mesh of the NACA 0012 airfoil

surface_elem_size = 0.005;
farfield_elem_size = 1.5;
chord = 1.0; 

le_distance = 10*chord;
te_distance = 10*chord;
upper_distance = 10*chord;

n_pts = 205;

x[    0	] =	1	;
x[    1	] = 	0.99	;
x[    2	] = 	0.98	;
x[    3	] = 	0.97	;
x[    4	] = 	0.96	;
x[    5	] = 	0.95	;
x[    6	] = 	0.94	;
x[    7	] = 	0.93	;
x[    8	] = 	0.92	;
x[    9	] = 	0.91	;
x[    10  ] = 	0.9	;
x[    11  ] = 	0.89	;
x[    12  ] = 	0.88	;
x[    13  ] = 	0.87	;
x[    14  ] = 	0.86	;
x[    15  ] = 	0.85	;
x[    16  ] = 	0.84	;
x[    17  ] = 	0.83	;
x[    18  ] = 	0.82	;
x[    19  ] = 	0.81	;
x[    20  ] = 	0.8	;
x[    21  ] = 	0.79	;
x[    22  ] = 	0.78	;
x[    23  ] = 	0.77	;
x[    24  ] = 	0.76	;
x[    25  ] = 	0.75	;
x[    26  ] = 	0.74	;
x[    27  ] = 	0.73	;
x[    28  ] = 	0.72	;
x[    29  ] = 	0.71	;
x[    30  ] = 	0.7	;
x[    31  ] = 	0.69	;
x[    32  ] = 	0.68	;
x[    33  ] = 	0.67	;
x[    34  ] = 	0.66	;
x[    35  ] = 	0.65	;
x[    36  ] = 	0.64	;
x[    37  ] = 	0.63	;
x[    38  ] = 	0.62	;
x[    39  ] = 	0.61	;
x[    40  ] = 	0.6	;
x[    41  ] = 	0.59	;
x[    42  ] = 	0.58	;
x[    43  ] = 	0.57	;
x[    44  ] = 	0.56	;
x[    45  ] = 	0.55	;
x[    46  ] = 	0.54	;
x[    47  ] = 	0.53	;
x[    48  ] = 	0.52	;
x[    49  ] = 	0.51	;
x[    50  ] = 	0.5	;
x[    51  ] = 	0.49	;
x[    52  ] = 	0.48	;
x[    53  ] = 	0.47	;
x[    54  ] = 	0.46	;
x[    55  ] = 	0.45	;
x[    56  ] = 	0.44	;
x[    57  ] = 	0.43	;
x[    58  ] = 	0.42	;
x[    59  ] = 	0.41	;
x[    60  ] = 	0.4	;
x[    61  ] = 	0.39	;
x[    62  ] = 	0.38	;
x[    63  ] = 	0.37	;
x[    64  ] = 	0.36	;
x[    65  ] = 	0.35	;
x[    66  ] = 	0.34	;
x[    67  ] = 	0.33	;
x[    68  ] = 	0.32	;
x[    69  ] = 	0.31	;
x[    70  ] = 	0.3	;
x[    71  ] = 	0.29	;
x[    72  ] = 	0.28	;
x[    73  ] = 	0.27	;
x[    74  ] = 	0.26	;
x[    75  ] = 	0.25	;
x[    76  ] = 	0.24	;
x[    77  ] = 	0.23	;
x[    78  ] = 	0.22	;
x[    79  ] = 	0.21	;
x[    80  ] = 	0.2	;
x[    81  ] = 	0.19	;
x[    82  ] = 	0.18	;
x[    83  ] = 	0.17	;
x[    84  ] = 	0.16	;
x[    85  ] = 	0.15	;
x[    86  ] = 	0.14	;
x[    87  ] = 	0.13	;
x[    88  ] = 	0.12	;
x[    89  ] = 	0.11	;
x[    90  ] = 	0.1	;
x[    91  ] = 	0.09	;
x[    92  ] = 	0.08	;
x[    93  ] = 	0.07	;
x[    94  ] = 	0.06	;
x[    95  ] = 	0.05	;
x[    96  ] = 	0.04	;
x[    97  ] = 	0.03	;
x[    98  ] = 	0.02	;
x[    99  ] = 	0.01	;
x[    100 ] = 	0.005	;
x[    101 ] = 	0.002	;
x[    102 ] = 	0	;

x[    103 ] = 	0.002	;
x[    104 ] = 	0.005	;
x[    105 ] = 	0.01	;
x[    106 ] = 	0.02	;
x[    107 ] = 	0.03	;
x[    108 ] = 	0.04	;
x[    109 ] = 	0.05	;
x[    110 ] = 	0.06	;
x[    111 ] = 	0.07	;
x[    112 ] = 	0.08	;
x[    113 ] = 	0.09	;
x[    114 ] = 	0.1	;
x[    115 ] = 	0.11	;
x[    116 ] = 	0.12	;
x[    117 ] = 	0.13	;
x[    118 ] = 	0.14	;
x[    119 ] = 	0.15	;
x[    120 ] = 	0.16	;
x[    121 ] = 	0.17	;
x[    122 ] = 	0.18	;
x[    123 ] = 	0.19	;
x[    124 ] = 	0.2	;
x[    125 ] = 	0.21	;
x[    126 ] = 	0.22	;
x[    127 ] = 	0.23	;
x[    128 ] = 	0.24	;
x[    129 ] = 	0.25	;
x[    130 ] = 	0.26	;
x[    131 ] = 	0.27	;
x[    132 ] = 	0.28	;
x[    133 ] = 	0.29	;
x[    134 ] = 	0.3	;
x[    135 ] = 	0.31	;
x[    136 ] = 	0.32	;
x[    137 ] = 	0.33	;
x[    138 ] = 	0.34	;
x[    139 ] = 	0.35	;
x[    140 ] = 	0.36	;
x[    141 ] = 	0.37	;
x[    142 ] = 	0.38	;
x[    143 ] = 	0.39	;
x[    144 ] = 	0.4	;
x[    145 ] = 	0.41	;
x[    146 ] = 	0.42	;
x[    147 ] = 	0.43	;
x[    148 ] = 	0.44	;
x[    149 ] = 	0.45	;
x[    150 ] = 	0.46	;
x[    151 ] = 	0.47	;
x[    152 ] = 	0.48	;
x[    153 ] = 	0.49	;
x[    154 ] = 	0.5	;
x[    155 ] = 	0.51	;
x[    156 ] = 	0.52	;
x[    157 ] = 	0.53	;
x[    158 ] = 	0.54	;
x[    159 ] = 	0.55	;
x[    160 ] = 	0.56	;
x[    161 ] = 	0.57	;
x[    162 ] = 	0.58	;
x[    163 ] = 	0.59	;
x[    164 ] = 	0.6	;
x[    165 ] = 	0.61	;
x[    166 ] = 	0.62	;
x[    167 ] = 	0.63	;
x[    168 ] = 	0.64	;
x[    169 ] = 	0.65	;
x[    170 ] = 	0.66	;
x[    171 ] = 	0.67	;
x[    172 ] = 	0.68	;
x[    173 ] = 	0.69	;
x[    174 ] = 	0.7	;
x[    175 ] = 	0.71	;
x[    176 ] = 	0.72	;
x[    177 ] = 	0.73	;
x[    178 ] = 	0.74	;
x[    179 ] = 	0.75	;
x[    180 ] = 	0.76	;
x[    181 ] = 	0.77	;
x[    182 ] = 	0.78	;
x[    183 ] = 	0.79	;
x[    184 ] = 	0.8	;
x[    185 ] = 	0.81	;
x[    186 ] = 	0.82	;
x[    187 ] = 	0.83	;
x[    188 ] = 	0.84	;
x[    189 ] = 	0.85	;
x[    190 ] = 	0.86	;
x[    191 ] = 	0.87	;
x[    192 ] = 	0.88	;
x[    193 ] = 	0.89	;
x[    194 ] = 	0.9	;
x[    195 ] = 	0.91	;
x[    196 ] = 	0.92	;
x[    197 ] = 	0.93	;
x[    198 ] = 	0.94	;
x[    199 ] = 	0.95	;
x[    200 ] = 	0.96	;
x[    201 ] = 	0.97	;
x[    202 ] = 	0.98	;
x[    203 ] = 	0.99	;
x[    204 ] = 	1	;

y[    0	  ] = 	0.0033	;
y[    1	  ] = 	0.0055	;
y[    2	  ] = 	0.0076	;
y[    3	  ] = 	0.0097	;
y[    4	  ] = 	0.0117	;
y[    5	  ] = 	0.0137	;
y[    6	  ] = 	0.0156	;
y[    7	  ] = 	0.0175	;
y[    8	  ] = 	0.0193	;
y[    9	  ] = 	0.0211	;
y[    10  ] = 	0.0229	;
y[    11  ] = 	0.0247	;
y[    12  ] = 	0.0264	;
y[    13  ] = 	0.0281	;
y[    14  ] = 	0.0298	;
y[    15  ] = 	0.0314	;
y[    16  ] = 	0.033	;
y[    17  ] = 	0.0346	;
y[    18  ] = 	0.0362	;
y[    19  ] = 	0.0377	;
y[    20  ] = 	0.0392	;
y[    21  ] = 	0.0407	;
y[    22  ] = 	0.0422	;
y[    23  ] = 	0.0436	;
y[    24  ] = 	0.045	;
y[    25  ] = 	0.0464	;
y[    26  ] = 	0.0477	;
y[    27  ] = 	0.049	;
y[    28  ] = 	0.0503	;
y[    29  ] = 	0.0516	;
y[    30  ] = 	0.0528	;
y[    31  ] = 	0.054	;
y[    32  ] = 	0.0551	;
y[    33  ] = 	0.0562	;
y[    34  ] = 	0.0573	;
y[    35  ] = 	0.0583	;
y[    36  ] = 	0.0593	;
y[    37  ] = 	0.0602	;
y[    38  ] = 	0.0611	;
y[    39  ] = 	0.062	;
y[    40  ] = 	0.0628	;
y[    41  ] = 	0.0636	;
y[    42  ] = 	0.0643	;
y[    43  ] = 	0.065	;
y[    44  ] = 	0.0656	;
y[    45  ] = 	0.0662	;
y[    46  ] = 	0.0667	;
y[    47  ] = 	0.0672	;
y[    48  ] = 	0.0676	;
y[    49  ] = 	0.068	;
y[    50  ] = 	0.0684	;
y[    51  ] = 	0.0687	;
y[    52  ] = 	0.069	;
y[    53  ] = 	0.0693	;
y[    54  ] = 	0.0695	;
y[    55  ] = 	0.0697	;
y[    56  ] = 	0.0699	;
y[    57  ] = 	0.07	;
y[    58  ] = 	0.0701	;
y[    59  ] = 	0.0702	;
y[    60  ] = 	0.0702	;
y[    61  ] = 	0.0702	;
y[    62  ] = 	0.0702	;
y[    63  ] = 	0.0701	;
y[    64  ] = 	0.07	;
y[    65  ] = 	0.0699	;
y[    66  ] = 	0.0697	;
y[    67  ] = 	0.0695	;
y[    68  ] = 	0.0693	;
y[    69  ] = 	0.0691	;
y[    70  ] = 	0.0688	;
y[    71  ] = 	0.0685	;
y[    72  ] = 	0.0681	;
y[    73  ] = 	0.0677	;
y[    74  ] = 	0.0673	;
y[    75  ] = 	0.0668	;
y[    76  ] = 	0.0663	;
y[    77  ] = 	0.0657	;
y[    78  ] = 	0.0651	;
y[    79  ] = 	0.0644	;
y[    80  ] = 	0.0637	;
y[    81  ] = 	0.0629	;
y[    82  ] = 	0.0621	;
y[    83  ] = 	0.0612	;
y[    84  ] = 	0.0602	;
y[    85  ] = 	0.0592	;
y[    86  ] = 	0.0581	;
y[    87  ] = 	0.0569	;
y[    88  ] = 	0.0556	;
y[    89  ] = 	0.0542	;
y[    90  ] = 	0.0527	;
y[    91  ] = 	0.051	;
y[    92  ] = 	0.0491	;
y[    93  ] = 	0.0471	;
y[    94  ] = 	0.0448	;
y[    95  ] = 	0.0421	;
y[    96  ] = 	0.0389	;
y[    97  ] = 	0.035	;
y[    98  ] = 	0.0299	;
y[    99  ] = 	0.0225	;
y[    100 ] = 	0.0166	;
y[    101 ] = 	0.0108	;
y[    102 ] = 	0	;

y[    103 ] = 	-0.0108	;
y[    104 ] = 	-0.0166	;
y[    105 ] = 	-0.0225	;
y[    106 ] = 	-0.0299	;
y[    107 ] = 	-0.035	;
y[    108 ] = 	-0.0389	;
y[    109 ] = 	-0.0421	;
y[    110 ] = 	-0.0448	;
y[    111 ] = 	-0.0472	;
y[    112 ] = 	-0.0493	;
y[    113 ] = 	-0.0512	;
y[    114 ] = 	-0.0529	;
y[    115 ] = 	-0.0545	;
y[    116 ] = 	-0.056	;
y[    117 ] = 	-0.0573	;
y[    118 ] = 	-0.0585	;
y[    119 ] = 	-0.0597	;
y[    120 ] = 	-0.0608	;
y[    121 ] = 	-0.0618	;
y[    122 ] = 	-0.0627	;
y[    123 ] = 	-0.0636	;
y[    124 ] = 	-0.0644	;
y[    125 ] = 	-0.0651	;
y[    126 ] = 	-0.0658	;
y[    127 ] = 	-0.0664	;
y[    128 ] = 	-0.067	;
y[    129 ] = 	-0.0675	;
y[    130 ] = 	-0.068	;
y[    131 ] = 	-0.0684	;
y[    132 ] = 	-0.0688	;
y[    133 ] = 	-0.0691	;
y[    134 ] = 	-0.0694	;
y[    135 ] = 	-0.0696	;
y[    136 ] = 	-0.0698	;
y[    137 ] = 	-0.0699	;
y[    138 ] = 	-0.07	;
y[    139 ] = 	-0.07	;
y[    140 ] = 	-0.07	;
y[    141 ] = 	-0.0699	;
y[    142 ] = 	-0.0698	;
y[    143 ] = 	-0.0697	;
y[    144 ] = 	-0.0695	;
y[    145 ] = 	-0.0693	;
y[    146 ] = 	-0.069	;
y[    147 ] = 	-0.0686	;
y[    148 ] = 	-0.0682	;
y[    149 ] = 	-0.0677	;
y[    150 ] = 	-0.0672	;
y[    151 ] = 	-0.0666	;
y[    152 ] = 	-0.0659	;
y[    153 ] = 	-0.0651	;
y[    154 ] = 	-0.0642	;
y[    155 ] = 	-0.0633	;
y[    156 ] = 	-0.0623	;
y[    157 ] = 	-0.0612	;
y[    158 ] = 	-0.06	;
y[    159 ] = 	-0.0587	;
y[    160 ] = 	-0.0573	;
y[    161 ] = 	-0.0558	;
y[    162 ] = 	-0.0543	;
y[    163 ] = 	-0.0527	;
y[    164 ] = 	-0.051	;
y[    165 ] = 	-0.0492	;
y[    166 ] = 	-0.0474	;
y[    167 ] = 	-0.0455	;
y[    168 ] = 	-0.0435	;
y[    169 ] = 	-0.0415	;
y[    170 ] = 	-0.0394	;
y[    171 ] = 	-0.0373	;
y[    172 ] = 	-0.0352	;
y[    173 ] = 	-0.033	;
y[    174 ] = 	-0.0308	;
y[    175 ] = 	-0.0286	;
y[    176 ] = 	-0.0264	;
y[    177 ] = 	-0.0242	;
y[    178 ] = 	-0.022	;
y[    179 ] = 	-0.0198	;
y[    180 ] = 	-0.0177	;
y[    181 ] = 	-0.0156	;
y[    182 ] = 	-0.0136	;
y[    183 ] = 	-0.0116	;
y[    184 ] = 	-0.0097	;
y[    185 ] = 	-0.0078	;
y[    186 ] = 	-0.006	;
y[    187 ] = 	-0.0043	;
y[    188 ] = 	-0.0027	;
y[    189 ] = 	-0.0012	;
y[    190 ] = 	0.0001	;
y[    191 ] = 	0.0013	;
y[    192 ] = 	0.0023	;
y[    193 ] = 	0.0032	;
y[    194 ] = 	0.0039	;
y[    195 ] = 	0.0044	;
y[    196 ] = 	0.0046	;
y[    197 ] = 	0.0046	;
y[    198 ] = 	0.0043	;
y[    199 ] = 	0.0038	;
y[    200 ] = 	0.0031	;
y[    201 ] = 	0.0021	;
y[    202 ] = 	0.0008	;
y[    203 ] = 	-0.0008	;
y[    204 ] = 	-0.0027	;


surface_points[] = {};

// use the coords to create the airfoil
For ival In {0:n_pts-1}
   Point(ival) = {x[ival]*chord, y[ival]*chord, 0.0 , surface_elem_size};   
   surface_points[ival] = ival;
EndFor


// now create the splines for the upper and lower sufaces
//Line (0) = {0, 1};
Line (1)  = {n_pts-1, 0};
BSpline (2) = {surface_points[]};


// Coherence;

// // // now create the airfoil loop 
// Line Loop (110) = {0, 1};

// // now define the outer boundary of the meshing region
// Point (2001) = {-le_distance,  upper_distance, 0, farfield_elem_size};
// Point (2002) = {chord+te_distance,  upper_distance, 0, farfield_elem_size};
// Point (2003) = {chord+te_distance, -upper_distance, 0, farfield_elem_size};
// Point (2004) = {-le_distance, -upper_distance, 0, farfield_elem_size};

// // // lines for the outer boundary
// Line (4) = {2001, 2002};
// Line (5) = {2002, 2003};
// Line (6) = {2003, 2004};
// Line (7) = {2004, 2001};

// // line loop for the outer boundary

// Line Loop (111) = {-7, -6, -5, -4};


Point (3000) = {0., 0., 0., farfield_elem_size};
Point (3001) = {10*chord*Cos(20.*3.14/180.), 10*chord*Sin(20.*3.14/180.), 0.};
Point (3002) = {-10*chord, 0., 0., farfield_elem_size};
Point (3003) = {10*chord*Cos(20.*3.14/180.), -10*chord*Sin(20.*3.14/180.), 0.};


Circle (10) = {3001, 3000, 3002};
Circle (11) = {3002, 3000, 3003};
Circle (12) = {3003, 3000, 3001};

Line (20)  = {0, 3001};
Line (21)  = {3003, n_pts-1};

Compound Line (30) = {10, 11};

Line Loop (100) = {2, -21, -11, -10, -20};

// surface defining the analysis boundary
Plane Surface (1) = {100};


//Physical Line (0) = {-2, -1, -0};
//Physical Line (1) = {-7, -6, -5, -4};
//Physical Surface (3) = {1};

//Mesh.CharacteristicLengthFromCurvature = 1;


Transfinite Surface {1};


