Xcos solvers: opening DDaskr's Krylov feature 51/10751/39
Paul BIGNIER [Fri, 8 Mar 2013 13:37:16 +0000 (14:37 +0100)]
The 'GMRes' Krylov method is now available to use
It is the main interest of implementing DDaskr
Doc already exists, tests are included

Change-Id: I74d1535381894e1139eb2d4d80a4e8442b47bf74

32 files changed:
scilab/CHANGES_5.5.X
scilab/modules/scicos/macros/scicos_auto/scicos_simulate.sci
scilab/modules/scicos/macros/scicos_scicos/Compute_cic.sci
scilab/modules/scicos/macros/scicos_scicos/c_pass2.sci
scilab/modules/scicos/macros/scicos_scicos/c_pass3.sci
scilab/modules/scicos/src/c/ddaskr.c
scilab/modules/scicos/src/c/ddaskr.h
scilab/modules/scicos/src/c/scicos.c
scilab/modules/scicos/src/scicos_sundials/src/ida/ida_impl.h
scilab/modules/scicos/tests/unit_tests/DDaskrK_Bouncing.dia.ref [new file with mode: 0644]
scilab/modules/scicos/tests/unit_tests/DDaskrK_Bouncing.tst [new file with mode: 0644]
scilab/modules/scicos/tests/unit_tests/DDaskrK_ODE.dia.ref [new file with mode: 0644]
scilab/modules/scicos/tests/unit_tests/DDaskrK_ODE.tst [moved from scilab/modules/scicos/tests/unit_tests/DDaskr_ODE.dia.ref with 72% similarity]
scilab/modules/scicos/tests/unit_tests/DDaskrK_Platform.dia.ref [new file with mode: 0644]
scilab/modules/scicos/tests/unit_tests/DDaskrK_Platform.tst [new file with mode: 0644]
scilab/modules/scicos/tests/unit_tests/DDaskrK_RLC.dia.ref [new file with mode: 0644]
scilab/modules/scicos/tests/unit_tests/DDaskrK_RLC.tst [new file with mode: 0644]
scilab/modules/scicos/tests/unit_tests/DDaskrN_Bouncing.dia.ref [moved from scilab/modules/scicos/tests/unit_tests/DDaskr_Bouncing.dia.ref with 95% similarity]
scilab/modules/scicos/tests/unit_tests/DDaskrN_Bouncing.tst [moved from scilab/modules/scicos/tests/unit_tests/DDaskr_Bouncing.tst with 90% similarity]
scilab/modules/scicos/tests/unit_tests/DDaskrN_ODE.dia.ref [new file with mode: 0644]
scilab/modules/scicos/tests/unit_tests/DDaskrN_ODE.tst [moved from scilab/modules/scicos/tests/unit_tests/DDaskr_ODE.tst with 77% similarity]
scilab/modules/scicos/tests/unit_tests/DDaskrN_Platform.dia.ref [new file with mode: 0644]
scilab/modules/scicos/tests/unit_tests/DDaskrN_Platform.tst [new file with mode: 0644]
scilab/modules/scicos/tests/unit_tests/DDaskrN_RLC.dia.ref [moved from scilab/modules/scicos/tests/unit_tests/DDaskr_RLC.dia.ref with 96% similarity]
scilab/modules/scicos/tests/unit_tests/DDaskrN_RLC.tst [moved from scilab/modules/scicos/tests/unit_tests/DDaskr_RLC.tst with 83% similarity]
scilab/modules/xcos/examples/solvers/benchBouncing.sce [moved from scilab/modules/xcos/examples/solvers/benchDDaskr_Bouncing.sce with 90% similarity]
scilab/modules/xcos/help/en_US/solvers/9-Comparisons.xml
scilab/modules/xcos/help/fr_FR/solvers/9-Comparaisons.xml
scilab/modules/xcos/macros/xcos_simulate.sci
scilab/modules/xcos/src/java/org/scilab/modules/xcos/actions/dialog/SetupDialog.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/graph/ScicosParameters.java
scilab/modules/xcos/tests/unit_tests/DDaskr_Platform_test.zcos [new file with mode: 0644]

index df940e4..b18a4e6 100644 (file)
@@ -98,9 +98,9 @@ SciNotes
 Xcos
 ====
 
-* Update Sundials to lastest "2.5.0", keeping our modifications
+* Updated Sundials to lastest "2.5.0", keeping our modifications
 
-* Added a new DAE solver : DDaskr (BDF / Newton), which includes rootfinding.
+* Added a new DAE solver : DDaskr, using BDF methods with direct Newton and preconditioned Krylov linear solvers, which includes rootfinding.
 
 * Bug #7350 fixed - The superblock I/O ports numbering was not updated
                     when a new port was dropped.
index cb052ae..769765c 100644 (file)
@@ -272,7 +272,7 @@ function Info = scicos_simulate(scs_m, Info, updated_vars, flag, Ignb)
         solver = 100
         tolerances(6) = solver
     elseif (%cpr.sim.xptr($) - 1) == size(%cpr.state.x,"*") & ...
-        (solver == 100 | solver == 101) & size(%cpr.state.x,"*") <> 0 then
+        (or (solver == [100 101 102])) & size(%cpr.state.x,"*") <> 0 then
         warning(msprintf(_("Diagram has been compiled for explicit solver\nswitching to explicit solver.\n")))
         solver = 0
         tolerances(6) = solver
index 270d406..7ff47fd 100644 (file)
@@ -28,7 +28,7 @@ function ok=Compute_cic(method,Nunknowns)
 
     tolerances=scs_m.props.tol
     solver=tolerances(6)
-    if solver <> 100 & solver <> 101 then solver=100; end
+    if (and (solver <> [100 101 102])) then solver=100; end
     tolerances(6)=solver
     Atol=tolerances(1)
     Rtol=tolerances(2)
index 64c269d..27ded82 100644 (file)
@@ -197,7 +197,7 @@ function cpr=c_pass2(bllst,connectmat,clkconnect,cor,corinv,flag)
         warning(_("Diagram contains implicit blocks, compiling for implicit Solver."))
         %scicos_solver=100
     end
-    if %scicos_solver==100 | %scicos_solver==101 then xc0=[xc0;xcd0],end
+    if (or (%scicos_solver == [100 101 102])) then xc0=[xc0;xcd0],end
     state=scicos_state()
     state.x=xc0
     state.z=xd0
index ddf302a..fb888b2 100644 (file)
@@ -239,7 +239,7 @@ function [cpr,ok]=c_pass3(scs_m,cpr)
         %scicos_solver=100
     end
 
-    if %scicos_solver==100 | %scicos_solver==101 then xc0=[xc0;xcd0],end
+    if (or (%scicos_solver == [100 101 102])) then xc0=[xc0;xcd0],end
 
     nb=size(clkptr,"*")-1;
     iz0=zeros(nb,1);
index 8b41e16..fa12f2c 100644 (file)
  *
  * =============================
  *
- * Actual solving function, from 'ODEPACK' in 'differential_equations' module
+ * Actual solving function, from 'ODEPACK' in 'differential_equations' module.
+ * Since we use ddaskr's built-in jacobian function, set jacpsol type to DDasJacPsolFn.
  */
 
-extern void C2F(ddaskr) (DDASResFn res, int *neq, realtype *t, realtype *y, realtype *yp, realtype *tout, int *info, realtype *reltol, realtype *abstol, int *istate, struct DDrWork_t *rwork, int *lrw, int *iwork, int *liw, double *dummy1, int *dummy2, DDASJacFn j_fun, DDASPsolFn psol, DDASRootFn grblk, int *ng, int *jroot);
+extern void C2F(ddaskr) (DDASResFn res, int *neq, realtype *t, realtype *y, realtype *yp, realtype *tout, int *info, realtype *reltol, realtype *abstol, int *istate, struct DDrWork_t *rwork, int *lrw, int *iwork, int *liw, double *dummy1, int *dummy2, DDASJacPsolFn jacpsol, DDASPsolFn psol, DDASRootFn grblk, int *ng, int *jroot);
 
 /* =============================
  *
@@ -69,9 +70,9 @@ extern void C2F(ddaskr) (DDASResFn res, int *neq, realtype *t, realtype *y, real
  * DDaskrCreate prints an error message to standard err and returns NULL.
  */
 
-void * DDaskrCreate (int * neq, int ng)
+void * DDaskrCreate (int * neq, int ng, int solverIndex)
 {
-    int lIw, lRw;
+    int lIw, lRw, LENWP, LENIWP;
     DDaskrMem ddaskr_mem;
 
     /* Allocate the problem memory space */
@@ -86,9 +87,20 @@ void * DDaskrCreate (int * neq, int ng)
     /* Zero out ddas_mem */
     memset(ddaskr_mem, 0, sizeof(struct DDaskrMemRec));
 
-    /* Set the 'rwork' and 'iwork' workspaces lengths by default */
-    lRw = 60 + (*neq) * max(MAXORD_DEFAULT + 4, 7) + (*neq) * (*neq) + 3 * ng;
-    lIw = 40 + 2 * (*neq);
+    /* Set the 'rwork' and 'iwork' workspaces lengths by default
+       LENWP and LENIWP are lentghts of segments of rwork and iwork (respectively),
+       that will contain preconditioner matrix information in compact sparse row format */
+    LENWP  = (*neq) * (*neq);
+    LENIWP = 2 * (*neq) * (*neq);
+    lRw    = 60 + (*neq) * (max(MAXORD_DEFAULT + 4, 7) + (*neq)) + 3 * ng;
+    lIw    = 40 + 2 * (*neq);
+
+    /* If we are going to use the Krylov method, resize the workspaces adequately */
+    if (solverIndex == 102)
+    {
+        lRw = 101 + 18 * (*neq) + 3 * ng + LENWP;
+        lIw = 40 + (*neq) + LENIWP;
+    }
 
     /* Copy the variables into the problem memory space */
     ddaskr_mem->nEquations = neq;
@@ -99,13 +111,15 @@ void * DDaskrCreate (int * neq, int ng)
     ddaskr_mem->lrw        = lRw;
     ddaskr_mem->iwork      = NULL;
     ddaskr_mem->liw        = lIw;
-    ddaskr_mem->j_fun      = NULL;
     ddaskr_mem->ehfun      = NULL;
     ddaskr_mem->g_fun      = NULL;
     ddaskr_mem->ng_fun     = ng;
     ddaskr_mem->jroot      = NULL;
+    ddaskr_mem->solver     = solverIndex;
     ddaskr_mem->jacpsol    = NULL;
     ddaskr_mem->psol       = NULL;
+    ddaskr_mem->rpar       = NULL;
+    ddaskr_mem->ipar       = NULL;
 
     return ((void *) ddaskr_mem);
 }
@@ -113,6 +127,7 @@ void * DDaskrCreate (int * neq, int ng)
 /* Shortcuts to problem memory space parameters */
 # define res        ddas_mem->res
 # define nEq        ddas_mem->nEquations
+# define user_data  ddas_mem->user_data
 # define yVec       ddas_mem->yVector
 # define ypVec      ddas_mem->yPrimeVector
 # define tStart     ddas_mem->tStart
@@ -128,9 +143,11 @@ void * DDaskrCreate (int * neq, int ng)
 # define g_fun      ddas_mem->g_fun
 # define ng_fun     ddas_mem->ng_fun
 # define jroot      ddas_mem->jroot
-# define user_data  ddas_mem->user_data
+# define solver     ddas_mem->solver
 # define jacpsol    ddas_mem->jacpsol
 # define psol       ddas_mem->psol
+# define rpar       ddas_mem->rpar
+# define ipar       ddas_mem->ipar
 
 /* =============================
  *
@@ -175,7 +192,15 @@ int DDaskrInit (void * ddaskr_mem, DDASResFn Res, realtype t0, N_Vector yy0, N_V
         return (IDA_ILL_INPUT);
     }
 
-    //@TODO: add error if jacpsol or psol NULL
+    /* Jacpsol = NULL or Psol = NULL is a problem only if the user decided to use the GMRes solver */
+    if (solver == 102)
+    {
+        if (Jacpsol == NULL || Psol == NULL)
+        {
+            DDASProcessError(ddas_mem, IDA_ILL_INPUT, "DDASKR", "DDaskrInit", MSG_BAD_KRY_INPUT);
+            return (IDA_ILL_INPUT);
+        }
+    }
 
     /* Copy the arguments into the problem memory space */
     res     = Res;
@@ -188,11 +213,34 @@ int DDaskrInit (void * ddaskr_mem, DDASResFn Res, realtype t0, N_Vector yy0, N_V
     /* Allocate the info[20] tab to zero, used to store parameters (zero is default value for mostof them) */
     info = calloc(20, sizeof(int));
 
+    /* info[11] = 1 => Krylov method selected
+       info[14] = 1 => providing jacobian function (to evaluate and LU-factor the preconditioner) */
+    if (solver == 102)
+    {
+        info[11] = 1;
+        info[14] = 1;
+    }
+
     /* Allocate rwork and iwork workspaces and set them to zero.
        Their size is lrw and liw, respectively */
     rwork = (struct DDrWork_t *) calloc(lrw, sizeof(realtype));
     iwork = calloc(liw, sizeof(int));
 
+    /* If the user selected the Krylov method, we will need rpar and ipar
+       So alloc them and set default parameters */
+    if (solver == 102)
+    {
+        rpar = calloc(2, sizeof(realtype));
+        ipar = calloc(30, sizeof(int));
+        rpar[0] = 0.005;
+        rpar[1] = 0.005;
+        ipar[0] = *nEq;
+        ipar[1] = *nEq;
+        ipar[2] = 2;
+        ipar[3] = 2;
+        ipar[4] = 1;
+    }
+
     /* Save their lengths in iwork */
     iwork[16] = lrw;
     iwork[17] = liw;
@@ -438,38 +486,6 @@ int DDaskrSetStopTime (void * ddaskr_mem, realtype tCrit)
 
 /* =============================
  *
- *    DDaskrDlsSetDenseJacFn
- *
- * =============================
- *
- * Specifies the dense Jacobian function.
- */
-
-int DDaskrDlsSetDenseJacFn (void * ddaskr_mem, DDASJacFn J_fun)
-{
-    DDaskrMem ddas_mem;
-
-    /* Return immediately if ddaskr_mem is NULL */
-    if (ddaskr_mem == NULL)
-    {
-        DDASProcessError(NULL, IDA_MEM_NULL, "DDASKR", "DDaskrDlsSetDenseJacFn", MSG_NO_MEM);
-        return(IDA_MEM_NULL);
-    }
-    ddas_mem = (DDaskrMem) ddaskr_mem;
-
-    if (J_fun != NULL)
-    {
-        j_fun   = J_fun;
-        /* Set info[4] = 1 for ddaskr to consider the jacobian function
-           Comment that change until a working Jacobiansddaskr function is devised in scicos.c */
-        //info[4] = 1;
-    }
-
-    return(IDA_SUCCESS);
-}
-
-/* =============================
- *
  *     DDaskrSetMaxNumJacsIC
  *
  * =============================
@@ -691,8 +707,6 @@ int DDaskrSetId (void * ddaskr_mem, N_Vector xproperty)
 int DDaskrSolve (void * ddaskr_mem, realtype tOut, realtype * tOld, N_Vector yOut, N_Vector ypOut, int itask)
 {
     DDaskrMem ddas_mem;
-    double dummy1 = 0.;
-    int dummy2 = 0;
 
     /* Check the input arguments */
 
@@ -738,7 +752,7 @@ int DDaskrSolve (void * ddaskr_mem, realtype tOut, realtype * tOld, N_Vector yOu
 
     /* Launch the simulation with the memory space parameters.
        ddaskr() will update yVec, iState, rwork, iwork and jroot */
-    C2F(ddaskr) (res, nEq, &tStart, yVec, ypVec, &tOut, info, &relTol, &absTol, &iState, rwork, &lrw, iwork, &liw, &dummy1, &dummy2, j_fun, psol, g_fun, &ng_fun, jroot);
+    C2F(ddaskr) (res, nEq, &tStart, yVec, ypVec, &tOut, info, &relTol, &absTol, &iState, rwork, &lrw, iwork, &liw, rpar, ipar, jacpsol, psol, g_fun, &ng_fun, jroot);
 
     /* Increment the start time */
     *tOld  = tStart;
@@ -841,7 +855,7 @@ int DDaskrCalcIC (void * ddaskr_mem, int icopt, realtype tout1)
         info[13] = 1;
     }
 
-    C2F(ddaskr) (res, nEq, &tStart, yVec, ypVec, &tout1, info, &relTol, &absTol, &iState, rwork, &lrw, iwork, &liw, &dummy1, &dummy2, j_fun, psol, g_fun, &ng_fun, jroot);
+    C2F(ddaskr) (res, nEq, &tStart, yVec, ypVec, &tout1, info, &relTol, &absTol, &iState, rwork, &lrw, iwork, &liw, rpar, ipar, jacpsol, psol, g_fun, &ng_fun, jroot);
 
     /* The continuation of the program will not need initial values computation again, unless ReInit */
     info[10] = 0;
@@ -852,8 +866,8 @@ int DDaskrCalcIC (void * ddaskr_mem, int icopt, realtype tout1)
         case 4:
             return (IDA_SUCCESS);
         default:
-            DDASProcessError(ddas_mem, IDA_ILL_INPUT, "DDASKR", "DDaskrCalcIC", MSG_IC_FAIL_CONSTR);
-            return (IDA_ILL_INPUT);
+            DDASProcessError(ddas_mem, IDA_CONV_FAIL, "DDASKR", "DDaskrCalcIC", MSG_IC_CONV_FAILED);
+            return (IDA_CONV_FAIL);
     }
 }
 
index 6a5617c..f426779 100644 (file)
@@ -47,15 +47,14 @@ struct DDrWork_t
 };
 
 // Derivative computation, root functions, preconditioner calculation and application
-typedef int (*DDASResFn) (realtype *tOld, realtype *y, realtype *yp, realtype *res, int *flag, double *dummy1, int *dummy2);
-typedef int (*DDASRootFn) (int *neq, realtype *tOld, realtype *y, int *ng, realtype *groot, double *dummy1, int *dummy2);
-typedef int (*DDASJacFn) (realtype *t, realtype *y, realtype *yp, realtype *pd, realtype *cj, double *dummy1, int *dummy2);
-typedef int (*DDASJacPsolFn) (realtype *res, int *ires, int *neq, realtype *tOld, realtype *actual, realtype *actualP,
-                              realtype *rewt, realtype *savr, realtype *wk, realtype *h, realtype *cj, realtype *wp,
-                              int *iwp, int *ier, double *dummy1, int *dummy2);
-typedef int (*DDASPsolFn) (int *neq, realtype *tOld, realtype *actual, realtype *actualP,
-                           realtype *savr, realtype *wk, realtype *cj, realtype *wght, realtype *wp,
-                           int *iwp, realtype *b, realtype *eplin, int *ier, double *dummy1, int *dummy2);
+typedef void (*DDASResFn) (realtype *tOld, realtype *y, realtype *yp, realtype *res, int *flag, realtype *dummy1, int *dummy2);
+typedef void (*DDASRootFn) (int *neq, realtype *tOld, realtype *y, int *ng, realtype *groot, realtype *dummy1, int *dummy2);
+typedef void (*DDASJacPsolFn) (realtype *res, int *ires, int *neq, realtype *tOld, realtype *actual, realtype *actualP,
+                               realtype *rewt, realtype *savr, realtype *wk, realtype *h, realtype *cj, realtype *wp,
+                               int *iwp, int *ier, realtype *dummy1, int *dummy2);
+typedef void (*DDASPsolFn) (int *neq, realtype *tOld, realtype *actual, realtype *actualP,
+                            realtype *savr, realtype *wk, realtype *cj, realtype *wght, realtype *wp,
+                            int *iwp, realtype *b, realtype *eplin, int *ier, realtype *dummy1, int *dummy2);
 typedef void (*DDASErrHandlerFn) (int error_code, const char *module, const char *function, char *msg, void *user_data);
 
 // DDaskr problem memory structure
@@ -75,17 +74,19 @@ typedef struct DDaskrMemRec
     int lrw;
     int * iwork;
     int liw;
-    DDASJacFn j_fun;
     DDASErrHandlerFn ehfun;
     DDASRootFn g_fun;
     int ng_fun;
     int * jroot;
+    int solver;
     DDASJacPsolFn jacpsol;
     DDASPsolFn psol;
+    realtype * rpar;
+    int * ipar;
 } *DDaskrMem;
 
 // Creating the problem
-void * DDaskrCreate (int * neq, int ng);
+void * DDaskrCreate (int * neq, int ng, int solverIndex);
 
 // Allocating the problem
 int DDaskrInit (void * ddaskr_mem, DDASResFn Res, realtype t0, N_Vector yy0, N_Vector yp0, DDASJacPsolFn jacpsol, DDASPsolFn psol);
@@ -123,9 +124,6 @@ int DDaskrSetLineSearchOffIC (void * ddaskr_mem, int lsoff);
 // Specifying which components are differential and which ones are algrebraic, in order to get consistent initial values
 int DDaskrSetId (void * ddaskr_mem, N_Vector xproperty);
 
-// Specifying the Jacobian function
-int DDaskrDlsSetDenseJacFn (void * ddaskr_mem, DDASJacFn J_fun);
-
 // Solving the problem
 int DDaskrSolve (void * ddaskr_mem, realtype tOut, realtype * tOld, N_Vector yOut, N_Vector ypOut, int itask);
 
index 760cfe1..909b89b 100644 (file)
 #include <math.h>
 
 /* Sundials includes */
-#include <cvode/cvode.h>           /* prototypes for CVODES fcts. and consts. */
+#include <cvode/cvode.h>            /* prototypes for CVODES fcts. and consts. */
 #include <cvode/cvode_dense.h>     /* prototype for CVDense */
 #include <cvode/cvode_direct.h>    /* prototypes for various DlsMat operations */
 #include <ida/ida.h>
 #include <ida/ida_dense.h>
 #include <ida/ida_direct.h>
-#include <nvector/nvector_serial.h>  /* serial N_Vector types, fcts., and macros */
-#include <sundials/sundials_dense.h> /* prototypes for various DlsMat operations */
+#include <nvector/nvector_serial.h>   /* serial N_Vector types, fcts., and macros */
+#include <sundials/sundials_dense.h>  /* prototypes for various DlsMat operations */
 #include <sundials/sundials_direct.h> /* definitions of DlsMat and DENSE_ELEM */
-#include <sundials/sundials_types.h> /* definition of type realtype */
+#include <sundials/sundials_types.h>  /* definition of type realtype */
 #include <sundials/sundials_math.h>
 #include <kinsol/kinsol.h>
 #include <kinsol/kinsol_dense.h>
@@ -235,14 +235,14 @@ static int grblkdaskr(realtype t, N_Vector yy, N_Vector yp, realtype *gout, void
 static int grblk(realtype t, N_Vector yy, realtype *gout, void *g_data);
 static int simblklsodar(int * nequations, realtype * tOld, realtype * actual, realtype * res);
 static int grblklsodar(int * nequations, realtype * tOld, realtype * actual, int * ngc, realtype * res);
-static int simblkddaskr(realtype *tOld, realtype *actual, realtype *actualP, realtype *res, int *flag, double *dummy1, int *dummy2);
-static int grblkddaskr(int *nequations, realtype *tOld, realtype *actual, int *ngc, realtype *res, double *dummy1, int *dummy2);
-static int jacpsol(realtype *res, int *ires, int *nequations, realtype *tOld, realtype *actual, realtype *actualP,
-                   realtype *rewt, realtype *savr, realtype *wk, realtype *h, realtype *cj, realtype *wp,
-                   int *iwp, int *ier, double *dummy1, int *dummy2);
-static int psol(int *nequations, realtype *tOld, realtype *actual, realtype *actualP,
-                realtype *savr, realtype *wk, realtype *cj, realtype *wght, realtype *wp,
-                int *iwp, realtype *b, realtype *eplin, int *ier, double *dummy1, int *dummy2);
+static void simblkddaskr(realtype *tOld, realtype *actual, realtype *actualP, realtype *res, int *flag, double *dummy1, int *dummy2);
+static void grblkddaskr(int *nequations, realtype *tOld, realtype *actual, int *ngc, realtype *res, double *dummy1, int *dummy2);
+static void jacpsol(realtype *res, int *ires, int *nequations, realtype *tOld, realtype *actual, realtype *actualP,
+                    realtype *rewt, realtype *savr, realtype *wk, realtype *h, realtype *cj, realtype *wp,
+                    int *iwp, int *ier, double *dummy1, int *dummy2);
+static void psol(int *nequations, realtype *tOld, realtype *actual, realtype *actualP,
+                 realtype *savr, realtype *wk, realtype *cj, realtype *wght, realtype *wp,
+                 int *iwp, realtype *b, realtype *eplin, int *ier, double *dummy1, int *dummy2);
 static void addevs(double t, int *evtnb, int *ierr1);
 static int synchro_g_nev(ScicosImport *scs_imp, double *g, int kf, int *ierr);
 static void Multp(double *A, double *B, double *R, int ra, int rb, int ca, int cb);
@@ -252,13 +252,12 @@ static void SundialsErrHandler(int error_code, const char *module, const char *f
 static int Jacobians(long int Neq, realtype tt, realtype cj, N_Vector yy,
                      N_Vector yp, N_Vector resvec, DlsMat Jacque, void *jdata,
                      N_Vector tempv1, N_Vector tempv2, N_Vector tempv3);
-static int Jacobiansddaskr(realtype *t, realtype *y, realtype *yp,
-                           realtype *pd, realtype *cj, double *dummy1, int *dummy2);
 static void call_debug_scicos(scicos_block *block, scicos_flag *flag, int flagi, int deb_blk);
 static int synchro_nev(ScicosImport *scs_imp, int kf, int *ierr);
 /*--------------------------------------------------------------------------*/
 extern int C2F(dset)(int *n, double *dx, double *dy, int *incy);
 extern int C2F(dcopy)(int *, double *, int *, double *, int *);
+extern int C2F(dgesv)(int *size, int *nColsB, double *A, int *lead_dim_A, int *ipivots, double *B, int *lead_dim_B, int *info);
 extern int C2F(msgs)();
 extern int C2F(getscsmax)();
 extern int C2F(makescicosimport)();
@@ -849,7 +848,8 @@ int C2F(scicos)(double *x_in, int *xptr_in, double *z__,
                 cossim(t0);
                 break;
             case 100: // IDA
-            case 101: // DDaskr
+            case 101: // DDaskr - BDF / Newton
+            case 102: // DDaskr - BDF / GMRes
                 cossimdaskr(t0);
                 break;
             default: // Unknown solver number
@@ -2130,7 +2130,8 @@ static void cossimdaskr(double *told)
             DAESetMaxNumStepsIC = &IDASetMaxNumStepsIC;
             DAESetLineSearchOffIC = &IDASetLineSearchOffIC;
             break;
-        case 101: // DDaskr
+        case 101: // DDaskr - BDF - Newton
+        case 102: // DDaskr - BDF / GMRes
             DAEFree = &DDaskrFree;
             DAESolve = &DDaskrSolve;
             DAESetId = &DDaskrSetId;
@@ -2283,9 +2284,9 @@ static void cossimdaskr(double *told)
 
         /* Call the Create and Init functions to initialize DAE memory */
         dae_mem = NULL;
-        if (C2F(cmsolver).solver == 101)
+        if (C2F(cmsolver).solver == 101 || C2F(cmsolver).solver == 102)
         {
-            dae_mem = DDaskrCreate(neq, ng);
+            dae_mem = DDaskrCreate(neq, ng, C2F(cmsolver).solver);
         }
         else
         {
@@ -2324,7 +2325,7 @@ static void cossimdaskr(double *told)
             copy_IDA_mem = (IDAMem) dae_mem;
         }
 
-        if (C2F(cmsolver).solver == 101)
+        if (C2F(cmsolver).solver == 101 || C2F(cmsolver).solver == 102)
         {
             flag = DDaskrSetErrHandlerFn(dae_mem, SundialsErrHandler, NULL);
         }
@@ -2366,7 +2367,7 @@ static void cossimdaskr(double *told)
             return;
         }
 
-        if (C2F(cmsolver).solver == 101)
+        if (C2F(cmsolver).solver == 101 || C2F(cmsolver).solver == 102)
         {
             flag = DDaskrInit(dae_mem, simblkddaskr, T0, yy, yp, jacpsol, psol);
         }
@@ -2443,7 +2444,7 @@ static void cossimdaskr(double *told)
             return;
         }
 
-        if (C2F(cmsolver).solver == 101)
+        if (C2F(cmsolver).solver == 101 || C2F(cmsolver).solver == 102)
         {
             flag = DDaskrRootInit(dae_mem, ng, grblkddaskr);
         }
@@ -2707,11 +2708,7 @@ static void cossimdaskr(double *told)
             return;
         }
 
