Skip to content

Commit

Permalink
- use the appropriate types everywhere in SimulationRuntime/c/
Browse files Browse the repository at this point in the history
  f2c defines subroutine as typedef /* Subroutine */ int (*S_fp)(...);
  so use that as the type of the functions sent in to the solvers.
- enable -Wall in MinGW makefiles and get rid of most of the -Wall warnings.

git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@15840 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
adrpo committed Apr 17, 2013
1 parent cf765cb commit 412f060
Show file tree
Hide file tree
Showing 13 changed files with 82 additions and 67 deletions.
9 changes: 5 additions & 4 deletions SimulationRuntime/c/simulation/simulation_info_xml.c
Expand Up @@ -33,13 +33,14 @@
#include <expat.h>
#include <errno.h>
#include <string.h>
#include <stdio.h>

static void XMLCALL startElement(void *userData, const char *name, const char **attr) {
MODEL_DATA_XML* xml = (MODEL_DATA_XML*) ((void**)userData)[0];
long curIndex = (long) ((void**)userData)[1];
long curProfileIndex = (long) ((void**)userData)[2];
//long curProfileIndex = (long) ((void**)userData)[2];
long curFunctionIndex = (long) ((void**)userData)[3];
int i;

if (0==strcmp("equation",name)) {
long ix;
if (curIndex > xml->nEquations) {
Expand Down Expand Up @@ -154,14 +155,14 @@ EQUATION_INFO modelInfoXmlGetEquationIndexByProfileBlock(MODEL_DATA_XML* xml, si
modelInfoXmlInit(xml);
}
if (ix < 0 || ix > xml->nProfileBlocks) {
THROW2("Requested equation with profiler index %ld, but we only have %ld such blocks", ix, xml->nProfileBlocks);
THROW2("Requested equation with profiler index %ld, but we only have %ld such blocks", (long int)ix, xml->nProfileBlocks);
}
for (i=0; i<xml->nEquations; i++) {
if (xml->equationInfo[i].profileBlockIndex == ix) {
return xml->equationInfo[i];
}
}
THROW1("Requested equation with profiler index %ld, but could not find it!", ix);
THROW1("Requested equation with profiler index %ld, but could not find it!", (long int)ix);
}

void freeModelInfoXml(MODEL_DATA_XML* xml) {
Expand Down
2 changes: 1 addition & 1 deletion SimulationRuntime/c/simulation/simulation_input_xml.cpp
Expand Up @@ -346,7 +346,7 @@ void read_input_xml(int argc, char **argv,
{
WARNING(LOG_SIMULATION, "Error, input data file does not match model.");
INDENT(LOG_SIMULATION);
WARNING2(LOG_SIMULATION, "nx in setup file: %ld from model code: %d", nxchk, modelData->nStates);
WARNING2(LOG_SIMULATION, "nx in setup file: %ld from model code: %d", nxchk, (int)modelData->nStates);
WARNING2(LOG_SIMULATION, "ny in setup file: %ld from model code: %ld", nychk, modelData->nVariablesReal - 2*modelData->nStates);
WARNING2(LOG_SIMULATION, "np in setup file: %ld from model code: %ld", npchk, modelData->nParametersReal);
WARNING2(LOG_SIMULATION, "npint in setup file: %ld from model code: %ld", npintchk, modelData->nParametersInteger);
Expand Down
6 changes: 3 additions & 3 deletions SimulationRuntime/c/simulation/simulation_runtime.cpp
Expand Up @@ -474,7 +474,7 @@ int startNonInteractiveSimulation(int argc, char**argv, DATA* data)
const char* lintime = omc_flagValue[FLAG_L];

/* activated measure time option with LOG_STATS */
if(ACTIVE_STREAM(LOG_STATS) || omc_flag[FLAG_CPU] && !measure_time_flag)
if(ACTIVE_STREAM(LOG_STATS) || (omc_flag[FLAG_CPU] && !measure_time_flag))
{
measure_time_flag = 1;
measureSimTime = 1;
Expand All @@ -486,7 +486,7 @@ int startNonInteractiveSimulation(int argc, char**argv, DATA* data)
{ /* Setup the clock */
enum omc_rt_clock_t clock = OMC_CLOCK_REALTIME;
const char *clockName;
if (clockName=omc_flagValue[FLAG_CLOCK]) {
if ((clockName = omc_flagValue[FLAG_CLOCK]) != NULL) {
if (0==strcmp(clockName, "CPU")) {
clock = OMC_CLOCK_CPUTIME;
} else if (0==strcmp(clockName, "RT")) {
Expand All @@ -496,7 +496,7 @@ int startNonInteractiveSimulation(int argc, char**argv, DATA* data)
}
}
if (rt_set_clock(clock)) {
WARNING1(LOG_STDOUT, "Chosen clock-type not available for the current platform. Defaulting to real-time.", clockName);
WARNING1(LOG_STDOUT, "Chosen clock-type: %s not available for the current platform. Defaulting to real-time.", clockName);
}
}

Expand Down
16 changes: 8 additions & 8 deletions SimulationRuntime/c/simulation/solver/dassl.c
Expand Up @@ -288,10 +288,10 @@ int dasrt_step(DATA* simData, SOLVER_INFO* solverInfo)
return retVal;
}

INFO2(LOG_DDASRT, "Calling DDASRT from %.10f to %.10f", solverInfo->currentTime, tout);
INFO2(LOG_DDASRT, "Calling DDASRT from %.15g to %.15g", solverInfo->currentTime, tout);
do
{
INFO2(LOG_SOLVER, "Start step %.10f to %.10f", solverInfo->currentTime, tout);
INFO2(LOG_SOLVER, "Start step %.15g to %.15g", solverInfo->currentTime, tout);
if(dasslData->idid == 1)
{
/* rotate RingBuffer before step is calculated */
Expand Down Expand Up @@ -399,16 +399,16 @@ int dasrt_step(DATA* simData, SOLVER_INFO* solverInfo)
{
INFO(LOG_DDASRT, "dassl call staistics: ");
INDENT(LOG_DDASRT);
INFO1(LOG_DDASRT, "value of idid: %d", dasslData->idid);
INFO1(LOG_DDASRT, "value of idid: %d", (int)dasslData->idid);
INFO1(LOG_DDASRT, "current time value: %0.4g", solverInfo->currentTime);
INFO1(LOG_DDASRT, "current integration time value: %0.4g", dasslData->rwork[3]);
INFO1(LOG_DDASRT, "step size H to be attempted on next step: %0.4g", dasslData->rwork[2]);
INFO1(LOG_DDASRT, "step size used on last successful step: %0.4g", dasslData->rwork[6]);
INFO1(LOG_DDASRT, "number of steps taken so far: %d", dasslData->iwork[10]);
INFO1(LOG_DDASRT, "number of calls of functionODE() : %d", dasslData->iwork[11]);
INFO1(LOG_DDASRT, "number of calculation of jacobian : %d", dasslData->iwork[12]);
INFO1(LOG_DDASRT, "total number of convergence test failures: %d", dasslData->iwork[13]);
INFO1(LOG_DDASRT, "total number of error test failures: %d", dasslData->iwork[14]);
INFO1(LOG_DDASRT, "number of steps taken so far: %d", (int)dasslData->iwork[10]);
INFO1(LOG_DDASRT, "number of calls of functionODE() : %d", (int)dasslData->iwork[11]);
INFO1(LOG_DDASRT, "number of calculation of jacobian : %d", (int)dasslData->iwork[12]);
INFO1(LOG_DDASRT, "total number of convergence test failures: %d", (int)dasslData->iwork[13]);
INFO1(LOG_DDASRT, "total number of error test failures: %d", (int)dasslData->iwork[14]);
RELEASE(LOG_DDASRT);
}

Expand Down
Expand Up @@ -80,7 +80,7 @@ static void NelderMeadOptimization(INIT_DATA* initData,

double fxr;
double fxe;
double fxk;
double fxk = 0;

long xb = 0; /* best vertex */
long xs = 0; /* worst vertex */
Expand Down
6 changes: 3 additions & 3 deletions SimulationRuntime/c/simulation/solver/linearSolverLapack.c
Expand Up @@ -97,7 +97,7 @@ int solveLapack(DATA *data, int sysNumber)

/* We are given the number of the linear system.
* We want to look it up among all equations. */
int eqSystemNumber = systemData->equationIndex;
// int eqSystemNumber = systemData->equationIndex;
int success = 1;

/* reset matrix A */
Expand All @@ -119,14 +119,14 @@ int solveLapack(DATA *data, int sysNumber)

if(solverData->info < 0)
{
WARNING3(LOG_STDOUT, "Error solving linear system of equations (no. %d) at time %f. Argument %d illegal.", (int)systemData->equationIndex, data->localData[0]->timeValue, solverData->info);
WARNING3(LOG_STDOUT, "Error solving linear system of equations (no. %d) at time %f. Argument %d illegal.", (int)systemData->equationIndex, data->localData[0]->timeValue, (int)solverData->info);
success = 0;
}
else if(solverData->info > 0)
{
WARNING4(LOG_STDOUT,
"Failed to solve linear system of equations (no. %d) at time %f, system is singular for U[%d, %d].",
(int)systemData->equationIndex, data->localData[0]->timeValue, solverData->info+1, solverData->info+1);
(int)systemData->equationIndex, data->localData[0]->timeValue, (int)solverData->info+1, (int)solverData->info+1);

/* debug output */
if (ACTIVE_STREAM(LOG_LS))
Expand Down
1 change: 1 addition & 0 deletions SimulationRuntime/c/simulation/solver/model_help.c
Expand Up @@ -38,6 +38,7 @@
#include "omc_error.h"
#include "varinfo.h"
#include "model_help.h"
#include "simulation_info_xml.h"

static const int IterationMax = 200;
const size_t SIZERINGBUFFER = 3;
Expand Down
30 changes: 16 additions & 14 deletions SimulationRuntime/c/simulation/solver/nonlinearSolverHybrd.c
Expand Up @@ -57,31 +57,31 @@ typedef struct DATA_HYBRD
double* x;
double* fvec;
double xtol;
int maxfev;
integer maxfev;
int ml;
int mu;
double epsfcn;
double* diag;
double* diagres;
int mode;
integer mode;
double factor;
int nprint;
int info;
int nfev;
int njev;
integer nprint;
integer info;
integer nfev;
integer njev;
double* fjac;
double* fjacobian;
int ldfjac;
integer ldfjac;
double* r__;
int lr;
integer lr;
double* qtf;
double* wa1;
double* wa2;
double* wa3;
double* wa4;
} DATA_HYBRD;

static void wrapper_fvec_hybrj(int* n, double* x, double* f, double* fjac, int* ldjac, int* iflag, void* data);
static int wrapper_fvec_hybrj(integer* n, double* x, double* f, double* fjac, integer* ldjac, integer* iflag, void* data);

/*! \fn allocate memory for nonlinear system solver hybrd
*
Expand Down Expand Up @@ -165,7 +165,7 @@ int freeHybrdData(void **voiddata)
*
* \author wbraun
*/
static void printVector(const double *vector, const int *size, const int logLevel, const char *name)
static void printVector(const double *vector, integer *size, const int logLevel, const char *name)
{
int i;

Expand Down Expand Up @@ -319,14 +319,14 @@ static int getAnalyticalJacobian(DATA* data, double* jac)
*
*
*/
static void wrapper_fvec_hybrj(int* n, double* x, double* f, double* fjac, int* ldjac, int* iflag, void* data){
static int wrapper_fvec_hybrj(integer* n, double* x, double* f, double* fjac, integer* ldjac, integer* iflag, void* data){

int i, currentSys = ((DATA*)data)->simulationInfo.currentNonlinearSystemIndex;
NONLINEAR_SYSTEM_DATA* systemData = &(((DATA*)data)->simulationInfo.nonlinearSystemData[currentSys]);
DATA_HYBRD* solverData = (DATA_HYBRD*)(systemData->solverData);

/* debug output */
INFO1(LOG_NLS_V, "# Call wrapper function with mode %d", *iflag);
INFO1(LOG_NLS_V, "# Call wrapper function with mode %d", (int)*iflag);
INDENT(LOG_NLS_V);

switch(*iflag)
Expand Down Expand Up @@ -371,6 +371,7 @@ static void wrapper_fvec_hybrj(int* n, double* x, double* f, double* fjac, int*
break;
}
RELEASE(LOG_NLS_V);
return 0;
}

/*! \fn solve non-linear system with hybrd method
Expand All @@ -390,7 +391,8 @@ int solveHybrd(DATA *data, int sysNumber)
*/
int eqSystemNumber = systemData->equationIndex;

int i, j, iflag=1;
int i, j;
integer iflag = 1;
double xerror, xerror_scaled;
int success = 0;
double local_tol = 1e-12;
Expand Down Expand Up @@ -542,7 +544,7 @@ int solveHybrd(DATA *data, int sysNumber)
{
char buffer[4096];

INFO2(LOG_NLS_JAC, "jacobian matrix [%dx%d]", solverData->n, solverData->n);
INFO2(LOG_NLS_JAC, "jacobian matrix [%dx%d]", (int)solverData->n, (int)solverData->n);
INDENT(LOG_NLS_JAC);
for(i=0; i<solverData->n; i++)
{
Expand Down
18 changes: 9 additions & 9 deletions SimulationRuntime/c/simulation/solver/nonlinearSolverHybrd.h
Expand Up @@ -48,19 +48,19 @@ extern "C" {
#endif

extern
void * _omc_hybrj_(void(*) (integer*, double*, double*, double *, int*, int*, void* data),
integer *n,double*x,double*fvec,double*fjac,int *ldfjac,double*xtol,int* maxfev,
double* diag,int *mode,double*factor,int *nprint,int*info,int*nfev,int*njev,
double* r,int *lr,double*qtf,double*wa1,double*wa2,
int _omc_hybrj_(int(*) (integer*, double*, double*, double *, integer*, integer*, void* data),
integer *n,double*x,double*fvec,double*fjac,integer *ldfjac,double*xtol,integer* maxfev,
double* diag,integer *mode,double*factor, integer *nprint,integer* info, integer* nfev, integer* njev,
double* r, integer *lr,double*qtf,double*wa1,double*wa2,
double* wa3,double* wa4, void* userdata);

extern
void _omc_hybrd_(void (*) (integer*, double *, double*, int*, void*),
int _omc_hybrd_(int (*) (integer*, double *, double*, integer*, void*),
integer* n, double* x ,double* fvec, double* xtol,
int* maxfev, int* ml, int* mu, double* epsfcn, double* diag,
int* mode, double* factor, int* nprint, int* info, int* nfev,
double* fjac, double* fjacobian, int* ldfjac, double* r__,
int* lr, double* qtf, double* wa1, double* wa2, double* wa3,
integer* maxfev, integer* ml, integer* mu, double* epsfcn, double* diag,
integer* mode, double* factor, integer* nprint, integer* info, integer* nfev,
double* fjac, double* fjacobian, integer* ldfjac, double* r__,
integer* lr, double* qtf, double* wa1, double* wa2, double* wa3,
double* wa4, void* userdata);

#ifdef __cplusplus
Expand Down
45 changes: 23 additions & 22 deletions SimulationRuntime/c/simulation/solver/nonlinearSolverNewton.c
Expand Up @@ -57,20 +57,20 @@ typedef struct DATA_NEWTON
double* fvec;
double xtol;
double ftol;
int nfev;
int maxfev;
int info;
integer nfev;
integer maxfev;
integer info;
double epsfcn;
double* fjac;
double* rwork;
integer* iwork;
} DATA_NEWTON;


static int _omc_newton(integer* n, double *x, double *fvec, double* eps, double* fdeps, int* maxfev,
int* nfev, void(*f)(integer*, double*, double*, int*, void*),
static int _omc_newton(integer* n, double *x, double *fvec, double* eps, double* fdeps, integer* maxfev,
integer* nfev, int(*f)(integer*, double*, double*, integer*, void*),
double* fjac, double* rwork, integer* iwork,
int* info, void* userdata);
integer* info, void* userdata);

#ifdef __cplusplus
extern "C" {
Expand Down Expand Up @@ -193,14 +193,15 @@ int getAnalyticalJacobianNewton(DATA* data, double* jac)
*
*
*/
static void wrapper_fvec_newton(integer* n, double* x, double* f, int* iflag, void* data){
static int wrapper_fvec_newton(integer* n, double* x, double* f, integer* iflag, void* data){

int i,currentSys = ((DATA*)data)->simulationInfo.currentNonlinearSystemIndex;
NONLINEAR_SYSTEM_DATA* systemData = &(((DATA*)data)->simulationInfo.nonlinearSystemData[currentSys]);
DATA_NEWTON* solverData = (DATA_NEWTON*)(systemData->solverData);
int currentSys = ((DATA*)data)->simulationInfo.currentNonlinearSystemIndex;
//NONLINEAR_SYSTEM_DATA* systemData = &(((DATA*)data)->simulationInfo.nonlinearSystemData[currentSys]);
//DATA_NEWTON* solverData = (DATA_NEWTON*)(systemData->solverData);

(*((DATA*)data)->simulationInfo.nonlinearSystemData[currentSys].residualFunc)(data,
x, f, iflag);
return 0;
}


Expand All @@ -224,7 +225,7 @@ int solveNewton(DATA *data, int sysNumber) {
*/
int eqSystemNumber = systemData->equationIndex;

int i, iflag=0;
int i;
double xerror, xerror_scaled;
char success = 0;
int nfunc_evals = 0;
Expand Down Expand Up @@ -368,12 +369,12 @@ int solveNewton(DATA *data, int sysNumber) {
* function calculates a jacobian matrix by
* numerical method finite differences
*/
static int fdjac(integer* n, void(*f)(integer*, double*, double*, int*, void*), double *x,
double* fvec, double *fjac, double* eps, int* iflag, double* wa,
static int fdjac(integer* n, int(*f)(integer*, double*, double*, integer*, void*), double *x,
double* fvec, double *fjac, double* eps, integer* iflag, double* wa,
void* userdata)
{
double delta_h = sqrt(*eps);
double delta_hh,delta_hhh;
double delta_hh;
double xsave;

int i,j,l;
Expand Down Expand Up @@ -418,16 +419,16 @@ static int fdjac(integer* n, void(*f)(integer*, double*, double*, int*, void*),
* [info]
*
*/
static int _omc_newton(integer* n, double *x, double *fvec, double* eps, double* fdeps, int* maxfev,
int* nfev, void(*f)(integer*, double*, double*, int*, void*),
double* fjac, double* work, integer* iwork, int* info, void* userdata)
static int _omc_newton(integer* n, double *x, double *fvec, double* eps, double* fdeps, integer* maxfev,
integer* nfev, int(*f)(integer*, double*, double*, integer*, void*),
double* fjac, double* work, integer* iwork, integer* info, void* userdata)
{
int currentSys = ((DATA*)userdata)->simulationInfo.currentNonlinearSystemIndex;
NONLINEAR_SYSTEM_DATA* systemData = &(((DATA*)userdata)->simulationInfo.nonlinearSystemData[currentSys]);
DATA_NEWTON* solverData = (DATA_NEWTON*)(systemData->solverData);

int i, j, l, k;
int iflag;
int i, j, l;
integer iflag;
double error_x, error_f, scaledError_f;
double tol_x = *eps, tol_f = solverData->ftol;
double *wa;
Expand All @@ -441,7 +442,7 @@ static int _omc_newton(integer* n, double *x, double *fvec, double* eps, double*
scaledError_f = 1.0 + tol_f;

if (ACTIVE_STREAM(LOG_NLS_V)) {
INFO1(LOG_NLS_V,"######### Start Newton maxfev :%d #########", *maxfev);
INFO1(LOG_NLS_V,"######### Start Newton maxfev :%d #########", (int)*maxfev);
for(i=0;i<*n;i++)
INFO2(LOG_NLS_V,"x[%d] : %e ", i, x[i]);
}
Expand Down Expand Up @@ -474,7 +475,7 @@ static int _omc_newton(integer* n, double *x, double *fvec, double* eps, double*
{
char buffer[4096];

INFO2(LOG_NLS_JAC, "jacobian matrix [%dx%d]", *n, *n);
INFO2(LOG_NLS_JAC, "jacobian matrix [%dx%d]", (int)*n, (int)*n);
INDENT(LOG_NLS_JAC);
for(i=0; i<solverData->n;i++)
{
Expand Down Expand Up @@ -522,7 +523,7 @@ static int _omc_newton(integer* n, double *x, double *fvec, double* eps, double*
WARNING(LOG_NLS,"Jacobian Matrix singular!");
}else if (lapackinfo < 0){
*info = -1;
WARNING1(LOG_NLS,"illegal input in argument %d", lapackinfo);
WARNING1(LOG_NLS,"illegal input in argument %d", (int)lapackinfo);
}else{
/* if no error occurs update x vector */
for (i = 0; i < *n; i++){
Expand Down

0 comments on commit 412f060

Please sign in to comment.