CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   Main CFD Forum (https://www.cfd-online.com/Forums/main/)
-   -   Storing discretized system into a matrix format for computation (https://www.cfd-online.com/Forums/main/239306-storing-discretized-system-into-matrix-format-computation.html)

ishan_ae October 30, 2021 18:29

Storing discretized system into a matrix format for computation
 
Hello,

I have a question related to how the coefficients from resulting discretized system of equations are stored.

I noticed that there are several sparse matrix storage formats such as CSR(compressed sparse row) that are used in linear solver libraries such as lis(https://github.com/anishida/lis) and PETSc.

When the coefficients are calculated for the CFD system under study, are the algorithms modified, not Physics-wise but implementation-wise, so that the coefficients are stored in the desired storage format in, lets say N steps?

If not, then are the coefficients calculated, stored temporarily and then the coefficients converted into the matrix format? To me this seems like it will increase the memory usage and also will need at least t N+1 steps implementation-wise.

I do not have expert-level know-how about about C or C++ but in my opinion this also depends on how the libraries are built.

This is something which I wondered about because I am right now using C in my CFD learning process. I want to use existing linear solver libraries for my code and in the code documentation they have mentioned about different storage formats.

Based on your experience how is this usually done?

FMDenaro October 31, 2021 04:22

What do you exactly mean for

"are the algorithms modified, not Physics-wise but implementation-wise"?

ishan_ae October 31, 2021 04:59

What I meant by it was that whether we modify lets say, a for loop to store the resulting calculations in a specific variable. This variable can be part of a larger process that is needed to set up the overall system of equations. While the calculation process will be the same, but what will change is how those calculations are implemented while coding.

aerosayan October 31, 2021 05:16

First write a solver for dense matrices. Use python/Matlab/octave to do it, so that your maths is correct. Then go to study other sparse matrix solvers. Then write sparse matrix solvers.

I hope you followed this path of learning in your journey. :)

If you don't understand dense matrix solvers, you won't understand sparse matrix solvers.

Answering your question : yes the code needs to be modified to work with sparse matrix form, and if you think of the algorithm as the pseudocode instead of the overall steps to take, then obviously the algorithm also changes.

I code in C/C++, C doesn't have the benefits of fortran's matrix manipulation, or C++'s OOP based abstraction. But it's simpler than C++ and harder than Fortran. If you're learning and don't care about performance, I would recommend languages like python/Matlab or octave/Julia/Fortran. They're almost similar, but I put the more easy to use languages at the front. Except Fortran, the rest have inbuilt data visualization/plotting system so they are easier for you to use.

aerosayan October 31, 2021 05:19

Also answering your question : yes, the implementation is often changed for efficiency. For example - No one actually computes A inverse for solving set of linear equations like Ax=b

sbaffini October 31, 2021 10:13

If you think a little about it, and realize that you only need those coefficients to actually solve the system, you also understand that there really is no reason to store them in any different way than the one demanded by the linear algebra part (typically csr). Even if you have many of them, they will probably demand all the same structure (I don't know a single one of them that doesn't).

ishan_ae October 31, 2021 12:05

Thanks everyone for your inputs.


All times are GMT -4. The time now is 20:16.