diff --git a/aerosandbox/aerodynamics/aero_2D/airfoil_inviscid.py b/aerosandbox/aerodynamics/aero_2D/airfoil_inviscid.py index 7b547d6c..024f954c 100644 --- a/aerosandbox/aerodynamics/aero_2D/airfoil_inviscid.py +++ b/aerosandbox/aerodynamics/aero_2D/airfoil_inviscid.py @@ -219,7 +219,7 @@ def draw_streamlines(self, res=200, show=True): V[contains] = np.nan speed = (U**2 + V**2) ** 0.5 - Cp = 1 - speed**2 + # Cp = 1 - speed**2 ### Draw the airfoils for airfoil in self.airfoils: diff --git a/aerosandbox/aerodynamics/aero_3D/aero_buildup.py b/aerosandbox/aerodynamics/aero_3D/aero_buildup.py index 7ebf6400..ffc48bbc 100644 --- a/aerosandbox/aerodynamics/aero_3D/aero_buildup.py +++ b/aerosandbox/aerodynamics/aero_3D/aero_buildup.py @@ -445,7 +445,6 @@ def run_with_stability_derivatives( "r": (2 * self.op_point.velocity) / self.airplane.b_ref, } - original_op_point = self.op_point # Compute the point analysis, which returns a dictionary that we will later add key:value pairs to. run_base = self.run() diff --git a/aerosandbox/aerodynamics/aero_3D/lifting_line.py b/aerosandbox/aerodynamics/aero_3D/lifting_line.py index 4a257d32..948c6994 100644 --- a/aerosandbox/aerodynamics/aero_3D/lifting_line.py +++ b/aerosandbox/aerodynamics/aero_3D/lifting_line.py @@ -448,7 +448,6 @@ def run_with_stability_derivatives( "r": (2 * self.op_point.velocity) / self.airplane.b_ref, } - original_op_point = self.op_point # Compute the point analysis, which returns a dictionary that we will later add key:value pairs to. run_base = self.run() diff --git a/aerosandbox/atmosphere/thermodynamics/gas.py b/aerosandbox/atmosphere/thermodynamics/gas.py index 821c86a4..ff509818 100644 --- a/aerosandbox/atmosphere/thermodynamics/gas.py +++ b/aerosandbox/atmosphere/thermodynamics/gas.py @@ -51,7 +51,8 @@ def __init__( self.effective_collision_diameter = effective_collision_diameter def __repr__(self) -> str: - f = lambda s, u: eng_string(s, unit=u, format="%.6g") + def f(val, unit): + return eng_string(val, unit=unit, format="%.6g") return f"Gas (P = {f(self.pressure, 'Pa')}, T = {self.temperature:.6g} K, ρ = {self.density:.6g} kg/m^3, Pv^gamma = {self.pressure * self.specific_volume ** self.ratio_of_specific_heats: .6g})" diff --git a/aerosandbox/geometry/polygon.py b/aerosandbox/geometry/polygon.py index a29575a0..1719c1dd 100644 --- a/aerosandbox/geometry/polygon.py +++ b/aerosandbox/geometry/polygon.py @@ -255,9 +255,9 @@ def J(self): A = 0.5 * np.sum(a) # area + # Centroid location x_c = 1 / (6 * A) * np.sum(a * (x + x_n)) y_c = 1 / (6 * A) * np.sum(a * (y + y_n)) - centroid = np.array([x_c, y_c]) Ixx = 1 / 12 * np.sum(a * (y**2 + y * y_n + y_n**2)) diff --git a/aerosandbox/geometry/test_geometry/test_airfoil.py b/aerosandbox/geometry/test_geometry/test_airfoil.py index d1ad8557..f5853208 100644 --- a/aerosandbox/geometry/test_geometry/test_airfoil.py +++ b/aerosandbox/geometry/test_geometry/test_airfoil.py @@ -44,7 +44,7 @@ def test_repanel(naca4412): def test_containts_points(naca4412): - assert naca4412.contains_points(x=0.5, y=0) == True + assert naca4412.contains_points(x=0.5, y=0) assert np.all( naca4412.contains_points(x=np.array([0.5, 0.5]), y=np.array([0, -0.1])) == np.array([True, False]) diff --git a/aerosandbox/geometry/test_geometry/test_polygon.py b/aerosandbox/geometry/test_geometry/test_polygon.py index b3aa7892..ab89c8a9 100644 --- a/aerosandbox/geometry/test_geometry/test_polygon.py +++ b/aerosandbox/geometry/test_geometry/test_polygon.py @@ -13,14 +13,14 @@ def test_polygon_creation(): def test_contains_points(): p = Polygon(coordinates=np.array([[0, 0], [1, 0], [1, 1], [0, 1]])) - assert p.contains_points(0.5, 0.5) == True - assert p.contains_points(-0.1, 0.5) == False - assert p.contains_points(0.5, -0.1) == False - assert p.contains_points(-0.1, -0.1) == False - assert p.contains_points(1.1, 1.1) == False - assert p.contains_points(1.0, 1.0) == True - assert p.contains_points(0.5, 1.0) == True - assert p.contains_points(0.5, 1.1) == False + assert p.contains_points(0.5, 0.5) + assert not p.contains_points(-0.1, 0.5) + assert not p.contains_points(0.5, -0.1) + assert not p.contains_points(-0.1, -0.1) + assert not p.contains_points(1.1, 1.1) + assert p.contains_points(1.0, 1.0) + assert p.contains_points(0.5, 1.0) + assert not p.contains_points(0.5, 1.1) assert np.all( p.contains_points( diff --git a/aerosandbox/geometry/test_geometry/test_wingxsec.py b/aerosandbox/geometry/test_geometry/test_wingxsec.py index a0ec2fe1..7222bf81 100644 --- a/aerosandbox/geometry/test_geometry/test_wingxsec.py +++ b/aerosandbox/geometry/test_geometry/test_wingxsec.py @@ -3,7 +3,7 @@ def test_init(): # TODO actually test this - xsec = WingXSec( + WingXSec( xyz_le=np.array([0, 0, 0]), chord=1.0, twist=0, diff --git a/aerosandbox/library/aerodynamics/transonic.py b/aerosandbox/library/aerodynamics/transonic.py index 9998b5bb..a1aca140 100644 --- a/aerosandbox/library/aerodynamics/transonic.py +++ b/aerosandbox/library/aerodynamics/transonic.py @@ -177,11 +177,8 @@ def approximate_CD_wave( if __name__ == "__main__": mc = 0.6 - drag = lambda mach: approximate_CD_wave( - mach, - mach_crit=mc, - CD_wave_at_fully_supersonic=1, - ) + def drag(mach): + return approximate_CD_wave(mach, mach_crit=mc, CD_wave_at_fully_supersonic=1) import matplotlib.pyplot as plt import aerosandbox.tools.pretty_plots as p diff --git a/aerosandbox/library/power_nuclear_rtg.py b/aerosandbox/library/power_nuclear_rtg.py index c6a4d5f9..0b5910d0 100644 --- a/aerosandbox/library/power_nuclear_rtg.py +++ b/aerosandbox/library/power_nuclear_rtg.py @@ -38,11 +38,11 @@ def po210_specific_power( days_after_formation=0, ): - half_life = 138.376 # days # Source: https://en.wikipedia.org/wiki/Polonium-210 - pure_specific_energy = ( + ( (po_210_mass_amu - alpha_particle_mass_amu - pb_206_mass_amu) * c**2 / po_210_mass_amu ) # J/kg # TODO finish + raise NotImplementedError() diff --git a/aerosandbox/library/weights/torenbeek_weights.py b/aerosandbox/library/weights/torenbeek_weights.py index c944a5a7..6345aaa0 100644 --- a/aerosandbox/library/weights/torenbeek_weights.py +++ b/aerosandbox/library/weights/torenbeek_weights.py @@ -420,7 +420,7 @@ def mass_fuselage( # Torenbeek Eq. D-3 fuselage.fineness_ratio() - fuselage_quasi_slenderness_ratio = fuselage.fineness_ratio( + fuselage.fineness_ratio( assumed_shape="sears_haack" ) @@ -428,7 +428,9 @@ def mass_fuselage( W_sk = 0.05428 * k_lambda * S_g**1.07 * never_exceed_airspeed**0.743 - W_g = W_sk + W_str + W_fr + W_sk + W_str + W_fr + + raise NotImplementedError() def mass_propeller( diff --git a/aerosandbox/library/winds.py b/aerosandbox/library/winds.py index efa928d2..395c9f95 100644 --- a/aerosandbox/library/winds.py +++ b/aerosandbox/library/winds.py @@ -223,10 +223,10 @@ def plot_winds_at_altitude(altitude=18000): levels = np.arange(0, 80.1, 5) CS = plt.contour(*args, levels=levels, linewidths=0.5, colors="k", alpha=0.7) - CF = plt.contourf( + plt.contourf( *args, levels=levels, cmap="viridis_r", alpha=0.7, extend="max" ) - cbar = plt.colorbar(label="Wind Speed [m/s]", extendrect=True) + plt.colorbar(label="Wind Speed [m/s]", extendrect=True) ax.clabel(CS, inline=1, fontsize=9, fmt="%.0f m/s") plt.xticks( @@ -280,10 +280,10 @@ def plot_winds_at_day(day_of_year=0): levels = np.arange(0, 80.1, 5) CS = plt.contour(*args, levels=levels, linewidths=0.5, colors="k", alpha=0.7) - CF = plt.contourf( + plt.contourf( *args, levels=levels, cmap="viridis_r", alpha=0.7, extend="max" ) - cbar = plt.colorbar(label="Wind Speed [m/s]", extendrect=True) + plt.colorbar(label="Wind Speed [m/s]", extendrect=True) ax.clabel(CS, inline=1, fontsize=9, fmt="%.0f m/s") lat_label_vals = np.arange(-80, 80.1, 20) @@ -316,10 +316,10 @@ def plot_tropopause_altitude(): levels = np.arange(10, 20.1, 1) CS = plt.contour(*args, levels=levels, linewidths=0.5, colors="k", alpha=0.7) - CF = plt.contourf( + plt.contourf( *args, levels=levels, cmap="viridis_r", alpha=0.7, extend="both" ) - cbar = plt.colorbar(label="Tropopause Altitude [km]", extendrect=True) + plt.colorbar(label="Tropopause Altitude [km]", extendrect=True) ax.clabel(CS, inline=1, fontsize=9, fmt="%.0f km") plt.xticks( @@ -373,10 +373,10 @@ def plot_winds_at_tropopause_altitude(): levels = np.arange(0, 80.1, 5) CS = plt.contour(*args, levels=levels, linewidths=0.5, colors="k", alpha=0.7) - CF = plt.contourf( + plt.contourf( *args, levels=levels, cmap="viridis_r", alpha=0.7, extend="max" ) - cbar = plt.colorbar(label="Wind Speed [m/s]", extendrect=True) + plt.colorbar(label="Wind Speed [m/s]", extendrect=True) ax.clabel(CS, inline=1, fontsize=9, fmt="%.0f m/s") plt.xticks( diff --git a/aerosandbox/modeling/fitting.py b/aerosandbox/modeling/fitting.py index 17c775e2..1f22bd03 100644 --- a/aerosandbox/modeling/fitting.py +++ b/aerosandbox/modeling/fitting.py @@ -143,13 +143,11 @@ def flatten(input): return np.array(input).flatten() try: - x_data = {k: flatten(v) for k, v in x_data.items()} - x_data_is_dict = True + x_data = {k: flatten(v) for k, v in x_data.items()} # type: dict except ( AttributeError ): # If it's not a dict or dict-like, assume it's a 1D ndarray dataset - x_data = flatten(x_data) - x_data_is_dict = False + x_data = flatten(x_data) # type: np.ndarray y_data = flatten(y_data) n_datapoints = np.length(y_data) diff --git a/aerosandbox/modeling/surrogate_model.py b/aerosandbox/modeling/surrogate_model.py index 834acec6..89933504 100644 --- a/aerosandbox/modeling/surrogate_model.py +++ b/aerosandbox/modeling/surrogate_model.py @@ -137,7 +137,7 @@ def axis_range(x_data_axis: np.ndarray) -> Tuple[float, float]: y_fit = self(x_fit) ### Plot the 2D figure - fig = plt.figure(dpi=200) + plt.figure(dpi=200) plt.plot( x_data, self.y_data, diff --git a/aerosandbox/numpy/surrogate_model_tools.py b/aerosandbox/numpy/surrogate_model_tools.py index c94a2341..039501d7 100644 --- a/aerosandbox/numpy/surrogate_model_tools.py +++ b/aerosandbox/numpy/surrogate_model_tools.py @@ -280,7 +280,8 @@ def blend( on the value of the 'switch' parameter. """ - blend_function = lambda x: sigmoid(x, normalization_range=(0, 1)) + def blend_function(x): + return sigmoid(x, normalization_range=(0, 1)) weight_to_value_switch_high = blend_function(switch) blend_value = value_switch_high * weight_to_value_switch_high + value_switch_low * ( diff --git a/aerosandbox/numpy/test_numpy/test_determine_type.py b/aerosandbox/numpy/test_numpy/test_determine_type.py index cc9a7845..c53a52cc 100644 --- a/aerosandbox/numpy/test_numpy/test_determine_type.py +++ b/aerosandbox/numpy/test_numpy/test_determine_type.py @@ -5,60 +5,59 @@ def test_int(): - assert is_casadi_type(5, recursive=True) == False - assert is_casadi_type(5, recursive=False) == False + assert not is_casadi_type(5, recursive=True) + assert not is_casadi_type(5, recursive=False) def test_float(): - assert is_casadi_type(5.0, recursive=True) == False - assert is_casadi_type(5.0, recursive=False) == False + assert not is_casadi_type(5.0, recursive=True) + assert not is_casadi_type(5.0, recursive=False) def test_numpy(): - assert is_casadi_type(np.array([1, 2, 3]), recursive=True) == False - assert is_casadi_type(np.array([1, 2, 3]), recursive=False) == False + assert not is_casadi_type(np.array([1, 2, 3]), recursive=True) + assert not is_casadi_type(np.array([1, 2, 3]), recursive=False) def test_casadi(): - assert is_casadi_type(cas.MX(np.ones(5)), recursive=False) == True - assert is_casadi_type(cas.MX(np.ones(5)), recursive=True) == True + assert is_casadi_type(cas.MX(np.ones(5)), recursive=False) + assert is_casadi_type(cas.MX(np.ones(5)), recursive=True) def test_numpy_list(): - assert is_casadi_type([np.array(5), np.array(7)], recursive=False) == False - assert is_casadi_type([np.array(5), np.array(7)], recursive=True) == False + assert not is_casadi_type([np.array(5), np.array(7)], recursive=False) + assert not is_casadi_type([np.array(5), np.array(7)], recursive=True) def test_casadi_list(): - assert ( + assert not ( is_casadi_type([cas.MX(np.ones(5)), cas.MX(np.ones(5))], recursive=False) - == False ) assert ( - is_casadi_type([cas.MX(np.ones(5)), cas.MX(np.ones(5))], recursive=True) == True + is_casadi_type([cas.MX(np.ones(5)), cas.MX(np.ones(5))], recursive=True) ) def test_mixed_list(): - assert is_casadi_type([np.array(5), cas.MX(np.ones(5))], recursive=False) == False - assert is_casadi_type([np.array(5), cas.MX(np.ones(5))], recursive=True) == True + assert not is_casadi_type([np.array(5), cas.MX(np.ones(5))], recursive=False) + assert is_casadi_type([np.array(5), cas.MX(np.ones(5))], recursive=True) def test_multi_level_contaminated_list(): a = [[1 for _ in range(10)] for _ in range(10)] - assert is_casadi_type(a, recursive=False) == False - assert is_casadi_type(a, recursive=True) == False + assert not is_casadi_type(a, recursive=False) + assert not is_casadi_type(a, recursive=True) a[5][5] = cas.MX(1) - assert is_casadi_type(a, recursive=False) == False - assert is_casadi_type(a, recursive=True) == True + assert not is_casadi_type(a, recursive=False) + assert is_casadi_type(a, recursive=True) a[5][5] = np.array(cas.DM(1), dtype="O") - assert is_casadi_type(a, recursive=False) == False - assert is_casadi_type(a, recursive=True) == False + assert not is_casadi_type(a, recursive=False) + assert not is_casadi_type(a, recursive=True) if __name__ == "__main__": diff --git a/aerosandbox/numpy/test_numpy/test_interpolate.py b/aerosandbox/numpy/test_numpy/test_interpolate.py index b0f3315d..e9d31365 100644 --- a/aerosandbox/numpy/test_numpy/test_interpolate.py +++ b/aerosandbox/numpy/test_numpy/test_interpolate.py @@ -105,12 +105,12 @@ def value_func_3d(x, y, z): point = np.array([5.21, 3.12, 1.15]) with pytest.raises(ValueError): - value = np.interpn(points, values, point) + np.interpn(points, values, point) ### CasADi test point = cas.DM(point) with pytest.raises(ValueError): - value = np.interpn(points, values, point) + np.interpn(points, values, point) def test_interpn_bounds_error_multiple_samples(): @@ -125,12 +125,12 @@ def value_func_3d(x, y, z): point = np.array([[2.21, 3.12, 1.15], [3.42, 5.81, 2.43]]) with pytest.raises(ValueError): - value = np.interpn(points, values, point) + np.interpn(points, values, point) ### CasADi test point = cas.DM(point) with pytest.raises(ValueError): - value = np.interpn(points, values, point) + np.interpn(points, values, point) def test_interpn_fill_value(): diff --git a/aerosandbox/optimization/test_optimization/test_opti_analytical_wing_drag_minimization.py b/aerosandbox/optimization/test_optimization/test_opti_analytical_wing_drag_minimization.py index c7bb0622..675e12d3 100644 --- a/aerosandbox/optimization/test_optimization/test_opti_analytical_wing_drag_minimization.py +++ b/aerosandbox/optimization/test_optimization/test_opti_analytical_wing_drag_minimization.py @@ -62,7 +62,7 @@ def test_log_transformed_negativity_error(): opti = asb.Opti() with pytest.raises(ValueError): - myvar = opti.variable(log_transform=True, init_guess=-1) + opti.variable(log_transform=True, init_guess=-1) def test_fixed_variable(): diff --git a/aerosandbox/structures/buckling.py b/aerosandbox/structures/buckling.py index a5831f1b..19202e36 100644 --- a/aerosandbox/structures/buckling.py +++ b/aerosandbox/structures/buckling.py @@ -114,7 +114,7 @@ def thin_walled_tube_crippling_buckling_critical_load( # Following the Air Force Stress Manual, Section 2.3.2.1, Eq. 2-20. # The above value assumes mu = 0.3, which is a good assumption for most metals. - crippling_stress = 0.3 * (elastic_modulus * wall_thickness / radius) + crippling_stress = crippling_stress_constant * (elastic_modulus * wall_thickness / radius) tube_xsec_area = 2 * np.pi * radius * wall_thickness diff --git a/aerosandbox/tools/statistics/time_series_uncertainty_quantification.py b/aerosandbox/tools/statistics/time_series_uncertainty_quantification.py index db9ce036..1a9e530b 100644 --- a/aerosandbox/tools/statistics/time_series_uncertainty_quantification.py +++ b/aerosandbox/tools/statistics/time_series_uncertainty_quantification.py @@ -51,7 +51,8 @@ def estimate_noise_standard_deviation( ##### Noise Variance Reconstruction ##### from scipy.special import gammaln - ln_factorial = lambda x: gammaln(x + 1) + def ln_factorial(x): + return gammaln(x + 1) ### For speed, pre-compute the log-factorial of integers from 1 to estimator_order # ln_f = ln_factorial(np.arange(estimator_order + 1)) @@ -166,21 +167,26 @@ def bootstrap_fits( y_rng = y_max - y_min if normalize: - x_normalize = lambda x: (x - x_min) / x_rng - y_normalize = lambda y: (y - y_min) / y_rng + def x_normalize(x): + return (x - x_min) / x_rng + def y_normalize(y): + return (y - y_min) / y_rng # x_unnormalize = lambda x_n: x_n * x_rng + x_min - y_unnormalize = lambda y_n: y_n * y_rng + y_min + def y_unnormalize(y_n): + return y_n * y_rng + y_min - x_stdev_normalized = x_noise_stdev / x_rng + x_noise_stdev / x_rng y_stdev_normalized = y_noise_stdev / y_rng else: - x_normalize = lambda x: x - y_normalize = lambda y: y + def x_normalize(x): + return x + def y_normalize(y): + return y # x_unnormalize = lambda x_n: x_n - y_unnormalize = lambda y_n: y_n + def y_unnormalize(y_n): + return y_n - x_stdev_normalized = x_noise_stdev y_stdev_normalized = y_noise_stdev with tqdm( diff --git a/aerosandbox/visualization/carpet_plot_utils.py b/aerosandbox/visualization/carpet_plot_utils.py index a2f3615a..7791648f 100644 --- a/aerosandbox/visualization/carpet_plot_utils.py +++ b/aerosandbox/visualization/carpet_plot_utils.py @@ -67,7 +67,8 @@ def patch_nans(array): # TODO remove modification on incoming values; only patc """ original_nans = np.isnan(array) - nanfrac = lambda array: np.sum(np.isnan(array)) / len(array.flatten()) + def nanfrac(array): + return np.sum(np.isnan(array)) / len(array.flatten()) def item(i, j): if i < 0 or j < 0: # don't allow wrapping other than what's controlled here @@ -77,8 +78,10 @@ def item(i, j): except IndexError: return np.nan - print_title = lambda name: print(f"{name}\nIter | NaN Fraction") - print_progress = lambda iter: print(f"{iter:4} | {nanfrac(array):.6f}") + def print_title(name): + return print(f"{name}\nIter | NaN Fraction") + def print_progress(iter): + return print(f"{iter:4} | {nanfrac(array):.6f}") # Bridging print_title("Bridging") diff --git a/aerosandbox/weights/mass_properties.py b/aerosandbox/weights/mass_properties.py index b18e50f8..52b03445 100644 --- a/aerosandbox/weights/mass_properties.py +++ b/aerosandbox/weights/mass_properties.py @@ -647,7 +647,8 @@ def fmt(x: float) -> str: assert mp1 + mp2 - mp2 == mp1 - r = lambda: np.random.randn() + def r(): + return np.random.randn() valid = False while not valid: diff --git a/studies/CircleToAirfoilOptimization/circle_to_airfoil.py b/studies/CircleToAirfoilOptimization/circle_to_airfoil.py index ae6e4a5d..5114f26b 100644 --- a/studies/CircleToAirfoilOptimization/circle_to_airfoil.py +++ b/studies/CircleToAirfoilOptimization/circle_to_airfoil.py @@ -59,10 +59,8 @@ af.local_thickness(np.linspace(0, 1, 20)[1:-1]) > 0 ) -get_wiggliness = lambda af: sum([ - np.sum(np.diff(np.diff(array)) ** 2) - for array in [af.lower_weights, af.upper_weights] -]) +def get_wiggliness(af): + return sum([np.sum(np.diff(np.diff(array)) ** 2) for array in [af.lower_weights, af.upper_weights]]) opti.subject_to( get_wiggliness(af) < 1 diff --git a/studies/MachFitting/CriticalMach/critical_mach_plotting.py b/studies/MachFitting/CriticalMach/critical_mach_plotting.py index 2a6783c4..63ddc90f 100644 --- a/studies/MachFitting/CriticalMach/critical_mach_plotting.py +++ b/studies/MachFitting/CriticalMach/critical_mach_plotting.py @@ -2,29 +2,20 @@ gamma = 1.4 -Cp_crit = lambda M: 2 / (gamma * M ** 2) * ( - ( - (1 + (gamma - 1) / 2 * M ** 2) - / - (1 + (gamma - 1) / 2) - ) ** (gamma / (gamma - 1)) - - 1 -) +def Cp_crit(M): + return 2 / (gamma * M ** 2) * (((1 + (gamma - 1) / 2 * M ** 2) / (1 + (gamma - 1) / 2)) ** (gamma / (gamma - 1)) - 1) # Prandtl-Glauert correction -Cp_PG = lambda Cp0, M: Cp0 / (1 - M ** 2) ** 0.5 +def Cp_PG(Cp0, M): + return Cp0 / (1 - M ** 2) ** 0.5 # Karman-Tsien correction -Cp_KT = lambda Cp0, M: Cp0 / ( - (1 - M ** 2) ** 0.5 - + M ** 2 / (1 + (1 - M ** 2) ** 0.5) * (Cp0 / 2) -) +def Cp_KT(Cp0, M): + return Cp0 / ((1 - M ** 2) ** 0.5 + M ** 2 / (1 + (1 - M ** 2) ** 0.5) * (Cp0 / 2)) ### Laitone's rule -Cp_L = lambda Cp0, M: Cp0 / ( - (1 - M ** 2) ** 0.5 - + (M ** 2) * (1 + (gamma - 1) / 2 * M ** 2) / (1 + (1 - M ** 2) ** 0.5) * (Cp0 / 2) -) +def Cp_L(Cp0, M): + return Cp0 / ((1 - M ** 2) ** 0.5 + M ** 2 * (1 + (gamma - 1) / 2 * M ** 2) / (1 + (1 - M ** 2) ** 0.5) * (Cp0 / 2)) if __name__ == '__main__': import matplotlib.pyplot as plt diff --git a/studies/MachFitting/CriticalMach/generate_and_fit_critical_mach.py b/studies/MachFitting/CriticalMach/generate_and_fit_critical_mach.py index 1a042a44..e11ef0d0 100644 --- a/studies/MachFitting/CriticalMach/generate_and_fit_critical_mach.py +++ b/studies/MachFitting/CriticalMach/generate_and_fit_critical_mach.py @@ -3,29 +3,20 @@ gamma = 1.4 -Cp_crit = lambda M: 2 / (gamma * M ** 2) * ( - ( - (1 + (gamma - 1) / 2 * M ** 2) - / - (1 + (gamma - 1) / 2) - ) ** (gamma / (gamma - 1)) - - 1 -) +def Cp_crit(M): + return 2 / (gamma * M ** 2) * (((1 + (gamma - 1) / 2 * M ** 2) / (1 + (gamma - 1) / 2)) ** (gamma / (gamma - 1)) - 1) # Prandtl-Glauert correction -Cp_PG = lambda Cp0, M: Cp0 / (1 - M ** 2) ** 0.5 +def Cp_PG(Cp0, M): + return Cp0 / (1 - M ** 2) ** 0.5 # Karman-Tsien correction -Cp_KT = lambda Cp0, M: Cp0 / ( - (1 - M ** 2) ** 0.5 - + M ** 2 / (1 + (1 - M ** 2) ** 0.5) * (Cp0 / 2) -) +def Cp_KT(Cp0, M): + return Cp0 / ((1 - M ** 2) ** 0.5 + M ** 2 / (1 + (1 - M ** 2) ** 0.5) * (Cp0 / 2)) ### Laitone's rule -Cp_L = lambda Cp0, M: Cp0 / ( - (1 - M ** 2) ** 0.5 - + (M ** 2) * (1 + (gamma - 1) / 2 * M ** 2) / (1 + (1 - M ** 2) ** 0.5) * (Cp0 / 2) -) +def Cp_L(Cp0, M): + return Cp0 / ((1 - M ** 2) ** 0.5 + M ** 2 * (1 + (gamma - 1) / 2 * M ** 2) / (1 + (1 - M ** 2) ** 0.5) * (Cp0 / 2)) M = np.linspace(0.001, 0.999, 500) diff --git a/studies/SmartFitting/branchandbound.py b/studies/SmartFitting/branchandbound.py index 9584a21f..924517b6 100644 --- a/studies/SmartFitting/branchandbound.py +++ b/studies/SmartFitting/branchandbound.py @@ -52,7 +52,7 @@ def branch_and_bound(obj, lower_bound, branch, init, term, eta, guess=None): guess- guess of an upper bound, can be produced by heuristic ''' # sets the initial upper bound - if guess != None: + if guess is not None: best_value = guess(eta) else: best_value = float('inf') @@ -99,22 +99,22 @@ def lower_bound(n): opti = asb.Opti() coeffs = opti.variable(init_guess=np.zeros(degree + 1)) - n_new = np.where(n == None, 1, n) + n_new = np.where(n is None, 1, n) n_new = np.array(n_new) y_model = model(coeffs * n_new) error = loss(y_model, y_data) opti.minimize( - error + eta * np.sum(np.where(n == None, 0, n)) + error + eta * np.sum(np.where(n is None, 0, n)) ) sol = opti.solve(verbose=False) - return sol.value(error) + eta * np.sum(np.where(n == None, 0, n)) + return sol.value(error) + eta * np.sum(np.where(n is None, 0, n)) def branch(n): n1 = np.copy(n) n2 = np.copy(n) for i in range(len(n)): - if n[i] == None: + if n[i] is None: n1[i] = 0 n2[i] = 1 return n1, n2 diff --git a/studies/SmartFitting/functional_approach/functionalapproach.py b/studies/SmartFitting/functional_approach/functionalapproach.py index f1833cb5..f88836ed 100644 --- a/studies/SmartFitting/functional_approach/functionalapproach.py +++ b/studies/SmartFitting/functional_approach/functionalapproach.py @@ -86,7 +86,7 @@ def get_sol(self, pnum=None): returns string representation of tree ''' - if pnum == None: + if pnum is None: pnum = [0] s = self.oper.__name__ + '(' for i in self.inputs: @@ -118,7 +118,6 @@ def optimize(self, x_data, y_data, loss): opti = asb.Opti() string_sol = self.get_sol() L = [] - x = x_data for j in range(self.pnum): exec('p' + str(j + 1) + '=' + 'opti.variable(init_guess=1)') exec('L.append(p' + str(j + 1) + ')')