Skip to content

Commit cae5afc

Browse files
committed
Merge pull request #72 from mtezzele/doc
fixed doc, renamed utilities and minor fixes
2 parents 210dad6 + d272c2a commit cae5afc

File tree

9 files changed

+61
-65
lines changed

9 files changed

+61
-65
lines changed

pygem/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
__all__ = ['affine', 'filehandler', 'freeform', 'openfhandler', 'params', 'stlhandler', 'unvhandler', 'vtkhandler', 'igeshandler', 'utilities']
2+
__all__ = ['affine', 'filehandler', 'freeform', 'openfhandler', 'params', 'stlhandler', 'unvhandler', 'vtkhandler', 'igeshandler', 'utils']
33

44
from . import affine
55
from . import freeform
@@ -10,4 +10,4 @@
1010
from . import unvhandler
1111
from . import vtkhandler
1212
from . import igeshandler
13-
from . import utilities
13+
from . import utils

pygem/filehandler.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""
2-
Utilities for reading and writing different CAD files.
2+
Base module with the base class for reading and writing different CAD files.
33
"""
44
import os
55

pygem/igeshandler.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""
2-
Utilities for reading and writing different CAD files.
2+
Derived module from filehandler.py to handle iges and igs files.
33
"""
44
import os
55
import numpy as np
@@ -52,6 +52,8 @@ def parse(self, filename):
5252
"""
5353
Method to parse the file `filename`. It returns a matrix with all the coordinates.
5454
55+
:param string filename: name of the input file.
56+
5557
:return: mesh_points: it is a `n_points`-by-3 matrix containing the coordinates of
5658
the points of the mesh
5759
:rtype: numpy.ndarray

pygem/openfhandler.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""
2-
Utilities for reading and writing different CAD files.
2+
Derived module from filehandler.py to handle OpenFOAM files.
33
"""
44
import numpy as np
55
import pygem.filehandler as fh
@@ -23,6 +23,8 @@ def parse(self, filename):
2323
"""
2424
Method to parse the `filename`. It returns a matrix with all the coordinates.
2525
26+
:param string filename: name of the input file.
27+
2628
:return: mesh_points: it is a `n_points`-by-3 matrix containing the coordinates of
2729
the points of the mesh
2830
:rtype: numpy.ndarray

pygem/stlhandler.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""
2-
Utilities for reading and writing different CAD files.
2+
Derived module from filehandler.py to handle STereoLithography files.
33
"""
44
import numpy as np
55
from mpl_toolkits import mplot3d
@@ -25,6 +25,8 @@ def parse(self, filename):
2525
"""
2626
Method to parse the `filename`. It returns a matrix with all the coordinates.
2727
28+
:param string filename: name of the input file.
29+
2830
:return: mesh_points: it is a `n_points`-by-3 matrix containing the coordinates of
2931
the points of the mesh
3032
:rtype: numpy.ndarray
@@ -55,8 +57,6 @@ def write(self, mesh_points, filename, write_bin=False):
5557
the coordinates of the points of the mesh.
5658
:param string filename: name of the output file.
5759
:param boolean write_bin: flag to write in the binary format. Default is False.
58-
59-
.. todo:: DOCS
6060
"""
6161
self._check_filename_type(filename)
6262
self._check_extension(filename)

pygem/unvhandler.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""
2-
Utilities for reading and writing different CAD files.
2+
Derived module from filehandler.py to handle Universal (unv) files.
33
"""
44
import numpy as np
55
import pygem.filehandler as fh
@@ -21,14 +21,13 @@ def __init__(self):
2121
def parse(self, filename):
2222
"""
2323
Method to parse the file `filename`. It returns a matrix with all the coordinates.
24+
It reads only the section 2411 of the unv files and it assumes there are only triangles.
2425
26+
:param string filename: name of the input file.
27+
2528
:return: mesh_points: it is a `n_points`-by-3 matrix containing the coordinates of
26-
the points of the mesh
29+
the points of the mesh.
2730
:rtype: numpy.ndarray
28-
29-
.. todo::
30-
31-
- specify when it works
3231
"""
3332
self._check_filename_type(filename)
3433
self._check_extension(filename)
@@ -83,8 +82,6 @@ def write(self, mesh_points, filename):
8382
:param numpy.ndarray mesh_points: it is a `n_points`-by-3 matrix containing
8483
the coordinates of the points of the mesh
8584
:param string filename: name of the output file.
86-
87-
.. todo:: DOCS
8885
"""
8986
self._check_filename_type(filename)
9087
self._check_extension(filename)
Lines changed: 31 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,86 +1,82 @@
11
"""
22
Auxiliary utilities for PyGeM.
33
"""
4-
54
import vtk
6-
import vtk.util.numpy_support as ns
75
import numpy as np
86

