Skip to content

Commit

Permalink
- added improved newton solver with damping strategies
Browse files Browse the repository at this point in the history
 - added -newton flag to simulation runtime to select different strategies


git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@21568 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
Willi Braun committed Jul 18, 2014
1 parent 94f0108 commit 2fb3bdf
Show file tree
Hide file tree
Showing 8 changed files with 483 additions and 142 deletions.
24 changes: 24 additions & 0 deletions SimulationRuntime/c/simulation/simulation_runtime.cpp
Expand Up @@ -286,6 +286,29 @@ int getlinearSolverMethod(int argc, char**argv)
return LS_NONE;
}

int getNewtonStrategy(int argc, char**argv)
{
int i;
const char *cflags = omc_flagValue[FLAG_NEWTON_STRATEGY];
const string *method = cflags ? new string(cflags) : NULL;

if(!method)
return NEWTON_DAMPED2; /* default method */

for(i=1; i<NEWTON_MAX; ++i)
if(*method == NEWTONSTRATEGY_NAME[i])
return i;

warningStreamPrint(LOG_STDOUT, 1, "unrecognized option -nls=%s, current options are:", method->c_str());
for(i=1; i<NEWTON_MAX; ++i)
warningStreamPrint(LOG_STDOUT, 0, "%-18s [%s]", NEWTONSTRATEGY_NAME[i], NEWTONSTRATEGY_DESC[i]);
messageClose(LOG_STDOUT);
throwStreamPrint(NULL,"see last warning");

return NEWTON_NONE;

}

/**
* Signals the type of the simulation
* retuns true for interactive and false for non-interactive
Expand Down Expand Up @@ -802,6 +825,7 @@ int initRuntimeAndSimulation(int argc, char**argv, DATA *data)

data->simulationInfo.nlsMethod = getNonlinearSolverMethod(argc, argv);
data->simulationInfo.lsMethod = getlinearSolverMethod(argc, argv);
data->simulationInfo.newtonStrategy = getNewtonStrategy(argc, argv);

rt_tick(SIM_TIMER_INIT_XML);
read_input_xml(&(data->modelData), &(data->simulationInfo));
Expand Down
1 change: 1 addition & 0 deletions SimulationRuntime/c/simulation/solver/model_help.c
Expand Up @@ -833,6 +833,7 @@ void initializeDataStruc(DATA *data)
data->simulationInfo.nlsMethod = NLS_HYBRID;
data->simulationInfo.lsMethod = LS_LAPACK;
data->simulationInfo.mixedMethod = MIXED_SEARCH;
data->simulationInfo.newtonStrategy = NEWTON_PURE;

data->simulationInfo.zeroCrossings = (modelica_real*) calloc(data->modelData.nZeroCrossings, sizeof(modelica_real));
data->simulationInfo.zeroCrossingsPre = (modelica_real*) calloc(data->modelData.nZeroCrossings, sizeof(modelica_real));
Expand Down

0 comments on commit 2fb3bdf

Please sign in to comment.