def local_thickness(self, x_over_c=np.linspace(0, 1, 101)): """ Returns the local thickness of the airfoil at a given point or points. :param x_over_c: The x/c locations to calculate the thickness at [1D array, more generally, an iterable of floats] :return: Local thickness of the airfoil (y/c) [1D array]. """ # TODO casadify? upper = self.upper_coordinates()[::-1] lower = self.lower_coordinates() upper_interpolated = np.interp( x_over_c, upper[:, 0], upper[:, 1], ) lower_interpolated = np.interp( x_over_c, lower[:, 0], lower[:, 1], ) return upper_interpolated - lower_interpolated
def local_camber( self, x_over_c: Union[float, np.ndarray] = np.linspace(0, 1, 101) ) -> Union[float, np.ndarray]: """ Returns the local camber of the airfoil at a given point or points. :param x_over_c: The x/c locations to calculate the camber at [1D array, more generally, an iterable of floats] :return: Local camber of the airfoil (y/c) [1D array]. """ upper = self.upper_coordinates()[::-1] lower = self.lower_coordinates() upper_interpolated = np.interp( x_over_c, upper[:, 0], upper[:, 1], ) lower_interpolated = np.interp( x_over_c, lower[:, 0], lower[:, 1], ) return (upper_interpolated + lower_interpolated) / 2
def test_interp(): x_np = np.arange(5) y_np = x_np + 10 for x, y in zip( [x_np, x_np], [y_np, cas.DM(y_np)] ): assert np.interp(0, x, y) == pytest.approx(10) assert np.interp(4, x, y) == pytest.approx(14) assert np.interp(0.5, x, y) == pytest.approx(10.5) assert np.interp(-1, x, y) == pytest.approx(10) assert np.interp(5, x, y) == pytest.approx(14) assert np.interp(-1, x, y, left=-10) == pytest.approx(-10) assert np.interp(5, x, y, right=-10) == pytest.approx(-10) assert np.interp(5, x, y, period=4) == pytest.approx(11)