original_docstring: Calculate  dependent shape coefficients for children configuration for a 4 order
      Bernstein polynomial and return the children upper, lower shape 
      coefficients, children chord and spar thicknesses. _P denotes parent parameters
docstring: Calculate  dependent shape coefficients for children configuration for a 4 order
  Bernstein polynomial and return the children upper, lower shape
  coefficients, children chord and spar thicknesses. _P denotes parent parameters
docstring_tokens: Calculate dependent shape coefficients for children configuration for a 4 order Bernstein polynomial and return the children upper lower shape coefficients children chord and spar thicknesses . _P denotes parent parameters
code: def calculate_dependent_shape_coefficients(Au_C_1_to_n,
                                             psi_spars, Au_P, Al_P, deltaz, c_P,
                                             morphing = 'backwards', l_LE=0, eps_LE=0):
      """Calculate  dependent shape coefficients for children configuration for a 4 order
      Bernstein polynomial and return the children upper, lower shape 
      coefficients, children chord and spar thicknesses. _P denotes parent parameters"""
      def calculate_AC_u0(AC_u0, constant_LE = True):
          Au_C = [AC_u0] + Au_C_1_to_n
          if constant_LE:
              return np.sqrt(c_P/c_C)*Au_P[0]
          else:
              return calculate_A0_moving_LE(psi_spars, psi_lower_children[0], Au_P, Au_C, deltaz,
                         c_P, l_LE, eps_LE)
      # Bersntein Polynomial
      def K(r,n):
          K=math.factorial(n)/(math.factorial(r)*math.factorial(n-r))
          return K
      # Bernstein Polynomial order
      # In case of leading edge radius constraint
      n = len(Au_C_1_to_n)
  
      # Find upper shape coefficient though iterative method since Au_0 is unknown
      # via fixed point iteration
      #AC_u0 = optimize.fixed_point(calculate_AC_u0, Au_P[0])
      #print AC_u0
      error = 9999
  
      psi_lower_children = psi_spars
      Au_C =  [Au_P[0]] + Au_C_1_to_n # [Au_P[0]] +
  
      former_chord = c_P
      while error > 1e-5:
          former_Au_C = []
          for i in range(len(Au_C)):
              former_Au_C.append(Au_C[i])
          
          # Because the output is an array, need the extra [0]      
          error_A0 = 999
          # Now that AC_u0 is known we can calculate the actual chord and AC_l0
          # c_C = calculate_c_baseline(c_P, Au_C, Au_P, deltaz/c_P, l_LE, eps_LE, psi_spars[0])
          Au_C[0] = calculate_AC_u0(Au_C[0], constant_LE = False)
          Al_C0 = Au_C[0]
          c_C = calculate_c_baseline(c_P, Au_C, Au_P, deltaz/c_P, l_LE, eps_LE, psi_spars[0])
          #Al_C0 = Au_C[0]
          # print '0 lower shape coefficient: ',AC_l0
          # Calculate thicknessed and tensor B for the constraint linear system problem
          spar_thicknesses = []
          
          if morphing == 'forwards':
              f = np.zeros((n,1))
              # psi/xi coordinates for lower surface of the children configuration
              psi_lower_children = []
              xi_lower_children = []
              xi_upper_children = []
  
              # psi_baseline, Au_baseline, Au_goal, deltaz, c_baseline, c_goal
              psi_upper_children = []
              for j in range(len(psi_spars)):
                  print(j)
                  psi_upper_children.append(calculate_psi_goal(psi_spars[j], Au_P, Au_C, deltaz,
                                         c_P, c_C,l_LE, eps_LE, psi_spars[0]))
                  
              # Calculate xi for upper children. Do not care about lower so just gave it random shape coefficients
              xi_upper_children = CST(psi_upper_children, 1., deltasz= [deltaz/2./c_C, deltaz/2./c_C],  Al= Au_C, Au =Au_C)
              xi_upper_children = xi_upper_children['u']
  
              # print xi_upper_children
              
              #Debugging section
              # x = np.linspace(0,1)
              # y = CST(x, 1., deltasz= [deltaz/2./c_C, deltaz/2./c_C],  Al= Au_C, Au =Au_C)
              # plt.plot(x,y['u'])
              # plt.scatter(psi_upper_children, xi_upper_children)
              # plt.grid()
              # plt.show()
              # BREAK
              print(Au_P, Au_C, len(psi_spars), n)
              for j in range(len(psi_spars)):
                  xi_parent = CST(psi_spars, 1., deltasz= [deltaz/2./c_P, deltaz/2./c_P],  Al= Al_P, Au =Au_P)
                  delta_j_P = xi_parent['u'][j]-xi_parent['l'][j]
                  t_j = c_P*(delta_j_P)
                  # Claculate orientation for children
                  s_j = calculate_spar_direction(psi_spars[j], Au_P, Au_C, deltaz, c_C, l_LE, eps_LE, psi_spars)
                  psi_l_j = psi_upper_children[j]-delta_j_P/c_C*s_j[0]
                  xi_l_j = xi_upper_children[j]-delta_j_P/c_C*s_j[1]
  
                  spar_thicknesses.append(t_j)
                  psi_lower_children.append(psi_l_j)
                  xi_lower_children.append(xi_l_j)
  
                  f[j] = (2*xi_l_j + psi_l_j*deltaz/c_C)/(2*(psi_l_j**0.5)*(psi_l_j-1)) - Al_C0*(1-psi_l_j)**n
  
              F = np.zeros((n,n))
              #j is the row dimension and i the column dimension in this case
              for j in range(n):
                  for i in range(n):
                      #Because in Python counting starts at 0, need to add 1 to be
                      #coherent for equations
                      r = i + 1
                      F[j][i] = K(r,n)*(psi_lower_children[j]**r)*(1-psi_lower_children[j])**(n-r)
              print(F)
              print(f)
              A_lower = np.dot(inv(F), f)
              print('result', A_lower)
              Al_C = [Al_C0]
              for i in range(len(A_lower)):
                  Al_C.append(A_lower[i][0]) #extra [0] is necessary because of array
          error_denominator = 0
          print('before', former_Au_C, Au_C)
          for i in range(len(Au_C)):
              error_denominator += Au_C[i]**2
          error = 0
          for i in range(len(Al_C)):
              error += (former_Au_C[i] - Au_C[i])**2/error_denominator
          error = math.sqrt(error)
          # error = abs(c_C-former_chord)/c_C
          # AC_u0 = calculate_AC_u0(AC_u0, constant_LE=False)
          print(error, Al_C, Au_C)
          # former_chord = c_C
      return Au_C, Al_C, c_C, spar_thicknesses
