original_docstring: 
      Based on the paper "Fundamental" Parametric Geometry Representations for
      Aircraft Component Shapes" from Brenda M. Kulfan and John E. Bussoletti. 
      The code uses a 1st order Bernstein Polynomial for the "Class Function" / 
      "Shape Function" airfoil representation.
      
      The degree of polynomial is dependant on how many values there are for the
      coefficients. The algorithm is able to use Bernstein Polynomials for any
      order automatically. The algorithm is also able to analyze only the top or
      lower surface if desired. It will recognize by the inputs given. i.e.:
      for CST(x=.2,c=1.,deltasx=.2,Au=.7), there is only one value for Au, so it
      is a Bernstein polynomial of 1st order for the upper surface. By ommiting 
      Al the code will only input and return the upper surface.
      
      Although the code is flexible, the inputs need to be coesive. len(deltasz)
      must be equal to the number of surfaces. Au and Al need to have the same 
      length if a full analysis is being realized.    
      
      The inputs are:
  
          - x:list or numpy. array of points along the chord, from TE and the LE,
            or vice-versa. The code works both ways.
            
          - c: chord
      
          - deltasz: list of thicknesses on the TE. In case the upper and lower
            surface are being analyzed, the first element in the list is related 
            to the upper surface and the second to the lower surface. There are 
            two because the CST method treats the airfoil surfaces as two 
            different surfaces (upper and lower)
          
          - Au: list/float of Au coefficients, which are design parameters. If 
            None,the surface is not analyzed. len(Au) equals  
          
          - Al: list/float of Al coefficients, which are design parameters. If 
            None,the surface is not analyzed. len(Al) equals  
           
      The outputs are:
          - y:
            - for a full analysis: disctionary with keys 'u' and 'l' each with 
              a list of the y positions for a surface.
            - for a half analysis: a list with the list of the y postions of the
              the desired surface
          
      Created on Sun Jan 19 16:36:55 2014
      
      Updated on Mon May 19 18:13:26 2014
  
      @author: Pedro Leal
      
docstring: Based on the paper "Fundamental" Parametric Geometry Representations for
  Aircraft Component Shapes" from Brenda M. Kulfan and John E. Bussoletti.
  The code uses a 1st order Bernstein Polynomial for the "Class Function"
  "Shape Function" airfoil representation.
  
  The degree of polynomial is dependant on how many values there are for the
  coefficients. The algorithm is able to use Bernstein Polynomials for any
  order automatically. The algorithm is also able to analyze only the top or
  lower surface if desired. It will recognize by the inputs given. i.e.:
  for CST(x=.2,c=1.,deltasx=.2,Au=.7), there is only one value for Au, so it
  is a Bernstein polynomial of 1st order for the upper surface. By ommiting
  Al the code will only input and return the upper surface.
  
  Although the code is flexible, the inputs need to be coesive. len(deltasz)
  must be equal to the number of surfaces. Au and Al need to have the same
  length if a full analysis is being realized.
  
  The inputs are.
  
  list or numpy. array of points along the chord, from TE and the LE,
  or vice-versa. The code works both ways.
  
  chord
  
  list of thicknesses on the TE. In case the upper and lower
  surface are being analyzed, the first element in the list is related
  to the upper surface and the second to the lower surface. There are
  two because the CST method treats the airfoil surfaces as two
  different surfaces (upper and lower)
  
  list/float of Au coefficients, which are design parameters. If
  None,the surface is not analyzed.
  
  list/float of Al coefficients, which are design parameters. If
  None,the surface is not analyzed.
  
  The outputs are:
  y:
  for a full analysis: disctionary with keys 'u' and 'l' each with
  a list of the y positions for a surface.
  for a half analysis: a list with the list of the y postions of the
  the desired surface
  
  
  
  
