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

 Register Blogs Members List Search Today's Posts Mark Forums Read

 April 16, 2018, 09:26 How can I get the number of elements per row form the matrix? #1 Senior Member   Klaus Join Date: Mar 2009 Posts: 144 Rep Power: 12 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 Last edited by klausb; April 16, 2018 at 19:57.

 April 16, 2018, 20:10 I have been thinking of modifying the following code which is used to print a matrix #2 Senior Member   Klaus Join Date: Mar 2009 Posts: 144 Rep Power: 12 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?

 December 30, 2018, 16:27 #3 Super Moderator   Bruno Santos Join Date: Mar 2009 Location: Lisbon, Portugal Posts: 10,676 Blog Entries: 42 Rep Power: 117 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... Daniel_Khazaei likes this. __________________ OpenFOAM: FAQ | Getting started Forum: How to get help, to post code/output and forum guide What am I doing/planning: blog/wiki Read this before sending me PM