Skip to content

Commit fc52219

Browse files
committed
updated tutorial3
# Conflicts: # pyproject.toml
1 parent 5bf496a commit fc52219

File tree

5 files changed

+155
-46
lines changed

5 files changed

+155
-46
lines changed

pyproject.toml

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
[build-system]
2+
requires = ["setuptools>=45", "wheel"]
3+
build-backend = "setuptools.build_meta"
4+
5+
[project]
6+
name = "pygem"
7+
dynamic = ["version"]
8+
description = "Python Geometrical Morphing"
9+
readme = {file = "README.md", content-type = "text/markdown"}
10+
keywords = ["dimension_reduction", "mathematics", "ffd", "morphing", "iges", "stl", "vtk", "openfoam"]
11+
authors = [
12+
{name = "Marco Tezzele", email = "[email protected]"},
13+
{name = "Nicola Demo", email = "[email protected]"},
14+
{name = "Andrea Mola", email = "[email protected]"}
15+
]
16+
license = {text = "MIT"}
17+
classifiers = [
18+
"Development Status :: 5 - Production/Stable",
19+
"License :: OSI Approved :: MIT License",
20+
"Programming Language :: Python :: 3",
21+
"Programming Language :: Python :: 3.9",
22+
"Programming Language :: Python :: 3.10",
23+
"Programming Language :: Python :: 3.11",
24+
"Programming Language :: Python :: 3.12",
25+
"Intended Audience :: Science/Research",
26+
"Topic :: Scientific/Engineering :: Mathematics"
27+
]
28+
requires-python = ">=3.9"
29+
dependencies = [
30+
"future",
31+
"numpy>=1.21.0",
32+
"scipy>=1.7.0",
33+
"matplotlib>=3.5.0"
34+
]
35+
36+
[project.urls]
37+
Homepage = "https://github.com/mathLab/PyGeM"
38+
Documentation = "http://mathlab.github.io/PyGeM/"
39+
Repository = "https://github.com/mathLab/PyGeM"
40+
"Bug Reports" = "https://github.com/mathLab/PyGeM/issues"
41+
42+
[project.optional-dependencies]
43+
docs = [
44+
"Sphinx>=5.0.0",
45+
"sphinx_rtd_theme>=1.0.0"
46+
]
47+
test = [
48+
"pytest>=6.0.0",
49+
"pytest-cov>=3.0.0"
50+
]
51+
tut = [
52+
"jupyter",
53+
"notebook",
54+
"ipywidgets",
55+
"nbconvert",
56+
]
57+
dev = [
58+
"Sphinx>=5.0.0",
59+
"sphinx_rtd_theme>=1.0.0",
60+
"pytest>=6.0.0",
61+
"pytest-cov>=3.0.0",
62+
"jupyter",
63+
"notebook",
64+
"ipywidgets",
65+
"nbconvert",
66+
"black>=23.0.0",
67+
"pylint>=3.0.0"
68+
]
69+
70+
[tool.setuptools]
71+
include-package-data = true
72+
73+
[tool.setuptools.packages.find]
74+
where = ["."]
75+
include = ["pygem*"]
76+
exclude = ["tests*", "docs*", "tutorials*"]
77+
78+
[tool.setuptools.dynamic]
79+
version = { attr = "pygem.meta.__version__" }
80+
81+
[tool.black]
82+
line-length = 88
83+
target-version = ['py39']

tutorials/tutorial1/tutorial-1-ffd.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@
2222

2323
np.random.seed(42)
2424

25-
26-
import numpy as np
2725
import mpl_toolkits.mplot3d
2826
import matplotlib.pyplot as plt
2927

tutorials/tutorial2/tutorial-2-iges.py

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,43 +5,49 @@
55

66
# ## Tutorial 2: Free Form Deformation on a cylinder in CAD file format
77

8+
import sys
9+
import platform
10+
print(f"Python Version: {sys.version}")
11+
print(f"Platform: {sys.platform}")
12+
print(f"System: {platform.system()} {platform.release()}")
13+
14+
try:
15+
import pygem
16+
print(f"PyGeM version: {pygem.__version__}")
17+
except ImportError:
18+
print(f"PyGeM not found. Installing...")
19+
import subprocess
20+
subprocess.check_call([sys.executable, "-m", "pip", "install", "-e", ".[tut]"])
21+
import pygem
22+
print(f"PyGeM version: {pygem.__version__}")
23+
24+
import numpy as np
25+
np.random.seed(42)
26+
827
# In this tutorial we show again an application of _free form deformation_ method, now to a CAD file. These files, that are often adopted to model complex geometries, require an additional pre- and post-processing of the surfaces to perform the deformation.
928
#
1029
# The **CAD** submodule of **PyGeM** takes care of the deformation to all CAD files (.step, .iges, etc.), so first of all we import from the submodule the `FFD` class.
1130

12-
# In[1]:
13-
14-
1531
from pygem.cad import FFD
1632

1733

1834
# Since the visualisation of CAD files may be tricky (depending by the operating system, the graphical front-end, ...), we avoid for this tutorial any graphical renderer, letting to the reader the possibility to implement by himself the needed plotting routines.
1935
#
2036
# The `FFD` class in the **CAD** module shares the same interface with the original `FFD` class (for discrete geometries). We can simply parse a parameter file to set everything like we want (remember you can do the same directly setting the object attributes).
2137

22-
# In[2]:
23-
24-
2538
ffd = FFD()
26-
ffd.read_parameters("../tests/test_datasets/parameters_test_ffd_iges.prm")
39+
ffd.read_parameters('../tests/test_datasets/parameters_test_ffd_iges.prm')
2740
print(ffd)
2841

