|
| 1 | +import numpy as np |
| 2 | +import mpl_toolkits.mplot3d |
| 3 | +import matplotlib.pyplot as plt |
| 4 | + |
| 5 | +from pygem import FFD |
| 6 | + |
| 7 | + |
| 8 | +def mesh_points(num_pts=2000): |
| 9 | + indices = np.arange(0, num_pts, dtype=float) + 0.5 |
| 10 | + |
| 11 | + phi = np.arccos(1 - 2*indices/num_pts) |
| 12 | + theta = np.pi * (1 + 5**0.5) * indices |
| 13 | + |
| 14 | + return np.array([np.cos(theta) * np.sin(phi), np.sin(theta) * np.sin(phi), np.cos(phi)]).T |
| 15 | + |
| 16 | + |
| 17 | +mesh = mesh_points() |
| 18 | +plt.figure(figsize=(8, 8)).add_subplot(111, projection='3d').scatter(*mesh.T) |
| 19 | +plt.show() |
| 20 | + |
| 21 | +ffd = FFD([2, 2, 2]) |
| 22 | +print(ffd) |
| 23 | + |
| 24 | +print('Movements of point[{}, {}, {}] along x: {}'.format(1, 1, 1, ffd.array_mu_x[1, 1, 1])) |
| 25 | +print('Movements of point[{}, {}, {}] along z: {}'.format(1, 1, 1, ffd.array_mu_z[1, 1, 1])) |
| 26 | + |
| 27 | +ffd.array_mu_x[1, 1, 1] = 2 |
| 28 | +ffd.array_mu_z[1, 1, 1] = 0.8 |
| 29 | +print() |
| 30 | +print('Movements of point[{}, {}, {}] along x: {}'.format(1, 1, 1, ffd.array_mu_x[1, 1, 1])) |
| 31 | +print('Movements of point[{}, {}, {}] along z: {}'.format(1, 1, 1, ffd.array_mu_z[1, 1, 1])) |
| 32 | + |
| 33 | +new_mesh = ffd(mesh) |
| 34 | +print(type(new_mesh), new_mesh.shape) |
| 35 | + |
| 36 | + |
| 37 | +ax = plt.figure(figsize=(8, 8)).add_subplot(111, projection='3d') |
| 38 | +ax.scatter(*new_mesh.T) |
| 39 | +ax.scatter(*ffd.control_points().T, s=50, c='red') |
| 40 | +plt.show() |
0 commit comments