Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pygem/affine.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
"""
import math
import sys
import numpy as np
from functools import reduce
import numpy as np


def angles2matrix(rot_z=0, rot_y=0, rot_x=0):
Expand Down
20 changes: 10 additions & 10 deletions pygem/freeform.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,19 +150,19 @@ def perform(self):

# shift_mesh_points needs to be transposed to be summed with mesh_points
# apply inverse transformation to shifted mesh points
new_mesh_points = self._transform_points(np.transpose(shift_mesh_points) +
mesh_points, inverse_transformation) + \
translation
new_mesh_points = self._transform_points(
np.transpose(shift_mesh_points) + mesh_points,
inverse_transformation) + translation

# merge non-shifted mesh points with shifted ones
self.modified_mesh_points = np.copy(self.original_mesh_points)
self.modified_mesh_points[(reference_frame_mesh_points[:,0] >= 0.) &
(reference_frame_mesh_points[:,0] <= 1.) &
(reference_frame_mesh_points[:,1] >= 0.) &
(reference_frame_mesh_points[:,1] <= 1.) &
(reference_frame_mesh_points[:,2] >= 0.) &
(reference_frame_mesh_points[:,2] <= 1.)] \
= new_mesh_points
self.modified_mesh_points[(reference_frame_mesh_points[:, 0] >= 0.)
& (reference_frame_mesh_points[:, 0] <= 1.) &
(reference_frame_mesh_points[:, 1] >= 0.) &
(reference_frame_mesh_points[:, 1] <= 1.) &
(reference_frame_mesh_points[:, 2] >= 0.) &
(reference_frame_mesh_points[:, 2] <=
1.)] = new_mesh_points

@staticmethod
def _transform_points(original_points, transformation):
Expand Down
10 changes: 5 additions & 5 deletions pygem/idw.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,18 @@
{\\displaystyle\\sum_{j=1}^\\mathcal{N} w(\\mathrm{x},\\mathrm{x}_j)}
u_k


where, in general, :math:`w(\\mathrm{x}, \\mathrm{x}_i)` represents the
weighting function:

.. math::
w(\\mathrm{x}, \\mathrm{x}_i) = \\| \\mathrm{x} - \\mathrm{x}_i \\|^{-p}

being :math:`\\| \\mathrm{x} - \\mathrm{x}_i \\|^{-p} \\ge 0` is the
Euclidean distance between :math:`\\mathrm{x}` and data point
:math:`\\mathrm{x}_i` and :math:`p` is a power parameter, typically equal to
2.

"""
import numpy as np

from scipy.spatial.distance import cdist


Expand Down Expand Up @@ -91,7 +88,10 @@ def perform(self):
"""

def distance(u, v):
return np.linalg.norm(u - v, self.parameters.power)
"""
Norm of u - v
"""
return np.linalg.norm(u - v, ord=self.parameters.power)

# Compute displacement of the control points
displ = (self.parameters.deformed_control_points -
Expand Down
1 change: 0 additions & 1 deletion pygem/igeshandler.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"""
Derived module from filehandler.py to handle iges and igs files.
"""

from OCC.IGESControl import (IGESControl_Reader, IGESControl_Writer,
IGESControl_Controller_Init)
from OCC.IFSelect import IFSelect_RetDone
Expand Down
26 changes: 14 additions & 12 deletions pygem/openfhandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ class OpenFoamHandler(fh.FileHandler):

:cvar string infile: name of the input file to be processed.
:cvar string outfile: name of the output file where to write in.
:cvar list extensions: extensions of the input/output files. It is equal to [''] since
openFOAM files do not have extension.
:cvar list extensions: extensions of the input/output files. It
is equal to [''] since openFOAM files do not have extension.
"""

def __init__(self):
Expand All @@ -21,12 +21,13 @@ def __init__(self):

def parse(self, filename):
"""
Method to parse the `filename`. It returns a matrix with all the coordinates.
Method to parse the `filename`. It returns a matrix with all
the coordinates.

:param string filename: name of the input file.

:return: mesh_points: it is a `n_points`-by-3 matrix containing the coordinates of
the points of the mesh
:return: mesh_points: it is a `n_points`-by-3 matrix containing
the coordinates of the points of the mesh
:rtype: numpy.ndarray

.. todo::
Expand Down Expand Up @@ -58,12 +59,13 @@ def parse(self, filename):

def write(self, mesh_points, filename):
"""
Writes a openFOAM file, called filename, copying all the lines from self.filename but
the coordinates. mesh_points is a matrix that contains the new coordinates to
write in the openFOAM file.
Writes a openFOAM file, called filename, copying all the
lines from self.filename but the coordinates. mesh_points
is a matrix that contains the new coordinates to write in
the openFOAM file.

