Beispiel #1
0
    def execute(self):
        """provides a default behavior (to not modify the airfoil)"""

        self.afOut = self.afIn
        
        # create polar object
        p = Polar(self.afIn.Re,
                  self.afIn.alpha,
                  self.afIn.cl,
                  self.afIn.cd,
                  self.afIn.cm)
        
        if self.AR == 0.0:
            AR = None
        else:
            AR = self.AR
            
        # extrapolate polar
        p_extrap = p.extrapolate(self.cdmax,
                                 AR,
                                 self.cdmin,
                                 self.nalpha)
        
        self.afOut.Re = p_extrap.Re
        self.afOut.alpha = p_extrap.alpha
        self.afOut.cl = p_extrap.cl
        self.afOut.cd = p_extrap.cd
        self.afOut.cm = p_extrap.cm
        
        
class TestExtrap(unittest.TestCase):

    def setUp(self):

        alpha = [-10.1, -8.2, -6.1, -4.1, -2.1, 0.1, 2, 4.1, 6.2, 8.1, 10.2,
                 11.3, 12.1, 13.2, 14.2, 15.3, 16.3, 17.1, 18.1, 19.1, 20.1]
        cl = [-0.6300, -0.5600, -0.6400, -0.4200, -0.2100, 0.0500, 0.3000,
              0.5400, 0.7900, 0.9000, 0.9300, 0.9200, 0.9500, 0.9900, 1.0100,
              1.0200, 1.0000, 0.9400, 0.8500, 0.7000, 0.6600]
        cd = [0.0390, 0.0233, 0.0131, 0.0134, 0.0119, 0.0122, 0.0116, 0.0144,
              0.0146, 0.0162, 0.0274, 0.0303, 0.0369, 0.0509, 0.0648, 0.0776,
              0.0917, 0.0994, 0.2306, 0.3142, 0.3186]
        Re = 1
        self.polar = Polar(Re, alpha, cl, cd)


    def test_extrap1(self):

        cdmax = 1.29
        newpolar = self.polar.extrapolate(cdmax=cdmax)

        alpha_extrap = [-180, -170, -160, -150, -140, -130, -120, -110, -100,
                        -90, -80, -70, -60, -50, -40, -30, -20, -10.1, -8.2,
                        -6.1, -4.1, -2.1, 0.1, 2, 4.1, 6.2, 8.1, 10.2, 11.3,
                        12.1, 13.2, 14.2, 15.3, 16.3, 17.1, 18.1, 19.1, 20.1,
                        30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140,
                        150, 160, 170, 180]
        cl_extrap = [0.0000, 0.2299, 0.4597, 0.4907, 0.5053, 0.4805, 0.4102,
                     0.2985, 0.1565, 0.0000, -0.1565, -0.2985, -0.4102,
                     -0.4805, -0.5053, -0.4907, -0.4637, -0.6300, -0.5600,
                     -0.6400, -0.4200, -0.2100, 0.0500, 0.3000, 0.5400,
                     0.7900, 0.9000, 0.9300, 0.9200, 0.9500, 0.9900, 1.0100,
                     1.0200, 1.0000, 0.9400, 0.8500, 0.7000, 0.6600, 0.7010,
                     0.7219, 0.6864, 0.5860, 0.4264, 0.2235, 0.0000, -0.1565,
                     -0.2985, -0.4102, -0.4805, -0.5053, -0.4907, -0.4597,
                     -0.2299, 0.0000]
        cd_extrap = [0.1770, 0.2132, 0.3173, 0.4758, 0.6686, 0.8708, 1.0560,
                     1.1996, 1.2818, 1.2900, 1.2818, 1.1996, 1.0560, 0.8708,
                     0.6686, 0.4758, 0.3158, 0.0390, 0.0233, 0.0131, 0.0134,
                     0.0119, 0.0122, 0.0116, 0.0144, 0.0146, 0.0162, 0.0274,
                     0.0303, 0.0369, 0.0509, 0.0648, 0.0776, 0.0917, 0.0994,
                     0.2306, 0.3142, 0.3186, 0.4758, 0.6686, 0.8708, 1.0560,
                     1.1996, 1.2818, 1.2900, 1.2818, 1.1996, 1.0560, 0.8708,
                     0.6686, 0.4758, 0.3173, 0.2132, 0.1770]

        # re-interpolate b/c angles of attack are different
        cl = np.interp(alpha_extrap, newpolar.alpha, newpolar.cl)
        cd = np.interp(alpha_extrap, newpolar.alpha, newpolar.cd)

        # test equality
        np.testing.assert_allclose(cl, cl_extrap, atol=1.5e-4)
        np.testing.assert_allclose(cd, cd_extrap, atol=1.5e-4)


    def test_extrap1_w_airfoil(self):

        cdmax = 1.29
        af = Airfoil([self.polar])
        newaf = af.extrapolate(cdmax=cdmax)
        newpolar = newaf.polars[0]

        alpha_extrap = [-180, -170, -160, -150, -140, -130, -120, -110, -100,
                        -90, -80, -70, -60, -50, -40, -30, -20, -10.1, -8.2,
                        -6.1, -4.1, -2.1, 0.1, 2, 4.1, 6.2, 8.1, 10.2, 11.3,
                        12.1, 13.2, 14.2, 15.3, 16.3, 17.1, 18.1, 19.1, 20.1,
                        30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140,
                        150, 160, 170, 180]
        cl_extrap = [0.0000, 0.2299, 0.4597, 0.4907, 0.5053, 0.4805, 0.4102,
                     0.2985, 0.1565, 0.0000, -0.1565, -0.2985, -0.4102,
                     -0.4805, -0.5053, -0.4907, -0.4637, -0.6300, -0.5600,
                     -0.6400, -0.4200, -0.2100, 0.0500, 0.3000, 0.5400,
                     0.7900, 0.9000, 0.9300, 0.9200, 0.9500, 0.9900, 1.0100,
                     1.0200, 1.0000, 0.9400, 0.8500, 0.7000, 0.6600, 0.7010,
                     0.7219, 0.6864, 0.5860, 0.4264, 0.2235, 0.0000, -0.1565,
                     -0.2985, -0.4102, -0.4805, -0.5053, -0.4907, -0.4597,
                     -0.2299, 0.0000]
        cd_extrap = [0.1770, 0.2132, 0.3173, 0.4758, 0.6686, 0.8708, 1.0560,
                     1.1996, 1.2818, 1.2900, 1.2818, 1.1996, 1.0560, 0.8708,
                     0.6686, 0.4758, 0.3158, 0.0390, 0.0233, 0.0131, 0.0134,
                     0.0119, 0.0122, 0.0116, 0.0144, 0.0146, 0.0162, 0.0274,
                     0.0303, 0.0369, 0.0509, 0.0648, 0.0776, 0.0917, 0.0994,
                     0.2306, 0.3142, 0.3186, 0.4758, 0.6686, 0.8708, 1.0560,
                     1.1996, 1.2818, 1.2900, 1.2818, 1.1996, 1.0560, 0.8708,
                     0.6686, 0.4758, 0.3173, 0.2132, 0.1770]

        # re-interpolate b/c angles of attack are different
        cl = np.interp(alpha_extrap, newpolar.alpha, newpolar.cl)
        cd = np.interp(alpha_extrap, newpolar.alpha, newpolar.cd)

        # test equality
        np.testing.assert_allclose(cl, cl_extrap, atol=1.5e-4)
        np.testing.assert_allclose(cd, cd_extrap, atol=1.5e-4)


    def test_extrap2(self):

        cdmax = 1.0
        newpolar = self.polar.extrapolate(cdmax=cdmax)

        alpha_extrap = [-180, -170, -160, -150, -140, -130, -120, -110, -100,
                        -90, -80, -70, -60, -50, -40, -30, -20, -10.1, -8.2,
                        -6.1, -4.1, -2.1, 0.1, 2, 4.1, 6.2, 8.1, 10.2, 11.3,
                        12.1, 13.2, 14.2, 15.3, 16.3, 17.1, 18.1, 19.1, 20.1,
                        30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140,
                        150, 160, 170, 180]
        cl_extrap = [0.0000, 0.2299, 0.4597, 0.4411, 0.4287, 0.3943, 0.3297,
                     0.2364, 0.1225, 0.0000, -0.1225, -0.2364, -0.3297,
                     -0.3943, -0.4287, -0.4411, -0.4637, -0.6300, -0.5600,
                     -0.6400, -0.4200, -0.2100, 0.0500, 0.3000, 0.5400,
                     0.7900, 0.9000, 0.9300, 0.9200, 0.9500, 0.9900, 1.0100,
                     1.0200, 1.0000, 0.9400, 0.8500, 0.7000, 0.6600, 0.6302,
                     0.6124, 0.5633, 0.4710, 0.3378, 0.1750, 0.0000, -0.1225,
                     -0.2364, -0.3297, -0.3943, -0.4287, -0.4411, -0.4597,
                     -0.2299, 0.0000]
        cd_extrap = [0.2135, 0.2404, 0.3176, 0.4349, 0.5767, 0.7241, 0.8568,
                     0.9560, 1.0069, 1.0000, 1.0069, 0.9560, 0.8568, 0.7241,
                     0.5767, 0.4349, 0.3158, 0.0390, 0.0233, 0.0131, 0.0134,
                     0.0119, 0.0122, 0.0116, 0.0144, 0.0146, 0.0162, 0.0274,
                     0.0303, 0.0369, 0.0509, 0.0648, 0.0776, 0.0917, 0.0994,
                     0.2306, 0.3142, 0.3186, 0.4349, 0.5767, 0.7241, 0.8568,
                     0.9560, 1.0069, 1.0000, 1.0069, 0.9560, 0.8568, 0.7241,
                     0.5767, 0.4349, 0.3176, 0.2404, 0.2135]

        # re-interpolate b/c angles of attack are different
        cl = np.interp(alpha_extrap, newpolar.alpha, newpolar.cl)
        cd = np.interp(alpha_extrap, newpolar.alpha, newpolar.cd)

        # test equality
        np.testing.assert_allclose(cl, cl_extrap, atol=1.5e-4)
        np.testing.assert_allclose(cd, cd_extrap, atol=1.5e-4)


    def test_extrap3(self):

        cdmax = 1.5
        newpolar = self.polar.extrapolate(cdmax)

        alpha_extrap = [-180, -170, -160, -150, -140, -130, -120, -110, -100,
                        -90, -80, -70, -60, -50, -40, -30, -20, -10.1, -8.2,
                        -6.1, -4.1, -2.1, 0.1, 2, 4.1, 6.2, 8.1, 10.2, 11.3,
                        12.1, 13.2, 14.2, 15.3, 16.3, 17.1, 18.1, 19.1, 20.1,
                        30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140,
                        150, 160, 170, 180]
        cl_extrap = [0.0000, 0.2299, 0.4597, 0.5266, 0.5608, 0.5429, 0.4685,
                     0.3434, 0.1810, 0.0000, -0.1810, -0.3434, -0.4685,
                     -0.5429, -0.5608, -0.5266, -0.4637, -0.6300, -0.5600,
                     -0.6400, -0.4200, -0.2100, 0.0500, 0.3000, 0.5400, 0.7900,
                     0.9000, 0.9300, 0.9200, 0.9500, 0.9900, 1.0100, 1.0200,
                     1.0000, 0.9400, 0.8500, 0.7000, 0.6600, 0.7523, 0.8012,
                     0.7756, 0.6693, 0.4906, 0.2586, 0.0000, -0.1810, -0.3434,
                     -0.4685, -0.5429, -0.5608, -0.5266, -0.4597, -0.2299,
                     0.0000]
        cd_extrap = [0.1506, 0.1936, 0.3170, 0.5054, 0.7351, 0.9771, 1.2003,
                     1.3760, 1.4809, 1.5000, 1.4809, 1.3760, 1.2003, 0.9771,
                     0.7351, 0.5054, 0.3158, 0.0390, 0.0233, 0.0131, 0.0134,
                     0.0119, 0.0122, 0.0116, 0.0144, 0.0146, 0.0162, 0.0274,
                     0.0303, 0.0369, 0.0509, 0.0648, 0.0776, 0.0917, 0.0994,
                     0.2306, 0.3142, 0.3186, 0.5054, 0.7351, 0.9771, 1.2003,
                     1.3760, 1.4809, 1.5000, 1.4809, 1.3760, 1.2003, 0.9771,
                     0.7351, 0.5054, 0.3170, 0.1936, 0.1506]

        # re-interpolate b/c angles of attack are different
        cl = np.interp(alpha_extrap, newpolar.alpha, newpolar.cl)
        cd = np.interp(alpha_extrap, newpolar.alpha, newpolar.cd)

        # test equality
        np.testing.assert_allclose(cl, cl_extrap, atol=1.5e-4)
        np.testing.assert_allclose(cd, cd_extrap, atol=1.5e-4)
