Skip to content

Commit

Permalink
- revised dump system for the c-runtime
Browse files Browse the repository at this point in the history
git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@13652 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
lochel committed Oct 26, 2012
1 parent 4f3d59b commit 0e22c33
Show file tree
Hide file tree
Showing 29 changed files with 1,059 additions and 1,022 deletions.
26 changes: 15 additions & 11 deletions Compiler/Template/CodegenC.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ template functionInitializeDataStruc(ModelInfo modelInfo, String fileNamePrefix,
<<
void setupDataStruc(DATA *data)
{
ASSERT(data,"Error while initialize Data");
ASSERT(data, "Error while initialize Data");
<%populateModelInfo(modelInfo, fileNamePrefix, guid, allEquations, symJacEquations, delayed)%>
}
>>
Expand Down Expand Up @@ -814,11 +814,13 @@ template functionUpdateBoundStartValues(list<SimEqSystem> startValueEquations)
<%eqPart%>
DEBUG_INFO(LOG_INIT, "updating start-values:");
INFO(LOG_INIT, "updating start-values");
INDENT(LOG_INIT);
<%startValueEquations |> SES_SIMPLE_ASSIGN(__) =>
'DEBUG_INFO_AL2(LOG_INIT, " %s(start=%f)", <%cref(cref)%>__varInfo.name, (<%crefType(cref)%>) <%cref(cref)%>);
'INFO2(LOG_INIT, "%s(start=%g)", <%cref(cref)%>__varInfo.name, (<%crefType(cref)%>) <%cref(cref)%>);
$P$ATTRIBUTE<%cref(cref)%>.start = <%cref(cref)%>;'
;separator="\n"%>
RELEASE(LOG_INIT);
return 0;
}
Expand Down Expand Up @@ -846,7 +848,7 @@ template functionInitialResidual(list<SimEqSystem> residualEquations)
let expPart = daeExp(exp, contextOther, &preExp /*BUFC*/, &varDecls /*BUFD*/)
<<
<%preExp%>initialResiduals[i++] = <%expPart%>;
DEBUG_INFO_AL3(LOG_RES_INIT, "| [%d]: %s = %g", i, initialResidualDescription[i-1], initialResiduals[i-1]);
INFO3(LOG_RES_INIT, "[%d]: %s = %g", i, initialResidualDescription[i-1], initialResiduals[i-1]);
>>
;separator="\n")

Expand All @@ -863,8 +865,10 @@ template functionInitialResidual(list<SimEqSystem> residualEquations)
<%varDecls%>
mem_state = get_memory_state();
DEBUG_INFO(LOG_RES_INIT, "updating initial residuals:");
INFO(LOG_RES_INIT, "updating initial residuals");
INDENT(LOG_RES_INIT);
<%body%>
RELEASE(LOG_RES_INIT);
restore_memory_state(mem_state);
return 0;
Expand Down Expand Up @@ -1082,7 +1086,7 @@ template functionWhenReinitStatementThen(list<WhenOperator> reinits, Text &varDe
else
'<%cref(stateVar)%> = <%val%>;'
<<
DEBUG_INFO_AL1(LOG_EVENTS,"| | reinit <%cref(stateVar)%> = %f", <%val%>);
INFO1(LOG_EVENTS, "| | reinit <%cref(stateVar)%> = %f", <%val%>);
<%preExp%>
<%lhs%>
data->simulationInfo.needToIterate = 1;
Expand Down Expand Up @@ -1383,7 +1387,7 @@ template functionCheckForDiscreteChanges(list<ComponentRef> discreteModelVars) "
match var
case CREF_QUAL(__)
case CREF_IDENT(__) then
'if(<%cref(var)%> != $P$PRE<%cref(var)%>) { DEBUG_INFO_AL2(LOG_EVENTS, "| events | | Discrete Var <%crefStr(var)%> changed: <%crefToPrintfArg(var)%> to <%crefToPrintfArg(var)%>", $P$PRE<%cref(var)%>, <%cref(var)%>); needToIterate=1; }'
'if(<%cref(var)%> != $P$PRE<%cref(var)%>) {INFO2(LOG_EVENTS, "| events | | Discrete Var <%crefStr(var)%> changed: <%crefToPrintfArg(var)%> to <%crefToPrintfArg(var)%>", $P$PRE<%cref(var)%>, <%cref(var)%>); needToIterate=1;}'
;separator="\n")