:param numpy.ndarray mesh_points: it is a `n_points`-by-3 matrix containing
the coordinates of the points of the mesh.
:param numpy.ndarray mesh_points: it is a `n_points`-by-3
matrix containing the coordinates of the points of the mesh.
:param string filename: name of the output file.

.. todo:: DOCS
Expand All @@ -82,8 +84,8 @@ def write(self, mesh_points, filename):
for line in input_file:
nrow += 1
if 20 < nrow < 21 + n_points:
output_file.write('(' + str(mesh_points[i][0]) + ' ' + str(mesh_points[i][1]) + \
' ' + str(mesh_points[i][2]) +')')
output_file.write('(' + str(mesh_points[i][0]) + ' ' + str(
mesh_points[i][1]) + ' ' + str(mesh_points[i][2]) + ')')
output_file.write('\n')
i += 1
else:
Expand Down
3 changes: 3 additions & 0 deletions pygem/params/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
"""
params init
"""
from .rbfparams import RBFParameters
from .ffdparams import FFDParameters
from .idwparams import IDWParameters
83 changes: 55 additions & 28 deletions pygem/params/ffdparams.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,18 @@
"""
Utilities for reading and writing parameters files to perform the desired
Utilities for reading and writing parameters files to perform FFD
geometrical morphing.
"""
try:
import configparser as configparser
except ImportError:
import ConfigParser as configparser
import os

import numpy as np
from OCC.Bnd import Bnd_Box
from OCC.BRepBndLib import brepbndlib_Add
from OCC.BRepMesh import BRepMesh_IncrementalMesh
from OCC.Bnd import Bnd_Box

import vtk
import pygem.affine as at
from math import radians


class FFDParameters(object):
Expand Down Expand Up @@ -44,7 +41,7 @@ class FFDParameters(object):
:Example: from file

