Skip to content

Commit

Permalink
- added a set of arguments that should be ignored by OMCFactory
Browse files Browse the repository at this point in the history
- disabled the unrecognized option warning of OMCFactory, if C-Runtime flags are used
  • Loading branch information
Marcus Walther authored and OpenModelica-Hudson committed Aug 28, 2015
1 parent e8a3994 commit e9cd523
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 11 deletions.
1 change: 1 addition & 0 deletions SimulationRuntime/cpp/Include/Core/Modelica.h
Expand Up @@ -15,6 +15,7 @@
#include <boost/assign/std/vector.hpp> // for 'operator+=()'
#include <boost/assign/list_of.hpp> // for 'list_of()'
#include <boost/unordered_map.hpp>
#include <boost/unordered_set.hpp>
#include <boost/ref.hpp>
#include <boost/bind.hpp>
#include <boost/function.hpp>
Expand Down
Expand Up @@ -35,13 +35,16 @@ class OMCFactory
/** merge command line args with built-in args and adapt OMEdit args to Cpp */
std::vector<const char *> preprocessArguments(int argc, const char* argv[], std::map<std::string, std::string> &opts);
SimSettings readSimulationParameter(int argc, const char* argv[]);
pair<string, string> parseIngoredAndWrongFormatOption(const string &s);
void fillArgumentsToIgnore();

//boost::shared_ptr<ISimController> _simController;
std::map<string,shared_library> _modules;
std::string _defaultLinSolver;
std::string _defaultNonLinSolver;
PATH _library_path;
PATH _modelicasystem_path;
boost::unordered_set<string> _argumentsToIgnore; //a set of arguments that should be ignored,
std::string _overrideOMEdit; // unrecognized options if called from OMEdit
};
/** @} */ // end of simcorefactoryOMCFactory
35 changes: 24 additions & 11 deletions SimulationRuntime/cpp/SimCoreFactory/OMCFactory/OMCFactory.cpp
Expand Up @@ -18,6 +18,7 @@ OMCFactory::OMCFactory(PATH library_path, PATH modelicasystem_path)
, _defaultLinSolver("kinsol")
, _defaultNonLinSolver("kinsol")
{
fillArgumentsToIgnore();
}

OMCFactory::OMCFactory()
Expand All @@ -26,6 +27,7 @@ OMCFactory::OMCFactory()
, _defaultLinSolver("kinsol")
, _defaultNonLinSolver("kinsol")
{
fillArgumentsToIgnore();
}

OMCFactory::~OMCFactory()
Expand All @@ -42,11 +44,15 @@ void OMCFactory::UnloadAllLibs(void)
}

// parse a long option that starts with one dash, like -port=12345
static pair<string, string> checkOMEditOption(const string &s)
// remove all options that are part of the ignore-set
pair<string, string> OMCFactory::parseIngoredAndWrongFormatOption(const string &s)
{
int sep = s.find("=");
if (sep > 2 && s[0] == '-' && s[1] != '-')
return make_pair(string("OMEdit"), s);
string key = s;
if(sep > 0)
s.substr(0, sep);
if (_argumentsToIgnore.find(key) != _argumentsToIgnore.end() || (sep > 2 && s[0] == '-' && s[1] != '-'))
return make_pair(string("Ignored"), s);
else
return make_pair(string(), string());
}
Expand All @@ -61,7 +67,6 @@ SimSettings OMCFactory::readSimulationParameter(int argc, const char* argv[])
po::options_description desc("Allowed options");
desc.add_options()
("help", "produce help message")
("emit_protected", "emits protected variables to the result file")
("nls_continue", po::bool_switch()->default_value(false),"non linear solver will continue if it can not reach the given precision")
("runtime-library,R", po::value<string>(),"path to cpp runtime libraries")
("Modelica-system-library,M", po::value<string>(), "path to Modelica library")
Expand All @@ -78,23 +83,24 @@ SimSettings OMCFactory::readSimulationParameter(int argc, const char* argv[])
("log-settings,V", po::value< std::vector<std::string> >(), "log information: init, nls, ls, solv, output, event, model, other")
("alarm,A", po::value<unsigned int >()->default_value(360), "sets timeout in seconds for simulation")
("output-type,O", po::value< string >()->default_value("all"), "the points in time written to result file: all (output steps + events), step (just output points), none")
("OMEdit", po::value<vector<string> >(), "OMEdit options")
("Ignored", po::value<vector<string> >(), "Ignored options")
;
po::variables_map vm;
boost::function<pair<string, string> (const string&)> parserFunction(boost::bind(&OMCFactory::parseIngoredAndWrongFormatOption, this, _1));
po::parsed_options parsed = po::command_line_parser(argc, argv)
.options(desc)
.style((po::command_line_style::default_style | po::command_line_style::allow_long_disguise) & ~po::command_line_style::allow_guessing)
.extra_parser(checkOMEditOption)
.extra_parser(parserFunction)
.allow_unregistered()
.run();
po::store(parsed, vm);
po::notify(vm);

// warn about unrecognized command line options, including OMEdit for now
vector<string> unrecognized = po::collect_unrecognized(parsed.options, po::include_positional);
if (vm.count("OMEdit")) {
vector<string> opts = vm["OMEdit"].as<vector<string> >();
unrecognized.insert(unrecognized.begin(), opts.begin(), opts.end());
if (vm.count("Ignored")) {
//vector<string> opts = vm["Ignored"].as<vector<string> >();
//unrecognized.insert(unrecognized.begin(), opts.begin(), opts.end());
}
if (unrecognized.size() > 0) {
std::cerr << "Warning: unrecognized command line options ";
Expand All @@ -116,7 +122,7 @@ SimSettings OMCFactory::readSimulationParameter(int argc, const char* argv[])
string solver = vm["solver"].as<string>();
string nonLinSolver = vm["non-lin-solver"].as<string>();
string linSolver = vm["lin-solver"].as<string>();
unsigned int time_out = vm["alarm"].as<unsigned int>();;
unsigned int timeOut = vm["alarm"].as<unsigned int>();
if (vm.count("runtime-library"))
{
//cout << "runtime library path set to " << vm["runtime-library"].as<string>() << std::endl;
Expand Down Expand Up @@ -201,7 +207,7 @@ SimSettings OMCFactory::readSimulationParameter(int argc, const char* argv[])



SimSettings settings = {solver,linSolver,nonLinSolver,starttime,stoptime,stepsize,1e-24,0.01,tolerance,resultsfilename,time_out,outputPointType,logSet,nlsContinueOnError};
SimSettings settings = {solver,linSolver,nonLinSolver,starttime,stoptime,stepsize,1e-24,0.01,tolerance,resultsfilename,timeOut,outputPointType,logSet,nlsContinueOnError};


_library_path = libraries_path;
Expand Down Expand Up @@ -262,6 +268,13 @@ std::vector<const char *> OMCFactory::preprocessArguments(int argc, const char*
return optv;
}

void OMCFactory::fillArgumentsToIgnore()
{
_argumentsToIgnore = boost::unordered_set<string>();
_argumentsToIgnore.insert("-w");
_argumentsToIgnore.insert("-emit_protected");
}

std::pair<boost::shared_ptr<ISimController>,SimSettings>
OMCFactory::createSimulation(int argc, const char* argv[],
std::map<std::string, std::string> &opts)
Expand Down

0 comments on commit e9cd523

Please sign in to comment.