-        if (C2F(cmsolver).solver == 101)
-        {
-            flag = DDaskrDlsSetDenseJacFn(dae_mem, Jacobiansddaskr);
-        }
-        else
+        if (C2F(cmsolver).solver == 100)
         {
             flag = IDADlsSetDenseJacFn(dae_mem, Jacobians);
         }
@@ -3569,7 +3566,7 @@ void callf(double *t, scicos_block *block, scicos_flag *flag)
     loc = block->funpt;
 
     /* continuous state */
-    if ((solver == 100 || solver == 101) && block->type < 10000 && *flag == 0)
+    if ((solver == 100 || solver == 101 || solver == 102) && block->type < 10000 && *flag == 0)
     {
         ptr_d = block->xd;
         block->xd  = block->res;
@@ -3939,7 +3936,7 @@ void callf(double *t, scicos_block *block, scicos_flag *flag)
     // sciprint("callf end  flag=%d\n",*flag);
     /* Implicit Solver & explicit block & flag==0 */
     /* adjust continuous state vector after call */
-    if ((solver == 100 || solver == 101) && block->type < 10000 && *flag == 0)
+    if ((solver == 100 || solver == 101 || solver == 102) && block->type < 10000 && *flag == 0)
     {
         block->xd  = ptr_d;
         if (flagi != 7)
@@ -3992,7 +3989,7 @@ static void call_debug_scicos(scicos_block *block, scicos_flag *flag, int flagi,
     loc4 = (ScicosF4) loc;
 
     /* continuous state */
-    if ((solver == 100 || solver == 101) && block->type < 10000 && *flag == 0)
+    if ((solver == 100 || solver == 101 || solver == 102) && block->type < 10000 && *flag == 0)
     {
         ptr_d = block->xd;
         block->xd  = block->res;
@@ -4002,7 +3999,7 @@ static void call_debug_scicos(scicos_block *block, scicos_flag *flag, int flagi,
 
     /* Implicit Solver & explicit block & flag==0 */
     /* adjust continuous state vector after call */
-    if ((solver == 100 || solver == 101) && block->type < 10000 && *flag == 0)
+    if ((solver == 100 || solver == 101 || solver == 102) && block->type < 10000 && *flag == 0)
     {
         block->xd  = ptr_d;
         if (flagi != 7)
@@ -4292,12 +4289,11 @@ static int grblkdaskr(realtype t, N_Vector yy, N_Vector yp, realtype *gout, void
 }/* grblkdaskr */
 /*--------------------------------------------------------------------------*/
 /* simblkddaskr */
-static int simblkddaskr(realtype *tOld, realtype *actual, realtype *actualP, realtype *res, int *flag, double *dummy1, int *dummy2)
+static void simblkddaskr(realtype *tOld, realtype *actual, realtype *actualP, realtype *res, int *flag, double *dummy1, int *dummy2)
 {
     double tx = 0.;
-    realtype alpha = 0.;
 
-    int jj = 0, nantest = 0;
+    int jj = 0;
 
     if (get_phase_simulation() == 1)
     {
@@ -4307,82 +4303,163 @@ static int simblkddaskr(realtype *tOld, realtype *actual, realtype *actualP, rea
         zdoit(&tx, actual, actualP, NULL);
     }
 
-    CJJ = 1.;
+    CJJ = 6;
 
     tx = (double) * tOld;
+    *flag = 0;
 
     C2F(dcopy)(neq, actualP, &c__1, res, &c__1);
     *ierr = 0;
     C2F(ierode).iero = 0;
     odoit(&tx, actual, actualP, res);
-
     C2F(ierode).iero = *ierr;
 
     if (*ierr == 0)
     {
-        nantest = 0;
         for (jj = 0; jj < *neq; jj++)
             if (res[jj] - res[jj] != 0) /* NaN checking */
             {
                 sciprint(_("\nWarning: The residual function #%d returns a NaN"), jj);
-                nantest = 1;
-                break;
+                *flag = -1; /* recoverable error; */
+                return;
             }
-        if (nantest == 1)
-        {
-            return 257;    /* recoverable error; */
-        }
     }
+    else
+    {
+        *flag = -2;
+        return;
+    }
+    /* *flag=-1 recoverable error; *flag=-2 unrecoverable error; *flag=0: ok*/
 
-    return (abs(*ierr)); /* ierr>0 recoverable error; ierr>0 unrecoverable error; ierr=0: ok*/
 }/* simblkddaskr */
 /*--------------------------------------------------------------------------*/
 /* grblkddaskr */
-static int grblkddaskr(int *nequations, realtype *tOld, realtype *actual, int *ngc, realtype *res, double *dummy1, int *dummy2)
+static void grblkddaskr(int *nequations, realtype *tOld, realtype *actual, int *ngc, realtype *res, double *dummy1, int *dummy2)
 {
     double tx = 0.;
-    int jj = 0, nantest = 0;
+    int jj = 0;
 
     tx = (double) * tOld;
 
     *ierr = 0;
     C2F(ierode).iero = 0;
     zdoit(&tx, actual, actual, res);
+    C2F(ierode).iero = *ierr;
     if (*ierr == 0)
     {
-        nantest = 0; /* NaN checking */
+        /* NaN checking */
         for (jj = 0; jj < *ngc; jj++)
         {
             if (res[jj] - res[jj] != 0)
             {
                 sciprint(_("\nWarning: The zero-crossing function #%d returns a NaN"), jj);
-                nantest = 1;
-                break;
+                return;
             }
         }
-        if (nantest == 1)
-        {
-            return 258; /* recoverable error; */
-        }
     }
-    C2F(ierode).iero = *ierr;
-    return (*ierr);
+    else
+    {
+        sciprint(_("\nError: Problem in the evaluation of a root function"));
+        return;
+    }
+
 }/* grblkddaskr */
 /*--------------------------------------------------------------------------*/
 /* jacpsol */
-static int jacpsol(realtype *res, int *ires, int *nequations, realtype *tOld, realtype *actual, realtype *actualP,
-                   realtype *rewt, realtype *savr, realtype *wk, realtype *h, realtype *cj, realtype *wp, int *iwp,
-                   int *ier, double *dummy1, int *dummy2)
+static void jacpsol(realtype *res, int *ires, int *nequations, realtype *tOld, realtype *actual, realtype *actualP,
+                    realtype *rewt, realtype *savr, realtype *wk, realtype *h, realtype *cj, realtype *wp, int *iwp,
+                    int *ier, double *dummy1, int *dummy2)
 {
-    // Empty routine to satisfy the ddaskr() loader. @TODO: open the Krylov feature for DDaskr.
+    /* Here, we compute the system preconditioner matrix P, which is actually the jacobian matrix,
+       so P(i,j) = dres(i)/dactual(j) + cj*dres(i)/dactualP(j). */
+    int i = 0, j = 0, nrow = 0;
+    realtype tx = 0, del = 0, delinv = 0, ysave = 0, ypsave = 0;
+    realtype * e = NULL;
+
+    tx = *tOld;
+
+    /* Work array used to evaluate res(*tOld, actual + small_increment, actualP + small_increment).
+       savr already contains res(*tOld, actual, actualP). */
+    e = (realtype *) calloc(*nequations, sizeof(realtype));
+
+    for (i = 0; i < *nequations; ++i)
+    {
+        del =  max (SQuround * max(fabs(actual[i]), fabs(*h * actualP[i])), 1. / rewt[i]);
+        del *= (*h * actualP[i] >= 0) ? 1 : -1;
+        ysave  = actual[i];
+        ypsave = actualP[i];
+        actual[i]  += del;
+        actualP[i] += *cj * del;
+        *ierr = 0;
+        C2F(ierode).iero = 0;
+        simblkddaskr(tOld, actual, actualP, e, ires, dummy1, dummy2);
+        C2F(ierode).iero = *ierr;
+        if (*ires == 0)
+        {
+            delinv = 1. / del;
+            for (j = 0; j < *nequations; ++j)
+            {
+                wp[nrow + j] = (e[j] - savr[j]) * delinv;
+                /* NaN test */
+                if (wp[nrow + j] - wp[nrow + j] != 0)
+                {
+                    sciprint(_("\nWarning: The preconditioner evaluation function returns a NaN at index #%d."), nrow + j);
+                    *ier = -1;
+                }
+                iwp[nrow + j] = i + 1;
+                iwp[nrow + j + *nequations * *nequations] = j + 1;
+            }
+            nrow       += *nequations;
+            actual[i]  =  ysave;
+            actualP[i] =  ypsave;
+        }
+        else
+        {
+            sciprint(_("\nError: The preconditioner evaluation function failed."));
+            *ier = -1;
+            free(e);
+            return;
+        }
+    }
+
+    free(e);
 }/* jacpsol */
 /*--------------------------------------------------------------------------*/
 /* psol */
-static int psol(int *nequations, realtype *tOld, realtype *actual, realtype *actualP,
-                realtype *savr, realtype *wk, realtype *cj, realtype *wght, realtype *wp,
-                int *iwp, realtype *b, realtype *eplin, int *ier, double *dummy1, int *dummy2)
+static void psol(int *nequations, realtype *tOld, realtype *actual, realtype *actualP,
+                 realtype *savr, realtype *wk, realtype *cj, realtype *wght, realtype *wp,
+                 int *iwp, realtype *b, realtype *eplin, int *ier, double *dummy1, int *dummy2)
 {
-    // Empty routine to satisfy the ddaskr() loader. @TODO: open the Krylov feature for DDaskr.
+    /* This function "applies" the inverse of the preconditioner to 'b' (computes P^-1*b).
+       It is done by solving P*x = b using the Lapack routine 'dgesv'. */
+    int i = 0, nColB = 1, info = 0;
+    int * ipiv = NULL;
+
+    ipiv = (int *) malloc(*nequations * sizeof(int));
+
+    C2F(dgesv) (nequations, &nColB, wp, nequations, ipiv, b, nequations, &info);
+
+    if (info == 0)
+    {
+        /* NaN test */
+        for (i = 0; i < *nequations; ++i)
+        {
+            if (b[i] - b[i] != 0)
+            {
+                sciprint(_("\nWarning: The preconditioner application function returns a NaN at index #%d."), i);
+                *ier = -1;
+            }
+        }
+    }
+    else
+    {
+        sciprint(_("\nError: The preconditioner application function failed to compute the solution of P*x = b."));
+        *ier = -1;
+    }
+
+    free (ipiv);
+    return;
+
 }/* psol */
 /*--------------------------------------------------------------------------*/
 /* Subroutine addevs */
@@ -6098,7 +6175,7 @@ void Coserror(const char *fmt, ...)
 */
 void SundialsErrHandler(int error_code, const char *module, const char *function, char *msg, void *user_data)
 {
-    char full_message[300]; // Set big buffer to be able to redesign the message later
+    char full_message[1800]; // Set big buffer to be able to redesign the message later
 
     full_message[0] = '\0';
     strncat(full_message, function, 25); // Sundials' longest function name : ~20 chars
@@ -6432,25 +6509,6 @@ static int Jacobians(long int Neq, realtype tt, realtype cj, N_Vector yy,
 
 }
 /*--------------------------------------------------------------------------*/
-static int Jacobiansddaskr(realtype *t, realtype *y, realtype *yp,
-                           realtype *pd, realtype *cj, double *dummy1, int *dummy2)
-{
-    double tx;
-    int job;
-
-    tx = *t;
-    job = 1;
-
-    // CJ = (double) *cj;  // For fonction Get_Jacobian_cj
-    CJJ = (double) * cj;  // Returned by Get_Jacobian_parameter
-
-    Jdoit(&tx, y, yp, pd, &job);
-
-    C2F(ierode).iero = *ierr;
-    return 0;
-
-}
-/*----------------------------------------------------*/
 static void Multp(double *A, double *B, double *R, int ra, int rb, int ca, int cb)
 {
     int i = 0, j = 0, k = 0;
index 79b0294..737b2ce 100644 (file)
@@ -435,6 +435,7 @@ extern "C" {
     /* IDASolve error messages */
 
 #define MSG_BAD_INPUT      "One of the arguments is illegal."
+#define MSG_BAD_KRY_INPUT  "One of the Krylov arguments is illegal (jacobian or psol functions)."
 #define MSG_SINGULAR       "The matrix of partial derivatives is singular."
 #define MSG_YRET_NULL      "yret = NULL illegal."
 #define MSG_YPRET_NULL     "ypret = NULL illegal."
diff --git a/scilab/modules/scicos/tests/unit_tests/DDaskrK_Bouncing.dia.ref b/scilab/modules/scicos/tests/unit_tests/DDaskrK_Bouncing.dia.ref
new file mode 100644 (file)
index 0000000..76d7972
--- /dev/null
@@ -0,0 +1,145 @@
+// =============================================================================
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) 2013 - Scilab Enterprises - Paul Bignier
+//
+//  This file is distributed under the same license as the Scilab package.
+// =============================================================================
+// <-- ENGLISH IMPOSED -->
+// <-- XCOS TEST -->
+// Import diagram
+assert_checktrue(importXcosDiagram("SCI/modules/xcos/tests/unit_tests/DDaskr_Bouncing_test.zcos"));
+// Redefining messagebox() to avoid popup
+prot = funcprot();
+funcprot(0);
+function messagebox(msg, msg_title)
+ disp(msg);
+endfunction
+funcprot(prot);
+// looking for the CLOCK_f/EVTDLY_f to update period
+for path_1=1:length(scs_m.objs)
+    if typeof(scs_m.objs(path_1))=="Block" & scs_m.objs(path_1).gui=="CLOCK_f" then
+        CLOCK_f_scs_m = scs_m.objs(path_1).model.rpar;
+        break;
+    end
+end
+for path_2=1:length(CLOCK_f_scs_m)
+    if typeof(CLOCK_f_scs_m.objs(path_2))=="Block" & CLOCK_f_scs_m.objs(path_2).gui=="EVTDLY_f" then
+        EVTDLY_f_blk = CLOCK_f_scs_m.objs(path_2);
+        break;
+    end
+end
+// Start by updating the clock block period (sampling)
+scs_m.objs(path_1).model.rpar.objs(path_2).graphics.exprs = [string(5*(10^-3));"0"];
+// Modify solver + run DDaskr + save results
+scs_m.props.tol(6) = 102;      // Solver
+//scs_m.props.tol(1) = 1.0e-10; // abstol
+//scs_m.props.tol(2) = 1.0e-10; // reltol
+scicos_simulate(scs_m, 'nw');  // DDaskr
+ CMSCOPE('set'): Wrong size for block parameter 'Refresh period': 2 exp 
+      ected, getting 50 50 50 50                                        
+--------------------------------------------\
+ Main Modelica : TMPDIR/DDaskr_test2_im.mo
+
+ Flat Modelica : TMPDIR/DDaskr_test2_imf.mo
+ Simulation C code :TMPDIR/DDaskr_test2_im.c
+!Modelica blocks are reduced to a block with:             !
+!                                                         !
+!Number of differential states: 2                         !
+!                                                         !
+!Number of algebraic states: 0                            !
+!                                                         !
+!Number of discrete time states  : 0                      !
+!                                                         !
+!Number of zero-crossing surfaces: 1                      !
+!                                                         !
+!Number of modes  : 0                                     !
+!                                                         !
+!Number of inputs : 0                                     !
+!                                                         !
+!Number of outputs: 3                                     !
+!                                                         !
+!Input/output dependency:[T]                              !
+!                                                         !
+!Analytical Jacobian: enabled  (%Jacobian=%t)             !
+!                                                         !
+!Parameter embedding mode: enabled (%Modelica_ParEmb=%t)  !
+!                                                         !
+!                                                         !
+!                                                         !
+!Generated files path: TMPDIR/         !
+!                                                         !
+!                                                         !
+   Generate a loader file
+   Generate a Makefile
+   ilib_gen_Make: Copy compilation files (Makefile*, libtool...) to TMPDIR
+   ilib_gen_Make: Copy DDaskr_test2_im.c to TMPDIR
+   ilib_gen_Make: configure : Generate Makefile.
+   ilib_gen_Make: Modification of the Makefile in TMPDIR.
+   Running the Makefile
+   Generate a cleaner file
+Shared archive loaded.
+Link done.
+ddaskrval = res.values;         // Results
+time = res.time;                // Time
+// Modify solver + run IDA + save results
+scs_m.props.tol(6) = 100;     // Solver
+scicos_simulate(scs_m, 'nw'); // IDA
+ CMSCOPE('set'): Wrong size for block parameter 'Refresh period': 2 exp 
+      ected, getting 50 50 50 50                                        
+--------------------------------------------\
+ Main Modelica : TMPDIR/DDaskr_test2_im.mo
+
+ Flat Modelica : TMPDIR/DDaskr_test2_imf.mo
+ Simulation C code :TMPDIR/DDaskr_test2_im.c
+!Modelica blocks are reduced to a block with:             !
+!                                                         !
+!Number of differential states: 2                         !
+!                                                         !
+!Number of algebraic states: 0                            !
+!                                                         !
+!Number of discrete time states  : 0                      !
+!                                                         !
+!Number of zero-crossing surfaces: 1                      !
+!                                                         !
+!Number of modes  : 0                                     !
+!                                                         !
+!Number of inputs : 0                                     !
+!                                                         !
+!Number of outputs: 3                                     !
+!                                                         !
+!Input/output dependency:[T]                              !
+!                                                         !
+!Analytical Jacobian: enabled  (%Jacobian=%t)             !
+!                                                         !
+!Parameter embedding mode: enabled (%Modelica_ParEmb=%t)  !
+!                                                         !
+!                                                         !
+!                                                         !
+!Generated files path: TMPDIR/         !
+!                                                         !
+!                                                         !
+   Generate a loader file
+   Generate a Makefile
+   ilib_gen_Make: Copy compilation files (Makefile*, libtool...) to TMPDIR
+   ilib_gen_Make: Copy DDaskr_test2_im.c to TMPDIR
+   ilib_gen_Make: configure : Generate Makefile.
+   ilib_gen_Make: Modification of the Makefile in TMPDIR.
+   Running the Makefile
+   Generate a cleaner file
+Shared archive loaded.
+Link done.
+idaval = res.values;          // Results
+// Compare results
+compa = abs(ddaskrval-idaval);
+// Extract mean, standard deviation, maximum
+mea = mean(compa);
+[maxi, indexMaxi] = max(compa);
+stdeviation = st_deviation(compa);
+// Verifying closeness of the results
+assert_checktrue(maxi <= 10^-(4));
+assert_checktrue(mea <= 10^-(4));
+assert_checktrue(stdeviation <= 10^-(4));
diff --git a/scilab/modules/scicos/tests/unit_tests/DDaskrK_Bouncing.tst b/scilab/modules/scicos/tests/unit_tests/DDaskrK_Bouncing.tst
new file mode 100644 (file)
index 0000000..bfa3a6b
--- /dev/null
@@ -0,0 +1,63 @@
+// =============================================================================
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) 2013 - Scilab Enterprises - Paul Bignier
+//
+//  This file is distributed under the same license as the Scilab package.
+// =============================================================================
+
+// <-- ENGLISH IMPOSED -->
+// <-- XCOS TEST -->
+
+// Import diagram
+assert_checktrue(importXcosDiagram("SCI/modules/xcos/tests/unit_tests/DDaskr_Bouncing_test.zcos"));
+
+// Redefining messagebox() to avoid popup
+prot = funcprot();
+funcprot(0);
+function messagebox(msg, msg_title)
+ disp(msg);
+endfunction
+funcprot(prot);
+
+// looking for the CLOCK_f/EVTDLY_f to update period
+for path_1=1:length(scs_m.objs)
+    if typeof(scs_m.objs(path_1))=="Block" & scs_m.objs(path_1).gui=="CLOCK_f" then
+        CLOCK_f_scs_m = scs_m.objs(path_1).model.rpar;
+        break;
+    end
+end
+for path_2=1:length(CLOCK_f_scs_m)
+    if typeof(CLOCK_f_scs_m.objs(path_2))=="Block" & CLOCK_f_scs_m.objs(path_2).gui=="EVTDLY_f" then
+        EVTDLY_f_blk = CLOCK_f_scs_m.objs(path_2);
+        break;
+    end
+end
+
+// Start by updating the clock block period (sampling)
+scs_m.objs(path_1).model.rpar.objs(path_2).graphics.exprs = [string(5*(10^-3));"0"];
+
+// Modify solver + run DDaskr + save results
+scs_m.props.tol(6) = 102;      // Solver
+//scs_m.props.tol(1) = 1.0e-10; // abstol
+//scs_m.props.tol(2) = 1.0e-10; // reltol
+scicos_simulate(scs_m, 'nw');  // DDaskr
+ddaskrval = res.values;         // Results
+time = res.time;                // Time
+
+// Modify solver + run IDA + save results
+scs_m.props.tol(6) = 100;     // Solver
+scicos_simulate(scs_m, 'nw'); // IDA
+idaval = res.values;          // Results
+
+// Compare results
+compa = abs(ddaskrval-idaval);
+
+// Extract mean, standard deviation, maximum
+mea = mean(compa);
+[maxi, indexMaxi] = max(compa);
+stdeviation = st_deviation(compa);
+
+// Verifying closeness of the results
+assert_checktrue(maxi <= 10^-(4));
+assert_checktrue(mea <= 10^-(4));
+assert_checktrue(stdeviation <= 10^-(4));
diff --git a/scilab/modules/scicos/tests/unit_tests/DDaskrK_ODE.dia.ref b/scilab/modules/scicos/tests/unit_tests/DDaskrK_ODE.dia.ref
new file mode 100644 (file)
index 0000000..b9a8602
--- /dev/null
@@ -0,0 +1,26 @@
+// =============================================================================
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) 2013 - Scilab Enterprises - Paul Bignier
+//
+//  This file is distributed under the same license as the Scilab package.
+// =============================================================================
+// <-- ENGLISH IMPOSED -->
+// <-- XCOS TEST -->
+// Import diagram
+assert_checktrue(importXcosDiagram("SCI/modules/xcos/tests/unit_tests/DoPri_test.zcos"));
+prot = funcprot();
+funcprot(0);
+function message(msg)
+ disp(msg);
+endfunction
+funcprot(prot);
+// Modify solver + run DDaskr + save results
+scs_m.props.tol(6) = 102;       // Solver
+scs_m.props.tol(1) = 1.0e-10;   // abstol
+scs_m.props.tol(2) = 1.0e-10;   // reltol
+ier = execstr('xcos_simulate(scs_m, 4);', 'errcatch'); // Run simulation (LSodar will actually take over DDaskr)
+!Diagram has been compiled for explicit solver  !
+!                                               !
+!switching to explicit Solver                   !
+assert_checkequal(ier, 0);
@@ -4,13 +4,23 @@
 //
 //  This file is distributed under the same license as the Scilab package.
 // =============================================================================
+
 // <-- ENGLISH IMPOSED -->
 // <-- XCOS TEST -->
+
 // Import diagram
 assert_checktrue(importXcosDiagram("SCI/modules/xcos/tests/unit_tests/DoPri_test.zcos"));
+
+prot = funcprot();
+funcprot(0);
+function message(msg)
+ disp(msg);
+endfunction
+funcprot(prot);
+
 // Modify solver + run DDaskr + save results
-scs_m.props.tol(6) = 101;       // Solver
+scs_m.props.tol(6) = 102;       // Solver
 scs_m.props.tol(1) = 1.0e-10;   // abstol
 scs_m.props.tol(2) = 1.0e-10;   // reltol
-ier = execstr('scicos_simulate(scs_m, ''nw'');', 'errcatch'); // Run simulation (LSodar will actually take over DDaskr)
+ier = execstr('xcos_simulate(scs_m, 4);', 'errcatch'); // Run simulation (LSodar will actually take over DDaskr)
 assert_checkequal(ier, 0);
diff --git a/scilab/modules/scicos/tests/unit_tests/DDaskrK_Platform.dia.ref b/scilab/modules/scicos/tests/unit_tests/DDaskrK_Platform.dia.ref
new file mode 100644 (file)
index 0000000..5418040
--- /dev/null
@@ -0,0 +1,227 @@
+// =============================================================================
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) 2013 - Scilab Enterprises - Paul Bignier
+//
+//  This file is distributed under the same license as the Scilab package.
+// =============================================================================
+// <-- ENGLISH IMPOSED -->
+// <-- XCOS TEST -->
+// Import diagram
+loadScicos();
+loadXcosLibs();
+assert_checktrue(importXcosDiagram("SCI/modules/xcos/tests/unit_tests/DDaskr_Platform_test.zcos"));
+// Redefining messagebox() to avoid popup
+prot = funcprot();
+funcprot(0);
+function messagebox(msg, msg_title)
+ disp(msg);
+endfunction
+funcprot(prot);
+// looking for the CLOCK_f/EVTDLY_f to update period
+for path_1=1:length(scs_m.objs)
+    if typeof(scs_m.objs(path_1))=="Block" & scs_m.objs(path_1).gui=="CLOCK_c" then
+        CLOCK_f_scs_m = scs_m.objs(path_1).model.rpar;
+        break;
+    end
+end
+for path_2=1:length(CLOCK_f_scs_m)
+    if typeof(CLOCK_f_scs_m.objs(path_2))=="Block" & CLOCK_f_scs_m.objs(path_2).gui=="EVTDLY_c" then
+        EVTDLY_f_blk = CLOCK_f_scs_m.objs(path_2);
+        break;
+    end
+end
+for i=1:2  // 'max step size' = 10^-i, precision
+    // Start by updating the clock block period (sampling)
+    scs_m.objs(path_1).model.rpar.objs(path_2).graphics.exprs = [string(5*(10^-i));"0"];
+    // Modify solver + run DDaskr + save results
+    scs_m.props.tol(6) = 102;     // Solver
+    scicos_simulate(scs_m, 'nw'); // DDaskr
+    ddaskrval = res.values;       // Results
+    time = res.time;              // Time
+    // Modify solver + run IDA + save results
+    scs_m.props.tol(6) = 100;     // Solver
+    scicos_simulate(scs_m, 'nw'); // IDA
+    idaval = res.values;          // Results
+    // Compare results
+    compa = abs(ddaskrval-idaval);
+    // Extract mean, standard deviation, maximum
+    mea = mean(compa);
+    [maxi, indexMaxi] = max(compa);
+    stdeviation = st_deviation(compa);
+    // Verifying closeness of the results
+    assert_checktrue(maxi <= 10^-(i+1));
+    assert_checktrue(mea <= 10^-(i+1));
+    assert_checktrue(stdeviation <= 10^-(i+1));
+end
+--------------------------------------------\
+ Main Modelica : TMPDIR/DDaskr_Platform_test_im.mo
+
+ Flat Modelica : TMPDIR/DDaskr_Platform_test_imf.mo
+ Simulation C code :TMPDIR/DDaskr_Platform_test_im.c
+!Modelica blocks are reduced to a block with:             !
+!                                                         !
+!Number of differential states: 4                         !
+!                                                         !
+!Number of algebraic states: 0                            !
+!                                                         !
+!Number of discrete time states  : 2                      !
+!                                                         !
+!Number of zero-crossing surfaces: 1                      !
+!                                                         !
+!Number of modes  : 0                                     !
+!                                                         !
+!Number of inputs : 0                                     !
+!                                                         !
+!Number of outputs: 3                                     !
+!                                                         !
+!Input/output dependency:[T]                              !
+!                                                         !
+!Analytical Jacobian: enabled  (%Jacobian=%t)             !
+!                                                         !
+!Parameter embedding mode: enabled (%Modelica_ParEmb=%t)  !
+!                                                         !
+!                                                         !
+!                                                         !
+!Generated files path: TMPDIR/         !
+!                                                         !
+!                                                         !
+   Generate a loader file
+   Generate a Makefile
+   ilib_gen_Make: Copy compilation files (Makefile*, libtool...) to TMPDIR
+   ilib_gen_Make: Copy DDaskr_Platform_test_im.c to TMPDIR
+   ilib_gen_Make: configure : Generate Makefile.
+   ilib_gen_Make: Modification of the Makefile in TMPDIR.
+   Running the Makefile
+   Generate a cleaner file
+Shared archive loaded.
+Link done.
+--------------------------------------------\
+ Main Modelica : TMPDIR/DDaskr_Platform_test_im.mo
+
+ Flat Modelica : TMPDIR/DDaskr_Platform_test_imf.mo
+ Simulation C code :TMPDIR/DDaskr_Platform_test_im.c
+!Modelica blocks are reduced to a block with:             !
+!                                                         !
+!Number of differential states: 4                         !
+!                                                         !
+!Number of algebraic states: 0                            !
+!                                                         !
+!Number of discrete time states  : 2                      !
+!                                                         !
+!Number of zero-crossing surfaces: 1                      !
+!                                                         !
+!Number of modes  : 0                                     !
+!                                                         !
+!Number of inputs : 0                                     !
+!                                                         !
+!Number of outputs: 3                                     !
+!                                                         !
+!Input/output dependency:[T]                              !
+!                                                         !
+!Analytical Jacobian: enabled  (%Jacobian=%t)             !
+!                                                         !
+!Parameter embedding mode: enabled (%Modelica_ParEmb=%t)  !
+!                                                         !
+!                                                         !
+!                                                         !
+!Generated files path: TMPDIR/         !
+!                                                         !
+!                                                         !
+   Generate a loader file
+   Generate a Makefile
+   ilib_gen_Make: Copy compilation files (Makefile*, libtool...) to TMPDIR
+   ilib_gen_Make: Copy DDaskr_Platform_test_im.c to TMPDIR
+   ilib_gen_Make: configure : Generate Makefile.
+   ilib_gen_Make: Modification of the Makefile in TMPDIR.
+   Running the Makefile
+   Generate a cleaner file
+Shared archive loaded.
+Link done.
+--------------------------------------------\
+ Main Modelica : TMPDIR/DDaskr_Platform_test_im.mo
+
+ Flat Modelica : TMPDIR/DDaskr_Platform_test_imf.mo
+ Simulation C code :TMPDIR/DDaskr_Platform_test_im.c
+!Modelica blocks are reduced to a block with:             !
+!                                                         !
+!Number of differential states: 4                         !
+!                                                         !
+!Number of algebraic states: 0                            !
+!                                                         !
+!Number of discrete time states  : 2                      !
+!                                                         !
+!Number of zero-crossing surfaces: 1                      !
+!                                                         !
+!Number of modes  : 0                                     !
+!                                                         !
+!Number of inputs : 0                                     !
+!                                                         !
+!Number of outputs: 3                                     !
+!                                                         !
+!Input/output dependency:[T]                              !
+!                                                         !
+!Analytical Jacobian: enabled  (%Jacobian=%t)             !
+!                                                         !
+!Parameter embedding mode: enabled (%Modelica_ParEmb=%t)  !
+!                                                         !
+!                                                         !
+!                                                         !
+!Generated files path: TMPDIR/         !
+!                                                         !
+!                                                         !
+   Generate a loader file
+   Generate a Makefile
+   ilib_gen_Make: Copy compilation files (Makefile*, libtool...) to TMPDIR
+   ilib_gen_Make: Copy DDaskr_Platform_test_im.c to TMPDIR
+   ilib_gen_Make: configure : Generate Makefile.
+   ilib_gen_Make: Modification of the Makefile in TMPDIR.
+   Running the Makefile
+   Generate a cleaner file
+Shared archive loaded.
+Link done.
+--------------------------------------------\
+ Main Modelica : TMPDIR/DDaskr_Platform_test_im.mo
+
+ Flat Modelica : TMPDIR/DDaskr_Platform_test_imf.mo
+ Simulation C code :TMPDIR/DDaskr_Platform_test_im.c
+!Modelica blocks are reduced to a block with:             !
+!                                                         !
+!Number of differential states: 4                         !
+!                                                         !
+!Number of algebraic states: 0                            !
+!                                                         !
+!Number of discrete time states  : 2                      !
+!                                                         !
+!Number of zero-crossing surfaces: 1                      !
+!                                                         !
+!Number of modes  : 0                                     !
+!                                                         !
+!Number of inputs : 0                                     !
+!                                                         !
+!Number of outputs: 3                                     !
+!                                                         !
+!Input/output dependency:[T]                              !
+!                                                         !
+!Analytical Jacobian: enabled  (%Jacobian=%t)             !
+!                                                         !
+!Parameter embedding mode: enabled (%Modelica_ParEmb=%t)  !
+!                                                         !
+!                                                         !
+!                                                         !
+!Generated files path: TMPDIR/         !
+!                                                         !
+!                                                         !
+   Generate a loader file
+   Generate a Makefile
+   ilib_gen_Make: Copy compilation files (Makefile*, libtool...) to TMPDIR
+   ilib_gen_Make: Copy DDaskr_Platform_test_im.c to TMPDIR
+   ilib_gen_Make: configure : Generate Makefile.
+   ilib_gen_Make: Modification of the Makefile in TMPDIR.
+   Running the Makefile
+   Generate a cleaner file
+Shared archive loaded.
+Link done.
diff --git a/scilab/modules/scicos/tests/unit_tests/DDaskrK_Platform.tst b/scilab/modules/scicos/tests/unit_tests/DDaskrK_Platform.tst
new file mode 100644 (file)
index 0000000..795842f
--- /dev/null
@@ -0,0 +1,67 @@
+// =============================================================================
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) 2013 - Scilab Enterprises - Paul Bignier
+//
+//  This file is distributed under the same license as the Scilab package.
+// =============================================================================
+
+// <-- ENGLISH IMPOSED -->
+// <-- XCOS TEST -->
+
+// Import diagram
+loadScicos();
+loadXcosLibs();
+assert_checktrue(importXcosDiagram("SCI/modules/xcos/tests/unit_tests/DDaskr_Platform_test.zcos"));
+
+// Redefining messagebox() to avoid popup
+prot = funcprot();
+funcprot(0);
+function messagebox(msg, msg_title)
+ disp(msg);
+endfunction
+funcprot(prot);
+
+// looking for the CLOCK_f/EVTDLY_f to update period
+for path_1=1:length(scs_m.objs)
+    if typeof(scs_m.objs(path_1))=="Block" & scs_m.objs(path_1).gui=="CLOCK_c" then
+        CLOCK_f_scs_m = scs_m.objs(path_1).model.rpar;
+        break;
+    end
+end
+for path_2=1:length(CLOCK_f_scs_m)
+    if typeof(CLOCK_f_scs_m.objs(path_2))=="Block" & CLOCK_f_scs_m.objs(path_2).gui=="EVTDLY_c" then
+        EVTDLY_f_blk = CLOCK_f_scs_m.objs(path_2);
+        break;
+    end
+end
+
+for i=1:2  // 'max step size' = 10^-i, precision
+
+    // Start by updating the clock block period (sampling)
+    scs_m.objs(path_1).model.rpar.objs(path_2).graphics.exprs = [string(5*(10^-i));"0"];
+
+    // Modify solver + run DDaskr + save results
+    scs_m.props.tol(6) = 102;     // Solver
+    scicos_simulate(scs_m, 'nw'); // DDaskr
+    ddaskrval = res.values;       // Results
+    time = res.time;              // Time
+
+    // Modify solver + run IDA + save results
+    scs_m.props.tol(6) = 100;     // Solver
+    scicos_simulate(scs_m, 'nw'); // IDA
+    idaval = res.values;          // Results
+
+    // Compare results
+    compa = abs(ddaskrval-idaval);
+
+    // Extract mean, standard deviation, maximum
+    mea = mean(compa);
+    [maxi, indexMaxi] = max(compa);
+    stdeviation = st_deviation(compa);
+
+    // Verifying closeness of the results
+    assert_checktrue(maxi <= 10^-(i+1));
+    assert_checktrue(mea <= 10^-(i+1));
+    assert_checktrue(stdeviation <= 10^-(i+1));
+
+end
diff --git a/scilab/modules/scicos/tests/unit_tests/DDaskrK_RLC.dia.ref b/scilab/modules/scicos/tests/unit_tests/DDaskrK_RLC.dia.ref
new file mode 100644 (file)
index 0000000..516c871
--- /dev/null
@@ -0,0 +1,237 @@
+// =============================================================================
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) 2013 - Scilab Enterprises - Paul Bignier
+//
+//  This file is distributed under the same license as the Scilab package.
+// =============================================================================
+// <-- ENGLISH IMPOSED -->
+// <-- XCOS TEST -->
+// Import diagram
+assert_checktrue(importXcosDiagram("SCI/modules/xcos/tests/unit_tests/DDaskr_RLC_test.zcos"));
+// Redefining messagebox() to avoid popup
+prot = funcprot();
+funcprot(0);
+function messagebox(msg, msg_title)
+ disp(msg);
+endfunction
+funcprot(prot);
+// looking for the CLOCK_f/EVTDLY_f to update period
+for path_1=1:length(scs_m.objs)
+    if typeof(scs_m.objs(path_1))=="Block" & scs_m.objs(path_1).gui=="CLOCK_f" then
+        CLOCK_f_scs_m = scs_m.objs(path_1).model.rpar;
+        break;
+    end
+end
+for path_2=1:length(CLOCK_f_scs_m)
+    if typeof(CLOCK_f_scs_m.objs(path_2))=="Block" & CLOCK_f_scs_m.objs(path_2).gui=="EVTDLY_f" then
+        EVTDLY_f_blk = CLOCK_f_scs_m.objs(path_2);
+        break;
+    end
+end
+for i=2:3
+    // Start by updating the clock block period (sampling)
+    scs_m.objs(path_1).model.rpar.objs(path_2).graphics.exprs = [string(5*(10^-i));"0"];
+    // Modify solver + run DDaskr + save results
+    scs_m.props.tol(6) = 102;     // Solver
+    scicos_simulate(scs_m, 'nw'); // DDaskr
+    ddaskrval = res.values;        // Results
+    time = res.time;               // Time
+    // Modify solver + run IDA + save results
+    scs_m.props.tol(6) = 100;     // Solver
+    scicos_simulate(scs_m, 'nw'); // IDA
+    idaval = res.values;          // Results
+    // Compare results
+    compa = abs(ddaskrval-idaval);
+    // Extract mean, standard deviation, maximum
+    mea = mean(compa);
+    [maxi, indexMaxi] = max(compa);
+    stdeviation = st_deviation(compa);
+    // Verifying closeness of the results
+    assert_checktrue(maxi <= 10^-(i+3));
+    assert_checktrue(mea <= 10^-(i+3));
+    assert_checktrue(stdeviation <= 10^-(i+3));
+end
+ CMSCOPE('set'): Wrong size for block parameter 'Refresh period': 2 exp 
+      ected, getting 2 2 2 2                                            
+--------------------------------------------\
+ Main Modelica : TMPDIR/DDaskr_RLC_test_im.mo
+
+ Flat Modelica : TMPDIR/DDaskr_RLC_test_imf.mo
+ Simulation C code :TMPDIR/DDaskr_RLC_test_im.c
+!Modelica blocks are reduced to a block with:             !
+!                                                         !
+!Number of differential states: 2                         !
+!                                                         !
+!Number of algebraic states: 1                            !
+!                                                         !
+!Number of discrete time states  : 0                      !
+!                                                         !
+!Number of zero-crossing surfaces: 0                      !
+!                                                         !
+!Number of modes  : 0                                     !
+!                                                         !
+!Number of inputs : 0                                     !
+!                                                         !
+!Number of outputs: 3                                     !
+!                                                         !
+!Input/output dependency:[T]                              !
+!                                                         !
+!Analytical Jacobian: enabled  (%Jacobian=%t)             !
+!                                                         !
+!Parameter embedding mode: enabled (%Modelica_ParEmb=%t)  !
+!                                                         !
+!                                                         !
+!                                                         !
+!Generated files path: TMPDIR/         !
+!                                                         !
+!                                                         !
+   Generate a loader file
+   Generate a Makefile
+   ilib_gen_Make: Copy compilation files (Makefile*, libtool...) to TMPDIR
+   ilib_gen_Make: Copy DDaskr_RLC_test_im.c to TMPDIR
+   ilib_gen_Make: configure : Generate Makefile.
+   ilib_gen_Make: Modification of the Makefile in TMPDIR.
+   Running the Makefile
+   Generate a cleaner file
+Shared archive loaded.
+Link done.
+ CMSCOPE('set'): Wrong size for block parameter 'Refresh period': 2 exp 
+      ected, getting 2 2 2 2                                            
+--------------------------------------------\
+ Main Modelica : TMPDIR/DDaskr_RLC_test_im.mo
+
+ Flat Modelica : TMPDIR/DDaskr_RLC_test_imf.mo
+ Simulation C code :TMPDIR/DDaskr_RLC_test_im.c
+!Modelica blocks are reduced to a block with:             !
+!                                                         !
+!Number of differential states: 2                         !
+!                                                         !
+!Number of algebraic states: 1                            !
+!                                                         !
+!Number of discrete time states  : 0                      !
+!                                                         !
+!Number of zero-crossing surfaces: 0                      !
+!                                                         !
+!Number of modes  : 0                                     !
+!                                                         !
+!Number of inputs : 0                                     !
+!                                                         !
+!Number of outputs: 3                                     !
+!                                                         !
+!Input/output dependency:[T]                              !
+!                                                         !
+!Analytical Jacobian: enabled  (%Jacobian=%t)             !
+!                                                         !
+!Parameter embedding mode: enabled (%Modelica_ParEmb=%t)  !
+!                                                         !
+!                                                         !
+!                                                         !
+!Generated files path: TMPDIR/         !
+!                                                         !
+!                                                         !
+   Generate a loader file
+   Generate a Makefile
+   ilib_gen_Make: Copy compilation files (Makefile*, libtool...) to TMPDIR
+   ilib_gen_Make: Copy DDaskr_RLC_test_im.c to TMPDIR
+   ilib_gen_Make: configure : Generate Makefile.
+   ilib_gen_Make: Modification of the Makefile in TMPDIR.
+   Running the Makefile
+   Generate a cleaner file
+Shared archive loaded.
+Link done.
+ CMSCOPE('set'): Wrong size for block parameter 'Refresh period': 2 exp 
+      ected, getting 2 2 2 2                                            
+--------------------------------------------\
+ Main Modelica : TMPDIR/DDaskr_RLC_test_im.mo
+
+ Flat Modelica : TMPDIR/DDaskr_RLC_test_imf.mo
+ Simulation C code :TMPDIR/DDaskr_RLC_test_im.c
+!Modelica blocks are reduced to a block with:             !
+!                                                         !
+!Number of differential states: 2                         !
+!                                                         !
+!Number of algebraic states: 1                            !
+!                                                         !
+!Number of discrete time states  : 0                      !
+!                                                         !
+!Number of zero-crossing surfaces: 0                      !
+!                                                         !
+!Number of modes  : 0                                     !
+!                                                         !
+!Number of inputs : 0                                     !
+!                                                         !
+!Number of outputs: 3                                     !
+!                                                         !
+!Input/output dependency:[T]                              !
+!                                                         !
+!Analytical Jacobian: enabled  (%Jacobian=%t)             !
+!                                                         !
+!Parameter embedding mode: enabled (%Modelica_ParEmb=%t)  !
+!                                                         !
+!                                                         !
+!                                                         !
+!Generated files path: TMPDIR/         !
+!                                                         !
+!                                                         !
+   Generate a loader file
+   Generate a Makefile
+   ilib_gen_Make: Copy compilation files (Makefile*, libtool...) to TMPDIR
+   ilib_gen_Make: Copy DDaskr_RLC_test_im.c to TMPDIR
+   ilib_gen_Make: configure : Generate Makefile.
+   ilib_gen_Make: Modification of the Makefile in TMPDIR.
+   Running the Makefile
+   Generate a cleaner file
+Shared archive loaded.
+Link done.
+ CMSCOPE('set'): Wrong size for block parameter 'Refresh period': 2 exp 
+      ected, getting 2 2 2 2                                            
+--------------------------------------------\
+ Main Modelica : TMPDIR/DDaskr_RLC_test_im.mo
+
+ Flat Modelica : TMPDIR/DDaskr_RLC_test_imf.mo
+ Simulation C code :TMPDIR/DDaskr_RLC_test_im.c
+!Modelica blocks are reduced to a block with:             !
+!                                                         !
+!Number of differential states: 2                         !
+!                                                         !
+!Number of algebraic states: 1                            !
+!                                                         !
+!Number of discrete time states  : 0                      !
+!                                                         !
+!Number of zero-crossing surfaces: 0                      !
+!                                                         !
+!Number of modes  : 0                                     !
+!                                                         !
+!Number of inputs : 0                                     !
+!                                                         !
+!Number of outputs: 3                                     !
+!                                                         !
+!Input/output dependency:[T]                              !
+!                                                         !
+!Analytical Jacobian: enabled  (%Jacobian=%t)             !
+!                                                         !
+!Parameter embedding mode: enabled (%Modelica_ParEmb=%t)  !
+!                                                         !
+!                                                         !
+!                                                         !
+!Generated files path: TMPDIR/         !
+!                                                         !
+!                                                         !
+   Generate a loader file
+   Generate a Makefile
+   ilib_gen_Make: Copy compilation files (Makefile*, libtool...) to TMPDIR
+   ilib_gen_Make: Copy DDaskr_RLC_test_im.c to TMPDIR
+   ilib_gen_Make: configure : Generate Makefile.
+   ilib_gen_Make: Modification of the Makefile in TMPDIR.
+   Running the Makefile
+   Generate a cleaner file
+Shared archive loaded.
+Link done.
diff --git a/scilab/modules/scicos/tests/unit_tests/DDaskrK_RLC.tst b/scilab/modules/scicos/tests/unit_tests/DDaskrK_RLC.tst
new file mode 100644 (file)
index 0000000..c55fd92
--- /dev/null
@@ -0,0 +1,66 @@
+// =============================================================================
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) 2013 - Scilab Enterprises - Paul Bignier
+//
+//  This file is distributed under the same license as the Scilab package.
+// =============================================================================
+
+// <-- ENGLISH IMPOSED -->
+// <-- XCOS TEST -->
+
+// Import diagram
+assert_checktrue(importXcosDiagram("SCI/modules/xcos/tests/unit_tests/DDaskr_RLC_test.zcos"));
+
+// Redefining messagebox() to avoid popup
+prot = funcprot();
+funcprot(0);
+function messagebox(msg, msg_title)
+ disp(msg);
+endfunction
+funcprot(prot);
+
+// looking for the CLOCK_f/EVTDLY_f to update period
+for path_1=1:length(scs_m.objs)
+    if typeof(scs_m.objs(path_1))=="Block" & scs_m.objs(path_1).gui=="CLOCK_f" then
+        CLOCK_f_scs_m = scs_m.objs(path_1).model.rpar;
+        break;
+    end
+end
+for path_2=1:length(CLOCK_f_scs_m)
+    if typeof(CLOCK_f_scs_m.objs(path_2))=="Block" & CLOCK_f_scs_m.objs(path_2).gui=="EVTDLY_f" then
+        EVTDLY_f_blk = CLOCK_f_scs_m.objs(path_2);
+        break;
+    end
+end
+
+
+
+for i=2:3
+
+    // Start by updating the clock block period (sampling)
+    scs_m.objs(path_1).model.rpar.objs(path_2).graphics.exprs = [string(5*(10^-i));"0"];
+
+    // Modify solver + run DDaskr + save results
+    scs_m.props.tol(6) = 102;     // Solver
+    scicos_simulate(scs_m, 'nw'); // DDaskr
+    ddaskrval = res.values;        // Results
+    time = res.time;               // Time
+
+    // Modify solver + run IDA + save results
+    scs_m.props.tol(6) = 100;     // Solver
+    scicos_simulate(scs_m, 'nw'); // IDA
+    idaval = res.values;          // Results
+
+    // Compare results
+    compa = abs(ddaskrval-idaval);
+
+    // Extract mean, standard deviation, maximum
+    mea = mean(compa);
+    [maxi, indexMaxi] = max(compa);
+    stdeviation = st_deviation(compa);
+
+    // Verifying closeness of the results
+    assert_checktrue(maxi <= 10^-(i+3));
+    assert_checktrue(mea <= 10^-(i+3));
+    assert_checktrue(stdeviation <= 10^-(i+3));
+end
@@ -31,10 +31,10 @@ end
 // Start by updating the clock block period (sampling)
 scs_m.objs(path_1).model.rpar.objs(path_2).graphics.exprs = [string(5*(10^-3));"0"];
 // Modify solver + run DDaskr + save results
-scs_m.props.tol(6) = 101;       // Solver
+scs_m.props.tol(6) = 101;      // Solver
 //scs_m.props.tol(1) = 1.0e-10; // abstol
 //scs_m.props.tol(2) = 1.0e-10; // reltol
-scicos_simulate(scs_m, 'nw');   // DDaskr
+scicos_simulate(scs_m, 'nw');  // DDaskr
  
  CMSCOPE('set'): Wrong size for block parameter 'Refresh period': 2 exp 
       ected, getting 50 50 50 50                                        
@@ -68,7 +68,7 @@ scicos_simulate(scs_m, 'nw');   // DDaskr
 !                                                         !
 !                                                         !
 !                                                         !
-!Generated files path: TMPDIR/         !
+!Generated files path: TMPDIR/          !
 !                                                         !
 !                                                         !
    Generate a loader file
@@ -84,8 +84,8 @@ Link done.
 ddaskrval = res.values;         // Results
 time = res.time;                // Time
 // Modify solver + run IDA + save results
-scs_m.props.tol(6) = 100;       // Solver
-scicos_simulate(scs_m, 'nw');   // IDA
+scs_m.props.tol(6) = 100;     // Solver
+scicos_simulate(scs_m, 'nw'); // IDA
  
  CMSCOPE('set'): Wrong size for block parameter 'Refresh period': 2 exp 
       ected, getting 50 50 50 50                                        
@@ -119,7 +119,7 @@ scicos_simulate(scs_m, 'nw');   // IDA
 !                                                         !
 !                                                         !
 !                                                         !
-!Generated files path: TMPDIR/         !
+!Generated files path: TMPDIR/          !
 !                                                         !
 !                                                         !
    Generate a loader file
@@ -132,7 +132,7 @@ scicos_simulate(scs_m, 'nw');   // IDA
    Generate a cleaner file
 Shared archive loaded.
 Link done.
-idaval = res.values;            // Results
+idaval = res.values;          // Results
 // Compare results
 compa = abs(ddaskrval-idaval);
 // Extract mean, standard deviation, maximum
@@ -37,17 +37,17 @@ end
 scs_m.objs(path_1).model.rpar.objs(path_2).graphics.exprs = [string(5*(10^-3));"0"];
 
 // Modify solver + run DDaskr + save results
-scs_m.props.tol(6) = 101;       // Solver
+scs_m.props.tol(6) = 101;      // Solver
 //scs_m.props.tol(1) = 1.0e-10; // abstol
 //scs_m.props.tol(2) = 1.0e-10; // reltol
-scicos_simulate(scs_m, 'nw');   // DDaskr
+scicos_simulate(scs_m, 'nw');  // DDaskr
 ddaskrval = res.values;         // Results
 time = res.time;                // Time
 
 // Modify solver + run IDA + save results
-scs_m.props.tol(6) = 100;       // Solver
-scicos_simulate(scs_m, 'nw');   // IDA
-idaval = res.values;            // Results
+scs_m.props.tol(6) = 100;     // Solver
+scicos_simulate(scs_m, 'nw'); // IDA
+idaval = res.values;          // Results
 
 // Compare results
 compa = abs(ddaskrval-idaval);
@@ -61,4 +61,3 @@ stdeviation = st_deviation(compa);
 assert_checktrue(maxi <= 10^-(12));
 assert_checktrue(mea <= 10^-(12));
 assert_checktrue(stdeviation <= 10^-(12));
-
diff --git a/scilab/modules/scicos/tests/unit_tests/DDaskrN_ODE.dia.ref b/scilab/modules/scicos/tests/unit_tests/DDaskrN_ODE.dia.ref
new file mode 100644 (file)
index 0000000..889e980
--- /dev/null
@@ -0,0 +1,26 @@
+// =============================================================================
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) 2013 - Scilab Enterprises - Paul Bignier
+//
+//  This file is distributed under the same license as the Scilab package.
+// =============================================================================
+// <-- ENGLISH IMPOSED -->
+// <-- XCOS TEST -->
+// Import diagram
+assert_checktrue(importXcosDiagram("SCI/modules/xcos/tests/unit_tests/DoPri_test.zcos"));
+prot = funcprot();
+funcprot(0);
+function message(msg)
+ disp(msg);
+endfunction
+funcprot(prot);
+// Modify solver + run DDaskr + save results
+scs_m.props.tol(6) = 101;       // Solver
+scs_m.props.tol(1) = 1.0e-10;   // abstol
+scs_m.props.tol(2) = 1.0e-10;   // reltol
+ier = execstr('xcos_simulate(scs_m, 4);', 'errcatch'); // Run simulation (LSodar will actually take over DDaskr)
+!Diagram has been compiled for explicit solver  !
+!                                               !
+!switching to explicit Solver                   !
+assert_checkequal(ier, 0);
 // Import diagram
 assert_checktrue(importXcosDiagram("SCI/modules/xcos/tests/unit_tests/DoPri_test.zcos"));
 
+prot = funcprot();
+funcprot(0);
+function message(msg)
+ disp(msg);
+endfunction
+funcprot(prot);
+
 // Modify solver + run DDaskr + save results
 scs_m.props.tol(6) = 101;       // Solver
 scs_m.props.tol(1) = 1.0e-10;   // abstol
 scs_m.props.tol(2) = 1.0e-10;   // reltol
-ier = execstr('scicos_simulate(scs_m, ''nw'');', 'errcatch'); // Run simulation (LSodar will actually take over DDaskr)
+ier = execstr('xcos_simulate(scs_m, 4);', 'errcatch'); // Run simulation (LSodar will actually take over DDaskr)
 assert_checkequal(ier, 0);
diff --git a/scilab/modules/scicos/tests/unit_tests/DDaskrN_Platform.dia.ref b/scilab/modules/scicos/tests/unit_tests/DDaskrN_Platform.dia.ref
new file mode 100644 (file)
index 0000000..51fded6
--- /dev/null
@@ -0,0 +1,313 @@
+// =============================================================================
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) 2013 - Scilab Enterprises - Paul Bignier
+//
+//  This file is distributed under the same license as the Scilab package.
+// =============================================================================
+// <-- ENGLISH IMPOSED -->
+// <-- XCOS TEST -->
+// Import diagram
+loadScicos();
+loadXcosLibs();
+assert_checktrue(importXcosDiagram("SCI/modules/xcos/tests/unit_tests/DDaskr_Platform_test.zcos"));
+// Redefining messagebox() to avoid popup
+prot = funcprot();
+funcprot(0);
+function messagebox(msg, msg_title)
+ disp(msg);
+endfunction
+funcprot(prot);
+// looking for the CLOCK_f/EVTDLY_f to update period
+for path_1=1:length(scs_m.objs)
+    if typeof(scs_m.objs(path_1))=="Block" & scs_m.objs(path_1).gui=="CLOCK_c" then
+        CLOCK_f_scs_m = scs_m.objs(path_1).model.rpar;
+        break;
+    end
+end
+for path_2=1:length(CLOCK_f_scs_m)
+    if typeof(CLOCK_f_scs_m.objs(path_2))=="Block" & CLOCK_f_scs_m.objs(path_2).gui=="EVTDLY_c" then
+        EVTDLY_f_blk = CLOCK_f_scs_m.objs(path_2);
+        break;
+    end
+end
+for i=1:3  // 'max step size' = 10^-i, precision
+    // Start by updating the clock block period (sampling)
+    scs_m.objs(path_1).model.rpar.objs(path_2).graphics.exprs = [string(5*(10^-i));"0"];
+    // Modify solver + run DDaskr + save results
+    scs_m.props.tol(6) = 101;     // Solver
+    scicos_simulate(scs_m, 'nw'); // DDaskr
+    ddaskrval = res.values;       // Results
+    time = res.time;              // Time
+    // Modify solver + run IDA + save results
+    scs_m.props.tol(6) = 100;     // Solver
+    scicos_simulate(scs_m, 'nw'); // IDA
+    idaval = res.values;          // Results
+    // Compare results
+    compa = abs(ddaskrval-idaval);
+    // Extract mean, standard deviation, maximum
+    mea = mean(compa);
+    [maxi, indexMaxi] = max(compa);
+    stdeviation = st_deviation(compa);
+    // Verifying closeness of the results
+    assert_checktrue(maxi <= 10^-(i+3));
+    assert_checktrue(mea <= 10^-(i+3));
+    assert_checktrue(stdeviation <= 10^-(i+3));
+end
+--------------------------------------------\
+ Main Modelica : TMPDIR/DDaskr_Platform_test_im.mo
+
+ Flat Modelica : TMPDIR/DDaskr_Platform_test_imf.mo
+ Simulation C code :TMPDIR/DDaskr_Platform_test_im.c
+!Modelica blocks are reduced to a block with:             !
+!                                                         !
+!Number of differential states: 4                         !
+!                                                         !
+!Number of algebraic states: 0                            !
+!                                                         !
+!Number of discrete time states  : 2                      !
+!                                                         !
+!Number of zero-crossing surfaces: 1                      !
+!                                                         !
+!Number of modes  : 0                                     !
+!                                                         !
+!Number of inputs : 0                                     !
+!                                                         !
+!Number of outputs: 3                                     !
+!                                                         !
+!Input/output dependency:[T]                              !
+!                                                         !
+!Analytical Jacobian: enabled  (%Jacobian=%t)             !
+!                                                         !
+!Parameter embedding mode: enabled (%Modelica_ParEmb=%t)  !
+!                                                         !
+!                                                         !
+!                                                         !
+!Generated files path: TMPDIR/          !
+!                                                         !
+!                                                         !
+   Generate a loader file
+   Generate a Makefile
+   ilib_gen_Make: Copy compilation files (Makefile*, libtool...) to TMPDIR
+   ilib_gen_Make: Copy DDaskr_Platform_test_im.c to TMPDIR
+   ilib_gen_Make: configure : Generate Makefile.
+   ilib_gen_Make: Modification of the Makefile in TMPDIR.
+   Running the Makefile
+   Generate a cleaner file
+Shared archive loaded.
+Link done.
+--------------------------------------------\
+ Main Modelica : TMPDIR/DDaskr_Platform_test_im.mo
+
+ Flat Modelica : TMPDIR/DDaskr_Platform_test_imf.mo
+ Simulation C code :TMPDIR/DDaskr_Platform_test_im.c
+!Modelica blocks are reduced to a block with:             !
+!                                                         !
+!Number of differential states: 4                         !
+!                                                         !
+!Number of algebraic states: 0                            !
+!                                                         !
+!Number of discrete time states  : 2                      !
+!                                                         !
+!Number of zero-crossing surfaces: 1                      !
+!                                                         !
+!Number of modes  : 0                                     !
+!                                                         !
+!Number of inputs : 0                                     !
+!                                                         !
+!Number of outputs: 3                                     !
+!                                                         !
+!Input/output dependency:[T]                              !
+!                                                         !
+!Analytical Jacobian: enabled  (%Jacobian=%t)             !
+!                                                         !
+!Parameter embedding mode: enabled (%Modelica_ParEmb=%t)  !
+!                                                         !
+!                                                         !
+!                                                         !
+!Generated files path: TMPDIR/          !
+!                                                         !
+!                                                         !
+   Generate a loader file
+   Generate a Makefile
+   ilib_gen_Make: Copy compilation files (Makefile*, libtool...) to TMPDIR
+   ilib_gen_Make: Copy DDaskr_Platform_test_im.c to TMPDIR
+   ilib_gen_Make: configure : Generate Makefile.
+   ilib_gen_Make: Modification of the Makefile in TMPDIR.
+   Running the Makefile
+   Generate a cleaner file
+Shared archive loaded.
+Link done.
+--------------------------------------------\
+ Main Modelica : TMPDIR/DDaskr_Platform_test_im.mo
+
+ Flat Modelica : TMPDIR/DDaskr_Platform_test_imf.mo
+ Simulation C code :TMPDIR/DDaskr_Platform_test_im.c
+!Modelica blocks are reduced to a block with:             !
+!                                                         !
+!Number of differential states: 4                         !
+!                                                         !
+!Number of algebraic states: 0                            !
+!                                                         !
+!Number of discrete time states  : 2                      !
+!                                                         !
+!Number of zero-crossing surfaces: 1                      !
+!                                                         !
+!Number of modes  : 0                                     !
+!                                                         !
+!Number of inputs : 0                                     !
+!                                                         !
+!Number of outputs: 3                                     !
+!                                                         !
+!Input/output dependency:[T]                              !
+!                                                         !
+!Analytical Jacobian: enabled  (%Jacobian=%t)             !
+!                                                         !
+!Parameter embedding mode: enabled (%Modelica_ParEmb=%t)  !
+!                                                         !
+!                                                         !
+!                                                         !
+!Generated files path: TMPDIR/          !
+!                                                         !
+!                                                         !
+   Generate a loader file
+   Generate a Makefile
+   ilib_gen_Make: Copy compilation files (Makefile*, libtool...) to TMPDIR
+   ilib_gen_Make: Copy DDaskr_Platform_test_im.c to TMPDIR
+   ilib_gen_Make: configure : Generate Makefile.
+   ilib_gen_Make: Modification of the Makefile in TMPDIR.
+   Running the Makefile
+   Generate a cleaner file
+Shared archive loaded.
+Link done.
+--------------------------------------------\
+ Main Modelica : TMPDIR/DDaskr_Platform_test_im.mo
+
+ Flat Modelica : TMPDIR/DDaskr_Platform_test_imf.mo
+ Simulation C code :TMPDIR/DDaskr_Platform_test_im.c
+!Modelica blocks are reduced to a block with:             !
+!                                                         !
+!Number of differential states: 4                         !
+!                                                         !
+!Number of algebraic states: 0                            !
+!                                                         !
+!Number of discrete time states  : 2                      !
+!                                                         !
+!Number of zero-crossing surfaces: 1                      !
+!                                                         !
+!Number of modes  : 0                                     !
+!                                                         !
+!Number of inputs : 0                                     !
+!                                                         !
+!Number of outputs: 3                                     !
+!                                                         !
+!Input/output dependency:[T]                              !
+!                                                         !
+!Analytical Jacobian: enabled  (%Jacobian=%t)             !
+!                                                         !
+!Parameter embedding mode: enabled (%Modelica_ParEmb=%t)  !
+!                                                         !
+!                                                         !
+!                                                         !
+!Generated files path: TMPDIR/          !
+!                                                         !
+!                                                         !
+   Generate a loader file
+   Generate a Makefile
+   ilib_gen_Make: Copy compilation files (Makefile*, libtool...) to TMPDIR
+   ilib_gen_Make: Copy DDaskr_Platform_test_im.c to TMPDIR
+   ilib_gen_Make: configure : Generate Makefile.
+   ilib_gen_Make: Modification of the Makefile in TMPDIR.
+   Running the Makefile
+   Generate a cleaner file
+Shared archive loaded.
+Link done.
+--------------------------------------------\
+ Main Modelica : TMPDIR/DDaskr_Platform_test_im.mo
+
+ Flat Modelica : TMPDIR/DDaskr_Platform_test_imf.mo
+ Simulation C code :TMPDIR/DDaskr_Platform_test_im.c
+!Modelica blocks are reduced to a block with:             !
+!                                                         !
+!Number of differential states: 4                         !
+!                                                         !
+!Number of algebraic states: 0                            !
+!                                                         !
+!Number of discrete time states  : 2                      !
+!                                                         !
+!Number of zero-crossing surfaces: 1                      !
+!                                                         !
+!Number of modes  : 0                                     !
+!                                                         !
+!Number of inputs : 0                                     !
+!                                                         !
+!Number of outputs: 3                                     !
+!                                                         !
+!Input/output dependency:[T]                              !
+!                                                         !
+!Analytical Jacobian: enabled  (%Jacobian=%t)             !
+!                                                         !
+!Parameter embedding mode: enabled (%Modelica_ParEmb=%t)  !
+!                                                         !
+!                                                         !
+!                                                         !
+!Generated files path: TMPDIR/          !
+!                                                         !
+!                                                         !
+   Generate a loader file
+   Generate a Makefile
+   ilib_gen_Make: Copy compilation files (Makefile*, libtool...) to TMPDIR
+   ilib_gen_Make: Copy DDaskr_Platform_test_im.c to TMPDIR
+   ilib_gen_Make: configure : Generate Makefile.
+   ilib_gen_Make: Modification of the Makefile in TMPDIR.
+   Running the Makefile
+   Generate a cleaner file
+Shared archive loaded.
+Link done.
+--------------------------------------------\
+ Main Modelica : TMPDIR/DDaskr_Platform_test_im.mo
+
+ Flat Modelica : TMPDIR/DDaskr_Platform_test_imf.mo
+ Simulation C code :TMPDIR/DDaskr_Platform_test_im.c
+!Modelica blocks are reduced to a block with:             !
+!                                                         !
+!Number of differential states: 4                         !
+!                                                         !
+!Number of algebraic states: 0                            !
+!                                                         !
+!Number of discrete time states  : 2                      !
+!                                                         !
+!Number of zero-crossing surfaces: 1                      !
+!                                                         !
+!Number of modes  : 0                                     !
+!                                                         !
+!Number of inputs : 0                                     !
+!                                                         !
+!Number of outputs: 3                                     !
+!                                                         !
+!Input/output dependency:[T]                              !
+!                                                         !
+!Analytical Jacobian: enabled  (%Jacobian=%t)             !
+!                                                         !
+!Parameter embedding mode: enabled (%Modelica_ParEmb=%t)  !
+!                                                         !
+!                                                         !
+!                                                         !
+!Generated files path: TMPDIR/          !
+!                                                         !
+!                                                         !
+   Generate a loader file
+   Generate a Makefile
+   ilib_gen_Make: Copy compilation files (Makefile*, libtool...) to TMPDIR
+   ilib_gen_Make: Copy DDaskr_Platform_test_im.c to TMPDIR
+   ilib_gen_Make: configure : Generate Makefile.
+   ilib_gen_Make: Modification of the Makefile in TMPDIR.
+   Running the Makefile
+   Generate a cleaner file
+Shared archive loaded.
+Link done.
diff --git a/scilab/modules/scicos/tests/unit_tests/DDaskrN_Platform.tst b/scilab/modules/scicos/tests/unit_tests/DDaskrN_Platform.tst
new file mode 100644 (file)
index 0000000..fecd6c2
--- /dev/null
@@ -0,0 +1,67 @@
+// =============================================================================
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) 2013 - Scilab Enterprises - Paul Bignier
+//
+//  This file is distributed under the same license as the Scilab package.
+// =============================================================================
+
+// <-- ENGLISH IMPOSED -->
+// <-- XCOS TEST -->
+
+// Import diagram
+loadScicos();
+loadXcosLibs();
+assert_checktrue(importXcosDiagram("SCI/modules/xcos/tests/unit_tests/DDaskr_Platform_test.zcos"));
+
+// Redefining messagebox() to avoid popup
+prot = funcprot();
+funcprot(0);
+function messagebox(msg, msg_title)
+ disp(msg);
+endfunction
+funcprot(prot);
+
+// looking for the CLOCK_f/EVTDLY_f to update period
+for path_1=1:length(scs_m.objs)
+    if typeof(scs_m.objs(path_1))=="Block" & scs_m.objs(path_1).gui=="CLOCK_c" then
+        CLOCK_f_scs_m = scs_m.objs(path_1).model.rpar;
+        break;
+    end
+end
+for path_2=1:length(CLOCK_f_scs_m)
+    if typeof(CLOCK_f_scs_m.objs(path_2))=="Block" & CLOCK_f_scs_m.objs(path_2).gui=="EVTDLY_c" then
+        EVTDLY_f_blk = CLOCK_f_scs_m.objs(path_2);
+        break;
+    end
+end
+
+for i=1:3  // 'max step size' = 10^-i, precision
+
+    // Start by updating the clock block period (sampling)
+    scs_m.objs(path_1).model.rpar.objs(path_2).graphics.exprs = [string(5*(10^-i));"0"];
+
+    // Modify solver + run DDaskr + save results
+    scs_m.props.tol(6) = 101;     // Solver
+    scicos_simulate(scs_m, 'nw'); // DDaskr
+    ddaskrval = res.values;       // Results
+    time = res.time;              // Time
+
+    // Modify solver + run IDA + save results
+    scs_m.props.tol(6) = 100;     // Solver
+    scicos_simulate(scs_m, 'nw'); // IDA
+    idaval = res.values;          // Results
+
+    // Compare results
+    compa = abs(ddaskrval-idaval);
+
+    // Extract mean, standard deviation, maximum
+    mea = mean(compa);
+    [maxi, indexMaxi] = max(compa);
+    stdeviation = st_deviation(compa);
+
+    // Verifying closeness of the results
+    assert_checktrue(maxi <= 10^-(i+3));
+    assert_checktrue(mea <= 10^-(i+3));
+    assert_checktrue(stdeviation <= 10^-(i+3));
+
+end
@@ -32,14 +32,14 @@ for i=2:3
     // Start by updating the clock block period (sampling)
     scs_m.objs(path_1).model.rpar.objs(path_2).graphics.exprs = [string(5*(10^-i));"0"];
     // Modify solver + run DDaskr + save results
