Skip to content

Commit

Permalink
- fix some comments
Browse files Browse the repository at this point in the history
- change type signature for check_*_solutions [* is an element of {nonlinear,linear,mixed}]


git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@16243 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
lochel committed Jun 7, 2013
1 parent 30d6761 commit f0decbc
Show file tree
Hide file tree
Showing 26 changed files with 134 additions and 134 deletions.
2 changes: 1 addition & 1 deletion SimulationRuntime/c/ModelicaExternalC/tables.c
Original file line number Diff line number Diff line change
Expand Up @@ -1053,7 +1053,7 @@ static InterpolationTable* InterpolationTable_init(double time, double startTime
}
tpl->data = *(double**)((void*)&table);
#else
//tpl->data = const_cast<double*>(table);
/* tpl->data = const_cast<double*>(table); */
tpl->data = (double*)malloc(size*sizeof(double));
if (!tpl->data) {
ModelicaFormatError("Not enough memory for Table: %s",tableName);
Expand Down
8 changes: 4 additions & 4 deletions SimulationRuntime/c/fmi/FMI1Common.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ static void fmilogger(fmi1_component_t c, fmi1_string_t instanceName, fmi1_statu
*/
void* fmi1ImportContext_OMC(int fmi_log_level)
{
// JM callbacks
/* JM callbacks */
static int init = 0;
static jm_callbacks callbacks;
if (!init) {
Expand Down Expand Up @@ -91,7 +91,7 @@ void fmi1ImportFreeContext_OMC(void* context)
*/
void* fmi1ImportInstance_OMC(void* context, char* working_directory)
{
// FMI callback functions
/* FMI callback functions */
static int init = 0;
fmi1_callback_functions_t callback_functions;
if (!init) {
Expand All @@ -100,14 +100,14 @@ void* fmi1ImportInstance_OMC(void* context, char* working_directory)
callback_functions.allocateMemory = calloc;
callback_functions.freeMemory = free;
}
// parse the xml file
/* parse the xml file */
fmi1_import_t* fmi;
fmi = fmi1_import_parse_xml((fmi_import_context_t*)context, working_directory);
if(!fmi) {
fprintf(stderr, "Error parsing the XML file contained in %s\n", working_directory);
return 0;
}
// Load the binary (dll/so)
/* Load the binary (dll/so) */
jm_status_enu_t status;
status = fmi1_import_create_dllfmu(fmi, callback_functions, 0);
if (status == jm_status_error) {
Expand Down
4 changes: 2 additions & 2 deletions SimulationRuntime/c/fmi/FMI1ModelExchange.c
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,8 @@ int fmi1CompletedIntegratorStep_OMC(void* fmi, double flowStates)
*/
int fmi1Terminate_OMC(void* fmi)
{
// fmi1_status_t fmistatus = fmi1_import_terminate((fmi1_import_t*)fmi);
// return fmistatus;
/* fmi1_status_t fmistatus = fmi1_import_terminate((fmi1_import_t*)fmi); */
/* return fmistatus; */
return 0;
}

Expand Down
8 changes: 4 additions & 4 deletions SimulationRuntime/c/math-support/pivot.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
/* Matrixes using column major order (as in Fortran) */
/* colInd, rowInd, n_rows is added implicitly, makes code easier to read but may be considered bad programming style! */
#define set_pivot_matrix_elt(A,r,c,value) set_matrix_elt(A,rowInd[r],colInd[c],n_rows,value)
//#define set_pivot_matrix_elt(A,r,c,value) set_matrix_elt(A,colInd[c],rowInd[r],n_cols,value)
/* #define set_pivot_matrix_elt(A,r,c,value) set_matrix_elt(A,colInd[c],rowInd[r],n_cols,value) */
#define get_pivot_matrix_elt(A,r,c) get_matrix_elt(A,rowInd[r],colInd[c],n_rows)
//#define get_pivot_matrix_elt(A,r,c) get_matrix_elt(A,colInd[c],rowInd[r],n_cols)
/* #define get_pivot_matrix_elt(A,r,c) get_matrix_elt(A,colInd[c],rowInd[r],n_cols) */
#define swap(a,b) { modelica_integer _swap=a; a=b; b=_swap; }

#ifndef min
Expand Down Expand Up @@ -62,7 +62,7 @@ int maxsearch( double *A, modelica_integer start, modelica_integer n_rows, model
/* assert that the matrix is not identical to zero */
if ((mrow < 0) || (mcol < 0)) return -1;

// return result */
/* return result */
*maxrow = mrow;
*maxcol = mcol;
*maxabsval = mabsval;
Expand All @@ -80,7 +80,7 @@ They hold the old (and new) pivoting information, such that
int pivot( double *A, modelica_integer n_rows, modelica_integer n_cols, modelica_integer *rowInd, modelica_integer *colInd )
{
/* parameter, determines how much larger an element should be before rows and columns are interchanged */
const double fac = 1.125; // approved by dymola ;)
const double fac = 1.125; /* approved by dymola ;) */

/* temporary variables */
modelica_integer row;
Expand Down
46 changes: 23 additions & 23 deletions SimulationRuntime/c/math-support/test/test_pivot.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,75 +9,75 @@
#define get_matrix_elt(A,r,c,n_rows) A[r + n_rows * c]
#endif

// forward declarations
/* forward declarations */
int test_Pendulum(double x, double y);
int test_Quaternion(double q0, double q1, double q2, double q3);
int test_35();
void pivot( double *A, int n_rows, int n_cols, int *rowInd, int *colInd );

// main
/* main */
int main()
{
// return code
/* return code */
int rc;

// Pendulum
/* Pendulum */
if ( (rc = test_Pendulum(1,0)) != 0) return 1000+rc;
if ( (rc = test_Pendulum(sqrt(2.0)/2.0,sqrt(2.0)/2.0)) != 0) return 1100+rc;
if ( (rc = test_Pendulum(0,1)) != 0) return 1200+rc;

// Quaternion
/* Quaternion */
if ( (rc = test_Quaternion(1,0,0,0)) != 0) return 2000+rc;
if ( (rc = test_Quaternion(0,1,0,0)) != 0) return 2100+rc;
if ( (rc = test_Quaternion(0,0,1,0)) != 0) return 2200+rc;
if ( (rc = test_Quaternion(0,0,0,1)) != 0) return 2300+rc;
if ( (rc = test_Quaternion(0.1,0.2,0.3,sqrt(1-0.1*0.1-0.2*0.2-0.3*0.3))) != 0) return 2400+rc;

// Random Test
/* Random Test */
if ( (rc = test_35()) != 0) return 3000+rc;

// everything OK
/* everything OK */
return 0;
}

int test_Pendulum(double x, double y)
{
// row and column indices
/* row and column indices */
const int n_rows = 1;
const int n_cols = 2;
int rowInd[] = {0};
int colInd[] = {0,1};

// Matrix
/* Matrix */
double A[] = {2*x, 2*y};

// Pivotisierung
/* Pivotisierung */
pivot(A, n_rows, n_cols, rowInd, colInd);

// test result
/* test result */
if (rowInd[0] != 0) return 1;
if (colInd[0] != (x >= y) ? 0 : 1 ) return 10;
if (colInd[1] != (x >= y) ? 1 : 0 ) return 11;

// everything is fine
/* everything is fine */
return 0;
}

int test_Quaternion(double q0, double q1, double q2, double q3)
{
// row and column indices
/* row and column indices */
const int n_rows = 1;
const int n_cols = 4;
int rowInd[] = {0};
int colInd[] = {0,1,2,3};

// Matrix
/* Matrix */
double A[] = {2*q0, 2*q1, 2*q2, 2*q3};

// Pivotisierung
/* Pivotisierung */
pivot(A, n_rows, n_cols, rowInd, colInd);

// test result
/* test result */
if (rowInd[0] != 0) return 1;
if ((colInd[0] < 0) || (colInd[0] > 3)) return 10;
if (colInd[0] == 0)
Expand All @@ -89,31 +89,31 @@ int test_Quaternion(double q0, double q1, double q2, double q3)
if (colInd[0] == 3)
if ((q3 < q0) || (q3 < q1) || (q3 < q2)) return 14;

// everything is fine
/* everything is fine */
return 0;
}

// a system that has been generated by random
/* a system that has been generated by random */
int test_35()
{
// row and column indices
/* row and column indices */
const int n_rows=3;
const int n_cols=5;
int rowInd[] = {0,1,2};
int colInd[] = {0,1,2,3,4};

// Matrix (transposed, since columns come first)
/* Matrix (transposed, since columns come first) */
double A[] = { 14.1886, 42.1761, 91.5736,
79.2207, 95.9492, 65.5741,
3.5712, 84.9129, 93.3993,
67.8735, 75.7740, 74.3132,
39.2227, 65.5478, 17.1187 };


// Pivotisierung
/* Pivotisierung */
pivot(A, n_rows, n_cols, rowInd, colInd);

// test result
/* test result */
if (rowInd[0] != 1) return 1;
if (rowInd[1] != 0) return 2;
if (rowInd[2] != 2) return 3;
Expand All @@ -123,6 +123,6 @@ int test_35()
if (colInd[3] != 3) return 11;
if (colInd[4] != 4) return 11;

// everything is fine
/* everything is fine */
return 0;
}
2 changes: 1 addition & 1 deletion SimulationRuntime/c/openmodelica_func.h
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ extern int function_ZeroCrossings(DATA *data, double* gout, double* t);
* This function evaluates current continuous relations.
*
* \param [ref] [data]
* \param [in] [evalZeroCross] flag for evaluating Relation with hysteresis
* \param [in] [evalZeroCross] flag for evaluating Relation with hysteresis
* function or without
*/
extern int function_updateRelations(DATA *data, int evalZeroCross);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ static void printPltLine(FILE* f, double time, double val);

static int calcDataSize(simulation_result *self,const MODEL_DATA *modelData)
{
int sz = 1, i; // time
if (self->cpuTime) sz++; // $cpuTime
int sz = 1, i; /* time */
if (self->cpuTime) sz++; /* $cpuTime */
for(i = 0; i < modelData->nVariablesReal; i++) if(!modelData->realVarsData[i].filterOutput) sz++;
for(i = 0; i < modelData->nVariablesInteger; i++) if(!modelData->integerVarsData[i].filterOutput) sz++;
for(i = 0; i < modelData->nVariablesBoolean; i++) if(!modelData->booleanVarsData[i].filterOutput) sz++;
Expand Down
2 changes: 1 addition & 1 deletion SimulationRuntime/c/simulation/simulation_info_xml.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ static VAR_INFO* findVariable(const char *name) {
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];

if (0==strcmp("var",name)) {
Expand Down
4 changes: 2 additions & 2 deletions SimulationRuntime/c/simulation/solver/events.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ void initSample(DATA* data, double startTime, double stopTime)

/*! \fn checkForSampleEvent
*
* \param [ref] [data]
* \param [ref] [solverInfo]
* \param [ref] [data]
* \param [ref] [solverInfo]
* \return indicates if a sample event is occuered or not.
*
* Function check if a sample expression should be activated
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -992,17 +992,17 @@ int initialization(DATA *data, const char* pInitMethod, const char* pOptiMethod,
/* check for unsolved (nonlinear|linear|mixed) systems
* This is a workaround and should be removed as soon as possible.
*/
if(check_nonlinear_solutions(data))
if(check_nonlinear_solutions(data, 1))
{
retVal = -2;
WARNING(LOG_NLS, "model terminate | non-linear system solver failed during initialization.");
}
else if(check_linear_solutions(data))
else if(check_linear_solutions(data, 1))
{
retVal = -3;
WARNING(LOG_LS, "model terminate | linear system solver failed during initialization.");
}
else if(check_mixed_solutions(data))
else if(check_mixed_solutions(data, 1))
{
retVal = -4;
WARNING(LOG_NLS, "model terminate | mixed system solver failed during initialiazation.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@

/*! \fn functionJacG_sparse
*
* \param [ref] [data]
* \param [ref] [data]
* \param [out] [jac]
*
* \author lochel
Expand Down
4 changes: 2 additions & 2 deletions SimulationRuntime/c/simulation/solver/linearSolverLapack.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ int freeLapackData(void **voiddata)

/*! \fn solve linear system with lapack method
*
* \param [in] [data]
* \param [in] [data]
* [sysNumber] index of the corresponing non-linear system
*
* \author wbraun
Expand All @@ -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 Down
7 changes: 4 additions & 3 deletions SimulationRuntime/c/simulation/solver/linearSystem.c
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ int freelinearSystem(DATA *data)

/*! \fn solve non-linear systems
*
* \param [in] [data]
* \param [in] [data]
* [sysNumber] index of corresponding non-linear System
*
* \author wbraun
Expand Down Expand Up @@ -139,11 +139,12 @@ int solve_linear_system(DATA *data, int sysNumber)
* This function check whether some of linear systems
* are failed to solve. If one is failed it returns 1 otherwise 0.
*
* \param [in] [data]
* \param [in] [data]
* \param [in] [printFailingSystems]
*
* \author wbraun
*/
int check_linear_solutions(DATA *data)
int check_linear_solutions(DATA *data, int printFailingSystems)
{
LINEAR_SYSTEM_DATA* linsys = data->simulationInfo.linearSystemData;
int i;
Expand Down
2 changes: 1 addition & 1 deletion SimulationRuntime/c/simulation/solver/linearSystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,6 @@ typedef void* LS_SOLVER_DATA;
int allocatelinearSystem(DATA *data);
int freelinearSystem(DATA *data);
int solve_linear_system(DATA *data, int sysNumber);
int check_linear_solutions(DATA *data);
int check_linear_solutions(DATA *data, int printFailingSystems);

#endif
2 changes: 1 addition & 1 deletion SimulationRuntime/c/simulation/solver/mixedSearchSolver.c
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ modelica_boolean nextVar(modelica_boolean *b, int n) {

/*! \fn solve mixed system with extended search
*
* \param [in] [data]
* \param [in] [data]
* [sysNumber] index of the corresponing mixed system
*
* \author wbraun
Expand Down
7 changes: 4 additions & 3 deletions SimulationRuntime/c/simulation/solver/mixedSystem.c
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ int freemixedSystem(DATA *data)

/*! \fn solve mixed systems
*
* \param [in] [data]
* \param [in] [data]
* [sysNumber] index of corresponding mixed System
*
* \author wbraun
Expand Down Expand Up @@ -133,11 +133,12 @@ int solve_mixed_system(DATA *data, int sysNumber)
* This function checks whether some of the mixed systems
* are failed to solve. If one is failed it returns 1 otherwise 0.
*
* \param [in] [data]
* \param [in] [data]
* \param [in] [printFailingSystems]
*
* \author wbraun
*/
int check_mixed_solutions(DATA *data)
int check_mixed_solutions(DATA *data, int printFailingSystems)
{
MIXED_SYSTEM_DATA* system = data->simulationInfo.mixedSystemData;
int i;
Expand Down
2 changes: 1 addition & 1 deletion SimulationRuntime/c/simulation/solver/mixedSystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,6 @@ typedef void* MIXED_SOLVER_DATA;
int allocatemixedSystem(DATA *data);
int freemixedSystem(DATA *data);
int solve_mixed_system(DATA *data, int sysNumber);
int check_mixed_solutions(DATA *data);
int check_mixed_solutions(DATA *data, int printFailingSystems);

#endif

0 comments on commit f0decbc

Please sign in to comment.