'''
NASA Common Research Model (CRM) Wing

https://commonresearchmodel.larc.nasa.gov/
'''

import os
import sys
sys.path.append('.')

from cst_modeling.surface2 import Surface


if __name__ == "__main__":

    path = os.path.dirname(sys.argv[0])

    '''
    Smooth surface is generated by setting smooth_surface=True.
    
    When smooth_sections = None, all sections are smoothed by cubic spline interpolation.
    It is not recommended to use this option when the wing has a kink, i.e., the guide curve has a sharp turn in the kink.
    
    When smooth_sections is a list of tuples, each tuple contains the start and end index of the sections of the surface to be smoothed.
    The surface's both ends are set to be tangent to the adjacent section's control point in the guide curve.
    
    For example, smooth_sections=[(0, 1), (2, 4), (5, 8)] means the first surface between section 0&1 is smoothed, the left end is left free,
    and the right end is tangent to segment of control point 1&2. So, this sequential list of tuples defines a smooth surface.
    
    On the other hand, when smooth_sections=[(0, 2), (4, 8)], the first surface between section 0&2 is smoothed, the left end is left free, 
    and the right end is tangent to segment of control point 2&3. 
    The second surface between section 4&8 is smoothed, the left end is tangent to segment of control point 3&4, 
    and the right end is tangent to segment of control point 8&9. 
    The surface between section 2&4 has a piecewise linear distribution.
    '''

    wing = Surface(n_sec=9, name='Wing-CRM', nn=201, ns=21, 
                    smooth_surface=True, smooth_sections=[(0, 2), (4, 8)])

    wing.read_setting(os.path.join(path, 'Wing.txt'))

    wing.prepare()
    
    wing.geo()

    wing.output_tecplot(fname=os.path.join(path, 'Wing-CRM.dat'), one_piece=False, split=True)

    wing.output_guide_curve(os.path.join(path, 'Wing-CRM-guide-curve.dat'))

