Added solver for band matrix and a test example.

This commit is contained in:
Xavier Raynaud
2012-03-15 16:17:16 +01:00
parent 153fee692a
commit 7fa98bc5ae
2 changed files with 61 additions and 3 deletions

View File

@@ -34,6 +34,7 @@ extern "C" {
#define MAT_SIZE_T int
#endif
/* C <- a1*op(A)*op(B) + a2*C where op(X) in {X, X.'} */
void dgemm_(const char *transA , const char *transB ,
const MAT_SIZE_T* m, const MAT_SIZE_T* n , const MAT_SIZE_T* k ,
@@ -81,6 +82,18 @@ void dgtsv_(const MAT_SIZE_T *n ,
const MAT_SIZE_T *ldb ,
MAT_SIZE_T *info);
/* B <- A \ B, band matrix A stored in AB with kl subdiagonals, ku superdiagonals */
void dgbsv_(const MAT_SIZE_T *n ,
const MAT_SIZE_T *kl ,
const MAT_SIZE_T *ku ,
const MAT_SIZE_T *nrhs ,
double *AB ,
const MAT_SIZE_T *ldab ,
MAT_SIZE_T *ipiv ,
double *B ,
const MAT_SIZE_T *ldb ,
MAT_SIZE_T *info);
/* A <- chol(A) */
void dpotrf_(const char *uplo, const MAT_SIZE_T *n,
double *A , const MAT_SIZE_T *lda,

View File

@@ -19,6 +19,8 @@
#include <opm/core/linalg/blas_lapack.h>
#include <iostream>
#include <vector>
int main()
{
@@ -27,15 +29,58 @@ int main()
double DU[N-1] = { 2.1, -1.0, 1.9, 8.0 };
double D[N] = { 3.0, 2.3, -5.0, -0.9, 7.1 };
double DL[N-1] = { 3.4, 3.6, 7.0, -6.0 };
double B[N] = { 2.7, -0.5, 2.6, 0.6, 2.7 };
double B[N] = { 2.7, -0.5, 2.6, 0.6, 2.7 };
// double B[N] = { 2.7, -0.5, 2.6, 0.6, 2.7 };
int info = 0;
dgtsv_(&N, &nrhs, DL, D, DU, B, &N, &info);
if (info == 0) {
for (int i = 0; i < N; ++i) {
std::cout << B[i] << ' ';
}
std::cout << std::endl;
} else {
std::cerr << "Something went wrong in dgtsv_()\n";
}
//test of dgbsv_
const int kl = 1;
const int ku = 1;
const int nrowAB = 2*kl + ku + 1;
const int ldb = N;
const int ldab = nrowAB;
int ipiv;
std::vector<double> AB(nrowAB*N, 0.);
std::vector<double> BB(N, 0.);
double ABu[N] = { 0., 2.1, -1.0, 1.9, 8.0};
double ABd[N] = { 3.0, 2.3, -5.0, -0.9, 7.1 };
double ABl[N] = { 3.4, 3.6, 7.0, - 6.0, 0. };
for (int i = 0; i<N; ++i) {
AB[kl + i*nrowAB] = ABu[i];
AB[kl + 1 + i*nrowAB] = ABd[i];
AB[kl + 2 + i*nrowAB] = ABl[i];
}
BB[0] = 2.7;
BB[1] = -0.5;
BB[2] = 2.6;
BB[3] = 0.6;
BB[4] = 2.7;
std::vector<double>::iterator it;
std::cout << "myvector contains:";
for ( it=AB.begin() ; it < AB.end(); it++ ) {
std::cout << " " << *it;
}
std::cout << std::endl;
dgbsv_(&N, &kl, &ku, &nrhs, &AB[0], &ldab, &ipiv, &BB[0], &ldb, &info);
if (info == 0) {
for (int i = 0; i < N; ++i) {
std::cout << B[i] << ' ';
std::cout << BB[i] << ' ';
}
std::cout << std::endl;
} else {
std::cerr << "Something went wrong in dgtsv_()\n";
std::cerr << "Something went wrong in dgbsv_()\n";
}
}