def test_decimals(self): h1 = [2, 1, 1, 2] h2 = [2, 1.04, 1.04, 2] grid1 = emg3d.TensorMesh([h1, h1, h1], (-3, -3, -3)) grid2 = emg3d.TensorMesh([h2, h2, h2], (-3, -3, -3)) source = np.array([[-0.5, 0, 0], [0.5, 0, 0]]) sfield1 = fields._dipole_vector(grid1, source) sfield2a = fields._dipole_vector(grid2, source, decimals=1) sfield2b = fields._dipole_vector(grid2, source) assert_allclose(sfield1.fx, sfield2a.fx) with pytest.raises(AssertionError, match='Not equal to tolerance'): assert_allclose(sfield1.fx, sfield2b.fx)
def test_basics_diag(self): h = [2, 1, 1, 2] grid = emg3d.TensorMesh([h, h, h], (-3, -3, -3)) # Diagonal source in the middle source = np.array([[-0.5, -0.5, -0.5], [0.5, 0.5, 0.5]]) vfield = fields._dipole_vector(grid, source) # x: exact in the middle on the two edges assert_allclose(vfield.fx[1:-2, 1:-2, 1:-2].ravel(), [0.03125, 0.09375, 0.09375, 0.28125]) # compare lower-left-front with upper-right-back assert_allclose(vfield.fx[1:-2, 1:-2, 1:-2].ravel(), vfield.fx[2:-1, 2:-1, 2:-1].ravel()[::-1]) # Source is 3D symmetric, compare all fields are the same assert_allclose(vfield.fx[1:-2, 1:-2, 1:-2].ravel(), vfield.fy[1:-2, 1:-2, 1:-2].ravel()) assert_allclose(vfield.fx[1:-2, 1:-2, 1:-2].ravel(), vfield.fz[1:-2, 1:-2, 1:-2].ravel()) assert_allclose(vfield.fx[2:-1, 2:-1, 2:-1].ravel(), vfield.fy[2:-1, 2:-1, 2:-1].ravel()) assert_allclose(vfield.fx[2:-1, 2:-1, 2:-1].ravel(), vfield.fz[2:-1, 2:-1, 2:-1].ravel())
def test_basics_xdir_on_x(self): h = [2, 1, 1, 2] grid = emg3d.TensorMesh([h, h, h], (-3, -3, -3)) # x-directed source in the middle source = np.array([[-0.5, 0, 0], [0.5, 0, 0]]) vfield = fields._dipole_vector(grid, source) # x: exact in the middle on the two edges assert_allclose(vfield.fx[1:-1, 2:-2, 2:-2].ravel(), [0.5, 0.5]) # y: as exact "on" x-grid, falls to the right assert_allclose(vfield.fy[1:-1, 2:-1, 2:-2].ravel(), 0) # z: as exact "on" x-grid, falls to top assert_allclose(vfield.fz[1:-1, 2:-2, 2:-1].ravel(), 0)
def test_warnings(self): h = np.ones(4) grid = emg3d.TensorMesh([h, h, h], (0, 0, 0)) source = np.array([[5, 2, 2], [2, 2, 2]]) with pytest.raises(ValueError, match='Provided source outside grid'): fields._dipole_vector(grid, source) source = np.array([[2, 2, 2], [2, 2, 2]]) with pytest.raises(ValueError, match='Provided finite dipole'): fields._dipole_vector(grid, source) # This is a warning that should never be raised... hx, x0 = np.ones(4), -2 grid = emg3d.TensorMesh([hx, hx, hx], (x0, x0, x0)) source = np.array([[-2, 2, 0], [0, -2, 0]]) with pytest.warns(UserWarning, match="Normalizing Source: 1.25000000"): fields._dipole_vector(grid, source, 30)
def test_basics_diag_large(self): h = [2, 1, 1, 2] grid = emg3d.TensorMesh([h, h, h], (-3, -3, -3)) # Large diagonal source in the middle source = np.array([[-2.5, -2.5, -2.5], [2.5, 2.5, 2.5]]) vfield = fields._dipole_vector(grid, source) # Source is 3D symmetric, compare all fields are the same assert_allclose(vfield.fx[0, :2, :2].ravel(), vfield.fy[:2, 0, :2].ravel()) assert_allclose(vfield.fx[0, :2, :2].ravel(), vfield.fz[:2, :2, 0].ravel()) assert_allclose(vfield.fx[1, 1:3, 1:3].ravel(), vfield.fy[1:3, 1, 1:3].ravel()) assert_allclose(vfield.fx[1, 1:3, 1:3].ravel(), vfield.fz[1:3, 1:3, 1].ravel()) assert_allclose(vfield.fx[0, :2, :2].ravel(), vfield.fx[3, 3:, 3:].ravel()[::-1]) assert_allclose(vfield.fx[1, 1:3, 1:3].ravel(), vfield.fx[2, 2:4, 2:4].ravel()[::-1])