def test_gmres_sparse(self):
     # Create sparse non-Hermitian problem.
     N = 100
     A = self._create_sparse_nonherm_matrix(N, 5*N*(1+2j), 2)
     rhs = np.ones( (N,1) )
     x0 = np.zeros( (N,1) )
     # Solve using GMRES.
     tol = 1.0e-11
     out = nm.gmres( A, rhs, x0, tol=tol )
     # Make sure the method converged.
     self.assertEqual(out['info'], 0)
     # Check the residual.
     res = rhs - A * out['xk']
     self.assertAlmostEqual( np.linalg.norm(res) / np.linalg.norm(rhs),
                             0.0,
                             delta=tol )
Esempio n. 2
0
 def test_gmres_sparse(self):
     # Create sparse non-Hermitian problem.
     N = 100
     A = self._create_sparse_nonherm_matrix(N, 5 * N * (1 + 2j), 2)
     rhs = np.ones((N, 1))
     x0 = np.zeros((N, 1))
     # Solve using GMRES.
     tol = 1.0e-11
     out = nm.gmres(A, rhs, x0, tol=tol)
     # Make sure the method converged.
     self.assertEqual(out['info'], 0)
     # Check the residual.
     res = rhs - A * out['xk']
     self.assertAlmostEqual(np.linalg.norm(res) / np.linalg.norm(rhs),
                            0.0,
                            delta=tol)
Esempio n. 3
0
 def test_gmres_sparse_Minner(self):
     # Create sparse non-Hermitian problem.
     N = 100
     A = self._create_sparse_nonherm_matrix(N, 5 * N * (1 + 2j), 2)
     rhs = np.ones((N, 1))
     x0 = np.zeros((N, 1))
     M = scipy.sparse.spdiags(range(1, N + 1), [0], N, N)
     # Solve using GMRES.
     tol = 1.0e-11
     out = nm.gmres(A, rhs, x0, tol=tol, M=M)
     # Make sure the method converged.
     self.assertEqual(out['info'], 0)
     # Check the residual.
     res = rhs - A * out['xk']
     Mres = M * res
     norm_res = np.sqrt(np.dot(res.T.conj(), Mres))
     self.assertAlmostEqual(norm_res / np.linalg.norm(rhs), 0.0, delta=tol)
 def test_gmres_sparse_Minner(self):
     # Create sparse non-Hermitian problem.
     N = 100
     A = self._create_sparse_nonherm_matrix(N, 5*N*(1+2j), 2)
     rhs = np.ones( (N,1) )
     x0 = np.zeros( (N,1) )
     M = scipy.sparse.spdiags( range(1,N+1), [0], N, N)
     # Solve using GMRES.
     tol = 1.0e-11
     out = nm.gmres( A, rhs, x0, tol=tol, M=M )
     # Make sure the method converged.
     self.assertEqual(out['info'], 0)
     # Check the residual.
     res = rhs - A * out['xk']
     Mres = M*res
     norm_res = np.sqrt(np.dot(res.T.conj(), Mres))
     self.assertAlmostEqual( norm_res / np.linalg.norm(rhs),
                             0.0,
                             delta=tol )