Ticket #4815: jmi_math.patch

File jmi_math.patch, 40.6 KB (added by efredriksson, 4 years ago)
  • RuntimeLibrary/Makefiles/Makefile.linux

     
    143143
    144144# Libraries necessary to link with jmi
    145145# Reused parts
    146 LIBS_FMU_STD = -ljmi "-L$(JMI_LIB_DIR)" $(EXT_LIB_DIRS) $(EXTERNAL_LIBS) -lModelicaExternalC
     146LIBS_FMU_STD = -ljmi "-L$(JMI_LIB_DIR)" $(EXT_LIB_DIRS) $(EXTERNAL_LIBS) -ljmi -lModelicaExternalC
    147147LIB_SUNDIALS = -L$(SUNDIALS_LIB_DIR) -l:libsundials_kinsol.a -l:libsundials_nvecserial.a
    148148LIB_MINPACK  = -L$(MINPACK_LIB_DIR) -l:libcminpack.a
    149149LIB_STD      = -lstdc++ -lm
  • RuntimeLibrary/Makefiles/Makefile.macosx

     
    142142
    143143# Libraries necessary to link with jmi
    144144# Reused parts
    145 LIBS_FMU_STD = -ljmi "-L$(JMI_LIB_DIR)" $(EXT_LIB_DIRS) $(EXTERNAL_LIBS) -lModelicaExternalC -static-libstdc++
     145LIBS_FMU_STD = -ljmi "-L$(JMI_LIB_DIR)" $(EXT_LIB_DIRS) $(EXTERNAL_LIBS) -ljmi -lModelicaExternalC -static-libstdc++
    146146LIB_SUNDIALS = -L$(SUNDIALS_LIB_DIR) $(SUNDIALS_HOME)/lib/libsundials_kinsol.a $(SUNDIALS_HOME)/lib/libsundials_nvecserial.a
    147147LIB_MINPACK  = -L$(MINPACK_LIB_DIR) ${JMODELICA_HOME}/ThirdParty/Minpack/lib/libcminpack.a
    148148LIB_COMMON   = $(LIB_SUNDIALS) $(LIB_MINPACK)
  • RuntimeLibrary/Makefiles/Makefile.windows

     
    9292# SUNDIALS home
    9393SUNDIALS_HOME =
    9494
    95 MODULE_HOME =
    96 
    9795# STATIC PTHREADS home
    9896STATIC_PTHREADS_HOME = $(JMODELICA_HOME)/ThirdParty/pthreads
    9997
     
    173171MINPACK_LIB_DIR64 = ${JMODELICA_HOME}/ThirdParty/Minpack/lib64
    174172SUNDIALS_LIB_DIR = $(SUNDIALS_HOME)/lib
    175173SUNDIALS_LIB_DIR64 = $(SUNDIALS_HOME)/lib64
    176 MODULE_LIB_DIR = $(MODULE_HOME)
    177174
    178175# Flags needed for specific libs
    179176ifdef IPOPT_HOME
     
    184181LIB_FLAGS_IPOPT := $(shell set "PKG_CONFIG_PATH=$(IPOPT_HOME)/lib/pkgconfig" && pkg-config --libs ipopt)
    185182LIB_MINPACK  = "-L$(MINPACK_LIB_DIR)" -l:libcminpack.a
    186183LIB_SUNDIALS = "-L$(SUNDIALS_LIB_DIR)" -l:libsundials_kinsol.a -l:libsundials_nvecserial.a -l:libsundials_cvode.a
    187 LIB_MODULE = "-L$(MODULE_LIB_DIR)" -l:libjmi_get_set_lazy.a
    188184STATIC_PTHREADS_CONT = $(shell dir "$(STATIC_PTHREADS_HOME)")
    189185ifneq ($(findstring ..,$(STATIC_PTHREADS_CONT)),)
    190186LIB_PTHREADS = "-L$(STATIC_PTHREADS_HOME)/lib" -lpthreadGC2-2-9-1
     
    193189endif
    194190
    195191# Libraries necessary to link with jmi
    196 LIBS_FMU_STD = -ljmi "-L$(JMI_LIB_DIR)" $(EXT_LIB_DIRS) $(EXTERNAL_LIBS) -lModelicaExternalC -lstdc++ -static-libstdc++
    197 LIBS_FMU_ALL = $(LIBS_FMU_STD) $(LIB_SUNDIALS) $(LIB_MINPACK) $(LIB_PTHREADS) $(LIB_MODULE)
     192LIBS_FMU_STD = -ljmi "-L$(JMI_LIB_DIR)" $(EXT_LIB_DIRS) $(EXTERNAL_LIBS) -ljmi -lModelicaExternalC -lstdc++ -static-libstdc++
     193LIBS_FMU_ALL = $(LIBS_FMU_STD) $(LIB_SUNDIALS) $(LIB_MINPACK) $(LIB_PTHREADS)
    198194LIBS_FMUME10 = -lfmi1_me           $(LIBS_FMU_ALL)
    199195LIBS_FMUCS10 = -lfmi1_cs -lfmi1_me $(LIBS_FMU_ALL)
    200196LIBS_FMU20   = -lfmi2              $(LIBS_FMU_ALL)
  • RuntimeLibrary/src/jmi/CMakeLists.txt

     
    3737    jmi_delay.h
    3838    jmi_delay_impl.h
    3939    jmi_dynamic_state.h
     40    jmi_math.h
    4041   
    4142    jmi_util.c
    4243    jmi_global.c
     
    4950    jmi_me.c
    5051    jmi_delay.c
    5152    jmi_dynamic_state.c
     53    jmi_math.c
    5254
    5355    # Logging sources
    5456        jmi_callbacks.h
  • RuntimeLibrary/src/jmi/jmi.c

     
    634634    return return_status;
    635635}
    636636
    637 jmi_ad_var_t jmi_sample(jmi_t* jmi, jmi_real_t offset, jmi_real_t h) {
    638     jmi_real_t t = jmi_get_t(jmi)[0];
    639     if (!jmi->atEvent || SURELY_LT_ZERO(t-offset)) {
    640       /*printf("jmi_sample1: %f %f %12.12f %12.12f\n",offset,fmod((t-offset),h),(t-offset));*/
    641         return JMI_FALSE;
    642     }
    643     /*  printf("jmi_sample2: %f %f %12.12f %12.12f\n",offset,h,fmod((t-offset),h),(t-offset));*/
    644     return ALMOST_ZERO(jmi_dremainder((t-offset),h));
    645 }
    646 
    647637int jmi_dae_F(jmi_t* jmi, jmi_real_t* res) {
    648638
    649639    /*jmi->dae->F->F(jmi, &res);*/
  • RuntimeLibrary/src/jmi/jmi_math.c

     
     1/*
     2    Copyright (C) 2016 Modelon AB
     3
     4    This program is free software: you can redistribute it and/or modify
     5    it under the terms of the GNU General Public License version 3 as published
     6    by the Free Software Foundation, or optionally, under the terms of the
     7    Common Public License version 1.0 as published by IBM.
     8
     9    This program is distributed in the hope that it will be useful,
     10    but WITHOUT ANY WARRANTY; without even the implied warranty of
     11    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     12    GNU General Public License, or the Common Public License, for more details.
     13
     14    You should have received copies of the GNU General Public License
     15    and the Common Public License along with this program.  If not,
     16    see <http://www.gnu.org/licenses/> or
     17    <http://www.ibm.com/developerworks/library/os-cpl.html/> respectively.
     18*/
     19
     20#include "jmi.h"
     21#include "jmi_math.h"
     22
     23
     24/* Helper function for logging warnings from the "_equation"- and "_function"-functions below */
     25void static jmi_log_func_or_eq(jmi_t *jmi, const char cathegory_name[], const char func_name[], const char msg[], const char val[]) {
     26    if (func_name != NULL) {
     27        char buf[64];
     28        sprintf(buf, "%s%s", cathegory_name, "InFunc");
     29        jmi_log_node(jmi->log, logWarning, buf, "<func: %s, exp: %s, val:%s>", func_name, msg, val);
     30    } else {
     31        jmi_log_node(jmi->log, logWarning, cathegory_name, "<exp:%s, val: %s>", msg, val);
     32    }
     33}
     34
     35int jmi_check_nan(jmi_t *jmi, jmi_real_t* val, size_t n_val, jmi_int_t* index_of_nan) {
     36    int i = 0;
     37    for (i = 0; i < n_val; i++) {
     38        if ( val[i] - val[i] != 0) {
     39            *index_of_nan = i;
     40            return JMI_ERROR;
     41        }
     42    }
     43    return JMI_OK;
     44}
     45
     46void jmi_inf_log(jmi_t *jmi, const char func_name[], const char msg[], jmi_real_t res, jmi_real_t x) {
     47    if (((res - res) != 0)) {
     48        if (jmi == NULL) jmi = jmi_get_current();
     49       
     50        if (res > 0) {
     51            /* res is +inf */
     52            char val[64];
     53            sprintf(val, "%.14E", x);
     54            jmi_log_func_or_eq(jmi, "RangeError", func_name, msg, val);
     55        } else if (res < 0){
     56            /* res is -inf */
     57            char val[64];
     58            sprintf(val, "%.14E", x);
     59            jmi_log_func_or_eq(jmi, "RangeError", func_name, msg, val);
     60        }
     61    }
     62}
     63
     64/*Some of these functions return types are a temporary remnant of CppAD*/
     65jmi_ad_var_t static jmi_divide(jmi_t *jmi, const char func_name[], jmi_ad_var_t num, jmi_ad_var_t den, const char msg[]) {
     66    if (den == 0) {
     67        char val[64];
     68        sprintf(val, "%.14E, %.14E", num, den);
     69       
     70        if (jmi == NULL) jmi = jmi_get_current();
     71        jmi_log_func_or_eq(jmi, "DivideByZero", func_name, msg, val);
     72    }
     73   
     74    return num/den;
     75}
     76
     77jmi_ad_var_t jmi_divide_function(const char func_name[], jmi_ad_var_t num, jmi_ad_var_t den, const char msg[]) {
     78    return jmi_divide(NULL, func_name, num, den, msg);
     79}
     80
     81jmi_ad_var_t jmi_divide_equation(jmi_t *jmi, jmi_ad_var_t num, jmi_ad_var_t den, const char msg[]) {
     82    return jmi_divide(jmi, NULL, num, den, msg);
     83}
     84
     85jmi_ad_var_t static jmi_pow(jmi_t *jmi, const char func_name[], jmi_ad_var_t x, jmi_ad_var_t y, const char msg[]) {
     86
     87    jmi_ad_var_t to_return = pow(x, y);
     88   
     89    if ((to_return - to_return) != 0) {
     90        /* The returned value is not a number */
     91        if (jmi == NULL) jmi = jmi_get_current();
     92   
     93        /* Check that the inputs are in the domain of the function*/
     94        if (x > 0 || (x == 0 && y > 0) || (x < 0 && (int)y == y)) {
     95            /* Range problem, will return JMI_INF or -JMI_INF */
     96            char val[64];
     97            sprintf(val, "%.14E, %.14E", x, y);
     98            jmi_log_func_or_eq(jmi, "RangeError", func_name, msg, val);
     99        } else if (x == 0 && y < 0) {
     100            /* Pole error */
     101            char val[64];
     102            sprintf(val, "%.14E, %.14E", x, y);
     103            jmi_log_func_or_eq(jmi, "DivideByZero", func_name, msg, val);
     104        }
     105    }
     106    /* jmi_inf_log(jmi, func_name, msg, to_return); */
     107    return to_return;
     108}
     109
     110jmi_ad_var_t jmi_pow_function(const char func_name[], jmi_ad_var_t x, jmi_ad_var_t y, const char msg[]) {
     111    return jmi_pow(NULL, func_name, x, y, msg);
     112}
     113
     114jmi_ad_var_t jmi_pow_equation(jmi_t *jmi, jmi_ad_var_t x, jmi_ad_var_t y, const char msg[]) {
     115    return jmi_pow(jmi, NULL, x, y, msg);
     116}
     117
     118jmi_ad_var_t static jmi_exp(jmi_t *jmi, const char func_name[], jmi_ad_var_t x, const char msg[]) {
     119
     120    jmi_ad_var_t to_return = exp(x);
     121    jmi_inf_log(jmi, func_name, msg, to_return, x);
     122    return to_return;
     123}
     124
     125jmi_ad_var_t jmi_exp_function(const char func_name[], jmi_ad_var_t x, const char msg[]) {
     126    return jmi_exp(NULL, func_name, x, msg);
     127}
     128
     129jmi_ad_var_t jmi_exp_equation(jmi_t *jmi, jmi_ad_var_t x, const char msg[]) {
     130    return jmi_exp(jmi, NULL, x, msg);
     131}
     132
     133jmi_ad_var_t static jmi_log(jmi_t *jmi, const char func_name[], jmi_ad_var_t x, const char msg[]) {
     134
     135    jmi_ad_var_t to_return = log(x);
     136   
     137    if ((to_return - to_return) != 0) {
     138        /* The returned value is not a number */
     139        if (jmi == NULL) jmi = jmi_get_current();
     140       
     141        if (x == 0) {
     142            /* Pole problem, will return -JMI_INF */
     143            char val[64];
     144            sprintf(val, "%.14E", x);
     145            jmi_log_func_or_eq(jmi, "LogarithmOfZero", func_name, msg, val);
     146        } else if (x > 0) {
     147            /* Range problem, will return JMI_INF */
     148            char val[64];
     149            sprintf(val, "%.14E", x);
     150            jmi_log_func_or_eq(jmi, "LogarithmOfInf", func_name, msg, val);
     151        }
     152    }
     153    return to_return;
     154}
     155
     156jmi_ad_var_t jmi_log_function(const char func_name[], jmi_ad_var_t x, const char msg[]) {
     157    return jmi_log(NULL, func_name, x, msg);
     158}
     159
     160jmi_ad_var_t jmi_log_equation(jmi_t *jmi, jmi_ad_var_t x, const char msg[]) {
     161    return jmi_log(jmi, NULL, x, msg);
     162}
     163
     164jmi_ad_var_t static jmi_log10(jmi_t *jmi, const char func_name[], jmi_ad_var_t x, const char msg[]) {
     165
     166    jmi_ad_var_t to_return = log10(x);
     167   
     168    if ((to_return - to_return) != 0) {
     169        /* The returned value is not a number */
     170        if (jmi == NULL) jmi = jmi_get_current();
     171       
     172        if (x == 0) {
     173            /* Pole problem, will return -JMI_INF */
     174            char val[64];
     175            sprintf(val, "%.14E", x);
     176            jmi_log_func_or_eq(jmi, "LogarithmOfZero", func_name, msg, val);
     177        } else if (x > 0) {
     178            /* Infinity problem, will return JMI_INF */
     179            char val[64];
     180            sprintf(val, "%.14E", x);
     181            jmi_log_func_or_eq(jmi, "LogarithmOfInf", func_name, msg, val);
     182        }
     183    }
     184    return to_return;
     185}
     186
     187jmi_ad_var_t jmi_log10_function(const char func_name[], jmi_ad_var_t x, const char msg[]) {
     188    return jmi_log10(NULL, func_name, x, msg);
     189}
     190
     191jmi_ad_var_t jmi_log10_equation(jmi_t *jmi, jmi_ad_var_t x, const char msg[]) {
     192    return jmi_log10(jmi, NULL, x, msg);
     193}
     194
     195jmi_ad_var_t static jmi_sinh(jmi_t *jmi, const char func_name[], jmi_ad_var_t x, const char msg[]) {
     196
     197    jmi_ad_var_t to_return = sinh(x);
     198    jmi_inf_log(jmi, func_name, msg, to_return, x);
     199    return to_return;
     200}
     201
     202jmi_ad_var_t jmi_sinh_function(const char func_name[], jmi_ad_var_t x, const char msg[]) {
     203    return jmi_sinh(NULL, func_name, x, msg);
     204}
     205
     206jmi_ad_var_t jmi_sinh_equation(jmi_t *jmi, jmi_ad_var_t x, const char msg[]) {
     207    return jmi_sinh(jmi, NULL, x, msg);
     208}
     209
     210jmi_ad_var_t static jmi_cosh(jmi_t *jmi, const char func_name[], jmi_ad_var_t x, const char msg[]) {
     211
     212    jmi_ad_var_t to_return = cosh(x);
     213    jmi_inf_log(jmi, func_name, msg, to_return, x);
     214    return to_return;
     215}
     216
     217jmi_ad_var_t jmi_cosh_function(const char func_name[], jmi_ad_var_t x, const char msg[]) {
     218    return jmi_cosh(NULL, func_name, x, msg);
     219}
     220
     221jmi_ad_var_t jmi_cosh_equation(jmi_t *jmi, jmi_ad_var_t x, const char msg[]) {
     222    return jmi_cosh(jmi, NULL, x, msg);
     223}
     224
     225jmi_ad_var_t static jmi_tan(jmi_t *jmi, const char func_name[], jmi_ad_var_t x, const char msg[]) {
     226
     227    jmi_ad_var_t to_return = tan(x);
     228    jmi_inf_log(jmi, func_name, msg, to_return, x);
     229    return to_return;
     230}
     231
     232jmi_ad_var_t jmi_tan_function(const char func_name[], jmi_ad_var_t x, const char msg[]) {
     233    return jmi_tan(NULL, func_name, x, msg);
     234}
     235
     236jmi_ad_var_t jmi_tan_equation(jmi_t *jmi, jmi_ad_var_t x, const char msg[]) {
     237    return jmi_tan(jmi, NULL, x, msg);
     238}
     239
     240jmi_ad_var_t jmi_abs(jmi_ad_var_t v) {
     241    return COND_EXP_GE(v, AD_WRAP_LITERAL(0), v, -v);
     242}
     243
     244jmi_ad_var_t jmi_sign(jmi_ad_var_t v) {
     245    return COND_EXP_GT(v, AD_WRAP_LITERAL(0), AD_WRAP_LITERAL(1),
     246        COND_EXP_LT(v, AD_WRAP_LITERAL(0), AD_WRAP_LITERAL(-1), AD_WRAP_LITERAL(0)));
     247}
     248
     249jmi_ad_var_t jmi_min(jmi_ad_var_t x, jmi_ad_var_t y) {
     250    return COND_EXP_LT(x, y, x ,y);
     251}
     252
     253jmi_ad_var_t jmi_max(jmi_ad_var_t x, jmi_ad_var_t y) {
     254    return COND_EXP_GT(x, y, x ,y);
     255}
     256
     257jmi_real_t jmi_dround(jmi_real_t x) {
     258        return (x >= 0)? floor(x + 0.5) : floor(x - 0.5);
     259}
     260
     261jmi_real_t jmi_dremainder(jmi_real_t x, jmi_real_t y) {
     262        jmi_real_t res = fmod(x,y);
     263        return (jmi_abs(res-y)<JMI_ALMOST_EPS)? res-y : res;
     264}
     265
     266jmi_ad_var_t jmi_sample(jmi_t* jmi, jmi_real_t offset, jmi_real_t h) {
     267    jmi_real_t t = jmi_get_t(jmi)[0];
     268    if (!jmi->atEvent || SURELY_LT_ZERO(t-offset)) {
     269      /*printf("jmi_sample1: %f %f %12.12f %12.12f\n",offset,fmod((t-offset),h),(t-offset));*/
     270        return JMI_FALSE;
     271    }
     272    /*  printf("jmi_sample2: %f %f %12.12f %12.12f\n",offset,h,fmod((t-offset),h),(t-offset));*/
     273    return ALMOST_ZERO(jmi_dremainder((t-offset),h));
     274}
  • RuntimeLibrary/src/jmi/jmi_math.h

     
     1 /*
     2    Copyright (C) 2016 Modelon AB
     3
     4    This program is free software: you can redistribute it and/or modify
     5    it under the terms of the GNU General Public License version 3 as published
     6    by the Free Software Foundation, or optionally, under the terms of the
     7    Common Public License version 1.0 as published by IBM.
     8
     9    This program is distributed in the hope that it will be useful,
     10    but WITHOUT ANY WARRANTY; without even the implied warranty of
     11    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     12    GNU General Public License, or the Common Public License, for more details.
     13
     14    You should have received copies of the GNU General Public License
     15    and the Common Public License along with this program.  If not,
     16    see <http://www.gnu.org/licenses/> or
     17    <http://www.ibm.com/developerworks/library/os-cpl.html/> respectively.
     18*/
     19
     20
     21/** \file jmi_math.h
     22 *  \brief Mathematical functions used in the run-time and code-gen.
     23 */
     24
     25#ifndef _JMI_MATH_H
     26#define _JMI_MATH_H
     27
     28#include "jmi_types.h"
     29
     30/* Define the machine epsilon */
     31#define JMI_EPS 2.2204460492503131e-16
     32#define JMI_ALMOST_EPS (JMI_EPS*100)
     33
     34/*#define ALMOST_ZERO(op) (jmi_abs(op)<=1e-6? JMI_TRUE: JMI_FALSE)*/
     35#define ALMOST_ZERO(op) LOG_EXP_AND(ALMOST_LT_ZERO(op),ALMOST_GT_ZERO(op))
     36#define ALMOST_LT_ZERO(op) (op<=JMI_ALMOST_EPS? JMI_TRUE: JMI_FALSE)
     37#define ALMOST_GT_ZERO(op) (op>=-JMI_ALMOST_EPS? JMI_TRUE: JMI_FALSE)
     38#define SURELY_LT_ZERO(op) (op<-JMI_ALMOST_EPS? JMI_TRUE: JMI_FALSE)
     39#define SURELY_GT_ZERO(op) (op>JMI_ALMOST_EPS? JMI_TRUE: JMI_FALSE)
     40
     41/**
     42 * Function for checking if a vector contains NAN values. Returns the
     43 * index of the NAN (if found) in the parameter index_of_nan
     44 */
     45int jmi_check_nan(jmi_t *jmi, jmi_real_t* val, size_t n_val, jmi_int_t* index_of_nan);
     46
     47/**
     48 * Function to wrap division and report errors to the log, for use in functions.
     49 */
     50jmi_ad_var_t jmi_divide_function(const char* name, jmi_ad_var_t num, jmi_ad_var_t den, const char* msg);
     51
     52/**
     53 * Function to wrap division and report errors to the log, for use in equations.
     54 */
     55jmi_ad_var_t jmi_divide_equation(jmi_t *jmi, jmi_ad_var_t num, jmi_ad_var_t den, const char* msg);
     56
     57/**
     58 * Function to wrap the C pow function and report errors to the log, for use in functions.
     59 */
     60jmi_ad_var_t jmi_pow_function(const char* name, jmi_ad_var_t x, jmi_ad_var_t y, const char* msg);
     61
     62/**
     63 * Function to wrap the C pow function and report errors to the log, for use in equations.
     64 */
     65jmi_ad_var_t jmi_pow_equation(jmi_t *jmi, jmi_ad_var_t x, jmi_ad_var_t y, const char* msg);
     66
     67/**
     68 * Function to wrap the C exp function and report errors to the log, for use in functions.
     69 */
     70jmi_ad_var_t jmi_exp_function(const char* name, jmi_ad_var_t x, const char* msg);
     71
     72/**
     73 * Function to wrap the C exp function and report errors to the log, for use in equations.
     74 */
     75jmi_ad_var_t jmi_exp_equation(jmi_t *jmi, jmi_ad_var_t x, const char* msg);
     76
     77/**
     78 * Function to wrap the C log function and report errors to the log, for use in functions.
     79 */
     80jmi_ad_var_t jmi_log_function(const char* name, jmi_ad_var_t x, const char* msg);
     81
     82/**
     83 * Function to wrap the C log function and report errors to the log, for use in equations.
     84 */
     85jmi_ad_var_t jmi_log_equation(jmi_t *jmi, jmi_ad_var_t x, const char* msg);
     86
     87/**
     88 * Function to wrap the C log10 function and report errors to the log, for use in functions.
     89 */
     90jmi_ad_var_t jmi_log10_function(const char* name, jmi_ad_var_t x, const char* msg);
     91
     92/**
     93 * Function to wrap the C log10 function and report errors to the log, for use in equations.
     94 */
     95jmi_ad_var_t jmi_log10_equation(jmi_t *jmi, jmi_ad_var_t x, const char* msg);
     96
     97/**
     98 * Function to wrap the C sinh function and report errors to the log, for use in functions.
     99 */
     100jmi_ad_var_t jmi_sinh_function(const char* name, jmi_ad_var_t x, const char* msg);
     101
     102/**
     103 * Function to wrap the C sinh function and report errors to the log, for use in equations.
     104 */
     105jmi_ad_var_t jmi_sinh_equation(jmi_t *jmi, jmi_ad_var_t x, const char* msg);
     106
     107/**
     108 * Function to wrap the C cosh function and report errors to the log, for use in functions.
     109 */
     110jmi_ad_var_t jmi_cosh_function(const char* name, jmi_ad_var_t x, const char* msg);
     111
     112/**
     113 * Function to wrap the C cosh function and report errors to the log, for use in equations.
     114 */
     115jmi_ad_var_t jmi_cosh_equation(jmi_t *jmi, jmi_ad_var_t x, const char* msg);
     116
     117/**
     118 * Function to wrap the C tan function and report errors to the log, for use in functions.
     119 */
     120jmi_ad_var_t jmi_tan_function(const char* name, jmi_ad_var_t x, const char* msg);
     121
     122/**
     123 * Function to wrap the C tan function and report errors to the log, for use in equations.
     124 */
     125jmi_ad_var_t jmi_tan_equation(jmi_t *jmi, jmi_ad_var_t x, const char* msg);
     126
     127/**
     128 * Function to get the absolute value.
     129 * Is a separate function to avoid evaluating expressions several times.
     130 */
     131jmi_ad_var_t jmi_abs(jmi_ad_var_t v);
     132
     133/**
     134 * Function to get the absolute value.
     135 * Is a separate function to avoid evaluating expressions several times.
     136 */
     137jmi_ad_var_t jmi_sign(jmi_ad_var_t v);
     138
     139/**
     140 * Function to get the smaller of two values.
     141 * Is a separate function to avoid evaluating expressions twice.
     142 */
     143jmi_ad_var_t jmi_min(jmi_ad_var_t x, jmi_ad_var_t y);
     144
     145/**
     146 * Function to get the larger of two values.
     147 * Is a separate function to avoid evaluating expressions twice.
     148 */
     149jmi_ad_var_t jmi_max(jmi_ad_var_t x, jmi_ad_var_t y);
     150
     151/**
     152 * The round function for double numbers.
     153 *
     154 */
     155jmi_real_t jmi_dround(jmi_real_t x);
     156
     157/**
     158 * The remainder function for double numbers.
     159 *
     160 */
     161jmi_real_t jmi_dremainder(jmi_real_t x, jmi_real_t y);
     162
     163/**
     164 * The sample operator. Returns true if time = offset + i*h, i>=0 during
     165 * handling of an event. During continuous integration, false is returned.
     166 *
     167 */
     168jmi_ad_var_t jmi_sample(jmi_t* jmi, jmi_real_t offset, jmi_real_t h);
     169
     170#endif /* _JMI_MATH_H */
  • RuntimeLibrary/src/jmi/jmi_me.h

     
    2222
    2323#include "stdio.h"
    2424
    25 #include "jmi.h"
    2625#include "jmi_util.h"
    2726#include "jmi_log.h"
     27#include "jmi_math.h"
     28#include "jmi_types.h"
    2829
    2930typedef unsigned int jmi_value_reference;
    3031
  • RuntimeLibrary/src/jmi/jmi_types.h

     
    2323
    2424#ifndef _JMI_TYPES_H
    2525#define _JMI_TYPES_H
     26
     27#include <stdio.h>
     28
    2629/* Typedef for the doubles used in the interface. */
    2730typedef double jmi_real_t; /*< Typedef for the real number
    2831               < representation used in the Runtime
     
    3639typedef void* jmi_extobj_t; /*< Typedef for the external object
    3740               < representation used in the Runtime
    3841               < Library. */
     42               
     43/* Forward declaration of jmi structs */
     44typedef struct jmi_t jmi_t;                                         /**< \brief Forward declaration of struct. */
     45typedef struct jmi_dae_t jmi_dae_t;                                 /**< \brief Forward declaration of struct. */
     46typedef struct jmi_init_t jmi_init_t;                               /**< \brief Forward declaration of struct. */
     47typedef struct jmi_func_t jmi_func_t;                               /**< \brief Forward declaration of struct. */
     48typedef struct jmi_block_residual_t jmi_block_residual_t;           /**< \brief Forward declaration of struct. */
     49typedef struct jmi_cs_input_t jmi_cs_input_t;                       /**< \brief Forward declaration of struct. */
     50typedef struct jmi_ode_solver_t jmi_ode_solver_t;                   /**< \brief Forward declaration of struct. */
     51typedef struct jmi_ode_problem_t jmi_ode_problem_t;                 /**< \brief Forward declaration of struct. */
     52typedef struct jmi_color_info jmi_color_info;                       /**< \brief Forward declaration of struct. */
     53typedef struct jmi_simple_color_info_t jmi_simple_color_info_t;     /**< \brief Forward declaration of struct. */
     54typedef struct jmi_delay_t jmi_delay_t;                             /**< \brief Forward declaration of struct. */
     55typedef struct jmi_spatialdist_t jmi_spatialdist_t;                 /**< \brief Forward declaration of struct. */
     56typedef struct jmi_dynamic_state_set_t jmi_dynamic_state_set_t;     /**< \brief Forward declaration of struct. */
     57typedef struct jmi_modules_t jmi_modules_t;                         /**< \brief Forward declaration of struct. */
     58typedef struct jmi_module_t jmi_module_t;                           /**< \brief Forward declaration of struct. */
     59typedef struct jmi_chattering_t jmi_chattering_t;                   /**< \brief Forward declaration of struct. */
    3960
    4061#define JMI_MIN(X,Y) ((X) < (Y) ? (X) : (Y))
    4162#define JMI_ABS(X)   ((X) < (0) ? (-1*X) : (X))
  • RuntimeLibrary/src/jmi/jmi_util.c

     
    2828#include "jmi_global.h"
    2929#include <stdio.h>
    3030#include <assert.h>
     31#include "jmi_math.h"
    3132
    3233void jmi_min_time_event(jmi_time_event_t* event, int def, int phase, jmi_ad_var_t time) {
    3334    if (JMI_TRUE == LOG_EXP_OR(LOG_EXP_OR(LOG_EXP_NOT(AD_WRAP_LITERAL(event->defined)), SURELY_GT_ZERO(event->time - time)), LOG_EXP_AND(ALMOST_ZERO(event->time - time), SURELY_GT_ZERO(event->phase - phase)))) {
     
    4344    jmi_log_node(jmi->log, logError, "Error", "Could not throw an exception after internal error", msg);
    4445}
    4546
    46 /* Helper function for logging warnings from the "_equation"- and "_function"-functions below */
    47 void static jmi_log_func_or_eq(jmi_t *jmi, const char cathegory_name[], const char func_name[], const char msg[], const char val[]) {
    48     if (func_name != NULL) {
    49         char buf[64];
    50         sprintf(buf, "%s%s", cathegory_name, "InFunc");
    51         jmi_log_node(jmi->log, logWarning, buf, "<func: %s, exp: %s, val:%s>", func_name, msg, val);
    52     } else {
    53         jmi_log_node(jmi->log, logWarning, cathegory_name, "<exp:%s, val: %s>", msg, val);
    54     }
    55 }
    56 
    57 int jmi_check_nan(jmi_t *jmi, jmi_real_t* val, size_t n_val, jmi_int_t* index_of_nan) {
    58     int i = 0;
    59     for (i = 0; i < n_val; i++) {
    60         if ( val[i] - val[i] != 0) {
    61             *index_of_nan = i;
    62             return JMI_ERROR;
    63         }
    64     }
    65     return JMI_OK;
    66 }
    67 
    68 void jmi_inf_log(jmi_t *jmi, const char func_name[], const char msg[], jmi_real_t res, jmi_real_t x) {
    69     if (((res - res) != 0)) {
    70         if (jmi == NULL) jmi = jmi_get_current();
    71        
    72         if (res > 0) {
    73             /* res is +inf */
    74             char val[64];
    75             sprintf(val, "%.14E", x);
    76             jmi_log_func_or_eq(jmi, "RangeError", func_name, msg, val);
    77         } else if (res < 0){
    78             /* res is -inf */
    79             char val[64];
    80             sprintf(val, "%.14E", x);
    81             jmi_log_func_or_eq(jmi, "RangeError", func_name, msg, val);
    82         }
    83     }
    84 }
    85 
    86 /*Some of these functions return types are a temporary remnant of CppAD*/
    87 jmi_ad_var_t static jmi_divide(jmi_t *jmi, const char func_name[], jmi_ad_var_t num, jmi_ad_var_t den, const char msg[]) {
    88     if (den == 0) {
    89         char val[64];
    90         sprintf(val, "%.14E, %.14E", num, den);
    91        
    92         if (jmi == NULL) jmi = jmi_get_current();
    93         jmi_log_func_or_eq(jmi, "DivideByZero", func_name, msg, val);
    94     }
    95    
    96     return num/den;
    97 }
    98 
    99 jmi_ad_var_t jmi_divide_function(const char func_name[], jmi_ad_var_t num, jmi_ad_var_t den, const char msg[]) {
    100     return jmi_divide(NULL, func_name, num, den, msg);
    101 }
    102 
    103 jmi_ad_var_t jmi_divide_equation(jmi_t *jmi, jmi_ad_var_t num, jmi_ad_var_t den, const char msg[]) {
    104     return jmi_divide(jmi, NULL, num, den, msg);
    105 }
    106 
    107 jmi_ad_var_t static jmi_pow(jmi_t *jmi, const char func_name[], jmi_ad_var_t x, jmi_ad_var_t y, const char msg[]) {
    108 
    109     jmi_ad_var_t to_return = pow(x, y);
    110    
    111     if ((to_return - to_return) != 0) {
    112         /* The returned value is not a number */
    113         if (jmi == NULL) jmi = jmi_get_current();
    114    
    115         /* Check that the inputs are in the domain of the function*/
    116         if (x > 0 || (x == 0 && y > 0) || (x < 0 && (int)y == y)) {
    117             /* Range problem, will return JMI_INF or -JMI_INF */
    118             char val[64];
    119             sprintf(val, "%.14E, %.14E", x, y);
    120             jmi_log_func_or_eq(jmi, "RangeError", func_name, msg, val);
    121         } else if (x == 0 && y < 0) {
    122             /* Pole error */
    123             char val[64];
    124             sprintf(val, "%.14E, %.14E", x, y);
    125             jmi_log_func_or_eq(jmi, "DivideByZero", func_name, msg, val);
    126         }
    127     }
    128     /* jmi_inf_log(jmi, func_name, msg, to_return); */
    129     return to_return;
    130 }
    131 
    132 jmi_ad_var_t jmi_pow_function(const char func_name[], jmi_ad_var_t x, jmi_ad_var_t y, const char msg[]) {
    133     return jmi_pow(NULL, func_name, x, y, msg);
    134 }
    135 
    136 jmi_ad_var_t jmi_pow_equation(jmi_t *jmi, jmi_ad_var_t x, jmi_ad_var_t y, const char msg[]) {
    137     return jmi_pow(jmi, NULL, x, y, msg);
    138 }
    139 
    140 jmi_ad_var_t static jmi_exp(jmi_t *jmi, const char func_name[], jmi_ad_var_t x, const char msg[]) {
    141 
    142     jmi_ad_var_t to_return = exp(x);
    143     jmi_inf_log(jmi, func_name, msg, to_return, x);
    144     return to_return;
    145 }
    146 
    147 jmi_ad_var_t jmi_exp_function(const char func_name[], jmi_ad_var_t x, const char msg[]) {
    148     return jmi_exp(NULL, func_name, x, msg);
    149 }
    150 
    151 jmi_ad_var_t jmi_exp_equation(jmi_t *jmi, jmi_ad_var_t x, const char msg[]) {
    152     return jmi_exp(jmi, NULL, x, msg);
    153 }
    154 
    155 jmi_ad_var_t static jmi_log(jmi_t *jmi, const char func_name[], jmi_ad_var_t x, const char msg[]) {
    156 
    157     jmi_ad_var_t to_return = log(x);
    158    
    159     if ((to_return - to_return) != 0) {
    160         /* The returned value is not a number */
    161         if (jmi == NULL) jmi = jmi_get_current();
    162        
    163         if (x == 0) {
    164             /* Pole problem, will return -JMI_INF */
    165             char val[64];
    166             sprintf(val, "%.14E", x);
    167             jmi_log_func_or_eq(jmi, "LogarithmOfZero", func_name, msg, val);
    168         } else if (x > 0) {
    169             /* Range problem, will return JMI_INF */
    170             char val[64];
    171             sprintf(val, "%.14E", x);
    172             jmi_log_func_or_eq(jmi, "LogarithmOfInf", func_name, msg, val);
    173         }
    174     }
    175     return to_return;
    176 }
    177 
    178 jmi_ad_var_t jmi_log_function(const char func_name[], jmi_ad_var_t x, const char msg[]) {
    179     return jmi_log(NULL, func_name, x, msg);
    180 }
    181 
    182 jmi_ad_var_t jmi_log_equation(jmi_t *jmi, jmi_ad_var_t x, const char msg[]) {
    183     return jmi_log(jmi, NULL, x, msg);
    184 }
    185 
    186 jmi_ad_var_t static jmi_log10(jmi_t *jmi, const char func_name[], jmi_ad_var_t x, const char msg[]) {
    187 
    188     jmi_ad_var_t to_return = log10(x);
    189    
    190     if ((to_return - to_return) != 0) {
    191         /* The returned value is not a number */
    192         if (jmi == NULL) jmi = jmi_get_current();
    193        
    194         if (x == 0) {
    195             /* Pole problem, will return -JMI_INF */
    196             char val[64];
    197             sprintf(val, "%.14E", x);
    198             jmi_log_func_or_eq(jmi, "LogarithmOfZero", func_name, msg, val);
    199         } else if (x > 0) {
    200             /* Infinity problem, will return JMI_INF */
    201             char val[64];
    202             sprintf(val, "%.14E", x);
    203             jmi_log_func_or_eq(jmi, "LogarithmOfInf", func_name, msg, val);
    204         }
    205     }
    206     return to_return;
    207 }
    208 
    209 jmi_ad_var_t jmi_log10_function(const char func_name[], jmi_ad_var_t x, const char msg[]) {
    210     return jmi_log10(NULL, func_name, x, msg);
    211 }
    212 
    213 jmi_ad_var_t jmi_log10_equation(jmi_t *jmi, jmi_ad_var_t x, const char msg[]) {
    214     return jmi_log10(jmi, NULL, x, msg);
    215 }
    216 
    217 jmi_ad_var_t static jmi_sinh(jmi_t *jmi, const char func_name[], jmi_ad_var_t x, const char msg[]) {
    218 
    219     jmi_ad_var_t to_return = sinh(x);
    220     jmi_inf_log(jmi, func_name, msg, to_return, x);
    221     return to_return;
    222 }
    223 
    224 jmi_ad_var_t jmi_sinh_function(const char func_name[], jmi_ad_var_t x, const char msg[]) {
    225     return jmi_sinh(NULL, func_name, x, msg);
    226 }
    227 
    228 jmi_ad_var_t jmi_sinh_equation(jmi_t *jmi, jmi_ad_var_t x, const char msg[]) {
    229     return jmi_sinh(jmi, NULL, x, msg);
    230 }
    231 
    232 jmi_ad_var_t static jmi_cosh(jmi_t *jmi, const char func_name[], jmi_ad_var_t x, const char msg[]) {
    233 
    234     jmi_ad_var_t to_return = cosh(x);
    235     jmi_inf_log(jmi, func_name, msg, to_return, x);
    236     return to_return;
    237 }
    238 
    239 jmi_ad_var_t jmi_cosh_function(const char func_name[], jmi_ad_var_t x, const char msg[]) {
    240     return jmi_cosh(NULL, func_name, x, msg);
    241 }
    242 
    243 jmi_ad_var_t jmi_cosh_equation(jmi_t *jmi, jmi_ad_var_t x, const char msg[]) {
    244     return jmi_cosh(jmi, NULL, x, msg);
    245 }
    246 
    247 jmi_ad_var_t static jmi_tan(jmi_t *jmi, const char func_name[], jmi_ad_var_t x, const char msg[]) {
    248 
    249     jmi_ad_var_t to_return = tan(x);
    250     jmi_inf_log(jmi, func_name, msg, to_return, x);
    251     return to_return;
    252 }
    253 
    254 jmi_ad_var_t jmi_tan_function(const char func_name[], jmi_ad_var_t x, const char msg[]) {
    255     return jmi_tan(NULL, func_name, x, msg);
    256 }
    257 
    258 jmi_ad_var_t jmi_tan_equation(jmi_t *jmi, jmi_ad_var_t x, const char msg[]) {
    259     return jmi_tan(jmi, NULL, x, msg);
    260 }
    261 
    26247void jmi_flag_termination(jmi_t *jmi, const char* msg) {
    26348    jmi->model_terminate = 1;
    26449    /* TODO: This is an informative message, not a warning, but is rather important. Change once log level is made separate from message category. */
     
    26550    jmi_log_node(jmi->log, logWarning, "SimulationTerminated", "<msg:%s>", msg);
    26651}
    26752
    268 jmi_ad_var_t jmi_abs(jmi_ad_var_t v) {
    269     return COND_EXP_GE(v, AD_WRAP_LITERAL(0), v, -v);
    270 }
    271 
    272 jmi_ad_var_t jmi_sign(jmi_ad_var_t v) {
    273     return COND_EXP_GT(v, AD_WRAP_LITERAL(0), AD_WRAP_LITERAL(1),
    274         COND_EXP_LT(v, AD_WRAP_LITERAL(0), AD_WRAP_LITERAL(-1), AD_WRAP_LITERAL(0)));
    275 }
    276 
    277 jmi_ad_var_t jmi_min(jmi_ad_var_t x, jmi_ad_var_t y) {
    278     return COND_EXP_LT(x, y, x ,y);
    279 }
    280 
    281 jmi_ad_var_t jmi_max(jmi_ad_var_t x, jmi_ad_var_t y) {
    282     return COND_EXP_GT(x, y, x ,y);
    283 }
    284 
    285 jmi_real_t jmi_dround(jmi_real_t x) {
    286         return (x >= 0)? floor(x + 0.5) : floor(x - 0.5);
    287 }
    288 
    289 jmi_real_t jmi_dremainder(jmi_real_t x, jmi_real_t y) {
    290         jmi_real_t res = fmod(x,y);
    291         return (jmi_abs(res-y)<JMI_ALMOST_EPS)? res-y : res;
    292 }
    293 
    294 
    29553int jmi_func_new(jmi_func_t** jmi_func, jmi_residual_func_t F, int n_eq_F, jmi_jacobian_func_t sym_dF,
    29654        int sym_dF_n_nz, int* sym_dF_row, int* sym_dF_col,jmi_directional_der_residual_func_t cad_dir_dF,
    29755        int cad_dF_n_nz, int* cad_dF_row, int* cad_dF_col) {
  • RuntimeLibrary/src/jmi/jmi_util.h

     
    3636#include "jmi_block_solver.h"
    3737
    3838#include "jmi_dyn_mem.h"
     39#include "jmi_types.h"
     40#include "jmi_math.h"
    3941
    4042/**
    4143 * \defgroup Jmi_internal Internal functions of the JMI Model \
     
    105107 *  Introduce #defines to denote different error codes
    106108 */
    107109
    108 /* Forward declaration of jmi structs */
    109 typedef struct jmi_t jmi_t;                               /**< \brief Forward declaration of struct. */
    110 typedef struct jmi_dae_t jmi_dae_t;                       /**< \brief Forward declaration of struct. */
    111 typedef struct jmi_init_t jmi_init_t;                     /**< \brief Forward declaration of struct. */
    112 typedef struct jmi_func_t jmi_func_t;                     /**< \brief Forward declaration of struct. */
    113 typedef struct jmi_block_residual_t jmi_block_residual_t; /**< \brief Forward declaration of struct. */
    114 typedef struct jmi_cs_input_t jmi_cs_input_t;             /**< \brief Forward declaration of struct. */
    115 typedef struct jmi_ode_solver_t jmi_ode_solver_t;         /**< \brief Forward declaration of struct. */
    116 typedef struct jmi_ode_problem_t jmi_ode_problem_t;       /**< \brief Forward declaration of struct. */
    117 typedef struct jmi_color_info jmi_color_info;             /**< \brief Forward declaration of struct. */
    118 typedef struct jmi_simple_color_info_t jmi_simple_color_info_t;      /**< \brief Forward declaration of struct. */
    119 typedef struct jmi_delay_t jmi_delay_t;                   /**< \brief Forward declaration of struct. */
    120 typedef struct jmi_spatialdist_t jmi_spatialdist_t;       /**< \brief Forward declaration of struct. */
    121 typedef struct jmi_dynamic_state_set_t jmi_dynamic_state_set_t;       /**< \brief Forward declaration of struct. */
    122 typedef struct jmi_modules_t jmi_modules_t;               /**< \brief Forward declaration of struct. */
    123 typedef struct jmi_module_t jmi_module_t;                 /**< \brief Forward declaration of struct. */
    124 
    125110typedef struct _jmi_time_event_t {
    126111    int defined;
    127112    int phase;
     
    158143#define LOG_EXP_AND(op1,op2) ((op1)*(op2))           /**< \brief Macro for logical expression and <br> */
    159144#define LOG_EXP_NOT(op)      (JMI_TRUE-(op))         /**< \brief Macro for logical expression not <br> */
    160145
    161 /* Define the machine epsilon */
    162 #define JMI_EPS 2.2204460492503131e-16
    163 #define JMI_ALMOST_EPS (JMI_EPS*100)
    164 
    165 /*#define ALMOST_ZERO(op) (jmi_abs(op)<=1e-6? JMI_TRUE: JMI_FALSE)*/
    166 #define ALMOST_ZERO(op) LOG_EXP_AND(ALMOST_LT_ZERO(op),ALMOST_GT_ZERO(op))
    167 #define ALMOST_LT_ZERO(op) (op<=JMI_ALMOST_EPS? JMI_TRUE: JMI_FALSE)
    168 #define ALMOST_GT_ZERO(op) (op>=-JMI_ALMOST_EPS? JMI_TRUE: JMI_FALSE)
    169 #define SURELY_LT_ZERO(op) (op<-JMI_ALMOST_EPS? JMI_TRUE: JMI_FALSE)
    170 #define SURELY_GT_ZERO(op) (op>JMI_ALMOST_EPS? JMI_TRUE: JMI_FALSE)
    171 
    172 
    173146/* Record creation macro */
    174147#define JMI_RECORD_STATIC(type, name) \
    175148    type name##_rec = {0};\
     
    192165/*Some of these functions return types are a temporary remnants of CppAD*/
    193166
    194167/**
    195  * Function for checking if a vector contains NAN values. Returns the
    196  * index of the NAN (if found) in the parameter index_of_nan
    197  */
    198 int jmi_check_nan(jmi_t *jmi, jmi_real_t* val, size_t n_val, jmi_int_t* index_of_nan);
    199 /**
    200  * Function to wrap division and report errors to the log, for use in functions.
    201  */
    202 jmi_ad_var_t jmi_divide_function(const char* name, jmi_ad_var_t num, jmi_ad_var_t den, const char* msg);
    203 
    204 /**
    205  * Function to wrap division and report errors to the log, for use in equations.
    206  */
    207 jmi_ad_var_t jmi_divide_equation(jmi_t *jmi, jmi_ad_var_t num, jmi_ad_var_t den, const char* msg);
    208 
    209 /**
    210  * Function to wrap the C pow function and report errors to the log, for use in functions.
    211  */
    212 jmi_ad_var_t jmi_pow_function(const char* name, jmi_ad_var_t x, jmi_ad_var_t y, const char* msg);
    213 
    214 /**
    215  * Function to wrap the C pow function and report errors to the log, for use in equations.
    216  */
    217 jmi_ad_var_t jmi_pow_equation(jmi_t *jmi, jmi_ad_var_t x, jmi_ad_var_t y, const char* msg);
    218 
    219 /**
    220  * Function to wrap the C exp function and report errors to the log, for use in functions.
    221  */
    222 jmi_ad_var_t jmi_exp_function(const char* name, jmi_ad_var_t x, const char* msg);
    223 
    224 /**
    225  * Function to wrap the C exp function and report errors to the log, for use in equations.
    226  */
    227 jmi_ad_var_t jmi_exp_equation(jmi_t *jmi, jmi_ad_var_t x, const char* msg);
    228 
    229 /**
    230  * Function to wrap the C log function and report errors to the log, for use in functions.
    231  */
    232 jmi_ad_var_t jmi_log_function(const char* name, jmi_ad_var_t x, const char* msg);
    233 
    234 /**
    235  * Function to wrap the C log function and report errors to the log, for use in equations.
    236  */
    237 jmi_ad_var_t jmi_log_equation(jmi_t *jmi, jmi_ad_var_t x, const char* msg);
    238 
    239 /**
    240  * Function to wrap the C log10 function and report errors to the log, for use in functions.
    241  */
    242 jmi_ad_var_t jmi_log10_function(const char* name, jmi_ad_var_t x, const char* msg);
    243 
    244 /**
    245  * Function to wrap the C log10 function and report errors to the log, for use in equations.
    246  */
    247 jmi_ad_var_t jmi_log10_equation(jmi_t *jmi, jmi_ad_var_t x, const char* msg);
    248 
    249 /**
    250  * Function to wrap the C sinh function and report errors to the log, for use in functions.
    251  */
    252 jmi_ad_var_t jmi_sinh_function(const char* name, jmi_ad_var_t x, const char* msg);
    253 
    254 /**
    255  * Function to wrap the C sinh function and report errors to the log, for use in equations.
    256  */
    257 jmi_ad_var_t jmi_sinh_equation(jmi_t *jmi, jmi_ad_var_t x, const char* msg);
    258 
    259 /**
    260  * Function to wrap the C cosh function and report errors to the log, for use in functions.
    261  */
    262 jmi_ad_var_t jmi_cosh_function(const char* name, jmi_ad_var_t x, const char* msg);
    263 
    264 /**
    265  * Function to wrap the C cosh function and report errors to the log, for use in equations.
    266  */
    267 jmi_ad_var_t jmi_cosh_equation(jmi_t *jmi, jmi_ad_var_t x, const char* msg);
    268 
    269 /**
    270  * Function to wrap the C tan function and report errors to the log, for use in functions.
    271  */
    272 jmi_ad_var_t jmi_tan_function(const char* name, jmi_ad_var_t x, const char* msg);
    273 
    274 /**
    275  * Function to wrap the C tan function and report errors to the log, for use in equations.
    276  */
    277 jmi_ad_var_t jmi_tan_equation(jmi_t *jmi, jmi_ad_var_t x, const char* msg);
    278 
    279 /**
    280168 * Set the terminate flag and log message.
    281169 */
    282170void jmi_flag_termination(jmi_t *jmi, const char* msg);
    283171
    284 /**
    285  * Function to get the absolute value.
    286  * Is a separate function to avoid evaluating expressions several times.
    287  */
    288 jmi_ad_var_t jmi_abs(jmi_ad_var_t v);
    289 
    290 /**
    291  * Function to get the absolute value.
    292  * Is a separate function to avoid evaluating expressions several times.
    293  */
    294 jmi_ad_var_t jmi_sign(jmi_ad_var_t v);
    295 
    296 /**
    297  * Function to get the smaller of two values.
    298  * Is a separate function to avoid evaluating expressions twice.
    299  */
    300 jmi_ad_var_t jmi_min(jmi_ad_var_t x, jmi_ad_var_t y);
    301 
    302 /**
    303  * Function to get the larger of two values.
    304  * Is a separate function to avoid evaluating expressions twice.
    305  */
    306 jmi_ad_var_t jmi_max(jmi_ad_var_t x, jmi_ad_var_t y);
    307 
    308 /**
    309  * The sample operator. Returns true if time = offset + i*h, i>=0 during
    310  * handling of an event. During continuous integration, false is returned.
    311  *
    312  */
    313 jmi_ad_var_t jmi_sample(jmi_t* jmi, jmi_real_t offset, jmi_real_t h);
    314 
    315 /**
    316  * The round function for double numbers.
    317  *
    318  */
    319 jmi_real_t jmi_dround(jmi_real_t x);
    320 
    321 /**
    322  * The remainder function for double numbers.
    323  *
    324  */
    325 jmi_real_t jmi_dremainder(jmi_real_t x, jmi_real_t y);
    326 
    327172/* @} */
    328173
    329174/**