def test_move_dipole_xyz(self, quadrant_points): v = sphere.potential_dipole_3layers([0.8, 0.9, 1], 1., 1., [0.3, 0.3, 0.3], [1, 0, 0], quadrant_points) v2 = sphere.potential_dipole_3layers([0.8, 0.9, 1], 1., 1., [-0.3, -0.3, -0.3], [-1, 0, 0], -quadrant_points) np.testing.assert_almost_equal(v, v2)
def test_rotate_and_move_dipole(self, quadrant_points): vx = sphere.potential_dipole_3layers( [0.8, 0.9, 1.], 1., 1., [0.5, 0, 0], [1, 0, 0], quadrant_points) M = np.array([[0, 1, 0], [1, 0, 0], [0, 0, 1]]) vy = sphere.potential_dipole_3layers( [0.8, 0.9, 1.], 1., 1., [0, 0.5, 0], [0, 1, 0], M.dot(quadrant_points.T).T) M = np.array([[0, 0, 1], [0, 1, 0], [1, 0, 0]]) vz = sphere.potential_dipole_3layers( [0.8, 0.9, 1.], 1., 1., [0, 0, 0.5], [0, 0, 1], M.dot(quadrant_points.T).T) np.testing.assert_allclose(vx, vy) np.testing.assert_allclose(vx, vz)
def test_compare_homogeneous(self, quadrant_points): p = sphere.fibonacci_sphere(11, 2) v1 = sphere.potential_dipole_3layers( [0.8, 0.9, 2], 1., 1., [0, 0, 0.5], [1, 1, 1], p, 500) v2 = sphere.potential_homogeneous_dipole( 2., 1., [0, 0, 0.5], [1, 1, 1], p) assert np.allclose(v1, v2)
def test_single_dipole(self, dipole_direction, pos_target, sphere3_msh): bar = sphere3_msh.elements_baricenters()[sphere3_msh.elm.tetrahedra] vol = sphere3_msh.elements_volumes_and_areas() dipole_th = np.argmin(np.linalg.norm(pos_target - bar, axis=1)) dipole_pos = bar[dipole_th] dipole_th = sphere3_msh.elm.tetrahedra[dipole_th] surface_nodes = np.unique( sphere3_msh.elm[sphere3_msh.elm.tag1 == 1005, :3]) surface_nodes_pos = sphere3_msh.nodes[surface_nodes] analytical_v = analytical_solutions.potential_dipole_3layers( [85, 90, 95], 2, 0.1, dipole_pos, dipole_direction, surface_nodes_pos) # Relationship between primary current J and dipole vector p # p = \int J dV # p = J*V_i # J = p/V_i primary_j = mesh_io.ElementData(np.zeros((sphere3_msh.elm.nr, 3))) primary_j[dipole_th] = dipole_direction / (vol[dipole_th] * 1e-9) cond = 2 * np.ones(sphere3_msh.elm.nr) cond[sphere3_msh.elm.tag1 == 4] = 0.1 S = fem.FEMSystem.electric_dipole(sphere3_msh, cond) b = S.assemble_electric_dipole_rhs(primary_j) numerical_v = S.solve(b)[surface_nodes - 1] analytical_v -= np.average(analytical_v) numerical_v -= np.average(numerical_v) assert rdm(analytical_v, numerical_v) < 0.2 assert mag(analytical_v, numerical_v) < 0.15
def test_tangential_dipole(self, quadrant_points): ''' Tests the relationship between a 3-sphere and single sphere model, Ari et. al 1998 ''' b_bar = 0.5 b_tilde = 0.316 m_bar = 1. m_tilde = 1./1.531 V_3layers = sphere.potential_dipole_3layers([.87, .92, 1.], 1., .0125, [b_bar, 0, 0], [0, m_bar, 0], quadrant_points) V_homo = sphere.potential_homogeneous_dipole(1., 1., [b_tilde, 0, 0], [0, m_tilde, 0], quadrant_points) assert np.allclose(V_3layers, V_homo, rtol=5e-2)
def test_tilt_dipole_x(self, quadrant_points): v = sphere.potential_dipole_3layers( [0.8, 0.9, 1], 1., 1., [0, 0, 0], [1, 0, 0], quadrant_points) np.testing.assert_almost_equal(v[quadrant_points[:, 0] > 0], -v[quadrant_points[:, 0] < 0])
def test_symmetry_z_axis(self, quadrant_points): v = sphere.potential_dipole_3layers( [0.8, 0.9, 1], 1., 1., [0, 0, 0], [0, 0, 1], quadrant_points) np.testing.assert_almost_equal(v[quadrant_points[:, 2] > 0], -v[quadrant_points[:, 2] < 0])
def test_dipole_source_at_center(self): points = np.array([[0, 0.7071, 0.7071]]) v = sphere.potential_dipole_3layers( [0.8, 0.9, 1], 1., 1., [0, 0, 0], [0, 0, 1], points, 1) v_simple = 3 / (4 * np.pi * 1e-6) * (1 / np.sqrt(2)) assert np.abs((v[0] - v_simple) / v_simple) < 1e-3