42 using namespace Eigen;
90 if (AF) cs_spfree(AF);
102 for (
int i=0; i<(int)cols.size(); i++)
104 map<int,Matrix<double,3,3>, less<int>,
105 aligned_allocator< Matrix <double,3,3> > > &col = cols[i];
116 for (
int i=0; i<(int)diag.size(); i++)
120 for (
int i=0; i<(int)cols.size(); i++)
122 map<int,Matrix<double,3,3>, less<int>,
123 aligned_allocator<Matrix<double,3,3> > > &col = cols[i];
126 map<int,Matrix<double,3,3>, less<int>,
127 aligned_allocator<Matrix<double,3,3> > >::iterator it;
128 for (it = col.begin(); it != col.end(); it++)
130 it->second.setZero();
137 if (Bprev.size() > 0)
139 B.head(Bprev.size()) = Bprev;
149 map<int,Matrix<double,3,3>, less<int>,
150 aligned_allocator<Matrix<double,3,3> > > &col = cols[jj];
152 map<int,Matrix<double,3,3>, less<int>,
153 aligned_allocator<Matrix<double,3,3> > >::iterator it;
156 col.insert(pair<
int,Matrix<double,3,3> >(ii,m));
164 for (
int i=0; i<(int)diag.size(); i++)
165 diag[i].diagonal() *= lam;
179 cholmod_start(&Common);
185 if (init || useCholmod)
191 for (
int i=0; i<(int)cols.size(); i++)
193 map<int,Matrix<double,3,3>, less<int>,
194 aligned_allocator<Matrix<double,3,3> > > &col = cols[i];
195 nnz += 9 * col.size();
203 chA = cholmod_allocate_sparse(csize,csize,nnz,
true,
true,1,CHOLMOD_REAL,&Common);
208 A = cs_spalloc(csize,csize,nnz,1,0);
227 for (
int i=0; i<(int)cols.size(); i++)
230 map<int,Matrix<double,3,3>, less<int>,
231 aligned_allocator<Matrix<double,3,3> > > &col = cols[i];
234 for (
int k=0; k<3; k++)
243 map<int,Matrix<double,3,3>, less<int>,
244 aligned_allocator<Matrix<double,3,3> > >::iterator it;
247 for (it = col.begin(); it != col.end(); it++)
250 for (
int j=0; j<3; j++)
257 for (
int kk=0; kk<k+1; kk++)
269 Ax = (
double *)chA->x;
274 for (
int i=0; i<(int)cols.size(); i++)
277 map<int,Matrix<double,3,3>, less<int>,
278 aligned_allocator<Matrix<double,3,3> > > &col = cols[i];
281 for (
int k=0; k<3; k++)
287 map<int,Matrix<double,3,3>, less<int>,
288 aligned_allocator<Matrix<double,3,3> > >::iterator it;
291 for (it = col.begin(); it != col.end(); it++)
293 Matrix<double,3,3> &m = it->second;
294 for (
int j=0; j<3; j++)
300 Matrix<double,3,3> &m = diag[i];
301 for (
int kk=0; kk<k+1; kk++)
302 Ax[colp++] = m(kk,k);
303 Ax[colp-1] *= diaginc;
317 m.setZero(csize,csize);
323 for (
int i=0; i<csize; i++)
328 for (
int j=rbeg; j<rend; j++)
339 cholmod_dense *
x, b, *R, *R2;
341 double *Xx, *Rx, *bb;
342 double one [2], minusone [2];
349 cholmod_print_sparse (chA, (
char *)
"A", &Common) ;
354 b.xtype = CHOLMOD_REAL;
355 b.dtype = CHOLMOD_DOUBLE;
358 L = cholmod_analyze (chA, &Common) ;
360 cholmod_factorize (chA, L, &Common) ;
362 x = cholmod_solve (CHOLMOD_A, L, &b, &Common) ;
368 R = cholmod_copy_dense (&b, &Common) ;
369 cholmod_sdmult(chA, 0, minusone, one, x, R, &Common) ;
371 R2 = cholmod_solve (CHOLMOD_A, L, R, &Common) ;
373 Xx = (
double *)x->x ;
374 Rx = (
double *)R2->x ;
375 for (
int i=0 ; i<csize ; i++)
377 Xx[i] = Xx[i] + Rx[i] ;
379 cholmod_free_dense (&R2, &Common) ;
380 cholmod_free_dense (&R, &Common) ;
383 for (
int i=0; i<csize; i++)
385 cholmod_free_factor (&L, &Common) ;
386 cholmod_free_dense (&x, &Common) ;
387 cholmod_free_sparse(&chA, &Common);
388 cholmod_finish (&Common) ;
399 if (csize > 100) order = 1;
400 bool ok = (bool)cs_cholsol(order,A,B.data());
436 AT = cs_transpose(A,1);
437 cs_fkeep (AT, &dropdiag, NULL);
438 if (AF) cs_spfree(AF);
439 AF = cs_add (A, AT, 1, 1);
443 CompCol_Mat_double Ap(csize, csize, AF->nzmax, AF->x, AF->i, AF->p);
444 VECTOR_double b(B.data(),csize);
445 VECTOR_double
x(csize, 0.0);
450 ICPreconditioner_double D(Ap);
451 res = CG(Ap,x,b,D,iters,tol);
453 for (
int i=0; i<csize; i++)
void uncompress(MatrixXd &m)
void incDiagBlocks(double lam)
void setupCSstructure(double diaginc, bool init=false)
TFSIMD_FORCE_INLINE const tfScalar & x() const
EIGEN_MAKE_ALIGNED_OPERATOR_NEW CSparse2d()
void setupBlockStructure(int n, bool eraseit=true)
void addOffdiagBlock(Matrix< double, 3, 3 > &m, int ii, int jj)