summarylogtreecommitdiffstats
path: root/r845.patch
blob: dec23fc92e5371cd9d27ee2d10c0c063997aefed (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
Index: setup.py
===================================================================
--- setup.py	(revision 844)
+++ setup.py	(revision 845)
@@ -309,15 +309,30 @@
             self.with_SUNDIALS=True
             L.debug('SUNDIALS found.')
             sundials_version = None
+            sundials_vector_type_size = None
             
             try:
                 if os.path.exists(os.path.join(os.path.join(self.incdirs,'sundials'), 'sundials_config.h')):
                     with open(os.path.join(os.path.join(self.incdirs,'sundials'), 'sundials_config.h')) as f:
                         for line in f:
-                            if "SUNDIALS_PACKAGE_VERSION" in line:
+                            if "SUNDIALS_PACKAGE_VERSION" in line or "SUNDIALS_VERSION" in line:
                                 sundials_version = tuple([int(f) for f in line.split()[-1][1:-1].split(".")])
                                 L.debug('SUNDIALS %d.%d found.'%(sundials_version[0], sundials_version[1]))
-            except Exception:
+                                break
+                    with open(os.path.join(os.path.join(self.incdirs,'sundials'), 'sundials_config.h')) as f:
+                        for line in f:
+                            if "SUNDIALS_INT32_T" in line and line.startswith("#define"):
+                                sundials_vector_type_size = "32"
+                                L.debug('SUNDIALS vector type size %s bit found.'%(sundials_vector_type_size))
+                                break
+                            if "SUNDIALS_INT64_T" in line and line.startswith("#define"):
+                                sundials_vector_type_size = "64"
+                                L.debug('SUNDIALS vector type size %s bit found.'%(sundials_vector_type_size))
+                                if self.with_SLU:
+                                    L.warning("It is recommended to set the SUNDIALS_INDEX_TYPE to an 32bit integer when using SUNDIALS together with SuperLU.")
+                                    L.warning("SuperLU may not function properly.")
+                                break
+            except Exception as e:
                 if os.path.exists(os.path.join(os.path.join(self.incdirs,'arkode'), 'arkode.h')): #This was added in 2.6
                     sundials_version = (2,6,0)
                     L.debug('SUNDIALS 2.6 found.')
@@ -326,6 +341,7 @@
                     L.debug('SUNDIALS 2.5 found.')
                 
             self.SUNDIALS_version = sundials_version
+            self.SUNDIALS_vector_size = sundials_vector_type_size
             
         else:    
             L.warning(("Could not find Sundials, check the provided path (--sundials-home={}) "+ 
@@ -375,7 +391,8 @@
         # SUNDIALS
         if self.with_SUNDIALS:
             compile_time_env = {'SUNDIALS_VERSION': self.SUNDIALS_version,
-                                'SUNDIALS_WITH_SUPERLU': self.sundials_with_superlu}
+                                'SUNDIALS_WITH_SUPERLU': self.sundials_with_superlu,
+                                'SUNDIALS_VECTOR_SIZE': self.SUNDIALS_vector_size}
             #CVode and IDA
             ext_list += cythonize(["assimulo" + os.path.sep + "solvers" + os.path.sep + "sundials.pyx"], 
                                  include_path=[".","assimulo","assimulo" + os.sep + "lib"],
@@ -382,11 +399,19 @@
                                  compile_time_env=compile_time_env, force=True)
             ext_list[-1].include_dirs = [np.get_include(), "assimulo","assimulo"+os.sep+"lib", self.incdirs]
             ext_list[-1].library_dirs = [self.libdirs]
-            ext_list[-1].libraries = ["sundials_cvodes", "sundials_nvecserial", "sundials_idas"]
+            
+            if self.SUNDIALS_version >= (3,0,0):
+                ext_list[-1].libraries = ["sundials_cvodes", "sundials_nvecserial", "sundials_idas", "sundials_sunlinsoldense", "sundials_sunlinsolspgmr", "sundials_sunmatrixdense", "sundials_sunmatrixsparse"]
+            else:
+                ext_list[-1].libraries = ["sundials_cvodes", "sundials_nvecserial", "sundials_idas"]
             if self.sundials_with_superlu and self.with_SLU: #If SUNDIALS is compiled with support for SuperLU
+                if self.SUNDIALS_version >= (3,0,0):
+                    ext_list[-1].libraries.extend(["sundials_sunlinsolsuperlumt"])
+                
                 ext_list[-1].include_dirs.append(self.SLUincdir)
                 ext_list[-1].library_dirs.append(self.SLUlibdir)
                 ext_list[-1].libraries.extend(self.superLUFiles)
+                
         
             #Kinsol
             ext_list += cythonize(["assimulo"+os.path.sep+"solvers"+os.path.sep+"kinsol.pyx"], 
@@ -395,7 +420,11 @@
             ext_list[-1].include_dirs = [np.get_include(), "assimulo","assimulo"+os.sep+"lib", self.incdirs]
             ext_list[-1].library_dirs = [self.libdirs]
             ext_list[-1].libraries = ["sundials_kinsol", "sundials_nvecserial"]
-    
+            
+            if self.sundials_with_superlu and self.with_SLU: #If SUNDIALS is compiled with support for SuperLU
+                ext_list[-1].include_dirs.append(self.SLUincdir)
+                ext_list[-1].library_dirs.append(self.SLUlibdir)
+                ext_list[-1].libraries.extend(self.superLUFiles)
         
         for el in ext_list:
             #Debug
Index: assimulo/solvers/__init__.py
===================================================================
--- assimulo/solvers/__init__.py	(revision 844)
+++ assimulo/solvers/__init__.py	(revision 845)
@@ -25,7 +25,7 @@
     from .euler import ExplicitEuler
     from .euler import ImplicitEuler
 except ImportError as ie:
-    sys.stderr.write("Could not find {}\n".format(ie.args[0].split("'")[1]))
+    sys.stderr.write("Could not find " + str(ie) + "\n")
 try:
     from .radau5 import Radau5ODE
     from .radau5 import Radau5DAE
@@ -32,43 +32,43 @@
     from .radau5 import _Radau5ODE
     from .radau5 import _Radau5DAE 
 except ImportError as ie:
-    sys.stderr.write("Could not find {}\n".format(ie.args[0].split("'")[1]))
+    sys.stderr.write("Could not find " + str(ie) + "\n")
 try:
     from .sundials import IDA
     from .sundials import CVode
 except ImportError as ie:
-    sys.stderr.write("Could not find {}\n".format(ie.args[0].split("'")[1]))
+    sys.stderr.write("Could not find " + str(ie) + "\n")
 try:
     from .kinsol import KINSOL
 except ImportError as ie:
-    sys.stderr.write("Could not find {}\n".format(ie.args[0].split("'")[1]))
+    sys.stderr.write("Could not find " + str(ie) + "\n")
 try:
     from .runge_kutta import RungeKutta34
     from .runge_kutta import RungeKutta4
     from .runge_kutta import Dopri5
 except ImportError as ie:
-    sys.stderr.write("Could not find {}\n".format(ie.args[0].split("'")[1]))
+    sys.stderr.write("Could not find " + str(ie) + "\n")
 try:
     from .rosenbrock import RodasODE
 except ImportError as ie:
-    sys.stderr.write("Could not find {}\n".format(ie.args[0].split("'")[1]))
+    sys.stderr.write("Could not find " + str(ie) + "\n")
 try:
     from .odassl import ODASSL
 except ImportError as ie:
-    sys.stderr.write("Could not find {}\n".format(ie.args[0].split("'")[1]))
+    sys.stderr.write("Could not find " + str(ie) + "\n")
 try:
     from .odepack import LSODAR
 except ImportError as ie:
-    sys.stderr.write("Could not find {}\n".format(ie.args[0].split("'")[1]))
+    sys.stderr.write("Could not find " + str(ie) + "\n")
 try:
     from .radar5 import Radar5ODE
 except ImportError as ie:
-    sys.stderr.write("Could not find {}\n".format(ie.args[0].split("'")[1]))
+    sys.stderr.write("Could not find " + str(ie) + "\n")
 try:
     from .dasp3 import DASP3ODE
 except ImportError as ie:
-    sys.stderr.write("Could not find {}\n".format(ie.args[0].split("'")[1]))
+    sys.stderr.write("Could not find " + str(ie) + "\n")
 try:
     from .glimda import GLIMDA
 except ImportError as ie:
-    sys.stderr.write("Could not find {}\n".format(ie.args[0].split("'")[1]))
+    sys.stderr.write("Could not find " + str(ie) + "\n")
Index: src/solvers/kinsol.pyx
===================================================================
--- assimulo/solvers/kinsol.pyx	(revision 844)
+++ assimulo/solvers/kinsol.pyx	(revision 845)
@@ -30,8 +30,8 @@
 cimport sundials_includes as SUNDIALS
 
 #Various C includes transfered to namespace
-from sundials_includes cimport N_Vector, realtype, N_VectorContent_Serial, DENSE_COL
-from sundials_includes cimport memcpy, N_VNew_Serial, DlsMat, SlsMat
+from sundials_includes cimport N_Vector, realtype, N_VectorContent_Serial, DENSE_COL, sunindextype
+from sundials_includes cimport memcpy, N_VNew_Serial, DlsMat, SlsMat, SUNMatrix, SUNMatrixContent_Dense, SUNMatrixContent_Sparse
 from sundials_includes cimport malloc, free, realtype, N_VCloneVectorArray_Serial
 from sundials_includes cimport N_VConst_Serial, N_VDestroy_Serial
 
@@ -57,6 +57,8 @@
     
     cdef object pt_fcn, pt_jac, pt_jacv, pt_prec_setup, pt_prec_solve
     cdef object _added_linear_solver
+    cdef SUNDIALS.SUNMatrix sun_matrix
+    cdef SUNDIALS.SUNLinearSolver sun_linearsolver
     
     def __init__(self, problem):
         Algebraic.__init__(self, problem) #Calls the base class
@@ -86,6 +88,7 @@
         self.options["no_min_epsilon"] = False #Specifies wheter the scaled linear residual is bounded from below
         self.options["max_beta_fails"] = 10
         self.options["max_krylov"] = 0
+        self.options["precond"] = PREC_NONE
         
         #Statistics
         self.statistics["nfevals"]    = 0 #Function evaluations
@@ -109,6 +112,13 @@
         if self.kinsol_mem != NULL:
             #Free Memory
             SUNDIALS.KINFree(&self.kinsol_mem)
+            
+        IF SUNDIALS_VERSION >= (3,0,0):
+            if self.sun_matrix != NULL:
+                SUNDIALS.SUNMatDestroy(self.sun_matrix)
+                
+            if self.sun_linearsolver != NULL:
+                SUNDIALS.SUNLinSolFree(self.sun_linearsolver)
         
     def update_variable_scaling(self, value="Automatic"):
         """
@@ -170,7 +180,7 @@
             
     cdef initialize_kinsol(self):
         cdef int flag #Used for return
-        
+
         self.y_temp  = arr2nv(self.y)
         self.y_scale = arr2nv([1.0]*self.problem_info["dim"])
         self.f_scale = arr2nv([1.0]*self.problem_info["dim"])
@@ -208,16 +218,34 @@
             
     cpdef add_linear_solver(self):
         if self.options["linear_solver"] == "DENSE":
-            flag = SUNDIALS.KINDense(self.kinsol_mem, self.problem_info["dim"])
+            IF SUNDIALS_VERSION >= (3,0,0):
+                #Create a dense Sundials matrix
+                self.sun_matrix = SUNDIALS.SUNDenseMatrix(self.pData.dim, self.pData.dim)
+                #Create a dense Sundials linear solver
+                self.sun_linearsolver = SUNDIALS.SUNDenseLinearSolver(self.y_temp, self.sun_matrix)
+                #Attach it to Kinsol
+                flag = SUNDIALS.KINDlsSetLinearSolver(self.kinsol_mem, self.sun_linearsolver, self.sun_matrix)
+            ELSE:
+                flag = SUNDIALS.KINDense(self.kinsol_mem, self.problem_info["dim"])
             if flag < 0:
                 raise KINSOLError(flag)
             
             if self.problem_info["jac_fcn"]:
-                flag = SUNDIALS.KINDlsSetDenseJacFn(self.kinsol_mem, kin_jac);
+                IF SUNDIALS_VERSION >= (3,0,0):
+                    flag = SUNDIALS.KINDlsSetJacFn(self.kinsol_mem, kin_jac);
+                ELSE:
+                    flag = SUNDIALS.KINDlsSetDenseJacFn(self.kinsol_mem, kin_jac);
                 if flag < 0:
                     raise KINSOLError(flag)
         elif self.options["linear_solver"] == "SPGMR":
-            flag = SUNDIALS.KINSpgmr(self.kinsol_mem, self.options["max_krylov"])
+            IF SUNDIALS_VERSION >= (3,0,0):
+                #Create the linear solver
+                self.sun_linearsolver = SUNDIALS.SUNSPGMR(self.y_temp, self.options["precond"], self.options["max_krylov"])
+                #Attach it to Kinsol
+                flag = SUNDIALS.KINSpilsSetLinearSolver(self.kinsol_mem, self.sun_linearsolver)
+            ELSE:
+                #Specify the use of KINSpgmr linear solver.
+                flag = SUNDIALS.KINSpgmr(self.kinsol_mem, self.options["max_krylov"])
             if flag < 0:
                 raise KINSOLError(flag)
             
Index: src/solvers/sundials.pyx
===================================================================
--- assimulo/solvers/sundials.pyx	(revision 844)
+++ assimulo/solvers/sundials.pyx	(revision 845)
@@ -34,8 +34,8 @@
 cimport sundials_includes as SUNDIALS
 
 #Various C includes transfered to namespace
-from sundials_includes cimport N_Vector, realtype, N_VectorContent_Serial, DENSE_COL
-from sundials_includes cimport memcpy, N_VNew_Serial, DlsMat, SlsMat
+from sundials_includes cimport N_Vector, realtype, N_VectorContent_Serial, DENSE_COL, sunindextype
+from sundials_includes cimport memcpy, N_VNew_Serial, DlsMat, SlsMat, SUNMatrix, SUNMatrixContent_Dense, SUNMatrixContent_Sparse
 from sundials_includes cimport malloc, free, realtype, N_VCloneVectorArray_Serial
 from sundials_includes cimport N_VConst_Serial, N_VDestroy_Serial
 
@@ -70,6 +70,8 @@
     cdef public N.ndarray yS0
     #cdef N.ndarray _event_info
     cdef public N.ndarray g_old
+    cdef SUNDIALS.SUNMatrix sun_matrix
+    cdef SUNDIALS.SUNLinearSolver sun_linearsolver
     
     def __init__(self, problem):
         Implicit_ODE.__init__(self, problem) #Calls the base class
@@ -100,7 +102,9 @@
         self.options["dqrhomax"] = 0.0
         self.options["pbar"] = [1]*self.problem_info["dimSens"]
         self.options["external_event_detection"] = False #Sundials rootfinding is used for event location as default 
+        self.options["precond"] = PREC_NONE
 
+
         #Solver support
         self.supports["report_continuously"] = True
         self.supports["interpolated_output"] = True
@@ -173,6 +177,13 @@
         if self.ida_mem != NULL: 
             #Free Memory
             SUNDIALS.IDAFree(&self.ida_mem)
+        
+        IF SUNDIALS_VERSION >= (3,0,0):
+            if self.sun_matrix != NULL:
+                SUNDIALS.SUNMatDestroy(self.sun_matrix)
+                
+            if self.sun_linearsolver != NULL:
+                SUNDIALS.SUNLinSolFree(self.sun_linearsolver)
     
     cpdef state_event_info(self):
         """
@@ -255,21 +266,30 @@
             if flag < 0:
                 raise IDAError(flag, self.t)
                 
-            #Specify the use of the internal dense linear algebra functions.
-            flag = SUNDIALS.IDADense(self.ida_mem, self.pData.dim)
-            if flag < 0:
-                raise IDAError(flag, self.t)
-                
-                    #Choose a linear solver if and only if NEWTON is choosen
+            #Choose a linear solver if and only if NEWTON is choosen
             if self.options["linear_solver"] == 'DENSE':
-                #Specify the use of the internal dense linear algebra functions.
-                flag = SUNDIALS.IDADense(self.ida_mem, self.pData.dim)
+                IF SUNDIALS_VERSION >= (3,0,0):
+                    #Create a dense Sundials matrix
+                    self.sun_matrix = SUNDIALS.SUNDenseMatrix(self.pData.dim, self.pData.dim)
+                    #Create a dense Sundials linear solver
+                    self.sun_linearsolver = SUNDIALS.SUNDenseLinearSolver(self.yTemp, self.sun_matrix)
+                    #Attach it to IDA
+                    flag = SUNDIALS.IDADlsSetLinearSolver(self.ida_mem, self.sun_linearsolver, self.sun_matrix);
+                ELSE:
+                    #Specify the use of the internal dense linear algebra functions.
+                    flag = SUNDIALS.IDADense(self.ida_mem, self.pData.dim)
                 if flag < 0:
                     raise IDAError(flag, self.t)
                         
             elif self.options["linear_solver"] == 'SPGMR':
-                #Specify the use of SPGMR linear solver.
-                flag = SUNDIALS.IDASpgmr(self.ida_mem, 0) #0 == Default krylov iterations
+                IF SUNDIALS_VERSION >= (3,0,0):
+                    #Create the linear solver
+                    self.sun_linearsolver = SUNDIALS.SUNSPGMR(self.yTemp, self.options["precond"], 0)
+                    #Attach it to IDAS
+                    flag = SUNDIALS.IDASpilsSetLinearSolver(self.ida_mem, self.sun_linearsolver)
+                ELSE:
+                    #Specify the use of SPGMR linear solver.
+                    flag = SUNDIALS.IDASpgmr(self.ida_mem, 0) #0 == Default krylov iterations
                 if flag < 0: 
                     raise IDAError(flag, self.t)
                 
@@ -310,12 +330,17 @@
         if self.options["linear_solver"] == 'DENSE':
             #Specify the jacobian to the solver
             if self.pData.JAC != NULL and self.options["usejac"]:
-                
-                flag = SUNDIALS.IDADlsSetDenseJacFn(self.ida_mem, ida_jac)
+                IF SUNDIALS_VERSION >= (3,0,0):
+                    flag = SUNDIALS.IDADlsSetJacFn(self.ida_mem, ida_jac)
+                ELSE:
+                    flag = SUNDIALS.IDADlsSetDenseJacFn(self.ida_mem, ida_jac)
                 if flag < 0:
                     raise IDAError(flag,self.t)
             else:
-                flag = SUNDIALS.IDADlsSetDenseJacFn(self.ida_mem, NULL)
+                IF SUNDIALS_VERSION >= (3,0,0):
+                    flag = SUNDIALS.IDADlsSetJacFn(self.ida_mem, NULL)
+                ELSE:
+                    flag = SUNDIALS.IDADlsSetDenseJacFn(self.ida_mem, NULL)
                 if flag < 0:
                     raise IDAError(flag,self.t)
                     
@@ -322,11 +347,17 @@
         elif self.options["linear_solver"] == 'SPGMR':
             #Specify the jacobian times vector function
             if self.pData.JACV != NULL and self.options["usejac"]:
-                flag = SUNDIALS.IDASpilsSetJacTimesVecFn(self.ida_mem, ida_jacv);
+                IF SUNDIALS_VERSION >= (3,0,0):
+                    flag = SUNDIALS.IDASpilsSetJacTimes(self.ida_mem, SUNDIALS.ida_spils_jtsetup_dummy, ida_jacv);
+                ELSE:
+                    flag = SUNDIALS.IDASpilsSetJacTimesVecFn(self.ida_mem, ida_jacv);
                 if flag < 0:
                     raise IDAError(flag, self.t)
             else:
-                flag = SUNDIALS.IDASpilsSetJacTimesVecFn(self.ida_mem, NULL);
+                IF SUNDIALS_VERSION >= (3,0,0):
+                    flag = SUNDIALS.IDASpilsSetJacTimes(self.ida_mem, NULL, NULL);
+                ELSE:
+                    flag = SUNDIALS.IDASpilsSetJacTimesVecFn(self.ida_mem, NULL);
                 if flag < 0:
                     raise IDAError(flag, self.t)
         else:
@@ -1415,6 +1446,8 @@
     cdef public N.ndarray yS0
     #cdef N.ndarray _event_info
     cdef public N.ndarray g_old
+    cdef SUNDIALS.SUNMatrix sun_matrix
+    cdef SUNDIALS.SUNLinearSolver sun_linearsolver
     
     def __init__(self, problem):
         Explicit_ODE.__init__(self, problem) #Calls the base class
@@ -1479,6 +1512,13 @@
         if self.cvode_mem != NULL:
             #Free Memory
             SUNDIALS.CVodeFree(&self.cvode_mem)
+        
+        IF SUNDIALS_VERSION >= (3,0,0):
+            if self.sun_matrix != NULL:
+                SUNDIALS.SUNMatDestroy(self.sun_matrix)
+                
+            if self.sun_linearsolver != NULL:
+                SUNDIALS.SUNLinSolFree(self.sun_linearsolver)
     
     cpdef get_local_errors(self):
         """
@@ -2019,29 +2059,51 @@
         Updates the simulation options.
         """
         cdef flag
-        
+
         #Choose a linear solver if and only if NEWTON is choosen
         if self.options["linear_solver"] == 'DENSE' and self.options["iter"] == "Newton":
-            #Specify the use of the internal dense linear algebra functions.
-            flag = SUNDIALS.CVDense(self.cvode_mem, self.pData.dim)
-            if flag < 0:
-                raise CVodeError(flag)
+            IF SUNDIALS_VERSION >= (3,0,0):
+                #Create a dense Sundials matrix
+                self.sun_matrix = SUNDIALS.SUNDenseMatrix(self.pData.dim, self.pData.dim)
+                #Create a dense Sundials linear solver
+                self.sun_linearsolver = SUNDIALS.SUNDenseLinearSolver(self.yTemp, self.sun_matrix)
+                #Attach it to CVode
+                flag = SUNDIALS.CVDlsSetLinearSolver(self.cvode_mem, self.sun_linearsolver, self.sun_matrix);
+                if flag < 0:
+                    raise CVodeError(flag)
+            ELSE:
+                #Specify the use of the internal dense linear algebra functions.
+                flag = SUNDIALS.CVDense(self.cvode_mem, self.pData.dim)
+                if flag < 0:
+                    raise CVodeError(flag)
                 
             #Specify the jacobian to the solver
             if self.pData.JAC != NULL and self.options["usejac"]:
-                flag = SUNDIALS.CVDlsSetDenseJacFn(self.cvode_mem, cv_jac)
+                IF SUNDIALS_VERSION >= (3,0,0):
+                    flag = SUNDIALS.CVDlsSetJacFn(self.cvode_mem, cv_jac);
+                ELSE:
+                    flag = SUNDIALS.CVDlsSetDenseJacFn(self.cvode_mem, cv_jac)
                 if flag < 0:
                     raise CVodeError(flag)
             else:
-                flag = SUNDIALS.CVDlsSetDenseJacFn(self.cvode_mem, NULL)
+                IF SUNDIALS_VERSION >= (3,0,0):
+                    flag = SUNDIALS.CVDlsSetJacFn(self.cvode_mem, NULL);
+                ELSE:
+                    flag = SUNDIALS.CVDlsSetDenseJacFn(self.cvode_mem, NULL)
                 if flag < 0:
                     raise CVodeError(flag)
                     
         elif self.options["linear_solver"] == 'SPGMR' and self.options["iter"] == "Newton":
-            #Specify the use of CVSPGMR linear solver.
-            flag = SUNDIALS.CVSpgmr(self.cvode_mem, self.options["precond"], self.options["maxkrylov"])
+            IF SUNDIALS_VERSION >= (3,0,0):
+                #Create the linear solver
+                self.sun_linearsolver = SUNDIALS.SUNSPGMR(self.yTemp, self.options["precond"], self.options["maxkrylov"])
+                #Attach it to CVode
+                flag = SUNDIALS.CVSpilsSetLinearSolver(self.cvode_mem, self.sun_linearsolver)
+            ELSE:
+                #Specify the use of CVSPGMR linear solver.
+                flag = SUNDIALS.CVSpgmr(self.cvode_mem, self.options["precond"], self.options["maxkrylov"])
             if flag < 0:
-                raise CVodeError(flag)
+                raise CVodeError(flag) 
                 
             if self.pData.PREC_SOLVE != NULL:
                 if self.pData.PREC_SETUP != NULL: 
@@ -2055,11 +2117,17 @@
                   
             #Specify the jacobian times vector function
             if self.pData.JACV != NULL and self.options["usejac"]:
-                flag = SUNDIALS.CVSpilsSetJacTimesVecFn(self.cvode_mem, cv_jacv)
-                if flag < 0:
+                IF SUNDIALS_VERSION >= (3,0,0):
+                    flag = SUNDIALS.CVSpilsSetJacTimes(self.cvode_mem, SUNDIALS.cv_spils_jtsetup_dummy, cv_jacv);
+                ELSE:
+                    flag = SUNDIALS.CVSpilsSetJacTimesVecFn(self.cvode_mem, cv_jacv)
+                if flag < 0: 
                     raise CVodeError(flag)
             else:
-                flag = SUNDIALS.CVSpilsSetJacTimesVecFn(self.cvode_mem, NULL)
+                IF SUNDIALS_VERSION >= (3,0,0):
+                    flag = SUNDIALS.CVSpilsSetJacTimes(self.cvode_mem, NULL, NULL);
+                ELSE:
+                    flag = SUNDIALS.CVSpilsSetJacTimesVecFn(self.cvode_mem, NULL)
                 if flag < 0:
                     raise CVodeError(flag)
         elif self.options["linear_solver"] == 'SPARSE' and self.options["iter"] == "Newton":
@@ -2066,17 +2134,28 @@
             
             if SUNDIALS.version() < (2,6,0): 
                 raise AssimuloException("Not supported with this SUNDIALS version.")
-            
+            if SUNDIALS.with_superlu() == 0:
+                raise AssimuloException("No support for SuperLU was detected, please verify that SuperLU and SUNDIALS has been installed correctly.")
+                
             #Specify the use of CVSPGMR linear solver.
             if self.problem_info["jac_fcn_nnz"] == -1:
                 raise AssimuloException("Need to specify the number of non zero elements in the Jacobian via the option 'jac_nnz'")
-            flag = SUNDIALS.CVSuperLUMT(self.cvode_mem, self.options["num_threads"], self.pData.dim, self.problem_info["jac_fcn_nnz"])
+                
+            IF SUNDIALS_VERSION >= (3,0,0):
+                self.sun_matrix = SUNDIALS.SUNSparseMatrix(self.pData.dim, self.pData.dim, self.problem_info["jac_fcn_nnz"], CSC_MAT)
+                self.sun_linearsolver = SUNDIALS.SUNSuperLUMT(self.yTemp, self.sun_matrix, self.options["num_threads"])
+                flag = SUNDIALS.CVDlsSetLinearSolver(self.cvode_mem, self.sun_linearsolver, self.sun_matrix)
+            ELSE:
+                flag = SUNDIALS.CVSuperLUMT(self.cvode_mem, self.options["num_threads"], self.pData.dim, self.problem_info["jac_fcn_nnz"])
             if flag < 0:
                     raise CVodeError(flag)
             
             #Specify the jacobian to the solver
             if self.pData.JAC != NULL and self.options["usejac"]:
-                flag = SUNDIALS.CVSlsSetSparseJacFn(self.cvode_mem, cv_jac_sparse)
+                IF SUNDIALS_VERSION >= (3,0,0):
+                    flag = SUNDIALS.CVDlsSetJacFn(self.cvode_mem, cv_jac_sparse)
+                ELSE:
+                    flag = SUNDIALS.CVSlsSetSparseJacFn(self.cvode_mem, cv_jac_sparse)
                 if flag < 0:
                     raise CVodeError(flag)
             else:
@@ -2899,7 +2978,10 @@
             flag = SUNDIALS.CVSpilsGetNumRhsEvals(self.cvode_mem, &nfevalsLS) #Number of rhs due to jac*vector
             self.statistics["njacvecs"]  += njvevals
         elif self.options["linear_solver"] == "SPARSE":
-            flag = SUNDIALS.CVSlsGetNumJacEvals(self.cvode_mem, &njevals)
+            IF SUNDIALS_VERSION >= (3,0,0):
+                flag = SUNDIALS.CVDlsGetNumJacEvals(self.cvode_mem, &njevals)
+            ELSE:
+                flag = SUNDIALS.CVSlsGetNumJacEvals(self.cvode_mem, &njevals)
             self.statistics["njacs"]   += njevals
         else:
             flag = SUNDIALS.CVDlsGetNumJacEvals(self.cvode_mem, &njevals) #Number of jac evals
Index: assimulo/lib/sundials_includes.pxd
===================================================================
--- assimulo/lib/sundials_includes.pxd	(revision 844)
+++ assimulo/lib/sundials_includes.pxd	(revision 845)
@@ -37,19 +37,6 @@
     ctypedef double realtype
     ctypedef bint booleantype # should be bool instead of bint, but there is a bug in Cython
 
-#==============================================
-# C headers
-#==============================================
-cdef extern from "string.h":
-    void *memcpy(void *s1, void *s2, int n)
-cdef extern from "stdlib.h":
-    void *malloc(int size)
-    void free(void *ptr)
-    
-#==============================================
-#External definitions from Sundials headers
-#==============================================
-
 cdef extern from "sundials/sundials_nvector.h":
     ctypedef _generic_N_Vector* N_Vector
     
@@ -77,6 +64,107 @@
     void N_VDestroy_Serial(N_Vector v)
     void N_VPrint_Serial(N_Vector v)
 
+IF SUNDIALS_VERSION >= (3,0,0):
+    cdef extern from "sundials/sundials_types.h":
+        IF SUNDIALS_VECTOR_SIZE == "64":
+            ctypedef long int sunindextype
+        ELSE:
+            ctypedef int sunindextype
+    cdef extern from "sundials/sundials_matrix.h":
+        ctypedef _generic_SUNMatrix *SUNMatrix;
+        void SUNMatDestroy(SUNMatrix A);
+        
+        cdef struct _generic_SUNMatrix_Ops:
+            SUNMatrix_ID (*getid)(SUNMatrix);
+            SUNMatrix    (*clone)(SUNMatrix);
+            void         (*destroy)(SUNMatrix);
+            int          (*zero)(SUNMatrix);
+            int          (*copy)(SUNMatrix, SUNMatrix);
+            int          (*scaleadd)(realtype, SUNMatrix, SUNMatrix);
+            int          (*scaleaddi)(realtype, SUNMatrix);
+            int          (*matvec)(SUNMatrix, N_Vector, N_Vector);
+            int          (*space)(SUNMatrix, long int*, long int*);
+
+        cdef struct _generic_SUNMatrix:
+            void *content;
+            _generic_SUNMatrix_Ops *ops;
+            
+        cdef enum SUNMatrix_ID:
+            SUNMATRIX_DENSE, 
+            SUNMATRIX_BAND, 
+            SUNMATRIX_SPARSE, 
+            SUNMATRIX_CUSTOM
+    
+    cdef extern from "sundials/sundials_linearsolver.h":
+        ctypedef _generic_SUNLinearSolver *SUNLinearSolver;
+        int SUNLinSolFree(SUNLinearSolver S);
+        
+        cdef struct _generic_SUNLinearSolver_Ops:
+            SUNLinearSolver_Type (*gettype)(SUNLinearSolver);
+            int                  (*setatimes)(SUNLinearSolver, void*, ATimesFn);
+            int                  (*setpreconditioner)(SUNLinearSolver, void*, 
+                                                    PSetupFn, PSolveFn);
+            int                  (*setscalingvectors)(SUNLinearSolver,
+                                                    N_Vector, N_Vector);
+            int                  (*initialize)(SUNLinearSolver);
+            int                  (*setup)(SUNLinearSolver, SUNMatrix);
+            int                  (*solve)(SUNLinearSolver, SUNMatrix, N_Vector, 
+                                        N_Vector, realtype);
+            int                  (*numiters)(SUNLinearSolver);
+            realtype             (*resnorm)(SUNLinearSolver);
+            long int             (*lastflag)(SUNLinearSolver);
+            int                  (*space)(SUNLinearSolver, long int*, long int*);
+            N_Vector             (*resid)(SUNLinearSolver);
+            int                  (*free)(SUNLinearSolver);
+        
+        cdef struct _generic_SUNLinearSolver:
+            void *content;
+            _generic_SUNLinearSolver_Ops *ops;
+            
+        cdef enum SUNLinearSolver_Type:
+            SUNLINEARSOLVER_DIRECT,
+            SUNLINEARSOLVER_ITERATIVE,
+            SUNLINEARSOLVER_CUSTOM
+    
+    cdef extern from "sunmatrix/sunmatrix_dense.h":
+        ctypedef _SUNMatrixContent_Dense *SUNMatrixContent_Dense;
+        cdef struct _SUNMatrixContent_Dense:
+            sunindextype M;
+            sunindextype N;
+            realtype *data;
+            sunindextype ldata;
+            realtype **cols;
+        SUNMatrix SUNDenseMatrix(sunindextype M, sunindextype N);
+    cdef extern from "sunmatrix/sunmatrix_sparse.h":
+        ctypedef _SUNMatrixContent_Sparse *SUNMatrixContent_Sparse;
+        cdef struct _SUNMatrixContent_Sparse:
+            sunindextype M;
+            sunindextype N;
+            sunindextype NNZ;
+            sunindextype NP;
+            realtype *data;
+            int sparsetype;
+            sunindextype *indexvals;
+            sunindextype *indexptrs;
+            sunindextype **rowvals;
+            sunindextype **colptrs;
+            sunindextype **colvals;
+            sunindextype **rowptrs;
+        SUNMatrix SUNSparseMatrix(sunindextype M, sunindextype N, sunindextype NNZ, int sparsetype);
+    cdef extern from "sunlinsol/sunlinsol_dense.h":
+        SUNLinearSolver SUNDenseLinearSolver(N_Vector y, SUNMatrix A);
+    cdef extern from "sunlinsol/sunlinsol_spgmr.h":
+        SUNLinearSolver SUNSPGMR(N_Vector y, int pretype, int maxl);
+        
+ELSE: 
+    #Dummy defines
+    ctypedef void *SUNLinearSolver
+    ctypedef void *SUNMatrix
+    ctypedef void *SUNMatrixContent_Dense
+    ctypedef void *SUNMatrixContent_Sparse
+    ctypedef int sunindextype
+
+
 #Struct for handling the Jacobian data
 cdef extern from "sundials/sundials_direct.h":
     cdef struct _DlsMat:
@@ -92,7 +180,7 @@
         realtype **cols
     ctypedef _DlsMat* DlsMat
     cdef realtype* DENSE_COL(DlsMat A, int j)
-
+    
 IF SUNDIALS_VERSION >= (2,6,3):
     cdef extern from "sundials/sundials_sparse.h":
         cdef struct _SlsMat:
@@ -128,7 +216,26 @@
         int *rowvals
         int *colptrs
     ctypedef _SlsMat* SlsMat
+    
+#==============================================
+# C headers
+#==============================================
+cdef extern from "string.h":
+    void *memcpy(void *s1, void *s2, int n)
+cdef extern from "stdlib.h":
+    void *malloc(int size)
+    void free(void *ptr)
+    
+#==============================================
+#External definitions from Sundials headers
+#==============================================
 
+IF SUNDIALS_WITH_SUPERLU:
+    cdef inline int with_superlu(): return 1
+ELSE:
+    cdef inline int with_superlu(): return 0
+
+
 cdef extern from "cvodes/cvodes.h":
     void* CVodeCreate(int lmm, int iter)
     ctypedef int (*CVRhsFn)(realtype t, N_Vector y, N_Vector ydot, void *f_data)
@@ -225,45 +332,67 @@
     int CVodeGetSensNonlinSolvStats(void *cvode_mem, long int *nSniters, long int *nSncfails)
     int CVodeGetStgrSensNumNonlinSolvIters(void *cvode_mem, long int *nSTGR1niters)
     int CVodeGetStgrSensNumNonlinSolvConvFails(void *cvode_mem, long int *nSTGR1ncfails)
+
+cdef extern from "cvodes/cvodes_spils.h":
+    ctypedef int (*CVSpilsJacTimesVecFn)(N_Vector v, N_Vector Jv, realtype t,
+            N_Vector y, N_Vector fy, void *user_data, N_Vector tmp)
+
+IF SUNDIALS_VERSION >= (3,0,0):
+    cdef extern from "cvodes/cvodes_direct.h":
+        ctypedef int (*CVDlsDenseJacFn)(realtype t, N_Vector y, N_Vector fy, 
+                       SUNMatrix Jac, void *user_data, N_Vector tmp1, N_Vector tmp2, N_Vector tmp3)
+        int CVDlsSetLinearSolver(void *cvode_mem, SUNLinearSolver LS, SUNMatrix A);
+        int CVDlsSetJacFn(void *cvode_mem, CVDlsDenseJacFn djac)
+    cdef extern from "cvodes/cvodes_spils.h":
+        int CVSpilsSetLinearSolver(void *cvode_mem, SUNLinearSolver LS);
+        ctypedef int (*CVSpilsJacTimesSetupFn)(realtype t, N_Vector y, N_Vector fy, void *user_data);
+        int CVSpilsSetJacTimes(void *cvode_mem, CVSpilsJacTimesSetupFn jtsetup, CVSpilsJacTimesVecFn jtimes);
     
     
-cdef extern from "cvodes/cvodes_dense.h":
-    int CVDense(void *cvode_mem, long int n)
-    ctypedef int (*CVDlsDenseJacFn)(int n, realtype t, N_Vector y, N_Vector fy, 
-                   DlsMat Jac, void *user_data, N_Vector tmp1, N_Vector tmp2, N_Vector tmp3)
-    int CVDlsSetDenseJacFn(void *cvode_mem, CVDlsDenseJacFn djac)
+    IF SUNDIALS_WITH_SUPERLU:
+        cdef extern from "sunlinsol/sunlinsol_superlumt.h":
+            SUNLinearSolver SUNSuperLUMT(N_Vector y, SUNMatrix A, int num_threads)
+    ELSE:
+        cdef inline SUNLinearSolver SUNSuperLUMT(N_Vector y, SUNMatrix A, int num_threads): return NULL
+    
+    cdef inline int cv_spils_jtsetup_dummy(realtype t, N_Vector y, N_Vector fy, void *user_data): return 0    
+    cdef inline tuple version(): return (3,0,0)
+ELSE:
+    cdef extern from "cvodes/cvodes_dense.h":
+        int CVDense(void *cvode_mem, long int n)
+        ctypedef int (*CVDlsDenseJacFn)(int n, realtype t, N_Vector y, N_Vector fy, 
+                       DlsMat Jac, void *user_data, N_Vector tmp1, N_Vector tmp2, N_Vector tmp3)
+        int CVDlsSetDenseJacFn(void *cvode_mem, CVDlsDenseJacFn djac)
 
-cdef extern from "cvodes/cvodes_spgmr.h":
-    int CVSpgmr(void *cvode_mem, int pretype, int max1)
+    cdef extern from "cvodes/cvodes_spgmr.h":
+        int CVSpgmr(void *cvode_mem, int pretype, int max1)
     
-IF SUNDIALS_VERSION >= (2,6,0):
-    cdef extern from "cvodes/cvodes_sparse.h":
+    cdef extern from "cvodes/cvodes_spils.h":
+        int CVSpilsSetJacTimesVecFn(void *cvode_mem,  CVSpilsJacTimesVecFn jtv)
+    
+    IF SUNDIALS_VERSION >= (2,6,0):
+        cdef extern from "cvodes/cvodes_sparse.h":
+            ctypedef int (*CVSlsSparseJacFn)(realtype t, N_Vector y, N_Vector fy,
+                                      SlsMat Jac, void *user_data, N_Vector tmp1,
+                                        N_Vector tmp2, N_Vector tmp3)
+            int CVSlsSetSparseJacFn(void *cvode_mem, CVSlsSparseJacFn jac)
+            int CVSlsGetNumJacEvals(void *cvode_mem, long int *njevals)
+        cdef inline tuple version(): return (2,6,0)
+        IF SUNDIALS_WITH_SUPERLU:
+            cdef extern from "cvodes/cvodes_sparse.h":
+                int CVSuperLUMT(void *cvode_mem, int numthreads, int n, int nnz)
+        ELSE:
+            cdef inline int CVSuperLUMT(void *cvode_mem, int numthreads, int n, int nnz): return -1
+    ELSE:
+        cdef inline int CVSuperLUMT(void *cvode_mem, int numthreads, int n, int nnz): return -1
         ctypedef int (*CVSlsSparseJacFn)(realtype t, N_Vector y, N_Vector fy,
                                   SlsMat Jac, void *user_data, N_Vector tmp1,
                                     N_Vector tmp2, N_Vector tmp3)
-        int CVSlsSetSparseJacFn(void *cvode_mem, CVSlsSparseJacFn jac)
-        int CVSlsGetNumJacEvals(void *cvode_mem, long int *njevals)
-    #cdef inline char* version(): return "2.6.0"
-    cdef inline tuple version(): return (2,6,0)
-    IF SUNDIALS_WITH_SUPERLU:
-        cdef extern from "cvodes/cvodes_sparse.h":
-            int CVSuperLUMT(void *cvode_mem, int numthreads, int n, int nnz)
-    ELSE:
-        cdef inline int CVSuperLUMT(void *cvode_mem, int numthreads, int n, int nnz): return -1
-ELSE:
-    cdef inline int CVSuperLUMT(void *cvode_mem, int numthreads, int n, int nnz): return -1
-    ctypedef int (*CVSlsSparseJacFn)(realtype t, N_Vector y, N_Vector fy,
-                              SlsMat Jac, void *user_data, N_Vector tmp1,
-                                N_Vector tmp2, N_Vector tmp3)
-    cdef inline int CVSlsSetSparseJacFn(void *cvode_mem, CVSlsSparseJacFn jac): return -1
-    cdef inline int CVSlsGetNumJacEvals(void *cvode_mem, long int *njevals): return -1
-    #cdef inline char* version(): return "2.5.0"
-    cdef inline tuple version(): return (2,5,0)
+        cdef inline int CVSlsSetSparseJacFn(void *cvode_mem, CVSlsSparseJacFn jac): return -1
+        cdef inline int CVSlsGetNumJacEvals(void *cvode_mem, long int *njevals): return -1
+        cdef inline tuple version(): return (2,5,0)
     
 cdef extern from "cvodes/cvodes_spils.h":
-    ctypedef int (*CVSpilsJacTimesVecFn)(N_Vector v, N_Vector Jv, realtype t,
-				    N_Vector y, N_Vector fy,
-				    void *user_data, N_Vector tmp)
     ctypedef int (*CVSpilsPrecSetupFn)(realtype t, N_Vector y, N_Vector fy,
 				  booleantype jok, booleantype *jcurPtr,
 				  realtype gamma, void *user_data,
@@ -273,13 +402,12 @@
 				  N_Vector r, N_Vector z,
 				  realtype gamma, realtype delta,
 				  int lr, void *user_data, N_Vector tmp)
-    int CVSpilsSetJacTimesVecFn(void *cvode_mem,  CVSpilsJacTimesVecFn jtv)
+    
     int CVSpilsSetPreconditioner(void *cvode_mem, CVSpilsPrecSetupFn psetup, CVSpilsPrecSolveFn psolve)
     int CVSpilsGetNumJtimesEvals(void *cvode_mem, long int *njvevals) #Number of jac*vector evals
     int CVSpilsGetNumRhsEvals(void *cvode_mem, long int *nfevalsLS) #Number of res evals due to jacÄvector evals
     int CVSpilsGetNumPrecEvals(void *cvode_mem, long int *npevals)
     int CVSpilsGetNumPrecSolves(void *cvode_mem, long int *npsolves)
-    
 
 cdef extern from "idas/idas.h":
     ctypedef int (*IDAResFn)(realtype tt, N_Vector yy, N_Vector yp, N_Vector rr, void *user_data)
@@ -380,19 +508,40 @@
     
     #End Sensitivities
     #=================
-
-cdef extern from "idas/idas_dense.h":
-    int IDADense(void *ida_mem, long int n)
-    ctypedef int (*IDADlsDenseJacFn)(int Neq, realtype tt, realtype cj, N_Vector yy, 
-                   N_Vector yp, N_Vector rr, DlsMat Jac, void *user_data, 
-                   N_Vector tmp1, N_Vector tmp2, N_Vector tmp3)
-    int IDADlsSetDenseJacFn(void *ida_mem, IDADlsDenseJacFn djac)
     
-cdef extern from "idas/idas_dense.h":
-    int IDASpgmr(void *ida_mem, int max1)
-    ctypedef int (*IDASpilsJacTimesVecFn)(realtype tt, N_Vector yy, N_Vector yp, N_Vector rr, N_Vector v, N_Vector Jv, realtype cj, void *user_data,N_Vector tmp1, N_Vector tmp2)
-    int IDASpilsSetJacTimesVecFn(void *ida_mem, IDASpilsJacTimesVecFn ida_jacv)
+cdef extern from "idas/idas_spils.h":
+    ctypedef int (*IDASpilsJacTimesVecFn)(realtype tt, N_Vector yy, N_Vector yp, N_Vector rr, 
+            N_Vector v, N_Vector Jv, realtype cj, void *user_data,N_Vector tmp1, N_Vector tmp2)
     
+IF SUNDIALS_VERSION >= (3,0,0):
+    cdef extern from "idas/idas_direct.h":
+        ctypedef int (*IDADlsDenseJacFn)(realtype tt, realtype cj, N_Vector yy, 
+                       N_Vector yp, N_Vector rr, SUNMatrix Jac, void *user_data, 
+                       N_Vector tmp1, N_Vector tmp2, N_Vector tmp3)
+        int IDADlsSetJacFn(void *ida_mem, IDADlsDenseJacFn djac)
+        int IDADlsSetLinearSolver(void *ida_mem, SUNLinearSolver LS, SUNMatrix A);
+    
+    cdef extern from "idas/idas_spils.h":
+        int IDASpilsSetLinearSolver(void *ida_mem, SUNLinearSolver LS);
+        ctypedef int (*IDASpilsJacTimesSetupFn)(realtype tt, N_Vector yy,
+                    N_Vector yp, N_Vector rr, realtype c_j, void *user_data);
+        int IDASpilsSetJacTimes(void *ida_mem,
+                IDASpilsJacTimesSetupFn jtsetup, IDASpilsJacTimesVecFn jtimes);
+                
+    cdef inline int ida_spils_jtsetup_dummy(realtype tt, N_Vector yy, N_Vector yp, N_Vector rr, realtype c_j, void *user_data): return 0
+ELSE:
+    cdef extern from "idas/idas_dense.h":
+        int IDADense(void *ida_mem, long int n)
+        ctypedef int (*IDADlsDenseJacFn)(int Neq, realtype tt, realtype cj, N_Vector yy, 
+                       N_Vector yp, N_Vector rr, DlsMat Jac, void *user_data, 
+                       N_Vector tmp1, N_Vector tmp2, N_Vector tmp3)
+        int IDADlsSetDenseJacFn(void *ida_mem, IDADlsDenseJacFn djac)
+    
+        int IDASpgmr(void *ida_mem, int max1)
+        
+    cdef extern from "idas/idas_spils.h":
+        int IDASpilsSetJacTimesVecFn(void *ida_mem, IDASpilsJacTimesVecFn ida_jacv)
+
 cdef extern from "idas/idas_spils.h":
     int IDASpilsGetNumJtimesEvals(void *ida_mem, long int *njvevals) #Number of jac*vector
     int IDASpilsGetNumResEvals(void *ida_mem, long int *nfevalsLS) #Number of rhs due to jac*vector
@@ -455,14 +604,31 @@
     # fuction used to deallocate memory used by KINSOL
     void KINFree(void **kinmem)
 
-# functions used for supplying jacobian, and receiving info from linear solver
-cdef extern from "kinsol/kinsol_direct.h":
-    # user functions
-    ctypedef int (*KINDlsDenseJacFn)(int dim, N_Vector u, N_Vector fu, DlsMat J, void *user_data, N_Vector tmp1, N_Vector tmp2)
+
+IF SUNDIALS_VERSION >= (3,0,0):
+    cdef extern from "kinsol/kinsol_direct.h":
+        ctypedef int (*KINDlsDenseJacFn)(N_Vector u, N_Vector fu, SUNMatrix J, void *user_data, N_Vector tmp1, N_Vector tmp2)
+        int KINDlsSetLinearSolver(void *kinmem, SUNLinearSolver LS, SUNMatrix A);
+        int KINDlsSetJacFn(void *kinmem, KINDlsDenseJacFn djac)
     
-    # function used to link user functions to KINSOL
-    int KINDlsSetDenseJacFn(void *kinmem, KINDlsDenseJacFn jac)
+    cdef extern from "kinsol/kinsol_spils.h":
+        int KINSpilsSetLinearSolver(void *kinsol_mem, SUNLinearSolver LS);
+ELSE:
+    # functions used for supplying jacobian, and receiving info from linear solver
+    cdef extern from "kinsol/kinsol_direct.h":
+        # user functions
+        ctypedef int (*KINDlsDenseJacFn)(int dim, N_Vector u, N_Vector fu, DlsMat J, void *user_data, N_Vector tmp1, N_Vector tmp2)
+        
+        # function used to link user functions to KINSOL
+        int KINDlsSetDenseJacFn(void *kinmem, KINDlsDenseJacFn jac)
+    
+    cdef extern from "kinsol/kinsol_dense.h":
+        int KINDense(void *kinmem, int dim)
+    
+    cdef extern from "kinsol/kinsol_spgmr.h":
+        int KINSpgmr(void *kinmem, int maxl)
 
+cdef extern from "kinsol/kinsol_direct.h":
     # optional output fcts for linear direct solver
     int KINDlsGetWorkSpace(void *kinmem, long int *lenrwB, long int *leniwB)
     int KINDlsGetNumJacEvals(void *kinmem, long int *njevalsB)
@@ -470,12 +636,6 @@
     int KINDlsGetLastFlag(void *kinmem, int *flag)
     char *KINDlsGetReturnFlagName(int flag)
 
-cdef extern from "kinsol/kinsol_dense.h":
-    int KINDense(void *kinmem, int dim)
-    
-cdef extern from "kinsol/kinsol_spgmr.h":
-    int KINSpgmr(void *kinmem, int maxl)
-
 cdef extern from "kinsol/kinsol_spils.h":
     ctypedef int (*KINSpilsJacTimesVecFn)(N_Vector vv, N_Vector Jv, N_Vector vx, bint new_u,
                 void *problem_data)
Index: src/lib/sundials_constants.pxi
===================================================================
--- assimulo/lib/sundials_constants.pxi	(revision 844)
+++ assimulo/lib/sundials_constants.pxi	(revision 845)
@@ -95,6 +95,9 @@
 DEF CV_BAD_IS             = -45
 
 
+DEF CSC_MAT = 0
+DEF CSR_MAT = 1
+
 #==========
 # IDA
 #==========
Index: src/lib/sundials_callbacks.pxi
===================================================================
--- assimulo/lib/sundials_callbacks.pxi	(revision 844)
+++ assimulo/lib/sundials_callbacks.pxi	(revision 845)
@@ -94,98 +94,55 @@
         traceback.print_exc()
         return CV_UNREC_RHSFUNC_ERR 
 
-@cython.boundscheck(False)
-@cython.wraparound(False)
-cdef int cv_jac_sparse(realtype t, N_Vector yv, N_Vector fy, SlsMat Jacobian,
-                void *problem_data, N_Vector tmp1, N_Vector tmp2, N_Vector tmp3):
-    """
-    This method is used to connect the Assimulo.Problem.jac to the Sundials
-    Sparse Jacobian function.
-    """
-    cdef ProblemData pData = <ProblemData>problem_data
-    #cdef N.ndarray y = nv2arr(yv)
-    cdef N.ndarray y = pData.work_y
-    cdef int i
-    cdef int nnz = Jacobian.NNZ
-    cdef int ret_nnz
-    cdef int dim = Jacobian.N
-    cdef realtype* data = Jacobian.data
-    
-    IF SUNDIALS_VERSION >= (2,6,3):
-        cdef int* rowvals = Jacobian.rowvals[0]
-        cdef int* colptrs = Jacobian.colptrs[0]
-    ELSE:
-        cdef int* rowvals = Jacobian.rowvals
-        cdef int* colptrs = Jacobian.colptrs
-    
-    nv2arr_inplace(yv, y)
-    """
-        realtype *data;
-        int *rowvals;
-        int *colptrs;
-    """
-    try:
-        if pData.dimSens > 0: #Sensitivity activated
-            p = realtype2arr(pData.p,pData.dimSens)
-            if pData.sw != NULL:
-                jac=(<object>pData.JAC)(t,y,p=p,sw=<list>pData.sw)
-            else:
-                jac=(<object>pData.JAC)(t,y,p=p)
-        else:
-            if pData.sw != NULL:
-                jac=(<object>pData.JAC)(t,y,sw=<list>pData.sw)
-            else:
-                jac=(<object>pData.JAC)(t,y)
-            
-        if not isinstance(jac, sparse.csc.csc_matrix):
-            jac = sparse.csc.csc_matrix(jac)
-            raise AssimuloException("The Jacobian must be stored on Scipy's CSC format.")
-        ret_nnz = jac.nnz
-        if ret_nnz > nnz:
-            raise AssimuloException("The Jacobian has more entries than supplied to the problem class via 'jac_nnz'")    
 
-        for i in range(min(ret_nnz,nnz)):
-            data[i]    = jac.data[i]
-            rowvals[i] = jac.indices[i]
-        for i in range(dim+1):
-            colptrs[i] = jac.indptr[i]
+IF SUNDIALS_VERSION >= (3,0,0):
+    @cython.boundscheck(False)
+    @cython.wraparound(False)
+    cdef int cv_jac_sparse(realtype t, N_Vector yv, N_Vector fy, SUNMatrix Jac,
+                    void *problem_data, N_Vector tmp1, N_Vector tmp2, N_Vector tmp3):
+        """
+        This method is used to connect the Assimulo.Problem.jac to the Sundials
+        Sparse Jacobian function.
+        """
+        cdef ProblemData pData = <ProblemData>problem_data
+        cdef SUNMatrixContent_Sparse Jacobian = <SUNMatrixContent_Sparse>Jac.content
+        cdef N.ndarray y = pData.work_y
+        cdef int i
+        cdef sunindextype nnz = Jacobian.NNZ
+        cdef int ret_nnz
+        cdef sunindextype dim = Jacobian.N
+        cdef realtype* data = Jacobian.data
+        cdef sunindextype* rowvals = Jacobian.rowvals[0]
+        cdef sunindextype* colptrs = Jacobian.colptrs[0]
         
-        return CVDLS_SUCCESS
-    except(N.linalg.LinAlgError,ZeroDivisionError,AssimuloRecoverableError):
-        return CVDLS_JACFUNC_RECVR #Recoverable Error (See Sundials description)
-    except:
-        traceback.print_exc()
-        return CVDLS_JACFUNC_UNRECVR
+        nv2arr_inplace(yv, y)
 
-cdef int cv_jac(int Neq, realtype t, N_Vector yv, N_Vector fy, DlsMat Jacobian, 
-                void *problem_data, N_Vector tmp1, N_Vector tmp2, N_Vector tmp3):
-    """
-    This method is used to connect the Assimulo.Problem.jac to the Sundials
-    Jacobian function.
-    """
-    cdef ProblemData pData = <ProblemData>problem_data
-    #cdef ndarray[realtype, ndim=2, mode='c'] jac #Used for return from the user function
-    cdef realtype* col_i=DENSE_COL(Jacobian,0)
-    #(<ndarray>pData.y).data =  <realtype*>((<N_VectorContent_Serial>yv.content).data)
-    #cdef N.ndarray y = nv2arr(yv)
-    cdef N.ndarray y = pData.work_y
-    cdef int i,j
-    
-    nv2arr_inplace(yv, y)
-
-    if pData.dimSens>0: #Sensitivity activated
-        p = realtype2arr(pData.p,pData.dimSens)
         try:
-            if pData.sw != NULL:
-                jac=(<object>pData.JAC)(t,y,sw=<list>pData.sw,p=p)
+            if pData.dimSens > 0: #Sensitivity activated
+                p = realtype2arr(pData.p,pData.dimSens)
+                if pData.sw != NULL:
+                    jac=(<object>pData.JAC)(t,y,p=p,sw=<list>pData.sw)
+                else:
+                    jac=(<object>pData.JAC)(t,y,p=p)
             else:
-                jac=(<object>pData.JAC)(t,y,p)
+                if pData.sw != NULL:
+                    jac=(<object>pData.JAC)(t,y,sw=<list>pData.sw)
+                else:
+                    jac=(<object>pData.JAC)(t,y)
                 
-            for i in range(Neq):
-                col_i = DENSE_COL(Jacobian, i)
-                for j in range(Neq):
-                    col_i[j] = jac[j,i]
+            if not isinstance(jac, sparse.csc.csc_matrix):
+                jac = sparse.csc.csc_matrix(jac)
+                raise AssimuloException("The Jacobian must be stored on Scipy's CSC format.")
+            ret_nnz = jac.nnz
+            if ret_nnz > nnz:
+                raise AssimuloException("The Jacobian has more entries than supplied to the problem class via 'jac_nnz'")    
 
+            for i in range(min(ret_nnz,nnz)):
+                data[i]    = jac.data[i]
+                rowvals[i] = jac.indices[i]
+            for i in range(dim+1):
+                colptrs[i] = jac.indptr[i]
+            
             return CVDLS_SUCCESS
         except(N.linalg.LinAlgError,ZeroDivisionError,AssimuloRecoverableError):
             return CVDLS_JACFUNC_RECVR #Recoverable Error (See Sundials description)
@@ -192,18 +149,62 @@
         except:
             traceback.print_exc()
             return CVDLS_JACFUNC_UNRECVR
-    else:
+ELSE:
+    @cython.boundscheck(False)
+    @cython.wraparound(False)
+    cdef int cv_jac_sparse(realtype t, N_Vector yv, N_Vector fy, SlsMat Jacobian,
+                    void *problem_data, N_Vector tmp1, N_Vector tmp2, N_Vector tmp3):
+        """
+        This method is used to connect the Assimulo.Problem.jac to the Sundials
+        Sparse Jacobian function.
+        """
+        cdef ProblemData pData = <ProblemData>problem_data
+        cdef N.ndarray y = pData.work_y
+        cdef int i
+        cdef int nnz = Jacobian.NNZ
+        cdef int ret_nnz
+        cdef int dim = Jacobian.N
+        cdef realtype* data = Jacobian.data
+        
+        IF SUNDIALS_VERSION >= (2,6,3):
+            cdef int* rowvals = Jacobian.rowvals[0]
+            cdef int* colptrs = Jacobian.colptrs[0]
+        ELSE:
+            cdef int* rowvals = Jacobian.rowvals
+            cdef int* colptrs = Jacobian.colptrs
+        
+        nv2arr_inplace(yv, y)
+        """
+            realtype *data;
+            int *rowvals;
+            int *colptrs;
+        """
         try:
-            if pData.sw != NULL:
-                jac=(<object>pData.JAC)(t,y,sw=<list>pData.sw)
+            if pData.dimSens > 0: #Sensitivity activated
+                p = realtype2arr(pData.p,pData.dimSens)
+                if pData.sw != NULL:
+                    jac=(<object>pData.JAC)(t,y,p=p,sw=<list>pData.sw)
+                else:
+                    jac=(<object>pData.JAC)(t,y,p=p)
             else:
-                jac=(<object>pData.JAC)(t,y)
-    
-            for i in range(Neq):
-                col_i = DENSE_COL(Jacobian, i)
-                for j in range(Neq):
-                    col_i[j] = jac[j,i]
+                if pData.sw != NULL:
+                    jac=(<object>pData.JAC)(t,y,sw=<list>pData.sw)
+                else:
+                    jac=(<object>pData.JAC)(t,y)
+                
+            if not isinstance(jac, sparse.csc.csc_matrix):
+                jac = sparse.csc.csc_matrix(jac)
+                raise AssimuloException("The Jacobian must be stored on Scipy's CSC format.")
+            ret_nnz = jac.nnz
+            if ret_nnz > nnz:
+                raise AssimuloException("The Jacobian has more entries than supplied to the problem class via 'jac_nnz'")    
 
+            for i in range(min(ret_nnz,nnz)):
+                data[i]    = jac.data[i]
+                rowvals[i] = jac.indices[i]
+            for i in range(dim+1):
+                colptrs[i] = jac.indptr[i]
+            
             return CVDLS_SUCCESS
         except(N.linalg.LinAlgError,ZeroDivisionError,AssimuloRecoverableError):
             return CVDLS_JACFUNC_RECVR #Recoverable Error (See Sundials description)
@@ -210,7 +211,112 @@
         except:
             traceback.print_exc()
             return CVDLS_JACFUNC_UNRECVR
+
+
+IF SUNDIALS_VERSION >= (3,0,0):
+    cdef int cv_jac(realtype t, N_Vector yv, N_Vector fy, SUNMatrix Jac, 
+                void *problem_data, N_Vector tmp1, N_Vector tmp2, N_Vector tmp3):
+        """
+        This method is used to connect the Assimulo.Problem.jac to the Sundials
+        Jacobian function.
+        """
+        cdef SUNMatrixContent_Dense Jacobian = <SUNMatrixContent_Dense>Jac.content
+        cdef ProblemData pData = <ProblemData>problem_data
+        cdef realtype* col_i=Jacobian.cols[0]
+        cdef N.ndarray y = pData.work_y
+        cdef int i,j, Neq = pData.dim
         
+        nv2arr_inplace(yv, y)
+
+        if pData.dimSens>0: #Sensitivity activated
+            p = realtype2arr(pData.p,pData.dimSens)
+            try:
+                if pData.sw != NULL:
+                    jac=(<object>pData.JAC)(t,y,sw=<list>pData.sw,p=p)
+                else:
+                    jac=(<object>pData.JAC)(t,y,p)
+                    
+                for i in range(Neq):
+                    col_i = Jacobian.cols[i]
+                    for j in range(Neq):
+                        col_i[j] = jac[j,i]
+
+                return CVDLS_SUCCESS
+            except(N.linalg.LinAlgError,ZeroDivisionError,AssimuloRecoverableError):
+                return CVDLS_JACFUNC_RECVR #Recoverable Error (See Sundials description)
+            except:
+                traceback.print_exc()
+                return CVDLS_JACFUNC_UNRECVR
+        else:
+            try:
+                if pData.sw != NULL:
+                    jac=(<object>pData.JAC)(t,y,sw=<list>pData.sw)
+                else:
+                    jac=(<object>pData.JAC)(t,y)
+        
+                for i in range(Neq):
+                    col_i = Jacobian.cols[i]
+                    for j in range(Neq):
+                        col_i[j] = jac[j,i]
+
+                return CVDLS_SUCCESS
+            except(N.linalg.LinAlgError,ZeroDivisionError,AssimuloRecoverableError):
+                return CVDLS_JACFUNC_RECVR #Recoverable Error (See Sundials description)
+            except:
+                traceback.print_exc()
+                return CVDLS_JACFUNC_UNRECVR
+ELSE:
+    cdef int cv_jac(int Neq, realtype t, N_Vector yv, N_Vector fy, DlsMat Jacobian, 
+                    void *problem_data, N_Vector tmp1, N_Vector tmp2, N_Vector tmp3):
+        """
+        This method is used to connect the Assimulo.Problem.jac to the Sundials
+        Jacobian function.
+        """
+        cdef ProblemData pData = <ProblemData>problem_data
+        cdef realtype* col_i=DENSE_COL(Jacobian,0)
+        cdef N.ndarray y = pData.work_y
+        cdef int i,j
+        
+        nv2arr_inplace(yv, y)
+
+        if pData.dimSens>0: #Sensitivity activated
+            p = realtype2arr(pData.p,pData.dimSens)
+            try:
+                if pData.sw != NULL:
+                    jac=(<object>pData.JAC)(t,y,sw=<list>pData.sw,p=p)
+                else:
+                    jac=(<object>pData.JAC)(t,y,p)
+                    
+                for i in range(Neq):
+                    col_i = DENSE_COL(Jacobian, i)
+                    for j in range(Neq):
+                        col_i[j] = jac[j,i]
+
+                return CVDLS_SUCCESS
+            except(N.linalg.LinAlgError,ZeroDivisionError,AssimuloRecoverableError):
+                return CVDLS_JACFUNC_RECVR #Recoverable Error (See Sundials description)
+            except:
+                traceback.print_exc()
+                return CVDLS_JACFUNC_UNRECVR
+        else:
+            try:
+                if pData.sw != NULL:
+                    jac=(<object>pData.JAC)(t,y,sw=<list>pData.sw)
+                else:
+                    jac=(<object>pData.JAC)(t,y)
+        
+                for i in range(Neq):
+                    col_i = DENSE_COL(Jacobian, i)
+                    for j in range(Neq):
+                        col_i[j] = jac[j,i]
+
+                return CVDLS_SUCCESS
+            except(N.linalg.LinAlgError,ZeroDivisionError,AssimuloRecoverableError):
+                return CVDLS_JACFUNC_RECVR #Recoverable Error (See Sundials description)
+            except:
+                traceback.print_exc()
+                return CVDLS_JACFUNC_UNRECVR
+        
 cdef int cv_jacv(N_Vector vv, N_Vector Jv, realtype t, N_Vector yv, N_Vector fyv,
 				    void *problem_data, N_Vector tmp):
     """
@@ -337,9 +443,6 @@
     Root-finding function.
     """
     cdef ProblemData pData = <ProblemData>problem_data
-    #cdef ndarray[realtype, ndim=1, mode='c'] root #Used for return from the user function
-    #(<ndarray>pData.y).data =  <realtype*>((<N_VectorContent_Serial>yv.content).data)
-    #cdef N.ndarray y = nv2arr(yv)
     cdef N.ndarray y = pData.work_y
     cdef int i
     
@@ -366,12 +469,8 @@
     """
     cdef ProblemData pData = <ProblemData>problem_data
     cdef N.ndarray[realtype, ndim=1, mode='c'] res #Used for return from the user function
-    #(<ndarray>pData.y).data  =  <realtype*>((<N_VectorContent_Serial>yv.content).data)
-    #(<ndarray>pData.yd).data =  <realtype*>((<N_VectorContent_Serial>yvdot.content).data)
     cdef N.ndarray y = pData.work_y
     cdef N.ndarray yd = pData.work_yd
-    # cdef N.ndarray y = nv2arr(yv)
-    # cdef N.ndarray yd = nv2arr(yvdot)
     cdef realtype* resptr=(<N_VectorContent_Serial>residual.content).data
     cdef int i
     
@@ -414,63 +513,113 @@
         except:
             traceback.print_exc()
             return IDA_RES_FAIL
-            
-cdef int ida_jac(int Neq, realtype t, realtype c, N_Vector yv, N_Vector yvdot, N_Vector residual, DlsMat Jacobian,
+
+IF SUNDIALS_VERSION >= (3,0,0):
+    cdef int ida_jac(realtype t, realtype c, N_Vector yv, N_Vector yvdot, N_Vector residual, SUNMatrix Jac,
+                 void *problem_data, N_Vector tmp1, N_Vector tmp2, N_Vector tmp3):
+        """
+        This method is used to connect the Assimulo.Problem.jac to the Sundials
+        Jacobian function.
+        """
+        cdef SUNMatrixContent_Dense Jacobian = <SUNMatrixContent_Dense>Jac.content
+        cdef ProblemData pData = <ProblemData>problem_data
+        cdef N.ndarray[realtype, ndim=2, mode='c'] jac #Used for return from the user function
+        cdef realtype* col_i=Jacobian.cols[0]
+        cdef N.ndarray y = pData.work_y
+        cdef N.ndarray yd = pData.work_yd
+        cdef int i,j, Neq = pData.dim
+        
+        nv2arr_inplace(yv, y)
+        nv2arr_inplace(yvdot, yd)
+        
+        if pData.dimSens!=0: #SENSITIVITY 
+            p = realtype2arr(pData.p,pData.dimSens)
+            try:
+                if pData.sw != NULL:
+                    jac=(<object>pData.JAC)(c,t,y,yd,sw=<list>pData.sw,p=p)  # call to the python residual function
+                else:
+                    jac=(<object>pData.JAC)(c,t,y,yd,p=p)
+                
+                for i in range(Neq):
+                    col_i = Jacobian.cols[i]
+                    for j in range(Neq):
+                        col_i[j] = jac[j,i]
+                return IDADLS_SUCCESS
+            except(N.linalg.LinAlgError,ZeroDivisionError,AssimuloRecoverableError):
+                return IDADLS_JACFUNC_RECVR #Recoverable Error
+            except:
+                traceback.print_exc()
+                return IDADLS_JACFUNC_UNRECVR
+        else:
+            try:
+                if pData.sw != NULL:
+                    jac=(<object>pData.JAC)(c,t,y,yd,<list>pData.sw)  # call to the python residual function
+                else:
+                    jac=(<object>pData.JAC)(c,t,y,yd)
+                
+                for i in range(Neq):
+                    col_i = Jacobian.cols[i]
+                    for j in range(Neq):
+                        col_i[j] = jac[j,i]
+                return IDADLS_SUCCESS
+            except(N.linalg.LinAlgError,ZeroDivisionError,AssimuloRecoverableError):
+                return IDADLS_JACFUNC_RECVR #Recoverable Error
+            except:
+                traceback.print_exc()
+                return IDADLS_JACFUNC_UNRECVR
+ELSE:
+    cdef int ida_jac(int Neq, realtype t, realtype c, N_Vector yv, N_Vector yvdot, N_Vector residual, DlsMat Jacobian,
                  void* problem_data, N_Vector tmp1, N_Vector tmp2, N_Vector tmp3):
-    """
-    This method is used to connect the Assimulo.Problem.jac to the Sundials
-    Jacobian function.
-    """
-    cdef ProblemData pData = <ProblemData>problem_data
-    cdef N.ndarray[realtype, ndim=2, mode='c'] jac #Used for return from the user function
-    cdef realtype* col_i=DENSE_COL(Jacobian,0)
-    #(<ndarray>pData.y).data  =  <realtype*>((<N_VectorContent_Serial>yv.content).data)
-    #(<ndarray>pData.yd).data =  <realtype*>((<N_VectorContent_Serial>yvdot.content).data)
-    cdef N.ndarray y = pData.work_y
-    cdef N.ndarray yd = pData.work_yd
-    #cdef N.ndarray y = nv2arr(yv)
-    #cdef N.ndarray yd = nv2arr(yvdot)
-    cdef int i,j
-    
-    nv2arr_inplace(yv, y)
-    nv2arr_inplace(yvdot, yd)
-    
-    if pData.dimSens!=0: #SENSITIVITY 
-        p = realtype2arr(pData.p,pData.dimSens)
-        try:
-            if pData.sw != NULL:
-                jac=(<object>pData.JAC)(c,t,y,yd,sw=<list>pData.sw,p=p)  # call to the python residual function
-            else:
-                jac=(<object>pData.JAC)(c,t,y,yd,p=p)
+        """
+        This method is used to connect the Assimulo.Problem.jac to the Sundials
+        Jacobian function.
+        """
+        cdef ProblemData pData = <ProblemData>problem_data
+        cdef N.ndarray[realtype, ndim=2, mode='c'] jac #Used for return from the user function
+        cdef realtype* col_i=DENSE_COL(Jacobian,0)
+        cdef N.ndarray y = pData.work_y
+        cdef N.ndarray yd = pData.work_yd
+        cdef int i,j
+        
+        nv2arr_inplace(yv, y)
+        nv2arr_inplace(yvdot, yd)
+        
+        if pData.dimSens!=0: #SENSITIVITY 
+            p = realtype2arr(pData.p,pData.dimSens)
+            try:
+                if pData.sw != NULL:
+                    jac=(<object>pData.JAC)(c,t,y,yd,sw=<list>pData.sw,p=p)  # call to the python residual function
+                else:
+                    jac=(<object>pData.JAC)(c,t,y,yd,p=p)
+                
+                for i in range(Neq):
+                    col_i = DENSE_COL(Jacobian, i)
+                    for j in range(Neq):
+                        col_i[j] = jac[j,i]
+                return IDADLS_SUCCESS
+            except(N.linalg.LinAlgError,ZeroDivisionError,AssimuloRecoverableError):
+                return IDADLS_JACFUNC_RECVR #Recoverable Error
+            except:
+                traceback.print_exc()
+                return IDADLS_JACFUNC_UNRECVR
+        else:
+            try:
+                if pData.sw != NULL:
+                    jac=(<object>pData.JAC)(c,t,y,yd,<list>pData.sw)  # call to the python residual function
+                else:
+                    jac=(<object>pData.JAC)(c,t,y,yd)
+                
+                for i in range(Neq):
+                    col_i = DENSE_COL(Jacobian, i)
+                    for j in range(Neq):
+                        col_i[j] = jac[j,i]
+                return IDADLS_SUCCESS
+            except(N.linalg.LinAlgError,ZeroDivisionError,AssimuloRecoverableError):
+                return IDADLS_JACFUNC_RECVR #Recoverable Error
+            except:
+                traceback.print_exc()
+                return IDADLS_JACFUNC_UNRECVR
             
-            for i in range(Neq):
-                col_i = DENSE_COL(Jacobian, i)
-                for j in range(Neq):
-                    col_i[j] = jac[j,i]
-            return IDADLS_SUCCESS
-        except(N.linalg.LinAlgError,ZeroDivisionError,AssimuloRecoverableError):
-            return IDADLS_JACFUNC_RECVR #Recoverable Error
-        except:
-            traceback.print_exc()
-            return IDADLS_JACFUNC_UNRECVR
-    else:
-        try:
-            if pData.sw != NULL:
-                jac=(<object>pData.JAC)(c,t,y,yd,<list>pData.sw)  # call to the python residual function
-            else:
-                jac=(<object>pData.JAC)(c,t,y,yd)
-            
-            for i in range(Neq):
-                col_i = DENSE_COL(Jacobian, i)
-                for j in range(Neq):
-                    col_i[j] = jac[j,i]
-            return IDADLS_SUCCESS
-        except(N.linalg.LinAlgError,ZeroDivisionError,AssimuloRecoverableError):
-            return IDADLS_JACFUNC_RECVR #Recoverable Error
-        except:
-            traceback.print_exc()
-            return IDADLS_JACFUNC_UNRECVR
-        
 
 cdef int ida_root(realtype t, N_Vector yv, N_Vector yvdot, realtype *gout,  void* problem_data):
     """
@@ -479,12 +628,8 @@
     """
     cdef ProblemData pData = <ProblemData>problem_data
     cdef N.ndarray[realtype, ndim=1, mode='c'] root #Used for return from the user function
-    #(<ndarray>pData.y).data  =  <realtype*>((<N_VectorContent_Serial>yv.content).data)
-    #(<ndarray>pData.yd).data =  <realtype*>((<N_VectorContent_Serial>yvdot.content).data)
     cdef N.ndarray y = pData.work_y
     cdef N.ndarray yd = pData.work_yd
-    #cdef N.ndarray y = nv2arr(yv)
-    #cdef N.ndarray yd = nv2arr(yvdot)
     cdef int i
     
     nv2arr_inplace(yv, y)
@@ -553,30 +698,54 @@
             traceback.print_exc()
             return SPGMR_PSOLVE_FAIL_UNREC
     
+IF SUNDIALS_VERSION >= (3,0,0):
+    cdef int kin_jac(N_Vector xv, N_Vector fval, SUNMatrix Jac, 
+                    void *problem_data, N_Vector tmp1, N_Vector tmp2):
+        """
+        This method is used to connect the assimulo.Problem.jac to the Sundials
+        Jacobian function.
+        """
+        cdef SUNMatrixContent_Dense Jacobian = <SUNMatrixContent_Dense>Jac.content
+        cdef ProblemDataEquationSolver pData = <ProblemDataEquationSolver>problem_data
+        cdef realtype* col_i=Jacobian.cols[0]
+        cdef N.ndarray x = nv2arr(xv)
+        cdef int i,j, Neq = pData.dim
+        
+        try:
+            jac=(<object>pData.JAC)(x)
 
-cdef int kin_jac(int Neq, N_Vector xv, N_Vector fval, DlsMat Jacobian, 
-                void *problem_data, N_Vector tmp1, N_Vector tmp2):
-    """
-    This method is used to connect the assimulo.Problem.jac to the Sundials
-    Jacobian function.
-    """
-    cdef ProblemDataEquationSolver pData = <ProblemDataEquationSolver>problem_data
-    cdef realtype* col_i=DENSE_COL(Jacobian,0)
-    cdef N.ndarray x = nv2arr(xv)
-    cdef int i,j
-    
-    try:
-        jac=(<object>pData.JAC)(x)
+            for i in range(Neq):
+                col_i = Jacobian.cols[i]
+                for j in range(Neq):
+                    col_i[j] = jac[j,i]
 
-        for i in range(Neq):
-            col_i = DENSE_COL(Jacobian, i)
-            for j in range(Neq):
-                col_i[j] = jac[j,i]
+            return KINDLS_SUCCESS
+        except:
+            return KINDLS_JACFUNC_RECVR #Recoverable Error (See Sundials description)
+ELSE:
+    cdef int kin_jac(int Neq, N_Vector xv, N_Vector fval, DlsMat Jacobian, 
+                    void *problem_data, N_Vector tmp1, N_Vector tmp2):
+        """
+        This method is used to connect the assimulo.Problem.jac to the Sundials
+        Jacobian function.
+        """
+        cdef ProblemDataEquationSolver pData = <ProblemDataEquationSolver>problem_data
+        cdef realtype* col_i=DENSE_COL(Jacobian,0)
+        cdef N.ndarray x = nv2arr(xv)
+        cdef int i,j
+        
+        try:
+            jac=(<object>pData.JAC)(x)
 
-        return KINDLS_SUCCESS
-    except:
-        return KINDLS_JACFUNC_RECVR #Recoverable Error (See Sundials description)
-        
+            for i in range(Neq):
+                col_i = DENSE_COL(Jacobian, i)
+                for j in range(Neq):
+                    col_i[j] = jac[j,i]
+
+            return KINDLS_SUCCESS
+        except:
+            return KINDLS_JACFUNC_RECVR #Recoverable Error (See Sundials description)
+            
 cdef int kin_jacv(N_Vector vv, N_Vector Jv, N_Vector vx, bint new_u,
             void *problem_data):
     cdef ProblemDataEquationSolver pData = <ProblemDataEquationSolver>problem_data
Index: examples/cvode_with_jac.py
===================================================================
--- assimulo/examples/cvode_with_jac.py	(revision 844)
+++ assimulo/examples/cvode_with_jac.py	(revision 845)
@@ -46,7 +46,6 @@
     def f(t,y):
         yd_0 = y[1]
         yd_1 = -9.82
-        #print y, yd_0, yd_1
         return N.array([yd_0,yd_1])
     
     #Defines the Jacobian
Index: examples/__init__.py
===================================================================
--- assimulo/examples/__init__.py	(revision 844)
+++ assimulo/examples/__init__.py	(revision 845)
@@ -24,6 +24,6 @@
            "mech_system_pendulum", "euler_vanderpol", "cvode_with_parameters_modified",
            "cvode_basic_backward","ida_basic_backward","dasp3_basic", "cvode_with_preconditioning",
            "kinsol_basic","kinsol_with_jac", "radau5dae_time_events", "kinsol_ors", "lsodar_bouncing_ball",
-           "cvode_with_parameters_fcn", "ida_with_user_defined_handle_result"]
+           "cvode_with_parameters_fcn", "ida_with_user_defined_handle_result", "cvode_with_jac_sparse"]
 
 
Index: examples/cvode_with_jac_sparse.py
===================================================================
--- assimulo/examples/cvode_with_jac_sparse.py	(nonexistent)
+++ assimulo/examples/cvode_with_jac_sparse.py	(revision 845)
@@ -0,0 +1,102 @@
+#!/usr/bin/env python 
+# -*- coding: utf-8 -*-
+
+# Copyright (C) 2010 Modelon AB
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Lesser General Public License as published by
+# the Free Software Foundation, version 3 of the License.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+import numpy as N
+import scipy.sparse as SP
+import pylab as P
+import nose
+from assimulo.solvers import CVode
+from assimulo.problem import Explicit_Problem
+
+
+def run_example(with_plots=True):
+    r"""
+    Example for demonstrating the use of a user supplied Jacobian (sparse).
+    Note that this will only work if Assimulo has been configured with
+    Sundials + SuperLU. Based on the SUNDIALS example cvRoberts_sps.c
+    
+    ODE:
+    
+    .. math::
+       
+       \dot y_1 &= -0.04y_1 + 1e4 y_2 y_3 \\
+       \dot y_2 &= - \dot y_1 - \dot y_3 \\
+       \dot y_3 &= 3e7 y_2^2
+       
+    
+    on return:
+    
+       - :dfn:`exp_mod`    problem instance
+    
+       - :dfn:`exp_sim`    solver instance
+       
+    """
+    
+    #Defines the rhs
+    def f(t,y):
+        yd_0 = -0.04*y[0] + 1e4*y[1]*y[2]
+        yd_2 = 3e7*y[1]*y[1]
+        yd_1 = -yd_0 - yd_2
+        return N.array([yd_0,yd_1,yd_2])
+    
+    #Defines the Jacobian
+    def jac(t,y):
+        
+        colptrs = [0,3,6,9]
+        rowvals = [0, 1, 2, 0, 1, 2, 0, 1, 2]
+        data = [-0.04, 0.04, 0.0, 1e4*y[2], -1e4*y[2]-6e7*y[1], 6e7*y[1], 1e4*y[1], -1e4*y[1], 0.0]
+
+        J = SP.csc_matrix((data, rowvals, colptrs))
+        return J
+    
+    #Defines an Assimulo explicit problem
+    y0 = [1.0,0.0,0.0] #Initial conditions
+
+    exp_mod = Explicit_Problem(f,y0, name = 'Example using analytic (sparse) Jacobian')
+    
+    exp_mod.jac = jac #Sets the Jacobian
+    exp_mod.jac_nnz = 9
+   
+    
+    exp_sim = CVode(exp_mod) #Create a CVode solver
+    
+    #Set the parameters
+    exp_sim.iter = 'Newton' #Default 'FixedPoint'
+    exp_sim.discr = 'BDF' #Default 'Adams'
+    exp_sim.atol = [1e-8,1e-14,1e-6] #Default 1e-6
+    exp_sim.rtol = 1e-4 #Default 1e-6
+    exp_sim.linear_solver = "sparse"
+    
+    #Simulate
+    t, y = exp_sim.simulate(0.4) #Simulate 0.4 seconds
+    
+    #Basic tests
+    nose.tools.assert_almost_equal(y[-1][0],0.9851,3)
+        
+    #Plot
+    if with_plots:
+        P.plot(t,y[:,1],linestyle="dashed",marker="o") #Plot the solution
+        P.xlabel('Time')
+        P.ylabel('State')
+        P.title(exp_mod.name)
+        P.show()
+        
+    return exp_mod, exp_sim
+
+
+if __name__=='__main__':
+    mod,sim = run_example()
Index: tests/test_examples.py
===================================================================
--- assimulo/tests/test_examples.py	(revision 844)
+++ assimulo/tests/test_examples.py	(revision 845)
@@ -22,7 +22,15 @@
 
 class Test_Examples:
     
+    
     @testattr(stddist = True)
+    def test_cvode_with_jac_sparse(self):
+        try:
+            cvode_with_jac_sparse.run_example(with_plots=False)
+        except AssimuloException:
+            pass #Handle the case when SuperLU is not installed
+    
+    @testattr(stddist = True)
     def test_ida_with_user_defined_handle_result(self):
         ida_with_user_defined_handle_result.run_example(with_plots=False)