97
# TODO: add the connectivity to the ffd control points to visualize the lattice.
108

11-
12-
139
def write_bounding_box(parameters, outfile, write_deformed=True):
1410
"""
1511
Method that writes a vtk file containing the FFD lattice. This method
1612
allows to visualize where the FFD control points are located before the geometrical morphing.
17-
If the flag is set to original (default) the method writes out the undeformed lattice,
18-
if it is set to modified it writes out the deformed lattice.
19-
13+
If the `write_deformed` flag is set to True the method writes out the deformed lattice, otherwise
14+
it writes one the original undeformed lattice.
15+
2016
:param FFDParameters parameters: parameters of the Free Form Deformation.
2117
:param string outfile: name of the output file.
22-
:param bool write_deformed: flag to write the original or modified FFD control lattice.
23-
The default is set to deformed.
24-
18+
:param bool write_deformed: flag to write the original or modified FFD control lattice.
19+
The default is set to True.
20+
2521
:Example:
26-
27-
>>> import pygem.utilities as util
22+
23+
>>> import pygem.utils as ut
2824
>>> import pygem.params as pars
2925
>>> import numpy as np
30-
26+
3127
>>> params = pars.FFDParameters()
3228
>>> params.read_parameters(filename='tests/test_datasets/parameters_test_ffd_sphere.prm')
33-
>>> util.write_bounding_box(params, 'tests/test_datasets/box_test_sphere.vtk')
29+
>>> ut.write_bounding_box(params, 'tests/test_datasets/box_test_sphere.vtk')
3430
"""
35-
3631
aux_x = np.linspace(0, parameters.lenght_box_x, parameters.n_control_points[0])
3732
aux_y = np.linspace(0, parameters.lenght_box_y, parameters.n_control_points[1])
3833
aux_z = np.linspace(0, parameters.lenght_box_z, parameters.n_control_points[2])
3934
lattice_y_coords, lattice_x_coords, lattice_z_coords = np.meshgrid(aux_y, aux_x, aux_z)
4035

41-
if write_deformed == False:
42-
box_points = np.array([lattice_x_coords.ravel(), lattice_y_coords.ravel(), lattice_z_coords.ravel()])
43-
if write_deformed == True:
44-
box_points = np.array([lattice_x_coords.ravel() + parameters.array_mu_x.ravel()*parameters.lenght_box_x, \
45-
lattice_y_coords.ravel() + parameters.array_mu_y.ravel()*parameters.lenght_box_y, \
46-
lattice_z_coords.ravel() + parameters.array_mu_z.ravel()*parameters.lenght_box_z])
47-
36+
if write_deformed:
37+
box_points = np.array([lattice_x_coords.ravel() + parameters.array_mu_x.ravel() * parameters.lenght_box_x,\
38+
lattice_y_coords.ravel() + parameters.array_mu_y.ravel() * parameters.lenght_box_y, \
39+
lattice_z_coords.ravel() + parameters.array_mu_z.ravel() * parameters.lenght_box_z])
40+
else:
41+
box_points = np.array([lattice_x_coords.ravel(), lattice_y_coords.ravel(), \
42+
lattice_z_coords.ravel()])
43+
4844
n_rows = box_points.shape[1]
45+
box_points = np.dot(parameters.rotation_matrix, box_points) + \
46+
np.transpose(np.tile(parameters.origin_box, (n_rows, 1)))
4947