class TestExtrap(unittest.TestCase):
    def setUp(self):

        alpha = [
            -10.1,
            -8.2,
            -6.1,
            -4.1,
            -2.1,
            0.1,
            2,
            4.1,
            6.2,
            8.1,
            10.2,
            11.3,
            12.1,
            13.2,
            14.2,
            15.3,
            16.3,
            17.1,
            18.1,
            19.1,
            20.1,
        ]
        cl = [
            -0.6300,
            -0.5600,
            -0.6400,
            -0.4200,
            -0.2100,
            0.0500,
            0.3000,
            0.5400,
            0.7900,
            0.9000,
            0.9300,
            0.9200,
            0.9500,
            0.9900,
            1.0100,
            1.0200,
            1.0000,
            0.9400,
            0.8500,
            0.7000,
            0.6600,
        ]
        cd = [
            0.0390,
            0.0233,
            0.0131,
            0.0134,
            0.0119,
            0.0122,
            0.0116,
            0.0144,
            0.0146,
            0.0162,
            0.0274,
            0.0303,
            0.0369,
            0.0509,
            0.0648,
            0.0776,
            0.0917,
            0.0994,
            0.2306,
            0.3142,
            0.3186,
        ]
        cm = [
            -0.0044,
            -0.0051,
            0.0018,
            -0.0216,
            -0.0282,
            -0.0346,
            -0.0405,
            -0.0455,
            -0.0507,
            -0.0404,
            -0.0321,
            -0.0281,
            -0.0284,
            -0.0322,
            -0.0361,
            -0.0363,
            -0.0393,
            -0.0398,
            -0.0983,
            -0.1242,
            -0.1155,
        ]
        cm_zeros = np.zeros(len(cm))
        Re = 1
        self.polar = Polar(Re, alpha, cl, cd, cm)
        self.polar2 = Polar(Re, alpha, cl, cd, cm_zeros)

    def test_extrap1(self):

        cdmax = 1.29
        newpolar = self.polar.extrapolate(cdmax=cdmax)

        alpha_extrap = [
            -180,
            -170,
            -160,
            -150,
            -140,
            -130,
            -120,
            -110,
            -100,
            -90,
            -80,
            -70,
            -60,
            -50,
            -40,
            -30,
            -20,
            -10.1,
            -8.2,
            -6.1,
            -4.1,
            -2.1,
            0.1,
            2,
            4.1,
            6.2,
            8.1,
            10.2,
            11.3,
            12.1,
            13.2,
            14.2,
            15.3,
            16.3,
            17.1,
            18.1,
            19.1,
            20.1,
            30,
            40,
            50,
            60,
            70,
            80,
            90,
            100,
            110,
            120,
            130,
            140,
            150,
            160,
            170,
            180,
        ]
        cl_extrap = [
            0.0000,
            0.2299,
            0.4597,
            0.4907,
            0.5053,
            0.4805,
            0.4102,
            0.2985,
            0.1565,
            0.0000,
            -0.1565,
            -0.2985,
            -0.4102,
            -0.4805,
            -0.5053,
            -0.4907,
            -0.4637,
            -0.6300,
            -0.5600,
            -0.6400,
            -0.4200,
            -0.2100,
            0.0500,
            0.3000,
            0.5400,
            0.7900,
            0.9000,
            0.9300,
            0.9200,
            0.9500,
            0.9900,
            1.0100,
            1.0200,
            1.0000,
            0.9400,
            0.8500,
            0.7000,
            0.6600,
            0.7010,
            0.7219,
            0.6864,
            0.5860,
            0.4264,
            0.2235,
            0.0000,
            -0.1565,
            -0.2985,
            -0.4102,
            -0.4805,
            -0.5053,
            -0.4907,
            -0.4597,
            -0.2299,
            0.0000,
        ]
        cd_extrap = [
            0.1770,
            0.2132,
            0.3173,
            0.4758,
            0.6686,
            0.8708,
            1.0560,
            1.1996,
            1.2818,
            1.2900,
            1.2818,
            1.1996,
            1.0560,
            0.8708,
            0.6686,
            0.4758,
            0.3158,
            0.0390,
            0.0233,
            0.0131,
            0.0134,
            0.0119,
            0.0122,
            0.0116,
            0.0144,
            0.0146,
            0.0162,
            0.0274,
            0.0303,
            0.0369,
            0.0509,
            0.0648,
            0.0776,
            0.0917,
            0.0994,
            0.2306,
            0.3142,
            0.3186,
            0.4758,
            0.6686,
            0.8708,
            1.0560,
            1.1996,
            1.2818,
            1.2900,
            1.2818,
            1.1996,
            1.0560,
            0.8708,
            0.6686,
            0.4758,
            0.3173,
            0.2132,
            0.1770,
        ]
        cm_extrap = [
            0.0000,
            0.4000,
            0.2431,
            0.2568,
            0.2865,
            0.3185,
            0.3458,
            0.3632,
            0.3672,
            0.3559,
            0.3443,
            0.3182,
            0.2808,
            0.2362,
            0.1886,
            0.1414,
            0.0942,
            -0.0044,
            -0.0051,
            0.0018,
            -0.0216,
            -0.0282,
            -0.0346,
            -0.0405,
            -0.0455,
            -0.0507,
            -0.0404,
            -0.0321,
            -0.0281,
            -0.0284,
            -0.0322,
            -0.0361,
            -0.0363,
            -0.0393,
            -0.0398,
            -0.0983,
            -0.1242,
            -0.1155,
            -0.1710,
            -0.2202,
            -0.2637,
            -0.3002,
            -0.3284,
            -0.3471,
            -0.3559,
            -0.3672,
            -0.3632,
            -0.3458,
            -0.3185,
            -0.2865,
            -0.2568,
            -0.2431,
            -0.5000,
            0.0000,
        ]

        # re-interpolate b/c angles of attack are different
        cl = np.interp(alpha_extrap, newpolar.alpha, newpolar.cl)
        cd = np.interp(alpha_extrap, newpolar.alpha, newpolar.cd)
        cm = np.interp(alpha_extrap, newpolar.alpha, newpolar.cm)

        # test equality
        np.testing.assert_allclose(cl, cl_extrap, atol=1.5e-4)
        np.testing.assert_allclose(cd, cd_extrap, atol=1.5e-4)
        np.testing.assert_allclose(cm, cm_extrap, atol=5e-3)

    def test_extrap1_w_airfoil(self):

        cdmax = 1.29
        af = Airfoil([self.polar2])
        newaf = af.extrapolate(cdmax=cdmax)
        newpolar = newaf.polars[0]

        alpha_extrap = [
            -180,
            -170,
            -160,
            -150,
            -140,
            -130,
            -120,
            -110,
            -100,
            -90,
            -80,
            -70,
            -60,
            -50,
            -40,
            -30,
            -20,
            -10.1,
            -8.2,
            -6.1,
            -4.1,
            -2.1,
            0.1,
            2,
            4.1,
            6.2,
            8.1,
            10.2,
            11.3,
            12.1,
            13.2,
            14.2,
            15.3,
            16.3,
            17.1,
            18.1,
            19.1,
            20.1,
            30,
            40,
            50,
            60,
            70,
            80,
            90,
            100,
            110,
            120,
            130,
            140,
            150,
            160,
            170,
            180,
        ]
        cl_extrap = [
            0.0000,
            0.2299,
            0.4597,
            0.4907,
            0.5053,
            0.4805,
            0.4102,
            0.2985,
            0.1565,
            0.0000,
            -0.1565,
            -0.2985,
            -0.4102,
            -0.4805,
            -0.5053,
            -0.4907,
            -0.4637,
            -0.6300,
            -0.5600,
            -0.6400,
            -0.4200,
            -0.2100,
            0.0500,
            0.3000,
            0.5400,
            0.7900,
            0.9000,
            0.9300,
            0.9200,
            0.9500,
            0.9900,
            1.0100,
            1.0200,
            1.0000,
            0.9400,
            0.8500,
            0.7000,
            0.6600,
            0.7010,
            0.7219,
            0.6864,
            0.5860,
            0.4264,
            0.2235,
            0.0000,
            -0.1565,
            -0.2985,
            -0.4102,
            -0.4805,
            -0.5053,
            -0.4907,
            -0.4597,
            -0.2299,
            0.0000,
        ]
        cd_extrap = [
            0.1770,
            0.2132,
            0.3173,
            0.4758,
            0.6686,
            0.8708,
            1.0560,
            1.1996,
            1.2818,
            1.2900,
            1.2818,
            1.1996,
            1.0560,
            0.8708,
            0.6686,
            0.4758,
            0.3158,
            0.0390,
            0.0233,
            0.0131,
            0.0134,
            0.0119,
            0.0122,
            0.0116,
            0.0144,
            0.0146,
            0.0162,
            0.0274,
            0.0303,
            0.0369,
            0.0509,
            0.0648,
            0.0776,
            0.0917,
            0.0994,
            0.2306,
            0.3142,
            0.3186,
            0.4758,
            0.6686,
            0.8708,
            1.0560,
            1.1996,
            1.2818,
            1.2900,
            1.2818,
            1.1996,
            1.0560,
            0.8708,
            0.6686,
            0.4758,
            0.3173,
            0.2132,
            0.1770,
        ]
        cm_extrap = np.linspace(0, 0, len(cd_extrap))

        # re-interpolate b/c angles of attack are different
        cl = np.interp(alpha_extrap, newpolar.alpha, newpolar.cl)
        cd = np.interp(alpha_extrap, newpolar.alpha, newpolar.cd)
        cm = np.interp(alpha_extrap, newpolar.alpha, newpolar.cm)

        # test equality
        np.testing.assert_allclose(cl, cl_extrap, atol=1.5e-4)
        np.testing.assert_allclose(cd, cd_extrap, atol=1.5e-4)
        np.testing.assert_allclose(cm, cm_extrap, atol=5e-3)

    def test_extrap2(self):

        cdmax = 1.0
        newpolar = self.polar.extrapolate(cdmax=cdmax)

        alpha_extrap = [
            -180,
            -170,
            -160,
            -150,
            -140,
            -130,
            -120,
            -110,
            -100,
            -90,
            -80,
            -70,
            -60,
            -50,
            -40,
            -30,
            -20,
            -10.1,
            -8.2,
            -6.1,
            -4.1,
            -2.1,
            0.1,
            2,
            4.1,
            6.2,
            8.1,
            10.2,
            11.3,
            12.1,
            13.2,
            14.2,
            15.3,
            16.3,
            17.1,
            18.1,
            19.1,
            20.1,
            30,
            40,
            50,
            60,
            70,
            80,
            90,
            100,
            110,
            120,
            130,
            140,
            150,
            160,
            170,
            180,
        ]
        cl_extrap = [
            0.0000,
            0.2299,
            0.4597,
            0.4411,
            0.4287,
            0.3943,
            0.3297,
            0.2364,
            0.1225,
            0.0000,
            -0.1225,
            -0.2364,
            -0.3297,
            -0.3943,
            -0.4287,
            -0.4411,
            -0.4637,
            -0.6300,
            -0.5600,
            -0.6400,
            -0.4200,
            -0.2100,
            0.0500,
            0.3000,
            0.5400,
            0.7900,
            0.9000,
            0.9300,
            0.9200,
            0.9500,
            0.9900,
            1.0100,
            1.0200,
            1.0000,
            0.9400,
            0.8500,
            0.7000,
            0.6600,
            0.6302,
            0.6124,
            0.5633,
            0.4710,
            0.3378,
            0.1750,
            0.0000,
            -0.1225,
            -0.2364,
            -0.3297,
            -0.3943,
            -0.4287,
            -0.4411,
            -0.4597,
            -0.2299,
            0.0000,
        ]
        cd_extrap = [
            0.2135,
            0.2404,
            0.3176,
            0.4349,
            0.5767,
            0.7241,
            0.8568,
            0.9560,
            1.0069,
            1.0000,
            1.0069,
            0.9560,
            0.8568,
            0.7241,
            0.5767,
            0.4349,
            0.3158,
            0.0390,
            0.0233,
            0.0131,
            0.0134,
            0.0119,
            0.0122,
            0.0116,
            0.0144,
            0.0146,
            0.0162,
            0.0274,
            0.0303,
            0.0369,
            0.0509,
            0.0648,
            0.0776,
            0.0917,
            0.0994,
            0.2306,
            0.3142,
            0.3186,
            0.4349,
            0.5767,
            0.7241,
            0.8568,
            0.9560,
            1.0069,
            1.0000,
            1.0069,
            0.9560,
            0.8568,
            0.7241,
            0.5767,
            0.4349,
            0.3176,
            0.2404,
            0.2135,
        ]
        cm_extrap = [
            0.0000,
            0.4000,
            0.2432,
            0.2354,
            0.2500,
            0.2695,
            0.2864,
            0.2961,
            0.2956,
            0.2834,
            0.2776,
            0.2603,
            0.2337,
            0.2013,
            0.1663,
            0.1310,
            0.0942,
            -0.0044,
            -0.0051,
            0.0018,
            -0.0216,
            -0.0282,
            -0.0346,
            -0.0405,
            -0.0455,
            -0.0507,
            -0.0404,
            -0.0321,
            -0.0281,
            -0.0284,
            -0.0322,
            -0.0361,
            -0.0363,
            -0.0393,
            -0.0398,
            -0.0983,
            -0.1242,
            -0.1155,
            -0.1577,
            -0.1930,
            -0.2239,
            -0.2494,
            -0.2683,
            -0.2798,
            -0.2834,
            -0.2956,
            -0.2961,
            -0.2864,
            -0.2695,
            -0.2500,
            -0.2354,
            -0.2432,
            -0.5000,
            0.0000,
        ]

        # re-interpolate b/c angles of attack are different
        cl = np.interp(alpha_extrap, newpolar.alpha, newpolar.cl)
        cd = np.interp(alpha_extrap, newpolar.alpha, newpolar.cd)
        cm = np.interp(alpha_extrap, newpolar.alpha, newpolar.cm)

        # test equality
        np.testing.assert_allclose(cl, cl_extrap, atol=1.5e-4)
        np.testing.assert_allclose(cd, cd_extrap, atol=1.5e-4)
        np.testing.assert_allclose(cm, cm_extrap, atol=5e-3)

    def test_extrap3(self):

        cdmax = 1.5
        newpolar = self.polar.extrapolate(cdmax)

        alpha_extrap = [
            -180,
            -170,
            -160,
            -150,
            -140,
            -130,
            -120,
            -110,
            -100,
            -90,
            -80,
            -70,
            -60,
            -50,
            -40,
            -30,
            -20,
            -10.1,
            -8.2,
            -6.1,
            -4.1,
            -2.1,
            0.1,
            2,
            4.1,
            6.2,
            8.1,
            10.2,
            11.3,
            12.1,
            13.2,
            14.2,
            15.3,
            16.3,
            17.1,
            18.1,
            19.1,
            20.1,
            30,
            40,
            50,
            60,
            70,
            80,
            90,
            100,
            110,
            120,
            130,
            140,
            150,
            160,
            170,
            180,
        ]
        cl_extrap = [
            0.0000,
            0.2299,
            0.4597,
            0.5266,
            0.5608,
            0.5429,
            0.4685,
            0.3434,
            0.1810,
            0.0000,
            -0.1810,
            -0.3434,
            -0.4685,
            -0.5429,
            -0.5608,
            -0.5266,
            -0.4637,
            -0.6300,
            -0.5600,
            -0.6400,
            -0.4200,
            -0.2100,
            0.0500,
            0.3000,
            0.5400,
            0.7900,
            0.9000,
            0.9300,
            0.9200,
            0.9500,
            0.9900,
            1.0100,
            1.0200,
            1.0000,
            0.9400,
            0.8500,
            0.7000,
            0.6600,
            0.7523,
            0.8012,
            0.7756,
            0.6693,
            0.4906,
            0.2586,
            0.0000,
            -0.1810,
            -0.3434,
            -0.4685,
            -0.5429,
            -0.5608,
            -0.5266,
            -0.4597,
            -0.2299,
            0.0000,
        ]
        cd_extrap = [
            0.1506,
            0.1936,
            0.3170,
            0.5054,
            0.7351,
            0.9771,
            1.2003,
            1.3760,
            1.4809,
            1.5000,
            1.4809,
            1.3760,
            1.2003,
            0.9771,
            0.7351,
            0.5054,
            0.3158,
            0.0390,
            0.0233,
            0.0131,
            0.0134,
            0.0119,
            0.0122,
            0.0116,
            0.0144,
            0.0146,
            0.0162,
            0.0274,
            0.0303,
            0.0369,
            0.0509,
            0.0648,
            0.0776,
            0.0917,
            0.0994,
            0.2306,
            0.3142,
            0.3186,
            0.5054,
            0.7351,
            0.9771,
            1.2003,
            1.3760,
            1.4809,
            1.5000,
            1.4809,
            1.3760,
            1.2003,
            0.9771,
            0.7351,
            0.5054,
            0.3170,
            0.1936,
            0.1506,
        ]
        cm_extrap = [
            0.0000,
            0.4000,
            0.2431,
            0.2723,
            0.3130,
            0.3540,
            0.3888,
            0.4118,
            0.4190,
            0.4084,
            0.3926,
            0.3602,
            0.3148,
            0.2614,
            0.2049,
            0.1488,
            0.0942,
            -0.0044,
            -0.0051,
            0.0018,
            -0.0216,
            -0.0282,
            -0.0346,
            -0.0405,
            -0.0455,
            -0.0507,
            -0.0404,
            -0.0321,
            -0.0281,
            -0.0284,
            -0.0322,
            -0.0361,
            -0.0363,
            -0.0393,
            -0.0398,
            -0.0983,
            -0.1242,
            -0.1155,
            -0.1807,
            -0.2399,
            -0.2925,
            -0.3370,
            -0.3719,
            -0.3959,
            -0.4084,
            -0.4190,
            -0.4118,
            -0.3888,
            -0.3540,
            -0.3130,
            -0.2723,
            -0.2431,
            -0.5000,
            0.0000,
        ]

        # re-interpolate b/c angles of attack are different
        cl = np.interp(alpha_extrap, newpolar.alpha, newpolar.cl)
        cd = np.interp(alpha_extrap, newpolar.alpha, newpolar.cd)
        cm = np.interp(alpha_extrap, newpolar.alpha, newpolar.cm)

        # test equality
        np.testing.assert_allclose(cl, cl_extrap, atol=1.5e-4)
        np.testing.assert_allclose(cd, cd_extrap, atol=1.5e-4)
        np.testing.assert_allclose(cm, cm_extrap, atol=5e-3)