>>> import pygem.params as ffdp
>>>
>>>
>>> # Reading an existing file
>>> params1 = ffdp.FFDParameters()
>>> params1.read_parameters(
Expand Down Expand Up @@ -115,8 +112,8 @@ def rotation_matrix(self):
:rtype: numpy.ndarray
"""
return at.angles2matrix(
radians(self.rot_angle[2]), radians(self.rot_angle[1]),
radians(self.rot_angle[0]))
np.radians(self.rot_angle[2]), np.radians(self.rot_angle[1]),
np.radians(self.rot_angle[0]))

@property
def position_vertices(self):
Expand Down Expand Up @@ -213,69 +210,99 @@ def write_parameters(self, filename='parameters.prm'):
output_string += 'n control points z: ' + str(
self.n_control_points[2]) + '\n'

output_string += '\n# box lenght indicates the length of the FFD bounding box along the three canonical directions (x, y, z).\n'
output_string += '\n# box lenght indicates the length of the FFD '
output_string += 'bounding box along the three canonical directions (x, y, z).\n'

output_string += '# It uses the local coordinate system.\n'
output_string += '# For example to create a 2 x 1.5 x 3 meters box use the following: lenght box: 2.0, 1.5, 3.0\n'
output_string += '# For example to create a 2 x 1.5 x 3 meters box '
output_string += 'use the following: lenght box: 2.0, 1.5, 3.0\n'

output_string += 'box lenght x: ' + str(self.lenght_box[0]) + '\n'
output_string += 'box lenght y: ' + str(self.lenght_box[1]) + '\n'
output_string += 'box lenght z: ' + str(self.lenght_box[2]) + '\n'

output_string += '\n# box origin indicates the x, y, and z coordinates of the origin of the FFD bounding box. That is center of\n'
output_string += '# rotation of the bounding box. It corresponds to the point coordinates with position [0][0][0].\n'
output_string += '\n# box origin indicates the x, y, and z coordinates of '
output_string += 'the origin of the FFD bounding box. That is center of\n'

output_string += '# rotation of the bounding box. It corresponds to '
output_string += 'the point coordinates with position [0][0][0].\n'

output_string += '# See section "Parameters weights" for more details.\n'
output_string += '# For example, if the origin is equal to 0., 0., 0., use the following: origin box: 0., 0., 0.\n'
output_string += '# For example, if the origin is equal to 0., 0., 0., use '
output_string += 'the following: origin box: 0., 0., 0.\n'

output_string += 'box origin x: ' + str(self.origin_box[0]) + '\n'
output_string += 'box origin y: ' + str(self.origin_box[1]) + '\n'
output_string += 'box origin z: ' + str(self.origin_box[2]) + '\n'

output_string += '\n# rotation angle indicates the rotation angle around the x, y, and z axis of the FFD bounding box in degrees.\n'
output_string += '\n# rotation angle indicates the rotation angle '
output_string += 'around the x, y, and z axis of the FFD bounding box in degrees.\n'

output_string += '# The rotation is done with respect to the box origin.\n'
output_string += '# For example, to rotate the box by 2 deg along the z direction, use the following: rotation angle: 0., 0., 2.\n'
output_string += '# For example, to rotate the box by 2 deg along the z '
output_string += 'direction, use the following: rotation angle: 0., 0., 2.\n'

output_string += 'rotation angle x: ' + str(self.rot_angle[0]) + '\n'
output_string += 'rotation angle y: ' + str(self.rot_angle[1]) + '\n'
output_string += 'rotation angle z: ' + str(self.rot_angle[2]) + '\n'

output_string += '\n\n[Parameters weights]\n'
output_string += '# This section describes the weights of the FFD control points.\n'
output_string += '# This section describes the weights of the FFD '
output_string += 'control points.\n'

output_string += '# We adopt the following convention:\n'
output_string += '# For example with a 2x2x2 grid of control points we have to fill a 2x2x2 matrix of weights.\n'
output_string += '# If a weight is equal to zero you can discard the line since the default is zero.\n'
output_string += '# For example with a 2x2x2 grid of control points we '
output_string += 'have to fill a 2x2x2 matrix of weights.\n'

output_string += '# If a weight is equal to zero you can discard the line '
output_string += 'since the default is zero.\n'

output_string += '#\n'
output_string += '# | x index | y index | z index | weight |\n'
output_string += '# --------------------------------------\n'
output_string += '# | 0 | 0 | 0 | 1.0 |\n'
output_string += '# | 0 | 1 | 1 | 0.0 | --> you can erase this line without effects\n'
output_string += '# | 0 | 1 | 1 | 0.0 | --> you '
output_string += 'can erase this line without effects\n'
output_string += '# | 0 | 1 | 0 | -2.1 |\n'
output_string += '# | 0 | 0 | 1 | 3.4 |\n'

output_string += '\n# parameter x collects the displacements along x, normalized with the box lenght x.'
output_string += '\n# parameter x collects the displacements along x, '
output_string += 'normalized with the box lenght x.'

output_string += '\nparameter x:'
offset = 1
for i in range(0, self.n_control_points[0]):
for j in range(0, self.n_control_points[1]):
for k in range(0, self.n_control_points[2]):
output_string += offset * ' ' + str(i) + ' ' + str(j) + ' ' + str(k) + \
' ' + str(self.array_mu_x[i][j][k]) + '\n'
output_string += offset * ' ' + str(i) + ' ' + str(
j) + ' ' + str(k) + ' ' + str(
self.array_mu_x[i][j][k]) + '\n'
offset = 13

output_string += '\n# parameter y collects the displacements along y, normalized with the box lenght y.'
output_string += '\n# parameter y collects the displacements along y, '
output_string += 'normalized with the box lenght y.'

output_string += '\nparameter y:'
offset = 1
for i in range(0, self.n_control_points[0]):
for j in range(0, self.n_control_points[1]):
for k in range(0, self.n_control_points[2]):
output_string += offset * ' ' + str(i) + ' ' + str(j) + ' ' + str(k) + \
' ' + str(self.array_mu_y[i][j][k]) + '\n'
output_string += offset * ' ' + str(i) + ' ' + str(
j) + ' ' + str(k) + ' ' + str(
self.array_mu_y[i][j][k]) + '\n'
offset = 13

output_string += '\n# parameter z collects the displacements along z, normalized with the box lenght z.'
output_string += '\n# parameter z collects the displacements along z, '
output_string += 'normalized with the box lenght z.'

output_string += '\nparameter z:'
offset = 1
for i in range(0, self.n_control_points[0]):
for j in range(0, self.n_control_points[1]):
for k in range(0, self.n_control_points[2]):
output_string += offset * ' ' + str(i) + ' ' + str(j) + ' ' + str(k) + \
' ' + str(self.array_mu_z[i][j][k]) + '\n'
output_string += offset * ' ' + str(i) + ' ' + str(
j) + ' ' + str(k) + ' ' + str(
self.array_mu_z[i][j][k]) + '\n'
offset = 13

with open(filename, 'w') as f:
Expand Down
6 changes: 5 additions & 1 deletion pygem/params/idwparams.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import numpy as np
"""
Utilities for reading and writing parameters files to perform IDW
geometrical morphing.
"""
import os
import numpy as np
try:
import configparser as configparser
except ImportError:
Expand Down
Loading