コード例 #1
0
ファイル: DenseMatrix.cpp プロジェクト: anujg1991/cantera
//====================================================================================================================
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(A.nRows(), A.nColumns(), A.ptrColumn(0),
              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, A.nRows(), b.nColumns(), A.ptrColumn(0),
              A.nRows(), &A.ipiv()[0], b.ptrColumn(0), 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;
}
コード例 #2
0
 double special_sum(DenseMatrix M) {
     double sum = 0;
     for (size_t i = 0; i < M.nRows(); i++) {
         for (size_t j = 0; j < M.nColumns(); j++) {
             sum += M(i,j) * (i+2*j+1);
         }
     }
     return sum;
 }
コード例 #3
0
ファイル: DenseMatrix.cpp プロジェクト: anujg1991/cantera
 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;
 }
コード例 #4
0
ファイル: DenseMatrix.cpp プロジェクト: anujg1991/cantera
    /** @todo fix lwork */
    int leastSquares(DenseMatrix& A, double* b) {
        int info = 0;
        int rank = 0;
        double rcond = -1.0;
        // fix this!
        int lwork = 6000; // 2*(3*min(m,n) + max(2*min(m,n), max(m,n)));
        vector_fp work(lwork);
        vector_fp s(min(static_cast<int>(A.nRows()),
					    static_cast<int>(A.nColumns())));
        ct_dgelss(static_cast<int>(A.nRows()), 
            static_cast<int>(A.nColumns()), 1, A.ptrColumn(0), 
            static_cast<int>(A.nRows()), b, 
            static_cast<int>(A.nColumns()), &s[0], //.begin(),
            rcond, rank, &work[0], work.size(), info);
        if (info != 0) 
            throw CanteraError("DenseMatrix::leaseSquares",
                "DGELSS returned INFO = "+int2str(info));
        return 0; 
    }
コード例 #5
0
ファイル: DenseMatrix.cpp プロジェクト: anujg1991/cantera
    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;
    }
コード例 #6
0
ファイル: DenseMatrix.cpp プロジェクト: anujg1991/cantera
void DenseMatrix::mult(const DenseMatrix& B, DenseMatrix& prod) const
{
    if (m_ncols != B.nColumns() || m_nrows != B.nRows() || m_ncols != m_nrows || m_ncols != prod.nColumns() || m_nrows != prod.nColumns()) {
        throw CanteraError("mult(const DenseMatrix &B, DenseMatrix &prod)",
                           "Cannot multiply matrices that are not square and/or not the same size.");
    }
    const doublereal* const* bcols = B.const_colPts();
    doublereal* const* prodcols = prod.colPts();
    for (size_t col=0; col < m_ncols; ++col) {
        // Loop over ncols multiplying A*column of B and storing in corresponding prod column
        mult(bcols[col], prodcols[col]);
    }
}
コード例 #7
0
ファイル: DenseMatrix.cpp プロジェクト: hkmoffat/cantera
  /** @todo fix lwork */
  int leastSquares(DenseMatrix& A, double* b) {
    int info = 0;
    int rank = 0;
    double rcond = -1.0;
    // fix this!
    int lwork = 6000; // 2*(3*min(m,n) + max(2*min(m,n), max(m,n)));
    vector_fp work(lwork);
    vector_fp s(min(static_cast<int>(A.nRows()),
		    static_cast<int>(A.nColumns())));
    ct_dgelss(static_cast<int>(A.nRows()), 
	      static_cast<int>(A.nColumns()), 1, A.ptrColumn(0), 
	      static_cast<int>(A.nRows()), b, 
	      static_cast<int>(A.nColumns()), &s[0], //.begin(),
	      rcond, rank, &work[0], work.size(), info);
    if (info != 0) {
      if (A.m_printLevel) {
	writelogf("leastSquares(): DGELSS returned INFO = %d\n", info);
      }
      if (! A.m_useReturnErrorCode) {
	throw CELapackError("leastSquares()", "DGELSS returned INFO = " + int2str(info));
      }
    }
    return info; 
  }
コード例 #8
0
DenseMatrix<double> ParSparseMatrix<double>::transMat(
    const DenseMatrix<double>& B) const {
  SparseMatrix<double>::compress(*this);
  GCK(*this, B, this->nRows() != B.nRows(), "ParSparseMatrix transpose * Matrix")

  DenseMatrix<double> C(nCols(), B.nCols(), true);

  SparseMatrix<double> A_local;
  partition(*static_cast<ParSparseMatrix<double>*>(&A_local));

  // actually do multiplication - end up with partial result matrix
  // on each processor
  DenseMatrix<double> C_local = A_local.transMat(B);

  static_cast<ParSparseMatrix<double>*>(&A_local)->finalize();

  // Add all the result vectors together on each processor.
  allsum(_comm, C_local.ptr(), C.ptr(), C_local.size());

  return C;
}
コード例 #9
0
ファイル: DenseMatrix.cpp プロジェクト: anujg1991/cantera
//====================================================================================================================
void increment(const DenseMatrix& A, const double* b, double* prod)
{
    ct_dgemv(ctlapack::ColMajor, ctlapack::NoTranspose,
             static_cast<int>(A.nRows()), static_cast<int>(A.nRows()), 1.0,
             A.ptrColumn(0), static_cast<int>(A.nRows()), b, 1, 1.0, prod, 1);
}
コード例 #10
0
ファイル: DenseMatrix.cpp プロジェクト: anujg1991/cantera
//====================================================================================================================
void multiply(const DenseMatrix& A, const double* const b, double* const prod)
{
    ct_dgemv(ctlapack::ColMajor, ctlapack::NoTranspose,
             static_cast<int>(A.nRows()), static_cast<int>(A.nColumns()), 1.0,
             A.ptrColumn(0), static_cast<int>(A.nRows()), b, 1, 0.0, prod, 1);
}
コード例 #11
0
ファイル: DenseMatrix.cpp プロジェクト: anujg1991/cantera
int solve(DenseMatrix& A, DenseMatrix& b)
{
    return solve(A, b.ptrColumn(0), b.nColumns(), b.nRows());
}