PETSc uses reference counting to track when an object is no longer needed
and can be freed. Thus XXXDestroy(&xxx) may not actually destroy an object it
just decreases the reference count by 1 (and destroys the object if the
reference count is 0).
1) TSSetIJacobian() increases the reference count of the matrix passed in.
Hence the user must destroy the J matrix at some time. Yes it is confusing to
call the destroy here, usually we call it at the end of the program.
2) TS computes the shift as needed inside the particular ODE integrator being
used; it is not set by the user.
3) This code is weird (not wrong, just weird). If you look at the end of the
function you will see:
ierr = MatDestroy(&A);CHKERRQ(ierr);
ierr = MatDestroy(&appctx.A);CHKERRQ(ierr);
that is the same matrix is destroyed twice. The PetscObjectReference()
increases the reference count to two hence the object needs to be destroyed
twice before it is actually destroyed. Note you don't need to do this. You
could skip the PetscObjectReference() in the code and remove one of the two
MatDestroy() at the end of the code.
Barry
> On Nov 27, 2018, at 3:25 PM, Sajid Ali via petsc-users
> <[email protected]> wrote:
>
> Hi,
>
> I wanted to ask a few questions about the TS example ex3.c when using the
> ifunc option
>
> 190: Mat
> J;
>
>
> 192:
> RHSMatrixHeat(ts,0.0,u,A,A,&appctx);
>
> 193: MatDuplicate(A,MAT_DO_NOT_COPY_VALUES
> ,&J);
>
> 194: TSSetIFunction
> (ts,NULL,IFunctionHeat,&appctx);
>
> 195: TSSetIJacobian
> (ts,J,J,IJacobianHeat,&appctx);
>
> 196: MatDestroy
> (&J);
>
>
> 198: PetscObjectReference((PetscObject
> )A);
>
> 199:
> appctx.A = A;
>
> 200:
> appctx.oshift = PETSC_MIN_REAL;
>
> 201: }
>
>
> 1) When TSSetIJacobian is called on line 195, J is empty. Why is J deleted
> after calling the routing but before TSSolve is called ? (Isn't J supposed to
> hold the jacobian ? )
>
> 2) The shift is not calculated before calling TSSetIJacobian. Does this mean
> that the TSSetIJacobian takes care of the shift ?
>
> 3) What is happening on line 198 ?
>
>
> Thank You,
> Sajid Ali
> Applied Physics
> Northwestern University