Skip to content

Commit

Permalink
Improve --help=simulation
Browse files Browse the repository at this point in the history
Some fixes for #3371
- Added solver details to simulation options file so omc can find it.
- Added --help=simulation-sphinxoutput
  • Loading branch information
sjoelund authored and OpenModelica-Hudson committed Jun 24, 2015
1 parent ec9f2b8 commit 3c02ab5
Show file tree
Hide file tree
Showing 11 changed files with 434 additions and 263 deletions.
7 changes: 6 additions & 1 deletion Compiler/Util/Flags.mo
Expand Up @@ -2017,7 +2017,12 @@ algorithm

case {"simulation"}
equation
help = System.gettext("The simulation executable takes the following flags:\n") + System.getSimulationHelpText(true);
help = System.gettext("The simulation executable takes the following flags:\n\n") + System.getSimulationHelpText(true);
then help;

case {"simulation-sphinxoutput"}
equation
help = System.gettext("The simulation executable takes the following flags:\n\n") + System.getSimulationHelpText(true,sphinx=true);
then help;

case {"debug"}
Expand Down
5 changes: 3 additions & 2 deletions Compiler/Util/System.mo
Expand Up @@ -1029,9 +1029,10 @@ public function realpath
end realpath;

public function getSimulationHelpText
input Boolean detailed;
input Boolean detailed=false;
input Boolean sphinx=false;
output String text;
external "C" text = System_getSimulationHelpText(detailed) annotation(Library = {"omcruntime"});
external "C" text = System_getSimulationHelpTextSphinx(detailed,sphinx) annotation(Library = {"omcruntime"});
end getSimulationHelpText;

public function getTerminalWidth
Expand Down
82 changes: 78 additions & 4 deletions Compiler/runtime/systemimpl.c
Expand Up @@ -2590,19 +2590,87 @@ int System_getTerminalWidth(void)

#include "simulation_options.h"

