2014-03-07 137 views
0

我正在寫一個基本的有限元程序使用犰狳。我使用sp_matvec作爲矩陣和矢量類型。問題是,當我做solve(X, b)我得到一個錯誤。難道是solve不支持sp_mat。除了使用密集矩陣之外的其他選擇?以下是sp_mat未編譯的代碼。如果我使用註釋行mat A,它可以正常工作。犰狳:解決與sp_mat

int N = 3; 
double h = 1./N; 

//mat A = zeros<mat>(N+1,N+1); 
sp_mat A(N+1,N+1); 
for(int i=0;i<=N;i++) { 
    if(i>0) {A(i,i-1)=-1.;} 
    A(i,i)=2.; 
    if(i<N) {A(i,i+1)=-1.;} 
} 
A(N,N)=1; 

vec b = zeros(N+1); 
for(int i=0;i<=N;i++) { 
    b(i)=h; 
} 

vec zeta = solve(A,b); 
cout << zeta; 

錯誤:在犰狳

make all 
Building file: ../src/FEM.cpp 
Invoking: GCC C++ Compiler 
g++ -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"src/FEM.d" -MT"src/FEM.d" -o "src/FEM.o" "../src/FEM.cpp" 
../src/FEM.cpp: In function ‘int main()’: 
../src/FEM.cpp:37:22: error: no matching function for call to ‘solve(arma::sp_mat&, arma::vec&)’ 
    vec zeta = solve(A,b); 
        ^
../src/FEM.cpp:37:22: note: candidates are: 
In file included from /usr/include/armadillo:397:0, 
       from ../src/FEM.cpp:10: 
/usr/include/armadillo_bits/fn_solve.hpp:25:1: note: template<class T1, class T2> const arma::Glue<T1, T2, arma::glue_solve> arma::solve(const arma::Base<typename T1::elem_type, T1>&, const arma::Base<typename T1::elem_type, T2>&, bool, const typename arma::arma_blas_type_only<typename T1::elem_type>::result*) 
solve 
^ 
/usr/include/armadillo_bits/fn_solve.hpp:25:1: note: template argument deduction/substitution failed: 
../src/FEM.cpp:37:22: note: ‘arma::sp_mat {aka arma::SpMat<double>}’ is not derived from ‘const arma::Base<typename T1::elem_type, T1>’ 
    vec zeta = solve(A,b); 
        ^
In file included from /usr/include/armadillo:397:0, 
       from ../src/FEM.cpp:10: 
/usr/include/armadillo_bits/fn_solve.hpp:44:1: note: template<class T1, class T2> const arma::Glue<T1, T2, arma::glue_solve> arma::solve(const arma::Base<typename T1::elem_type, T1>&, const arma::Base<typename T1::elem_type, T2>&, const char*, const typename arma::arma_blas_type_only<typename T1::elem_type>::result*) 
solve 
^ 
/usr/include/armadillo_bits/fn_solve.hpp:44:1: note: template argument deduction/substitution failed: 
../src/FEM.cpp:37:22: note: ‘arma::sp_mat {aka arma::SpMat<double>}’ is not derived from ‘const arma::Base<typename T1::elem_type, T1>’ 
    vec zeta = solve(A,b); 
        ^
In file included from /usr/include/armadillo:397:0, 
       from ../src/FEM.cpp:10: 
/usr/include/armadillo_bits/fn_solve.hpp:67:1: note: template<class T1, class T2> const arma::Glue<T1, T2, arma::glue_solve_tr> arma::solve(const arma::Op<T1, arma::op_trimat>&, const arma::Base<typename T1::elem_type, T2>&, bool, const typename arma::arma_blas_type_only<typename T1::elem_type>::result*) 
solve 
^ 
/usr/include/armadillo_bits/fn_solve.hpp:67:1: note: template argument deduction/substitution failed: 
../src/FEM.cpp:37:22: note: ‘arma::sp_mat {aka arma::SpMat<double>}’ is not derived from ‘const arma::Op<T1, arma::op_trimat>’ 
    vec zeta = solve(A,b); 
        ^
In file included from /usr/include/armadillo:397:0, 
       from ../src/FEM.cpp:10: 
/usr/include/armadillo_bits/fn_solve.hpp:87:1: note: template<class T1, class T2> const arma::Glue<T1, T2, arma::glue_solve_tr> arma::solve(const arma::Op<T1, arma::op_trimat>&, const arma::Base<typename T1::elem_type, T2>&, const char*, const typename arma::arma_blas_type_only<typename T1::elem_type>::result*) 
solve 
^ 
/usr/include/armadillo_bits/fn_solve.hpp:87:1: note: template argument deduction/substitution failed: 
../src/FEM.cpp:37:22: note: ‘arma::sp_mat {aka arma::SpMat<double>}’ is not derived from ‘const arma::Op<T1, arma::op_trimat>’ 
    vec zeta = solve(A,b); 
        ^
In file included from /usr/include/armadillo:397:0, 
       from ../src/FEM.cpp:10: 
/usr/include/armadillo_bits/fn_solve.hpp:110:1: note: template<class T1, class T2> bool arma::solve(arma::Mat<typename T1::elem_type>&, const arma::Base<typename T1::elem_type, T1>&, const arma::Base<typename T1::elem_type, T2>&, bool, const typename arma::arma_blas_type_only<typename T1::elem_type>::result*) 
solve 
^ 
/usr/include/armadillo_bits/fn_solve.hpp:110:1: note: template argument deduction/substitution failed: 
../src/FEM.cpp:37:22: note: ‘arma::sp_mat {aka arma::SpMat<double>}’ is not derived from ‘arma::Mat<typename T1::elem_type>’ 
    vec zeta = solve(A,b); 
        ^
In file included from /usr/include/armadillo:397:0, 
       from ../src/FEM.cpp:10: 
/usr/include/armadillo_bits/fn_solve.hpp:139:1: note: template<class T1, class T2> bool arma::solve(arma::Mat<typename T1::elem_type>&, const arma::Base<typename T1::elem_type, T1>&, const arma::Base<typename T1::elem_type, T2>&, const char*, const typename arma::arma_blas_type_only<typename T1::elem_type>::result*) 
solve 
^ 
/usr/include/armadillo_bits/fn_solve.hpp:139:1: note: template argument deduction/substitution failed: 
../src/FEM.cpp:37:22: note: ‘arma::sp_mat {aka arma::SpMat<double>}’ is not derived from ‘arma::Mat<typename T1::elem_type>’ 
    vec zeta = solve(A,b); 
        ^
make: *** [src/FEM.o] Error 1 

回答

2

稀疏矩陣的支持還沒有完成。

您可以使用ARPACK進行稀疏矩陣的(本徵)分解。稀疏矩陣求解器可能會在下一個版本中使用,該版本可能會使用SuiteSparse項目中的CXSparse庫。