3 //#include <CHOLMOD/cholmod.h>
13 bool CSolver::solve(const CSparseMatrix
& A_in
, CVectorD
& x_out
, const CVectorD
& b_in
) {
14 // To support this function, a massive amount of third party code would have to be added to the project,
15 // which is not desirable. There is already one custom UV unwrapping function, which does an OK job ...
17 assert(A_in
.n() == A_in
.m()) ;
18 assert(A_in
.has_symmetric_storage()) ;
20 // Step 1: initialize CHOLMOD library
21 //----------------------------------------------------
26 int NNZ
= A_in
.nnz() ;
28 // Step 2: translate sparse matrix into cholmod format
29 //---------------------------------------------------------------------------
30 cholmod_sparse
* A
= cholmod_allocate_sparse(N
, N
, NNZ
, false, true, -1, CHOLMOD_REAL
, &c
);
32 int* colptr
= static_cast<int*>(A
->p
) ;
33 int* rowind
= static_cast<int*>(A
->i
) ;
34 double* a
= static_cast<double*>(A
->x
) ;
36 // Convert Graphite Matrix into CHOLMOD Matrix
38 for(int j
=0; j
<N
; j
++) {
39 const CSparseMatrix::Column
& Cj
= A_in
.column(j
) ;
41 for(int ii
=0; ii
<Cj
.nb_coeffs(); ii
++) {
42 a
[count
] = Cj
.coeff(ii
).a
;
43 rowind
[count
] = Cj
.coeff(ii
).index
;
50 // Step 2: construct right-hand side
51 cholmod_dense
* b
= cholmod_allocate_dense(N
, 1, N
, CHOLMOD_REAL
, &c
) ;
52 memcpy(b
->x
, b_in
.data(), N
* sizeof(double)) ;
55 cholmod_factor
* L
= cholmod_analyze(A
, &c
) ;
56 cholmod_factorize(A
, L
, &c
) ;
57 cholmod_dense
* x
= cholmod_solve(CHOLMOD_A
, L
, b
, &c
) ;
58 memcpy(x_out
.data(), x
->x
, N
* sizeof(double)) ;
61 cholmod_free_factor(&L
, &c
) ;
62 cholmod_free_sparse(&A
, &c
) ;
63 cholmod_free_dense(&x
, &c
) ;
64 cholmod_free_dense(&b
, &c
) ;
72 bool CSolver::needs_rows() const {
76 bool CSolver::needs_columns() const {
80 bool CSolver::supports_symmetric_storage() const {