Example #1
0
    def test_dbiot_segment_mid(self):
        if self.print_info:
            print(
                '\n------------------------- Testing dbiot.eval_seg at mid-point'
            )

        gamma = 2.4
        zetaA = self.zeta1
        zetaB = self.zeta2
        zetaP = .3 * zetaA + 0.7 * zetaB

        Q0 = uvlmutils.biot_segment(zetaP, zetaA, zetaB, vortex_radius, gamma)

        ### compare different analytical derivative
        DerP_an, DerA_an, DerB_an = dbiot.eval_seg_exp(zetaP, zetaA, zetaB,
                                                       vortex_radius, gamma)
        DerP_an2, DerA_an2, DerB_an2 = dbiot.eval_seg_comp(
            zetaP, zetaA, zetaB, gamma)
        er_max = max(np.max(np.abs(DerP_an2 - DerP_an)),
                     np.max(np.abs(DerA_an2 - DerA_an)),
                     np.max(np.abs(DerB_an2 - DerB_an)))
        assert er_max < 1e-16, 'Analytical models not matching'

        ### compare vs numerical derivative
        #  first step must be smaller than vortex radius
        Steps = np.linspace(vortex_radius * 0.99, vortex_radius * 1e-2, 4)
        Er_max = 0.0 * Steps
        for ss in range(len(Steps)):
            step = Steps[ss]
            DerP_num = 0.0 * DerP_an
            DerA_num = 0.0 * DerA_an
            DerB_num = 0.0 * DerB_an
            for cc_zeta in range(3):
                dzeta = np.zeros((3, ))
                dzeta[cc_zeta] = step
                DerP_num[:, cc_zeta] = (uvlmutils.biot_segment(
                    zetaP + dzeta, zetaA, zetaB, vortex_radius, gamma) -
                                        Q0) / step
                DerA_num[:, cc_zeta] = (uvlmutils.biot_segment(
                    zetaP, zetaA + dzeta, zetaB, vortex_radius, gamma) -
                                        Q0) / step
                DerB_num[:, cc_zeta] = (uvlmutils.biot_segment(
                    zetaP, zetaA, zetaB + dzeta, vortex_radius, gamma) -
                                        Q0) / step
            er_max = max(np.max(np.abs(DerP_num - DerP_an)),
                         np.max(np.abs(DerA_num - DerA_an)),
                         np.max(np.abs(DerB_num - DerB_an)))

            if self.print_info:
                print('FD step: %.2e ---> Max error: %.2e' % (step, er_max))
            assert er_max < 5e1 * step, 'Error larger than 50 times step size'
            Er_max[ss] = er_max
Example #2
0
    def test_dbiot_segment_mid(self):
        print(
            '\n------------------------- Testing dbiot.eval_seg at mid-point')

        gamma = 2.4
        zetaA = self.zeta1
        zetaB = self.zeta2
        zetaP = .3 * zetaA + 0.7 * zetaB

        Q0 = libuvlm.biot_segment(zetaP, zetaA, zetaB, gamma)

        ### compare different analytical derivative
        DerP_an, DerA_an, DerB_an = dbiot.eval_seg_exp(zetaP, zetaA, zetaB,
                                                       gamma)
        DerP_an2, DerA_an2, DerB_an2 = dbiot.eval_seg_comp(
            zetaP, zetaA, zetaB, gamma)
        er_max = max(np.max(np.abs(DerP_an2 - DerP_an)),
                     np.max(np.abs(DerA_an2 - DerA_an)),
                     np.max(np.abs(DerB_an2 - DerB_an)))
        assert er_max < 1e-16, 'Analytical models not matching'

        ### compare vs numerical derivative
        Steps = np.array([1e-2, 1e-4, 1e-6])
        Er_max = 0.0 * Steps
        for ss in range(len(Steps)):
            step = Steps[ss]
            DerP_num = 0.0 * DerP_an
            DerA_num = 0.0 * DerA_an
            DerB_num = 0.0 * DerB_an
            for cc_zeta in range(3):
                dzeta = np.zeros((3, ))
                dzeta[cc_zeta] = step
                DerP_num[:, cc_zeta] = (libuvlm.biot_segment(
                    zetaP + dzeta, zetaA, zetaB, gamma) - Q0) / step
                DerA_num[:, cc_zeta] = (libuvlm.biot_segment(
                    zetaP, zetaA + dzeta, zetaB, gamma) - Q0) / step
                DerB_num[:, cc_zeta] = (libuvlm.biot_segment(
                    zetaP, zetaA, zetaB + dzeta, gamma) - Q0) / step
            er_max = max(np.max(np.abs(DerP_num - DerP_an)),
                         np.max(np.abs(DerA_num - DerA_an)),
                         np.max(np.abs(DerB_num - DerB_an)))
            print('FD step: %.2e ---> Max error: %.2e' % (step, er_max))
            assert er_max < 5e1 * step, 'Error larger than 50 times step size'
            Er_max[ss] = er_max
Example #3
0
    def test_dbiot_segment(self):
        print('\n-------------------------------------- Testing dbiot.eval_seg')

        gamma = 2.4
        zetaP = self.zetaP
        zetaA = self.zeta1
        zetaB = self.zeta2
        Q0 = uvlmutils.biot_segment(zetaP, zetaA, zetaB, gamma)

        ### compare different analytical derivative
        DerP_an, DerA_an, DerB_an = dbiot.eval_seg_exp(zetaP, zetaA, zetaB, gamma)
        DerP_an2, DerA_an2, DerB_an2 = dbiot.eval_seg_comp(zetaP, zetaA, zetaB, gamma)
        er_max = max(np.max(np.abs(DerP_an2 - DerP_an)),
                     np.max(np.abs(DerA_an2 - DerA_an)),
                     np.max(np.abs(DerB_an2 - DerB_an)))
        assert er_max < 1e-16, 'Analytical models not matching'

        ### compare vs numerical derivative
        Steps = np.linspace(uvlmutils.VORTEX_RADIUS * 0.99, uvlmutils.VORTEX_RADIUS * 1e-2, 4)
        Er_max = 0.0 * Steps
        for ss in range(len(Steps)):
            step = Steps[ss]
            DerP_num = 0.0 * DerP_an
            DerA_num = 0.0 * DerA_an
            DerB_num = 0.0 * DerB_an
            for cc_zeta in range(3):
                dzeta = np.zeros((3,))
                dzeta[cc_zeta] = step
                DerP_num[:, cc_zeta] = (
                                               uvlmutils.biot_segment(zetaP + dzeta, zetaA, zetaB, gamma) - Q0) / step
                DerA_num[:, cc_zeta] = (
                                               uvlmutils.biot_segment(zetaP, zetaA + dzeta, zetaB, gamma) - Q0) / step
                DerB_num[:, cc_zeta] = (
                                               uvlmutils.biot_segment(zetaP, zetaA, zetaB + dzeta, gamma) - Q0) / step
            er_max = max(np.max(np.abs(DerP_num - DerP_an)),
                         np.max(np.abs(DerA_num - DerA_an)),
                         np.max(np.abs(DerB_num - DerB_an)))
            print('FD step: %.2e ---> Max error: %.2e' % (step, er_max))
            assert er_max < 5e1 * step, 'Error larger than 50 times step size'
            Er_max[ss] = er_max