Skip to content

Commit 7afe6c1

Browse files
committed
modified tutorial 7
1 parent 107a2fe commit 7afe6c1

File tree

2 files changed

+180
-40
lines changed

2 files changed

+180
-40
lines changed

tutorials/tutorial7/tutorial-7-cffd.ipynb

Lines changed: 146 additions & 36 deletions
Large diffs are not rendered by default.

tutorials/tutorial7/tutorial-7-cffd.py

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,34 @@
11
#!/usr/bin/env python
22
# coding: utf-8
3-
from pygem.cffd import CFFD
3+
4+
import sys
5+
import platform
6+
print(f"Python Version: {sys.version}")
7+
print(f"Platform: {sys.platform}")
8+
print(f"System: {platform.system()} {platform.release()}")
9+
10+
try:
11+
import pygem
12+
print(f"PyGeM version: {pygem.__version__}")
13+
except ImportError:
14+
print(f"PyGeM not found. Installing...")
15+
import subprocess
16+
subprocess.check_call([sys.executable, "-m", "pip", "install", "-e", ".[tut]"])
17+
import pygem
18+
print(f"PyGeM version: {pygem.__version__}")
19+
420
import numpy as np
21+
np.random.seed(42)
22+
523
import matplotlib.pyplot as plt
624

25+
from pygem.cffd import CFFD
26+
727
np.random.seed(0)
828
x = 0.5 * np.random.rand(100, 3) + 0.25
929
ax = plt.axes(projection="3d")
1030
ax.plot3D(x[:, 0], x[:, 1], x[:, 2], "o")
31+
1132
from pygem.ffd import FFD
1233

1334
ffd = FFD([8, 8, 1])
@@ -33,6 +54,7 @@ def custom_linear_constraint(x):
3354
"The custom linear function on the classic FFD deformed points is",
3455
custom_linear_constraint(x_def),
3556
)
57+
3658
from pygem.cffd import CFFD
3759

3860
ffd = CFFD(np.array([1.0]), custom_linear_constraint, [3, 3, 1])
@@ -47,6 +69,7 @@ def custom_linear_constraint(x):
4769
"The custom linear function on the constrained FFD deformed points is",
4870
custom_linear_constraint(x_def),
4971
)
72+
5073
from pygem.bffd import BFFD
5174

5275

@@ -72,8 +95,14 @@ def mesh_points(num_pts=2000):
7295
ax.scatter(*mesh_def.T)
7396
ax.scatter(*ffd.control_points().T, s=50, c="red")
7497
plt.show()
75-
import meshio
76-
import numpy as np
98+
99+
try:
100+
import meshio
101+
except ImportError:
102+
print("meshio not found. Installing...")
103+
import subprocess
104+
subprocess.check_call([sys.executable, "-m", "pip", "install", "meshio"])
105+
import meshio
77106

78107
mesh = meshio.read("../../tests/test_datasets/Stanford_Bunny.stl")
79108
points = mesh.points
@@ -87,6 +116,7 @@ def mesh_points(num_pts=2000):
87116
ax.plot_trisurf(
88117
points[:, 0], points[:, 1], points[:, 2], triangles=faces, cmap=plt.cm.Spectral
89118
)
119+
90120
from pygem.vffd import VFFD, _volume
91121

92122
initvolume = _volume(points, faces)
@@ -110,4 +140,4 @@ def mesh_points(num_pts=2000):
110140
mesh_def[:, 2],
111141
triangles=faces,
112142
cmap=plt.cm.Spectral,
113-
)
143+
)

0 commit comments

Comments
 (0)