Hello Gennadiy,
unfortunately you have to check the value of the entries:
if (std::abs (sparse_matrix.el (i,j)) > 1e-15)
std::cout ...
Best Regards,
Markus
Am 26.08.11 14:02, schrieb Gennadiy Rishkin:
Hi
I'm trying to iterate over the nonzero entries in a matrix but the
code below gives all entries including zero entries. How do I obtain
the values and indexes of the nonzero entries?
The test system_matrix is from step-2 (no refinement):
6.667e-01 0.000e+00 0.000e+00 0.000e+00
0.000e+00 6.667e-01 0.000e+00 0.000e+00
0.000e+00 0.000e+00 6.667e-01 0.000e+00
0.000e+00 0.000e+00 0.000e+00 6.667e-01
for (unsigned int i = 0; i < 1 /*system_matrix.m()*/; ++i) {
std::cout << "Row " << i << " has " <<
sparsity_pattern.row_length(i) << " entries." << std::endl;
SparsityPattern::row_iterator rowBegin =
sparsity_pattern.row_begin(i);
SparsityPattern::row_iterator rowEnd =
sparsity_pattern.row_end(i);
for ( ; rowBegin != rowEnd; ++rowBegin) {
if ( sparsity_pattern.exists( i,
sparsity_pattern.column_number(i, *rowBegin) ) )
std::cout << *rowBegin << std::endl;
}
}
OUTPUT:
Row 0 has 4 entries.
0
1
2
3
Gennadiy
_______________________________________________
dealii mailing list http://poisson.dealii.org/mailman/listinfo/dealii
_______________________________________________
dealii mailing list http://poisson.dealii.org/mailman/listinfo/dealii