char* System_getSimulationHelpText(int detailed)
char* System_getSimulationHelpTextSphinx(int detailed, int sphinx)
{
static char buf[8192];
int i;
int i,j;
const char **desc = detailed ? FLAG_DETAILED_DESC : FLAG_DESC;
char *cur = buf;
*cur = 0;
for(i=1; i<FLAG_MAX; ++i)
{
if (sphinx) {
cur += snprintf(cur, 8191-(buf-cur), "\n.. _simflag-%s :\n\n", FLAG_NAME[i]);
}
if (FLAG_TYPE[i] == FLAG_TYPE_FLAG) {
cur += snprintf(cur, 8191-(buf-cur), "<-%s>\n %s\n", FLAG_NAME[i], desc[i]);
if (sphinx) {
cur += snprintf(cur, 8191-(buf-cur), ":ref:`-%s <simflag-%s>`\n%s\n", FLAG_NAME[i], FLAG_NAME[i], desc[i]);
} else {
cur += snprintf(cur, 8191-(buf-cur), "<-%s>\n%s\n", FLAG_NAME[i], desc[i]);
}
} else if (FLAG_TYPE[i] == FLAG_TYPE_OPTION) {
cur += snprintf(cur, 8191-(buf-cur), "<-%s=value> or <-%s value>\n %s\n", FLAG_NAME[i], FLAG_NAME[i], desc[i]);
int numExtraFlags=0;
int firstExtraFlag=1;
const char **flagName;
const char **flagDesc;
if (sphinx) {
cur += snprintf(cur, 8191-(buf-cur), ":ref:`-%s=value <simflag-%s>` *or* -%s value \n%s\n", FLAG_NAME[i], FLAG_NAME[i], FLAG_NAME[i], desc[i]);
} else {
cur += snprintf(cur, 8191-(buf-cur), "<-%s=value> or <-%s value>\n%s\n", FLAG_NAME[i], FLAG_NAME[i], desc[i]);
}

switch(i) {
case FLAG_LS:
numExtraFlags = LS_MAX;
flagName = LS_NAME;
flagDesc = LS_DESC;
break;

case FLAG_NLS:
numExtraFlags = NLS_MAX;
flagName = NLS_NAME;
flagDesc = NLS_DESC;
break;

case FLAG_NEWTON_STRATEGY:
numExtraFlags = NEWTON_MAX;
flagName = NEWTONSTRATEGY_NAME;
flagDesc = NEWTONSTRATEGY_DESC;
break;

case FLAG_LV:
firstExtraFlag=firstOMCErrorStream;
numExtraFlags = SIM_LOG_MAX;
flagName = LOG_STREAM_NAME;
flagDesc = LOG_STREAM_DESC;
break;

case FLAG_IIM:
numExtraFlags = IIM_MAX;
flagName = INIT_METHOD_NAME;
flagDesc = INIT_METHOD_DESC;
break;

case FLAG_S:
numExtraFlags = S_MAX;
flagName = NULL;
flagDesc = SOLVER_METHOD_DESC;
break;
}

if (numExtraFlags) {
cur += snprintf(cur, 8191-(buf-cur), "\n");
if (flagName) {
for (j=firstExtraFlag; j<numExtraFlags; j++) {
cur += snprintf(cur, 8191-(buf-cur), " * %s (%s)\n", flagName[j], flagDesc[j]);
}
} else {
for (j=firstExtraFlag; j<numExtraFlags; j++) {
cur += snprintf(cur, 8191-(buf-cur), " * %s\n", flagDesc[j]);
}
}
}

} else {
cur += snprintf(cur, 8191-(buf-cur), "[unknown flag-type] <-%s>\n", FLAG_NAME[i]);
}
Expand All @@ -2611,6 +2679,12 @@ char* System_getSimulationHelpText(int detailed)
return buf;
}

/* TODO: Remove me with new tarball */
char* System_getSimulationHelpText(int detailed)
{
return System_getSimulationHelpTextSphinx(detailed, 0);
}

int SystemImpl__fileIsNewerThan(const char *file1, const char *file2)
{
#if defined(_MSC_VER)
Expand Down
Expand Up @@ -42,25 +42,6 @@ extern "C"
{
#endif

enum INIT_INIT_METHOD
{
IIM_UNKNOWN = 0,
IIM_NONE,
IIM_SYMBOLIC,
IIM_MAX
};

static const char *INIT_METHOD_NAME[IIM_MAX] = {
"unknown",
"none",
"symbolic"
};
static const char *INIT_METHOD_DESC[IIM_MAX] = {
"unknown",
"sets all variables to their start values and skips the initialization process",
"solves the initialization problem symbolically - default"
};

extern int initialization(DATA *data, const char* pInitMethod, const char* pInitFile, double initTime, int lambda_steps);
int importStartValues(DATA *data, const char *pInitFile, const double initTime);

Expand Down
28 changes: 0 additions & 28 deletions SimulationRuntime/c/simulation/solver/linearSystem.c
Expand Up @@ -52,34 +52,6 @@ static void setBElementLis(int row, double value, void *data );

int check_linear_solution(DATA *data, int printFailingSystems, int sysNumber);

const char *LS_NAME[LS_MAX+1] = {
"LS_UNKNOWN",

/* LS_LAPACK */ "lapack",
#if !defined(OMC_MINIMAL_RUNTIME)
/* LS_LIS */ "lis",
#endif
/* LS_UMFPACK */ "umfpack",
/* LS_TOTALPIVOT */ "totalpivot",
/* LS_DEFAULT */ "default",

"LS_MAX"
};

const char *LS_DESC[LS_MAX+1] = {
"unknown",

/* LS_LAPACK */ "method using lapack LU factorization",
#if !defined(OMC_MINIMAL_RUNTIME)
/* LS_LIS */ "method using iterativ solver Lis",
#endif
/* LS_UMFPACK */ "method using umfpack sparse linear solver",
/* LS_TOTALPIVOT */ "method using a total pivoting LU factorization for underdetermination systems",
/* LS_DEFAULT */ "default method - lapack with total pivoting as fallback",

"LS_MAX"
};

/* Data structure for the default solver
* where two different solverData for lapack and
* totalpivot as fallback
Expand Down
19 changes: 1 addition & 18 deletions SimulationRuntime/c/simulation/solver/linearSystem.h
Expand Up @@ -36,6 +36,7 @@
#define _LINEARSYSTEM_H_

#include "simulation_data.h"
#include "util/simulation_options.h"

#ifdef __cplusplus
extern "C" {
Expand All @@ -45,24 +46,6 @@ extern "C" {
#undef VOID
#endif

enum LINEAR_SOLVER
{
LS_NONE = 0,

LS_LAPACK,
#if !defined(OMC_MINIMAL_RUNTIME)
LS_LIS,
#endif
LS_UMFPACK,
LS_TOTALPIVOT,
LS_DEFAULT,

LS_MAX
};

extern const char *LS_NAME[LS_MAX+1];
extern const char *LS_DESC[LS_MAX+1];

typedef void* LS_SOLVER_DATA;

int initializeLinearSystems(DATA *data);
Expand Down
52 changes: 0 additions & 52 deletions SimulationRuntime/c/simulation/solver/nonlinearSystem.c
Expand Up @@ -48,58 +48,6 @@

int check_nonlinear_solution(DATA *data, int printFailingSystems, int sysNumber);

const char *NLS_NAME[NLS_MAX+1] = {
"NLS_UNKNOWN",

#if !defined(OMC_MINIMAL_RUNTIME)
/* NLS_HYBRID */ "hybrid",
/* NLS_KINSOL */ "kinsol",
/* NLS_NEWTON */ "newton",
#endif
/* NLS_HOMOTOPY */ "homotopy",
#if !defined(OMC_MINIMAL_RUNTIME)
/* NLS_MIXED */ "mixed",
#endif
"NLS_MAX"
};

const char *NLS_DESC[NLS_MAX+1] = {
"unknown",

#if !defined(OMC_MINIMAL_RUNTIME)
/* NLS_HYBRID */ "Modification of the Powell hybrid method from minpack - former default solver",
/* NLS_KINSOL */ "sundials/kinsol - prototype implementation",
/* NLS_NEWTON */ "Newton Raphson - prototype implementation",
#endif
/* NLS_HOMOTOPY */ "Damped Newton solver if failing case fixed-point and Newton homotopies are tried.",
#if !defined(OMC_MINIMAL_RUNTIME)
/* NLS_MIXED */ "Mixed strategy. First the homotopy solver is tried and then as fallback the hybrid solver.",
#endif
"NLS_MAX"
};

const char *NEWTONSTRATEGY_NAME[NEWTON_MAX+1] = {
"NEWTON_UNKNOWN",

/* NEWTON_DAMPED */ "damped",
/* NEWTON_DAMPED2 */ "damped2",
/* NEWTON_DAMPED_LS */ "damped_ls",
/* NEWTON_PURE */ "pure",

"NEWTON_MAX"
};

const char *NEWTONSTRATEGY_DESC[NEWTON_MAX+1] = {
"unknown",

/* NEWTON_DAMPED */ "Newton with a damping strategy",
/* NEWTON_DAMPED2 */ "Newton with a damping strategy 2",
/* NEWTON_DAMPED_LS */ "Newton with a damping line search",
/* NEWTON_PURE */ "Newton without damping strategy",

"NEWTON_MAX"
};

struct dataNewtonAndHybrid {
void* newtonData;
void* hybridData;
Expand Down
35 changes: 1 addition & 34 deletions SimulationRuntime/c/simulation/solver/nonlinearSystem.h
Expand Up @@ -36,6 +36,7 @@
#define _NONLINEARSYSTEM_H_

#include "simulation_data.h"
#include "util/simulation_options.h"

#ifdef __cplusplus
extern "C" {
Expand All @@ -45,40 +46,6 @@ extern "C" {
#undef VOID
#endif

enum NONLINEAR_SOLVER
{
NLS_NONE = 0,

#if !defined(OMC_MINIMAL_RUNTIME)
NLS_HYBRID,
NLS_KINSOL,
#endif
NLS_NEWTON,
NLS_HOMOTOPY,
NLS_MIXED,

NLS_MAX
};


enum NEWTON_STRATEGY
{
NEWTON_NONE = 0,

NEWTON_DAMPED,
NEWTON_DAMPED2,
NEWTON_DAMPED_LS,
NEWTON_PURE,

NEWTON_MAX
};

extern const char *NLS_NAME[NLS_MAX+1];
extern const char *NLS_DESC[NLS_MAX+1];

extern const char *NEWTONSTRATEGY_NAME[NEWTON_MAX+1];
extern const char *NEWTONSTRATEGY_DESC[NEWTON_MAX+1];

typedef void* NLS_SOLVER_DATA;

int initializeNonlinearSystems(DATA *data);
Expand Down
52 changes: 1 addition & 51 deletions SimulationRuntime/c/simulation/solver/solver_main.h
Expand Up @@ -40,6 +40,7 @@
#include "openmodelica.h"
#include "simulation_data.h"
#include "util/list.h"
#include "util/simulation_options.h"

typedef struct SOLVER_INFO
{
Expand All @@ -66,57 +67,6 @@ typedef struct SOLVER_INFO
extern "C" {
#endif

enum SOLVER_METHOD
{
S_UNKNOWN = 0,

S_EULER, /* 1 */
S_RUNGEKUTTA, /* 2 */
S_DASSL, /* 3 */
S_OPTIMIZATION, /* 4 */
S_RADAU5, /* 5 */
S_RADAU3, /* 6 */
S_RADAU1, /* 7 */
S_LOBATTO2, /* 8 */
S_LOBATTO4, /* 9 */
S_LOBATTO6, /* 10 */
S_SYM_EULER, /* 11 */
S_QSS,

S_MAX
};

static const char *SOLVER_METHOD_NAME[S_MAX] = {
"unknown",
"euler",
"rungekutta",
"dassl",
"optimization",
"radau5",
"radau3",
"radau1",
"lobatto2",
"lobatto4",
"lobatto6",
"symEuler",
"qss"
};
static const char *SOLVER_METHOD_DESC[S_MAX] = {
"unknown",
"euler",
"rungekutta",
"dassl with colored numerical jacobian, with interval root finding - default",
"optimization",
"radau5 [sundial/kinsol needed]",
"radau3 [sundial/kinsol needed]",
"radau1 [sundial/kinsol needed]",
"lobatto2 [sundial/kinsol needed]",
"lobatto4 [sundial/kinsol needed]",
"lobatto6 [sundial/kinsol needed]",
"symbolic implicit euler, [compiler flag +symEuler needed]",
"qss"
};

extern int solver_main(DATA* data, const char* init_initMethod,
const char* init_file, double init_time, int lambda_steps,
int solverID, const char* outputVariablesAtEnd);
Expand Down

0 comments on commit 3c02ab5

Please sign in to comment.