Skip to content

Commit

Permalink
Changed the log functions from macros to vararg functions (since vara…
Browse files Browse the repository at this point in the history
…rg macros do not work very well and the current approach is not maintainable)

git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@18352 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
sjoelund committed Nov 29, 2013
1 parent fd9b4a5 commit 1d85211
Show file tree
Hide file tree
Showing 45 changed files with 1,145 additions and 1,134 deletions.
26 changes: 13 additions & 13 deletions Compiler/Template/CodegenC.tpl
Expand Up @@ -727,7 +727,7 @@ template functionInitializeDataStruc(ModelInfo modelInfo, String fileNamePrefix,
<<
void <%symbolName(modelNamePrefix,"setupDataStruc")%>(DATA *data)
{
ASSERT(data, "Error while initialize Data");
assertStreamPrint(0!=data, "Error while initialize Data");
data->callback = &<%symbolName(modelNamePrefix,"callback")%>;
<%populateModelInfo(modelInfo, fileNamePrefix, guid, allEquations, symJacs, delayed)%>
}
Expand Down Expand Up @@ -1104,10 +1104,10 @@ template functionCallExternalObjectConstructors(ExtObjInfo extObjInfo, String mo
{
<%varDecls%>
/* data->simulationInfo.extObjs = NULL; */
INFO(LOG_DEBUG, "call external Object Constructors");
infoStreamPrint(LOG_DEBUG, "call external Object Constructors");
<%ctorCalls%>
<%aliases |> (var1, var2) => '<%cref(var1)%> = <%cref(var2)%>;' ;separator="\n"%>
INFO(LOG_DEBUG, "call external Object Constructors finished");
infoStreamPrint(LOG_DEBUG, "call external Object Constructors finished");
}
>>
end match
Expand Down Expand Up @@ -1191,7 +1191,7 @@ template functionInitSample(BackendDAE.SampleLookup sampleLookup, String modelNa
data->modelData.samplesInfo[i].index = <%index%>;
data->modelData.samplesInfo[i].start = <%e1%>;
data->modelData.samplesInfo[i].interval = <%e2%>;
ASSERT(data->modelData.samplesInfo[i].interval > 0.0, "sample-interval <= 0.0");
assertStreamPrint(data->modelData.samplesInfo[i].interval > 0.0, "sample-interval <= 0.0");
i++;
>>)%>
}
Expand Down Expand Up @@ -1602,11 +1602,11 @@ template functionUpdateBoundStartValues(list<SimEqSystem> startValueEquations, S
<%eqPart%>
INFO(LOG_INIT, "updating start-values");
infoStreamPrint(LOG_INIT, "updating start-values");
INDENT(LOG_INIT);
<%startValueEquations |> SES_SIMPLE_ASSIGN(__) =>
<<
INFO2(LOG_INIT, "%s(start=<%crefToPrintfArg(cref)%>)", <%cref(cref)%>__varInfo.name, (<%crefType(cref)%>) <%cref(cref)%>);
infoStreamPrint(LOG_INIT, "%s(start=<%crefToPrintfArg(cref)%>)", <%cref(cref)%>__varInfo.name, (<%crefType(cref)%>) <%cref(cref)%>);
$P$ATTRIBUTE<%cref(cref)%>.start = <%cref(cref)%>;
>>
;separator="\n"%>
Expand Down Expand Up @@ -1657,7 +1657,7 @@ template functionInitialResidualBody(SimEqSystem eq, Text &varDecls /*BUFP*/, Te
let expPart = daeExp(exp, contextOther, &preExp /*BUFC*/, &varDecls /*BUFD*/)
<<
<%preExp%>initialResiduals[i++] = <%expPart%>;
INFO3(LOG_RES_INIT, "[%d]: %s = %g", i, <%symbolName(modelNamePrefix,"initialResidualDescription")%>(i-1), initialResiduals[i-1]);
infoStreamPrint(LOG_RES_INIT, "[%d]: %s = %g", i, <%symbolName(modelNamePrefix,"initialResidualDescription")%>(i-1), initialResiduals[i-1]);
>>
end match
else
Expand Down Expand Up @@ -1706,7 +1706,7 @@ template functionInitialResidual(list<SimEqSystem> residualEquations, String mod
int i = 0;
<%varDecls%>
INFO(LOG_RES_INIT, "updating initial residuals");
infoStreamPrint(LOG_RES_INIT, "updating initial residuals");
INDENT(LOG_RES_INIT);
<%body%>
RELEASE(LOG_RES_INIT);
Expand All @@ -1728,7 +1728,7 @@ template functionInitialEquations(Boolean useSymbolicInitialization, list<SimEqS
>>
;separator="\n")

let errorMsg = if not useSymbolicInitialization then 'ERROR0(LOG_INIT, "The symbolic initialization was not generated.");'
let errorMsg = if not useSymbolicInitialization then 'errorStreamPrint(LOG_INIT, "The symbolic initialization was not generated.");'

<<
<%&tmp%>
Expand Down Expand Up @@ -1865,7 +1865,7 @@ template functionWhenReinitStatementThen(Boolean initialCall, list<WhenOperator>
if not initialCall then
"data->simulationInfo.needToIterate = 1;"
<<
INFO1(LOG_EVENTS, "reinit <%cref(stateVar)%> = %f", <%val%>);
infoStreamPrint(LOG_EVENTS, "reinit <%cref(stateVar)%> = %f", <%val%>);
<%preExp%>
<%lhs%>
<%needToIterate%>
Expand Down Expand Up @@ -2776,7 +2776,7 @@ template functionCheckForDiscreteChanges(list<ComponentRef> discreteModelVars, S
<<
if(<%cref(var)%> != $P$PRE<%cref(var)%>)
{
INFO2(LOG_EVENTS_V, "discrete var changed: <%crefStr(var)%> from <%crefToPrintfArg(var)%> to <%crefToPrintfArg(var)%>", $P$PRE<%cref(var)%>, <%cref(var)%>);
infoStreamPrint(LOG_EVENTS_V, "discrete var changed: <%crefStr(var)%> from <%crefToPrintfArg(var)%> to <%crefToPrintfArg(var)%>", $P$PRE<%cref(var)%>, <%cref(var)%>);
needToIterate = 1;
}
>>
Expand All @@ -2787,7 +2787,7 @@ template functionCheckForDiscreteChanges(list<ComponentRef> discreteModelVars, S
{
int needToIterate = 0;
INFO(LOG_EVENTS_V, "check for discrete changes");
infoStreamPrint(LOG_EVENTS_V, "check for discrete changes");
INDENT(LOG_EVENTS_V);
<%changediscreteVars%>
RELEASE(LOG_EVENTS_V);
Expand Down Expand Up @@ -7336,7 +7336,7 @@ template algStmtReinit(DAE.Statement stmt, Context context, Text &varDecls /*BUF
<<
<%preExp%>
<%expPart1%> = <%expPart2%>;
INFO1(LOG_EVENTS, "reinit <%expPart1%> = %f", <%expPart1%>);
infoStreamPrint(LOG_EVENTS, "reinit <%expPart1%> = %f", <%expPart1%>);
data->simulationInfo.needToIterate = 1;
>>
end algStmtReinit;
Expand Down
54 changes: 26 additions & 28 deletions SimulationRuntime/c/linearization/linearize.cpp
Expand Up @@ -75,7 +75,7 @@ int functionJacA(DATA* data, double* jac){
printf("Caluculate one col:\n");
for(j=0; j < data->simulationInfo.analyticJacobians[index].sizeCols;j++)
{
INFO2(LOG_JAC,"seed: data->simulationInfo.analyticJacobians[index].seedVars[%d]= %f",j,data->simulationInfo.analyticJacobians[index].seedVars[j]);
infoStreamPrint(LOG_JAC,"seed: data->simulationInfo.analyticJacobians[index].seedVars[%d]= %f",j,data->simulationInfo.analyticJacobians[index].seedVars[j]);
}
}

Expand All @@ -84,14 +84,14 @@ int functionJacA(DATA* data, double* jac){
for(j = 0; j < data->simulationInfo.analyticJacobians[index].sizeRows; j++)
{
jac[k++] = 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]);
infoStreamPrint(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]);
}

data->simulationInfo.analyticJacobians[index].seedVars[i] = 0.0;
}
if(ACTIVE_STREAM(LOG_JAC))
{
INFO(LOG_JAC,"Print jac:");
infoStreamPrint(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 @@ -116,7 +116,7 @@ int functionJacB(DATA* data, double* jac){
printf("Caluculate one col:\n");
for(j=0; j < data->simulationInfo.analyticJacobians[index].sizeCols;j++)
{
INFO2(LOG_JAC,"seed: data->simulationInfo.analyticJacobians[index].seedVars[%d]= %f",j,data->simulationInfo.analyticJacobians[index].seedVars[j]);
infoStreamPrint(LOG_JAC,"seed: data->simulationInfo.analyticJacobians[index].seedVars[%d]= %f",j,data->simulationInfo.analyticJacobians[index].seedVars[j]);
}
}

Expand All @@ -125,14 +125,14 @@ int functionJacB(DATA* data, double* jac){
for(j = 0; j < data->simulationInfo.analyticJacobians[index].sizeRows; j++)
{
jac[k++] = 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]);
infoStreamPrint(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]);
}

data->simulationInfo.analyticJacobians[index].seedVars[i] = 0.0;
}
if(ACTIVE_STREAM(LOG_JAC))
{
INFO(LOG_JAC, "Print jac:");
infoStreamPrint(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 @@ -155,22 +155,22 @@ int functionJacC(DATA* data, double* jac){
{
printf("Caluculate one col:\n");
for(j=0; j < data->simulationInfo.analyticJacobians[index].sizeCols;j++)
INFO2(LOG_JAC,"seed: data->simulationInfo.analyticJacobians[index].seedVars[%d]= %f",j,data->simulationInfo.analyticJacobians[index].seedVars[j]);
infoStreamPrint(LOG_JAC,"seed: data->simulationInfo.analyticJacobians[index].seedVars[%d]= %f",j,data->simulationInfo.analyticJacobians[index].seedVars[j]);
}

data->callback->functionJacC_column(data);

for(j = 0; j < data->simulationInfo.analyticJacobians[index].sizeRows; j++)
{
jac[k++] = 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]);
infoStreamPrint(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]);
}

data->simulationInfo.analyticJacobians[index].seedVars[i] = 0.0;
}
if(ACTIVE_STREAM(LOG_JAC))
{
INFO(LOG_JAC, "Print jac:");
infoStreamPrint(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 @@ -192,23 +192,24 @@ int functionJacD(DATA* data, double* jac){
if(ACTIVE_STREAM(LOG_JAC))
{
printf("Caluculate one col:\n");
for(j=0; j < data->simulationInfo.analyticJacobians[index].sizeCols;j++)
INFO2(LOG_JAC,"seed: data->simulationInfo.analyticJacobians[index].seedVars[%d]= %f",j,data->simulationInfo.analyticJacobians[index].seedVars[j]);
for(j=0; j < data->simulationInfo.analyticJacobians[index].sizeCols;j++) {
infoStreamPrint(LOG_JAC,"seed: data->simulationInfo.analyticJacobians[index].seedVars[%d]= %f",j,data->simulationInfo.analyticJacobians[index].seedVars[j]);
}
}

data->callback->functionJacD_column(data);

for(j = 0; j < data->simulationInfo.analyticJacobians[index].sizeRows; j++)
{
jac[k++] = 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]);
infoStreamPrint(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]);
}

data->simulationInfo.analyticJacobians[index].seedVars[i] = 0.0;
}
if(ACTIVE_STREAM(LOG_JAC))
{
INFO(LOG_JAC, "Print jac:");
infoStreamPrint(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 @@ -234,36 +235,32 @@ int linearize(DATA* data)
double* matrixD = (double*)calloc(size_Outputs*size_Inputs,sizeof(double));
string strA, strB, strC, strD, strX, strU, filename, linearModel;

ASSERT(matrixA,"Calloc");
ASSERT(matrixB,"Calloc");
ASSERT(matrixC,"Calloc");;
ASSERT(matrixD,"Calloc");
assertStreamPrint(0!=matrixA,"calloc failed");
assertStreamPrint(0!=matrixB,"calloc failed");
assertStreamPrint(0!=matrixC,"calloc failed");;
assertStreamPrint(0!=matrixD,"calloc failed");

/* Determine Matrix A */
if(!data->callback->initialAnalyticJacobianA(data)){
if(functionJacA(data, matrixA))
THROW("Error, can not get Matrix A ");
assertStreamPrint(0==functionJacA(data, matrixA),"Error, can not get Matrix A ");
}
strA = array2string(matrixA,size_A,size_A);

/* Determine Matrix B */
if(!data->callback->initialAnalyticJacobianB(data)){
if(functionJacB(data, matrixB))
THROW("Error, can not get Matrix B ");
assertStreamPrint(0==functionJacB(data, matrixB),"Error, can not get Matrix B ");
}
strB = array2string(matrixB,size_A,size_Inputs);

/* Determine Matrix C */
if(!data->callback->initialAnalyticJacobianC(data)){
if(functionJacC(data, matrixC))
THROW("Error, can not get Matrix C ");
assertStreamPrint(0==functionJacC(data, matrixC),"Error, can not get Matrix C ");
}
strC = array2string(matrixC,size_Outputs,size_A);

/* Determine Matrix D */
if(!data->callback->initialAnalyticJacobianD(data)){
if(functionJacD(data, matrixD))
THROW("Error, can not get Matrix D ");
assertStreamPrint(0==functionJacD(data, matrixD),"Error, can not get Matrix D ");
}
strD = array2string(matrixD,size_Outputs,size_Inputs);

Expand All @@ -288,10 +285,11 @@ int linearize(DATA* data)
filename = "linear_" + string(data->modelData.modelName) + ".mo";

FILE *fout = fopen(filename.c_str(),"wb");
ASSERT1(fout,"Cannot open File %s",filename.c_str());
assertStreamPrint(0!=fout,"Cannot open File %s",filename.c_str());
fprintf(fout, data->callback->linear_model_frame(), strX.c_str(), strU.c_str(), strA.c_str(), strB.c_str(), strC.c_str(), strD.c_str());
if(ACTIVE_STREAM(LOG_STATS))
INFO6(LOG_STATS, data->callback->linear_model_frame(), strX.c_str(), strU.c_str(), strA.c_str(), strB.c_str(), strC.c_str(), strD.c_str());
if(ACTIVE_STREAM(LOG_STATS)) {
infoStreamPrint(LOG_STATS, data->callback->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
24 changes: 12 additions & 12 deletions SimulationRuntime/c/math-support/ddassl.c
Expand Up @@ -3757,19 +3757,19 @@ doublereal ddanrm_(integer *neq, doublereal *v, doublereal *wt, doublereal *
i__2 = *neq;
buffer = (char*)malloc(20*(*neq)*sizeof(char));

INFO1(LOG_JAC, "at point in time: %g", *x);
infoStreamPrint(LOG_JAC, "at point in time: %g", *x);
INDENT(LOG_JAC);

INFO1(LOG_JAC, "cj: %g", *cj);
INFO(LOG_JAC, "states");
infoStreamPrint(LOG_JAC, "cj: %g", *cj);
infoStreamPrint(LOG_JAC, "states");
INDENT(LOG_JAC);
for(k=0;k<*neq;k++)
{
INFO2(LOG_JAC, "[%ld] %g", (long) k+1, y[k+1]);
infoStreamPrint(LOG_JAC, "[%ld] %g", (long) k+1, y[k+1]);
}
RELEASE(LOG_JAC);

INFO(LOG_JAC, "analytical Jacobian");
infoStreamPrint(LOG_JAC, "analytical Jacobian");
INDENT(LOG_JAC);
for(i__ = 1; i__ <= i__1; ++i__)
{
Expand All @@ -3779,7 +3779,7 @@ doublereal ddanrm_(integer *neq, doublereal *v, doublereal *wt, doublereal *
{
sprintf(buffer, "%s%g ", buffer, wm[nrow + l]);
}
INFO1(LOG_JAC, "%s", buffer);
infoStreamPrint(LOG_JAC, "%s", buffer);
wm[nrow+i__] -= *cj;
nrow += *neq;
}
Expand Down Expand Up @@ -3837,19 +3837,19 @@ doublereal ddanrm_(integer *neq, doublereal *v, doublereal *wt, doublereal *
i__2 = *neq;
buffer = (char*)malloc(20*(*neq)*sizeof(char));

INFO1(LOG_JAC, "at point in time: %g", *x);
infoStreamPrint(LOG_JAC, "at point in time: %g", *x);
INDENT(LOG_JAC);

INFO1(LOG_JAC, "cj: %g", *cj);
INFO(LOG_JAC, "states");
infoStreamPrint(LOG_JAC, "cj: %g", *cj);
infoStreamPrint(LOG_JAC, "states");
INDENT(LOG_JAC);
for(k=0;k<*neq;k++)
{
INFO2(LOG_JAC, "[%ld] %g", (long) k+1, y[k+1]);
infoStreamPrint(LOG_JAC, "[%ld] %g", (long) k+1, y[k+1]);
}
RELEASE(LOG_JAC);

INFO(LOG_JAC, "numerical Jacobian");
infoStreamPrint(LOG_JAC, "numerical Jacobian");
INDENT(LOG_JAC);
for(i__ = 1; i__ <= i__1; ++i__)
{
Expand All @@ -3859,7 +3859,7 @@ doublereal ddanrm_(integer *neq, doublereal *v, doublereal *wt, doublereal *
{
sprintf(buffer, "%s%g ", buffer, wm[nrow + l]);
}
INFO1(LOG_JAC, "%s", buffer);
infoStreamPrint(LOG_JAC, "%s", buffer);
wm[nrow+i__] -= *cj;
nrow += *neq;
}
Expand Down
Expand Up @@ -64,7 +64,7 @@ int initial_guess_ipopt(IPOPT_DATA_ *iData,SOLVER_INFO* solverInfo)

tol = data->simulationInfo.tolerance;
data->simulationInfo.tolerance = fmin(fmax(tol,1e-8),1e-3);
INFO(LOG_SOLVER, "Initializing DASSL");
infoStreamPrint(LOG_SOLVER, "Initializing DASSL");
sInfo->solverMethod = "dasslColorSymJac";
solverInfo->solverMethod = S_DASSL;
dasrt_initial(iData->data, solverInfo, dasslData);
Expand Down

0 comments on commit 1d85211

Please sign in to comment.