Skip to content

Commit

Permalink
- Added c_runtime/fortran_types.h
Browse files Browse the repository at this point in the history
  + Contains only fortran_integer - the same size integer as the ones used by the DASSL solver.
- Updated solver_dasrt.h to use fortran_integer instead of long.
  + Fixes some of the new 64-bit issues.
  + Also updated functions that were used by this function.
  + Updated code generation for the new function defintions.
- The testsuite now runs on 64-bit machines (except some MetaModelica tests)


git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@4918 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
sjoelund committed Feb 4, 2010
1 parent 8312a2a commit 159bb32
Show file tree
Hide file tree
Showing 11 changed files with 58 additions and 39 deletions.
6 changes: 3 additions & 3 deletions Compiler/SimCodegen.mo
Expand Up @@ -7272,8 +7272,8 @@ algorithm
cfunc_2 = Codegen.cMergeFns({cfunc0,cfunc,cfuncHelpvars});

func_zc0 = Codegen.cMakeFunction("int", "function_zeroCrossing", {},
{"long *neqm","double *t","double *x","long *ng",
"double *gout","double *rpar","long* ipar"});
{"fortran_integer *neqm","double *t","double *x","fortran_integer *ng",
"double *gout","double *rpar","fortran_integer* ipar"});
func_zc0 = Codegen.cAddVariables(func_zc0,{"double timeBackup;"});
func_zc0 = Codegen.cAddStatements(func_zc0,{"timeBackup = localData->timeValue;",
"localData->timeValue = *t;"
Expand Down Expand Up @@ -8286,7 +8286,7 @@ algorithm
equation
cfn1 = Codegen.cMakeFunction("int", "functionDAE_res", {},
{"double *t","double *x","double *xd","double *delta",
"long int *ires","double *rpar","long int* ipar"}) "build_residual_blocks(dae,dlow,ass1,ass2,blocks,0) => (cfn2,_) &" ;
"fortran_integer *ires","double *rpar","fortran_integer* ipar"}) "build_residual_blocks(dae,dlow,ass1,ass2,blocks,0) => (cfn2,_) &" ;
cfn2 = Codegen.cAddVariables(cfn1, {"int i;",
"double temp_xd[NX];",
"double* statesBackup;",
Expand Down
2 changes: 1 addition & 1 deletion c_runtime/Makefile
Expand Up @@ -39,7 +39,7 @@ HFILES = blaswrap.h f2c.h integer_array.h memory_pool.h modelica_string.h \
simulation_init.h simulation_input.h solver_dasrt.h solver_euler.h simulation_result.h \
meta_modelica.h meta_modelica_builtin.h sendData/sendData.h sendData/humbug.h \
java_interface.h jni.h jni_md.h jni_md_solaris.h jni_md_windows.h \
simulation_delay.h
simulation_delay.h fortran_types.h

LIBS = libc_runtime.a libsim.a

Expand Down
15 changes: 15 additions & 0 deletions c_runtime/fortran_types.h
@@ -0,0 +1,15 @@
/* From f2c.h for compatibility - you may not include f2c.h in C++ headers or
* or you break the templates. */

#ifndef FORTRAN_TYPES_INCLUDE
#define FORTRAN_TYPES_INCLUDE

#if defined(__alpha__) || defined(__sparc64__) || defined(__x86_64__) || defined(__ia64__)
typedef int fortran_integer;
typedef unsigned int fortran_uinteger;
#else
typedef long int fortran_integer;
typedef unsigned long int fortran_uinteger;
#endif

#endif
2 changes: 1 addition & 1 deletion c_runtime/index_spec.c
Expand Up @@ -120,7 +120,7 @@ void print_size_array(int size, size_t* arr)
int i;
printf("{");
for(i = 0; i < size; ++i) {
printf("%d", arr[i]);
printf("%d", (int) arr[i]);
if (i != (size - 1)) printf(",");
}
printf("}\n");
Expand Down
2 changes: 1 addition & 1 deletion c_runtime/modelica_string.c
Expand Up @@ -37,7 +37,7 @@
int modelica_string_ok(modelica_string_t* a)
{
/* Since a modelica string is a char* check that it is not null.*/
return (int)a;
return (a != NULL ? 1 : 0);
}

int modelica_string_length(modelica_string_t* a)
Expand Down
2 changes: 1 addition & 1 deletion c_runtime/read_write.c
Expand Up @@ -68,7 +68,7 @@ void puttype(const type_description *desc)
break;
case TYPE_DESC_TUPLE: {
size_t e;
fprintf(stderr, "TUPLE (%u):\n", desc->data.tuple.elements);
fprintf(stderr, "TUPLE (%u):\n", (unsigned) desc->data.tuple.elements);
for (e = 0; e < desc->data.tuple.elements; ++e) {
fprintf(stderr, "\t");
puttype(desc->data.tuple.element + e);
Expand Down
4 changes: 2 additions & 2 deletions c_runtime/simulation_events.cpp
Expand Up @@ -101,7 +101,7 @@ void deinitializeEventData() {
* This function checks such initial events and calls the event handling for this. The function is called after the first
* step is taken by DASSRT (a small tiny step just to check these events)
* */
void checkForInitialZeroCrossings(long*jroot) {
void checkForInitialZeroCrossings(fortran_integer* jroot) {
int i;
if (sim_verbose) {
cout << "checkForIntialZeroCrossings" << endl;
Expand Down Expand Up @@ -252,7 +252,7 @@ void StartEventIteration(double *t) {
// cout << "EventIteration done" << endl;
}

void StateEventHandler(long* jroot, double *t) {
void StateEventHandler(fortran_integer* jroot, double *t) {
inSample = 1;
for (int i = 0; i < globalData->nZeroCrossing; i++) {
if (jroot[i]) {
Expand Down
8 changes: 5 additions & 3 deletions c_runtime/simulation_events.h
Expand Up @@ -37,16 +37,18 @@
#ifndef _SIMULATION_EVENTS_H
#define _SIMULATION_EVENTS_H

#include "fortran_types.h"

int initializeEventData();
void deinitializeEventData();

int checkForDiscreteVarChanges();
void calcEnabledZeroCrossings();
void CheckForNewEvents(double *t);
void CheckForInitialEvents(double *t);
void checkForInitialZeroCrossings(long*jroot);
void checkForInitialZeroCrossings(fortran_integer* jroot);
void StartEventIteration(double *t);
void StateEventHandler(long jroot[], double *t);
void StateEventHandler(fortran_integer jroot[], double *t);
void AddEvent(long);

void saveall();
Expand Down Expand Up @@ -108,7 +110,7 @@ extern long inUpdate;
#define initial() localData->init

int
function_zeroCrossing(long *neqm, double *t, double *x, long *ng, double *gout, double *rpar, long* ipar);
function_zeroCrossing(fortran_integer *neqm, double *t, double *x, fortran_integer *ng, double *gout, double *rpar, fortran_integer* ipar);

int
handleZeroCrossing(long index);
Expand Down
8 changes: 4 additions & 4 deletions c_runtime/simulation_runtime.h
Expand Up @@ -137,13 +137,13 @@ typedef struct sim_DATA {
int init; // =1 during initialization, 0 otherwise.
void** extObjs; // External objects
/* nStatesDerivatives == states */
long nStates,nAlgebraic,nParameters;
fortran_integer nStates,nAlgebraic,nParameters;
long nInputVars,nOutputVars;
long nZeroCrossing/*NG*/;
fortran_integer nZeroCrossing/*NG*/;
long nInitialResiduals/*NR*/;
long nHelpVars/* NHELP */;
//extern char init_fixed[];
DATA_STRING stringVariables;
DATA_STRING stringVariables;

char* modelName;
char** statesNames;
Expand Down Expand Up @@ -216,7 +216,7 @@ functionDAE_output2();
// function for calculating state values on residual form
/*used in DDASRT fortran function*/
int
functionDAE_res(double *t, double *x, double *xprime, double *delta, long int *ires, double *rpar, long int* ipar);
functionDAE_res(double *t, double *x, double *xprime, double *delta, fortran_integer *ires, double *rpar, fortran_integer* ipar);


int
Expand Down
22 changes: 11 additions & 11 deletions c_runtime/solver_dasrt.cpp
Expand Up @@ -44,10 +44,10 @@ using namespace std;

#define MAXORD 5

bool continue_with_dassl(long* idid, double* atol, double *rtol);
bool continue_with_dassl(fortran_integer* idid, double* atol, double *rtol);

// dummy Jacobian
int dummyJacobianDASSL(double *t, double *y, double *yprime, double *pd, long *cj, double *rpar, long* ipar)
int dummyJacobianDASSL(double *t, double *y, double *yprime, double *pd, fortran_integer *cj, double *rpar, fortran_integer* ipar)
{
return 0;
//provides a dummy Jacobian to be used with DASSL
Expand All @@ -69,7 +69,7 @@ double calcTinyStep(double tout)
}
}
/* Returns the index of the first root that is active*/
int activeEvent(int nRoots, long *jroot)
int activeEvent(int nRoots, fortran_integer *jroot)
{
int i;
for (i=0; i < nRoots; i++) {
Expand All @@ -84,26 +84,26 @@ int dassl_main(int argc, char**argv,double &start, double &stop, double &step,
{
int status=0;

long info[15];
fortran_integer info[15];
status = 0;
double tout;
double rtol = 1.0e-5;
double atol = 1.0e-5;
double uround = dlamch_("P",1);
long idid = 0;
fortran_integer idid = 0;


//double rpar = 0.0;
long ipar = 0;
fortran_integer ipar = 0;
int i;

// work arrays for dassl
long liw = 20+globalData->nStates;
long lrw = 52+(MAXORD+4)*globalData->nStates+
fortran_integer liw = 20+globalData->nStates;
fortran_integer lrw = 52+(MAXORD+4)*globalData->nStates+
globalData->nStates*globalData->nStates+3*globalData->nZeroCrossing;
long *iwork = new long[liw];
fortran_integer *iwork = new fortran_integer[liw];
double *rwork = new double[lrw];
long *jroot = new long[globalData->nZeroCrossing];
fortran_integer *jroot = new fortran_integer[globalData->nZeroCrossing];


// Used when calculating residual for its side effects. (alg. var calc)
Expand Down Expand Up @@ -414,7 +414,7 @@ int dassl_main(int argc, char**argv,double &start, double &stop, double &step,
}


bool continue_with_dassl(long* idid, double* atol, double *rtol)
bool continue_with_dassl(fortran_integer* idid, double* atol, double *rtol)
{
static int atolZeroIterations=0;
bool retValue = true;
Expand Down
26 changes: 14 additions & 12 deletions c_runtime/solver_dasrt.h
Expand Up @@ -39,6 +39,8 @@
#ifndef _SOLVER_DASRT_H
#define _SOLVER_DASRT_H

#include "fortran_types.h"

int dassl_main(int argc, char**argv,double &start, double &stop, double &step, long &outputSteps,
double &tolerance);

Expand All @@ -48,26 +50,26 @@ int dassl_main(int argc, char**argv,double &start, double &stop, double &step,

extern "C" {
void DDASRT(
int (*res) (double *t, double *y, double *yprime, double *delta, long *ires, double *rpar, long* ipar),
long *neq,
int (*res) (double *t, double *y, double *yprime, double *delta, fortran_integer *ires, double *rpar, fortran_integer* ipar),
fortran_integer *neq,
double *t,
double *y,
double *yprime,
double *tout,
long *info,
fortran_integer *info,
double *rtol,
double *atol,
long *idid,
fortran_integer *idid,
double *rwork,
long *lrw,
long *iwork,
long *liw,
fortran_integer *lrw,
fortran_integer *iwork,
fortran_integer *liw,
double *rpar,
long *ipar,
int (*jac) (double *t, double *y, double *yprime, double *delta, long *ires, double *rpar, long* ipar),
int (*g) (long *neqm, double *t, double *y, long *ng, double *gout, double *rpar, long* ipar),
long *ng,
long *jroot
fortran_integer *ipar,
int (*jac) (double *t, double *y, double *yprime, double *delta, fortran_integer *ires, double *rpar, fortran_integer* ipar),
int (*g) (fortran_integer *neqm, double *t, double *y, fortran_integer *ng, double *gout, double *rpar, fortran_integer* ipar),
fortran_integer *ng,
fortran_integer *jroot
);

double dlamch_(char*,int);
Expand Down

0 comments on commit 159bb32

Please sign in to comment.