def test_ADM_no_rotate(): np.random.seed(2) coil_dipole_pos = np.array( np.meshgrid(np.linspace(-.5, .5, 5), np.linspace(-.5, .5, 5), np.linspace(-.2, .2, 3))).reshape(3, -1).T coil_dipole_weights = np.zeros_like(coil_dipole_pos) coil_dipole_weights[:, 2] = 1 current_elm_positions = np.random.rand(1000, 3) + 10 currents = np.random.rand(len(current_elm_positions), 3) observation_pos = np.random.rand(10, 3) coildir = np.array([[0, 1, 0]]) coil_matrices = np.repeat(np.eye(4)[..., None], len(observation_pos), axis=2) coil_matrices[:3, 3, :] = observation_pos.T E_adm = ADMlib.ADM(current_elm_positions.T, currents.T, coil_dipole_pos.T, coil_dipole_weights.T, coil_matrices, coildir.T) # Total H field in the coil for i, p in enumerate(observation_pos): H = calculate_Hprim(current_elm_positions, currents, coil_dipole_pos + p) E = -np.sum(H * coil_dipole_weights) assert np.allclose(E_adm[0, i], E)
def test_ADM_rotate(): np.random.seed(2) coil_dipole_pos = np.array( np.meshgrid(np.linspace(-.5, .5, 5), np.linspace(-.5, .5, 5), np.linspace(-.2, .2, 3))).reshape(3, -1).T coil_dipole_weights = np.zeros_like(coil_dipole_pos) coil_dipole_weights[:, 2] = 1 current_elm_positions = np.random.rand(1000, 3) + 10 currents = np.random.rand(len(current_elm_positions), 3) observation_pos = np.random.rand(10, 3) coil_dir = [] for angle in np.linspace(np.pi / 2, np.pi, 7): coil_dir.append([-np.sin(angle), np.cos(angle), 0]) coil_dir = np.array(coil_dir) coil_matrices = np.repeat(np.eye(4)[..., None], len(observation_pos), axis=2) coil_matrices[:3, 3, :] = observation_pos.T E_adm = ADMlib.ADM(current_elm_positions.T, currents.T, coil_dipole_pos.T, coil_dipole_weights.T, coil_matrices, coil_dir.T) # Total H field in the coil z = np.array([0, 0, 1]) for i, p in enumerate(observation_pos): for j, cd in enumerate(coil_dir): rotation_matrix = np.array([np.cross(cd, z), cd, z]).T coil_dipole_pos_moved = rotation_matrix.dot( coil_dipole_pos.T).T + p coil_dipole_weights_rot = rotation_matrix.dot( coil_dipole_weights.T).T H = calculate_Hprim(current_elm_positions, currents, coil_dipole_pos_moved) E = -np.sum(H * coil_dipole_weights_rot) assert np.allclose(E_adm[j, i], E)