StiffnessSolver.cpp
Go to the documentation of this file.
2 
4 {
5  detailed_timing_ = false;
6 }
7 
8 /* Eigen solver */
9 bool StiffnessSolver::SolveSystem(SpMat &K, VX &D, VX &F, int verbose, int &info)
10 {
11  Eigen::SimplicialLDLT<Eigen::SparseMatrix<double>> solver;
12 
13  if (detailed_timing_)
14  {
15  compute_k_.Start();
16  }
17 
18  solver.compute(K);
19 
20  if (detailed_timing_)
21  {
22  compute_k_.Stop();
23  }
24 
25  info = 0;
26 
27  if (solver.info() != Eigen::Success)
28  {
29  fprintf(stderr, "SolverSystem(LDLT): Error in Decomposition!\n");
30  return false;
31  }
32 
33  VX Diag = solver.vectorD();
34 
35  for (int i = 0; i < Diag.size(); i++)
36  {
37  if (Diag[i] == 0.0)
38  {
39  fprintf(stderr, " SolveSystem(LDLT): zero found on diagonal ...\n");
40  fprintf(stderr, " d[%d] = %11.4e\n", i, Diag[i]);
41  return false;
42  }
43 
44  if (Diag[i] < 0.0)
45  {
46  fprintf(stderr, " SolveSystem(LDLT): negative number found on diagonal ...\n");
47  fprintf(stderr, " d[%d] = %11.4e\n", i, Diag[i]);
48  info--;
49  return false;
50  }
51  }
52 
53  if (info < 0)
54  {
55  fprintf(stderr, "Stiffness Matrix is not positive definite: %d negative elements\n", info);
56  fprintf(stderr, "found on decomp diagonal of K.\n");
57  fprintf(stderr, "The stucture may have mechanism and thus not stable in general\n");
58  fprintf(stderr, "Please Make sure that all six\n");
59  fprintf(stderr, "rigid body translations are restrained!\n");
60 
61  return false;
62  }
63 
64  if (detailed_timing_)
65  {
66  solve_d_.Start();
67  }
68 
69  D = solver.solve(F);
70 
71  if (detailed_timing_)
72  {
73  solve_d_.Stop();
74  }
75 
76  if (solver.info() != Eigen::Success)
77  {
78  fprintf(stderr, "SolverSystem(LDLT): Error in Solving!\n");
79  return false;
80  }
81 
82  return true;
83 }
84 
85 
86 bool StiffnessSolver::SolveSystem(SpMat &K, VX &D, VX &F, VX &D0, int verbose, int &info)
87 {
88  Eigen::ConjugateGradient<SpMat> solver;
89 
90  if (detailed_timing_)
91  {
92  compute_k_.Start();
93  }
94 
95  solver.compute(K);
96 
97  if (detailed_timing_)
98  {
99  compute_k_.Stop();
100  }
101  info = 0;
102 
103  if (solver.info() != Eigen::Success)
104  {
105  fprintf(stderr, "SolverSystem(ConjugateGradient): Error in Decomposition!\n");
106  return false;
107  }
108 
109  solver.setMaxIterations(3000);
110  //D = solver.solve(F);
111 
112  if (detailed_timing_)
113  {
114  solve_d_.Start();
115  }
116 
117  D = solver.solveWithGuess(F, D0);
118 
119  if (detailed_timing_)
120  {
121  solve_d_.Stop();
122  }
123 
124  if (solver.info() != Eigen::Success)
125  {
126  fprintf(stderr, "SolverSystem(ConjugateGradient): Error in Solving!\n");
127  return false;
128  }
129 
130  D0 = D;
131  return true;
132 }
133 
134 
136 {
137  x = A.fullPivLu().solve(b);
138 
139  if ((A*x).isApprox(b))
140  {
141  return true;
142  }
143  else
144  {
145  return false;
146  }
147 }
148 
150 {
151 }
GLint GLenum GLint x
void Stop()
Definition: Timer.cpp:21
bool SolveSystem(SpMat &K, VX &D, VX &F, int verbose, int &info)
Eigen::MatrixXd MX
GLboolean GLboolean GLboolean b
Eigen::SparseMatrix< double > SpMat
void Start()
Definition: Timer.cpp:15
Eigen::VectorXd VX
bool LUDecomp(MX &A, VX &x, VX &b)


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