code_tokens: def calculate_dependent_shape_coefficients ( Au_C_1_to_n , psi_spars , Au_P , Al_P , deltaz , c_P , morphing = 'backwards' , l_LE = 0 , eps_LE = 0 ) : def calculate_AC_u0 ( AC_u0 , constant_LE = True ) : Au_C = [ AC_u0 ] + Au_C_1_to_n if constant_LE : return np . sqrt ( c_P / c_C ) * Au_P [ 0 ] else : return calculate_A0_moving_LE ( psi_spars , psi_lower_children [ 0 ] , Au_P , Au_C , deltaz , c_P , l_LE , eps_LE ) def K ( r , n ) : K = math . factorial ( n ) / ( math . factorial ( r ) * math . factorial ( n - r ) ) return K n = len ( Au_C_1_to_n ) error = 9999 psi_lower_children = psi_spars Au_C = [ Au_P [ 0 ] ] + Au_C_1_to_n former_chord = c_P while error > 1e-5 : former_Au_C = [ ] for i in range ( len ( Au_C ) ) : former_Au_C . append ( Au_C [ i ] ) error_A0 = 999 Au_C [ 0 ] = calculate_AC_u0 ( Au_C [ 0 ] , constant_LE = False ) Al_C0 = Au_C [ 0 ] c_C = calculate_c_baseline ( c_P , Au_C , Au_P , deltaz / c_P , l_LE , eps_LE , psi_spars [ 0 ] ) spar_thicknesses = [ ] if morphing == 'forwards' : f = np . zeros ( ( n , 1 ) ) psi_lower_children = [ ] xi_lower_children = [ ] xi_upper_children = [ ] psi_upper_children = [ ] for j in range ( len ( psi_spars ) ) : print ( j ) psi_upper_children . append ( calculate_psi_goal ( psi_spars [ j ] , Au_P , Au_C , deltaz , c_P , c_C , l_LE , eps_LE , psi_spars [ 0 ] ) ) xi_upper_children = CST ( psi_upper_children , 1. , deltasz = [ deltaz / 2. / c_C , deltaz / 2. / c_C ] , Al = Au_C , Au = Au_C ) xi_upper_children = xi_upper_children [ 'u' ] print ( Au_P , Au_C , len ( psi_spars ) , n ) for j in range ( len ( psi_spars ) ) : xi_parent = CST ( psi_spars , 1. , deltasz = [ deltaz / 2. / c_P , deltaz / 2. / c_P ] , Al = Al_P , Au = Au_P ) delta_j_P = xi_parent [ 'u' ] [ j ] - xi_parent [ 'l' ] [ j ] t_j = c_P * ( delta_j_P ) s_j = calculate_spar_direction ( psi_spars [ j ] , Au_P , Au_C , deltaz , c_C , l_LE , eps_LE , psi_spars ) psi_l_j = psi_upper_children [ j ] - delta_j_P / c_C * s_j [ 0 ] xi_l_j = xi_upper_children [ j ] - delta_j_P / c_C * s_j [ 1 ] spar_thicknesses . append ( t_j ) psi_lower_children . append ( psi_l_j ) xi_lower_children . append ( xi_l_j ) f [ j ] = ( 2 * xi_l_j + psi_l_j * deltaz / c_C ) / ( 2 * ( psi_l_j ** 0.5 ) * ( psi_l_j - 1 ) ) - Al_C0 * ( 1 - psi_l_j ) ** n F = np . zeros ( ( n , n ) ) for j in range ( n ) : for i in range ( n ) : r = i + 1 F [ j ] [ i ] = K ( r , n ) * ( psi_lower_children [ j ] ** r ) * ( 1 - psi_lower_children [ j ] ) ** ( n - r ) print ( F ) print ( f ) A_lower = np . dot ( inv ( F ) , f ) print ( 'result' , A_lower ) Al_C = [ Al_C0 ] for i in range ( len ( A_lower ) ) : Al_C . append ( A_lower [ i ] [ 0 ] ) error_denominator = 0 print ( 'before' , former_Au_C , Au_C ) for i in range ( len ( Au_C ) ) : error_denominator += Au_C [ i ] ** 2 error = 0 for i in range ( len ( Al_C ) ) : error += ( former_Au_C [ i ] - Au_C [ i ] ) ** 2 / error_denominator error = math . sqrt ( error ) print ( error , Al_C , Au_C ) return Au_C , Al_C , c_C , spar_thicknesses
short_docstring: Calculate  dependent shape coefficients for children configuration for a 4 order
  Bernstein polynomial and return the children upper, lower shape
  coefficients, children chord and spar thicknesses.
