1 /*===========================================================================*\
2 * *
3 * CoMISo *
4 * Copyright (C) 2008-2009 by Computer Graphics Group, RWTH Aachen *
5 * www.rwth-graphics.de *
6 * *
7 *---------------------------------------------------------------------------*
8 * This file is part of CoMISo. *
9 * *
10 * CoMISo is free software: you can redistribute it and/or modify *
11 * it under the terms of the GNU General Public License as published by *
12 * the Free Software Foundation, either version 3 of the License, or *
13 * (at your option) any later version. *
14 * *
15 * CoMISo is distributed in the hope that it will be useful, *
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
18 * GNU General Public License for more details. *
19 * *
20 * You should have received a copy of the GNU General Public License *
21 * along with CoMISo. If not, see <http://www.gnu.org/licenses/>. *
22 * *
23 \*===========================================================================*/
24
25 #include <iostream>
26
27
28 //== COMPILE-TIME PACKAGE REQUIREMENTS ========================================
29 #include <CoMISo/Config/config.hh>
30 #if (COMISO_ARPACK_AVAILABLE && COMISO_SUITESPARSE_AVAILABLE && COMISO_EIGEN3_AVAILABLE)
31 //=============================================================================
32
33 #include <CoMISo/Utils/StopWatch.hh>
34 #include <vector>
35 #include <CoMISo/EigenSolver/ArpackSolver.hh>
36 #define EIGEN_YES_I_KNOW_SPARSE_MODULE_IS_NOT_STABLE_YET
37 #include <Eigen/Sparse>
38 #include <Eigen/Dense>
39
40
41 //------------------------------------------------------------------------------------------------------
42
43 // Example main
main(void)44 int main(void)
45 {
46 // matrix types
47 #if EIGEN_VERSION_AT_LEAST(3,1,0)
48 typedef Eigen::SparseMatrix<double,Eigen::ColMajor> SMatrix;
49 #else
50 typedef Eigen::DynamicSparseMatrix<double,Eigen::ColMajor> SMatrix;
51 #endif
52 typedef Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic> Matrix;
53
54 std::cout << "---------- 1) Setting up matrix..." << std::endl;
55 unsigned int n=5;
56 SMatrix A(n,n);
57 // 1D Laplacian
58 for(unsigned int i=0; i<n; ++i)
59 {
60 int count = 0;
61 if( i > 0)
62 {
63 A.coeffRef(i,i-1) = -1.0;
64 ++count;
65 }
66 if(i<n-1)
67 {
68 A.coeffRef(i,i+1) = -1.0;
69 ++count;
70 }
71
72 A.coeffRef(i,i) = count;
73 }
74
75
76 std::cout << "---------- 2) Solving for m smallest eigenvalues and eigenvectors..." << std::endl;
77 unsigned int m=3;
78 COMISO::ArpackSolver arsolv;
79 std::vector<double> evals;
80 Matrix evects;
81 arsolv.solve(A, evals, evects, m);
82
83 std::cout << "---------- 3) printing results..." << std::endl;
84 std::cerr << "********* eigenvalues: ";
85 for(unsigned int i=0; i<evals.size(); ++i)
86 std::cerr << evals[i] << ", ";
87 std::cerr << std::endl;
88
89 std::cerr <<"********* eigenvectors:" << std::endl;
90 std::cerr << evects << std::endl;
91
92 return 0;
93 }
94
95 //=============================================================================
96 #else
97 //=============================================================================
98
99 // Example main
main(void)100 int main(void)
101 {
102 std::cerr << "Info: required dependencies are missing, abort...\n";
103 return 0;
104 }
105 //=============================================================================
106 #endif // COMISO_SUITESPARSE_AVAILABLE
107 //=============================================================================
108