Skip to content
This repository was archived by the owner on May 18, 2019. It is now read-only.

Commit aee683c

Browse files
ptaeuberOpenModelica-Hudson
authored andcommitted
Improve adaptive homotopy
- Add orthogonal backtrace strategy for homotopy corrector step - Break if tau cannot be decreased any further - Fix lambda in the last step to avoid going beyond 1 - Set tolerance in last homotopy step to global tolerance - Fix generation of homotopy component for equation systems - Some more debugging and clean up Belonging to [master]: - #2090 - OpenModelica/OpenModelica-testsuite#809
1 parent 7366c32 commit aee683c

File tree

12 files changed

+230
-90
lines changed

12 files changed

+230
-90
lines changed

Compiler/BackEnd/BackendDAEOptimize.mo

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6023,7 +6023,7 @@ algorithm
60236023

60246024
if hasHomotopy then
60256025
hasAnyHomotopy = true;
6026-
comp = BackendDAE.EQUATIONSYSTEM(eqnIndexes, varIndexes, jac, jacType, mixedSystem);
6026+
comp = BackendDAE.EQUATIONSYSTEM(eqnIndexes, listAppend(varIndexes, {lambdaIdx}), jac, jacType, mixedSystem);
60276027
end if;
60286028
then comp;
60296029

SimulationRuntime/c/simulation/simulation_runtime.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ static void readFlag(int *flag, int max, const char *value, const char *flagName
239239
}
240240

241241
warningStreamPrint(LOG_STDOUT, 1, "unrecognized option %s=%s, current options are:", flagName, value);
242-
for (i=1; i<LS_MAX; ++i) {
242+
for (i=1; i<max; ++i) {
243243
warningStreamPrint(LOG_STDOUT, 0, "%-18s [%s]", names[i], desc[i]);
244244
}
245245
messageClose(LOG_STDOUT);
@@ -758,6 +758,7 @@ int initRuntimeAndSimulation(int argc, char**argv, DATA *data, threadData_t *thr
758758
readFlag(&data->simulationInfo->nlsMethod, NLS_MAX, omc_flagValue[FLAG_NLS], "-nls", NLS_NAME, NLS_DESC);
759759
readFlag(&data->simulationInfo-> lsMethod, LS_MAX, omc_flagValue[FLAG_LS ], "-ls", LS_NAME, LS_DESC);
760760
readFlag(&data->simulationInfo->lssMethod, LSS_MAX, omc_flagValue[FLAG_LSS], "-lss", LSS_NAME, LSS_DESC);
761+
readFlag(&homBacktraceStrategy, HOM_BACK_STRAT_MAX, omc_flagValue[FLAG_HOMOTOPY_BACKTRACE_STRATEGY], "-homBacktraceStrategy", HOM_BACK_STRAT_NAME, HOM_BACK_STRAT_DESC);
761762
readFlag(&data->simulationInfo->newtonStrategy, NEWTON_MAX, omc_flagValue[FLAG_NEWTON_STRATEGY], "-newton", NEWTONSTRATEGY_NAME, NEWTONSTRATEGY_DESC);
762763
data->simulationInfo->nlsCsvInfomation = omc_flag[FLAG_NLS_INFO];
763764
readFlag(&data->simulationInfo->nlsLinearSolver, NLS_LS_MAX, omc_flagValue[FLAG_NLS_LS], "-nlsLS", NLS_LS_METHOD, NLS_LS_METHOD_DESC);

SimulationRuntime/c/simulation/solver/initialization/initialization.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ static int symbolic_initialization(DATA *data, threadData_t *threadData)
288288
}
289289
#endif
290290
}
291-
data->simulationInfo->homotopyUsed = 1;
291+
data->simulationInfo->homotopySteps += init_lambda_steps;
292292
messageClose(LOG_INIT);
293293