short_docstring_tokens: Calculate dependent shape coefficients for children configuration for a 4 order Bernstein polynomial and return the children upper lower shape coefficients children chord and spar thicknesses .
comment: """Calculate  dependent shape coefficients for children configuration for a 4 order
      Bernstein polynomial and return the children upper, lower shape 
      coefficients, children chord and spar thicknesses. _P denotes parent parameters"""$SEP$# Bersntein Polynomial
  $SEP$# Bernstein Polynomial order
  $SEP$# In case of leading edge radius constraint
  $SEP$# Find upper shape coefficient though iterative method since Au_0 is unknown
  $SEP$# via fixed point iteration
  $SEP$#AC_u0 = optimize.fixed_point(calculate_AC_u0, Au_P[0])
  $SEP$#print AC_u0
  $SEP$# [Au_P[0]] +
  $SEP$# Because the output is an array, need the extra [0]      
  $SEP$# Now that AC_u0 is known we can calculate the actual chord and AC_l0
  $SEP$# c_C = calculate_c_baseline(c_P, Au_C, Au_P, deltaz/c_P, l_LE, eps_LE, psi_spars[0])
  $SEP$#Al_C0 = Au_C[0]
  $SEP$# print '0 lower shape coefficient: ',AC_l0
  $SEP$# Calculate thicknessed and tensor B for the constraint linear system problem
  $SEP$# psi/xi coordinates for lower surface of the children configuration
  $SEP$# psi_baseline, Au_baseline, Au_goal, deltaz, c_baseline, c_goal
  $SEP$# Calculate xi for upper children. Do not care about lower so just gave it random shape coefficients
  $SEP$# print xi_upper_children
  $SEP$#Debugging section
  $SEP$# x = np.linspace(0,1)
  $SEP$# y = CST(x, 1., deltasz= [deltaz/2./c_C, deltaz/2./c_C],  Al= Au_C, Au =Au_C)
  $SEP$# plt.plot(x,y['u'])
  $SEP$# plt.scatter(psi_upper_children, xi_upper_children)
  $SEP$# plt.grid()
  $SEP$# plt.show()
  $SEP$# BREAK
  $SEP$# Claculate orientation for children
  $SEP$#j is the row dimension and i the column dimension in this case
  $SEP$#Because in Python counting starts at 0, need to add 1 to be
  $SEP$#coherent for equations
  $SEP$#extra [0] is necessary because of array
  $SEP$# error = abs(c_C-former_chord)/c_C
  $SEP$# AC_u0 = calculate_AC_u0(AC_u0, constant_LE=False)
  $SEP$# former_chord = c_C
  