std::pair<unsigned int, unsigned int> SlepcEigenSolver<T>::solve_standard (ShellMatrix<T> &shell_matrix, int nev, // number of requested eigenpairs int ncv, // number of basis vectors const double tol, // solver tolerance const unsigned int m_its) // maximum number of iterations { this->init (); int ierr=0; // Prepare the matrix. Mat mat; ierr = MatCreateShell(this->comm().get(), shell_matrix.m(), // Specify the number of local rows shell_matrix.n(), // Specify the number of local columns PETSC_DETERMINE, PETSC_DETERMINE, const_cast<void*>(static_cast<const void*>(&shell_matrix)), &mat); /* Note that the const_cast above is only necessary because PETSc does not accept a const void*. Inside the member function _petsc_shell_matrix() below, the pointer is casted back to a const ShellMatrix<T>*. */ LIBMESH_CHKERRABORT(ierr); ierr = MatShellSetOperation(mat,MATOP_MULT,reinterpret_cast<void(*)(void)>(_petsc_shell_matrix_mult)); ierr = MatShellSetOperation(mat,MATOP_GET_DIAGONAL,reinterpret_cast<void(*)(void)>(_petsc_shell_matrix_get_diagonal)); LIBMESH_CHKERRABORT(ierr); return _solve_standard_helper(mat, nev, ncv, tol, m_its); }
std::pair<unsigned int, unsigned int> SlepcEigenSolver<T>::solve_standard (SparseMatrix<T> &matrix_A_in, int nev, // number of requested eigenpairs int ncv, // number of basis vectors const double tol, // solver tolerance const unsigned int m_its) // maximum number of iterations { // START_LOG("solve_standard()", "SlepcEigenSolver"); this->init (); // Make sure the SparseMatrix passed in is really a PetscMatrix PetscMatrix<T>* matrix_A = libmesh_cast_ptr<PetscMatrix<T>*>(&matrix_A_in); // Close the matrix and vectors in case this wasn't already done. matrix_A->close (); // just for debugging, remove this // char mat_file[] = "matA.petsc"; // PetscViewer petsc_viewer; // ierr = PetscViewerBinaryOpen(this->comm().get(), mat_file, PETSC_FILE_CREATE, &petsc_viewer); // LIBMESH_CHKERRABORT(ierr); // ierr = MatView(matrix_A->mat(),petsc_viewer); // LIBMESH_CHKERRABORT(ierr); return _solve_standard_helper(matrix_A->mat(), nev, ncv, tol, m_its); }
std::pair<unsigned int, unsigned int> SlepcEigenSolver<T>::solve_standard (SparseMatrix<T> & matrix_A_in, int nev, // number of requested eigenpairs int ncv, // number of basis vectors const double tol, // solver tolerance const unsigned int m_its) // maximum number of iterations { LOG_SCOPE("solve_standard()", "SlepcEigenSolver"); this->init (); // Make sure the SparseMatrix passed in is really a PetscMatrix PetscMatrix<T> * matrix_A = dynamic_cast<PetscMatrix<T> *>(&matrix_A_in); if (!matrix_A) libmesh_error_msg("Error: input matrix to solve_standard() must be a PetscMatrix."); // Close the matrix and vectors in case this wasn't already done. if (this->_close_matrix_before_solve) matrix_A->close (); return _solve_standard_helper(matrix_A->mat(), nev, ncv, tol, m_its); }