Re: [eigen] row and col setZero in sparse matrices

[ Thread Index | Date Index | More lists.tuxfamily.org/eigen Archives ]


Thanks Gael, I understand. I was not aware of the permutation matrices in Eigen. That's a good idea. Since, I am doing finite elements, I have switched to applying the boundary conditions for every element matrix.


2014-04-22 15:55 GMT+01:00 Gael Guennebaud <gael.guennebaud@xxxxxxxxx>:

Hi,

sorry for late reply. I agree this would be convenient, but this would also be pretty slow, especially if you fix several values this ways. If A is column major:

  b-=value*A.col(dof);

-> fine
 
  A.col(dof).setZero();

-> fine if we keep the memory allocated for col(dof), otherwise all remaining columns have to be copied to keep a compact storage.
 
  A.row(dof).setZero();

This is basically a O(nnz) operation, so pretty costly if you do it multiple times.
 
  A.coeffRef(dof,dof)=1.0;

-> fine if we kept a non-compact storage

Since in most cases you want to fix several unkowns, I usually build a permutation matrix P, permute A in a symmetric fashion (A1 = A.twistedBy(P)), and then pick sub matrices to solve:

A1.topLeftCorner(....) * x1.head(...) = b.head(...) - A1.topRightCorner(...) * values

and then apply P.inverse() on x1 to get x.

gael



Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/