Skip to content
Snippets Groups Projects
Commit 655458b4 authored by Sebastien Blaise's avatar Sebastien Blaise
Browse files

Added LU factorization and substitution to fullMatrix

parent 4baacdf3
No related branches found
No related tags found
No related merge requests found
......@@ -208,6 +208,8 @@ extern "C" {
void F77NAME(dgesv)(int *N, int *nrhs, double *A, int *lda, int *ipiv,
double *b, int *ldb, int *info);
void F77NAME(dgetrf)(int *M, int *N, double *A, int *lda, int *ipiv, int *info);
void F77NAME(dgetrs)(char *trans, int *N, int *nrhs, double *A, int *lda, int *ipiv,
double *b, int *ldb, int *info);
void F77NAME(dgetri)(int *M, double *A, int *lda, int *ipiv, double *work,
int *lwork, int *info);
void F77NAME(dgesvd)(const char* jobu, const char *jobvt, int *M, int *N,
......@@ -284,10 +286,29 @@ bool fullMatrix<double>::luSolve(const fullVector<double> &rhs, fullVector<doubl
F77NAME(dgesv)(&N, &nrhs, _data, &lda, ipiv, result._data, &ldb, &info);
delete [] ipiv;
if(info == 0) return true;
// if(info > 0)
// Msg::Error("U(%d,%d)=0 in LU decomposition", info, info);
// else
// Msg::Error("Wrong %d-th argument in LU decomposition", -info);
return false;
}
template<>
bool fullMatrix<double>::luFactor()
{
int M = size1(), N = size2(), lda = size1(), info;
int *ipiv = new int[std::min(M, N)];
F77NAME(dgetrf)(&M, &N, _data, &lda, ipiv, &info);
delete [] ipiv;
if(info == 0) return true;
return false;
}
template<>
bool fullMatrix<double>::luSubstitute(const fullVector<double> &rhs, fullVector<double> &result)
{
int N = size1(), nrhs=1, lda = N, ldb = N, info;
int *ipiv = new int[N];
for(int i = 0; i < N; i++) result(i) = rhs(i);
F77NAME(dgetrs)("N", &N, &nrhs, _data, &lda, ipiv, result._data, &ldb, &info);
delete [] ipiv;
if(info == 0) return true;
return false;
}
......
......@@ -679,11 +679,27 @@ class fullMatrix
}
}
bool luSolve(const fullVector<scalar> &rhs, fullVector<scalar> &result)
#if !defined(HAVE_LAPACK)
{
Msg::Error("LU factorization and substitution requires LAPACK");
return false;
}
#endif
;
bool luFactor()
#if !defined(HAVE_LAPACK)
{
Msg::Error("LU factorization requires LAPACK");
return false;
}
#endif
;
bool luSubstitute(const fullVector<double> &rhs, fullVector<double> &result)
#if !defined(HAVE_LAPACK)
{
Msg::Error("LU substitution requires LAPACK");
return false;
}
#endif
;
bool invertInPlace()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment