For cvsRoberts_FSA_dns, sensi_meth = CV_SIMULTANEOUS, err_con = true, solutions and...
authorilb@NIH.GOV <ilb@NIH.GOV@ba61647d-9d00-f842-95cd-605cb4296b96>
Fri, 16 Mar 2018 22:15:25 +0000 (22:15 +0000)
committerilb@NIH.GOV <ilb@NIH.GOV@ba61647d-9d00-f842-95cd-605cb4296b96>
Fri, 16 Mar 2018 22:15:25 +0000 (22:15 +0000)
git-svn-id: https://citdcbmipav.cit.nih.gov/repos-pub/mipav/trunk@15418 ba61647d-9d00-f842-95cd-605cb4296b96

mipav/src/gov/nih/mipav/model/algorithms/CVODES.java

index c5ebd0c..b256d4a 100644 (file)
@@ -2,11 +2,7 @@ package gov.nih.mipav.model.algorithms;
 \r
 import java.io.RandomAccessFile;\r
 \r
-import gov.nih.mipav.model.algorithms.CVODES.CVodeMemRec;\r
-import gov.nih.mipav.model.algorithms.CVODES.NVector;\r
-import gov.nih.mipav.model.algorithms.CVODES.UserData;\r
 import gov.nih.mipav.view.MipavUtil;\r
