1 /*
2 * -----------------------------------------------------------------
3 * Programmer(s): Daniel R. Reynolds and Ting Yan @ SMU
4 * Carol Woodward @ LLNL
5 * -----------------------------------------------------------------
6 * SUNDIALS Copyright Start
7 * Copyright (c) 2002-2020, Lawrence Livermore National Security
8 * and Southern Methodist University.
9 * All rights reserved.
10 *
11 * See the top-level LICENSE and NOTICE files for details.
12 *
13 * SPDX-License-Identifier: BSD-3-Clause
14 * SUNDIALS Copyright End
15 * -----------------------------------------------------------------
16 */
17
18 #include <stdio.h>
19 #include <stdlib.h>
20 #include "fcvode.h"
21 #include "cvode_impl.h"
22 #include <cvode/cvode_ls.h>
23 #include <sunmatrix/sunmatrix_sparse.h>
24
25 /* Prototype of the Fortran routine */
26
27 #ifdef __cplusplus /* wrapper to enable C++ usage */
28 extern "C" {
29 #endif
30
31 extern void FCV_SPJAC(realtype *T, realtype *Y,
32 realtype *FY, long int *N,
33 long int *NNZ, realtype *JDATA,
34 sunindextype *JRVALS,
35 sunindextype *JCPTRS, realtype *H,
36 long int *IPAR, realtype *RPAR,
37 realtype *V1, realtype *V2,
38 realtype *V3, int *ier);
39
40 #ifdef __cplusplus
41 }
42 #endif
43
44 /*=============================================================*/
45
46 /* Fortran interface to C routine CVSlsSetSparseJacFn; see
47 fcvode.h for further information */
FCV_SPARSESETJAC(int * ier)48 void FCV_SPARSESETJAC(int *ier)
49 {
50 #if defined(SUNDIALS_INT32_T)
51 cvProcessError((CVodeMem) CV_cvodemem, CV_ILL_INPUT, "CVODE",
52 "FCVSPARSESETJAC",
53 "Sparse Fortran users must configure SUNDIALS with 64-bit integers.");
54 *ier = 1;
55 #else
56 *ier = CVodeSetJacFn(CV_cvodemem, FCVSparseJac);
57 #endif
58 }
59
60 /*=============================================================*/
61
62 /* C interface to user-supplied Fortran routine FCVSPJAC; see
63 fcvode.h for additional information */
FCVSparseJac(realtype t,N_Vector y,N_Vector fy,SUNMatrix J,void * user_data,N_Vector vtemp1,N_Vector vtemp2,N_Vector vtemp3)64 int FCVSparseJac(realtype t, N_Vector y, N_Vector fy,
65 SUNMatrix J, void *user_data, N_Vector vtemp1,
66 N_Vector vtemp2, N_Vector vtemp3)
67 {
68 int ier;
69 realtype *ydata, *fydata, *v1data, *v2data, *v3data, *Jdata;
70 realtype h;
71 long int NP, NNZ;
72 sunindextype *indexvals, *indexptrs;
73 FCVUserData CV_userdata;
74
75 CVodeGetLastStep(CV_cvodemem, &h);
76 ydata = N_VGetArrayPointer(y);
77 fydata = N_VGetArrayPointer(fy);
78 v1data = N_VGetArrayPointer(vtemp1);
79 v2data = N_VGetArrayPointer(vtemp2);
80 v3data = N_VGetArrayPointer(vtemp3);
81 CV_userdata = (FCVUserData) user_data;
82 NP = SUNSparseMatrix_NP(J);
83 NNZ = SUNSparseMatrix_NNZ(J);
84 Jdata = SUNSparseMatrix_Data(J);
85 indexvals = SUNSparseMatrix_IndexValues(J);
86 indexptrs = SUNSparseMatrix_IndexPointers(J);
87
88 FCV_SPJAC(&t, ydata, fydata, &NP, &NNZ, Jdata, indexvals,
89 indexptrs, &h, CV_userdata->ipar, CV_userdata->rpar,
90 v1data, v2data, v3data, &ier);
91 return(ier);
92 }
93
94