From c1e80532a198476af2e4d9d516a40c2789ee0968 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Jab=C3=B3n?= Date: Fri, 4 Nov 2022 10:44:43 +0100 Subject: [PATCH] UPDATED FFD.PY FILE WITH ROTATION MATRIX AS INPUT This new file allows the user to directly introduce the rotation matrix as input. The attribute rot_mode is created in order to create the rotation matrix through rotation angles (0-value) or to directly introduce the matrix (1-value) --- pygem/ffd.py | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/pygem/ffd.py b/pygem/ffd.py index ab98870..13d57c9 100644 --- a/pygem/ffd.py +++ b/pygem/ffd.py @@ -93,7 +93,9 @@ def __init__(self, n_control_points=None): self.box_length = np.array([1., 1., 1.]) self.box_origin = np.array([0., 0., 0.]) + self.rot_mode = 0 self.rot_angle = np.array([0., 0., 0.]) + self.rot_matrix = np.eye(3) self.array_mu_x = None self.array_mu_y = None @@ -206,15 +208,23 @@ def T_mapping(points): @property def rotation_matrix(self): - """ - The rotation matrix (according to rot_angle_x, rot_angle_y, - rot_angle_z). - - :rtype: numpy.ndarray - """ - return angles2matrix(np.radians(self.rot_angle[2]), - np.radians(self.rot_angle[1]), - np.radians(self.rot_angle[0])) + if self.rot_mode == 0: + """ + The rotation matrix (according to rot_angle_x, rot_angle_y, + rot_angle_z). + + :rtype: numpy.ndarray + """ + return angles2matrix(np.radians(self.rot_angle[2]), + np.radians(self.rot_angle[1]), + np.radians(self.rot_angle[0])) + else: + """ + The rotation matrix as input + + :rtype: numpy.ndarray + """ + return self.rot_matrix @property def position_vertices(self): @@ -269,6 +279,7 @@ def read_parameters(self, filename='parameters.prm'): self.box_origin[1] = config.getfloat('Box info', 'box origin y') self.box_origin[2] = config.getfloat('Box info', 'box origin z') + self.rot_mode = config.getfloat('Box info', 'rotation mode') self.rot_angle[0] = config.getfloat('Box info', 'rotation angle x') self.rot_angle[1] = config.getfloat('Box info', 'rotation angle y') self.rot_angle[2] = config.getfloat('Box info', 'rotation angle z') @@ -358,6 +369,8 @@ def write_parameters(self, filename='parameters.prm'): output_string += 'direction, use the following: rotation angle: ' output_string += '0., 0., 2.\n' + output_string += 'rotation mode: ' + str(self.rot_mode) + '\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' @@ -434,6 +447,7 @@ def __str__(self): string += 'n_control_points = {}\n\n'.format(self.n_control_points) string += 'box_length = {}\n'.format(self.box_length) string += 'box_origin = {}\n'.format(self.box_origin) + string += 'rot_mode = {}\n'.format(self.rot_mode) string += 'rot_angle = {}\n'.format(self.rot_angle) string += '\narray_mu_x =\n{}\n'.format(self.array_mu_x) string += '\narray_mu_y =\n{}\n'.format(self.array_mu_y)