Skip to content

Commit

Permalink
Fix writing of homotopy csv-file for matrix elements
Browse files Browse the repository at this point in the history
Belonging to [master]:
  - OpenModelica/OMCompiler#1998
  • Loading branch information
ptaeuber authored and OpenModelica-Hudson committed Nov 8, 2017
1 parent 9cb312a commit 7360bc3
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 11 deletions.
Expand Up @@ -234,14 +234,15 @@ static int symbolic_initialization(DATA *data, threadData_t *threadData)
char buffer[4096];

#if !defined(OMC_NO_FILESYSTEM)
const char sep[] = ",";
if(ACTIVE_STREAM(LOG_INIT))
{
sprintf(buffer, "%s_global_homotopy.csv", mData->modelFilePrefix);
infoStreamPrint(LOG_INIT, 0, "The homotopy path will be exported to %s.", buffer);
pFile = fopen(buffer, "wt");
fprintf(pFile, "\"sep=,\"\n%s", "lambda");
fprintf(pFile, "\"sep=%s\"\n%s", sep, "\"lambda\"");
for(i=0; i<mData->nVariablesReal; ++i)
fprintf(pFile, ",%s", mData->realVarsData[i].info.name);
fprintf(pFile, "%s\"%s\"", sep, mData->realVarsData[i].info.name);
fprintf(pFile, "\n");
}
#endif
Expand All @@ -268,7 +269,7 @@ static int symbolic_initialization(DATA *data, threadData_t *threadData)
{
fprintf(pFile, "%.16g", data->simulationInfo->lambda);
for(i=0; i<mData->nVariablesReal; ++i)
fprintf(pFile, ",%.16g", data->localData[0]->realVars[i]);
fprintf(pFile, "%s%.16g", sep, data->localData[0]->realVars[i]);
fprintf(pFile, "\n");
}
#endif
Expand Down
12 changes: 7 additions & 5 deletions SimulationRuntime/c/simulation/solver/nonlinearSolverHomotopy.c
Expand Up @@ -1610,19 +1610,19 @@ static int homotopyAlgorithm(DATA_HOMOTOPY* solverData, double *x)
char buffer[4096];

#if !defined(OMC_NO_FILESYSTEM)
const char sep[] = ",";
if(solverData->initHomotopy && ACTIVE_STREAM(LOG_INIT))
{
sprintf(buffer, "%s_syst%d_new_global_homotopy_%s.csv", solverData->data->modelData->modelFilePrefix, solverData->sysNumber, solverData->startDirection > 0 ? "pos" : "neg");
infoStreamPrint(LOG_INIT, 0, "The homotopy path will be exported to %s.", buffer);
pFile = fopen(buffer, "wt");
fprintf(pFile, "\"sep=,\"\n");
fprintf(pFile, "%s", modelInfoGetEquation(&solverData->data->modelData->modelDataXml,solverData->eqSystemNumber).vars[n]);
fprintf(pFile, "\"sep=%s\"\n%s", sep, "\"lambda\"");
for(i=0; i<n; ++i)
fprintf(pFile, ",%s", modelInfoGetEquation(&solverData->data->modelData->modelDataXml,solverData->eqSystemNumber).vars[i]);
fprintf(pFile, "%s\"%s\"", sep, modelInfoGetEquation(&solverData->data->modelData->modelDataXml,solverData->eqSystemNumber).vars[i]);
fprintf(pFile, "\n");
fprintf(pFile, "0.0");
for(i=0; i<n; ++i)
fprintf(pFile, ",%.16g", x[i]);
fprintf(pFile, "%s%.16g", sep, x[i]);
fprintf(pFile, "\n");
}
#endif
Expand Down Expand Up @@ -1919,12 +1919,14 @@ static int homotopyAlgorithm(DATA_HOMOTOPY* solverData, double *x)
{
fprintf(pFile, "%.16g", solverData->y0[n]);
for(i=0; i<n; ++i)
fprintf(pFile, ",%.16g", solverData->y0[i]);
fprintf(pFile, "%s%.16g", sep, solverData->y0[i]);
fprintf(pFile, "\n");
}
#endif
}
}
if (solverData->initHomotopy)
infoStreamPrint(LOG_INIT, 0, "homotopy parameter lambda = %g", solverData->y0[solverData->n]);
/* copy solution back to vector x */
vecCopy(solverData->n, solverData->y1, x);

Expand Down
7 changes: 4 additions & 3 deletions SimulationRuntime/c/simulation/solver/nonlinearSystem.c
Expand Up @@ -861,14 +861,15 @@ int solve_nonlinear_system(DATA *data, threadData_t *threadData, int sysNumber)
warningStreamPrint(LOG_ASSERT, 0, "Failed to solve initial system %d without homotopy method. The homotopy method is used now.", sysNumber);
}
#if !defined(OMC_NO_FILESYSTEM)
const char sep[] = ",";
if(ACTIVE_STREAM(LOG_INIT))
{
sprintf(buffer, "%s_homotopy_nls_%d.csv", data->modelData->modelFilePrefix, sysNumber);
infoStreamPrint(LOG_INIT, 0, "The homotopy path of system %d will be exported to %s.", sysNumber, buffer);
pFile = fopen(buffer, "wt");
fprintf(pFile, "\"sep=,\"\n%s", "lambda");
fprintf(pFile, "\"sep=%s\"\n%s", sep, "\"lambda\"");
for(j=0; j<nonlinsys->size; ++j)
fprintf(pFile, ",%s", modelInfoGetEquation(&data->modelData->modelDataXml, nonlinsys->equationIndex).vars[j]);
fprintf(pFile, "%s\"%s\"", sep, modelInfoGetEquation(&data->modelData->modelDataXml, nonlinsys->equationIndex).vars[j]);
fprintf(pFile, "\n");
}
#endif
Expand All @@ -891,7 +892,7 @@ int solve_nonlinear_system(DATA *data, threadData_t *threadData, int sysNumber)
infoStreamPrint(LOG_INIT, 0, "[system %d] homotopy parameter lambda = %g done\n---------------------------", sysNumber, data->simulationInfo->lambda);
fprintf(pFile, "%.16g", data->simulationInfo->lambda);
for(j=0; j<nonlinsys->size; ++j)
fprintf(pFile, ",%.16g", nonlinsys->nlsx[j]);
fprintf(pFile, "%s%.16g", sep, nonlinsys->nlsx[j]);
fprintf(pFile, "\n");
}
#endif
Expand Down

0 comments on commit 7360bc3

Please sign in to comment.