Ejemplo n.º 1
0
//====================================================================================================================
int invert(DenseMatrix& A, size_t nn)
{
    integer n = static_cast<int>(nn != npos ? nn : A.nRows());
    int info=0;
    ct_dgetrf(n, n, A.ptrColumn(0), static_cast<int>(A.nRows()),
              &A.ipiv()[0], info);
    if (info != 0) {
        if (A.m_printLevel) {
            writelogf("invert(DenseMatrix& A, int nn): DGETRS returned INFO = %d\n", info);
        }
        if (! A.m_useReturnErrorCode) {
            throw CELapackError("invert(DenseMatrix& A, int nn)", "DGETRS returned INFO = "+int2str(info));
        }
        return info;
    }

    vector_fp work(n);
    integer lwork = static_cast<int>(work.size());
    ct_dgetri(n, A.ptrColumn(0), static_cast<int>(A.nRows()),
              &A.ipiv()[0],  &work[0], lwork, info);
    if (info != 0) {
        if (A.m_printLevel) {
            writelogf("invert(DenseMatrix& A, int nn): DGETRS returned INFO = %d\n", info);
        }
        if (! A.m_useReturnErrorCode) {
            throw CELapackError("invert(DenseMatrix& A, int nn)", "DGETRI returned INFO="+int2str(info));
        }
    }
    return info;
}
Ejemplo n.º 2
0
  //====================================================================================================================
  int solve(DenseMatrix& A, DenseMatrix& b) {
    int info = 0;
    if (A.nColumns() != A.nRows()) {
      if (A.m_printLevel) {
	writelogf("solve(DenseMatrix& A, DenseMatrix& b): Can only solve a square matrix\n");
      }  
      if (! A.m_useReturnErrorCode) {
	throw CELapackError("solve(DenseMatrix& A, DenseMatrix& b)", "Can only solve a square matrix");
      }
      return -1;
    }
    ct_dgetrf(static_cast<int>(A.nRows()), 
	      static_cast<int>(A.nColumns()), A.ptrColumn(0), 
	      static_cast<int>(A.nRows()), &A.ipiv()[0], info);
    if (info != 0) {
      if (info > 0) {
        if (A.m_printLevel) {
	  writelogf("solve(DenseMatrix& A, DenseMatrix& b): DGETRF returned INFO = %d   U(i,i) is exactly zero. The factorization has"
		    " been completed, but the factor U is exactly singular, and division by zero will occur if "
		    "it is used to solve a system of equations.\n", info);
        }
        if (! A.m_useReturnErrorCode) {
          throw CELapackError("solve(DenseMatrix& A, DenseMatrix& b)",
			     "DGETRF returned INFO = "+int2str(info) + ".   U(i,i) is exactly zero. The factorization has"
			     " been completed, but the factor U is exactly singular, and division by zero will occur if "
			     "it is used to solve a system of equations.");
        }
      } else {
	if (A.m_printLevel) {
	  writelogf("solve(DenseMatrix& A, DenseMatrix& b): DGETRF returned INFO = %d. The argument i has an illegal value\n", info);
	}
	if (! A.m_useReturnErrorCode) {
	  throw CELapackError("solve(DenseMatrix& A, DenseMatrix& b)",
			     "DGETRF returned INFO = "+int2str(info) + ". The argument i has an illegal value");
	}
      }
      return info;
    }
  
    ct_dgetrs(ctlapack::NoTranspose, static_cast<int>(A.nRows()),
	      static_cast<int>(b.nColumns()), 
	      A.ptrColumn(0), static_cast<int>(A.nRows()), 
	      &A.ipiv()[0], b.ptrColumn(0), 
	      static_cast<int>(b.nRows()), info);
    if (info != 0) {
      if (A.m_printLevel) {
	writelogf("solve(DenseMatrix& A, DenseMatrix& b): DGETRS returned INFO = %d\n", info);
      }
      if (! A.m_useReturnErrorCode) {
        throw CELapackError("solve(DenseMatrix& A, DenseMatrix& b)", "DGETRS returned INFO = "+int2str(info));
      }
    }
  
    return info;
  }
Ejemplo n.º 3
0
 int solve(DenseMatrix& A, DenseMatrix& b) {
     int info=0;
     ct_dgetrf(static_cast<int>(A.nRows()), 
         static_cast<int>(A.nColumns()), A.ptrColumn(0), 
         static_cast<int>(A.nRows()), &A.ipiv()[0], info);
     if (info != 0) 
         throw CanteraError("DenseMatrix::solve",
             "DGETRF returned INFO = "+int2str(info)); 
     ct_dgetrs(ctlapack::NoTranspose, static_cast<int>(A.nRows()),
         static_cast<int>(b.nColumns()), 
         A.ptrColumn(0), static_cast<int>(A.nRows()), 
         &A.ipiv()[0], b.ptrColumn(0), 
         static_cast<int>(b.nRows()), info);
     if (info != 0)
         throw CanteraError("DenseMatrix::solve",
             "DGETRS returned INFO = "+int2str(info));
     return 0;
 }
Ejemplo n.º 4
0
    int invert(DenseMatrix& A, int nn) {
        integer n = (nn > 0 ? nn : static_cast<int>(A.nRows()));
        int info=0;
        ct_dgetrf(n, n, A.ptrColumn(0), static_cast<int>(A.nRows()), 
            &A.ipiv()[0], info);
        if (info != 0) 
            throw CanteraError("invert",
                "DGETRF returned INFO="+int2str(info));

        vector_fp work(n);
        integer lwork = static_cast<int>(work.size()); 
        ct_dgetri(n, A.ptrColumn(0), static_cast<int>(A.nRows()),
            &A.ipiv()[0], 
            &work[0], lwork, info);
        if (info != 0) 
            throw CanteraError("invert",
                "DGETRI returned INFO="+int2str(info));
        return 0;
    }
Ejemplo n.º 5
0
 /*
  *   @param y Object to be copied
  */
 DenseMatrix::DenseMatrix(const DenseMatrix& y) :
   Array2D(y),
   m_ipiv(0),
   m_useReturnErrorCode(0),
   m_printLevel(0)
 {
   m_ipiv = y.ipiv();
   m_colPts.resize(m_ncols);
   for (int j = 0; j < m_ncols; j++) {
     m_colPts[j] = &(m_data[m_nrows*j]);
   }
 }