CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM Programming & Development (https://www.cfd-online.com/Forums/openfoam-programming-development/)
-   -   How can I get the number of elements per row form the matrix? (https://www.cfd-online.com/Forums/openfoam-programming-development/200890-how-can-i-get-number-elements-per-row-form-matrix.html)

klausb April 16, 2018 08:26

How can I get the number of elements per row form the matrix?
 
Hi,

how can I compute the number of elements of a particular row of the coefficient matrix?

I know how to compute the totals of the lower, upper and diagonal part e.g.

int elements_lower_triangle = matrix.lower().size() + matrix.diag().size();

int elements_upper_triangle = matrix.upper().size() + matrix.diag().size();

Klaus

klausb April 16, 2018 19:10

I have been thinking of modifying the following code which is used to print a matrix
 
Code:

    for(int i = 0; i < matrix_.lower().size(); i++){
        int r = matrix_.lduAddr().upperAddr()[i];
        int c = matrix_.lduAddr().lowerAddr()[i];
        a[r*n + c] = matrix_.lower()[i];
    }

    for(int i = 0; i < matrix_.diag().size(); i++){
        a[i*n + i] = matrix_.diag()[i];
    }

    for(int i = 0; i < matrix_.upper().size(); i++){
        int r = matrix_.lduAddr().lowerAddr()[i];
        int c = matrix_.lduAddr().upperAddr()[i];
        a[r*n + c] = matrix_.upper()[i];
    }

It produces something like this (example):
Code:

  0  1  2  3
0  D  U  U  .
1  L  D  .  U
2  L  .  D  U
3  .  L  L  D

But I couldn't work out how to count the number of nonzero values (the L,D,Us) per row?

wyldckat December 30, 2018 15:27

Quick note: I was looking into answering another thread of yours and while deducing how to do things, I remembered that gdbOF does what you're looking for: https://openfoamwiki.net/index.php/Contrib_gdbOF

If you look into the manual they provide, in the appendices are the pseudo-code blocks that tell how the matrices are reconstructed... which is what you're looking for here...


All times are GMT -4. The time now is 11:47.