-    scs_m.props.tol(6) = 101;           // Solver
-    scicos_simulate(scs_m, 'nw');       // DDaskr
-    ddaskrval = res.values;             // Results
-    time = res.time;                    // Time
+    scs_m.props.tol(6) = 101;     // Solver
+    scicos_simulate(scs_m, 'nw'); // DDaskr
+    ddaskrval = res.values;        // Results
+    time = res.time;               // Time
     // Modify solver + run IDA + save results
-    scs_m.props.tol(6) = 100;           // Solver
-    scicos_simulate(scs_m, 'nw');       // DDaskr
-    idaval = res.values;                // Results
+    scs_m.props.tol(6) = 100;     // Solver
+    scicos_simulate(scs_m, 'nw'); // IDA
+    idaval = res.values;          // Results
     // Compare results
     compa = abs(ddaskrval-idaval);
     // Extract mean, standard deviation, maximum
@@ -41,15 +41,15 @@ for i=2:3
     scs_m.objs(path_1).model.rpar.objs(path_2).graphics.exprs = [string(5*(10^-i));"0"];
 
     // Modify solver + run DDaskr + save results
-    scs_m.props.tol(6) = 101;           // Solver
-    scicos_simulate(scs_m, 'nw');       // DDaskr
-    ddaskrval = res.values;             // Results
-    time = res.time;                    // Time
+    scs_m.props.tol(6) = 101;     // Solver
+    scicos_simulate(scs_m, 'nw'); // DDaskr
+    ddaskrval = res.values;        // Results
+    time = res.time;               // Time
 
     // Modify solver + run IDA + save results
