use of linear solver in cs_user_solver

Questions and remarks about code_saturne usage
Forum rules
Please read the forum usage recommendations before posting.
Post Reply
lzhang
Posts: 44
Joined: Mon Nov 06, 2017 2:54 pm

use of linear solver in cs_user_solver

Post by lzhang »

Hello,

I am trying to adapt the example "cs_user_solver-heat-equation.c" for my own application. However for my application, an implicit scheme requiring a linear solver is used. I would like to know how I could define and assemble a matrix, and then use a linear solver to resolve it, please! A small example or some indications will help a lot, as I am trying to read through the files in src/alge, but it is not that easy to understand.

Thanks in advance!

Best regards,
Lei
Yvan Fournier
Posts: 4077
Joined: Mon Feb 20, 2012 3:25 pm

Re: use of linear solver in cs_user_solver

Post by Yvan Fournier »

Hello,

If your scheme uses the main Code_Saturne discretization and operators (cell-centered finite volumes or any scheme leading to matrices have rows matching cells and nonzeroes matching faces connecting 2 cells), you can use the main functions, using the default matrix stuctures. In this case you can check src/alge/cs_matrix_building.c to see how coefficients are computed (maybe not useful for you if you already have your scheme), and in src/alge/cs_sles.c, check the cs_sles_setup_native_conv_diff function sources to see both how matrix coefficients are assigned (cs_matrix_set_coefficients), and a linear system solution is called.

If your scheme uses another connectivity, you can use the more recent and "general" cs_matrix_assembler API, which is also used in a variant of the above example (see cs_matrix_set_coefficients_coupled), but you can also find simple, more minimalist examples both in src/alge/cs_benchmark.c, or the unit tests tests/cs_matrix_test.c. To set up a linear system resolution, the above example (cs_sles_setup_native_conv_diff) is also valid, though there are also codes in the CDO portion of the code (though I am less familiar with that part, which evolves quite fast).

Best regards,

Yvan
Post Reply