<<
Expand Down Expand Up @@ -1706,10 +1710,10 @@ template functionJac(list<SimEqSystem> jacEquations, list<SimVar> tmpVars, Strin
<%eqns_%>
int i;
if(DEBUG_FLAG(LOG_DEBUG))
if(DEBUG_STREAM(LOG_DEBUG))
{
for(i=0; i<<%columnLength%>; i++)
DEBUG_INFO2(LOG_DEBUG, "col: col[%d] = %f", i, data->simulationInfo.analyticJacobians[index].resultVars[i]);
INFO2(LOG_DEBUG, "col: col[%d] = %f", i, data->simulationInfo.analyticJacobians[index].resultVars[i]);
}

restore_memory_state(mem_state);
Expand Down Expand Up @@ -5665,8 +5669,8 @@ template algStmtReinit(DAE.Statement stmt, Context context, Text &varDecls /*BUF
let expPart1 = daeExp(var, context, &preExp /*BUFC*/, &varDecls /*BUFD*/)
let expPart2 = daeExp(value, context, &preExp /*BUFC*/, &varDecls /*BUFD*/)
<<
if (DEBUG_FLAG(LOG_EVENTS)) {
INFO1("reinit <%expPart1%> = %f", <%expPart1%>);
if (DEBUG_STREAM(LOG_EVENTS)) {
INFO1(LOG_INIT, "reinit <%expPart1%> = %f", <%expPart1%>);
}
$P$PRE<%expPart1%> = <%expPart1%>;
<%preExp%>
Expand Down
52 changes: 26 additions & 26 deletions SimulationRuntime/c/ModelicaExternalC/tables.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
#endif

/* Definition to get some Debug information if interface is called */
/* #define DEBUG_INFOS */
/* #define INFOS */

/* Definition to make a copy of the arrays */
#define COPY_ARRAYS
Expand Down Expand Up @@ -136,20 +136,20 @@ int omcTableTimeIni(double timeIn, double startTime,int ipoType,int expoType,
{
size_t i = 0;
InterpolationTable** tmp = NULL;
#ifdef DEBUG_INFOS
#ifdef INFOS
INFO10("Init Table \n timeIn %f \n startTime %f \n ipoType %d \n expoType %d \n tableName %s \n fileName %s \n table %p \n tableDim1 %d \n tableDim2 %d \n colWise %d", timeIn, startTime, ipoType, expoType, tableName, fileName, table, tableDim1, tableDim2, colWise);
#endif
/* if table is already initialized, find it */
for(i = 0; i < ninterpolationTables; ++i)
if (InterpolationTable_compare(interpolationTables[i],fileName,tableName,table))
{
#ifdef DEBUG_INFOS
INFO_AL1("Table id = %d",i);
#ifdef INFOS
INFO1("Table id = %d",i);
#endif
return i;
}
#ifdef DEBUG_INFOS
INFO_AL1("Table id = %d",ninterpolationTables);
#ifdef INFOS
INFO1("Table id = %d",ninterpolationTables);
#endif
/* increase array */
tmp = (InterpolationTable**)malloc((ninterpolationTables+1)*sizeof(InterpolationTable*));
Expand All @@ -173,7 +173,7 @@ int omcTableTimeIni(double timeIn, double startTime,int ipoType,int expoType,

void omcTableTimeIpoClose(int tableID)
{
#ifdef DEBUG_INFOS
#ifdef INFOS
INFO1("Close Table[%d]",tableID);
#endif
if (tableID >= 0 && tableID < (int)ninterpolationTables)
Expand All @@ -189,7 +189,7 @@ void omcTableTimeIpoClose(int tableID)

double omcTableTimeIpo(int tableID, int icol, double timeIn)
{
#ifdef DEBUG_INFOS
#ifdef INFOS
INFO3("Interpolate Table[%d][%d] add Time %f",tableID,icol,timeIn);
#endif
if (tableID >= 0 && tableID < (int)ninterpolationTables)
Expand All @@ -203,7 +203,7 @@ double omcTableTimeIpo(int tableID, int icol, double timeIn)

double omcTableTimeTmax(int tableID)
{
#ifdef DEBUG_INFOS
#ifdef INFOS
INFO1("Time max from Table[%d]",tableID);
#endif
if (tableID >= 0 && tableID < (int)ninterpolationTables)
Expand All @@ -215,7 +215,7 @@ double omcTableTimeTmax(int tableID)

double omcTableTimeTmin(int tableID)
{
#ifdef DEBUG_INFOS
#ifdef INFOS
INFO1("Time min from Table[%d]",tableID);
#endif
if (tableID >= 0 && tableID < (int)ninterpolationTables)
Expand All @@ -230,20 +230,20 @@ int omcTable2DIni(int ipoType, const char *tableName, const char* fileName,
{
size_t i=0;
InterpolationTable2D** tmp = NULL;
#ifdef DEBUG_INFOS
#ifdef INFOS
INFO7("Init Table \n ipoType %f \n tableName %f \n fileName %d \n table %p \n tableDim1 %d \n tableDim2 %d \n colWise %d", ipoType, tableName, fileName, table, tableDim1, tableDim2, colWise);
#endif
/* if table is already initialized, find it */
for(i = 0; i < ninterpolationTables2D; ++i)
if (InterpolationTable2D_compare(interpolationTables2D[i],fileName,tableName,table))
{
#ifdef DEBUG_INFOS
INFO_AL1("Table id = %d",i);
#ifdef INFOS
INFO1("Table id = %d",i);
#endif
return i;
}
#ifdef DEBUG_INFOS
INFO_AL1("Table id = %d",ninterpolationTables2D);
#ifdef INFOS
INFO1("Table id = %d",ninterpolationTables2D);
#endif
/* increase array */
tmp = (InterpolationTable2D**)malloc((ninterpolationTables2D+1)*sizeof(InterpolationTable2D*));
Expand All @@ -264,7 +264,7 @@ int omcTable2DIni(int ipoType, const char *tableName, const char* fileName,

void omcTable2DIpoClose(int tableID)
{
#ifdef DEBUG_INFOS
#ifdef INFOS
INFO1("Close Table[%d]",tableID);
#endif
if (tableID >= 0 && tableID < (int)ninterpolationTables2D)
Expand All @@ -280,7 +280,7 @@ void omcTable2DIpoClose(int tableID)

double omcTable2DIpo(int tableID,double u1_, double u2_)
{
#ifdef DEBUG_INFOS
#ifdef INFOS
INFO3("Interpolate Table[%d][%d] add Time %f",tableID,u1_,u2_);
#endif
if (tableID >= 0 && tableID < (int)ninterpolationTables2D)
Expand Down Expand Up @@ -1474,11 +1474,11 @@ char InterpolationTable2D_compare(InterpolationTable2D *tpl, const char* fname,
return 0;
}

double InterpolationTable2D_linInterpolate(double x, double x_1, double x_2,
double f_1, double f_2)
double InterpolationTable2D_linInterpolate(double x, double x_1, double x_2, double f_1, double f_2)
{
return ((x_2 - x)*f_1 + (x - x_1)*f_2) / (x_2-x_1);
}

const double InterpolationTable2D_getElt(InterpolationTable2D *tpl, size_t row, size_t col)
{
ASSERT6(row < tpl->rows && col < tpl->cols, "In Table: %s from File: %s with Size[%lu,%lu] try to get Element[%lu,%lu] aut of range!", tpl->tablename, tpl->filename, (unsigned long)tpl->rows, (unsigned long)tpl->cols, (unsigned long)row, (unsigned long)col);
Expand All @@ -1489,18 +1489,18 @@ void InterpolationTable2D_checkValidityOfData(InterpolationTable2D *tpl)
{
size_t i = 0;
/* check if table has values */
ASSERT2((tpl->rows > 1) && (tpl->cols > 1),"Table %s from file %s has no data!",tpl->tablename,tpl->filename);
ASSERT2((tpl->rows > 1) && (tpl->cols > 1), "Table %s from file %s has no data!", tpl->tablename, tpl->filename);
/* check that first row and column are strictly monotonous */
for(i=2; i < tpl->rows; ++i) {
for(i=2; i < tpl->rows; ++i)
{
if (InterpolationTable2D_getElt(tpl,i-1,0) >= InterpolationTable2D_getElt(tpl,i,0))
THROW3("Table: %s independent variable u1 not strictly \
monotonous: %g >= %g.",tpl->tablename, InterpolationTable2D_getElt(tpl,i-1,0), InterpolationTable2D_getElt(tpl,i,0));
monotonous: %g >= %g.",tpl->tablename, InterpolationTable2D_getElt(tpl,i-1,0), InterpolationTable2D_getElt(tpl,i,0));
}
for(i=2; i < tpl->cols; ++i) {
for(i=2; i < tpl->cols; ++i)
{
if (InterpolationTable2D_getElt(tpl,0,i-1) >= InterpolationTable2D_getElt(tpl,0,i))
THROW3("Table: %s independent variable u2 not strictly \
monotonous: %g >= %g.",tpl->tablename, InterpolationTable2D_getElt(tpl,0,i-1), InterpolationTable2D_getElt(tpl,0,i));
monotonous: %g >= %g.",tpl->tablename, InterpolationTable2D_getElt(tpl,0,i-1), InterpolationTable2D_getElt(tpl,0,i));
}
}


53 changes: 31 additions & 22 deletions SimulationRuntime/c/linearization/linearize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,26 +68,30 @@ int functionJacA(DATA* data, double* jac){
for(i=0; i < data->simulationInfo.analyticJacobians[index].sizeCols; i++)
{
data->simulationInfo.analyticJacobians[index].seedVars[i] = 1.0;
if (DEBUG_FLAG((LOG_JAC | LOG_ENDJAC)))
if (DEBUG_STREAM((LOG_JAC | LOG_ENDJAC)))
{
printf("Caluculate one col:\n");
for(j=0; j < data->simulationInfo.analyticJacobians[index].sizeCols;j++)
DEBUG_INFO2((LOG_JAC | LOG_ENDJAC),"seed: data->simulationInfo.analyticJacobians[index].seedVars[%d]= %f",j,data->simulationInfo.analyticJacobians[index].seedVars[j]);
{
INFO2(LOG_JAC,"seed: data->simulationInfo.analyticJacobians[index].seedVars[%d]= %f",j,data->simulationInfo.analyticJacobians[index].seedVars[j]);
INFO2(LOG_ENDJAC,"seed: data->simulationInfo.analyticJacobians[index].seedVars[%d]= %f",j,data->simulationInfo.analyticJacobians[index].seedVars[j]);
}
}

functionJacA_column(data);

for(j = 0; j < data->simulationInfo.analyticJacobians[index].sizeRows; j++)
{
jac[k++] = data->simulationInfo.analyticJacobians[index].resultVars[j];
DEBUG_INFO6((LOG_JAC | LOG_ENDJAC),"write in jac[%d]-[%d,%d]=%g from row[%d]=%g",k-1,i,j,jac[k-1],i,data->simulationInfo.analyticJacobians[index].resultVars[j]);
INFO6(LOG_JAC,"write in jac[%d]-[%d,%d]=%g from row[%d]=%g",k-1,i,j,jac[k-1],i,data->simulationInfo.analyticJacobians[index].resultVars[j]);
INFO6(LOG_ENDJAC,"write in jac[%d]-[%d,%d]=%g from row[%d]=%g",k-1,i,j,jac[k-1],i,data->simulationInfo.analyticJacobians[index].resultVars[j]);
}

data->simulationInfo.analyticJacobians[index].seedVars[i] = 0.0;
}
if (DEBUG_FLAG((LOG_JAC | LOG_ENDJAC)))
if (DEBUG_STREAM((LOG_JAC | LOG_ENDJAC)))
{
INFO("Print jac:");
INFO(LOG_JAC,"Print jac:");
for(i=0; i < data->simulationInfo.analyticJacobians[index].sizeRows;i++)
{
for(j=0; j < data->simulationInfo.analyticJacobians[index].sizeCols;j++)
Expand All @@ -106,26 +110,30 @@ int functionJacB(DATA* data, double* jac){
for(i=0; i < data->simulationInfo.analyticJacobians[index].sizeCols; i++)
{
data->simulationInfo.analyticJacobians[index].seedVars[i] = 1.0;
if (DEBUG_FLAG((LOG_JAC | LOG_ENDJAC)))
if (DEBUG_STREAM((LOG_JAC | LOG_ENDJAC)))
{
printf("Caluculate one col:\n");
for(j=0; j < data->simulationInfo.analyticJacobians[index].sizeCols;j++)
DEBUG_INFO2((LOG_JAC | LOG_ENDJAC),"seed: data->simulationInfo.analyticJacobians[index].seedVars[%d]= %f",j,data->simulationInfo.analyticJacobians[index].seedVars[j]);
{
INFO2(LOG_JAC,"seed: data->simulationInfo.analyticJacobians[index].seedVars[%d]= %f",j,data->simulationInfo.analyticJacobians[index].seedVars[j]);
INFO2(LOG_ENDJAC,"seed: data->simulationInfo.analyticJacobians[index].seedVars[%d]= %f",j,data->simulationInfo.analyticJacobians[index].seedVars[j]);
}
}

functionJacB_column(data);

for(j = 0; j < data->simulationInfo.analyticJacobians[index].sizeRows; j++)
{
jac[k++] = data->simulationInfo.analyticJacobians[index].resultVars[j];
DEBUG_INFO6((LOG_JAC | LOG_ENDJAC),"write in jac[%d]-[%d,%d]=%g from row[%d]=%g",k-1,i,j,jac[k-1],i,data->simulationInfo.analyticJacobians[index].resultVars[j]);
INFO6(LOG_JAC,"write in jac[%d]-[%d,%d]=%g from row[%d]=%g",k-1,i,j,jac[k-1],i,data->simulationInfo.analyticJacobians[index].resultVars[j]);
INFO6(LOG_ENDJAC,"write in jac[%d]-[%d,%d]=%g from row[%d]=%g",k-1,i,j,jac[k-1],i,data->simulationInfo.analyticJacobians[index].resultVars[j]);
}

data->simulationInfo.analyticJacobians[index].seedVars[i] = 0.0;
}
if (DEBUG_FLAG((LOG_JAC | LOG_ENDJAC)))
if (DEBUG_STREAM((LOG_JAC | LOG_ENDJAC)))
{
INFO("Print jac:");
INFO(LOG_JAC, "Print jac:");
for(i=0; i < data->simulationInfo.analyticJacobians[index].sizeRows;i++)
{
for(j=0; j < data->simulationInfo.analyticJacobians[index].sizeCols;j++)
Expand All @@ -144,26 +152,27 @@ int functionJacC(DATA* data, double* jac){
for(i=0; i < data->simulationInfo.analyticJacobians[index].sizeCols; i++)
{
data->simulationInfo.analyticJacobians[index].seedVars[i] = 1.0;
if (DEBUG_FLAG((LOG_JAC | LOG_ENDJAC)))
if (DEBUG_STREAM((LOG_JAC | LOG_ENDJAC)))
{
printf("Caluculate one col:\n");
for(j=0; j < data->simulationInfo.analyticJacobians[index].sizeCols;j++)
DEBUG_INFO2((LOG_JAC | LOG_ENDJAC),"seed: data->simulationInfo.analyticJacobians[index].seedVars[%d]= %f",j,data->simulationInfo.analyticJacobians[index].seedVars[j]);
INFO2((LOG_JAC | LOG_ENDJAC),"seed: data->simulationInfo.analyticJacobians[index].seedVars[%d]= %f",j,data->simulationInfo.analyticJacobians[index].seedVars[j]);
}

functionJacC_column(data);

for(j = 0; j < data->simulationInfo.analyticJacobians[index].sizeRows; j++)
{
jac[k++] = data->simulationInfo.analyticJacobians[index].resultVars[j];
DEBUG_INFO6((LOG_JAC | LOG_ENDJAC),"write in jac[%d]-[%d,%d]=%g from row[%d]=%g",k-1,i,j,jac[k-1],i,data->simulationInfo.analyticJacobians[index].resultVars[j]);
INFO6(LOG_JAC,"write in jac[%d]-[%d,%d]=%g from row[%d]=%g",k-1,i,j,jac[k-1],i,data->simulationInfo.analyticJacobians[index].resultVars[j]);
INFO6(LOG_ENDJAC,"write in jac[%d]-[%d,%d]=%g from row[%d]=%g",k-1,i,j,jac[k-1],i,data->simulationInfo.analyticJacobians[index].resultVars[j]);
}

data->simulationInfo.analyticJacobians[index].seedVars[i] = 0.0;
}
if (DEBUG_FLAG((LOG_JAC | LOG_ENDJAC)))
if (DEBUG_STREAM((LOG_JAC | LOG_ENDJAC)))
{
INFO("Print jac:");
INFO(LOG_JAC, "Print jac:");
for(i=0; i < data->simulationInfo.analyticJacobians[index].sizeRows;i++)
{
for(j=0; j < data->simulationInfo.analyticJacobians[index].sizeCols;j++)
Expand All @@ -182,26 +191,26 @@ int functionJacD(DATA* data, double* jac){
for(i=0; i < data->simulationInfo.analyticJacobians[index].sizeCols; i++)
{
data->simulationInfo.analyticJacobians[index].seedVars[i] = 1.0;
if (DEBUG_FLAG((LOG_JAC | LOG_ENDJAC)))
if (DEBUG_STREAM((LOG_JAC | LOG_ENDJAC)))
{
printf("Caluculate one col:\n");
for(j=0; j < data->simulationInfo.analyticJacobians[index].sizeCols;j++)
DEBUG_INFO2((LOG_JAC | LOG_ENDJAC),"seed: data->simulationInfo.analyticJacobians[index].seedVars[%d]= %f",j,data->simulationInfo.analyticJacobians[index].seedVars[j]);
INFO2((LOG_JAC | LOG_ENDJAC),"seed: data->simulationInfo.analyticJacobians[index].seedVars[%d]= %f",j,data->simulationInfo.analyticJacobians[index].seedVars[j]);
}

functionJacD_column(data);

for(j = 0; j < data->simulationInfo.analyticJacobians[index].sizeRows; j++)
{
jac[k++] = data->simulationInfo.analyticJacobians[index].resultVars[j];
DEBUG_INFO6((LOG_JAC | LOG_ENDJAC),"write in jac[%d]-[%d,%d]=%g from row[%d]=%g",k-1,i,j,jac[k-1],i,data->simulationInfo.analyticJacobians[index].resultVars[j]);
INFO6((LOG_JAC | LOG_ENDJAC),"write in jac[%d]-[%d,%d]=%g from row[%d]=%g",k-1,i,j,jac[k-1],i,data->simulationInfo.analyticJacobians[index].resultVars[j]);
}

data->simulationInfo.analyticJacobians[index].seedVars[i] = 0.0;
}
if (DEBUG_FLAG((LOG_JAC | LOG_ENDJAC)))
if (DEBUG_STREAM((LOG_JAC | LOG_ENDJAC)))
{
INFO("Print jac:");
INFO(LOG_JAC, "Print jac:");
for(i=0; i < data->simulationInfo.analyticJacobians[index].sizeRows;i++)
{
for(j=0; j < data->simulationInfo.analyticJacobians[index].sizeCols;j++)
Expand Down Expand Up @@ -285,8 +294,8 @@ int linearize(DATA* data)
FILE *fout = fopen(filename.c_str(),"wb");
ASSERT1(fout,"Cannot open File %s",filename.c_str());
fprintf(fout, linear_model_frame, strX.c_str(), strU.c_str(), strA.c_str(), strB.c_str(), strC.c_str(), strD.c_str());
if (DEBUG_FLAG(LOG_STATS))
DEBUG_INFO6(LOG_STATS, linear_model_frame, strX.c_str(), strU.c_str(), strA.c_str(), strB.c_str(), strC.c_str(), strD.c_str());
if (DEBUG_STREAM(LOG_STATS))
INFO6(LOG_STATS, linear_model_frame, strX.c_str(), strU.c_str(), strA.c_str(), strB.c_str(), strC.c_str(), strD.c_str());
fflush(fout);
fclose(fout);

Expand Down

0 comments on commit 0e22c33

Please sign in to comment.