-    scs_m.props.tol(6) = 100;           // Solver
-    scicos_simulate(scs_m, 'nw');       // DDaskr
-    idaval = res.values;                // Results
+    scs_m.props.tol(6) = 100;     // Solver
+    scicos_simulate(scs_m, 'nw'); // IDA
+    idaval = res.values;          // Results
 
     // Compare results
     compa = abs(ddaskrval-idaval);
@@ -64,4 +64,3 @@ for i=2:3
     assert_checktrue(mea <= 10^-(i+4));
     assert_checktrue(stdeviation <= 10^-(i+4));
 end
-
@@ -3,12 +3,10 @@
 //
 // This file is released under the 3-clause BSD license. See COPYING-BSD.
 
-// Run with exec("SCI/modules/xcos/examples/solvers/benchDDaskr_Bouncing.sce");
-
 // Import the diagram, modify parameters, augment the ending time and store its compilation in Info()
 loadScicos();
 loadXcosLibs();
-importXcosDiagram("SCI/modules/xcos/demos/ModelicaBlocks/BouncingBall_Modelica.xcos");
+importXcosDiagram("SCI/modules/xcos/demos/ModelicaBlocks/BouncingBall_Modelica.zcos");
 scs_m.objs(3).graphics.exprs.paramv(1) = 0.15; // Gravity
 scs_m.objs(3).graphics.exprs.paramv(2) = 0.99; // Floor stickiness
 Info = scicos_simulate(scs_m, "nw");
