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

Commit

Permalink
Add flag to start running the homotopy path ...
Browse files Browse the repository at this point in the history
... in negative direction first.

Belonging to [master]:
  - #2040
  • Loading branch information
ptaeuber authored and OpenModelica-Hudson committed Nov 21, 2017
1 parent 5730246 commit 9ec3abd
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
Expand Up @@ -42,6 +42,7 @@
#include <stdlib.h>
#include <string.h> /* memcpy */

#include "simulation/options.h"
#include "simulation/simulation_info_json.h"
#include "util/omc_error.h"
#include "util/varinfo.h"
Expand Down Expand Up @@ -2250,15 +2251,15 @@ int solveHomotopy(DATA *data, threadData_t *threadData, int sysNumber)
if (runHomotopy == 1) {
solverData->h_function = wrapper_fvec;
solverData->hJac_dh = wrapper_fvec_der;
solverData->startDirection = 1.0;
solverData->startDirection = omc_flag[FLAG_HOMOTOPY_NEG_START_DIR] ? -1.0 : 1.0;
debugInt(LOG_INIT, "Homotopy run: ", runHomotopy);
debugDouble(LOG_INIT,"startDirection = ", solverData->startDirection);
}

if (runHomotopy == 2) {
solverData->h_function = wrapper_fvec;
solverData->hJac_dh = wrapper_fvec_der;
solverData->startDirection = -1.0;
solverData->startDirection = omc_flag[FLAG_HOMOTOPY_NEG_START_DIR] ? 1.0 : -1.0;
debugInt(LOG_INIT, "Homotopy run: ", runHomotopy);
debugDouble(LOG_INIT,"Try again with startDirection = ", solverData->startDirection);
}
Expand Down
5 changes: 5 additions & 0 deletions SimulationRuntime/c/util/simulation_options.c
Expand Up @@ -52,6 +52,7 @@ const char *FLAG_NAME[FLAG_MAX+1] = {
/* FLAG_HOMOTOPY_MAX_LAMBDA_STEPS */ "homMaxLambdaSteps",
/* FLAG_HOMOTOPY_MAX_NEWTON_STEPS */ "homMaxNewtonSteps",
/* FLAG_HOMOTOPY_MAX_TRIES */ "homMaxTries",
/* FLAG_HOMOTOPY_NEG_START_DIR */ "homNegStartDir",
/* FLAG_HOMOTOPY_ON_FIRST_TRY */ "homotopyOnFirstTry",
/* FLAG_HOMOTOPY_TAU_DEC_FACTOR */ "homTauDecFac",
/* FLAG_HOMOTOPY_TAU_DEC_FACTOR_PRED */ "homTauDecFacPredictor",
Expand Down Expand Up @@ -160,6 +161,7 @@ const char *FLAG_DESC[FLAG_MAX+1] = {
/* FLAG_HOMOTOPY_MAX_LAMBDA_STEPS */ "[int (default size dependent)] maximum lambda steps allowed to run the homotopy path",
/* FLAG_HOMOTOPY_MAX_NEWTON_STEPS */ "[int (default 20)] maximum newton steps in the homotopy corrector step",
/* FLAG_HOMOTOPY_MAX_TRIES */ "[int (default 10)] maximum number of tries for one homotopy lambda step",
/* FLAG_HOMOTOPY_NEG_START_DIR */ "start to run along the homotopy path in the negative direction",
/* FLAG_HOMOTOPY_ON_FIRST_TRY */ "directly use the homotopy method to solve the initialization problem",
/* FLAG_HOMOTOPY_TAU_DEC_FACTOR */ "[double (default 10.0)] decrease homotopy step size tau by this factor if tau is too big in the homotopy corrector step",
/* FLAG_HOMOTOPY_TAU_DEC_FACTOR_PRED */ "[double (default 2.0)] decrease homotopy step size tau by this factor if tau is too big in the homotopy predictor step",
Expand Down Expand Up @@ -294,6 +296,8 @@ const char *FLAG_DETAILED_DESC[FLAG_MAX+1] = {
" maximum newton steps in the homotopy corrector step",
/* FLAG_HOMOTOPY_MAX_TRIES */
" maximum number of tries for one homotopy lambda step",
/* FLAG_HOMOTOPY_NEG_START_DIR */
" start to run along the homotopy path in the negative direction",
/* FLAG_HOMOTOPY_ON_FIRST_TRY */
" If the model contains the homotopy operator, directly use the homotopy method to solve the initialization problem.\n"
" Without this flag, the solver first tries to solve the initialization problem without homotopy and only uses homotopy as fallback option.",
Expand Down Expand Up @@ -540,6 +544,7 @@ const int FLAG_TYPE[FLAG_MAX] = {
/* FLAG_HOMOTOPY_MAX_LAMBDA_STEPS */ FLAG_TYPE_OPTION,
/* FLAG_HOMOTOPY_MAX_NEWTON_STEPS */ FLAG_TYPE_OPTION,
/* FLAG_HOMOTOPY_MAX_TRIES */ FLAG_TYPE_OPTION,
/* FLAG_HOMOTOPY_NEG_START_DIR */ FLAG_TYPE_FLAG,
/* FLAG_HOMOTOPY_ON_FIRST_TRY */ FLAG_TYPE_FLAG,
/* FLAG_HOMOTOPY_TAU_DEC_FACTOR */ FLAG_TYPE_OPTION,
/* FLAG_HOMOTOPY_TAU_DEC_FACTOR_PRED */ FLAG_TYPE_OPTION,
Expand Down
1 change: 1 addition & 0 deletions SimulationRuntime/c/util/simulation_options.h
Expand Up @@ -60,6 +60,7 @@ enum _FLAG
FLAG_HOMOTOPY_MAX_LAMBDA_STEPS,
FLAG_HOMOTOPY_MAX_NEWTON_STEPS,
FLAG_HOMOTOPY_MAX_TRIES,
FLAG_HOMOTOPY_NEG_START_DIR,
FLAG_HOMOTOPY_ON_FIRST_TRY,
FLAG_HOMOTOPY_TAU_DEC_FACTOR,
FLAG_HOMOTOPY_TAU_DEC_FACTOR_PRED,
Expand Down

0 comments on commit 9ec3abd

Please sign in to comment.