2942

3043
# Almost already completed! We now specify the input file (the one which contains the shape to deform) and the output file: these are the two input argument to pass to the object in order to perform the deformation.
3144

32-
# In[3]:
33-
34-
3545
input_cad_file_name = "../tests/test_datasets/test_pipe.iges"
3646
modified_cad_file_name = "test_pipe_deformed.iges"
3747
ffd(input_cad_file_name, modified_cad_file_name)
3848

3949

4050
# The output file is created and the deformed shape is stored into it. We skip any visual check because of the **CAD** format file, so as final proof we simply show the differences, lines by lines, between the input and the output. Even if we can't be sure about the correctness of the results, in this way we ensure the outcome is different from the original inpuit.
4151

42-
# In[4]:
43-
44-
45-
get_ipython().system(
46-
"diff -y ../tests/test_datasets/test_pipe.iges test_pipe_deformed.iges"
47-
)
52+
import subprocess
53+
subprocess.run(["diff", "-y", "../tests/test_datasets/test_pipe.iges", "test_pipe_deformed.iges"])

tutorials/tutorial3/tutorial-3-rbf.ipynb

Lines changed: 28 additions & 7 deletions
Large diffs are not rendered by default.

tutorials/tutorial3/tutorial-3-rbf.py

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,41 +6,50 @@
66

77
# In this tutorial we will show how to use the Radial Basis Functions interpolation technique to deform a cube.
88
#
9-
# First of all we import the required **PyGeM** class, we import numpy and we set matplotlib for the notebook.
9+
# First of all we import the required **PyGeM** class, we import numpy and matplotlib
1010

1111
# In[1]:
12+
import sys
13+
import platform
14+
print(f"Python Version: {sys.version}")
15+
print(f"Platform: {sys.platform}")
16+
print(f"System: {platform.system()} {platform.release()}")
17+
18+
try:
19+
import pygem
20+
print(f"PyGeM version: {pygem.__version__}")
21+
except ImportError:
22+
print(f"PyGeM not found. Installing...")
23+
import subprocess
24+
subprocess.check_call([sys.executable, "-m", "pip", "install", "-e", ".[tut]"])
25+
import pygem
26+
print(f"PyGeM version: {pygem.__version__}")
1227

13-
14-
get_ipython().run_line_magic("matplotlib", "inline")
15-
from pygem import RBF
1628
import numpy as np
29+
np.random.seed(42)
1730
import matplotlib.pyplot as plt
31+
from pygem import RBF
1832

1933

2034
# Using RBF, we can control the deformation by arranging some control points around the object to deform, then moving these latter to induce the morphing. Within **PyGeM**, the setting of such parameters can be done by parsing an input text file or manually touching the `RBF` attributes.
2135
#
2236
# Let's try togheter by using an input file: the first step is the creation of the new object. After this, we can use the `read_parameters` to set the parameters.
2337

2438
# In[2]:
25-
26-
2739
rbf = RBF()
28-
rbf.read_parameters(filename="../tests/test_datasets/parameters_rbf_cube.prm")
40+
rbf.read_parameters(filename='../tests/test_datasets/parameters_rbf_cube.prm')
2941

3042

3143
# The following is the parameters file for this particular case. The Radial Basis Functions section describes the basis functions to use. Here we use Gaussian splines with the distance parameter equal to 0.5 (see the documentation of the [RBF](http://mathlab.github.io/PyGeM/rbf.html) class for more details). As control points we consider the 8 vertices of the cube (the first one is not exactly the vertex), and we move 3 of them. In the Control points section there are all the coordinates of the control points.
3244

3345
# In[3]:
34-
35-
36-
get_ipython().run_line_magic("cat", "../tests/test_datasets/parameters_rbf_cube.prm")
46+
import subprocess
47+
subprocess.run(['cat', '../tests/test_datasets/parameters_rbf_cube.prm'])
3748

3849

3950
# Here we create a $10 \times10 \times 10$ lattice to mimic a cube.
4051

4152
# In[4]:
42-
43-
4453
nx, ny, nz = (10, 10, 10)
4554
mesh = np.zeros((nx * ny * nz, 3))
4655

@@ -56,8 +65,6 @@
5665
# Now we plot the points to see what we are doing.
5766

5867
# In[5]:
59-
60-
6168
fig = plt.figure(1)
6269
ax = fig.add_subplot(111, projection="3d")
6370
ax.scatter(mesh[:, 0], mesh[:, 1], mesh[:, 2], c="blue", marker="o")
@@ -70,28 +77,22 @@
7077
# We can also plot the original control points and the deformed ones.
7178

7279
# In[6]:
73-
74-
7580
rbf.plot_points()
7681

7782

7883
# Finally we perform the RBF interpolation using the `RBF` class.
7984

8085
# In[7]:
81-
82-
8386
new_mesh = rbf(mesh)
8487

8588

8689
# We can plot the new points in order to see the deformation. Try different basis functions and radius to better fit your specific problem.
8790

8891
# In[8]:
89-
90-
9192
fig = plt.figure(2)
9293
ax = fig.add_subplot(111, projection="3d")
9394
ax.scatter(new_mesh[:, 0], new_mesh[:, 1], new_mesh[:, 2], c="red", marker="o")
9495
ax.set_xlabel("X axis")
9596
ax.set_ylabel("Y axis")
9697
ax.set_zlabel("Z axis")
97-
plt.show()
98+
plt.show()

0 commit comments

Comments
 (0)