@@ -24,10 +22,10 @@ function messagebox(msg, title)
     disp(msg);
 endfunction
 
-solverName = ["IDA", "DDaskr"];
+solverName = ["IDA" "DDaskr - Newton" "DDaskr - GMRes"];
 
 disp("--------------------------------");
-for solver = 0:1
+for solver = 0:2
 
     disp("Time for " + solverName(solver + 1) + ":");
     tolerances(6) = solver+100;
index 2dcc70b..1b76302 100644 (file)
@@ -644,7 +644,7 @@ Time for implicit Runge-Kutta:
             Example: a bouncing ball.
         </para>
         <para>
-            <link type="scilab" linkend="scilab.xcos/xcos/demos/ModelicaBlocks/BouncingBall_Modelica.zcos">
+            <link type="scilab" linkend="scilab.zcos/xcos/demos/ModelicaBlocks/BouncingBall_Modelica.zcos">
                 <inlinemediaobject>
                     <imageobject>
                         <imagedata align="center" fileref="../../../demos/ModelicaBlocks/BouncingBall_Modelica.zcos" valign="middle"/>
@@ -665,8 +665,8 @@ try xcos_simulate(scs_m, 4); catch disp(lasterror()); end
 ]]></scilab:image>
         </para>
         <para>
-            In the following script, we compare the time difference between the solvers by running the example with the two solvers in turn:
-            <link type="scilab" linkend ="scilab.scinotes/xcos/examples/solvers/benchDDaskr_Bouncing.sce">
+            In the following script, we compare the time difference between the solvers by running the example with the three solvers in turn:
+            <link type="scilab" linkend ="scilab.scinotes/xcos/examples/solvers/benchBouncing.sce">
                 Open the script
             </link>
         </para>
