Skip to content

Commit

Permalink
Use modelica_booleans (OpenModelica#12204)
Browse files Browse the repository at this point in the history
  • Loading branch information
phannebohm committed Apr 5, 2024
1 parent 3ad175e commit ff4a0ea
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 28 deletions.
2 changes: 1 addition & 1 deletion OMCompiler/SimulationRuntime/c/simulation/solver/irksco.c
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ int rk_imp_step(DATA* data, threadData_t* threadData, SOLVER_INFO* solverInfo, d
sData->timeValue = irkscoData->radauTime + irkscoData->radauStepSize;
solverInfo->currentTime = sData->timeValue;

newtonData->initialized = 1;
newtonData->initialized = TRUE;
newtonData->numberOfIterations = 0;
newtonData->numberOfFunctionEvaluations = 0;
newtonData->n = n*irkscoData->ordersize;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ extern int dgesv_(int *n, int *nrhs, doublereal *a, int *lda, int *ipiv, doubler
*/
typedef struct DATA_HOMOTOPY
{
int initialized; /* 1 = initialized, else = 0*/
modelica_boolean initialized;

size_t n; /* dimension; n == size */
size_t m; /* dimension: m == size+1 */
Expand Down Expand Up @@ -169,7 +169,7 @@ DATA_HOMOTOPY* allocateHomotopyData(size_t size, NLS_USERDATA* userData)
DATA_HOMOTOPY* homotopyData = (DATA_HOMOTOPY*) malloc(sizeof(DATA_HOMOTOPY));
assertStreamPrint(NULL, NULL != homotopyData, "allocationHomotopyData() failed!");

homotopyData->initialized = 0;
homotopyData->initialized = FALSE;
homotopyData->n = size;
homotopyData->m = size + 1;
homotopyData->xtol_sqrd = newtonXTol*newtonXTol;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ DATA_HYBRD* allocateHybrdData(size_t size, NLS_USERDATA* userData)
DATA_HYBRD* hybrdData = (DATA_HYBRD*) malloc(sizeof(DATA_HYBRD));
assertStreamPrint(NULL, hybrdData != NULL, "allocationHybrdData() failed!");

hybrdData->initialized = 0;
hybrdData->initialized = FALSE;
hybrdData->resScaling = (double*) malloc(size*sizeof(double));
hybrdData->fvecScaled = (double*) malloc(size*sizeof(double));
hybrdData->useXScaling = 1;
Expand Down Expand Up @@ -328,7 +328,7 @@ static void wrapper_fvec_hybrj(const integer *n_p, const double* x, double* f, d
threadData_t* threadData = userData->threadData;
NONLINEAR_SYSTEM_DATA* systemData = userData->nlsData;
DATA_HYBRD* hybrdData = (DATA_HYBRD*)(systemData->solverData);
int continuous = data->simulationInfo->solveContinuous;
modelica_boolean continuous = data->simulationInfo->solveContinuous;
RESIDUAL_USERDATA resUserData = {.data=data, .threadData=threadData, .solverData=userData->solverData};

switch(*iflag)
Expand Down Expand Up @@ -364,7 +364,7 @@ static void wrapper_fvec_hybrj(const integer *n_p, const double* x, double* f, d
case 2:
/* set residual function continuous for jacobian calculation */
if(continuous)
data->simulationInfo->solveContinuous = 0;
data->simulationInfo->solveContinuous = FALSE;

if(ACTIVE_STREAM(LOG_NLS_RES))
infoStreamPrint(LOG_NLS_RES, 0, "-- begin calculating jacobian --");
Expand Down Expand Up @@ -404,7 +404,7 @@ static void wrapper_fvec_hybrj(const integer *n_p, const double* x, double* f, d
}
/* reset residual function again */
if(continuous)
data->simulationInfo->solveContinuous = 1;
data->simulationInfo->solveContinuous = TRUE;

/* performance measurement and statistics */
systemData->jacobianTime += rt_ext_tp_tock(&(systemData->jacobianTimeClock));
Expand Down Expand Up @@ -439,7 +439,7 @@ NLS_SOLVER_STATUS solveHybrd(DATA *data, threadData_t *threadData, NONLINEAR_SYS
double local_tol = 1e-12;
double initial_factor = hybrdData->factor;
int nfunc_evals = 0;
int continuous = 1;
modelica_boolean continuous = TRUE;
int nonContinuousCase = 0;

int giveUp = 0;
Expand Down Expand Up @@ -524,13 +524,8 @@ NLS_SOLVER_STATUS solveHybrd(DATA *data, threadData_t *threadData, NONLINEAR_SYS
printVector(hybrdData->x, hybrdData->n, LOG_NLS_V, "Iteration variable values (scaled)");
}

/* set residual function continuous
*/
if(continuous) {
data->simulationInfo->solveContinuous = 1;
} else {
data->simulationInfo->solveContinuous = 0;
}
/* set residual function continuous */
data->simulationInfo->solveContinuous = continuous;

giveUp = 1;

Expand Down Expand Up @@ -591,15 +586,8 @@ NLS_SOLVER_STATUS solveHybrd(DATA *data, threadData_t *threadData, NONLINEAR_SYS
}
}

/* set residual function continuous */
if(continuous)
{
data->simulationInfo->solveContinuous = 0;
}
else
{
data->simulationInfo->solveContinuous = 1;
}
/* reset residual function continuous */
data->simulationInfo->solveContinuous = !continuous;

/* re-scaling x vector */
if(hybrdData->useXScaling)
Expand All @@ -621,7 +609,7 @@ NLS_SOLVER_STATUS solveHybrd(DATA *data, threadData_t *threadData, NONLINEAR_SYS
if(scaling)
hybrdData->useXScaling = 0;

data->simulationInfo->solveContinuous = 0;
data->simulationInfo->solveContinuous = FALSE;

/* try */
#ifndef OMC_EMCC
Expand Down Expand Up @@ -893,7 +881,7 @@ NLS_SOLVER_STATUS solveHybrd(DATA *data, threadData_t *threadData, NONLINEAR_SYS
retries++;

/* try to solve a discontinuous system */
continuous = 0;
continuous = FALSE;

nonContinuousCase = 1;
memcpy(relationsPreBackup, data->simulationInfo->relationsPre, sizeof(modelica_boolean)*data->modelData->nRelations);
Expand All @@ -914,7 +902,7 @@ NLS_SOLVER_STATUS solveHybrd(DATA *data, threadData_t *threadData, NONLINEAR_SYS
if(!scaling)
hybrdData->useXScaling = 1;

continuous = 1;
continuous = TRUE;
hybrdData->factor = initial_factor;

retries = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ extern "C" {

typedef struct DATA_HYBRD
{
int initialized; /* 1 = initialized, else = 0*/
modelica_boolean initialized;
double* resScaling;
int useXScaling;
double* xScalefactors;
Expand Down

0 comments on commit ff4a0ea

Please sign in to comment.