You can refer to the example 
src/ts/tutorials/advection-diffusion-reaction/ex5adj_mf.c
which uses a matrix-free approach for a 2D multi-component reaction-diffusion 
PDE.
In particular, you only need to look at MyIMatMult() and ignore the transposed 
version
which is intended for adjoint calculations.

Hong (Mr.)

On Sep 6, 2022, at 10:00 PM, Tu, Jiannan 
<jiannan...@uml.edu<mailto:jiannan...@uml.edu>> wrote:

I am using TS IMEX to solve a large DAE system. The DAE is obtained by applying 
finite FV method to 3-D multi-specie ion/neutral fluids equations with magnetic 
induction equation. The Jacobian for stiff part is formed by using 
MatSetValuesStencil(). The Jacobian matrix is very sparse, no more than 10 
non-zeros on each row. MatSetValuesStencil requires local to global mapping by 
calling ISLocaltoGlobalMapping(). Could you please instruct me how to use local 
to global mapping?

I also tried using DMCreateMatrix() to create the Jacobian. While local to 
global mapping is not necessary, the matrix takes too much memory and requires 
64-bit indices. I would prefer to take the advantage of sparsity of the 
Jacobian, pre-allocate the matrix to use as less as possible memory so that the 
code can be run on a multi-core desktop.

Thank you very much for your advice.

Jiannan

Reply via email to