@@ -676,18 +676,24 @@ try xcos_simulate(scs_m, 4); catch disp(lasterror()); end
 Time for IDA:
  7.5
 
-Time for DDaskr:
+Time for DDaskr - Newton:
  5.4
+
+Time for DDaskr - GMRes:
+ 10.2
             ]]></screen>
         </para>
         <para>
-            This result shows that on a stiff problem, with rootfinding and for same precision required, <emphasis>DDaskr</emphasis> is fastest.
+            This result shows that on a stiff problem, with rootfinding and for same precision required, <emphasis>DDaskr - Newton</emphasis> is fastest.
         </para>
         <para>
             The difference in time is attributed to the powerful implementation of DDaskr and its least error control.
         </para>
         <para>
-            From the result, we can extract the speed factor:
+            GMRes is slower due to the small size of the problem.
+        </para>
+        <para>
+            From the result, we can extract the speed factors:
         </para>
         <para>
             <informaltable border="1">
@@ -696,12 +702,16 @@ Time for DDaskr:
                     <td align="center">
                         <emphasis>IDA</emphasis> 
                     </td>
+                    <td align="center">
+                        <emphasis>DDaskr G</emphasis> 
+                    </td>
                 </tr>
                 <tr>
                     <td align="center">
-                        <emphasis>DDaskr</emphasis> 
+                        <emphasis>DDaskr N</emphasis> 
                     </td>
                     <td align="center"> 1.39x </td>
