Skip to content

Commit

Permalink
Filter protected and hidden in Cpp runtime, ticket:4089
Browse files Browse the repository at this point in the history
The former global setting ResultsOutput {true, false} is replaced
with enum EmitResults {EMIT_ALL, EMIT_PUBLIC, EMIT_NONE}.
The default value is EMIT_ALL (cf. former true).

OMCFactory uses the default value EMIT_PUBLIC and introduces the
new option --emit-results with the values all, public or none.
The OMEdit option `-emit-protected` is tranlated to `--emit-results all`.

The actual filtering simply skips values in XmlPropertyReader. This works
out as protected values are not needed from init.xml because they are
calculated in the generated code.
  • Loading branch information
rfranke authored and OpenModelica-Hudson committed Oct 24, 2016
1 parent 32dfa07 commit 599e0f6
Show file tree
Hide file tree
Showing 11 changed files with 105 additions and 56 deletions.
4 changes: 2 additions & 2 deletions Compiler/Template/CodegenCpp.tpl
Expand Up @@ -5876,9 +5876,9 @@ case SIMCODE(modelInfo = MODELINFO(__),makefileParams = MAKEFILE_PARAMS(__)) th
{
#if !defined(FMU_BUILD)
#if defined(__vxworks)
_reader = shared_ptr<IPropertyReader>(new XmlPropertyReader("/SYSTEM/bundles/com.boschrexroth.<%modelname%>/<%fileNamePrefix%>_init.xml"));
_reader = shared_ptr<IPropertyReader>(new XmlPropertyReader(_global_settings, "/SYSTEM/bundles/com.boschrexroth.<%modelname%>/<%fileNamePrefix%>_init.xml"));
#else
_reader = shared_ptr<IPropertyReader>(new XmlPropertyReader("<%makefileParams.compileDir%>/<%fileNamePrefix%>_init.xml"));
_reader = shared_ptr<IPropertyReader>(new XmlPropertyReader(_global_settings, "<%makefileParams.compileDir%>/<%fileNamePrefix%>_init.xml"));
#endif
_reader->readInitialValues(*this, getSimVars());
#endif
Expand Down
53 changes: 41 additions & 12 deletions SimulationRuntime/cpp/Core/DataExchange/XmlPropertyReader.cpp
Expand Up @@ -9,9 +9,10 @@
#include <fstream>
#include <iostream>

XmlPropertyReader::XmlPropertyReader(std::string propertyFile)
XmlPropertyReader::XmlPropertyReader(IGlobalSettings *globalSettings, std::string propertyFile)
: IPropertyReader()
,propertyFile(propertyFile)
,_globalSettings(globalSettings)
,_propertyFile(propertyFile)
,_isInitialized(false)
{
}
Expand All @@ -24,7 +25,7 @@ void XmlPropertyReader::readInitialValues(IContinuous& system, shared_ptr<ISimVa
{
using boost::property_tree::ptree;
std::ifstream file;
file.open(propertyFile.c_str(), std::ifstream::in);
file.open (_propertyFile.c_str(), std::ifstream::in);
if (file.good())
{
double *realVars = sim_vars->getRealVarsVector();
Expand All @@ -51,12 +52,23 @@ void XmlPropertyReader::readInitialValues(IContinuous& system, shared_ptr<ISimVa
//boost::property_tree::xml_parser::write_xml(std::cout, vars.second);
continue;
}

string name = vars.second.get<string>("<xmlattr>.name");
boost::optional<string> descriptonOpt = vars.second.get_optional<string>("<xmlattr>.description");
string descripton;
if (descriptonOpt)
descripton = *descriptonOpt;

if (_globalSettings->getEmitResults() != EMIT_ALL)
{
if (name.substr(0, 3) == "_D_")
continue;
std::string hideResultInfo = vars.second.get<std::string>("<xmlattr>.hideResult");
if (hideResultInfo.compare("true") == 0)
// Note: we don't need values of hidden variables because the code calculates them
continue;
}

refIdx = *refIdxOpt;
std::string aliasInfo = vars.second.get<std::string>("<xmlattr>.alias");
std::string variabilityInfo = vars.second.get<std::string>("<xmlattr>.variability");
Expand All @@ -67,7 +79,6 @@ void XmlPropertyReader::readInitialValues(IContinuous& system, shared_ptr<ISimVa

FOREACH(ptree::value_type const& var, vars.second.get_child(""))
{

if (var.first == "Real")
{
//If a start value is given for the alias and the referred variable, skip the alias declaration
Expand Down Expand Up @@ -148,34 +159,52 @@ void XmlPropertyReader::readInitialValues(IContinuous& system, shared_ptr<ISimVa

const output_int_vars_t& XmlPropertyReader::getIntOutVars()
{
static output_int_vars_t int_none;
if (_isInitialized)
return _intVars;
{
if (_globalSettings->getEmitResults() == EMIT_NONE)
return int_none;
else
return _intVars;
}
else
throw ModelicaSimulationError(UTILITY,"init xml file has not been read");
throw ModelicaSimulationError(UTILITY, "init xml file has not been read");
}

const output_real_vars_t& XmlPropertyReader::getRealOutVars()
{
static output_real_vars_t real_none;
if (_isInitialized)
return _realVars;
{
if (_globalSettings->getEmitResults() == EMIT_NONE)
return real_none;
else
return _realVars;
}
else
throw ModelicaSimulationError(UTILITY,"init xml file has not been read");
throw ModelicaSimulationError(UTILITY, "init xml file has not been read");
}

const output_bool_vars_t& XmlPropertyReader::getBoolOutVars()
{
static output_bool_vars_t bool_none;
if (_isInitialized)
return _boolVars;
{
if (_globalSettings->getEmitResults() == EMIT_NONE)
return bool_none;
else
return _boolVars;
}
else
throw ModelicaSimulationError(UTILITY,"init xml file has not been read");
throw ModelicaSimulationError(UTILITY, "init xml file has not been read");
}

std::string XmlPropertyReader::getPropertyFile()
{
return propertyFile;
return _propertyFile;
}

void XmlPropertyReader::setPropertyFile(std::string file)
{
propertyFile = file;
_propertyFile = file;
}
6 changes: 4 additions & 2 deletions SimulationRuntime/cpp/Core/SimController/SimController.cpp
Expand Up @@ -133,7 +133,8 @@ void SimController::StartVxWorks(SimSettings simsettings,string modelKey)
global_settings->setAlarmTime(simsettings.timeOut);
global_settings->setLogSettings(simsettings.logSettings);
global_settings->setOutputPointType(simsettings.outputPointType);
global_settings->setOutputFormat(simsettings.outputFomrat);
global_settings->setOutputFormat(simsettings.outputFormat);
global_settings->setEmitResults(simsettings.emitResults);
/*shared_ptr<SimManager>*/ _simMgr = shared_ptr<SimManager>(new SimManager(mixedsystem, _config.get()));

ISolverSettings* solver_settings = _config->getSolverSettings();
Expand Down Expand Up @@ -185,7 +186,8 @@ void SimController::Start(SimSettings simsettings, string modelKey)
global_settings->setLogSettings(simsettings.logSettings);
global_settings->setAlarmTime(simsettings.timeOut);
global_settings->setOutputPointType(simsettings.outputPointType);
global_settings->setOutputFormat(simsettings.outputFomrat);
global_settings->setOutputFormat(simsettings.outputFormat);
global_settings->setEmitResults(simsettings.emitResults);
global_settings->setNonLinearSolverContinueOnError(simsettings.nonLinearSolverContinueOnError);
global_settings->setSolverThreads(simsettings.solverThreads);
/*shared_ptr<SimManager>*/ _simMgr = shared_ptr<SimManager>(new SimManager(mixedsystem, _config.get()));
Expand Down
14 changes: 7 additions & 7 deletions SimulationRuntime/cpp/Core/SimulationSettings/GlobalSettings.cpp
Expand Up @@ -12,7 +12,7 @@ GlobalSettings::GlobalSettings()
: _startTime(0.0)
, _endTime(5.0)
, _hOutput(0.001)
, _resultsOutput(true)
, _emitResults(EMIT_ALL)
, _infoOutput(true)
, _selected_solver("Euler")
, _selected_lin_solver("Newton")
Expand All @@ -22,7 +22,7 @@ GlobalSettings::GlobalSettings()
, _nonLinSolverContinueOnError(false)
, _outputPointType(OPT_ALL)
, _alarm_time(0)
,_outputFormat(MAT)
, _outputFormat(MAT)
{
}

Expand Down Expand Up @@ -93,15 +93,15 @@ void GlobalSettings::setLogSettings(LogSettings set)
_log_settings = set;
}

///< Write out results ([false,true]; default: true)
bool GlobalSettings::getResultsOutput()
///< Write out results (default: EMIT_ALL)
EmitResults GlobalSettings::getEmitResults()
{
return _resultsOutput;
return _emitResults;
}

void GlobalSettings::setResultsOutput(bool output)
void GlobalSettings::setEmitResults(EmitResults emitResults)
{
_resultsOutput = output;
_emitResults = emitResults;
}

void GlobalSettings::setResultsFileName(string name)
Expand Down
@@ -1,11 +1,12 @@
#pragma once

class IContinuous;
class IGlobalSettings;

class BOOST_EXTENSION_XML_READER_DECL XmlPropertyReader : public IPropertyReader
{
public:
XmlPropertyReader(std::string propertyFile);
XmlPropertyReader(IGlobalSettings *globalSettings, std::string propertyFile);
~XmlPropertyReader();

void readInitialValues(IContinuous& system, shared_ptr<ISimVars> sim_vars);
Expand All @@ -15,9 +16,10 @@ class BOOST_EXTENSION_XML_READER_DECL XmlPropertyReader : public IPropertyReader
const output_int_vars_t& getIntOutVars();
const output_real_vars_t& getRealOutVars();
const output_bool_vars_t& getBoolOutVars();
private:

string propertyFile;
private:
IGlobalSettings *_globalSettings;
string _propertyFile;

output_int_vars_t _intVars;
output_bool_vars_t _boolVars;
Expand Down
Expand Up @@ -21,7 +21,8 @@ struct SimSettings
LogSettings logSettings;
bool nonLinearSolverContinueOnError;
int solverThreads;
OutputFormat outputFomrat;
OutputFormat outputFormat;
EmitResults emitResults;
};

/**
Expand Down
Expand Up @@ -21,9 +21,9 @@ class GlobalSettings : public IGlobalSettings
///< Output step size (default: 20 ms)
virtual double gethOutput();
virtual void sethOutput(double);
///< Write out results ([false,true]; default: true)
virtual bool getResultsOutput();
virtual void setResultsOutput(bool);
///< Write out results (default: EMIT_ALL)
virtual EmitResults getEmitResults();
virtual void setEmitResults(EmitResults);
///< Write out statistical simulation infos, e.g. number of steps (at the end of simulation); [false, true]; default: true)
virtual bool getInfoOutput();
virtual void setInfoOutput(bool);
Expand Down Expand Up @@ -62,12 +62,13 @@ class GlobalSettings : public IGlobalSettings

private:
double
_startTime, ///< Start time of integration (default: 0.0)
_endTime, ///< End time of integraiton (default: 1.0)
_hOutput; //< Output step size (default: 20 ms)
_startTime, ///< Start time of integration (default: 0.0)
_endTime, ///< End time of integraiton (default: 1.0)
_hOutput; ///< Output step size (default: 20 ms)
EmitResults
_emitResults; ///< Write out results (default: EMIT_ALL)
bool
_resultsOutput, ///< Write out results ([false,true]; default: true)
_infoOutput, ///< Write out statistical simulation infos, e.g. number of steps (at the end of simulation); [false,true]; default: true)
_infoOutput, ///< Write out statistical simulation infos, e.g. number of steps (at the end of simulation); [false,true]; default: true)
_endless_sim,
_nonLinSolverContinueOnError;
string
Expand Down
Expand Up @@ -28,7 +28,8 @@ using std::string;
enum LogCategory {LC_INIT = 0, LC_NLS = 1, LC_LS = 2, LC_SOLV = 3, LC_OUT = 4, LC_EVT = 5, LC_OTHER = 6, LC_MOD = 7};
enum LogLevel {LL_ERROR = 0, LL_WARNING = 1, LL_INFO = 2, LL_DEBUG = 3};
enum OutputPointType {OPT_ALL, OPT_STEP, OPT_NONE};
enum OutputFormat{CSV, MAT,BUFFER,EMPTY};
enum OutputFormat {CSV, MAT, BUFFER, EMPTY};
enum EmitResults {EMIT_ALL, EMIT_PUBLIC, EMIT_NONE};
struct LogSettings
{
std::vector<LogLevel> modes;
Expand Down Expand Up @@ -58,9 +59,9 @@ class IGlobalSettings
///< Output step size (default: 20 ms)
virtual double gethOutput() = 0;
virtual void sethOutput(double) = 0;
///< Write out results ([false,true]; default: true)
virtual bool getResultsOutput() = 0;
virtual void setResultsOutput(bool) = 0;
///< Write out results (default: EMIT_ALL)
virtual EmitResults getEmitResults() = 0;
virtual void setEmitResults(EmitResults) = 0;
virtual OutputPointType getOutputPointType() = 0;
virtual void setOutputPointType(OutputPointType) = 0;
virtual LogSettings getLogSettings() = 0;
Expand Down
6 changes: 3 additions & 3 deletions SimulationRuntime/cpp/Include/FMU/FMUGlobalSettings.h
Expand Up @@ -24,9 +24,9 @@ class FMUGlobalSettings : public IGlobalSettings
///< Output step size (default: 20 ms)
virtual double gethOutput() { return 20; }
virtual void sethOutput(double) {}
///< Write out results ([false,true]; default: true)
virtual bool getResultsOutput() { return false; }
virtual void setResultsOutput(bool) {}
///< Write out results (EMIT_NONE)
virtual EmitResults getEmitResults() { return EMIT_NONE; }
virtual void setEmitResults(EmitResults) {}
virtual bool useEndlessSim() {return true; }
virtual void useEndlessSim(bool) {}
///< Write out statistical simulation infos, e.g. number of steps (at the end of simulation); [false,true]; default: true)
Expand Down
6 changes: 3 additions & 3 deletions SimulationRuntime/cpp/Include/FMU2/FMU2GlobalSettings.h
Expand Up @@ -56,9 +56,9 @@ class FMU2GlobalSettings : public IGlobalSettings
///< Output step size (default: 20 ms)
virtual double gethOutput() { return 20; }
virtual void sethOutput(double) {}
///< Write out results ([false,true]; default: true)
virtual bool getResultsOutput() { return false; }
virtual void setResultsOutput(bool) {}
///< Write out results (EMIT_NONE)
virtual EmitResults getEmitResults() { return EMIT_NONE; }
virtual void setEmitResults(EmitResults) {}
virtual bool useEndlessSim() {return true; }
virtual void useEndlessSim(bool) {}
///< Write out statistical simulation infos, e.g. number of steps (at the end of simulation); [false,true]; default: true)
Expand Down
35 changes: 24 additions & 11 deletions SimulationRuntime/cpp/SimCoreFactory/OMCFactory/OMCFactory.cpp
Expand Up @@ -83,10 +83,12 @@ SimSettings OMCFactory::readSimulationParameter(int argc, const char* argv[])
map<string, OutputPointType> outputPointTypeMap = MAP_LIST_OF
"all", OPT_ALL MAP_LIST_SEP "step", OPT_STEP MAP_LIST_SEP
"none", OPT_NONE MAP_LIST_END;

map<string, OutputFormat> outputFormatTypeMap = MAP_LIST_OF
map<string, OutputFormat> outputFormatMap = MAP_LIST_OF
"csv", CSV MAP_LIST_SEP "mat", MAT MAP_LIST_SEP
"buffer", BUFFER MAP_LIST_SEP "empty", EMPTY MAP_LIST_END;
map<string, EmitResults> emitResultsMap = MAP_LIST_OF
"all", EMIT_ALL MAP_LIST_SEP "public", EMIT_PUBLIC MAP_LIST_SEP
"none", EMIT_NONE MAP_LIST_END;
po::options_description desc("Allowed options");

//program options that can be overwritten by OMEdit must be declared as vector
Expand All @@ -111,6 +113,7 @@ SimSettings OMCFactory::readSimulationParameter(int argc, const char* argv[])
("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")
("output-format,P", po::value< string >()->default_value("mat"), "The simulation results output format")
("emit-results,U", po::value< string >()->default_value("public"), "emit results: all, public, none")
;

// a group for all options that should not be visible if '--help' is set
Expand Down Expand Up @@ -232,22 +235,26 @@ SimSettings OMCFactory::readSimulationParameter(int argc, const char* argv[])
OutputFormat outputFormat;
if (vm.count("output-format"))
{

string outputFormatType_str = vm["output-format"].as<string>();
outputFormat = outputFormatTypeMap[outputFormatType_str];
string outputFormat_str = vm["output-format"].as<string>();
outputFormat = outputFormatMap[outputFormat_str];
}
else
throw ModelicaSimulationError(MODEL_FACTORY, "output-format is not set");

EmitResults emitResults = EMIT_PUBLIC; // emit public per default for OMC use
if (vm.count("emit-results"))
{
string emitResults_str = vm["emit-results"].as<string>();
emitResults = emitResultsMap[emitResults_str];
}


fs::path libraries_path = fs::path( runtime_lib_path) ;
fs::path libraries_path = fs::path( runtime_lib_path) ;
fs::path modelica_path = fs::path( modelica_lib_path) ;

libraries_path.make_preferred();
modelica_path.make_preferred();

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

_library_path = libraries_path.string();
_modelicasystem_path = modelica_path.string();
Expand Down Expand Up @@ -340,6 +347,12 @@ vector<const char *> OMCFactory::handleComplexCRuntimeArguments(int argc, const
opts[oit->second] = strs[++j];
}
else {
// ignore filter for all variables
if (strs[j] == "variableFilter"
&& j < strs.size() - 1 && strs[j+1] == ".*") {
++j;
continue;
}
// leave unrecognized overrides
if (_overrideOMEdit.size() > 10)
_overrideOMEdit += ",";
Expand All @@ -365,14 +378,14 @@ vector<const char *> OMCFactory::handleComplexCRuntimeArguments(int argc, const
void OMCFactory::fillArgumentsToIgnore()
{
_argumentsToIgnore = unordered_set<string>();
_argumentsToIgnore.insert("-emit_protected");
}

void OMCFactory::fillArgumentsToReplace()
{
_argumentsToReplace = map<string, string>();
_argumentsToReplace.insert(pair<string,string>("-r","-F"));
_argumentsToReplace.insert(pair<string,string>("-w","-V all=warning"));
_argumentsToReplace.insert(pair<string,string>("-r", "-F"));
_argumentsToReplace.insert(pair<string,string>("-w", "-V all=warning"));
_argumentsToReplace.insert(pair<string,string>("-emit_protected", "--emit-results all"));
}

pair<shared_ptr<ISimController>,SimSettings>
Expand Down

0 comments on commit 599e0f6

Please sign in to comment.