When learning the deal.II FE library, I am a bit confused about the mechanism of its "SparsityPattern" class. Through reading the documentation, I only got to know that it uses the Compressed Row Storage format to store indices of nonzero entries of a sparse matrix.
To put my confusion be explicit, suppose I have a quare 10x10 sparse matrix which stores the values corresponding to 10 degrees of freedom, namely dof_handler.n_dofs = 10
:
But at first, suppose we don't know exactly where the nonzero entries are and can only get a maximal estimate of their number at each row, say max_per_row
, and let max_per_row = 5
. Then the sparsity pattern would be:
One way to get the sparsitypattern is:
SparsityPattern sparsity_pattern;
sparsity_pattern.reinit(10, 10, 5);
DoFTools::make_sparsity_pattern(dof_handler, sparsity_pattern);
sparsity_pattern.compress()
where dof_handler
stores the information of degrees of freedom.
And it can also be implemented as below:
DynamicSparsityPattern dynamic_pattern (dof_handler.n_dofs());
DoFTools::make_sparsity_pattern (dof_handler, dynamic_pattern);
constraints.condense (dynamic_pattern);
SparsityPattern sp;
sp.copy_from (dynamic_pattern);
So, my question is:
*1) Here, when we call sparsity_pattern.reinit(10, 10, 5)
, does it create an empty 10x10 matrix (2D vector) or just a 1x100 vector storing the values row by row? And if it is 10x10 or 1x100, then what is the functionality of third parameter max_per_row=5
?
*2) I think sparsity_pattern.reinit(10, 10, 5)
creates a 10x10 matrix and then using DoFTools::make_sparsity_pattern(dof_handler, sparsity_pattern)
to create a CRS format, i.e, two vectors storing the row columm index of nonzero entries at each row and the index starting a new row respectively, according to the dof information stored in dof_handler
. Does this understanding make sense?
*3) I know in C++ STL, we can compress a vector to its actuall capacity using its member function vector.shrink_to_fit
. But here if DoFTools::make_sparsity_pattern
has already make a compressed format of 5 entries at each row (according to *2), how can it be compressed again using sparsity_pattern.compress()
?
*4) Does DynamicSparsityPattern dynamic_pattern (dof_handler.n_dofs())
creates a (n_dofs) x (n_dofs)
matrix, then what's the difference between DoFTools::make_sparsity_pattern(dof_handler, sparsity_pattern)
and DoFTools::make_sparsity_pattern (dof_handler, dynamic_pattern)
.
*5) What about constraints.condense (dynamic_pattern)
?
*6) In C++ STL, we know that we can copy a vector v1
of size 4, capacity 8 to a vector v2
, then v2
will be of capacity 4. In this way, can can also compress a vector to its actuall capacity. Is it the same mechanism to use `sp.copy_from (dynamic_pattern)'?
I know these questions are so dummy to experienced users of deal.II. But to green learners as me, they are really great hurdles to jump. I sincerely hope someone could be so kind to give some help, and any comments would be greatly appreciated. Thanks in advance!