class TestExtrap(unittest.TestCase):
    def setUp(self):

        alpha = [
            -10.1, -8.2, -6.1, -4.1, -2.1, 0.1, 2, 4.1, 6.2, 8.1, 10.2, 11.3,
            12.1, 13.2, 14.2, 15.3, 16.3, 17.1, 18.1, 19.1, 20.1
        ]
        cl = [
            -0.6300, -0.5600, -0.6400, -0.4200, -0.2100, 0.0500, 0.3000,
            0.5400, 0.7900, 0.9000, 0.9300, 0.9200, 0.9500, 0.9900, 1.0100,
            1.0200, 1.0000, 0.9400, 0.8500, 0.7000, 0.6600
        ]
        cd = [
            0.0390, 0.0233, 0.0131, 0.0134, 0.0119, 0.0122, 0.0116, 0.0144,
            0.0146, 0.0162, 0.0274, 0.0303, 0.0369, 0.0509, 0.0648, 0.0776,
            0.0917, 0.0994, 0.2306, 0.3142, 0.3186
        ]
        Re = 1
        self.polar = Polar(Re, alpha, cl, cd)

    def test_extrap1(self):

        cdmax = 1.29
        newpolar = self.polar.extrapolate(cdmax=cdmax)

        alpha_extrap = [
            -180, -170, -160, -150, -140, -130, -120, -110, -100, -90, -80,
            -70, -60, -50, -40, -30, -20, -10.1, -8.2, -6.1, -4.1, -2.1, 0.1,
            2, 4.1, 6.2, 8.1, 10.2, 11.3, 12.1, 13.2, 14.2, 15.3, 16.3, 17.1,
            18.1, 19.1, 20.1, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130,
            140, 150, 160, 170, 180
        ]
        cl_extrap = [
            0.0000, 0.2299, 0.4597, 0.4907, 0.5053, 0.4805, 0.4102, 0.2985,
            0.1565, 0.0000, -0.1565, -0.2985, -0.4102, -0.4805, -0.5053,
            -0.4907, -0.4637, -0.6300, -0.5600, -0.6400, -0.4200, -0.2100,
            0.0500, 0.3000, 0.5400, 0.7900, 0.9000, 0.9300, 0.9200, 0.9500,
            0.9900, 1.0100, 1.0200, 1.0000, 0.9400, 0.8500, 0.7000, 0.6600,
            0.7010, 0.7219, 0.6864, 0.5860, 0.4264, 0.2235, 0.0000, -0.1565,
            -0.2985, -0.4102, -0.4805, -0.5053, -0.4907, -0.4597, -0.2299,
            0.0000
        ]
        cd_extrap = [
            0.1770, 0.2132, 0.3173, 0.4758, 0.6686, 0.8708, 1.0560, 1.1996,
            1.2818, 1.2900, 1.2818, 1.1996, 1.0560, 0.8708, 0.6686, 0.4758,
            0.3158, 0.0390, 0.0233, 0.0131, 0.0134, 0.0119, 0.0122, 0.0116,
            0.0144, 0.0146, 0.0162, 0.0274, 0.0303, 0.0369, 0.0509, 0.0648,
            0.0776, 0.0917, 0.0994, 0.2306, 0.3142, 0.3186, 0.4758, 0.6686,
            0.8708, 1.0560, 1.1996, 1.2818, 1.2900, 1.2818, 1.1996, 1.0560,
            0.8708, 0.6686, 0.4758, 0.3173, 0.2132, 0.1770
        ]

        # re-interpolate b/c angles of attack are different
        cl = np.interp(alpha_extrap, newpolar.alpha, newpolar.cl)
        cd = np.interp(alpha_extrap, newpolar.alpha, newpolar.cd)

        # test equality
        np.testing.assert_allclose(cl, cl_extrap, atol=1.5e-4)
        np.testing.assert_allclose(cd, cd_extrap, atol=1.5e-4)

    def test_extrap1_w_airfoil(self):

        cdmax = 1.29
        af = Airfoil([self.polar])
        newaf = af.extrapolate(cdmax=cdmax)
        newpolar = newaf.polars[0]

        alpha_extrap = [
            -180, -170, -160, -150, -140, -130, -120, -110, -100, -90, -80,
            -70, -60, -50, -40, -30, -20, -10.1, -8.2, -6.1, -4.1, -2.1, 0.1,
            2, 4.1, 6.2, 8.1, 10.2, 11.3, 12.1, 13.2, 14.2, 15.3, 16.3, 17.1,
            18.1, 19.1, 20.1, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130,
            140, 150, 160, 170, 180
        ]
        cl_extrap = [
            0.0000, 0.2299, 0.4597, 0.4907, 0.5053, 0.4805, 0.4102, 0.2985,
            0.1565, 0.0000, -0.1565, -0.2985, -0.4102, -0.4805, -0.5053,
            -0.4907, -0.4637, -0.6300, -0.5600, -0.6400, -0.4200, -0.2100,
            0.0500, 0.3000, 0.5400, 0.7900, 0.9000, 0.9300, 0.9200, 0.9500,
            0.9900, 1.0100, 1.0200, 1.0000, 0.9400, 0.8500, 0.7000, 0.6600,
            0.7010, 0.7219, 0.6864, 0.5860, 0.4264, 0.2235, 0.0000, -0.1565,
            -0.2985, -0.4102, -0.4805, -0.5053, -0.4907, -0.4597, -0.2299,
            0.0000
        ]
        cd_extrap = [
            0.1770, 0.2132, 0.3173, 0.4758, 0.6686, 0.8708, 1.0560, 1.1996,
            1.2818, 1.2900, 1.2818, 1.1996, 1.0560, 0.8708, 0.6686, 0.4758,
            0.3158, 0.0390, 0.0233, 0.0131, 0.0134, 0.0119, 0.0122, 0.0116,
            0.0144, 0.0146, 0.0162, 0.0274, 0.0303, 0.0369, 0.0509, 0.0648,
            0.0776, 0.0917, 0.0994, 0.2306, 0.3142, 0.3186, 0.4758, 0.6686,
            0.8708, 1.0560, 1.1996, 1.2818, 1.2900, 1.2818, 1.1996, 1.0560,
            0.8708, 0.6686, 0.4758, 0.3173, 0.2132, 0.1770
        ]

        # re-interpolate b/c angles of attack are different
        cl = np.interp(alpha_extrap, newpolar.alpha, newpolar.cl)
        cd = np.interp(alpha_extrap, newpolar.alpha, newpolar.cd)

        # test equality
        np.testing.assert_allclose(cl, cl_extrap, atol=1.5e-4)
        np.testing.assert_allclose(cd, cd_extrap, atol=1.5e-4)

    def test_extrap2(self):

        cdmax = 1.0
        newpolar = self.polar.extrapolate(cdmax=cdmax)

        alpha_extrap = [
            -180, -170, -160, -150, -140, -130, -120, -110, -100, -90, -80,
            -70, -60, -50, -40, -30, -20, -10.1, -8.2, -6.1, -4.1, -2.1, 0.1,
            2, 4.1, 6.2, 8.1, 10.2, 11.3, 12.1, 13.2, 14.2, 15.3, 16.3, 17.1,
            18.1, 19.1, 20.1, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130,
            140, 150, 160, 170, 180
        ]
        cl_extrap = [
            0.0000, 0.2299, 0.4597, 0.4411, 0.4287, 0.3943, 0.3297, 0.2364,
            0.1225, 0.0000, -0.1225, -0.2364, -0.3297, -0.3943, -0.4287,
            -0.4411, -0.4637, -0.6300, -0.5600, -0.6400, -0.4200, -0.2100,
            0.0500, 0.3000, 0.5400, 0.7900, 0.9000, 0.9300, 0.9200, 0.9500,
            0.9900, 1.0100, 1.0200, 1.0000, 0.9400, 0.8500, 0.7000, 0.6600,
            0.6302, 0.6124, 0.5633, 0.4710, 0.3378, 0.1750, 0.0000, -0.1225,
            -0.2364, -0.3297, -0.3943, -0.4287, -0.4411, -0.4597, -0.2299,
            0.0000
        ]
        cd_extrap = [
            0.2135, 0.2404, 0.3176, 0.4349, 0.5767, 0.7241, 0.8568, 0.9560,
            1.0069, 1.0000, 1.0069, 0.9560, 0.8568, 0.7241, 0.5767, 0.4349,
            0.3158, 0.0390, 0.0233, 0.0131, 0.0134, 0.0119, 0.0122, 0.0116,
            0.0144, 0.0146, 0.0162, 0.0274, 0.0303, 0.0369, 0.0509, 0.0648,
            0.0776, 0.0917, 0.0994, 0.2306, 0.3142, 0.3186, 0.4349, 0.5767,
            0.7241, 0.8568, 0.9560, 1.0069, 1.0000, 1.0069, 0.9560, 0.8568,
            0.7241, 0.5767, 0.4349, 0.3176, 0.2404, 0.2135
        ]

        # re-interpolate b/c angles of attack are different
        cl = np.interp(alpha_extrap, newpolar.alpha, newpolar.cl)
        cd = np.interp(alpha_extrap, newpolar.alpha, newpolar.cd)

        # test equality
        np.testing.assert_allclose(cl, cl_extrap, atol=1.5e-4)
        np.testing.assert_allclose(cd, cd_extrap, atol=1.5e-4)

    def test_extrap3(self):

        cdmax = 1.5
        newpolar = self.polar.extrapolate(cdmax)

        alpha_extrap = [
            -180, -170, -160, -150, -140, -130, -120, -110, -100, -90, -80,
            -70, -60, -50, -40, -30, -20, -10.1, -8.2, -6.1, -4.1, -2.1, 0.1,
            2, 4.1, 6.2, 8.1, 10.2, 11.3, 12.1, 13.2, 14.2, 15.3, 16.3, 17.1,
            18.1, 19.1, 20.1, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130,
            140, 150, 160, 170, 180
        ]
        cl_extrap = [
            0.0000, 0.2299, 0.4597, 0.5266, 0.5608, 0.5429, 0.4685, 0.3434,
            0.1810, 0.0000, -0.1810, -0.3434, -0.4685, -0.5429, -0.5608,
            -0.5266, -0.4637, -0.6300, -0.5600, -0.6400, -0.4200, -0.2100,
            0.0500, 0.3000, 0.5400, 0.7900, 0.9000, 0.9300, 0.9200, 0.9500,
            0.9900, 1.0100, 1.0200, 1.0000, 0.9400, 0.8500, 0.7000, 0.6600,
            0.7523, 0.8012, 0.7756, 0.6693, 0.4906, 0.2586, 0.0000, -0.1810,
            -0.3434, -0.4685, -0.5429, -0.5608, -0.5266, -0.4597, -0.2299,
            0.0000
        ]
        cd_extrap = [
            0.1506, 0.1936, 0.3170, 0.5054, 0.7351, 0.9771, 1.2003, 1.3760,
            1.4809, 1.5000, 1.4809, 1.3760, 1.2003, 0.9771, 0.7351, 0.5054,
            0.3158, 0.0390, 0.0233, 0.0131, 0.0134, 0.0119, 0.0122, 0.0116,
            0.0144, 0.0146, 0.0162, 0.0274, 0.0303, 0.0369, 0.0509, 0.0648,
            0.0776, 0.0917, 0.0994, 0.2306, 0.3142, 0.3186, 0.5054, 0.7351,
            0.9771, 1.2003, 1.3760, 1.4809, 1.5000, 1.4809, 1.3760, 1.2003,
            0.9771, 0.7351, 0.5054, 0.3170, 0.1936, 0.1506
        ]

        # re-interpolate b/c angles of attack are different
        cl = np.interp(alpha_extrap, newpolar.alpha, newpolar.cl)
        cd = np.interp(alpha_extrap, newpolar.alpha, newpolar.cd)

        # test equality
        np.testing.assert_allclose(cl, cl_extrap, atol=1.5e-4)
        np.testing.assert_allclose(cd, cd_extrap, atol=1.5e-4)
