xref: /petsc/src/ts/impls/implicit/sundials/sundials.c (revision 5d47aee6dde82290b0b2a6e048526792585136c9)
17cb94ee6SHong Zhang #define PETSCTS_DLL
27cb94ee6SHong Zhang 
37cb94ee6SHong Zhang /*
4db268bfaSHong Zhang     Provides a PETSc interface to SUNDIALS/CVODE solver.
57cb94ee6SHong Zhang     The interface to PVODE (old version of CVODE) was originally contributed
67cb94ee6SHong Zhang     by Liyang Xu. It has been redone by Hong Zhang and Dinesh Kaushik.
7db268bfaSHong Zhang     Reference: sundials-2.3.0/examples/cvode/parallel/cvkryx_p.c
87cb94ee6SHong Zhang */
956a740aaSHong Zhang #include "sundials.h"  /*I "petscts.h" I*/
107cb94ee6SHong Zhang 
117cb94ee6SHong Zhang /*
127cb94ee6SHong Zhang       TSPrecond_Sundials - function that we provide to SUNDIALS to
137cb94ee6SHong Zhang                         evaluate the preconditioner.
147cb94ee6SHong Zhang */
157cb94ee6SHong Zhang #undef __FUNCT__
167cb94ee6SHong Zhang #define __FUNCT__ "TSPrecond_Sundials"
177cb94ee6SHong Zhang PetscErrorCode TSPrecond_Sundials(realtype tn,N_Vector y,N_Vector fy,
187cb94ee6SHong Zhang                     booleantype jok,booleantype *jcurPtr,
197cb94ee6SHong Zhang                     realtype _gamma,void *P_data,
207cb94ee6SHong Zhang                     N_Vector vtemp1,N_Vector vtemp2,N_Vector vtemp3)
217cb94ee6SHong Zhang {
227cb94ee6SHong Zhang   TS             ts = (TS) P_data;
237cb94ee6SHong Zhang   TS_Sundials    *cvode = (TS_Sundials*)ts->data;
247cb94ee6SHong Zhang   PC             pc = cvode->pc;
257cb94ee6SHong Zhang   PetscErrorCode ierr;
267cb94ee6SHong Zhang   Mat            Jac = ts->B;
277cb94ee6SHong Zhang   Vec            yy = cvode->w1;
287cb94ee6SHong Zhang   PetscScalar    one = 1.0,gm;
297cb94ee6SHong Zhang   MatStructure   str = DIFFERENT_NONZERO_PATTERN;
307cb94ee6SHong Zhang   PetscScalar    *y_data;
317cb94ee6SHong Zhang 
327cb94ee6SHong Zhang   PetscFunctionBegin;
337cb94ee6SHong Zhang   /* This allows us to construct preconditioners in-place if we like */
347cb94ee6SHong Zhang   ierr = MatSetUnfactored(Jac);CHKERRQ(ierr);
357cb94ee6SHong Zhang 
367cb94ee6SHong Zhang   /* jok - TRUE means reuse current Jacobian else recompute Jacobian */
377cb94ee6SHong Zhang   if (jok) {
387cb94ee6SHong Zhang     ierr     = MatCopy(cvode->pmat,Jac,str);CHKERRQ(ierr);
397cb94ee6SHong Zhang     *jcurPtr = FALSE;
407cb94ee6SHong Zhang   } else {
417cb94ee6SHong Zhang     /* make PETSc vector yy point to SUNDIALS vector y */
427cb94ee6SHong Zhang     y_data = (PetscScalar *) N_VGetArrayPointer(y);
437cb94ee6SHong Zhang     ierr   = VecPlaceArray(yy,y_data); CHKERRQ(ierr);
444ac7836bSHong Zhang 
457cb94ee6SHong Zhang     /* compute the Jacobian */
467cb94ee6SHong Zhang     ierr = TSComputeRHSJacobian(ts,ts->ptime,yy,&Jac,&Jac,&str);CHKERRQ(ierr);
477cb94ee6SHong Zhang     ierr = VecResetArray(yy); CHKERRQ(ierr);
484ac7836bSHong Zhang 
497cb94ee6SHong Zhang     /* copy the Jacobian matrix */
507cb94ee6SHong Zhang     if (!cvode->pmat) {
517cb94ee6SHong Zhang       ierr = MatDuplicate(Jac,MAT_COPY_VALUES,&cvode->pmat);CHKERRQ(ierr);
527cb94ee6SHong Zhang       ierr = PetscLogObjectParent(ts,cvode->pmat);CHKERRQ(ierr);
532c823083SHong Zhang     } else {
547cb94ee6SHong Zhang       ierr = MatCopy(Jac,cvode->pmat,str);CHKERRQ(ierr);
557cb94ee6SHong Zhang     }
567cb94ee6SHong Zhang     *jcurPtr = TRUE;
577cb94ee6SHong Zhang   }
587cb94ee6SHong Zhang 
597cb94ee6SHong Zhang   /* construct I-gamma*Jac  */
607cb94ee6SHong Zhang   gm   = -_gamma;
617cb94ee6SHong Zhang   ierr = MatScale(Jac,gm);CHKERRQ(ierr);
627cb94ee6SHong Zhang   ierr = MatShift(Jac,one);CHKERRQ(ierr);
637cb94ee6SHong Zhang 
647cb94ee6SHong Zhang   ierr = PCSetOperators(pc,Jac,Jac,str);CHKERRQ(ierr);
657cb94ee6SHong Zhang   PetscFunctionReturn(0);
667cb94ee6SHong Zhang }
677cb94ee6SHong Zhang 
687cb94ee6SHong Zhang /*
697cb94ee6SHong Zhang      TSPSolve_Sundials -  routine that we provide to Sundials that applies the preconditioner.
707cb94ee6SHong Zhang */
717cb94ee6SHong Zhang #undef __FUNCT__
727cb94ee6SHong Zhang #define __FUNCT__ "TSPSolve_Sundials"
734ac7836bSHong Zhang PetscErrorCode TSPSolve_Sundials(realtype tn,N_Vector y,N_Vector fy,N_Vector r,N_Vector z,
744ac7836bSHong Zhang                                  realtype _gamma,realtype delta,int lr,void *P_data,N_Vector vtemp)
757cb94ee6SHong Zhang {
767cb94ee6SHong Zhang   TS              ts = (TS) P_data;
777cb94ee6SHong Zhang   TS_Sundials     *cvode = (TS_Sundials*)ts->data;
787cb94ee6SHong Zhang   PC              pc = cvode->pc;
797cb94ee6SHong Zhang   Vec             rr = cvode->w1,zz = cvode->w2;
807cb94ee6SHong Zhang   PetscErrorCode  ierr;
817cb94ee6SHong Zhang   PetscScalar     *r_data,*z_data;
827cb94ee6SHong Zhang 
837cb94ee6SHong Zhang   PetscFunctionBegin;
847cb94ee6SHong Zhang   /* Make the PETSc work vectors rr and zz point to the arrays in the SUNDIALS vectors r and z respectively*/
857cb94ee6SHong Zhang   r_data  = (PetscScalar *) N_VGetArrayPointer(r);
867cb94ee6SHong Zhang   z_data  = (PetscScalar *) N_VGetArrayPointer(z);
877cb94ee6SHong Zhang   ierr = VecPlaceArray(rr,r_data); CHKERRQ(ierr);
887cb94ee6SHong Zhang   ierr = VecPlaceArray(zz,z_data); CHKERRQ(ierr);
894ac7836bSHong Zhang 
907cb94ee6SHong Zhang   /* Solve the Px=r and put the result in zz */
917cb94ee6SHong Zhang   ierr = PCApply(pc,rr,zz); CHKERRQ(ierr);
927cb94ee6SHong Zhang   ierr = VecResetArray(rr); CHKERRQ(ierr);
937cb94ee6SHong Zhang   ierr = VecResetArray(zz); CHKERRQ(ierr);
947cb94ee6SHong Zhang   PetscFunctionReturn(0);
957cb94ee6SHong Zhang }
967cb94ee6SHong Zhang 
977cb94ee6SHong Zhang /*
987cb94ee6SHong Zhang         TSFunction_Sundials - routine that we provide to Sundials that applies the right hand side.
997cb94ee6SHong Zhang */
1007cb94ee6SHong Zhang #undef __FUNCT__
1017cb94ee6SHong Zhang #define __FUNCT__ "TSFunction_Sundials"
1024ac7836bSHong Zhang int TSFunction_Sundials(realtype t,N_Vector y,N_Vector ydot,void *ctx)
1037cb94ee6SHong Zhang {
1047cb94ee6SHong Zhang   TS              ts = (TS) ctx;
1057adad957SLisandro Dalcin   MPI_Comm        comm = ((PetscObject)ts)->comm;
1067cb94ee6SHong Zhang   TS_Sundials     *cvode = (TS_Sundials*)ts->data;
1077cb94ee6SHong Zhang   Vec             yy = cvode->w1,yyd = cvode->w2;
1087cb94ee6SHong Zhang   PetscScalar     *y_data,*ydot_data;
1097cb94ee6SHong Zhang   PetscErrorCode  ierr;
1107cb94ee6SHong Zhang 
1117cb94ee6SHong Zhang   PetscFunctionBegin;
1125ff03cf7SDinesh Kaushik   /* Make the PETSc work vectors yy and yyd point to the arrays in the SUNDIALS vectors y and ydot respectively*/
1137cb94ee6SHong Zhang   y_data     = (PetscScalar *) N_VGetArrayPointer(y);
1147cb94ee6SHong Zhang   ydot_data  = (PetscScalar *) N_VGetArrayPointer(ydot);
1154ac7836bSHong Zhang   ierr = VecPlaceArray(yy,y_data);CHKERRABORT(comm,ierr);
1164ac7836bSHong Zhang   ierr = VecPlaceArray(yyd,ydot_data); CHKERRABORT(comm,ierr);
1174ac7836bSHong Zhang 
1187cb94ee6SHong Zhang   /* now compute the right hand side function */
1197cb94ee6SHong Zhang   ierr = TSComputeRHSFunction(ts,t,yy,yyd); CHKERRABORT(comm,ierr);
1207cb94ee6SHong Zhang   ierr = VecResetArray(yy); CHKERRABORT(comm,ierr);
1217cb94ee6SHong Zhang   ierr = VecResetArray(yyd); CHKERRABORT(comm,ierr);
1224ac7836bSHong Zhang   PetscFunctionReturn(0);
1237cb94ee6SHong Zhang }
1247cb94ee6SHong Zhang 
1257cb94ee6SHong Zhang /*
1267cb94ee6SHong Zhang        TSStep_Sundials_Nonlinear - Calls Sundials to integrate the ODE.
1277cb94ee6SHong Zhang */
1287cb94ee6SHong Zhang #undef __FUNCT__
1297cb94ee6SHong Zhang #define __FUNCT__ "TSStep_Sundials_Nonlinear"
1307cb94ee6SHong Zhang /*
1317cb94ee6SHong Zhang     TSStep_Sundials_Nonlinear -
1327cb94ee6SHong Zhang 
1337cb94ee6SHong Zhang    steps - number of time steps
1347cb94ee6SHong Zhang    time - time that integrater is  terminated.
1357cb94ee6SHong Zhang */
1367cb94ee6SHong Zhang PetscErrorCode TSStep_Sundials_Nonlinear(TS ts,int *steps,double *time)
1377cb94ee6SHong Zhang {
1387cb94ee6SHong Zhang   TS_Sundials    *cvode = (TS_Sundials*)ts->data;
1397cb94ee6SHong Zhang   Vec            sol = ts->vec_sol;
1407cb94ee6SHong Zhang   PetscErrorCode ierr;
141*5d47aee6SHong Zhang   PetscInt       i,max_steps = ts->max_steps,flag;
1427cb94ee6SHong Zhang   long int       its;
1437cb94ee6SHong Zhang   realtype       t,tout;
1447cb94ee6SHong Zhang   PetscScalar    *y_data;
1457cb94ee6SHong Zhang   void           *mem;
146*5d47aee6SHong Zhang   const PCType   pctype;
147*5d47aee6SHong Zhang   PetscTruth     pcnone;
1487cb94ee6SHong Zhang 
1497cb94ee6SHong Zhang   PetscFunctionBegin;
150db268bfaSHong Zhang   /* Call CVodeCreate to create the solver memory */
1517cb94ee6SHong Zhang   mem = CVodeCreate(cvode->cvode_type, CV_NEWTON);
1527cb94ee6SHong Zhang   if (!mem) SETERRQ(1,"CVodeCreate() fails");
1537cb94ee6SHong Zhang   flag = CVodeSetFdata(mem,ts);
1547cb94ee6SHong Zhang   if (flag) SETERRQ(1,"CVodeSetFdata() fails");
1557cb94ee6SHong Zhang 
1567cb94ee6SHong Zhang   /*
1577cb94ee6SHong Zhang      Call CVodeMalloc to initialize the integrator memory:
1587cb94ee6SHong Zhang      mem is the pointer to the integrator memory returned by CVodeCreate
1597cb94ee6SHong Zhang      f       is the user's right hand side function in y'=f(t,y)
1607cb94ee6SHong Zhang      T0      is the initial time
1617cb94ee6SHong Zhang      u       is the initial dependent variable vector
1627cb94ee6SHong Zhang      CV_SS   specifies scalar relative and absolute tolerances
1637cb94ee6SHong Zhang      reltol  is the relative tolerance
1647cb94ee6SHong Zhang      &abstol is a pointer to the scalar absolute tolerance
1657cb94ee6SHong Zhang   */
1667cb94ee6SHong Zhang   flag = CVodeMalloc(mem,TSFunction_Sundials,ts->ptime,cvode->y,CV_SS,cvode->reltol,&cvode->abstol);
1677cb94ee6SHong Zhang   if (flag) SETERRQ(1,"CVodeMalloc() fails");
1687cb94ee6SHong Zhang 
1697cb94ee6SHong Zhang   /* initialize the number of steps */
1707cb94ee6SHong Zhang   *steps = -ts->steps;
1717cb94ee6SHong Zhang   ierr   = TSMonitor(ts,ts->steps,ts->ptime,sol);CHKERRQ(ierr);
1727cb94ee6SHong Zhang 
1737cb94ee6SHong Zhang   /* call CVSpgmr to use GMRES as the linear solver.        */
1747cb94ee6SHong Zhang   /* setup the ode integrator with the given preconditioner */
175*5d47aee6SHong Zhang   ierr = PCGetType(cvode->pc,&pctype);CHKERRQ(ierr);
176*5d47aee6SHong Zhang   ierr = PetscTypeCompare((PetscObject)cvode->pc,PCNONE,&pcnone);CHKERRQ(ierr);
177*5d47aee6SHong Zhang   if (pcnone){
178*5d47aee6SHong Zhang     flag  = CVSpgmr(mem,PREC_NONE,0);
179*5d47aee6SHong Zhang   } else {
1807cb94ee6SHong Zhang     flag  = CVSpgmr(mem,PREC_LEFT,0);
181*5d47aee6SHong Zhang   }
1827cb94ee6SHong Zhang   if (flag) SETERRQ(1,"CVSpgmr() fails");
1834ac7836bSHong Zhang 
1847cb94ee6SHong Zhang   /* Set preconditioner setup and solve routines Precond and PSolve,
1857cb94ee6SHong Zhang      and the pointer to the user-defined block data */
1864ac7836bSHong Zhang   flag = CVSpilsSetPreconditioner(mem,TSPrecond_Sundials,TSPSolve_Sundials,ts);
1877cb94ee6SHong Zhang   if (flag) SETERRQ(1,"CVSpgmrSetPreconditioner() fails");
1887cb94ee6SHong Zhang 
189*5d47aee6SHong Zhang   flag = CVSpilsSetGSType(mem, MODIFIED_GS);
190*5d47aee6SHong Zhang   if (flag) SETERRQ(1,"CVSpgmrSetGSType() fails");
191*5d47aee6SHong Zhang 
1927cb94ee6SHong Zhang   tout = ts->max_time;
1937cb94ee6SHong Zhang   ierr = VecGetArray(ts->vec_sol,&y_data);CHKERRQ(ierr);
1947cb94ee6SHong Zhang   N_VSetArrayPointer((realtype *)y_data,cvode->y);
1957cb94ee6SHong Zhang   ierr = VecRestoreArray(ts->vec_sol,PETSC_NULL);CHKERRQ(ierr);
1967cb94ee6SHong Zhang   for (i = 0; i < max_steps; i++) {
1977cb94ee6SHong Zhang     if (ts->ptime >= ts->max_time) break;
1987cb94ee6SHong Zhang     ierr = CVode(mem,tout,cvode->y,&t,CV_ONE_STEP);CHKERRQ(ierr);
199e44a3fc5SHong Zhang     if (ts->ops->postupdate){
200e44a3fc5SHong Zhang       ierr = (*ts->ops->postupdate)(ts,ts->ptime,PETSC_NULL);CHKERRQ(ierr);
201e44a3fc5SHong Zhang     }
2027cb94ee6SHong Zhang     if (t > ts->max_time && cvode->exact_final_time) {
2037cb94ee6SHong Zhang       /* interpolate to final requested time */
2047cb94ee6SHong Zhang       ierr = CVodeGetDky(mem,tout,0,cvode->y);CHKERRQ(ierr);
2057cb94ee6SHong Zhang       t = tout;
2067cb94ee6SHong Zhang     }
2077cb94ee6SHong Zhang     ts->time_step = t - ts->ptime;
2087cb94ee6SHong Zhang     ts->ptime     = t;
2097cb94ee6SHong Zhang 
2107cb94ee6SHong Zhang     /* copy the solution from cvode->y to cvode->update and sol */
2117cb94ee6SHong Zhang     ierr = VecPlaceArray(cvode->w1,y_data); CHKERRQ(ierr);
2127cb94ee6SHong Zhang     ierr = VecCopy(cvode->w1,cvode->update);CHKERRQ(ierr);
2137cb94ee6SHong Zhang     ierr = VecResetArray(cvode->w1); CHKERRQ(ierr);
2147cb94ee6SHong Zhang     ierr = VecCopy(cvode->update,sol);CHKERRQ(ierr);
2157cb94ee6SHong Zhang     ierr = CVodeGetNumNonlinSolvIters(mem,&its);CHKERRQ(ierr);
2167cb94ee6SHong Zhang     ts->nonlinear_its = its;
2174ac7836bSHong Zhang     ierr = CVSpilsGetNumLinIters(mem, &its);
2187cb94ee6SHong Zhang     ts->linear_its = its;
2197cb94ee6SHong Zhang     ts->steps++;
2207cb94ee6SHong Zhang     ierr = TSMonitor(ts,ts->steps,t,sol);CHKERRQ(ierr);
2217cb94ee6SHong Zhang   }
2222c823083SHong Zhang   cvode->mem = mem;
2237cb94ee6SHong Zhang   *steps    += ts->steps;
2247cb94ee6SHong Zhang   *time      = t;
2257cb94ee6SHong Zhang   PetscFunctionReturn(0);
2267cb94ee6SHong Zhang }
2277cb94ee6SHong Zhang 
2287cb94ee6SHong Zhang #undef __FUNCT__
2297cb94ee6SHong Zhang #define __FUNCT__ "TSDestroy_Sundials"
2307cb94ee6SHong Zhang PetscErrorCode TSDestroy_Sundials(TS ts)
2317cb94ee6SHong Zhang {
2327cb94ee6SHong Zhang   TS_Sundials    *cvode = (TS_Sundials*)ts->data;
2337cb94ee6SHong Zhang   PetscErrorCode ierr;
2347cb94ee6SHong Zhang 
2357cb94ee6SHong Zhang   PetscFunctionBegin;
2367cb94ee6SHong Zhang   if (cvode->pmat)   {ierr = MatDestroy(cvode->pmat);CHKERRQ(ierr);}
2377cb94ee6SHong Zhang   if (cvode->pc)     {ierr = PCDestroy(cvode->pc);CHKERRQ(ierr);}
2387cb94ee6SHong Zhang   if (cvode->update) {ierr = VecDestroy(cvode->update);CHKERRQ(ierr);}
2397cb94ee6SHong Zhang   if (cvode->func)   {ierr = VecDestroy(cvode->func);CHKERRQ(ierr);}
2407cb94ee6SHong Zhang   if (cvode->rhs)    {ierr = VecDestroy(cvode->rhs);CHKERRQ(ierr);}
2417cb94ee6SHong Zhang   if (cvode->w1)     {ierr = VecDestroy(cvode->w1);CHKERRQ(ierr);}
2427cb94ee6SHong Zhang   if (cvode->w2)     {ierr = VecDestroy(cvode->w2);CHKERRQ(ierr);}
243a07356b8SSatish Balay   ierr = MPI_Comm_free(&(cvode->comm_sundials));CHKERRQ(ierr);
2442c823083SHong Zhang   if (cvode->mem) {CVodeFree(&cvode->mem);}
2457cb94ee6SHong Zhang   ierr = PetscFree(cvode);CHKERRQ(ierr);
2467cb94ee6SHong Zhang   PetscFunctionReturn(0);
2477cb94ee6SHong Zhang }
2487cb94ee6SHong Zhang 
2497cb94ee6SHong Zhang #undef __FUNCT__
2507cb94ee6SHong Zhang #define __FUNCT__ "TSSetUp_Sundials_Nonlinear"
2517cb94ee6SHong Zhang PetscErrorCode TSSetUp_Sundials_Nonlinear(TS ts)
2527cb94ee6SHong Zhang {
2537cb94ee6SHong Zhang   TS_Sundials    *cvode = (TS_Sundials*)ts->data;
2547cb94ee6SHong Zhang   PetscErrorCode ierr;
2557cb94ee6SHong Zhang   int            glosize,locsize,i;
2567cb94ee6SHong Zhang   PetscScalar    *y_data,*parray;
2577cb94ee6SHong Zhang 
2587cb94ee6SHong Zhang   PetscFunctionBegin;
2597cb94ee6SHong Zhang   ierr = PCSetFromOptions(cvode->pc);CHKERRQ(ierr);
2607cb94ee6SHong Zhang   /* get the vector size */
2617cb94ee6SHong Zhang   ierr = VecGetSize(ts->vec_sol,&glosize);CHKERRQ(ierr);
2627cb94ee6SHong Zhang   ierr = VecGetLocalSize(ts->vec_sol,&locsize);CHKERRQ(ierr);
2637cb94ee6SHong Zhang 
2647cb94ee6SHong Zhang   /* allocate the memory for N_Vec y */
265a07356b8SSatish Balay   cvode->y = N_VNew_Parallel(cvode->comm_sundials,locsize,glosize);
2667cb94ee6SHong Zhang   if (!cvode->y) SETERRQ(1,"cvode->y is not allocated");
2677cb94ee6SHong Zhang 
2687cb94ee6SHong Zhang   /* initialize N_Vec y */
2697cb94ee6SHong Zhang   ierr = VecGetArray(ts->vec_sol,&parray);CHKERRQ(ierr);
2707cb94ee6SHong Zhang   y_data = (PetscScalar *) N_VGetArrayPointer(cvode->y);
2717cb94ee6SHong Zhang   for (i = 0; i < locsize; i++) y_data[i] = parray[i];
2727cb94ee6SHong Zhang   /*ierr = PetscMemcpy(y_data,parray,locsize*sizeof(PETSC_SCALAR)); CHKERRQ(ierr);*/
2737cb94ee6SHong Zhang   ierr = VecRestoreArray(ts->vec_sol,PETSC_NULL);CHKERRQ(ierr);
2747cb94ee6SHong Zhang   ierr = VecDuplicate(ts->vec_sol,&cvode->update);CHKERRQ(ierr);
2757cb94ee6SHong Zhang   ierr = VecDuplicate(ts->vec_sol,&cvode->func);CHKERRQ(ierr);
2767cb94ee6SHong Zhang   ierr = PetscLogObjectParent(ts,cvode->update);CHKERRQ(ierr);
2777cb94ee6SHong Zhang   ierr = PetscLogObjectParent(ts,cvode->func);CHKERRQ(ierr);
2787cb94ee6SHong Zhang 
2797cb94ee6SHong Zhang   /*
2807cb94ee6SHong Zhang       Create work vectors for the TSPSolve_Sundials() routine. Note these are
2817cb94ee6SHong Zhang     allocated with zero space arrays because the actual array space is provided
2827cb94ee6SHong Zhang     by Sundials and set using VecPlaceArray().
2837cb94ee6SHong Zhang   */
2847adad957SLisandro Dalcin   ierr = VecCreateMPIWithArray(((PetscObject)ts)->comm,locsize,PETSC_DECIDE,0,&cvode->w1);CHKERRQ(ierr);
2857adad957SLisandro Dalcin   ierr = VecCreateMPIWithArray(((PetscObject)ts)->comm,locsize,PETSC_DECIDE,0,&cvode->w2);CHKERRQ(ierr);
2867cb94ee6SHong Zhang   ierr = PetscLogObjectParent(ts,cvode->w1);CHKERRQ(ierr);
2877cb94ee6SHong Zhang   ierr = PetscLogObjectParent(ts,cvode->w2);CHKERRQ(ierr);
2887cb94ee6SHong Zhang   PetscFunctionReturn(0);
2897cb94ee6SHong Zhang }
2907cb94ee6SHong Zhang 
2916fadb2cdSHong Zhang /* type of CVODE linear multistep method */
292dfcd32c8SHong Zhang const char *TSSundialsLmmTypes[] = {"","adams","bdf","TSSundialsLmmType","SUNDIALS_",0};
2936fadb2cdSHong Zhang /* type of G-S orthogonalization used by CVODE linear solver */
294dfcd32c8SHong Zhang const char *TSSundialsGramSchmidtTypes[] = {"","modified","classical","TSSundialsGramSchmidtType","SUNDIALS_",0};
295a04cf4d8SBarry Smith 
2967cb94ee6SHong Zhang #undef __FUNCT__
2977cb94ee6SHong Zhang #define __FUNCT__ "TSSetFromOptions_Sundials_Nonlinear"
2987cb94ee6SHong Zhang PetscErrorCode TSSetFromOptions_Sundials_Nonlinear(TS ts)
2997cb94ee6SHong Zhang {
3007cb94ee6SHong Zhang   TS_Sundials    *cvode = (TS_Sundials*)ts->data;
3017cb94ee6SHong Zhang   PetscErrorCode ierr;
3027cb94ee6SHong Zhang   int            indx;
3037cb94ee6SHong Zhang   PetscTruth     flag;
3047cb94ee6SHong Zhang 
3057cb94ee6SHong Zhang   PetscFunctionBegin;
3067cb94ee6SHong Zhang   ierr = PetscOptionsHead("SUNDIALS ODE solver options");CHKERRQ(ierr);
3076fadb2cdSHong Zhang     ierr = PetscOptionsEList("-ts_sundials_type","Scheme","TSSundialsSetType",TSSundialsLmmTypes,3,TSSundialsLmmTypes[cvode->cvode_type],&indx,&flag);CHKERRQ(ierr);
3087cb94ee6SHong Zhang     if (flag) {
3096fadb2cdSHong Zhang       ierr = TSSundialsSetType(ts,(TSSundialsLmmType)indx);CHKERRQ(ierr);
3107cb94ee6SHong Zhang     }
3116fadb2cdSHong Zhang     ierr = PetscOptionsEList("-ts_sundials_gramschmidt_type","Type of orthogonalization","TSSundialsSetGramSchmidtType",TSSundialsGramSchmidtTypes,3,TSSundialsGramSchmidtTypes[cvode->gtype],&indx,&flag);CHKERRQ(ierr);
3127cb94ee6SHong Zhang     if (flag) {
3137cb94ee6SHong Zhang       ierr = TSSundialsSetGramSchmidtType(ts,(TSSundialsGramSchmidtType)indx);CHKERRQ(ierr);
3147cb94ee6SHong Zhang     }
3157cb94ee6SHong Zhang     ierr = PetscOptionsReal("-ts_sundials_atol","Absolute tolerance for convergence","TSSundialsSetTolerance",cvode->abstol,&cvode->abstol,PETSC_NULL);CHKERRQ(ierr);
3167cb94ee6SHong Zhang     ierr = PetscOptionsReal("-ts_sundials_rtol","Relative tolerance for convergence","TSSundialsSetTolerance",cvode->reltol,&cvode->reltol,PETSC_NULL);CHKERRQ(ierr);
3177cb94ee6SHong Zhang     ierr = PetscOptionsReal("-ts_sundials_linear_tolerance","Convergence tolerance for linear solve","TSSundialsSetLinearTolerance",cvode->linear_tol,&cvode->linear_tol,&flag);CHKERRQ(ierr);
3187cb94ee6SHong Zhang     ierr = PetscOptionsInt("-ts_sundials_gmres_restart","Number of GMRES orthogonalization directions","TSSundialsSetGMRESRestart",cvode->restart,&cvode->restart,&flag);CHKERRQ(ierr);
319d7fc3247SBarry Smith     ierr = PetscOptionsName("-ts_sundials_exact_final_time","Allow SUNDIALS to stop near the final time, not exactly on it","TSSundialsSetExactFinalTime",&flag);CHKERRQ(ierr);
320d7fc3247SBarry Smith     if (flag) cvode->exact_final_time = PETSC_TRUE;
3217cb94ee6SHong Zhang   ierr = PetscOptionsTail();CHKERRQ(ierr);
3227cb94ee6SHong Zhang   PetscFunctionReturn(0);
3237cb94ee6SHong Zhang }
3247cb94ee6SHong Zhang 
3257cb94ee6SHong Zhang #undef __FUNCT__
3267cb94ee6SHong Zhang #define __FUNCT__ "TSView_Sundials"
3277cb94ee6SHong Zhang PetscErrorCode TSView_Sundials(TS ts,PetscViewer viewer)
3287cb94ee6SHong Zhang {
3297cb94ee6SHong Zhang   TS_Sundials    *cvode = (TS_Sundials*)ts->data;
3307cb94ee6SHong Zhang   PetscErrorCode ierr;
3317cb94ee6SHong Zhang   char           *type;
3327cb94ee6SHong Zhang   char           atype[] = "Adams";
3337cb94ee6SHong Zhang   char           btype[] = "BDF: backward differentiation formula";
3347cb94ee6SHong Zhang   PetscTruth     iascii,isstring;
3352c823083SHong Zhang   long int       nsteps,its,nfevals,nlinsetups,nfails,itmp;
3362c823083SHong Zhang   PetscInt       qlast,qcur;
337*5d47aee6SHong Zhang   PetscReal      hinused,hlast,hcur,tcur,tolsfac;
3387cb94ee6SHong Zhang 
3397cb94ee6SHong Zhang   PetscFunctionBegin;
3407cb94ee6SHong Zhang   if (cvode->cvode_type == SUNDIALS_ADAMS) {type = atype;}
3417cb94ee6SHong Zhang   else                                     {type = btype;}
3427cb94ee6SHong Zhang 
3437cb94ee6SHong Zhang   ierr = PetscTypeCompare((PetscObject)viewer,PETSC_VIEWER_ASCII,&iascii);CHKERRQ(ierr);
3447cb94ee6SHong Zhang   ierr = PetscTypeCompare((PetscObject)viewer,PETSC_VIEWER_STRING,&isstring);CHKERRQ(ierr);
3457cb94ee6SHong Zhang   if (iascii) {
3467cb94ee6SHong Zhang     ierr = PetscViewerASCIIPrintf(viewer,"Sundials integrater does not use SNES!\n");CHKERRQ(ierr);
3477cb94ee6SHong Zhang     ierr = PetscViewerASCIIPrintf(viewer,"Sundials integrater type %s\n",type);CHKERRQ(ierr);
3487cb94ee6SHong Zhang     ierr = PetscViewerASCIIPrintf(viewer,"Sundials abs tol %g rel tol %g\n",cvode->abstol,cvode->reltol);CHKERRQ(ierr);
3497cb94ee6SHong Zhang     ierr = PetscViewerASCIIPrintf(viewer,"Sundials linear solver tolerance factor %g\n",cvode->linear_tol);CHKERRQ(ierr);
3507cb94ee6SHong Zhang     ierr = PetscViewerASCIIPrintf(viewer,"Sundials GMRES max iterations (same as restart in SUNDIALS) %D\n",cvode->restart);CHKERRQ(ierr);
3517cb94ee6SHong Zhang     if (cvode->gtype == SUNDIALS_MODIFIED_GS) {
3527cb94ee6SHong Zhang       ierr = PetscViewerASCIIPrintf(viewer,"Sundials using modified Gram-Schmidt for orthogonalization in GMRES\n");CHKERRQ(ierr);
3537cb94ee6SHong Zhang     } else {
3547cb94ee6SHong Zhang       ierr = PetscViewerASCIIPrintf(viewer,"Sundials using unmodified (classical) Gram-Schmidt for orthogonalization in GMRES\n");CHKERRQ(ierr);
3557cb94ee6SHong Zhang     }
3562c823083SHong Zhang 
357*5d47aee6SHong Zhang     /* Outputs from CVODE, CVSPILS */
358*5d47aee6SHong Zhang     ierr = CVodeGetTolScaleFactor(cvode->mem,&tolsfac);CHKERRQ(ierr);
359*5d47aee6SHong Zhang     ierr = PetscViewerASCIIPrintf(viewer,"Sundials suggested factor for tolerance scaling %g\n",tolsfac);CHKERRQ(ierr);
3602c823083SHong Zhang     ierr = CVodeGetIntegratorStats(cvode->mem,&nsteps,&nfevals,
3612c823083SHong Zhang                                    &nlinsetups,&nfails,&qlast,&qcur,
3622c823083SHong Zhang                                    &hinused,&hlast,&hcur,&tcur);CHKERRQ(ierr);
3632c823083SHong Zhang     ierr = PetscViewerASCIIPrintf(viewer,"Sundials cumulative number of internal steps %D\n",nsteps);CHKERRQ(ierr);
3642c823083SHong Zhang     ierr = PetscViewerASCIIPrintf(viewer,"Sundials no. of calls to rhs function %D\n",nfevals);CHKERRQ(ierr);
3652c823083SHong Zhang     ierr = PetscViewerASCIIPrintf(viewer,"Sundials no. of calls to linear solver setup function %D\n",nlinsetups);CHKERRQ(ierr);
3662c823083SHong Zhang     ierr = PetscViewerASCIIPrintf(viewer,"Sundials no. of error test failures %D\n",nfails);CHKERRQ(ierr);
3672c823083SHong Zhang 
3682c823083SHong Zhang     ierr = CVodeGetNonlinSolvStats(cvode->mem,&its,&nfails);CHKERRQ(ierr);
3692c823083SHong Zhang     ierr = PetscViewerASCIIPrintf(viewer,"Sundials no. of nonlinear solver iterations %D\n",its);CHKERRQ(ierr);
3702c823083SHong Zhang     ierr = PetscViewerASCIIPrintf(viewer,"Sundials no. of nonlinear convergence failure %D\n",nfails);CHKERRQ(ierr);
3712c823083SHong Zhang 
3722c823083SHong Zhang     ierr = CVSpilsGetNumLinIters(cvode->mem, &its);CHKERRQ(ierr); /* its = no. of calls to TSPrecond_Sundials() */
3732c823083SHong Zhang     ierr = PetscViewerASCIIPrintf(viewer,"Sundials no. of linear iterations %D\n",its);CHKERRQ(ierr);
3742c823083SHong Zhang     ierr = CVSpilsGetNumConvFails(cvode->mem,&itmp);CHKERRQ(ierr);
3752c823083SHong Zhang     ierr = PetscViewerASCIIPrintf(viewer,"Sundials no. of linear convergence failures %D\n",itmp);CHKERRQ(ierr);
3762c823083SHong Zhang     ierr = CVSpilsGetNumPrecEvals(cvode->mem,&itmp);CHKERRQ(ierr);
3772c823083SHong Zhang     ierr = PetscViewerASCIIPrintf(viewer,"Sundials no. of preconditioner evaluations %D\n",itmp);CHKERRQ(ierr);
3782c823083SHong Zhang     ierr = CVSpilsGetNumPrecSolves(cvode->mem,&itmp);CHKERRQ(ierr);
3792c823083SHong Zhang     ierr = PetscViewerASCIIPrintf(viewer,"Sundials no. of preconditioner solves %D\n",itmp);CHKERRQ(ierr);
3802c823083SHong Zhang     ierr = CVSpilsGetNumJtimesEvals(cvode->mem,&itmp);CHKERRQ(ierr);
3812c823083SHong Zhang     ierr = PetscViewerASCIIPrintf(viewer,"Sundials no. of Jacobian-vector product evaluations %D\n",itmp);CHKERRQ(ierr);
3822c823083SHong Zhang     ierr = CVSpilsGetNumRhsEvals(cvode->mem,&itmp);CHKERRQ(ierr);
3832c823083SHong Zhang     ierr = PetscViewerASCIIPrintf(viewer,"Sundials no. of rhs calls for finite diff. Jacobian-vector evals %D\n",itmp);CHKERRQ(ierr);
3847cb94ee6SHong Zhang   } else if (isstring) {
3857cb94ee6SHong Zhang     ierr = PetscViewerStringSPrintf(viewer,"Sundials type %s",type);CHKERRQ(ierr);
3867cb94ee6SHong Zhang   } else {
3877cb94ee6SHong Zhang     SETERRQ1(PETSC_ERR_SUP,"Viewer type %s not supported by TS Sundials",((PetscObject)viewer)->type_name);
3887cb94ee6SHong Zhang   }
3897cb94ee6SHong Zhang   ierr = PetscViewerASCIIPushTab(viewer);CHKERRQ(ierr);
3907cb94ee6SHong Zhang   ierr = PCView(cvode->pc,viewer);CHKERRQ(ierr);
3917cb94ee6SHong Zhang   ierr = PetscViewerASCIIPopTab(viewer);CHKERRQ(ierr);
3927cb94ee6SHong Zhang   PetscFunctionReturn(0);
3937cb94ee6SHong Zhang }
3947cb94ee6SHong Zhang 
3957cb94ee6SHong Zhang 
3967cb94ee6SHong Zhang /* --------------------------------------------------------------------------*/
3977cb94ee6SHong Zhang EXTERN_C_BEGIN
3987cb94ee6SHong Zhang #undef __FUNCT__
3997cb94ee6SHong Zhang #define __FUNCT__ "TSSundialsSetType_Sundials"
4006fadb2cdSHong Zhang PetscErrorCode PETSCTS_DLLEXPORT TSSundialsSetType_Sundials(TS ts,TSSundialsLmmType type)
4017cb94ee6SHong Zhang {
4027cb94ee6SHong Zhang   TS_Sundials *cvode = (TS_Sundials*)ts->data;
4037cb94ee6SHong Zhang 
4047cb94ee6SHong Zhang   PetscFunctionBegin;
4057cb94ee6SHong Zhang   cvode->cvode_type = type;
4067cb94ee6SHong Zhang   PetscFunctionReturn(0);
4077cb94ee6SHong Zhang }
4087cb94ee6SHong Zhang EXTERN_C_END
4097cb94ee6SHong Zhang 
4107cb94ee6SHong Zhang EXTERN_C_BEGIN
4117cb94ee6SHong Zhang #undef __FUNCT__
4127cb94ee6SHong Zhang #define __FUNCT__ "TSSundialsSetGMRESRestart_Sundials"
4137cb94ee6SHong Zhang PetscErrorCode PETSCTS_DLLEXPORT TSSundialsSetGMRESRestart_Sundials(TS ts,int restart)
4147cb94ee6SHong Zhang {
4157cb94ee6SHong Zhang   TS_Sundials *cvode = (TS_Sundials*)ts->data;
4167cb94ee6SHong Zhang 
4177cb94ee6SHong Zhang   PetscFunctionBegin;
4187cb94ee6SHong Zhang   cvode->restart = restart;
4197cb94ee6SHong Zhang   PetscFunctionReturn(0);
4207cb94ee6SHong Zhang }
4217cb94ee6SHong Zhang EXTERN_C_END
4227cb94ee6SHong Zhang 
4237cb94ee6SHong Zhang EXTERN_C_BEGIN
4247cb94ee6SHong Zhang #undef __FUNCT__
4257cb94ee6SHong Zhang #define __FUNCT__ "TSSundialsSetLinearTolerance_Sundials"
4267cb94ee6SHong Zhang PetscErrorCode PETSCTS_DLLEXPORT TSSundialsSetLinearTolerance_Sundials(TS ts,double tol)
4277cb94ee6SHong Zhang {
4287cb94ee6SHong Zhang   TS_Sundials *cvode = (TS_Sundials*)ts->data;
4297cb94ee6SHong Zhang 
4307cb94ee6SHong Zhang   PetscFunctionBegin;
4317cb94ee6SHong Zhang   cvode->linear_tol = tol;
4327cb94ee6SHong Zhang   PetscFunctionReturn(0);
4337cb94ee6SHong Zhang }
4347cb94ee6SHong Zhang EXTERN_C_END
4357cb94ee6SHong Zhang 
4367cb94ee6SHong Zhang EXTERN_C_BEGIN
4377cb94ee6SHong Zhang #undef __FUNCT__
4387cb94ee6SHong Zhang #define __FUNCT__ "TSSundialsSetGramSchmidtType_Sundials"
4397cb94ee6SHong Zhang PetscErrorCode PETSCTS_DLLEXPORT TSSundialsSetGramSchmidtType_Sundials(TS ts,TSSundialsGramSchmidtType type)
4407cb94ee6SHong Zhang {
4417cb94ee6SHong Zhang   TS_Sundials *cvode = (TS_Sundials*)ts->data;
4427cb94ee6SHong Zhang 
4437cb94ee6SHong Zhang   PetscFunctionBegin;
4447cb94ee6SHong Zhang   cvode->gtype = type;
4457cb94ee6SHong Zhang   PetscFunctionReturn(0);
4467cb94ee6SHong Zhang }
4477cb94ee6SHong Zhang EXTERN_C_END
4487cb94ee6SHong Zhang 
4497cb94ee6SHong Zhang EXTERN_C_BEGIN
4507cb94ee6SHong Zhang #undef __FUNCT__
4517cb94ee6SHong Zhang #define __FUNCT__ "TSSundialsSetTolerance_Sundials"
4527cb94ee6SHong Zhang PetscErrorCode PETSCTS_DLLEXPORT TSSundialsSetTolerance_Sundials(TS ts,double aabs,double rel)
4537cb94ee6SHong Zhang {
4547cb94ee6SHong Zhang   TS_Sundials *cvode = (TS_Sundials*)ts->data;
4557cb94ee6SHong Zhang 
4567cb94ee6SHong Zhang   PetscFunctionBegin;
4577cb94ee6SHong Zhang   if (aabs != PETSC_DECIDE) cvode->abstol = aabs;
4587cb94ee6SHong Zhang   if (rel != PETSC_DECIDE)  cvode->reltol = rel;
4597cb94ee6SHong Zhang   PetscFunctionReturn(0);
4607cb94ee6SHong Zhang }
4617cb94ee6SHong Zhang EXTERN_C_END
4627cb94ee6SHong Zhang 
4637cb94ee6SHong Zhang EXTERN_C_BEGIN
4647cb94ee6SHong Zhang #undef __FUNCT__
4657cb94ee6SHong Zhang #define __FUNCT__ "TSSundialsGetPC_Sundials"
4667cb94ee6SHong Zhang PetscErrorCode PETSCTS_DLLEXPORT TSSundialsGetPC_Sundials(TS ts,PC *pc)
4677cb94ee6SHong Zhang {
4687cb94ee6SHong Zhang   TS_Sundials *cvode = (TS_Sundials*)ts->data;
4697cb94ee6SHong Zhang 
4707cb94ee6SHong Zhang   PetscFunctionBegin;
4717cb94ee6SHong Zhang   *pc = cvode->pc;
4727cb94ee6SHong Zhang   PetscFunctionReturn(0);
4737cb94ee6SHong Zhang }
4747cb94ee6SHong Zhang EXTERN_C_END
4757cb94ee6SHong Zhang 
4767cb94ee6SHong Zhang EXTERN_C_BEGIN
4777cb94ee6SHong Zhang #undef __FUNCT__
4787cb94ee6SHong Zhang #define __FUNCT__ "TSSundialsGetIterations_Sundials"
4797cb94ee6SHong Zhang PetscErrorCode PETSCTS_DLLEXPORT TSSundialsGetIterations_Sundials(TS ts,int *nonlin,int *lin)
4807cb94ee6SHong Zhang {
4817cb94ee6SHong Zhang   PetscFunctionBegin;
4822c823083SHong Zhang   if (nonlin) *nonlin = ts->nonlinear_its;
4832c823083SHong Zhang   if (lin)    *lin    = ts->linear_its;
4847cb94ee6SHong Zhang   PetscFunctionReturn(0);
4857cb94ee6SHong Zhang }
4867cb94ee6SHong Zhang EXTERN_C_END
4877cb94ee6SHong Zhang 
4887cb94ee6SHong Zhang EXTERN_C_BEGIN
4897cb94ee6SHong Zhang #undef __FUNCT__
4907cb94ee6SHong Zhang #define __FUNCT__ "TSSundialsSetExactFinalTime_Sundials"
4917cb94ee6SHong Zhang PetscErrorCode PETSCTS_DLLEXPORT TSSundialsSetExactFinalTime_Sundials(TS ts,PetscTruth s)
4927cb94ee6SHong Zhang {
4937cb94ee6SHong Zhang   TS_Sundials *cvode = (TS_Sundials*)ts->data;
4947cb94ee6SHong Zhang 
4957cb94ee6SHong Zhang   PetscFunctionBegin;
4967cb94ee6SHong Zhang   cvode->exact_final_time = s;
4977cb94ee6SHong Zhang   PetscFunctionReturn(0);
4987cb94ee6SHong Zhang }
4997cb94ee6SHong Zhang EXTERN_C_END
5007cb94ee6SHong Zhang /* -------------------------------------------------------------------------------------------*/
5017cb94ee6SHong Zhang 
5027cb94ee6SHong Zhang #undef __FUNCT__
5037cb94ee6SHong Zhang #define __FUNCT__ "TSSundialsGetIterations"
5047cb94ee6SHong Zhang /*@C
5057cb94ee6SHong Zhang    TSSundialsGetIterations - Gets the number of nonlinear and linear iterations used so far by Sundials.
5067cb94ee6SHong Zhang 
5077cb94ee6SHong Zhang    Not Collective
5087cb94ee6SHong Zhang 
5097cb94ee6SHong Zhang    Input parameters:
5107cb94ee6SHong Zhang .    ts     - the time-step context
5117cb94ee6SHong Zhang 
5127cb94ee6SHong Zhang    Output Parameters:
5137cb94ee6SHong Zhang +   nonlin - number of nonlinear iterations
5147cb94ee6SHong Zhang -   lin    - number of linear iterations
5157cb94ee6SHong Zhang 
5167cb94ee6SHong Zhang    Level: advanced
5177cb94ee6SHong Zhang 
5187cb94ee6SHong Zhang    Notes:
5197cb94ee6SHong Zhang     These return the number since the creation of the TS object
5207cb94ee6SHong Zhang 
5217cb94ee6SHong Zhang .keywords: non-linear iterations, linear iterations
5227cb94ee6SHong Zhang 
5237cb94ee6SHong Zhang .seealso: TSSundialsSetType(), TSSundialsSetGMRESRestart(),
5247cb94ee6SHong Zhang           TSSundialsSetLinearTolerance(), TSSundialsSetGramSchmidtType(), TSSundialsSetTolerance(),
5257cb94ee6SHong Zhang           TSSundialsGetIterations(), TSSundialsSetType(), TSSundialsSetGMRESRestart(),
5267cb94ee6SHong Zhang           TSSundialsSetLinearTolerance(), TSSundialsSetTolerance(), TSSundialsGetPC(),
5277cb94ee6SHong Zhang           TSSundialsSetExactFinalTime()
5287cb94ee6SHong Zhang 
5297cb94ee6SHong Zhang @*/
5307cb94ee6SHong Zhang PetscErrorCode PETSCTS_DLLEXPORT TSSundialsGetIterations(TS ts,int *nonlin,int *lin)
5317cb94ee6SHong Zhang {
5327cb94ee6SHong Zhang   PetscErrorCode ierr,(*f)(TS,int*,int*);
5337cb94ee6SHong Zhang 
5347cb94ee6SHong Zhang   PetscFunctionBegin;
5357cb94ee6SHong Zhang   ierr = PetscObjectQueryFunction((PetscObject)ts,"TSSundialsGetIterations_C",(void (**)(void))&f);CHKERRQ(ierr);
5367cb94ee6SHong Zhang   if (f) {
5377cb94ee6SHong Zhang     ierr = (*f)(ts,nonlin,lin);CHKERRQ(ierr);
5387cb94ee6SHong Zhang   }
5397cb94ee6SHong Zhang   PetscFunctionReturn(0);
5407cb94ee6SHong Zhang }
5417cb94ee6SHong Zhang 
5427cb94ee6SHong Zhang #undef __FUNCT__
5437cb94ee6SHong Zhang #define __FUNCT__ "TSSundialsSetType"
5447cb94ee6SHong Zhang /*@
5457cb94ee6SHong Zhang    TSSundialsSetType - Sets the method that Sundials will use for integration.
5467cb94ee6SHong Zhang 
5477cb94ee6SHong Zhang    Collective on TS
5487cb94ee6SHong Zhang 
5497cb94ee6SHong Zhang    Input parameters:
5507cb94ee6SHong Zhang +    ts     - the time-step context
5517cb94ee6SHong Zhang -    type   - one of  SUNDIALS_ADAMS or SUNDIALS_BDF
5527cb94ee6SHong Zhang 
5537cb94ee6SHong Zhang    Level: intermediate
5547cb94ee6SHong Zhang 
5557cb94ee6SHong Zhang .keywords: Adams, backward differentiation formula
5567cb94ee6SHong Zhang 
5577cb94ee6SHong Zhang .seealso: TSSundialsGetIterations(),  TSSundialsSetGMRESRestart(),
5587cb94ee6SHong Zhang           TSSundialsSetLinearTolerance(), TSSundialsSetGramSchmidtType(), TSSundialsSetTolerance(),
5597cb94ee6SHong Zhang           TSSundialsGetIterations(), TSSundialsSetType(), TSSundialsSetGMRESRestart(),
5607cb94ee6SHong Zhang           TSSundialsSetLinearTolerance(), TSSundialsSetTolerance(), TSSundialsGetPC(),
5617cb94ee6SHong Zhang           TSSundialsSetExactFinalTime()
5627cb94ee6SHong Zhang @*/
5636fadb2cdSHong Zhang PetscErrorCode PETSCTS_DLLEXPORT TSSundialsSetType(TS ts,TSSundialsLmmType type)
5647cb94ee6SHong Zhang {
5656fadb2cdSHong Zhang   PetscErrorCode ierr,(*f)(TS,TSSundialsLmmType);
5667cb94ee6SHong Zhang 
5677cb94ee6SHong Zhang   PetscFunctionBegin;
5687cb94ee6SHong Zhang   ierr = PetscObjectQueryFunction((PetscObject)ts,"TSSundialsSetType_C",(void (**)(void))&f);CHKERRQ(ierr);
5697cb94ee6SHong Zhang   if (f) {
5707cb94ee6SHong Zhang     ierr = (*f)(ts,type);CHKERRQ(ierr);
5717cb94ee6SHong Zhang   }
5727cb94ee6SHong Zhang   PetscFunctionReturn(0);
5737cb94ee6SHong Zhang }
5747cb94ee6SHong Zhang 
5757cb94ee6SHong Zhang #undef __FUNCT__
5767cb94ee6SHong Zhang #define __FUNCT__ "TSSundialsSetGMRESRestart"
5777cb94ee6SHong Zhang /*@
5787cb94ee6SHong Zhang    TSSundialsSetGMRESRestart - Sets the dimension of the Krylov space used by
5797cb94ee6SHong Zhang        GMRES in the linear solver in SUNDIALS. SUNDIALS DOES NOT use restarted GMRES so
5807cb94ee6SHong Zhang        this is ALSO the maximum number of GMRES steps that will be used.
5817cb94ee6SHong Zhang 
5827cb94ee6SHong Zhang    Collective on TS
5837cb94ee6SHong Zhang 
5847cb94ee6SHong Zhang    Input parameters:
5857cb94ee6SHong Zhang +    ts      - the time-step context
5867cb94ee6SHong Zhang -    restart - number of direction vectors (the restart size).
5877cb94ee6SHong Zhang 
5887cb94ee6SHong Zhang    Level: advanced
5897cb94ee6SHong Zhang 
5907cb94ee6SHong Zhang .keywords: GMRES, restart
5917cb94ee6SHong Zhang 
5927cb94ee6SHong Zhang .seealso: TSSundialsGetIterations(), TSSundialsSetType(),
5937cb94ee6SHong Zhang           TSSundialsSetLinearTolerance(), TSSundialsSetGramSchmidtType(), TSSundialsSetTolerance(),
5947cb94ee6SHong Zhang           TSSundialsGetIterations(), TSSundialsSetType(), TSSundialsSetGMRESRestart(),
5957cb94ee6SHong Zhang           TSSundialsSetLinearTolerance(), TSSundialsSetTolerance(), TSSundialsGetPC(),
5967cb94ee6SHong Zhang           TSSundialsSetExactFinalTime()
5977cb94ee6SHong Zhang 
5987cb94ee6SHong Zhang @*/
5997cb94ee6SHong Zhang PetscErrorCode PETSCTS_DLLEXPORT TSSundialsSetGMRESRestart(TS ts,int restart)
6007cb94ee6SHong Zhang {
6017cb94ee6SHong Zhang   PetscErrorCode ierr,(*f)(TS,int);
6027cb94ee6SHong Zhang 
6037cb94ee6SHong Zhang   PetscFunctionBegin;
6047cb94ee6SHong Zhang   ierr = PetscObjectQueryFunction((PetscObject)ts,"TSSundialsSetGMRESRestart_C",(void (**)(void))&f);CHKERRQ(ierr);
6057cb94ee6SHong Zhang   if (f) {
6067cb94ee6SHong Zhang     ierr = (*f)(ts,restart);CHKERRQ(ierr);
6077cb94ee6SHong Zhang   }
6087cb94ee6SHong Zhang   PetscFunctionReturn(0);
6097cb94ee6SHong Zhang }
6107cb94ee6SHong Zhang 
6117cb94ee6SHong Zhang #undef __FUNCT__
6127cb94ee6SHong Zhang #define __FUNCT__ "TSSundialsSetLinearTolerance"
6137cb94ee6SHong Zhang /*@
6147cb94ee6SHong Zhang    TSSundialsSetLinearTolerance - Sets the tolerance used to solve the linear
6157cb94ee6SHong Zhang        system by SUNDIALS.
6167cb94ee6SHong Zhang 
6177cb94ee6SHong Zhang    Collective on TS
6187cb94ee6SHong Zhang 
6197cb94ee6SHong Zhang    Input parameters:
6207cb94ee6SHong Zhang +    ts     - the time-step context
6217cb94ee6SHong Zhang -    tol    - the factor by which the tolerance on the nonlinear solver is
6227cb94ee6SHong Zhang              multiplied to get the tolerance on the linear solver, .05 by default.
6237cb94ee6SHong Zhang 
6247cb94ee6SHong Zhang    Level: advanced
6257cb94ee6SHong Zhang 
6267cb94ee6SHong Zhang .keywords: GMRES, linear convergence tolerance, SUNDIALS
6277cb94ee6SHong Zhang 
6287cb94ee6SHong Zhang .seealso: TSSundialsGetIterations(), TSSundialsSetType(), TSSundialsSetGMRESRestart(),
6297cb94ee6SHong Zhang           TSSundialsSetGramSchmidtType(), TSSundialsSetTolerance(),
6307cb94ee6SHong Zhang           TSSundialsGetIterations(), TSSundialsSetType(), TSSundialsSetGMRESRestart(),
6317cb94ee6SHong Zhang           TSSundialsSetLinearTolerance(), TSSundialsSetTolerance(), TSSundialsGetPC(),
6327cb94ee6SHong Zhang           TSSundialsSetExactFinalTime()
6337cb94ee6SHong Zhang 
6347cb94ee6SHong Zhang @*/
6357cb94ee6SHong Zhang PetscErrorCode PETSCTS_DLLEXPORT TSSundialsSetLinearTolerance(TS ts,double tol)
6367cb94ee6SHong Zhang {
6377cb94ee6SHong Zhang   PetscErrorCode ierr,(*f)(TS,double);
6387cb94ee6SHong Zhang 
6397cb94ee6SHong Zhang   PetscFunctionBegin;
6407cb94ee6SHong Zhang   ierr = PetscObjectQueryFunction((PetscObject)ts,"TSSundialsSetLinearTolerance_C",(void (**)(void))&f);CHKERRQ(ierr);
6417cb94ee6SHong Zhang   if (f) {
6427cb94ee6SHong Zhang     ierr = (*f)(ts,tol);CHKERRQ(ierr);
6437cb94ee6SHong Zhang   }
6447cb94ee6SHong Zhang   PetscFunctionReturn(0);
6457cb94ee6SHong Zhang }
6467cb94ee6SHong Zhang 
6477cb94ee6SHong Zhang #undef __FUNCT__
6487cb94ee6SHong Zhang #define __FUNCT__ "TSSundialsSetGramSchmidtType"
6497cb94ee6SHong Zhang /*@
6507cb94ee6SHong Zhang    TSSundialsSetGramSchmidtType - Sets type of orthogonalization used
6517cb94ee6SHong Zhang         in GMRES method by SUNDIALS linear solver.
6527cb94ee6SHong Zhang 
6537cb94ee6SHong Zhang    Collective on TS
6547cb94ee6SHong Zhang 
6557cb94ee6SHong Zhang    Input parameters:
6567cb94ee6SHong Zhang +    ts  - the time-step context
6577cb94ee6SHong Zhang -    type - either SUNDIALS_MODIFIED_GS or SUNDIALS_CLASSICAL_GS
6587cb94ee6SHong Zhang 
6597cb94ee6SHong Zhang    Level: advanced
6607cb94ee6SHong Zhang 
6617cb94ee6SHong Zhang .keywords: Sundials, orthogonalization
6627cb94ee6SHong Zhang 
6637cb94ee6SHong Zhang .seealso: TSSundialsGetIterations(), TSSundialsSetType(), TSSundialsSetGMRESRestart(),
6647cb94ee6SHong Zhang           TSSundialsSetLinearTolerance(),  TSSundialsSetTolerance(),
6657cb94ee6SHong Zhang           TSSundialsGetIterations(), TSSundialsSetType(), TSSundialsSetGMRESRestart(),
6667cb94ee6SHong Zhang           TSSundialsSetLinearTolerance(), TSSundialsSetTolerance(), TSSundialsGetPC(),
6677cb94ee6SHong Zhang           TSSundialsSetExactFinalTime()
6687cb94ee6SHong Zhang 
6697cb94ee6SHong Zhang @*/
6707cb94ee6SHong Zhang PetscErrorCode PETSCTS_DLLEXPORT TSSundialsSetGramSchmidtType(TS ts,TSSundialsGramSchmidtType type)
6717cb94ee6SHong Zhang {
6727cb94ee6SHong Zhang   PetscErrorCode ierr,(*f)(TS,TSSundialsGramSchmidtType);
6737cb94ee6SHong Zhang 
6747cb94ee6SHong Zhang   PetscFunctionBegin;
6757cb94ee6SHong Zhang   ierr = PetscObjectQueryFunction((PetscObject)ts,"TSSundialsSetGramSchmidtType_C",(void (**)(void))&f);CHKERRQ(ierr);
6767cb94ee6SHong Zhang   if (f) {
6777cb94ee6SHong Zhang     ierr = (*f)(ts,type);CHKERRQ(ierr);
6787cb94ee6SHong Zhang   }
6797cb94ee6SHong Zhang   PetscFunctionReturn(0);
6807cb94ee6SHong Zhang }
6817cb94ee6SHong Zhang 
6827cb94ee6SHong Zhang #undef __FUNCT__
6837cb94ee6SHong Zhang #define __FUNCT__ "TSSundialsSetTolerance"
6847cb94ee6SHong Zhang /*@
6857cb94ee6SHong Zhang    TSSundialsSetTolerance - Sets the absolute and relative tolerance used by
6867cb94ee6SHong Zhang                          Sundials for error control.
6877cb94ee6SHong Zhang 
6887cb94ee6SHong Zhang    Collective on TS
6897cb94ee6SHong Zhang 
6907cb94ee6SHong Zhang    Input parameters:
6917cb94ee6SHong Zhang +    ts  - the time-step context
6927cb94ee6SHong Zhang .    aabs - the absolute tolerance
6937cb94ee6SHong Zhang -    rel - the relative tolerance
6947cb94ee6SHong Zhang 
6957cb94ee6SHong Zhang      See the Cvode/Sundials users manual for exact details on these parameters. Essentially
6967cb94ee6SHong Zhang     these regulate the size of the error for a SINGLE timestep.
6977cb94ee6SHong Zhang 
6987cb94ee6SHong Zhang    Level: intermediate
6997cb94ee6SHong Zhang 
7007cb94ee6SHong Zhang .keywords: Sundials, tolerance
7017cb94ee6SHong Zhang 
7027cb94ee6SHong Zhang .seealso: TSSundialsGetIterations(), TSSundialsSetType(), TSSundialsSetGMRESRestart(),
7037cb94ee6SHong Zhang           TSSundialsSetLinearTolerance(), TSSundialsSetGramSchmidtType(),
7047cb94ee6SHong Zhang           TSSundialsGetIterations(), TSSundialsSetType(), TSSundialsSetGMRESRestart(),
7057cb94ee6SHong Zhang           TSSundialsSetLinearTolerance(), TSSundialsSetTolerance(), TSSundialsGetPC(),
7067cb94ee6SHong Zhang           TSSundialsSetExactFinalTime()
7077cb94ee6SHong Zhang 
7087cb94ee6SHong Zhang @*/
7097cb94ee6SHong Zhang PetscErrorCode PETSCTS_DLLEXPORT TSSundialsSetTolerance(TS ts,double aabs,double rel)
7107cb94ee6SHong Zhang {
7117cb94ee6SHong Zhang   PetscErrorCode ierr,(*f)(TS,double,double);
7127cb94ee6SHong Zhang 
7137cb94ee6SHong Zhang   PetscFunctionBegin;
7147cb94ee6SHong Zhang   ierr = PetscObjectQueryFunction((PetscObject)ts,"TSSundialsSetTolerance_C",(void (**)(void))&f);CHKERRQ(ierr);
7157cb94ee6SHong Zhang   if (f) {
7167cb94ee6SHong Zhang     ierr = (*f)(ts,aabs,rel);CHKERRQ(ierr);
7177cb94ee6SHong Zhang   }
7187cb94ee6SHong Zhang   PetscFunctionReturn(0);
7197cb94ee6SHong Zhang }
7207cb94ee6SHong Zhang 
7217cb94ee6SHong Zhang #undef __FUNCT__
7227cb94ee6SHong Zhang #define __FUNCT__ "TSSundialsGetPC"
7237cb94ee6SHong Zhang /*@
7247cb94ee6SHong Zhang    TSSundialsGetPC - Extract the PC context from a time-step context for Sundials.
7257cb94ee6SHong Zhang 
7267cb94ee6SHong Zhang    Input Parameter:
7277cb94ee6SHong Zhang .    ts - the time-step context
7287cb94ee6SHong Zhang 
7297cb94ee6SHong Zhang    Output Parameter:
7307cb94ee6SHong Zhang .    pc - the preconditioner context
7317cb94ee6SHong Zhang 
7327cb94ee6SHong Zhang    Level: advanced
7337cb94ee6SHong Zhang 
7347cb94ee6SHong Zhang .seealso: TSSundialsGetIterations(), TSSundialsSetType(), TSSundialsSetGMRESRestart(),
7357cb94ee6SHong Zhang           TSSundialsSetLinearTolerance(), TSSundialsSetGramSchmidtType(), TSSundialsSetTolerance(),
7367cb94ee6SHong Zhang           TSSundialsGetIterations(), TSSundialsSetType(), TSSundialsSetGMRESRestart(),
7377cb94ee6SHong Zhang           TSSundialsSetLinearTolerance(), TSSundialsSetTolerance()
7387cb94ee6SHong Zhang @*/
7397cb94ee6SHong Zhang PetscErrorCode PETSCTS_DLLEXPORT TSSundialsGetPC(TS ts,PC *pc)
7407cb94ee6SHong Zhang {
7417cb94ee6SHong Zhang   PetscErrorCode ierr,(*f)(TS,PC *);
7427cb94ee6SHong Zhang 
7437cb94ee6SHong Zhang   PetscFunctionBegin;
7447cb94ee6SHong Zhang   ierr = PetscObjectQueryFunction((PetscObject)ts,"TSSundialsGetPC_C",(void (**)(void))&f);CHKERRQ(ierr);
7457cb94ee6SHong Zhang   if (f) {
7467cb94ee6SHong Zhang     ierr = (*f)(ts,pc);CHKERRQ(ierr);
7477cb94ee6SHong Zhang   } else {
7487cb94ee6SHong Zhang     SETERRQ(PETSC_ERR_ARG_WRONGSTATE,"TS must be of Sundials type to extract the PC");
7497cb94ee6SHong Zhang   }
7507cb94ee6SHong Zhang 
7517cb94ee6SHong Zhang   PetscFunctionReturn(0);
7527cb94ee6SHong Zhang }
7537cb94ee6SHong Zhang 
7547cb94ee6SHong Zhang #undef __FUNCT__
7557cb94ee6SHong Zhang #define __FUNCT__ "TSSundialsSetExactFinalTime"
7567cb94ee6SHong Zhang /*@
7577cb94ee6SHong Zhang    TSSundialsSetExactFinalTime - Determines if Sundials interpolates solution to the
7587cb94ee6SHong Zhang       exact final time requested by the user or just returns it at the final time
7597cb94ee6SHong Zhang       it computed. (Defaults to true).
7607cb94ee6SHong Zhang 
7617cb94ee6SHong Zhang    Input Parameter:
7627cb94ee6SHong Zhang +   ts - the time-step context
7637cb94ee6SHong Zhang -   ft - PETSC_TRUE if interpolates, else PETSC_FALSE
7647cb94ee6SHong Zhang 
7657cb94ee6SHong Zhang    Level: beginner
7667cb94ee6SHong Zhang 
7677cb94ee6SHong Zhang .seealso:TSSundialsGetIterations(), TSSundialsSetType(), TSSundialsSetGMRESRestart(),
7687cb94ee6SHong Zhang           TSSundialsSetLinearTolerance(), TSSundialsSetGramSchmidtType(), TSSundialsSetTolerance(),
7697cb94ee6SHong Zhang           TSSundialsGetIterations(), TSSundialsSetType(), TSSundialsSetGMRESRestart(),
7707cb94ee6SHong Zhang           TSSundialsSetLinearTolerance(), TSSundialsSetTolerance(), TSSundialsGetPC()
7717cb94ee6SHong Zhang @*/
7727cb94ee6SHong Zhang PetscErrorCode PETSCTS_DLLEXPORT TSSundialsSetExactFinalTime(TS ts,PetscTruth ft)
7737cb94ee6SHong Zhang {
7747cb94ee6SHong Zhang   PetscErrorCode ierr,(*f)(TS,PetscTruth);
7757cb94ee6SHong Zhang 
7767cb94ee6SHong Zhang   PetscFunctionBegin;
7777cb94ee6SHong Zhang   ierr = PetscObjectQueryFunction((PetscObject)ts,"TSSundialsSetExactFinalTime_C",(void (**)(void))&f);CHKERRQ(ierr);
7787cb94ee6SHong Zhang   if (f) {
7797cb94ee6SHong Zhang     ierr = (*f)(ts,ft);CHKERRQ(ierr);
7807cb94ee6SHong Zhang   }
7817cb94ee6SHong Zhang   PetscFunctionReturn(0);
7827cb94ee6SHong Zhang }
7837cb94ee6SHong Zhang 
7847cb94ee6SHong Zhang /* -------------------------------------------------------------------------------------------*/
7857cb94ee6SHong Zhang /*MC
7867cb94ee6SHong Zhang       TS_Sundials - ODE solver using the LLNL CVODE/SUNDIALS package (now called SUNDIALS)
7877cb94ee6SHong Zhang 
7887cb94ee6SHong Zhang    Options Database:
7897cb94ee6SHong Zhang +    -ts_sundials_type <bdf,adams>
7907cb94ee6SHong Zhang .    -ts_sundials_gramschmidt_type <modified, classical> - type of orthogonalization inside GMRES
7917cb94ee6SHong Zhang .    -ts_sundials_atol <tol> - Absolute tolerance for convergence
7927cb94ee6SHong Zhang .    -ts_sundials_rtol <tol> - Relative tolerance for convergence
7937cb94ee6SHong Zhang .    -ts_sundials_linear_tolerance <tol>
7947cb94ee6SHong Zhang .    -ts_sundials_gmres_restart <restart> - Number of GMRES orthogonalization directions
7957cb94ee6SHong Zhang -    -ts_sundials_not_exact_final_time -Allow SUNDIALS to stop near the final time, not exactly on it
7967cb94ee6SHong Zhang 
7977cb94ee6SHong Zhang     Notes: This uses its own nonlinear solver and Krylov method so PETSc SNES and KSP options do not apply
7987cb94ee6SHong Zhang            only PETSc PC options
7997cb94ee6SHong Zhang 
8007cb94ee6SHong Zhang     Level: beginner
8017cb94ee6SHong Zhang 
8027cb94ee6SHong Zhang .seealso:  TSCreate(), TS, TSSetType(), TSSundialsSetType(), TSSundialsSetGMRESRestart(), TSSundialsSetLinearTolerance(),
8037cb94ee6SHong Zhang            TSSundialsSetGramSchmidtType(), TSSundialsSetTolerance(), TSSundialsGetPC(), TSSundialsGetIterations(), TSSundialsSetExactFinalTime()
8047cb94ee6SHong Zhang 
8057cb94ee6SHong Zhang M*/
8067cb94ee6SHong Zhang EXTERN_C_BEGIN
8077cb94ee6SHong Zhang #undef __FUNCT__
8087cb94ee6SHong Zhang #define __FUNCT__ "TSCreate_Sundials"
8097cb94ee6SHong Zhang PetscErrorCode PETSCTS_DLLEXPORT TSCreate_Sundials(TS ts)
8107cb94ee6SHong Zhang {
8117cb94ee6SHong Zhang   TS_Sundials *cvode;
8127cb94ee6SHong Zhang   PetscErrorCode ierr;
8137cb94ee6SHong Zhang 
8147cb94ee6SHong Zhang   PetscFunctionBegin;
8157cb94ee6SHong Zhang   ts->ops->destroy         = TSDestroy_Sundials;
8167cb94ee6SHong Zhang   ts->ops->view            = TSView_Sundials;
8177cb94ee6SHong Zhang 
8187cb94ee6SHong Zhang   if (ts->problem_type != TS_NONLINEAR) {
8197cb94ee6SHong Zhang     SETERRQ(PETSC_ERR_SUP,"Only support for nonlinear problems");
8207cb94ee6SHong Zhang   }
8217cb94ee6SHong Zhang   ts->ops->setup           = TSSetUp_Sundials_Nonlinear;
8227cb94ee6SHong Zhang   ts->ops->step            = TSStep_Sundials_Nonlinear;
8237cb94ee6SHong Zhang   ts->ops->setfromoptions  = TSSetFromOptions_Sundials_Nonlinear;
8247cb94ee6SHong Zhang 
82538f2d2fdSLisandro Dalcin   ierr = PetscNewLog(ts,TS_Sundials,&cvode);CHKERRQ(ierr);
8267adad957SLisandro Dalcin   ierr = PCCreate(((PetscObject)ts)->comm,&cvode->pc);CHKERRQ(ierr);
8277cb94ee6SHong Zhang   ierr = PetscLogObjectParent(ts,cvode->pc);CHKERRQ(ierr);
8287cb94ee6SHong Zhang   ts->data          = (void*)cvode;
8296fadb2cdSHong Zhang   cvode->cvode_type = SUNDIALS_BDF;
8306fadb2cdSHong Zhang   cvode->gtype      = SUNDIALS_CLASSICAL_GS;
8317cb94ee6SHong Zhang   cvode->restart    = 5;
8327cb94ee6SHong Zhang   cvode->linear_tol = .05;
8337cb94ee6SHong Zhang 
8347cb94ee6SHong Zhang   cvode->exact_final_time = PETSC_FALSE;
8357cb94ee6SHong Zhang 
836a07356b8SSatish Balay   ierr = MPI_Comm_dup(((PetscObject)ts)->comm,&(cvode->comm_sundials));CHKERRQ(ierr);
8377cb94ee6SHong Zhang   /* set tolerance for Sundials */
8387cb94ee6SHong Zhang   cvode->reltol = 1e-6;
8392c823083SHong Zhang   cvode->abstol = 1e-6;
8407cb94ee6SHong Zhang 
8417cb94ee6SHong Zhang   ierr = PetscObjectComposeFunctionDynamic((PetscObject)ts,"TSSundialsSetType_C","TSSundialsSetType_Sundials",
8427cb94ee6SHong Zhang                     TSSundialsSetType_Sundials);CHKERRQ(ierr);
8437cb94ee6SHong Zhang   ierr = PetscObjectComposeFunctionDynamic((PetscObject)ts,"TSSundialsSetGMRESRestart_C",
8447cb94ee6SHong Zhang                     "TSSundialsSetGMRESRestart_Sundials",
8457cb94ee6SHong Zhang                     TSSundialsSetGMRESRestart_Sundials);CHKERRQ(ierr);
8467cb94ee6SHong Zhang   ierr = PetscObjectComposeFunctionDynamic((PetscObject)ts,"TSSundialsSetLinearTolerance_C",
8477cb94ee6SHong Zhang                     "TSSundialsSetLinearTolerance_Sundials",
8487cb94ee6SHong Zhang                      TSSundialsSetLinearTolerance_Sundials);CHKERRQ(ierr);
8497cb94ee6SHong Zhang   ierr = PetscObjectComposeFunctionDynamic((PetscObject)ts,"TSSundialsSetGramSchmidtType_C",
8507cb94ee6SHong Zhang                     "TSSundialsSetGramSchmidtType_Sundials",
8517cb94ee6SHong Zhang                      TSSundialsSetGramSchmidtType_Sundials);CHKERRQ(ierr);
8527cb94ee6SHong Zhang   ierr = PetscObjectComposeFunctionDynamic((PetscObject)ts,"TSSundialsSetTolerance_C",
8537cb94ee6SHong Zhang                     "TSSundialsSetTolerance_Sundials",
8547cb94ee6SHong Zhang                      TSSundialsSetTolerance_Sundials);CHKERRQ(ierr);
8557cb94ee6SHong Zhang   ierr = PetscObjectComposeFunctionDynamic((PetscObject)ts,"TSSundialsGetPC_C",
8567cb94ee6SHong Zhang                     "TSSundialsGetPC_Sundials",
8577cb94ee6SHong Zhang                      TSSundialsGetPC_Sundials);CHKERRQ(ierr);
8587cb94ee6SHong Zhang   ierr = PetscObjectComposeFunctionDynamic((PetscObject)ts,"TSSundialsGetIterations_C",
8597cb94ee6SHong Zhang                     "TSSundialsGetIterations_Sundials",
8607cb94ee6SHong Zhang                      TSSundialsGetIterations_Sundials);CHKERRQ(ierr);
8617cb94ee6SHong Zhang   ierr = PetscObjectComposeFunctionDynamic((PetscObject)ts,"TSSundialsSetExactFinalTime_C",
8627cb94ee6SHong Zhang                     "TSSundialsSetExactFinalTime_Sundials",
8637cb94ee6SHong Zhang                      TSSundialsSetExactFinalTime_Sundials);CHKERRQ(ierr);
8647cb94ee6SHong Zhang   PetscFunctionReturn(0);
8657cb94ee6SHong Zhang }
8667cb94ee6SHong Zhang EXTERN_C_END
8677cb94ee6SHong Zhang 
8687cb94ee6SHong Zhang 
8697cb94ee6SHong Zhang 
8707cb94ee6SHong Zhang 
8717cb94ee6SHong Zhang 
8727cb94ee6SHong Zhang 
8737cb94ee6SHong Zhang 
8747cb94ee6SHong Zhang 
8757cb94ee6SHong Zhang 
8767cb94ee6SHong Zhang 
877