From f608efb5214d35d8841c70cdcedc49a873edc809 Mon Sep 17 00:00:00 2001 From: Marco Tezzele Date: Mon, 26 Mar 2018 13:44:13 +0200 Subject: [PATCH] Code formatter script also in submodules and minor fixes --- bladex/ndinterpolator.py | 9 ++++++--- bladex/profilebase.py | 29 +++++++++++++---------------- bladex/profiles.py | 37 +++++++++++++++++++++++++------------ code_formatter.sh | 2 +- 4 files changed, 45 insertions(+), 32 deletions(-) diff --git a/bladex/ndinterpolator.py b/bladex/ndinterpolator.py index e96dd4f..ad6702f 100644 --- a/bladex/ndinterpolator.py +++ b/bladex/ndinterpolator.py @@ -69,13 +69,16 @@ def __init__(self, radius, basis): self.radius = radius self.bases = { - 'gaussian_spline': self.gaussian_spline, + 'gaussian_spline': + self.gaussian_spline, 'multi_quadratic_biharmonic_spline': self.multi_quadratic_biharmonic_spline, 'inv_multi_quadratic_biharmonic_spline': self.inv_multi_quadratic_biharmonic_spline, - 'thin_plate_spline': self.thin_plate_spline, - 'beckert_wendland_c2_basis': self.beckert_wendland_c2_basis + 'thin_plate_spline': + self.thin_plate_spline, + 'beckert_wendland_c2_basis': + self.beckert_wendland_c2_basis } if basis in self.bases: diff --git a/bladex/profilebase.py b/bladex/profilebase.py index fb0eecc..ec2f2e3 100644 --- a/bladex/profilebase.py +++ b/bladex/profilebase.py @@ -105,7 +105,7 @@ def interpolate_coordinates(self, num=500, radius=1.0): positive """ if not isinstance(num, int): - raise TypeError('inserted value must be of type integer.') + raise TypeError('Inserted value must be of type integer.') if num <= 0 or radius <= 0: raise ValueError('Inserted value must be positive.') @@ -143,10 +143,10 @@ def compute_chord_line(self, interpolate=False, n_interpolated_points=500): :param bool interpolate: if True, then the coordinates are computed at equally spaced intervals within the range of LE and TE. Default - value is False + value is False. :param int n_interpolated_points: number of points to be used for the equally-spaced sample computations, and is used only if parameter - interpolate is True. Default value is 500 + interpolate is True. Default value is 500. """ self._update_edges() aratio = ((self.trailing_edge[1] - self.leading_edge[1]) / @@ -182,12 +182,12 @@ def compute_camber_line(self, interpolate=False, n_interpolated_points=500): coordinates are used. Default value is False. :param int n_interpolated_points: number of points to be used for the uniform interpolation, and is used only if parameter interpolate - is True. Default value is 500 + is True. Default value is 500. We note that a uniform interpolation becomes necessary for the cases when the X-coordinates of the upper and lower surfaces do not correspond to the same vertical sections, since this would imply - inaccurate measurements for obtaining the camberline. + inaccurate measurements for obtaining the camber line. """ if (interpolate is True) or ( (self.xup_coordinates == self.xdown_coordinates).all() is False): @@ -227,15 +227,14 @@ def deform_camber_line(self, airfoil coordinates, hence any measurements or scalings will be inaccurate for the foils not in their reference position. - :param float max_camber_change_percent: percentage of change of the + :param float percent_change: percentage of change of the maximum camber. Default value is None :param bool interpolate: if True, the interpolated coordinates are used to compute the camber line and foil's thickness, otherwise the original discrete coordinates are used. Default value is False. - :param n_interpolated_points: number of points to be used for the + :param int n_interpolated_points: number of points to be used for the uniform interpolation, and is used only if parameter interpolate - is True. Default value is 500 - :raises ValueError: if max_camber_change_percent is None + is True. Default value is 500. """ # Updating camber line self.compute_camber_line( @@ -253,7 +252,7 @@ def deform_camber_line(self, # is required. (self.xup_coordinates, self.xdown_coordinates, self.yup_coordinates, self.ydown_coordinates - ) = self.interpolate_coordinates(num=n_interpolated_points) + ) = self.interpolate_coordinates(num=n_interpolated_points) half_thickness = 0.5 * np.fabs( self.yup_coordinates - self.ydown_coordinates) @@ -281,7 +280,7 @@ def chord_length(self): """ Measure the l2-norm (Euclidean distance) between the leading edge and the trailing edge. - + :return: chord length :rtype: float """ @@ -361,13 +360,11 @@ def get_max_camber(self, interpolate=False, n_interpolated_points=500): camber[i] = np.linalg.norm( self.chord_line[:, i] - self.camber_line[:, i]) - if (self.camber_line[1][camber.argmax()] > + max_camber = camber.max() + if (self.camber_line[1][camber.argmax()] < self.chord_line[1][camber.argmax()]): - # Camber line is above the chord line, at the point of max camber - max_camber = camber.max() - else: # Camber line is below the chord line, at the point of max camber - max_camber = camber.max() * -1 + max_camber *= -1 return max_camber diff --git a/bladex/profiles.py b/bladex/profiles.py index cfd137f..b1bcf40 100644 --- a/bladex/profiles.py +++ b/bladex/profiles.py @@ -41,7 +41,8 @@ def _check_coordinates(self): self.ydown_coordinates, dtype=float) if self.xup_coordinates.shape != self.yup_coordinates.shape or self.xdown_coordinates.shape != self.ydown_coordinates.shape: raise ValueError( - 'Arrays {xup_coordinates, yup_coordinates} or {xdown_coordinates, ydown_coordinates} do not have the same shape.') + 'Arrays {xup_coordinates, yup_coordinates} or {xdown_coordinates, ydown_coordinates} do not have the same shape.' + ) if not all( np.greater_equal(self.yup_coordinates, self.ydown_coordinates)): @@ -54,7 +55,8 @@ def _check_coordinates(self): not self.xdown_coordinates[-1] == self.xup_coordinates[-1]) or ( not self.ydown_coordinates[0] == self.yup_coordinates[0]): raise ValueError( - 'One of the following conditions is not satisfied: (xdown_coordinates[0]=xup_coordinates[0]) or (xdown_coordinates[-1]=xup_coordinates[-1]) or (ydown_coordinates[0]=yup_coordinates[0])') + 'One of the following conditions is not satisfied: (xdown_coordinates[0]=xup_coordinates[0]) or (xdown_coordinates[-1]=xup_coordinates[-1]) or (ydown_coordinates[0]=yup_coordinates[0])' + ) class NacaProfile(ProfileBase): @@ -139,8 +141,10 @@ def _generate_coordinates(self): x = np.linspace(0.0, 1.0, num=self.n_points + 1) - yt = [5 * t * (a0 * sqrt(xx) + a1 * xx + a2 * pow(xx, 2) + a3 * pow( - xx, 3) + a4 * pow(xx, 4)) for xx in x] + yt = [ + 5 * t * (a0 * sqrt(xx) + a1 * xx + a2 * pow(xx, 2) + + a3 * pow(xx, 3) + a4 * pow(xx, 4)) for xx in x + ] if p == 0: xu = np.linspace(0.0, 1.0, num=self.n_points + 1) @@ -151,8 +155,10 @@ def _generate_coordinates(self): xc1 = [xx for xx in x if xx <= p] xc2 = [xx for xx in x if xx > p] yc1 = [m / pow(p, 2) * xx * (2 * p - xx) for xx in xc1] - yc2 = [m / pow(1 - p, 2) * (1 - 2 * p + xx) * (1 - xx) - for xx in xc2] + yc2 = [ + m / pow(1 - p, 2) * (1 - 2 * p + xx) * (1 - xx) + for xx in xc2 + ] zc = yc1 + yc2 dyc1_dx = [m / pow(p, 2) * (2 * p - 2 * xx) for xx in xc1] @@ -190,8 +196,10 @@ def _generate_coordinates(self): x = np.linspace(0.0, 1.0, num=self.n_points + 1) - yt = [5 * t * (a0 * sqrt(xx) + a1 * xx + a2 * pow(xx, 2) + a3 * pow( - xx, 3) + a4 * pow(xx, 4)) for xx in x] + yt = [ + 5 * t * (a0 * sqrt(xx) + a1 * xx + a2 * pow(xx, 2) + + a3 * pow(xx, 3) + a4 * pow(xx, 4)) for xx in x + ] P = [0.05, 0.1, 0.15, 0.2, 0.25] M = [0.0580, 0.1260, 0.2025, 0.2900, 0.3910] @@ -207,13 +215,18 @@ def _generate_coordinates(self): k1 = self._cubic_spline_interpolation(M, K, [m]) xc1 = [xx for xx in x if xx <= p] xc2 = [xx for xx in x if xx > p] - yc1 = [k1 / 6.0 * (pow(xx, 3) - 3 * m * pow(xx, 2) + pow(m, 2) * - (3 - m) * xx) for xx in xc1] + yc1 = [ + k1 / 6.0 * (pow(xx, 3) - 3 * m * pow(xx, 2) + pow(m, 2) * + (3 - m) * xx) for xx in xc1 + ] yc2 = [k1 / 6.0 * pow(m, 3) * (1 - xx) for xx in xc2] zc = [cld / 0.3 * xx for xx in yc1 + yc2] - dyc1_dx = [cld / 0.3 * (1.0 / 6.0) * k1 * (3 * pow( - xx, 2) - 6 * m * xx + pow(m, 2) * (3 - m)) for xx in xc1] + dyc1_dx = [ + cld / 0.3 * (1.0 / 6.0) * k1 * + (3 * pow(xx, 2) - 6 * m * xx + pow(m, 2) * (3 - m)) + for xx in xc1 + ] dyc2_dx = [cld / 0.3 * (1.0 / 6.0) * k1 * pow(m, 3)] * len(xc2) dyc_dx = dyc1_dx + dyc2_dx diff --git a/code_formatter.sh b/code_formatter.sh index d1b32a5..588c039 100755 --- a/code_formatter.sh +++ b/code_formatter.sh @@ -34,7 +34,7 @@ done # Find all python files in code directories python_files="" for dir in $code_directories; do - python_files="$python_files `ls $dir/*.py`" + python_files="$python_files $(find $dir -name '*.py')" done [[ $# != 0 ]] && python_files=$@