Beispiel #5
0
    def solve_nonlinear(self, params, unknowns, resids):

        # determine aspect ratio = (rotor radius / chord_75% radius)\
        #    if provided, cdmax is computed from AR'
        bl = params['blade_length']
        dr = params['rotor_diameter']
        hr = 0.5 * dr - bl
        rotor_radius = 0.5 * dr
        chord = params['chord_st'] * bl
        s = params['s_st']
        r = (s * bl + hr) / rotor_radius
        chord_75 = np.interp(0.75, r, chord)
        AR = rotor_radius / chord_75

        # write aerodyn files
        af_name_base = 'cs_'
        af_name_suffix = '_aerodyn'
        tcs = params['cs_polars_tc']

        n_cs_alpha = params['n_cs_alpha']
        pol = params['cs_polars']
        nmet = 0
        # TODO: blend polars determined with different methods
        for i, tc in enumerate(self.blend_var):
            af_name = af_name_base + \
                '%03d_%04d' % (i, tc * 1000) + af_name_suffix
            re_polars = []
            for nre, re in enumerate(self.res):
                # create polar object
                p = Polar(re,
                          pol[:n_cs_alpha[i, nre, nmet], 0, i, nre, nmet],
                          pol[:n_cs_alpha[i, nre, nmet], 1, i, nre, nmet],
                          pol[:n_cs_alpha[i, nre, nmet], 2, i, nre, nmet],
                          pol[:n_cs_alpha[i, nre, nmet], 3, i, nre, nmet])

                # extrapolate polar
                if tc < self.tc_max:
                    p_extrap = p.extrapolate(self.cdmax,
                                             AR,
                                             self.cdmin,
                                             self.nalpha)
                else:
                    p_extrap = p.extrapolate_as_cylinder()
                p_extrap.useCM = self.useCM
                re_polars.append(p_extrap)

                # TODO: output as HAWC2/FAST format
                # See if HAWC can take several af tables with different Re
                # numbers
                '''
                unknowns['airfoildata:aoa%02d' % i] = p_extrap.alpha
                unknowns['airfoildata:cl%02d' % i] = p_extrap.cl
                unknowns['airfoildata:cd%02d' % i] = p_extrap.cd
                unknowns['airfoildata:cm%02d' % i] = p_extrap.cm
                '''

            # create airfoil object
            af = Airfoil(re_polars)
            af.interpToCommonAlpha()
            af.writeToAerodynFile(af_name + '.dat')

            if self.plot_polars:
                figs = af.plot(single_figure=True)
                titles = ['cl', 'cd', 'cm']
                for (fig, title) in zip(figs, titles):
                    fig.savefig(af_name + '_' + title + '.png', dpi=400)
                    fig.savefig(af_name + '_' + title + '.pdf')

        self._get_unknowns(unknowns)
