Hi Markus
That worked. Thanks.
However, there's a new problem. When I refine the matrix (mesh) above once,
the same code produces an error. I don't see how "index<row_length(row)".
It fails at the highlighted line:
for (unsigned int i = 0; i < system_matrix.m(); ++i) {
SparsityPattern::row_iterator rowBegin =
sparsity_pattern.row_begin(i);
SparsityPattern::row_iterator rowEnd = sparsity_pattern.row_end(i);
for ( ; rowBegin != rowEnd; ++rowBegin) {
j = system_matrix.get_sparsity_pattern().column_number(i,
*rowBegin); // <---------------------------------------- FAILS HERE
// if ( (value = std::abs(system_matrix.el(i,j)) ) > 1e-15) {
// //std::cout << "Row " << i << ":" << value << std::endl;
// }
}
The new matrix is:
6.667e-01 0.000e+00 0.000e+00
0.000e+00
0.000e+00 1.333e+00 0.000e+00 0.000e+00 0.000e+00
0.000e+00
0.000e+00 0.000e+00 1.333e+00 0.000e+00
0.000e+00 0.000e+00
0.000e+00 0.000e+00 0.000e+00 2.667e+00 0.000e+00 0.000e+00
0.000e+00 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
1.333e+00 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
0.000e+00 1.333e+00 0.000e+00
0.000e+00
0.000e+00 0.000e+00 6.667e-01
# NNZ: 49
# NANZ: 9
Number of rows: 9
The error:
--------------------------------------------------------
An error occurred in line <1921> of file
</gennadiy/deal.II/include/deal.II/lac/sparsity_pattern.h> in function
unsigned int dealii::SparsityPattern::column_number(unsigned int,
unsigned int) const
The violated condition was:
index<row_length(row)
The name and call sequence of the exception was:
ExcIndexRange(index,0,row_length(row))
Additional Information:
Index 6 is not in [0,6[
Stacktrace:
-----------
#0 3 main 0x000000010000971b
_ZNK6dealii15SparsityPattern13column_numberEjj + 287: 3
main 0x000000010000971b
_ZNK6dealii15SparsityPattern13column_numberEjj
#1 4 main 0x0000000100003ce8
_ZN14LaplaceProblem30get_data_structureEv + 546: 4
main 0x0000000100003ce8
_ZN14LaplaceProblem30get_data_structureEv
#2 5 main 0x000000010000404e
_ZN14LaplaceProblem3runEv + 48: 5 main
0x000000010000404e _ZN14LaplaceProblem3runEv
#3 6 main 0x000000010000407c main + 44:
6 main 0x000000010000407c main
#4 7 main 0x0000000100002e00 start + 52:
7 main 0x0000000100002e00 start
--------------------------------------------------------
Abort trap
Regards,
Gennadiy
On 26 August 2011 13:49, Markus Bürg <[email protected]> wrote:
> **
> 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
>
>
_______________________________________________
dealii mailing list http://poisson.dealii.org/mailman/listinfo/dealii