docstring_tokens: Based on the paper " Fundamental " Parametric Geometry Representations for Aircraft Component Shapes " from Brenda M . Kulfan and John E . Bussoletti . The code uses a 1st order Bernstein Polynomial for the " Class Function " " Shape Function " airfoil representation . The degree of polynomial is dependant on how many values there are for the coefficients . The algorithm is able to use Bernstein Polynomials for any order automatically . The algorithm is also able to analyze only the top or lower surface if desired . It will recognize by the inputs given . i . e . : for CST ( x = . 2 c = 1 . deltasx = . 2 Au = . 7 ) there is only one value for Au so it is a Bernstein polynomial of 1st order for the upper surface . By ommiting Al the code will only input and return the upper surface . Although the code is flexible the inputs need to be coesive . len ( deltasz ) must be equal to the number of surfaces . Au and Al need to have the same length if a full analysis is being realized . The inputs are . list or numpy . array of points along the chord from TE and the LE or vice - versa . The code works both ways . chord list of thicknesses on the TE . In case the upper and lower surface are being analyzed the first element in the list is related to the upper surface and the second to the lower surface . There are two because the CST method treats the airfoil surfaces as two different surfaces ( upper and lower ) list / float of Au coefficients which are design parameters . If None the surface is not analyzed . list / float of Al coefficients which are design parameters . If None the surface is not analyzed . The outputs are : y : for a full analysis : disctionary with keys ' u ' and ' l ' each with a list of the y positions for a surface . for a half analysis : a list with the list of the y postions of the the desired surface
code: def CST(x, c, deltasz=None, Au=None, Al=None):
      """
      Based on the paper "Fundamental" Parametric Geometry Representations for
      Aircraft Component Shapes" from Brenda M. Kulfan and John E. Bussoletti. 
      The code uses a 1st order Bernstein Polynomial for the "Class Function" / 
      "Shape Function" airfoil representation.
      
      The degree of polynomial is dependant on how many values there are for the
      coefficients. The algorithm is able to use Bernstein Polynomials for any
      order automatically. The algorithm is also able to analyze only the top or
      lower surface if desired. It will recognize by the inputs given. i.e.:
      for CST(x=.2,c=1.,deltasx=.2,Au=.7), there is only one value for Au, so it
      is a Bernstein polynomial of 1st order for the upper surface. By ommiting 
      Al the code will only input and return the upper surface.
      
      Although the code is flexible, the inputs need to be coesive. len(deltasz)
      must be equal to the number of surfaces. Au and Al need to have the same 
      length if a full analysis is being realized.    
      
      The inputs are:
  
          - x:list or numpy. array of points along the chord, from TE and the LE,
            or vice-versa. The code works both ways.
            
          - c: chord
      
          - deltasz: list of thicknesses on the TE. In case the upper and lower
            surface are being analyzed, the first element in the list is related 
            to the upper surface and the second to the lower surface. There are 
            two because the CST method treats the airfoil surfaces as two 
            different surfaces (upper and lower)
          
          - Au: list/float of Au coefficients, which are design parameters. If 
            None,the surface is not analyzed. len(Au) equals  
          
          - Al: list/float of Al coefficients, which are design parameters. If 
            None,the surface is not analyzed. len(Al) equals  
           
      The outputs are:
          - y:
            - for a full analysis: disctionary with keys 'u' and 'l' each with 
              a list of the y positions for a surface.
            - for a half analysis: a list with the list of the y postions of the
              the desired surface
          
      Created on Sun Jan 19 16:36:55 2014
      
      Updated on Mon May 19 18:13:26 2014
  
      @author: Pedro Leal
      """
      
      # Bersntein Polynomial
      def K(r,n):
          K=math.factorial(n)/(math.factorial(r)*math.factorial(n-r))
          return K
      
      # Shape Function   
      def S(r,n,psi):
          S=K(r,n)*(psi**r)*(1.-psi)**(n-r)
          return S
      
      # Class Function    
      def C(N1,N2,psi):
          C=((psi)**N1)*((1.-psi)**N2)
          return C
      
      if type(x)==list:
          x=np.array(x)
      # Adimensionalizing
      psi=x/c;    
      
      #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      #                           Class Function
      #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~    
      # The Coefficients for an airfoil with a rounded leading edge and a sharp
      # trailing edge are N1=0.5 and N2=1.0.
      N1=0.5;
      N2=1.0;
      C=C(N1,N2,psi);
      
      #==========================================================================
      #                   Defining the working surfaces
      #==========================================================================
      deltaz={}
      eta={}
      y={}
      Shape={}
      
      if Al and Au:
          deltaz['u']=deltasz[0]
          deltaz['l']=deltasz[1]
          
          if len(Au)!=len(Al):
              raise Exception("Au and Al need to have the same dimensions")
          elif len(deltasz)!=2:
              raise Exception("If both surfaces are being analyzed, two values for deltasz are needed")
          
      elif Au and not Al:
          if type(deltasz)==list:
              if len(deltaz['u'])!=1:
                  raise Exception("If only one surface is being analyzed, one value for deltasz is needed")
              else:
                  deltaz['u']=float(deltasz)
          else:
              deltaz['u']=deltasz
         
      elif Al and not Au:
          if type(deltasz)==list:
              if (deltaz['l'])!=1:
                  raise Exception("If only one surface is being analyzed, one value for deltasz is needed")
              else:
                  deltaz['l']=float(deltasz)
          else:
              deltaz['l']=deltasz
      else:
          raise Exception("Au or Al need to have at least one value")
      A={'u':Au,'l':Al}
      for surface in ['u','l']:
          if A[surface]:
              
              if type(A[surface])==int or type(A[surface])==float:
                  A[surface]=[A[surface]]
              # the degree of the Bernstein polynomial is given by the number of
              # coefficients
              n=len(A[surface])-1
      #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      #                           Shape Function
      #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~  
              Shape[surface]=0    
              for i in range(len(A[surface])):
  #                print A
  #                print S(i,n,psi)
                  if surface=='l':
                      Shape[surface]-=A[surface][i]*S(i,n,psi)
                  else:
                      Shape[surface]+=A[surface][i]*S(i,n,psi)
      
      #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      #                           Airfoil Shape (eta=z/c)
      #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~        
              # Airfoil Shape (eta=z/c)
              if surface=='l':
                  eta[surface]= C*Shape[surface]-psi*deltaz[surface]/c;
              else:
                  eta[surface]= C*Shape[surface]+psi*deltaz[surface]/c;  
              # Giving back the dimensions
              y[surface]=c*eta[surface]
      if Al and Au:     
          return y
      elif Au:
          return y['u']
      else:
          return y['l']