-import gov.nih.mipav.view.Preferences;\r
 \r
 public abstract class CVODES {\r
        // This is a port of code from CVODES, a stiff and non-stiff ODE solver, from C to Java\r
@@ -574,7 +570,7 @@ public abstract class CVODES {
     final int cvsDirectDemo_ls_Problem_1 = 2;\r
     final int cvsRoberts_dns_uw = 3;\r
     final int cvsRoberts_FSA_dns = 4;\r
-    int problem = cvsDirectDemo_ls_Problem_1;\r
+    int problem = cvsRoberts_FSA_dns;\r
     boolean testMode = true;\r
        \r
     // Linear Solver options for runcvsDirectDemo\r
@@ -611,7 +607,7 @@ public abstract class CVODES {
                  return 0;\r
          }\r
          \r
-         public int fS(int Ns, double t, NVector yv, NVector ydot, int is,\r
+         public int fS1(int Ns, double t, NVector yv, NVector ydot, int is,\r
                                 NVector yS, NVector ySdot, UserData user_data, NVector tmp1, NVector tmp2) {\r
                          return 0;  \r
           }\r
@@ -1239,7 +1235,6 @@ public abstract class CVODES {
                int qu;\r
                double hu;\r
                int f = cvsRoberts_FSA_dns;\r
-               int g = cvsRoberts_FSA_dns;\r
                int Jac = cvsRoberts_FSA_dns;\r
                int ewt_select = cvEwtUser_select1;\r
                // User data structure\r
@@ -1261,13 +1256,11 @@ public abstract class CVODES {
                abstol.setData(abstolr);\r
                CVodeMemRec cvode_mem;\r
                int flag;\r
-               int flagr;\r
                double A[][];\r
                SUNLinearSolver LS;\r
                double tout;\r
                int iout;\r
                double t[] = new double[1];\r
-               int rootsfound[] = new int[2];\r
                int i;\r
                double pbar[] = new double[3];\r
                int is;\r
@@ -1488,6 +1481,11 @@ public abstract class CVODES {
                // Free y and abstol vectors\r
                N_VDestroy(y);\r
                N_VDestroy(abstol);\r
+               if (sensi) {\r
+                   N_VDestroyVectorArray(yS, NS);  // Free yS vector \r
+               }\r
+               data.array = null;\r
+               data = null;\r
                \r
                // Free the integrator memory\r
                CVodeFree(cvode_mem);\r
@@ -1532,9 +1530,9 @@ public abstract class CVODES {
                System.out.println("of the sensitivity equations = " + cv_mem.cv_nfeS);\r
             System.out.println("Number of calls made to the linear solver's setup routine due to ");\r
             System.out.println("sensitivity computations = " + cv_mem.cv_nsetupsS);\r
-            System.out.println("Number of local error test failures for sensitivity variables = " + cv_mem.cv_netfS);\r
+            System.out.println("Number of local error test failures for sensitivity variables = " + cv_mem.cv_netfS[0]);\r
             System.out.println("Total number of nonlinear iterations for sensitivity variables = " + cv_mem.cv_nniS);\r
-            System.out.println("Total number of nonlinear convergence failures for sensitivity variables = " + cv_mem.cv_ncfnS);\r
+            System.out.println("Total number of nonlinear convergence failures for sensitivity variables = " + cv_mem.cv_ncfnS[0]);\r
            } // if (sensi)\r
            \r
            System.out.println("Number of Jacobian evaluations = " + cv_mem.cv_lmem.nje);\r
@@ -1656,7 +1654,7 @@ public abstract class CVODES {
                double tout;\r
                int qu;\r
                double hu;\r
-               int nerr = 0;\r
+               //int nerr = 0;\r
                double er;\r
            NVector y = null;\r
            double A[][] = null;\r
@@ -1723,14 +1721,14 @@ public abstract class CVODES {
                        System.out.println("Step order qu = " + qu);\r
                        System.out.println("Step size hu = " + hu);\r
                        if (flag != CV_SUCCESS) {\r
-                               nerr++;\r
+                               //nerr++;\r
                                break;\r
                        }\r
                        if ((iout %2) == 0) {\r
                            er = Math.abs(y.data[0])/abstol;\r
                            if (er > ero) ero = er;\r
                            if (er > P1_TOL_FACTOR) {\r
-                               nerr++;\r
+                               //nerr++;\r
                                System.out.println("Error exceeds " + P1_TOL_FACTOR + " * tolerance");\r
                            }\r
                        } // if ((iout %2) == 0)\r
@@ -1791,14 +1789,14 @@ public abstract class CVODES {
                        System.out.println("Step order qu = " + qu);\r
                        System.out.println("Step size hu = " + hu);\r
                        if (flag != CV_SUCCESS) {\r
-                               nerr++;\r
+                               //nerr++;\r
                                break;\r
                        }\r
                        if ((iout %2) == 0) {\r
                            er = Math.abs(y.data[0])/abstol;\r
                            if (er > ero) ero = er;\r
                            if (er > P1_TOL_FACTOR) {\r
-                               nerr++;\r
+                               //nerr++;\r
                                System.out.println("Error exceeds " + P1_TOL_FACTOR + " * tolerance");\r
                            }\r
                        } // if ((iout %2) == 0)\r
@@ -1978,7 +1976,7 @@ public abstract class CVODES {
        \r
        public abstract int fQ(double t, NVector x, NVector y, UserData user_data);\r
        \r
-       private int fsTestMode(int Ns, double t, NVector yv, NVector ydot, int is,\r
+       private int fS1TestMode(int Ns, double t, NVector yv, NVector ydot, int is,\r
                        NVector yS, NVector ySdot, UserData user_data, NVector tmp1, NVector tmp2) {\r
                double y[] = yv.data;\r
                double p[] = user_data.array;\r
@@ -2008,7 +2006,7 @@ public abstract class CVODES {
                return 0;\r
        }\r
        \r
-       public abstract int fS(int Ns, double t, NVector yv, NVector ydot, int is,\r
+       public abstract int fS1(int Ns, double t, NVector yv, NVector ydot, int is,\r
                        NVector yS, NVector ySdot, UserData user_data, NVector tmp1, NVector tmp2);\r
        \r
        /**\r
@@ -2740,7 +2738,8 @@ public abstract class CVODES {
 \r
      int CVodeInit(CVodeMemRec cv_mem, int f, double t0, NVector y0)\r
      {\r
-       boolean nvectorOK, allocOK;\r
+       //boolean nvectorOK; \r
+       boolean allocOK;\r
        long lrw1[] = new long[1];\r
        long liw1[] = new long[1];\r
        int i,k;\r
@@ -5103,13 +5102,25 @@ public abstract class CVODES {
    int retval=0, is;\r
 \r
    if (cv_mem.cv_ifS==CV_ALLSENS) {\r
-     retval = cvSensRhsInternalDQ(cv_mem.cv_Ns, time, ycur, fcur, yScur, \r
+        if (cv_mem.cv_fSDQ) {\r
+         retval = cvSensRhsInternalDQ(cv_mem.cv_Ns, time, ycur, fcur, yScur, \r
                             fScur, cv_mem.cv_fS_data.memRec, temp1, temp2);\r
+        }\r
      cv_mem.cv_nfSe++;\r
    } else {\r
      for (is=0; is<cv_mem.cv_Ns; is++) {\r
+      if (cv_mem.cv_fSDQ) {\r
        retval = cvSensRhs1InternalDQ(cv_mem.cv_Ns, time, ycur, fcur, is, yScur[is], \r
                                fScur[is], cv_mem.cv_fS_data.memRec, temp1, temp2);\r
+       }\r
+       else if (testMode) {\r
+         fS1TestMode(cv_mem.cv_Ns, time, ycur, fcur, is, yScur[is], \r
+                  fScur[is], cv_mem.cv_fS_data, temp1, temp2);\r
+       }\r
+       else {\r
+          fS1(cv_mem.cv_Ns, time, ycur, fcur, is, yScur[is], \r
+                   fScur[is], cv_mem.cv_fS_data, temp1, temp2);   \r
+       }\r
        cv_mem.cv_nfSe++;\r
        if (retval != 0) break;\r
      }\r
@@ -9033,8 +9044,18 @@ else                return(snrm);
         {\r
           int retval;\r
 \r
-          retval = cvSensRhs1InternalDQ(cv_mem.cv_Ns, time, ycur, fcur, is, yScur, \r
+          if (cv_mem.cv_fSDQ) {\r
+              retval = cvSensRhs1InternalDQ(cv_mem.cv_Ns, time, ycur, fcur, is, yScur, \r
                                   fScur, cv_mem.cv_fS_data.memRec, temp1, temp2);\r
+          }\r
+          else if (testMode) {\r
+                  retval = fS1TestMode(cv_mem.cv_Ns, time, ycur, fcur, is, yScur, \r
+                   fScur, cv_mem.cv_fS_data, temp1, temp2);   \r
+          }\r
+          else {\r
+                  retval = fS1(cv_mem.cv_Ns, time, ycur, fcur, is, yScur, \r
+                   fScur, cv_mem.cv_fS_data, temp1, temp2);      \r
+          }\r
           cv_mem.cv_nfSe++;\r
 \r
           return(retval);\r
@@ -10650,8 +10671,6 @@ else                return(snrm);
          CVDlsMemRec cvdls_mem;\r
          int lrw1[] = new int[1];\r
          int liw1[] = new int[1];\r
-         long lrw, liw;\r
-         int flag;\r
 \r
          /* Return immediately if cvode_mem or cv_mem->cv_lmem are NULL */\r
          if (cv_mem == null) {\r
@@ -10801,7 +10820,6 @@ else                return(snrm);
 \r
          vs = null;\r
          vs = new NVector[count];\r
-         if(vs == null) return(null);\r
 \r
          for (j = 0; j < count; j++) {\r
            vs[j] = null;\r