From 8c400156d4156a8c4868b12e3b0cbf91f5ba47c8 Mon Sep 17 00:00:00 2001 From: Sylvain GENIN Date: Thu, 12 Feb 2015 09:31:03 +0100 Subject: [PATCH] correction equation in sci_daskr test_run differential_equations daskr Change-Id: Ie4bd0feadfb44f3a646123866d6430588efbf8c2 --- .../includes/checkodeerror.h | 16 -------------- .../includes/checkodeerror.hxx | 22 ++++++++++++++++++++ .../sci_gateway/cpp/sci_daskr.cpp | 14 ++++++------- .../sci_gateway/cpp/sci_dasrt.cpp | 4 ++-- .../sci_gateway/cpp/sci_dassl.cpp | 5 ++--- .../sci_gateway/cpp/sci_impl.cpp | 4 ++-- .../sci_gateway/cpp/sci_ode.cpp | 2 +- .../sci_gateway/cpp/sci_odedc.cpp | 2 +- .../src/cpp/checkodeerror.cpp | 10 +++++---- .../src/cpp/differentialequationfunctions.cpp | 15 ++++++++++--- 10 files changed, 55 insertions(+), 39 deletions(-) delete mode 100644 scilab/modules/differential_equations/includes/checkodeerror.h create mode 100644 scilab/modules/differential_equations/includes/checkodeerror.hxx diff --git a/scilab/modules/differential_equations/includes/checkodeerror.h b/scilab/modules/differential_equations/includes/checkodeerror.h deleted file mode 100644 index 51481e2..0000000 --- a/scilab/modules/differential_equations/includes/checkodeerror.h +++ /dev/null @@ -1,16 +0,0 @@ -/* -* Scilab ( http://www.scilab.org/ ) - This file is part of Scilab -* Copyright (C) 2011 - DIGITEO - Cedric DELAMARRE -* -* This file must be used under the terms of the CeCILL. -* This source file is licensed as described in the file COPYING, which -* you should have received as part of this distribution. The terms -* are also available at -* http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt -* -*/ -/*--------------------------------------------------------------------------*/ -#include "dynlib_differential_equations.h" - -DIFFERENTIAL_EQUATIONS_IMPEXP int checkOdeError(int meth, int istate); -DIFFERENTIAL_EQUATIONS_IMPEXP int checkDasslError(int idid); diff --git a/scilab/modules/differential_equations/includes/checkodeerror.hxx b/scilab/modules/differential_equations/includes/checkodeerror.hxx new file mode 100644 index 0000000..0ce7032 --- /dev/null +++ b/scilab/modules/differential_equations/includes/checkodeerror.hxx @@ -0,0 +1,22 @@ +/* +* Scilab ( http://www.scilab.org/ ) - This file is part of Scilab +* Copyright (C) 2011 - DIGITEO - Cedric DELAMARRE +* +* This file must be used under the terms of the CeCILL. +* This source file is licensed as described in the file COPYING, which +* you should have received as part of this distribution. The terms +* are also available at +* http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt +* +*/ +/*--------------------------------------------------------------------------*/ +#ifndef __CHECK_ODE_ERROR__ +#define __CHECK_ODE_ERROR__ + +#include +#include "dynlib_differential_equations.h" + +DIFFERENTIAL_EQUATIONS_IMPEXP int checkOdeError(int meth, int istate); +DIFFERENTIAL_EQUATIONS_IMPEXP int checkError(int idid, std::string strName); + +#endif // __CHECK_ODE_ERROR__ diff --git a/scilab/modules/differential_equations/sci_gateway/cpp/sci_daskr.cpp b/scilab/modules/differential_equations/sci_gateway/cpp/sci_daskr.cpp index 5a76344..4ef2f0b 100644 --- a/scilab/modules/differential_equations/sci_gateway/cpp/sci_daskr.cpp +++ b/scilab/modules/differential_equations/sci_gateway/cpp/sci_daskr.cpp @@ -20,6 +20,7 @@ #include "callable.hxx" #include "differentialequationfunctions.hxx" #include "runvisitor.hxx" +#include "checkodeerror.hxx" extern "C" { @@ -29,7 +30,6 @@ extern "C" #include "sciprint.h" #include "scifunctions.h" #include "elem_common.h" -#include "checkodeerror.h" } /*--------------------------------------------------------------------------*/ @@ -618,7 +618,7 @@ types::Function::ReturnValue sci_daskr(types::typed_list &in, int _iRetCount, ty if (pDblTemp->getSize() == 0) { // maxl and kmp need default values - maxl = min(5, pDblX0->getSize()); + maxl = min(5, pDblX0->getRows()); kmp = maxl; } else @@ -753,7 +753,7 @@ types::Function::ReturnValue sci_daskr(types::typed_list &in, int _iRetCount, ty //compute itol and set the tolerances rtol and atol. double* rtol = NULL; double* atol = NULL; - double rpar[2] = {0, 0}; + double rpar[2] = {0, 0 }; int ipar[30]; memset(ipar, 0x00, 30 * sizeof(int)); @@ -839,7 +839,7 @@ types::Function::ReturnValue sci_daskr(types::typed_list &in, int _iRetCount, ty // LENWP is the length ot the rwork segment containing // the matrix elements of the preconditioner P - LENWP = 7 * pDblX0->getRows(); + LENWP = pDblX0->getRows() * pDblX0->getRows(); rworksize += (maxord + 5) * pDblX0->getRows() + 3 * ng + (maxl + 3 + min(1, maxl - kmp)) * pDblX0->getRows() + (maxl + 3) * maxl + 1 + LENWP; @@ -862,7 +862,7 @@ types::Function::ReturnValue sci_daskr(types::typed_list &in, int _iRetCount, ty // LENIWP is the length ot the iwork segment containing // the matrix indexes of the preconditioner P // (compressed sparse row format) - LENIWP = 25 * pDblX0->getRows() + 1; + LENIWP = 2 * pDblX0->getRows() * pDblX0->getRows(); iworksize += LENIWP; } @@ -964,7 +964,7 @@ types::Function::ReturnValue sci_daskr(types::typed_list &in, int _iRetCount, ty ipar[3] = 2; ipar[4] = 1; rpar[0] = 0.005; - rpar[1] = 0.005; + rpar[1] = 0.05; } if (info[15] == 1) @@ -1046,7 +1046,7 @@ types::Function::ReturnValue sci_daskr(types::typed_list &in, int _iRetCount, ty } // use the same error function that dasrt - iret = checkDasslError(idid); + iret = checkError(idid, "daskr"); if (iret == 1) // error { Scierror(999, _("%s: ddaskr return with state %d.\n"), "daskr", ididtmp); diff --git a/scilab/modules/differential_equations/sci_gateway/cpp/sci_dasrt.cpp b/scilab/modules/differential_equations/sci_gateway/cpp/sci_dasrt.cpp index 5548e9a..d33b2f2 100644 --- a/scilab/modules/differential_equations/sci_gateway/cpp/sci_dasrt.cpp +++ b/scilab/modules/differential_equations/sci_gateway/cpp/sci_dasrt.cpp @@ -19,6 +19,7 @@ #include "callable.hxx" #include "differentialequationfunctions.hxx" #include "runvisitor.hxx" +#include "checkodeerror.hxx" extern "C" { @@ -28,7 +29,6 @@ extern "C" #include "sciprint.h" #include "scifunctions.h" #include "elem_common.h" -#include "checkodeerror.h" } /*--------------------------------------------------------------------------*/ @@ -744,7 +744,7 @@ types::Function::ReturnValue sci_dasrt(types::typed_list &in, int _iRetCount, ty try { C2F(ddasrt)(dassl_f, YSize, &t0, pdYData, pdYdotData, &t, info, rtol, atol, &idid, rwork, &rworksize, iwork, &iworksize, &rpar, &ipar, dassl_jac, dasrt_g, &ng, root); - iret = checkDasslError(idid); + iret = checkError(idid, "dasrt"); if (iret == 1) // error { Scierror(999, _("%s: ddasrt return with state %d.\n"), "dasrt", idid); diff --git a/scilab/modules/differential_equations/sci_gateway/cpp/sci_dassl.cpp b/scilab/modules/differential_equations/sci_gateway/cpp/sci_dassl.cpp index 6709a36..5e1c103 100644 --- a/scilab/modules/differential_equations/sci_gateway/cpp/sci_dassl.cpp +++ b/scilab/modules/differential_equations/sci_gateway/cpp/sci_dassl.cpp @@ -19,6 +19,7 @@ #include "callable.hxx" #include "differentialequationfunctions.hxx" #include "runvisitor.hxx" +#include "checkodeerror.hxx" extern "C" { @@ -28,9 +29,7 @@ extern "C" #include "sciprint.h" #include "scifunctions.h" #include "elem_common.h" -#include "checkodeerror.h" #include "xerhlt.h" - } /*--------------------------------------------------------------------------*/ @@ -681,7 +680,7 @@ types::Function::ReturnValue sci_dassl(types::typed_list &in, int _iRetCount, ty { C2F(dassl)(dassl_f, YSize, &t0, pdYData, pdYdotData, &t, info, rtol, atol, &idid, rwork, &rworksize, iwork, &iworksize, &rpar, &ipar, dassl_jac); - iret = checkDasslError(idid); + iret = checkError(idid, "dassl"); if (iret == 1) // error { Scierror(999, _("%s: dassl return with state %d.\n"), "dassl", idid); diff --git a/scilab/modules/differential_equations/sci_gateway/cpp/sci_impl.cpp b/scilab/modules/differential_equations/sci_gateway/cpp/sci_impl.cpp index f093740..78ebdce 100644 --- a/scilab/modules/differential_equations/sci_gateway/cpp/sci_impl.cpp +++ b/scilab/modules/differential_equations/sci_gateway/cpp/sci_impl.cpp @@ -19,6 +19,7 @@ #include "callable.hxx" #include "differentialequationfunctions.hxx" #include "runvisitor.hxx" +#include "checkodeerror.hxx" extern "C" { @@ -27,7 +28,6 @@ extern "C" #include "Scierror.h" #include "scifunctions.h" #include "elem_common.h" -#include "checkodeerror.h" #include "sciprint.h" #include "common_structure.h" } @@ -575,7 +575,7 @@ types::Function::ReturnValue sci_impl(types::typed_list &in, int _iRetCount, typ nyh = C2F(ls0001).nyh; } - rworkSize = 20 + nyh * (maxord + 1) + 3 * *YSize + *YSize * *YSize + 2; + rworkSize = 20 + nyh * (maxord + 1) + 3 * *YSize + *YSize **YSize + 2; iworkSize = 20 + *YSize; rwSize = rworkSize + dStructTabSize; diff --git a/scilab/modules/differential_equations/sci_gateway/cpp/sci_ode.cpp b/scilab/modules/differential_equations/sci_gateway/cpp/sci_ode.cpp index 8230a80..bf35d2a 100644 --- a/scilab/modules/differential_equations/sci_gateway/cpp/sci_ode.cpp +++ b/scilab/modules/differential_equations/sci_gateway/cpp/sci_ode.cpp @@ -20,6 +20,7 @@ #include "differentialequationfunctions.hxx" #include "runvisitor.hxx" #include "context.hxx" +#include "checkodeerror.hxx" extern "C" { @@ -30,7 +31,6 @@ extern "C" #include "configvariable_interface.h" #include "sciprint.h" #include "common_structure.h" -#include "checkodeerror.h" #include "sci_malloc.h" } /*--------------------------------------------------------------------------*/ diff --git a/scilab/modules/differential_equations/sci_gateway/cpp/sci_odedc.cpp b/scilab/modules/differential_equations/sci_gateway/cpp/sci_odedc.cpp index a60d8e1..ea0dc3e 100644 --- a/scilab/modules/differential_equations/sci_gateway/cpp/sci_odedc.cpp +++ b/scilab/modules/differential_equations/sci_gateway/cpp/sci_odedc.cpp @@ -20,6 +20,7 @@ #include "differentialequationfunctions.hxx" #include "runvisitor.hxx" #include "context.hxx" +#include "checkodeerror.hxx" extern "C" { @@ -31,7 +32,6 @@ extern "C" #include "sciprint.h" #include "common_structure.h" #include "scifunctions.h" -#include "checkodeerror.h" } /*--------------------------------------------------------------------------*/ diff --git a/scilab/modules/differential_equations/src/cpp/checkodeerror.cpp b/scilab/modules/differential_equations/src/cpp/checkodeerror.cpp index 4598bd2..8e904a1 100644 --- a/scilab/modules/differential_equations/src/cpp/checkodeerror.cpp +++ b/scilab/modules/differential_equations/src/cpp/checkodeerror.cpp @@ -11,8 +11,10 @@ */ /*--------------------------------------------------------------------------*/ -extern "C" { -#include "checkodeerror.h" +#include "checkodeerror.hxx" + +extern "C" +{ #include "sciprint.h" #include "localization.h" #include "configvariable_interface.h" @@ -155,7 +157,7 @@ int checkOdeError(int meth, int istate) return 0; } -int checkDasslError(int idid) +int checkError(int idid, std::string strName) { switch (idid) { @@ -281,7 +283,7 @@ int checkDasslError(int idid) //when invalid input is detected. if (getWarningMode()) { - sciprint(_("encountered trouble.\n")); + sciprint(_("%s encountered trouble.\n"), strName.c_str()); } return 2; } diff --git a/scilab/modules/differential_equations/src/cpp/differentialequationfunctions.cpp b/scilab/modules/differential_equations/src/cpp/differentialequationfunctions.cpp index 41456ab..e027a76 100644 --- a/scilab/modules/differential_equations/src/cpp/differentialequationfunctions.cpp +++ b/scilab/modules/differential_equations/src/cpp/differentialequationfunctions.cpp @@ -2635,10 +2635,16 @@ void DifferentialEquationFunctions::callDasslMacroF(double* t, double* y, double C2F(dcopy)(&m_odeYRows, pDblOutDelta->get(), &one, delta, &one); *ires = (int)pDblOutIres->get(0); + if (out[0]->isDeletable()) { delete out[0]; } + + if (out[1]->isDeletable()) + { + delete out[1]; + } } void DifferentialEquationFunctions::callDasslMacroJac(double* t, double* y, double* ydot, double* pd, double* cj, double* rpar, int* ipar) @@ -2909,6 +2915,8 @@ void DifferentialEquationFunctions::callDaskrMacroPjac(double* res, int* ires, i } out[0]->IncreaseRef(); + out[1]->IncreaseRef(); + out[2]->IncreaseRef(); pDblNeq->DecreaseRef(); if (pDblNeq->isDeletable()) @@ -3060,12 +3068,12 @@ void DifferentialEquationFunctions::callDaskrMacroPsol(int* neq, double* t, doub ast::ExecVisitor execFunc; // input arguments psol(R, iR, b) - types::Double* pDblR = new types::Double(1, *neq **neq); + types::Double* pDblR = new types::Double(*neq **neq, 1); pDblR->set(wp); pDblR->IncreaseRef(); in.push_back(pDblR); - types::Double* pDblIR = new types::Double(1, 2 * *neq **neq); + types::Double* pDblIR = new types::Double(*neq **neq, 2); double* pdblIR = pDblIR->get(); for (int i = 0; i < pDblIR->getSize(); i++) { @@ -3074,7 +3082,7 @@ void DifferentialEquationFunctions::callDaskrMacroPsol(int* neq, double* t, doub pDblIR->IncreaseRef(); in.push_back(pDblIR); - types::Double* pDblB = new types::Double(1, *neq); + types::Double* pDblB = new types::Double(*neq, 1); pDblB->set(b); pDblB->IncreaseRef(); in.push_back(pDblB); @@ -3104,6 +3112,7 @@ void DifferentialEquationFunctions::callDaskrMacroPsol(int* neq, double* t, doub } out[0]->IncreaseRef(); + out[1]->IncreaseRef(); // free input arguments pDblR->DecreaseRef(); -- 1.7.9.5