code_tokens: def CST ( x , c , deltasz = None , Au = None , Al = None ) : def K ( r , n ) : K = math . factorial ( n ) / ( math . factorial ( r ) * math . factorial ( n - r ) ) return K def S ( r , n , psi ) : S = K ( r , n ) * ( psi ** r ) * ( 1. - psi ) ** ( n - r ) return S def C ( N1 , N2 , psi ) : C = ( ( psi ) ** N1 ) * ( ( 1. - psi ) ** N2 ) return C if type ( x ) == list : x = np . array ( x ) psi = x / c ; N1 = 0.5 ; N2 = 1.0 ; C = C ( N1 , N2 , psi ) ; deltaz = { } eta = { } y = { } Shape = { } if Al and Au : deltaz [ 'u' ] = deltasz [ 0 ] deltaz [ 'l' ] = deltasz [ 1 ] if len ( Au ) != len ( Al ) : raise Exception ( "Au and Al need to have the same dimensions" ) elif len ( deltasz ) != 2 : raise Exception ( "If both surfaces are being analyzed, two values for deltasz are needed" ) elif Au and not Al : if type ( deltasz ) == list : if len ( deltaz [ 'u' ] ) != 1 : raise Exception ( "If only one surface is being analyzed, one value for deltasz is needed" ) else : deltaz [ 'u' ] = float ( deltasz ) else : deltaz [ 'u' ] = deltasz elif Al and not Au : if type ( deltasz ) == list : if ( deltaz [ 'l' ] ) != 1 : raise Exception ( "If only one surface is being analyzed, one value for deltasz is needed" ) else : deltaz [ 'l' ] = float ( deltasz ) else : deltaz [ 'l' ] = deltasz else : raise Exception ( "Au or Al need to have at least one value" ) A = { 'u' : Au , 'l' : Al } for surface in [ 'u' , 'l' ] : if A [ surface ] : if type ( A [ surface ] ) == int or type ( A [ surface ] ) == float : A [ surface ] = [ A [ surface ] ] n = len ( A [ surface ] ) - 1 Shape [ surface ] = 0 for i in range ( len ( A [ surface ] ) ) : if surface == 'l' : Shape [ surface ] -= A [ surface ] [ i ] * S ( i , n , psi ) else : Shape [ surface ] += A [ surface ] [ i ] * S ( i , n , psi ) if surface == 'l' : eta [ surface ] = C * Shape [ surface ] - psi * deltaz [ surface ] / c ; else : eta [ surface ] = C * Shape [ surface ] + psi * deltaz [ surface ] / c ; y [ surface ] = c * eta [ surface ] if Al and Au : return y elif Au : return y [ 'u' ] else : return y [ 'l' ]
short_docstring: Based on the paper "Fundamental" Parametric Geometry Representations for
  Aircraft Component Shapes" from Brenda M. Kulfan and John E. Bussoletti.