294294
#if !defined(OMC_NO_FILESYSTEM)
@@ -582,7 +582,7 @@ int initialization(DATA *data, threadData_t *threadData, const char* pInitMethod
582582
int retVal = -1;
583583
int i;
584584

585-
data->simulationInfo->homotopyUsed = 0;
585+
data->simulationInfo->homotopySteps = 0;
586586

587587
infoStreamPrint(LOG_INIT, 0, "### START INITIALIZATION ###");
588588

SimulationRuntime/c/simulation/solver/model_help.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ double homTauIncreasingThreshold = 10.0;
7777
double homTauMax = 10.0;
7878
double homTauMin = 1e-4;
7979
double homTauStart = 0.2;
80+
int homBacktraceStrategy = 1;
8081

8182
static double tolZC;
8283

SimulationRuntime/c/simulation/solver/model_help.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ extern double homTauIncreasingThreshold;
100100
extern double homTauMax;
101101
extern double homTauMin;
102102
extern double homTauStart;
103+
extern int homBacktraceStrategy;
103104

104105
void initializeDataStruc(DATA *data, threadData_t *threadData);
105106

SimulationRuntime/c/simulation/solver/nonlinearSolverHomotopy.c

Lines changed: 143 additions & 49 deletions
Large diffs are not rendered by default.

SimulationRuntime/c/simulation/solver/nonlinearSystem.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -874,7 +874,6 @@ int solve_nonlinear_system(DATA *data, threadData_t *threadData, int sysNumber)
874874
nonlinsys->solverData = mixedSolverData;
875875
}
876876
}
877-
data->simulationInfo->homotopyUsed = 1;
878877
}
879878
else {
880879
if (!(equidistantHomotopy && omc_flag[FLAG_HOMOTOPY_ON_FIRST_TRY])) {
@@ -939,7 +938,7 @@ int solve_nonlinear_system(DATA *data, threadData_t *threadData, int sysNumber)
939938
fclose(pFile);
940939
}
941940
#endif
942-
data->simulationInfo->homotopyUsed = 1;
941+
data->simulationInfo->homotopySteps += init_lambda_steps;
943942
}
944943

945944
/* handle asserts */

SimulationRuntime/c/simulation/solver/nonlinearSystem.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ int print_csvLineIterStats(void* csvData, int size, int num,
6363
extern void debugMatrixPermutedDouble(int logName, char* matrixName, double* matrix, int n, int m, int* indRow, int* indCol);
6464
extern void debugMatrixDouble(int logName, char* matrixName, double* matrix, int n, int m);
6565
extern void debugVectorDouble(int logName, char* vectorName, double* vector, int n);
66-
extern void debugVectorInt(int logName, char* vectorName, modelica_boolean* vector, int n);
66+
extern void debugVectorBool(int logName, char* vectorName, modelica_boolean* vector, int n);
67+
extern void debugVectorInt(int logName, char* vectorName, int* vector, int n);
6768

6869
static inline void debugString(int logName, char* message)
6970
{

SimulationRuntime/c/simulation/solver/solver_main.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,12 @@ int initializeModel(DATA* data, threadData_t *threadData, const char* init_initM
466466
retValue = -1;
467467
}
468468
if (!retValue)
469-
infoStreamPrint(LOG_SUCCESS, 0, "The initialization finished successfully %s homotopy method.", data->simulationInfo->homotopyUsed ? "with" : "without");
469+
{
470+
if (data->simulationInfo->homotopySteps == 0)
471+
infoStreamPrint(LOG_SUCCESS, 0, "The initialization finished successfully without homotopy method.");
472+
else
473+
infoStreamPrint(LOG_SUCCESS, 0, "The initialization finished successfully with %d homotopy steps.", data->simulationInfo->homotopySteps);
474+
}
470475

471476
success = 1;
472477
#if !defined(OMC_EMCC)

SimulationRuntime/c/simulation_data.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -594,7 +594,7 @@ typedef struct SIMULATION_INFO
594594
int jacobianEvals; /* number of different columns to evaluate functionODE */
595595
int currentJacobianEval; /* current column to evaluate functionODE for Jacobian*/
596596

597-
int homotopyUsed; /* =1 the initialization problem was solved with a homotopy method, =0 otherwise */
597+
int homotopySteps; /* the number of homotopy lambda steps during initialization, =0 no homotopy was used */
598598
double lambda; /* homotopy parameter E [0, 1.0] */
599599

600600
/* indicators for simulations state */

0 commit comments

Comments
 (0)