50-
box_points = np.dot(parameters.rotation_matrix,box_points) + np.transpose(np.tile(parameters.origin_box, (n_rows,1)))
51-
5248
_write_vtk_box(box_points, outfile)
53-
54-
49+
50+
5551
def _write_vtk_box(box_points, filename):
5652
"""
57-
Method that writes a vtk file containing FFD control points.
58-
53+
Private method that writes a vtk file containing FFD control points.
54+
5955
:param numpy.ndarray box_points: coordinates of the FFD control points.
6056
:param string filename: name of the output file.
6157
"""
6258
# setup points and vertices
6359
points = vtk.vtkPoints()
6460
vertices = vtk.vtkCellArray()
65-
61+
6662
for index in range(0, box_points.shape[1]):
67-
id = points.InsertNextPoint(box_points[0, index], box_points[1, index], box_points[2, index])
63+
ind = points.InsertNextPoint(box_points[0, index], box_points[1, index], box_points[2, index])
6864
vertices.InsertNextCell(1)
69-
vertices.InsertCellPoint(id)
70-
65+
vertices.InsertCellPoint(ind)
66+
7167
polydata = vtk.vtkPolyData()
7268
polydata.SetPoints(points)
7369
polydata.SetVerts(vertices)
74-
7570
polydata.Modified()
71+
7672
writer = vtk.vtkDataSetWriter()
7773
writer.SetFileName(filename)
78-
74+
7975
if vtk.VTK_MAJOR_VERSION <= 5:
8076
polydata.Update()
8177
writer.SetInput(polydata)
8278
else:
8379
writer.SetInputData(polydata)
84-
80+
8581
writer.Write()
8682

pygem/vtkhandler.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""
2-
Utilities for reading and writing different CAD files.
2+
Derived module from filehandler.py to handle vtk files.
33
"""
44
import numpy as np
55
import matplotlib.pyplot as plt
@@ -25,6 +25,8 @@ def parse(self, filename):
2525
"""
2626
Method to parse the file `filename`. It returns a matrix with all the coordinates.
2727
28+
:param string filename: name of the input file.
29+
2830
:return: mesh_points: it is a `n_points`-by-3 matrix containing the coordinates of
2931
the points of the mesh
3032
:rtype: numpy.ndarray
Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,38 @@
11

22
from unittest import TestCase
33
import unittest
4-
import pygem.utilities as util
4+
import pygem.utils as ut
55
import pygem.params as pars
66
import numpy as np
77
import filecmp
88
import os
9+
import vtk
910

1011

1112
class TestVtkHandler(TestCase):
1213

1314

14-
def test_utilities_write_original_box(self):
15+
def test_utils_write_original_box(self):
1516
params = pars.FFDParameters()
1617
params.read_parameters(filename='tests/test_datasets/parameters_test_ffd_sphere.prm')
1718

1819
outfilename = 'tests/test_datasets/box_test_sphere.vtk'
1920

20-
util.write_bounding_box(params, outfilename, False)
21+
ut.write_bounding_box(params, outfilename, False)
2122
os.remove(outfilename)
2223

2324

24-
def test_utilities_write_modified_box(self):
25+
def test_utils_write_modified_box(self):
2526
params = pars.FFDParameters()
2627
params.read_parameters(filename='tests/test_datasets/parameters_test_ffd_sphere.prm')
2728

2829
outfilename = 'tests/test_datasets/box_test_sphere.vtk'
2930

30-
util.write_bounding_box(params, outfilename)
31+
ut.write_bounding_box(params, outfilename)
3132
os.remove(outfilename)
3233

3334

34-
def test_utilities_check_vtk_original_box(self):
35-
import vtk
36-
35+
def test_utils_check_vtk_original_box(self):
3736
params = pars.FFDParameters()
3837
params.read_parameters(filename='tests/test_datasets/parameters_test_ffd_sphere.prm')
3938

@@ -43,15 +42,13 @@ def test_utilities_check_vtk_original_box(self):
4342
else:
4443
outfilename_expected = 'tests/test_datasets/box_test_sphere_true_version6.vtk'
4544

46-
util.write_bounding_box(params, outfilename, False)
45+
ut.write_bounding_box(params, outfilename, False)
4746

4847
self.assertTrue(filecmp.cmp(outfilename, outfilename_expected))
4948
os.remove(outfilename)
5049

5150

52-
def test_utilities_check_vtk_modified_box(self):
53-
import vtk
54-
51+
def test_utils_check_vtk_modified_box(self):
5552
params = pars.FFDParameters()
5653
params.read_parameters(filename='tests/test_datasets/parameters_test_ffd_sphere.prm')
5754

@@ -61,7 +58,7 @@ def test_utilities_check_vtk_modified_box(self):
6158
else:
6259
outfilename_expected = 'tests/test_datasets/box_modified_test_sphere_true_version6.vtk'
6360

64-
util.write_bounding_box(params, outfilename)
61+
ut.write_bounding_box(params, outfilename)
6562

6663
self.assertTrue(filecmp.cmp(outfilename, outfilename_expected))
6764
os.remove(outfilename)

0 commit comments

Comments
 (0)