Advertisement
Guest User

Untitled

a guest
Nov 28th, 2014
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.79 KB | None | 0 0
  1. def boundaryFunction(parameter):
  2. return 1 + 0.1 * np.cos(parameter)
  3.  
  4. def boundaryDerivative(parameter):
  5. return -0.1 * np.sin(parameter)
  6.  
  7. def trajectoryFunction(parameter):
  8. aux = np.sin(beta - phi) / np.sin(beta - parameter)
  9. return boundaryFunction(phi) * aux
  10.  
  11. def difference(parameter):
  12. return trajectoryFunction(parameter) - boundaryFunction(parameter)
  13.  
  14. def integrand(parameter):
  15. rr = boundaryFunction(parameter)
  16. dd = boundaryDerivative (parameter)
  17. return np.sqrt(rr ** 2 + dd ** 2)
  18.  
  19. ##### Main #####
  20.  
  21. length_vals = np.array([], dtype=np.float64)
  22. alpha_vals = np.array([], dtype=np.float64)
  23.  
  24. # nof initial phi angles, alpha angles, and nof collisions for each.
  25. n_phi, n_alpha, n_cols, count = 10, 10, 10, 0
  26. # Length of the boundary
  27. total_length, err = integrate.quad(integrand, 0, 2 * np.pi)
  28.  
  29. for phi in np.linspace(0, 2 * np.pi, n_phi):
  30. for alpha in np.linspace(0, 2 * np.pi, n_alpha):
  31. for n in np.arange(1, n_cols):
  32.  
  33. nu = np.arctan(boundaryFunction(phi) / boundaryDerivative(phi))
  34. beta = np.pi + phi + alpha - nu
  35.  
  36. # Determines next impact coordinate.
  37. bnds = (0, 2 * np.pi)
  38. phi_new = optimize.minimize_scalar(difference, bounds=bnds, method='bounded').x
  39.  
  40. nu_new = np.arctan(boundaryFunction(phi_new) / boundaryDerivative(phi_new))
  41. # Reflection angle with relation to tangent.
  42. alpha_new = phi_new - phi + nu - nu_new - alpha
  43. # Arc length for current phi value.
  44. arc_length, err = integrate.quad(integrand, 0, phi_new)
  45.  
  46. # Append values to list
  47. length_vals = np.append(length_vals, arc_length / total_length)
  48. alpha_vals = np.append(alpha_vals, alpha)
  49.  
  50.  
  51. count += 1
  52. print "{}%" .format(100 * count / (n_phi * n_alpha))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement