def conical_deflection_Mach_sigma(Mach, sigma, gamma=defg._gamma, tol=1.0e-6): """ Args: Mach: param sigma: gamma: Default value = defg._gamma) tol: Default value = 1.0e-6) sigma: Returns: """ def rhs(phi, data): """RHS for conical equations (2 equations) Args: phi: angle (coordinate of the ODE) data: theta (flow angle) and Mach number Returns: theta/mach variation rate (RHS) """ th = data[0] ma = data[1] k = 1. - (ma * degree.sin(phi - th))**2 rhs = np.zeros(2) rhs[0] = -degree.sin(th) * degree.cos(phi - th) / degree.sin(phi) / k rhs[1] = np.pi / 180. * degree.sin(th) * degree.sin( phi - th) / degree.sin(phi) / k * ma * (1. + .5 * (gamma - 1) * ma * ma) return rhs # initial data for integration from downstream shock to wall th = deflection_Mach_sigma(Mach, sigma, gamma) ma = downstream_Mn(Mach * degree.sin(sigma), gamma) / degree.sin(sigma - th) phi = sigma thma = np.array([th, ma]) h = -phi / 10. conv = phi while (abs(conv) >= tol): dthma, err = _rkf45(rhs, phi, thma, h) # Accept integration step if error e is within tolerance if err <= tol: conv = thma[0] - phi if conv / (h - dthma[0]) < 1: h = h * conv / (h - dthma[0]) else: thma = thma + dthma phi = phi + h #print(Mach, sigma, phi, thma) else: h = 0.9 * h * (tol / err)**0.2 #print("new h ",h) deflection = .5 * (thma[0] + phi) return deflection
def downstreamMach_Mach_ShockPsratio(Mach, Pratio, gamma=defg._gamma): """ Args: Mach: param Pratio: gamma: Default value = defg._gamma) Pratio: Returns: """ Mn0 = Mn_Ps_ratio(Pratio, gamma) sig = degree.asin(Mn0 / Mach) dev = deflection_Mach_sigma(Mach, sig, gamma) Mn1 = downstream_Mn(Mn0, gamma) return Mn1 / degree.sin(sig - dev)
def conical_Mach_walldeflection_sigma(deflection, sigma, gamma=defg._gamma): """computes upstream Mach number from wall deflection and shock angle sigma Args: Mach: param deflection: gamma: Default value = defg._gamma) deflection: Returns: """ assert sigma > deflection def local_def(mach): """internal wrapping function to iterative solve """ #print("local mach sigma", mach, sigma) return conical_deflection_Mach_sigma(mach, sigma, gamma) return ITS.secant_solve(local_def, deflection, 1. / degree.sin(sigma - .5 * deflection))
def rhs(phi, data): """RHS for conical equations (2 equations) Args: phi: angle (coordinate of the ODE) data: theta (flow angle) and Mach number Returns: theta/mach variation rate (RHS) """ th = data[0] ma = data[1] k = 1. - (ma * degree.sin(phi - th))**2 rhs = np.zeros(2) rhs[0] = -degree.sin(th) * degree.cos(phi - th) / degree.sin(phi) / k rhs[1] = np.pi / 180. * degree.sin(th) * degree.sin( phi - th) / degree.sin(phi) / k * ma * (1. + .5 * (gamma - 1) * ma * ma) return rhs
def test_degree_numpy(): a = np.linspace(0., 360, 50) np.testing.assert_allclose(deg.cos(a), deg.sin(a + 90.), rtol=1.e-12)
def plot_theta_pressure(mach, gamma=defg._gamma, npts=100, thet_init=0., p_init=1., curve='both', devmax=False, sonic=False, color='k', linestyle='-', ax=plt, **kwargs): """ Plot shock polar curve in deviation / pressure ratio axes Long comment :param mach: upstream Mach number :param gamma: specific heat ratio, default from aerokit.common.defaultgas :param npts: number of computed points, curve accuracy :param thet_init: upstream angle (shift the curve by this angle), default 0. :param p_init: reference pressure (shift the curve by this ratio), default 1. :param curve: choose which curve to plot (left, right or both) :return: :Example: .. seealso:: .. note:: """ sig = np.linspace(deg.asin(1. / mach), 90., npts + 1) dev = sw.deflection_Mach_sigma(mach, sig, gamma) ps = p_init * sw.Ps_ratio( mach * deg.sin(sig), gamma) # pressure ratio only depends on normal Mach number if curve in ['right', 'both']: ax.plot(thet_init + dev, ps, color=color, linestyle=linestyle, **kwargs) if curve in ['left', 'both']: ax.plot(thet_init - dev, ps, color=color, linestyle=linestyle, **kwargs) if devmax: thet = sw.dev_Max(mach, gamma=gamma) sig = sw.sigma_DevMax(mach, gamma=gamma) ps = sw.Ps_ratio(mach * deg.sin(sig), gamma=gamma) if curve in ['right', 'both']: ax.plot(thet_init + thet, p_init * ps, 'ro', alpha=0.9) if curve in ['left', 'both']: ax.plot(thet_init - thet, p_init * ps, 'ro', alpha=0.9) if sonic: thet = sw.dev_Sonic(mach, gamma=gamma) sig = sw.sigma_Sonic(mach, gamma=gamma) ps = sw.Ps_ratio(mach * deg.sin(sig), gamma=gamma) if curve in ['right', 'both']: ax.plot(thet_init + thet, p_init * ps, 'ko', markerfacecolor='white') if curve in ['left', 'both']: ax.plot(thet_init - thet, p_init * ps, 'ko', markerfacecolor='white')