Changeset 9578


Ignore:
Timestamp:
Jan 20, 2017 10:47:55 AM (3 years ago)
Author:
Christian Andersson
Message:

Removed dependencies that should not have been there. Related to ticket:4815

Location:
trunk/RuntimeLibrary/src/jmi
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/RuntimeLibrary/src/jmi/jmi_block_residual.c

    r9448 r9578  
    274274
    275275        for (i=0;i<block->n_dr; i++) {
    276             if (RAbs(pre_discrete_reals[i] - discrete_reals[i])/block->discrete_nominals[i] > JMI_ALMOST_EPS) {
     276            if (JMI_ABS(pre_discrete_reals[i] - discrete_reals[i])/block->discrete_nominals[i] > JMI_ALMOST_EPS) {
    277277                jmi_log_node(jmi->log, logInfo, "Info", " <discrete_real: #r%d#> <from: %g> <to: %g>  ", block->dr_vref[i], pre_discrete_reals[i], discrete_reals[i]);
    278278            }
  • trunk/RuntimeLibrary/src/jmi/jmi_block_solver.h

    r9454 r9578  
    2727
    2828#include "jmi_log.h"
     29#include "jmi_types.h"
    2930#include <time.h>
    30 #include <sundials/sundials_math.h>
    31 #include <sundials/sundials_direct.h>
    32 #include <nvector/nvector_serial.h>
    33 #include <kinsol/kinsol_direct.h>
    34 #include <kinsol/kinsol_impl.h>
    35 #include <sundials/sundials_dense.h>
    3631
    3732/** \brief Evaluation modes for the residual function.*/
     
    444439
    445440/** \brief Check and log illegal iv inputs */
    446 int jmi_check_and_log_illegal_iv_input(jmi_block_solver_t* block, double* ivs, int N);
     441int jmi_check_and_log_illegal_iv_input(jmi_block_solver_t* block, jmi_real_t* ivs, int N);
    447442
    448443/** \brief Check and log illegal residual output(s) */
    449 int jmi_check_and_log_illegal_residual_output(jmi_block_solver_t *block, double* f, double* ivs, double* heuristic_nominal,int N);
     444int jmi_check_and_log_illegal_residual_output(jmi_block_solver_t *block, jmi_real_t* f, jmi_real_t* ivs, jmi_real_t* heuristic_nominal,int N);
    450445#endif /* _JMI_BLOCK_SOLVER_H */
  • trunk/RuntimeLibrary/src/jmi/jmi_block_solver_impl.h

    r9454 r9578  
    2626#define _JMI_BLOCK_SOLVER_IMPL_H
    2727#include "jmi_block_solver.h"
     28#include <nvector/nvector_serial.h>
     29#include <sundials/sundials_direct.h>
    2830
    2931/**
  • trunk/RuntimeLibrary/src/jmi/jmi_brent_search.h

    r7338 r9578  
    2727    Errata and new print: http://wwwmaths.anu.edu.au/~brent/pub/pub011.html
    2828*/
    29 #include <sundials/sundials_types.h>
    30 #include <sundials/sundials_math.h>
     29#include "jmi_types.h"
    3130
    32 typedef int (*jmi_brent_func_t)(realtype u, realtype* f, void* data);
     31typedef int (*jmi_brent_func_t)(jmi_real_t u, jmi_real_t* f, void* data);
    3332
    3433/*
     
    4746    @return Error flag (may be forwarded from the call to f() or one of jmi_brent_exit_codes_t)
    4847 */
    49 int jmi_brent_search(jmi_brent_func_t f, realtype u_min, realtype u_max,
    50                      realtype f_min, realtype f_max, realtype tolerance,
    51                      realtype* u_out, realtype* f_out, void *data);
    52 
    53 #include <kinsol/kinsol.h>
     48int jmi_brent_search(jmi_brent_func_t f, jmi_real_t u_min, jmi_real_t u_max,
     49                     jmi_real_t f_min, jmi_real_t f_max, jmi_real_t tolerance,
     50                     jmi_real_t* u_out, jmi_real_t* f_out, void *data);
    5451
    5552/**< \brief Convert Brent return flag to readable name */
     
    5855/**< \brief Error codes used by the Brent solver */
    5956typedef enum {
    60     JMI_BRENT_SUCCESS = KIN_SUCCESS,
    61     JMI_BRENT_ILL_INPUT = KIN_ILL_INPUT,
    62     JMI_BRENT_MEM_FAIL = KIN_MEM_FAIL,
    63     JMI_BRENT_SYSFUNC_FAIL = KIN_SYSFUNC_FAIL,
    64     JMI_BRENT_FIRST_SYSFUNC_ERR = KIN_FIRST_SYSFUNC_ERR,
    65     JMI_BRENT_REPTD_SYSFUNC_ERR = KIN_REPTD_SYSFUNC_ERR,
     57    JMI_BRENT_SUCCESS                = 0,
     58    JMI_BRENT_ILL_INPUT              = -2,
     59    JMI_BRENT_MEM_FAIL               = -1,
     60    JMI_BRENT_SYSFUNC_FAIL           = -13,
     61    JMI_BRENT_FIRST_SYSFUNC_ERR      = -14,
     62    JMI_BRENT_REPTD_SYSFUNC_ERR      = -15,
    6663    JMI_BRENT_ROOT_BRACKETING_FAILED = -16,
    67     JMI_BRENT_FAILED = -17
     64    JMI_BRENT_FAILED                 = -17
    6865}
    6966jmi_brent_exit_codes_t;
     
    7471   @param problem_data - solver object propagated as opaques data
    7572*/
    76 int brentf(realtype y, realtype* f, void* problem_data);
     73int brentf(jmi_real_t y, jmi_real_t* f, void* problem_data);
    7774
    7875#endif /* JMI_BRENT_SEARCH_H */
  • trunk/RuntimeLibrary/src/jmi/jmi_brent_solver.c

    r9551 r9578  
    4343   @param problem_data - solver object propagated as opaques data
    4444*/
    45 int brentf(realtype y, realtype* f, void* problem_data) {
     45int brentf(jmi_real_t y, jmi_real_t* f, void* problem_data) {
    4646    jmi_block_solver_t *block = (jmi_block_solver_t*)problem_data;
    4747    int ret = 0;
     
    7474}
    7575
    76 int brentdf(realtype y, realtype f, realtype* df, void* problem_data) {
     76int brentdf(jmi_real_t y, jmi_real_t f, jmi_real_t* df, void* problem_data) {
    7777    jmi_block_solver_t *block = (jmi_block_solver_t*)problem_data;
    7878    int ret = 0;
    79     realtype y0 = y;
    80     realtype ftemp;
     79    jmi_real_t y0 = y, ftemp, inc;
    8180    int sign;
    82     realtype inc;
    8381
    8482    /* Check that arguments are valid */
     
    106104        }
    107105    } else {
    108         sign = (y >= 0) ? 1 : -1;
    109         inc = MAX(ABS(y), block->nominal[0])*sign*1e-8;
     106        sign = (y >= 0)  ? 1 : -1;
     107        inc = JMI_MAX(JMI_ABS(y), block->nominal[0])*sign*1e-8;
    110108        y += inc;
    111109        /* make sure we're inside bounds*/
     
    140138    /* Check that outputs are valid */   
    141139    {
    142         realtype v = *df;
     140        jmi_real_t v = *df;
    143141        if (v- v != 0) {
    144142             jmi_log_t* log = block->log;
     
    519517
    520518        if ((init > max) || (init < min)) {
    521             realtype old_init = init;
     519            jmi_real_t old_init = init;
    522520            init = init > max ? max : min;
    523521            block->x[0] = block->initial[0] = init;
     
    798796
    799797    {           
    800         realtype u, f;
     798        jmi_real_t u, f;
    801799        flag = jmi_brent_search(brentf, solver->y_neg_max,  solver->y_pos_min,
    802800                                solver->f_neg_max, solver->f_pos_min, 0, &u, &f,block);
     
    829827}
    830828
    831 int jmi_brent_search(jmi_brent_func_t f, realtype u_min, realtype u_max, realtype f_min, realtype f_max, realtype tolerance, realtype* u_out, realtype* f_out,void *data) {
    832     realtype a=u_min; /* left point */
    833     realtype fa = f_min;
    834     realtype b=u_max; /* right point */
    835     realtype fb = f_max;
    836     realtype c = u_min; /* Intermediate point a <= c <= b */
    837     realtype fc = f_min;
    838     realtype e= u_max - u_min;
    839     realtype d=e;
    840     realtype m;
    841     realtype s;
    842     realtype p;
    843     realtype q;
    844     realtype r;
    845     realtype tol; /* absolute tolerance for the current "b" */
     829int jmi_brent_search(jmi_brent_func_t f, jmi_real_t u_min, jmi_real_t u_max, jmi_real_t f_min, jmi_real_t f_max, jmi_real_t tolerance, jmi_real_t* u_out, jmi_real_t* f_out,void *data) {
     830    jmi_real_t a=u_min; /* left point */
     831    jmi_real_t fa = f_min;
     832    jmi_real_t b=u_max; /* right point */
     833    jmi_real_t fb = f_max;
     834    jmi_real_t c = u_min; /* Intermediate point a <= c <= b */
     835    jmi_real_t fc = f_min;
     836    jmi_real_t e= u_max - u_min;
     837    jmi_real_t d=e;
     838    jmi_real_t m,s,p,q,r;
     839    jmi_real_t tol; /* absolute tolerance for the current "b" */
    846840    int flag;
    847841    jmi_block_solver_t* block = (jmi_block_solver_t*)data;
     
    862856#endif
    863857    while(1) {
    864         if (RAbs(fc) < RAbs(fb)) {
     858        if (JMI_ABS(fc) < JMI_ABS(fb)) {
    865859            a = b;
    866860            b = c;
     
    875869                     b, c, fb, fc);
    876870
    877         tol = 2*UNIT_ROUNDOFF*RAbs(b) + tolerance;
     871        tol = 2*UNIT_ROUNDOFF*JMI_ABS(b) + tolerance;
    878872        m = (c - b)/2;
    879873       
    880         if ((RAbs(m) <= tol) || (fb == 0.0)) {
     874        if ((JMI_ABS(m) <= tol) || (fb == 0.0)) {
    881875            /* root found (interval is small enough) */
    882             if (RAbs(fb) < RAbs(fc)) {
     876            if (JMI_ABS(fb) < JMI_ABS(fc)) {
    883877                *u_out = b;
    884878                *f_out = fb;
     
    895889        /* Find the new point: */
    896890        /* Determine if a bisection is needed */
    897         if ((RAbs(e) < tol) || ( RAbs(fa) <= RAbs(fb))) {
     891        if ((JMI_ABS(e) < tol) || ( JMI_ABS(fa) <= JMI_ABS(fb))) {
    898892            e = m;
    899893            d = e;
     
    920914            e = d;
    921915           
    922             if ((2*p < 3*m*q - RAbs(tol*q)) && (p < RAbs(0.5*s*q)))
     916            if ((2*p < 3*m*q - JMI_ABS(tol*q)) && (p < JMI_ABS(0.5*s*q)))
    923917                /* interpolation successful */
    924918                d = p/q;
     
    934928        a = b;
    935929        fa = fb;
    936         b = b + ((RAbs(d) > tol) ? d : ((m > 0) ? tol: -tol));
     930        b = b + ((JMI_ABS(d) > tol) ? d : ((m > 0) ? tol: -tol));
    937931        flag = f(b, &fb, data);
    938932        if (flag) {
    939              if (RAbs(fa) < RAbs(fc)) {
     933             if (JMI_ABS(fa) < JMI_ABS(fc)) {
    940934                *u_out = a;
    941935                *f_out = fa;
  • trunk/RuntimeLibrary/src/jmi/jmi_brent_solver.h

    r9540 r9578  
    2727#define _JMI_BRENT_SOLVER_H
    2828
     29#include "jmi_types.h"
    2930#include "jmi_block_solver.h"
    3031
     
    4142
    4243/**< \brief Newton before Brent */
    43 int jmi_brent_newton(jmi_block_solver_t *block, double *x0, double *f0, double *d);
     44int jmi_brent_newton(jmi_block_solver_t *block, jmi_real_t *x0, jmi_real_t *f0, jmi_real_t *d);
    4445
    4546/**< \brief Notifies Brent that an integrator step has been accepted */
     
    4748
    4849/**< \brief Test if the best guess is good enough */
    49 int jmi_brent_test_best_guess(jmi_block_solver_t *block, double xBest, double fBest);
     50int jmi_brent_test_best_guess(jmi_block_solver_t *block, jmi_real_t xBest, jmi_real_t fBest);
    5051
    5152/**< \brief Data structure used by the Brent algorithm */
    5253struct jmi_brent_solver_t {
    53     double y;              /**< \brief current/last iterate */
    54     double f;              /**< \brief Residual at "y" */
     54    jmi_real_t y;              /**< \brief current/last iterate */
     55    jmi_real_t f;              /**< \brief Residual at "y" */
    5556
    56     double originalStart; /**< \brief The start value used during the first call */
     57    jmi_real_t originalStart; /**< \brief The start value used during the first call */
    5758   
    58     double y_pos_min;      /**< \brief Iteration variable value for minimal known positive f */
    59     double f_pos_min;       /**< \brief Residual at y_pos_min */
    60     double y_neg_max;       /**< \brief Iteration variable value for maximum known negativ f*/
    61     double f_neg_max;       /**< \brief Residual at y_neg_max */
     59    jmi_real_t y_pos_min;      /**< \brief Iteration variable value for minimal known positive f */
     60    jmi_real_t f_pos_min;       /**< \brief Residual at y_pos_min */
     61    jmi_real_t y_neg_max;       /**< \brief Iteration variable value for maximum known negativ f*/
     62    jmi_real_t f_neg_max;       /**< \brief Residual at y_neg_max */
    6263};
    6364
  • trunk/RuntimeLibrary/src/jmi/jmi_util.c

    r9572 r9578  
    256256   
    257257    for (i = 0; i < size; i++){
    258         if (RAbs(dr_pre[i] - dr_post[i])/nominals[i] > JMI_ALMOST_EPS ){
     258        if (JMI_ABS(dr_pre[i] - dr_post[i])/nominals[i] > JMI_ALMOST_EPS ){
    259259            all_discrete_reals_equal = 0;
    260260            break;
Note: See TracChangeset for help on using the changeset viewer.