示例#1
0
    def test_biotsavart_coil_current_taylortest(self):
        coil0 = get_coil()
        current0 = 1e4
        coil1 = get_coil(perturb=True)
        current1 = 1e3
        bs = BiotSavart([coil0, coil1], [current0, current1])
        points = np.asarray(
            17 * [[-1.41513202e-03, 8.99999382e-01, -3.14473221e-04]])
        bs.set_points(points)
        B = bs.B()
        J = bs.dB_by_dX()
        H = bs.d2B_by_dXdX()
        dB = bs.dB_by_dcoilcurrents()
        dJ = bs.d2B_by_dXdcoilcurrents()
        dH = bs.d3B_by_dXdXdcoilcurrents()

        h = 1.
        bs.currents_optim[0].set_dofs(1e4 + h)
        bs.invalidate_cache()
        Bp = bs.B()
        Jp = bs.dB_by_dX()
        Hp = bs.d2B_by_dXdX()
        bs.currents_optim[0].set_dofs(1e4 - h)
        bs.invalidate_cache()
        Bm = bs.B()
        Jm = bs.dB_by_dX()
        Hm = bs.d2B_by_dXdX()
        dB_approx = (Bp - Bm) / (2 * h)
        dJ_approx = (Jp - Jm) / (2 * h)
        dH_approx = (Hp - Hm) / (2 * h)
        assert np.linalg.norm(dB[0] - dB_approx) < 1e-15
        assert np.linalg.norm(dJ[0] - dJ_approx) < 1e-15
        assert np.linalg.norm(dH[0] - dH_approx) < 1e-13
示例#2
0
    def subtest_biotsavart_d2B_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)
        dB_by_dX, d2B_by_dXdX = bs.dB_by_dX(), bs.d2B_by_dXdX()
        for d1 in range(3):
            for d2 in range(3):
                second_deriv = d2B_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)
                    dB_dXp = bs.dB_by_dX()[idx, d1]

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

                    second_deriv_est = (dB_dXp - dB_dXm) / (2. * eps)

                    new_err = np.linalg.norm(second_deriv - second_deriv_est)
                    assert new_err < 0.30 * err
                    err = new_err
示例#3
0
 def subtest_d2B_by_dXdX_is_symmetric(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)
     d2B_by_dXdX = bs.d2B_by_dXdX()
     for i in range(3):
         assert np.allclose(d2B_by_dXdX[idx, :, :, i],
                            d2B_by_dXdX[idx, :, :, i].T)