9#include <gsl/gsl_linalg.h>
37 if (luPtr_) gsl_matrix_free(luPtr_);
38 if (gMatInverse_) gsl_matrix_free(gMatInverse_);
39 if (permPtr_) gsl_permutation_free(permPtr_);
52 luPtr_ = gsl_matrix_alloc(n, n);
53 gMatInverse_ = gsl_matrix_alloc(n, n);
54 permPtr_ = gsl_permutation_alloc(n);
71 for (i = 0; i < n_; ++i) {
72 for (j = 0; j < n_; ++j) {
73 luPtr_->data[k] = A(i,j);
77 gsl_linalg_LU_decomp(luPtr_, permPtr_, &signum_);
94 gsl_linalg_LU_solve(luPtr_, permPtr_, &b_, &x_);
108 gMatInverse_->data = inv.
cArray();
109 gsl_linalg_LU_invert(luPtr_, permPtr_, gMatInverse_);
void inverse(Matrix< double > &inv)
Compute inverse of matrix A.
void allocate(int n)
Allocate memory.
void solve(Array< double > &b, Array< double > &x)
Solve Ax = b for known b to compute x.
void computeLU(const Matrix< double > &A)
Compute the LU decomposition for later use.
Array container class template.
Data * cArray()
Return a pointer to the underlying C array.
int capacity() const
Return allocated size.
Two-dimensional array container template (abstract).
Data * cArray()
Return pointer to underlying one-dimensional C array.
int capacity2() const
Get number of columns (range of the second array index).
int capacity1() const
Get number of rows (range of the first array index).
#define UTIL_CHECK(condition)
Assertion macro suitable for serial or parallel production code.
C++ namespace for polymer self-consistent field theory (PSCF).