
Ublas : 
From: Gunter Winkler (guwi17_at_[hidden])
Date: 20080318 17:52:59
Am Dienstag, 18. MÃ¤rz 2008 21:31 schrieb TunÃ§ BahÃ§ecioÄŸlu:
> Hi,
> I have the following code that I use in my FEM program
>
> for (int i=0;i<cCount;i++)
> {
> for (int j=0;j<cCount;j++) // for every col and row that used the
> used DOF {
> if (E(i)>=0 && E(j) >=0)
> {
> globalStifnessMatrix (E(i),E(j)) += K(i,j); }
> }
> }
> When I use the code with a coordinate_matrix the += operation get
> slower and slower as I assemble more element stiffness matrices to
> the global one. If I use compressed matrix issue resolves but since I
> want to use mumps binding I believe I am stuck with the coordinate
> matrix type. Also I don't want to change the += operator(maybe using
> append_element will solve my problem?) since my function is a
> template one and I want to use it with different matrix types (dense,
> sparse etc..).
Yes, the solution is to use append_element().
The += operator looks first if an element is present and updates this
element or inserts a new one. Only the append_element() method uses the
special property of the coordinate matrix. BTW. the fastest method to
assemble a stiffness matrix is to precompute the structure, fill a
compressed matrix row by row with zeros and then do the usual assembly.
The IMO second best solution is to use a generalized_vector_of_vector
with compressed rows and copy the result into your favorite matrix
format. As long as you do not reach the memory limit of your system,
the additional copy is a lot cheaper than the final sort and compress
of a coordinate matrix or the slow insert of a compressed matrix.
mfg
Gunter