예제 #1
0
    def subtest_biotsavart_d2A_by_dXdX_taylortest(self, idx):
        coil = get_coil()
        bs = BiotSavart([coil], [1e4])
        points = np.asarray(
            17 * [[-1.41513202e-03, 8.99999382e-01, -3.14473221e-04]])
        bs.set_points(points)
        dA_by_dX, d2A_by_dXdX = bs.dA_by_dX(), bs.d2A_by_dXdX()
        for d1 in range(3):
            for d2 in range(3):
                second_deriv = d2A_by_dXdX[idx, d1, d2]
                err = 1e6
                for i in range(5, 10):
                    eps = 0.5**i

                    ed2 = np.zeros((1, 3))
                    ed2[0, d2] = 1.

                    bs.set_points(points + eps * ed2)
                    dA_dXp = bs.dA_by_dX()[idx, d1]

                    bs.set_points(points - eps * ed2)
                    dA_dXm = bs.dA_by_dX()[idx, d1]

                    second_deriv_est = (dA_dXp - dA_dXm) / (2. * eps)

                    new_err = np.linalg.norm(second_deriv - second_deriv_est)
                    print("new_err", new_err)
                    assert new_err < 0.30 * err
                    err = new_err
예제 #2
0
    def subtest_biotsavart_dAdX_taylortest(self, idx):
        coil = get_coil()
        bs = BiotSavart([coil], [1e4])
        points = np.asarray(
            17 * [[-1.41513202e-03, 8.99999382e-01, -3.14473221e-04]])
        points += 0.001 * (np.random.rand(*points.shape) - 0.5)
        bs.set_points(points)
        A0 = bs.A()[idx]
        dA = bs.dA_by_dX()[idx]

        for direction in [
                np.asarray((1., 0, 0)),
                np.asarray((0, 1., 0)),
                np.asarray((0, 0, 1.))
        ]:
            deriv = dA.T.dot(direction)
            err = 1e6
            for i in range(5, 10):
                eps = 0.5**i
                bs.set_points(points + eps * direction)
                Aeps = bs.A()[idx]
                deriv_est = (Aeps - A0) / (eps)
                new_err = np.linalg.norm(deriv - deriv_est)
                assert new_err < 0.55 * err
                err = new_err
예제 #3
0
 def test_biotsavart_B_is_curlA(self):
     coil = get_coil()
     bs = BiotSavart([coil], [1e4])
     points = np.asarray(
         17 * [[-1.41513202e-03, 8.99999382e-01, -3.14473221e-04]])
     bs.set_points(points)
     B, dA_by_dX = bs.B(), bs.dA_by_dX()
     curlA1 = dA_by_dX[:, 1, 2] - dA_by_dX[:, 2, 1]
     curlA2 = dA_by_dX[:, 2, 0] - dA_by_dX[:, 0, 2]
     curlA3 = dA_by_dX[:, 0, 1] - dA_by_dX[:, 1, 0]
     curlA = np.concatenate(
         (curlA1[:, None], curlA2[:, None], curlA3[:, None]), axis=1)
     err = np.max(np.abs(curlA - B))
     assert err < 1e-14