IllCondDetector.h
Go to the documentation of this file.
1 /*
2 * ==========================================================================
3 * This file is part of the implementation of
4 *
5 * <FrameFab: Robotic Fabrication of Frame Shapes>
6 * Yijiang Huang, Juyong Zhang, Xin Hu, Guoxian Song, Zhongyuan Liu, Lei Yu, Ligang Liu
7 * In ACM Transactions on Graphics (Proc. SIGGRAPH Asia 2016)
8 ----------------------------------------------------------------------------
9 * Class: IllConditioner
10 *
11 * Description: Matrix condition checking related computational units.
12 *
13 * Version: 2.0
14 * Created: Oct/10/2015
15 * Updated: Aug/24/2016
16 *
17 * Author: Xin Hu, Yijiang Huang, Guoxian Song
18 * Company: GCL@USTC
19 * Citation: This file use matrix operation module from
20 * Title: LAPACK
21 * a linear algebra package
22 * Code Version: 3.6.1
23 * Availability: http://www.netlib.org/lapack/
24 ----------------------------------------------------------------------------
25 * Copyright (C) 2016 Yijiang Huang, Xin Hu, Guoxian Song, Juyong Zhang
26 * and Ligang Liu.
27 *
28 * FrameFab is free software: you can redistribute it and/or modify
29 * it under the terms of the GNU General Public License as published by
30 * the Free Software Foundation, either version 3 of the License, or
31 * (at your option) any later version.
32 *
33 * FrameFab is distributed in the hope that it will be useful,
34 * but WITHOUT ANY WARRANTY; without even the implied warranty of
35 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
36 * GNU General Public License for more details.
37 *
38 * You should have received a copy of the GNU General Public License
39 * along with FrameFab. If not, see <http://www.gnu.org/licenses/>.
40 * ==========================================================================
41 */
42 
43 #ifndef ILLCONDDECTOR_H
44 #define ILLCONDDECTOR_H
45 
46 #include <iostream>
47 #include <stdlib.h>
48 #include "assert.h"
49 #include <Eigen/Sparse>
50 
52 
53 extern "C" void dgesv_(const int *N, const int *nrhs, double *A, const int *lda, int
54  *ipiv, double *b, const int *ldb, int *info);
55 
56 extern "C" void dgels_(const char *trans, const int *M, const int *N, const int *nrhs,
57  double *A, const int *lda, double *b, const int *ldb, double *work,
58  const int * lwork, int *info);
59 
60 // Computes the Cholesky factorization of a real symmetric
61 // positive definite matrix A.
62 // A = Ut * U, for uplo = "U"
63 // A = L * Lt, for uplo = "L"
64 extern "C" void dpotrf_(const char *UPLO, const int *N, double *A, const int *LDA, int *info);
65 
66 // Estimates the reciprocal of the condition number (in the 1 - norm)
67 // of a real symmetric positive definite packed matrix using
68 // the Cholesky factorization A = U**T*U or A = L*L**T computed by
69 // DPPTRF.
70 // refer : http://www.netlib.org/lapack/explore-html/d0/d9b/dppcon_8f.html#a8107a68e3c7d948fe246bf0feae0470b
71 extern "C" void dpocon_(const char *UPLO, const int *N, const double *AP, const int *lda, const double *ANORM,
72  double *RCOND, double *WORK, int *LWORK, int *INFO);
73 
74 // Rank computing, the rank of input matrix is the number of singular values that are not zero
75 // A = U * SIGMA * transpose(V)
76 // refer : http://icl.cs.utk.edu/lapack-forum/viewtopic.php?f=2&t=818
77 extern "C" void dgesvd_(const char *JOBU, const char *JOBVT, const int *M, const int *N, double *A, const int *LDA,
78  double *S, double *U, const int *LDU, double *VT, const int *LDVT, double *WORK, const int *LWORK, int *info);
79 
81 public:
82  typedef Eigen::SparseMatrix<double> EigenSp;
83  typedef Eigen::VectorXd VX;
84 public:
86  IllCondDetector(EigenSp const &K);
88 
89 public:
90  // I\O
91  void inline SetParm(int _ns, int _nl, int _condthres, int _gap);
92  double GetCondNum() const { return rcond_num_; }
93 
94  // Library Compatibility
95  void EigenLap(EigenSp const &K);
96 
97  /* Condition number of the stiffness matrix */
98  double ComputeCondNum();
99 
100  /* Root Mean Square Equilibrium Error Check */
101  double EquilibriumError(EigenSp const &K, VX const &D, VX const &F);
102 
103  void Debug();
104 private:
105  int ns_; // ns_ : The number of smallest eigenpairs
106  int nl_; // nl_ : The number of largest eigenpairs
107  int cond_thres_; // cond_thres_ : The condition number threshold for triggering analysis
108  int gap_; // gap_ : The order of the gap between a cluster of smallest eigenvalues
109  // and the next largest eigen values
110 
111  /*
112  * Matrices are well-conditioned if the
113  * reciprocal condition number is near 1 and ill-conditioned if it is near zero.
114  *
115  * About numerical value of condition number, please refer to:
116  * http://math.stackexchange.com/questions/675474/what-is-the-practical-impact-of-a-matrixs-condition-number
117  * "Condition number exceeds 10e10 could be problematic. condition number from 10e^3~6 could be acceptable."
118  */
119  int N_; // N_ : the matrix's row number
120  double rcond_num_; // rcond_num :the reciprocal of the condition number
121  double *A_; // A[] : LAPACK storage of the matrix
122  double Anorm_; // Anorm_ : 1 norm = max_j{ sum_{i}abs(a_ij)}
123 
124  bool debug_;
125 };
126 
127 #endif
Eigen::VectorXd VX
void SetParm(int _ns, int _nl, int _condthres, int _gap)
double GetCondNum() const
void dgesvd_(const char *JOBU, const char *JOBVT, const int *M, const int *N, double *A, const int *LDA, double *S, double *U, const int *LDU, double *VT, const int *LDVT, double *WORK, const int *LWORK, int *info)
void dpocon_(const char *UPLO, const int *N, const double *AP, const int *lda, const double *ANORM, double *RCOND, double *WORK, int *LWORK, int *INFO)
void dgesv_(const int *N, const int *nrhs, double *A, const int *lda, int *ipiv, double *b, const int *ldb, int *info)
double EquilibriumError(EigenSp const &K, VX const &D, VX const &F)
GLboolean GLboolean GLboolean b
void dgels_(const char *trans, const int *M, const int *N, const int *nrhs, double *A, const int *lda, double *b, const int *ldb, double *work, const int *lwork, int *info)
void dpotrf_(const char *UPLO, const int *N, double *A, const int *LDA, int *info)
Eigen::SparseMatrix< double > EigenSp
void EigenLap(EigenSp const &K)


choreo_task_sequence_planner
Author(s): Yijiang Huang
autogenerated on Thu Jul 18 2019 04:03:14