short_docstring_tokens: Based on the paper " Fundamental " Parametric Geometry Representations for Aircraft Component Shapes " from Brenda M . Kulfan and John E . Bussoletti .
comment: """
      Based on the paper "Fundamental" Parametric Geometry Representations for
      Aircraft Component Shapes" from Brenda M. Kulfan and John E. Bussoletti. 
      The code uses a 1st order Bernstein Polynomial for the "Class Function" / 
      "Shape Function" airfoil representation.
      
      The degree of polynomial is dependant on how many values there are for the
      coefficients. The algorithm is able to use Bernstein Polynomials for any
      order automatically. The algorithm is also able to analyze only the top or
      lower surface if desired. It will recognize by the inputs given. i.e.:
      for CST(x=.2,c=1.,deltasx=.2,Au=.7), there is only one value for Au, so it
      is a Bernstein polynomial of 1st order for the upper surface. By ommiting 
      Al the code will only input and return the upper surface.
      
      Although the code is flexible, the inputs need to be coesive. len(deltasz)
      must be equal to the number of surfaces. Au and Al need to have the same 
      length if a full analysis is being realized.    
      
      The inputs are:
  
          - x:list or numpy. array of points along the chord, from TE and the LE,
            or vice-versa. The code works both ways.
            
          - c: chord
      
          - deltasz: list of thicknesses on the TE. In case the upper and lower
            surface are being analyzed, the first element in the list is related 
            to the upper surface and the second to the lower surface. There are 
            two because the CST method treats the airfoil surfaces as two 
            different surfaces (upper and lower)
          
          - Au: list/float of Au coefficients, which are design parameters. If 
            None,the surface is not analyzed. len(Au) equals  
          
          - Al: list/float of Al coefficients, which are design parameters. If 
            None,the surface is not analyzed. len(Al) equals  
           
      The outputs are:
          - y:
            - for a full analysis: disctionary with keys 'u' and 'l' each with 
              a list of the y positions for a surface.
            - for a half analysis: a list with the list of the y postions of the
              the desired surface
          
      Created on Sun Jan 19 16:36:55 2014
      
      Updated on Mon May 19 18:13:26 2014
  
      @author: Pedro Leal
      """$SEP$# Bersntein Polynomial$SEP$# Shape Function   $SEP$# Class Function    $SEP$# Adimensionalizing$SEP$#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~$SEP$#                           Class Function$SEP$#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~    $SEP$# The Coefficients for an airfoil with a rounded leading edge and a sharp$SEP$# trailing edge are N1=0.5 and N2=1.0.$SEP$#==========================================================================$SEP$#                   Defining the working surfaces$SEP$#==========================================================================$SEP$# the degree of the Bernstein polynomial is given by the number of$SEP$# coefficients$SEP$#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~$SEP$#                           Shape Function$SEP$#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~  $SEP$#                print A$SEP$#                print S(i,n,psi)$SEP$#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~$SEP$#                           Airfoil Shape (eta=z/c)$SEP$#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~        $SEP$# Airfoil Shape (eta=z/c)$SEP$# Giving back the dimensions