Skip to content

Commit

Permalink
- some minor changes for simulation dumps
Browse files Browse the repository at this point in the history
- if unsupported -lv flag is used, a list of all supported -lv flags is shown


git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@14346 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
lochel committed Dec 12, 2012
1 parent 5ce247b commit 3bd3e72
Show file tree
Hide file tree
Showing 5 changed files with 153 additions and 66 deletions.
26 changes: 17 additions & 9 deletions SimulationRuntime/c/simulation/options.cpp
Expand Up @@ -36,31 +36,39 @@ using namespace std;

int flagSet(const char *option, int argc, char** argv)
{
for(int i=0; i<argc;i++) {
if(("-"+string(option))==string(argv[i])) return 1;
for(int i=0; i<argc;i++)
{
if(("-"+string(option)) == string(argv[i]))
return 1;
}
return 0;
}
/* returns the value of a flag on the form -flagname=value
*/

/* returns the value of a flag on the form -flagname=value */
const string* getOption(const char *option, int argc, char **argv)
{
for(int i=0; i<argc;i++) {
for(int i=0; i<argc;i++)
{
string tmpStr=string(argv[i]);
if(("-"+string(option))==(tmpStr.substr(0,tmpStr.find("=")))) {
if(("-"+string(option)) == (tmpStr.substr(0,tmpStr.find("="))))
{
string str=string(argv[i]);
return new string(str.substr(str.find("=")+1));
}
}
return NULL;
}

/* returns the value of a flag on the form -flagname value */
const string* getFlagValue(const char *option, int argc, char **argv)
{
for(int i=0; i<argc;i++) {
for(int i=0; i<argc;i++)
{
string tmpStr=string(argv[i]);
if(("-"+string(option))==string(argv[i])) {
if(argc > i+1) {
if(("-"+string(option)) == string(argv[i]))
{
if(argc > i+1)
{
return new string(argv[i+1]);
}
}
Expand Down
141 changes: 91 additions & 50 deletions SimulationRuntime/c/simulation/simulation_runtime.cpp
Expand Up @@ -147,8 +147,9 @@ void setTermMsg(const char *msg)
*/
void setGlobalVerboseLevel(int argc, char**argv)
{
const string * flags = getFlagValue("lv", argc, argv);
const string *flags = getFlagValue("lv", argc, argv);
int i;
int error = 0;

if(!flags)
{
Expand All @@ -160,19 +161,42 @@ void setGlobalVerboseLevel(int argc, char**argv)

if(flags->find("LOG_ALL", 0) != string::npos)
{
for(i=0; i<LOG_MAX; ++i)
for(i=1; i<LOG_MAX; ++i)
useStream[i] = 1;
}
else
{
for(i=0; i<LOG_MAX; ++i)
string flagList = *flags;
string flag;
unsigned long pos;
int localError;

do
{
if(flags->find(LOG_STREAM_NAME[i], 0) != string::npos)
useStream[i] = 1;
localError = 1;
pos = flagList.find(",", 0);
if(pos != string::npos)
{
flag = flagList.substr(0, pos);
flagList = flagList.substr(pos+1);
}
else
useStream[i] = 0;
}
flag = flagList;

for(i=1; i<LOG_MAX; ++i)
{
if(flag == string(LOG_STREAM_NAME[i]))
{
useStream[i] = 1;
localError = 0;
}
}

if(localError)
error = 1;
}while(pos != string::npos);
}

/* default activated */
useStream[LOG_STDOUT] = 1;
useStream[LOG_ASSERT] = 1;
Expand All @@ -185,6 +209,17 @@ void setGlobalVerboseLevel(int argc, char**argv)
if(useStream[LOG_SOLVER] == 1)
useStream[LOG_STATS] = 1;

if(error)
{
WARNING1(LOG_STDOUT, "unrecognized option -lv %s", flags->c_str());
WARNING(LOG_STDOUT, "current options are:");
INDENT(LOG_STDOUT);
for(i=1; i<LOG_MAX; ++i)
WARNING2(LOG_STDOUT, "%-18s [%s]", LOG_STREAM_NAME[i], LOG_STREAM_DETAILED_DESC[i]);
RELEASE(LOG_STDOUT);
THROW("see last warning");
}

delete flags;
}

Expand Down Expand Up @@ -484,51 +519,57 @@ int callSolver(DATA* simData, string result_file_cstr, string init_initMethod,
*/
int initRuntimeAndSimulation(int argc, char**argv, DATA *data)
{
int i;
initDumpSystem();

if(flagSet("?", argc, argv) || flagSet("help", argc, argv))
{
cout << "usage: " << argv[0] << "\n\t"
<< "<-f setup file> "
"\n\t\t[specify a new setup XML file to the generated simulation code]" << "\n\t"
<< "<-r result file> "
"\n\t\t[specify a new result file than the default Model_res.mat]" << "\n\t"
<< "<-m|s solver:{dassl,euler,rungekutta,inline-euler,inline-rungekutta,qss}> "
"\n\t\t[specify the solver]" << "\n\t"
<< "<-interactive> <-port value> "
"\n\t\t[specify interactive simulation and port]" << "\n\t"
<< "<-iim initialization method:{none,numeric,symbolic}> "
"\n\t\t[specify the initialization method]" << "\n\t"
<< "<-iom optimization method:{nelder_mead_ex,nelder_mead_ex2,simplex,newuoa}> "
"\n\t\t[specify the initialization optimization method]" << "\n\t"
<< "<-iif initialization file> "
"\n\t\t[specify an external file for the initialization of the model]" << "\n\t"
<< "<-iit initialization time> "
"\n\t\t[specify a time for the initialization of the model]" << "\n\t"
<< "<-override var1=start1,var2=start2,par3=start3,\n\t "
"startTime=val1,stopTime=val2,stepSize=val3,tolerance=val4,\n\t "
"solver=\"see -m\",outputFormat=\"mat|plt|csv|empty\",variableFilter=\"filter\"> "
"\n\t\t[override the variables or the simulation settings in the XML setup file]" << "\n\t"
<< "<-overrideFile overrideFileName"
"\n\t\t[note that: -overrideFile CANNOT be used with -override]" <<
"\n\t\t[use when variables for -override are too many and do not fit in command line size]" <<
"\n\t\t[overrideFileName contains lines of the form: var1=start1]" <<
"\n\t\t[will override the variables or the simulation settings in the XML setup file with the values from the file]" << "\n\t"
<< "<-output a,b,c>"
"\n\t\t[output the variables a, b and c at the end of the simulation to the standard output as time = value, a = value, b = value, c = value]" << "\n\t"
<< "<-noemit>"
"\n\t\t[do not emit any results to the result file]" << "\n\t"
<< "<-jac> " <<
"\n\t\t[specify jacobian]" << "\n\t"
<< "<-numjac> " <<
"\n\t\t[specify numerical jacobian]" << "\n\t"
<< "<-l linear time> "
"\n\t\t[specify a time where the linearization of the model should be performed]" << "\n\t"
<< "<-mt> "
"\n\t\t[this command line parameter is DEPRECATED!]" << "\n\t"
<< "<-measureTimePlotFormat svg|jpg|ps|gif|...> "
"\n\t\t[specify the output format of the measure time functionality]" << "\n\t"
<< "<-lv [LOG_STATS][,LOG_INIT][,LOG_RES_INIT][,LOG_SOLVER][,LOG_EVENTS][,LOG_NONLIN_SYS][,LOG_ZEROCROSSINGS][,LOG_DEBUG]> "
"\n\t\t[specify the logging level]" << "\n\t"
<< endl;
INFO1(LOG_STDOUT, "usage: %s", argv[0]);
INDENT(LOG_STDOUT);
INFO(LOG_STDOUT, "<-f setup file>");
INFO(LOG_STDOUT, "\tspecify a new setup XML file to the generated simulation code");
INFO(LOG_STDOUT, "<-r result file>");
INFO(LOG_STDOUT, "\tspecify a new result file than the default Model_res.mat");
INFO(LOG_STDOUT, "<-m|s solver:{dassl,euler,rungekutta,inline-euler,inline-rungekutta,qss}>");
INFO(LOG_STDOUT, "\tspecify the solver");
INFO(LOG_STDOUT, "<-interactive> <-port value>");
INFO(LOG_STDOUT, "\tspecify interactive simulation and port");
INFO(LOG_STDOUT, "<-iim initialization method:{none,numeric,symbolic}>");
INFO(LOG_STDOUT, "\tspecify the initialization method");
INFO(LOG_STDOUT, "<-iom optimization method:{nelder_mead_ex,nelder_mead_ex2,simplex,newuoa}>");
INFO(LOG_STDOUT, "\tspecify the initialization optimization method");
INFO(LOG_STDOUT, "<-iif initialization file>");
INFO(LOG_STDOUT, "\tspecify an external file for the initialization of the model");
INFO(LOG_STDOUT, "<-iit initialization time>");
INFO(LOG_STDOUT, "\tspecify a time for the initialization of the model");
INFO(LOG_STDOUT, "<-override var1=start1,var2=start2,par3=start3,");
INFO(LOG_STDOUT, " startTime=val1,stopTime=val2,stepSize=val3,tolerance=val4,");
INFO(LOG_STDOUT, " solver=\"see -m\",outputFormat=\"mat|plt|csv|empty\",variableFilter=\"filter\">");
INFO(LOG_STDOUT, "\toverride the variables or the simulation settings in the XML setup file");
INFO(LOG_STDOUT, "<-overrideFile overrideFileName>");
INFO(LOG_STDOUT, "\tnote that: -overrideFile CANNOT be used with -override");
INFO(LOG_STDOUT, "\tuse when variables for -override are too many and do not fit in command line size");
INFO(LOG_STDOUT, "\toverrideFileName contains lines of the form: var1=start1");
INFO(LOG_STDOUT, "\twill override the variables or the simulation settings in the XML setup file with the values from the file");
INFO(LOG_STDOUT, "<-output a,b,c>");
INFO(LOG_STDOUT, "\toutput the variables a, b and c at the end of the simulation to the standard output as time = value, a = value, b = value, c = value");
INFO(LOG_STDOUT, "<-noemit>");
INFO(LOG_STDOUT, "\tdo not emit any results to the result file");
INFO(LOG_STDOUT, "<-jac> ");
INFO(LOG_STDOUT, "\tspecify jacobian");
INFO(LOG_STDOUT, "<-numjac> ");
INFO(LOG_STDOUT, "\tspecify numerical jacobian");
INFO(LOG_STDOUT, "<-l linear time> ");
INFO(LOG_STDOUT, "\tspecify a time where the linearization of the model should be performed");
INFO(LOG_STDOUT, "<-mt> ");
INFO(LOG_STDOUT, "\tthis command line parameter is DEPRECATED!");
INFO(LOG_STDOUT, "<-measureTimePlotFormat svg|jpg|ps|gif|...> ");
INFO(LOG_STDOUT, "\tspecify the output format of the measure time functionality");
INFO(LOG_STDOUT, "<-lv [flag1][,flags2][,...]>");
INFO(LOG_STDOUT, "\tspecify the logging level");
for(i=1; i<LOG_MAX; ++i)
INFO2(LOG_STDOUT, "\t%-18s [%s]", LOG_STREAM_NAME[i], LOG_STREAM_DETAILED_DESC[i]);
RELEASE(LOG_STDOUT);
EXIT(0);
}

Expand Down
Expand Up @@ -868,10 +868,10 @@ int initialization(DATA *data, const char* pInitMethod, const char* pOptiMethod,

if(initMethod == IIM_UNKNOWN)
{
WARNING1(LOG_INIT, "unrecognized option -iim %s", pInitMethod);
WARNING(LOG_INIT, "current options are:");
WARNING1(LOG_STDOUT, "unrecognized option -iim %s", pInitMethod);
WARNING(LOG_STDOUT, "current options are:");
for(i=1; i<IIM_MAX; ++i)
WARNING2(LOG_INIT, "| %-15s [%s]", initMethodStr[i], initMethodDescStr[i]);
WARNING2(LOG_STDOUT, "| %-15s [%s]", initMethodStr[i], initMethodDescStr[i]);
THROW("see last warning");
}
}
Expand All @@ -888,10 +888,10 @@ int initialization(DATA *data, const char* pInitMethod, const char* pOptiMethod,

if(optiMethod == IOM_UNKNOWN)
{
WARNING1(LOG_INIT, "unrecognized option -iom %s", pOptiMethod);
WARNING(LOG_INIT, "current options are:");
WARNING1(LOG_STDOUT, "unrecognized option -iom %s", pOptiMethod);
WARNING(LOG_STDOUT, "current options are:");
for(i=1; i<IOM_MAX; ++i)
WARNING2(LOG_INIT, "| %-15s [%s]", optiMethodStr[i], optiMethodDescStr[i]);
WARNING2(LOG_STDOUT, "| %-15s [%s]", optiMethodStr[i], optiMethodDescStr[i]);
THROW("see last warning");
}
}
Expand Down
38 changes: 37 additions & 1 deletion SimulationRuntime/c/util/omc_error.c
Expand Up @@ -77,7 +77,28 @@ const char *LOG_STREAM_DESC[LOG_MAX] = {
"events",
"zerocrossings",
"debug",
""
"|"
};

const char *LOG_STREAM_DETAILED_DESC[LOG_MAX] = {
"unknown",
"this stream is alway active",
"util",
"simulation",
"stats",
"additional information during initialization",
"final solution of the initialization",
"res_init",
"solver",
"ddasrt",
"jac",
"endjac",
"nonlin_sys",
"nonlin_sys_v",
"additional information during event iteration",
"zerocrossings",
"debug",
"this stream is alway active"
};

static const char *LOG_TYPE_DESC[LOG_TYPE_MAX] = {
Expand All @@ -95,6 +116,21 @@ int lastType[LOG_MAX];
int lastStream = LOG_UNKNOWN;
char logBuffer[2048];

void initDumpSystem()
{
int i;

for(i=0; i<LOG_MAX; ++i)
{
useStream[i] = 0;
level[i] = 0;
lastType[i] = 0;
}

useStream[LOG_STDOUT] = 1;
useStream[LOG_ASSERT] = 1;
}

void printInfo(FILE *stream, FILE_INFO info)
{
fprintf(stream, "[%s:%d:%d-%d:%d:%s]", info.filename, info.lineStart, info.colStart, info.lineEnd, info.colEnd, info.readonly ? "readonly" : "writable");
Expand Down
2 changes: 2 additions & 0 deletions SimulationRuntime/c/util/omc_error.h
Expand Up @@ -55,6 +55,7 @@ extern void (*omc_assert)(const char*, FILE_INFO);
extern void (*omc_assert_warning)(const char*, FILE_INFO);
extern void (*omc_terminate)(const char*, FILE_INFO);
extern void (*omc_throw)();
void initDumpSystem();
void omc_assert_function(const char *msg, FILE_INFO info);
void omc_assert_warning_function(const char *msg, FILE_INFO info);
void omc_terminate_function(const char *msg, FILE_INFO info);
Expand Down Expand Up @@ -90,6 +91,7 @@ enum LOG_STREAM
};
extern const char *LOG_STREAM_NAME[LOG_MAX];
extern const char *LOG_STREAM_DESC[LOG_MAX];
extern const char *LOG_STREAM_DETAILED_DESC[LOG_MAX];

enum LOG_TYPE
{
Expand Down

0 comments on commit 3bd3e72

Please sign in to comment.