+                    <td align="center"> 1.9x </td>
                 </tr>
             </informaltable>
         </para>
index d3ada6b..d29cfbb 100644 (file)
@@ -644,7 +644,7 @@ Temps pour Runge-Kutta implicite :
             Exemple : une balle rebondissante.
         </para>
         <para>
-            <link type="scilab" linkend="scilab.xcos/xcos/demos/ModelicaBlocks/BouncingBall_Modelica.zcos">
+            <link type="scilab" linkend="scilab.zcos/xcos/demos/ModelicaBlocks/BouncingBall_Modelica.zcos">
                 <inlinemediaobject>
                     <imageobject>
                         <imagedata align="center" fileref="../../../demos/ModelicaBlocks/BouncingBall_Modelica.zcos" valign="middle"/>
@@ -660,8 +660,8 @@ try xcos_simulate(scs_m, 4); catch disp(lasterror()); end
 ]]></scilab:image>
         </para>
         <para>
-            Dans le script suivant, on compare la différence de temps entre les solveurs en lançant les deux solveurs tout à tour :
-            <link type="scilab" linkend ="scilab.scinotes/xcos/examples/solvers/benchDDaskr_Bouncing.sce">
+            Dans le script suivant, on compare la différence de temps entre les solveurs en lançant les trois solveurs tout à tour :
+            <link type="scilab" linkend ="scilab.scinotes/xcos/examples/solvers/benchBouncing.sce">
                 Ouverture du script
             </link>
         </para>
@@ -671,18 +671,24 @@ try xcos_simulate(scs_m, 4); catch disp(lasterror()); end
 Temps pour IDA :
  7.5
 
-Temps pour DDaskr :
+Temps pour DDaskr - Newton :
  5.4
+
+Temps pour DDaskr - GMRes :
+ 10.2
             ]]></screen>
         </para>
         <para>
-            Ces résultats montrent que pour un problème raide, avec traversées de zéro et à même précision, <emphasis>DDaskr</emphasis> est le plus rapide.
+            Ces résultats montrent que pour un problème raide, avec traversées de zéro et à même précision, <emphasis>DDaskr - Newton</emphasis> est le plus rapide.
         </para>
         <para>
             La différence de temps est attribuée à l'implémentation optimale de DDaskr et à son moindre contrôle d'erreur.
         </para>
         <para>
-            Des résultats on extrait le facteur de vitesse :
+            GMRes est plus lent dû à la petitesse du problème (pas suffisamment d'états continus).
+        </para>
+        <para>
+            Des résultats on extrait les facteurs de vitesse :
         </para>
         <para>
             <informaltable border="1">
@@ -691,12 +697,16 @@ Temps pour DDaskr :
                     <td align="center">
                         <emphasis>IDA</emphasis> 
                     </td>
+                    <td align="center">
+                        <emphasis>DDaskr G</emphasis> 
+                    </td>
                 </tr>
                 <tr>
                     <td align="center">
-                        <emphasis>DDaskr</emphasis> 
+                        <emphasis>DDaskr N</emphasis> 
                     </td>
                     <td align="center"> 1.39x </td>
+                    <td align="center"> 1.9x </td>
                 </tr>
             </informaltable>
         </para>
index 22f06ac..15302c3 100644 (file)
@@ -169,7 +169,7 @@ function %cpr = xcos_simulate(scs_m, needcompile)
         "switching to implicit Solver"])
         solver = 100 ; //** Magic number
         tolerances(6) = solver ; //** save Magic number solver type
-    elseif (%cpr.sim.xptr($)-1==size(%cpr.state.x,"*")) & ((solver==100 | solver==101) & size(%cpr.state.x,"*")<>0) then
+    elseif (%cpr.sim.xptr($)-1==size(%cpr.state.x,"*")) & ((or (solver == [100 101 102])) & size(%cpr.state.x,"*")<>0) then
         message(["Diagram has been compiled for explicit solver"
         "switching to explicit Solver"])
         solver = 0 ; //** Magic number
index f3b515a..e0f2141 100644 (file)
@@ -176,11 +176,12 @@ public class SetupDialog extends JDialog {
         JLabel solverLabel = new JLabel(XcosMessages.SOLVER_CHOICE);
         final String[] solvers = new String[] { "LSodar", "Sundials/CVODE - BDF - NEWTON", "Sundials/CVODE - BDF - FUNCTIONAL",
                                                 "Sundials/CVODE - ADAMS - NEWTON", "Sundials/CVODE - ADAMS - FUNCTIONAL", "DOPRI5 - Dormand-Prince 4(5)",
-                                                "RK45 - Runge-Kutta 4(5)", "Implicit RK45 - Runge-Kutta 4(5)", "Sundials/IDA", "DDaskr"
+                                                "RK45 - Runge-Kutta 4(5)", "Implicit RK45 - Runge-Kutta 4(5)", "Sundials/IDA", "DDaskr - Newton", "DDaskr - GMRes"
                                               };
         final String[] solversTooltips = new String[] { "Method: dynamic, Nonlinear solver= dynamic", "Method: BDF, Nonlinear solver= NEWTON",
                 "Method: BDF, Nonlinear solver= FUNCTIONAL", "Method: ADAMS, Nonlinear solver= NEWTON", "Method: ADAMS, Nonlinear solver= FUNCTIONAL",
-                "Method: Fixed step", "Method: Fixed step", "Method: Fixed step, Nonlinear solver= FIXED-POINT", "Method: BDF, Nonlinear solver= NEWTON", "Method: BDF, Nonlinear solver= NEWTON"
+                "Method: Fixed step", "Method: Fixed step", "Method: Fixed step, Nonlinear solver= FIXED-POINT", "Method: BDF, Nonlinear solver= NEWTON",
+                "Method: BDF, Nonlinear solver= NEWTON", "Method: BDF - Nonlinear solver = GMRES"
                                                       };
 
         solver = new JComboBox(solvers);
@@ -188,7 +189,8 @@ public class SetupDialog extends JDialog {
         if (solverValue >= 0.0 && solverValue <= solvers.length - 2) {
             solver.setSelectedIndex((int) solverValue);
         } else {
-            // IDA = 8+92 = 100, DDaskr = 9+92 = 101. Here, we turn IDA and DDaskr solver numbers back into indexes (8 and 9)
+            // IDA = 8+92 = 100, DDaskr-Newton = 9+92 = 101, DDaskr-GMRes = 102
+            // Here, we turn IDA and DDaskr solver numbers back into indexes (8, 9 and 10)
             solver.setSelectedIndex((int) solverValue - 92);
         }
 
@@ -353,10 +355,10 @@ public class SetupDialog extends JDialog {
                          * handler
                          */
                         int solverSelectedIndex = solver.getSelectedIndex();
-                        if (solverSelectedIndex >= 0.0 && solverSelectedIndex <= solver.getModel().getSize() - 3) {
+                        if (solverSelectedIndex >= 0.0 && solverSelectedIndex <= solver.getModel().getSize() - 4) {
                             parameters.setSolver(solverSelectedIndex);
                         } else {
-                            parameters.setSolver(solverSelectedIndex + 92); // IDA = 8+92 = 100, DDaskr = 9+92 = 101
+                            parameters.setSolver(solverSelectedIndex + 92); // IDA = 8+92 = 100, DDaskr-Newton = 9+92 = 101, DDaskr-GMRes = 102
                         }
 
                         parameters.setFinalIntegrationTime(((BigDecimal) integration.getValue()).doubleValue());
index e6f420e..59b5e09 100644 (file)
@@ -307,6 +307,7 @@ public class ScicosParameters implements Serializable, Cloneable {
      * <li>7 : Implicit RK45 : Method: Runge-Kutta 4(5), Nonlinear solver= Fixed-point
      * <li>100 : Sundials/IDA : Method: BDF, Nonlinear solver= NEWTON
      * <li>101 : DDaskr : Method: BDF, Nonlinear solver= NEWTON
+     * <li>102 : DDaskr : Method: BDF, Nonlinear solver= GMRES
      *
      *
      * @return solver value
@@ -327,6 +328,7 @@ public class ScicosParameters implements Serializable, Cloneable {
      * <li>7 : Implicit RK45 : Method: Runge-Kutta 4(5), Nonlinear solver= FIXED-POINT
      * <li>100 : Sundials/IDA : Method: BDF, Nonlinear solver= NEWTON
      * <li>101 : DDaskr : Method: BDF, Nonlinear solver= NEWTON
+     * <li>102 : DDaskr : Method: BDF, Nonlinear solver= GMRES
      *
      *
      * @param solver
diff --git a/scilab/modules/xcos/tests/unit_tests/DDaskr_Platform_test.zcos b/scilab/modules/xcos/tests/unit_tests/DDaskr_Platform_test.zcos
new file mode 100644 (file)
index 0000000..2b85b48
Binary files /dev/null and b/scilab/modules/xcos/tests/unit_tests/DDaskr_Platform_test.zcos differ