Beispiel #6
0
class TestExtrap(unittest.TestCase):
    def setUp(self):

        alpha = [
            -10.1, -8.2, -6.1, -4.1, -2.1, 0.1, 2, 4.1, 6.2, 8.1, 10.2, 11.3,
            12.1, 13.2, 14.2, 15.3, 16.3, 17.1, 18.1, 19.1, 20.1
        ]
        cl = [
            -0.6300, -0.5600, -0.6400, -0.4200, -0.2100, 0.0500, 0.3000,
            0.5400, 0.7900, 0.9000, 0.9300, 0.9200, 0.9500, 0.9900, 1.0100,
            1.0200, 1.0000, 0.9400, 0.8500, 0.7000, 0.6600
        ]
        cd = [
            0.0390, 0.0233, 0.0131, 0.0134, 0.0119, 0.0122, 0.0116, 0.0144,
            0.0146, 0.0162, 0.0274, 0.0303, 0.0369, 0.0509, 0.0648, 0.0776,
            0.0917, 0.0994, 0.2306, 0.3142, 0.3186
        ]
        cm = [
            -0.0044, -0.0051, 0.0018, -0.0216, -0.0282, -0.0346, -0.0405,
            -0.0455, -0.0507, -0.0404, -0.0321, -0.0281, -0.0284, -0.0322,
            -0.0361, -0.0363, -0.0393, -0.0398, -0.0983, -0.1242, -0.1155
        ]
        cm_zeros = np.zeros(len(cm))
        Re = 1
        self.polar = Polar(Re, alpha, cl, cd, cm)
        self.polar2 = Polar(Re, alpha, cl, cd, cm_zeros)

    def test_extrap1(self):

        cdmax = 1.29
        newpolar = self.polar.extrapolate(cdmax=cdmax)

        alpha_extrap = [
            -180, -170, -160, -150, -140, -130, -120, -110, -100, -90, -80,
            -70, -60, -50, -40, -30, -20, -10.1, -8.2, -6.1, -4.1, -2.1, 0.1,
            2, 4.1, 6.2, 8.1, 10.2, 11.3, 12.1, 13.2, 14.2, 15.3, 16.3, 17.1,
            18.1, 19.1, 20.1, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130,
            140, 150, 160, 170, 180
        ]
        cl_extrap = [
            0.0000, 0.2299, 0.4597, 0.4907, 0.5053, 0.4805, 0.4102, 0.2985,
            0.1565, 0.0000, -0.1565, -0.2985, -0.4102, -0.4805, -0.5053,
            -0.4907, -0.4637, -0.6300, -0.5600, -0.6400, -0.4200, -0.2100,
            0.0500, 0.3000, 0.5400, 0.7900, 0.9000, 0.9300, 0.9200, 0.9500,
            0.9900, 1.0100, 1.0200, 1.0000, 0.9400, 0.8500, 0.7000, 0.6600,
            0.7010, 0.7219, 0.6864, 0.5860, 0.4264, 0.2235, 0.0000, -0.1565,
            -0.2985, -0.4102, -0.4805, -0.5053, -0.4907, -0.4597, -0.2299,
            0.0000
        ]
        cd_extrap = [
            0.1770, 0.2132, 0.3173, 0.4758, 0.6686, 0.8708, 1.0560, 1.1996,
            1.2818, 1.2900, 1.2818, 1.1996, 1.0560, 0.8708, 0.6686, 0.4758,
            0.3158, 0.0390, 0.0233, 0.0131, 0.0134, 0.0119, 0.0122, 0.0116,
            0.0144, 0.0146, 0.0162, 0.0274, 0.0303, 0.0369, 0.0509, 0.0648,
            0.0776, 0.0917, 0.0994, 0.2306, 0.3142, 0.3186, 0.4758, 0.6686,
            0.8708, 1.0560, 1.1996, 1.2818, 1.2900, 1.2818, 1.1996, 1.0560,
            0.8708, 0.6686, 0.4758, 0.3173, 0.2132, 0.1770
        ]
        cm_extrap = [
            0.0000, 0.4000, 0.2431, 0.2568, 0.2865, 0.3185, 0.3458, 0.3632,
            0.3672, 0.3559, 0.3443, 0.3182, 0.2808, 0.2362, 0.1886, 0.1414,
            0.0942, -0.0044, -0.0051, 0.0018, -0.0216, -0.0282, -0.0346,
            -0.0405, -0.0455, -0.0507, -0.0404, -0.0321, -0.0281, -0.0284,
            -0.0322, -0.0361, -0.0363, -0.0393, -0.0398, -0.0983, -0.1242,
            -0.1155, -0.1710, -0.2202, -0.2637, -0.3002, -0.3284, -0.3471,
            -0.3559, -0.3672, -0.3632, -0.3458, -0.3185, -0.2865, -0.2568,
            -0.2431, -0.5000, 0.0000
        ]

        # re-interpolate b/c angles of attack are different
        cl = np.interp(alpha_extrap, newpolar.alpha, newpolar.cl)
        cd = np.interp(alpha_extrap, newpolar.alpha, newpolar.cd)
        cm = np.interp(alpha_extrap, newpolar.alpha, newpolar.cm)

        # test equality
        np.testing.assert_allclose(cl, cl_extrap, atol=1.5e-4)
        np.testing.assert_allclose(cd, cd_extrap, atol=1.5e-4)
        np.testing.assert_allclose(cm, cm_extrap, atol=5e-3)

    def test_extrap1_w_airfoil(self):

        cdmax = 1.29
        af = Airfoil([self.polar2])
        newaf = af.extrapolate(cdmax=cdmax)
        newpolar = newaf.polars[0]

        alpha_extrap = [
            -180, -170, -160, -150, -140, -130, -120, -110, -100, -90, -80,
            -70, -60, -50, -40, -30, -20, -10.1, -8.2, -6.1, -4.1, -2.1, 0.1,
            2, 4.1, 6.2, 8.1, 10.2, 11.3, 12.1, 13.2, 14.2, 15.3, 16.3, 17.1,
            18.1, 19.1, 20.1, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130,
            140, 150, 160, 170, 180
        ]
        cl_extrap = [
            0.0000, 0.2299, 0.4597, 0.4907, 0.5053, 0.4805, 0.4102, 0.2985,
            0.1565, 0.0000, -0.1565, -0.2985, -0.4102, -0.4805, -0.5053,
            -0.4907, -0.4637, -0.6300, -0.5600, -0.6400, -0.4200, -0.2100,
            0.0500, 0.3000, 0.5400, 0.7900, 0.9000, 0.9300, 0.9200, 0.9500,
            0.9900, 1.0100, 1.0200, 1.0000, 0.9400, 0.8500, 0.7000, 0.6600,
            0.7010, 0.7219, 0.6864, 0.5860, 0.4264, 0.2235, 0.0000, -0.1565,
            -0.2985, -0.4102, -0.4805, -0.5053, -0.4907, -0.4597, -0.2299,
            0.0000
        ]
        cd_extrap = [
            0.1770, 0.2132, 0.3173, 0.4758, 0.6686, 0.8708, 1.0560, 1.1996,
            1.2818, 1.2900, 1.2818, 1.1996, 1.0560, 0.8708, 0.6686, 0.4758,
            0.3158, 0.0390, 0.0233, 0.0131, 0.0134, 0.0119, 0.0122, 0.0116,
            0.0144, 0.0146, 0.0162, 0.0274, 0.0303, 0.0369, 0.0509, 0.0648,
            0.0776, 0.0917, 0.0994, 0.2306, 0.3142, 0.3186, 0.4758, 0.6686,
            0.8708, 1.0560, 1.1996, 1.2818, 1.2900, 1.2818, 1.1996, 1.0560,
            0.8708, 0.6686, 0.4758, 0.3173, 0.2132, 0.1770
        ]
        cm_extrap = np.linspace(0, 0, len(cd_extrap))

        # re-interpolate b/c angles of attack are different
        cl = np.interp(alpha_extrap, newpolar.alpha, newpolar.cl)
        cd = np.interp(alpha_extrap, newpolar.alpha, newpolar.cd)
        cm = np.interp(alpha_extrap, newpolar.alpha, newpolar.cm)

        # test equality
        np.testing.assert_allclose(cl, cl_extrap, atol=1.5e-4)
        np.testing.assert_allclose(cd, cd_extrap, atol=1.5e-4)
        np.testing.assert_allclose(cm, cm_extrap, atol=5e-3)

    def test_extrap2(self):

        cdmax = 1.0
        newpolar = self.polar.extrapolate(cdmax=cdmax)

        alpha_extrap = [
            -180, -170, -160, -150, -140, -130, -120, -110, -100, -90, -80,
            -70, -60, -50, -40, -30, -20, -10.1, -8.2, -6.1, -4.1, -2.1, 0.1,
            2, 4.1, 6.2, 8.1, 10.2, 11.3, 12.1, 13.2, 14.2, 15.3, 16.3, 17.1,
            18.1, 19.1, 20.1, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130,
            140, 150, 160, 170, 180
        ]
        cl_extrap = [
            0.0000, 0.2299, 0.4597, 0.4411, 0.4287, 0.3943, 0.3297, 0.2364,
            0.1225, 0.0000, -0.1225, -0.2364, -0.3297, -0.3943, -0.4287,
            -0.4411, -0.4637, -0.6300, -0.5600, -0.6400, -0.4200, -0.2100,
            0.0500, 0.3000, 0.5400, 0.7900, 0.9000, 0.9300, 0.9200, 0.9500,
            0.9900, 1.0100, 1.0200, 1.0000, 0.9400, 0.8500, 0.7000, 0.6600,
            0.6302, 0.6124, 0.5633, 0.4710, 0.3378, 0.1750, 0.0000, -0.1225,
            -0.2364, -0.3297, -0.3943, -0.4287, -0.4411, -0.4597, -0.2299,
            0.0000
        ]
        cd_extrap = [
            0.2135, 0.2404, 0.3176, 0.4349, 0.5767, 0.7241, 0.8568, 0.9560,
            1.0069, 1.0000, 1.0069, 0.9560, 0.8568, 0.7241, 0.5767, 0.4349,
            0.3158, 0.0390, 0.0233, 0.0131, 0.0134, 0.0119, 0.0122, 0.0116,
            0.0144, 0.0146, 0.0162, 0.0274, 0.0303, 0.0369, 0.0509, 0.0648,
            0.0776, 0.0917, 0.0994, 0.2306, 0.3142, 0.3186, 0.4349, 0.5767,
            0.7241, 0.8568, 0.9560, 1.0069, 1.0000, 1.0069, 0.9560, 0.8568,
            0.7241, 0.5767, 0.4349, 0.3176, 0.2404, 0.2135
        ]
        cm_extrap = [
            0.0000, 0.4000, 0.2432, 0.2354, 0.2500, 0.2695, 0.2864, 0.2961,
            0.2956, 0.2834, 0.2776, 0.2603, 0.2337, 0.2013, 0.1663, 0.1310,
            0.0942, -0.0044, -0.0051, 0.0018, -0.0216, -0.0282, -0.0346,
            -0.0405, -0.0455, -0.0507, -0.0404, -0.0321, -0.0281, -0.0284,
            -0.0322, -0.0361, -0.0363, -0.0393, -0.0398, -0.0983, -0.1242,
            -0.1155, -0.1577, -0.1930, -0.2239, -0.2494, -0.2683, -0.2798,
            -0.2834, -0.2956, -0.2961, -0.2864, -0.2695, -0.2500, -0.2354,
            -0.2432, -0.5000, 0.0000
        ]

        # re-interpolate b/c angles of attack are different
        cl = np.interp(alpha_extrap, newpolar.alpha, newpolar.cl)
        cd = np.interp(alpha_extrap, newpolar.alpha, newpolar.cd)
        cm = np.interp(alpha_extrap, newpolar.alpha, newpolar.cm)

        # test equality
        np.testing.assert_allclose(cl, cl_extrap, atol=1.5e-4)
        np.testing.assert_allclose(cd, cd_extrap, atol=1.5e-4)
        np.testing.assert_allclose(cm, cm_extrap, atol=5e-3)

    def test_extrap3(self):

        cdmax = 1.5
        newpolar = self.polar.extrapolate(cdmax)

        alpha_extrap = [
            -180, -170, -160, -150, -140, -130, -120, -110, -100, -90, -80,
            -70, -60, -50, -40, -30, -20, -10.1, -8.2, -6.1, -4.1, -2.1, 0.1,
            2, 4.1, 6.2, 8.1, 10.2, 11.3, 12.1, 13.2, 14.2, 15.3, 16.3, 17.1,
            18.1, 19.1, 20.1, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130,
            140, 150, 160, 170, 180
        ]
        cl_extrap = [
            0.0000, 0.2299, 0.4597, 0.5266, 0.5608, 0.5429, 0.4685, 0.3434,
            0.1810, 0.0000, -0.1810, -0.3434, -0.4685, -0.5429, -0.5608,
            -0.5266, -0.4637, -0.6300, -0.5600, -0.6400, -0.4200, -0.2100,
            0.0500, 0.3000, 0.5400, 0.7900, 0.9000, 0.9300, 0.9200, 0.9500,
            0.9900, 1.0100, 1.0200, 1.0000, 0.9400, 0.8500, 0.7000, 0.6600,
            0.7523, 0.8012, 0.7756, 0.6693, 0.4906, 0.2586, 0.0000, -0.1810,
            -0.3434, -0.4685, -0.5429, -0.5608, -0.5266, -0.4597, -0.2299,
            0.0000
        ]
        cd_extrap = [
            0.1506, 0.1936, 0.3170, 0.5054, 0.7351, 0.9771, 1.2003, 1.3760,
            1.4809, 1.5000, 1.4809, 1.3760, 1.2003, 0.9771, 0.7351, 0.5054,
            0.3158, 0.0390, 0.0233, 0.0131, 0.0134, 0.0119, 0.0122, 0.0116,
            0.0144, 0.0146, 0.0162, 0.0274, 0.0303, 0.0369, 0.0509, 0.0648,
            0.0776, 0.0917, 0.0994, 0.2306, 0.3142, 0.3186, 0.5054, 0.7351,
            0.9771, 1.2003, 1.3760, 1.4809, 1.5000, 1.4809, 1.3760, 1.2003,
            0.9771, 0.7351, 0.5054, 0.3170, 0.1936, 0.1506
        ]
        cm_extrap = [
            0.0000, 0.4000, 0.2431, 0.2723, 0.3130, 0.3540, 0.3888, 0.4118,
            0.4190, 0.4084, 0.3926, 0.3602, 0.3148, 0.2614, 0.2049, 0.1488,
            0.0942, -0.0044, -0.0051, 0.0018, -0.0216, -0.0282, -0.0346,
            -0.0405, -0.0455, -0.0507, -0.0404, -0.0321, -0.0281, -0.0284,
            -0.0322, -0.0361, -0.0363, -0.0393, -0.0398, -0.0983, -0.1242,
            -0.1155, -0.1807, -0.2399, -0.2925, -0.3370, -0.3719, -0.3959,
            -0.4084, -0.4190, -0.4118, -0.3888, -0.3540, -0.3130, -0.2723,
            -0.2431, -0.5000, 0.0000
        ]

        # re-interpolate b/c angles of attack are different
        cl = np.interp(alpha_extrap, newpolar.alpha, newpolar.cl)
        cd = np.interp(alpha_extrap, newpolar.alpha, newpolar.cd)
        cm = np.interp(alpha_extrap, newpolar.alpha, newpolar.cm)

        # test equality
        np.testing.assert_allclose(cl, cl_extrap, atol=1.5e-4)
        np.testing.assert_allclose(cd, cd_extrap, atol=1.5e-4)
        np.testing.assert_allclose(cm, cm_extrap, atol=5e-3)