Skip to content
This repository has been archived by the owner on May 18, 2019. It is now read-only.

Commit

Permalink
[Cpp] Implement flags for input and output path, ticket:4773
Browse files Browse the repository at this point in the history
This follows up 1be2a07 that implemented
these flags to the C runtime.

Both flags are added to GlobalSettings and default to the path of the
compiled model. The flag inputPath replaces the previously hard coded
path in OMCpp<Model>Initialize.cpp.

The flag outputPath is not yet used (the results file has an own flag).
These flags make sense once more that one input or output file will be used.

Belonging to [master]:
  - #2807
  • Loading branch information
rfranke authored and OpenModelica-Hudson committed Dec 2, 2018
1 parent 9bcafd6 commit 2661fa9
Show file tree
Hide file tree
Showing 10 changed files with 46 additions and 19 deletions.
15 changes: 1 addition & 14 deletions Compiler/Template/CodegenCpp.tpl
Expand Up @@ -5791,20 +5791,7 @@ case SIMCODE(modelInfo = MODELINFO(__),makefileParams = MAKEFILE_PARAMS(__)) th
void <%lastIdentOfPath(modelInfo.name)%>Initialize::initializeFreeVariables()
{
#if !defined(FMU_BUILD)
#if defined(__vxworks)
_reader = shared_ptr<IPropertyReader>(new XmlPropertyReader(_global_settings, "/SYSTEM/bundles/com.boschrexroth.<%modelname%>/<%fileNamePrefix%>_init.xml"));
#else
<%if (Flags.getConfigBool(Flags.LABELED_REDUCTION)) then
<<
_reader = shared_ptr<IPropertyReader>(new XmlPropertyReader(_global_settings, "<%makefileParams.compileDir%>/<%fileNamePrefix%>_init.xml",_dimRHS));
>>
else
<<
_reader = shared_ptr<IPropertyReader>(new XmlPropertyReader(_global_settings, "<%makefileParams.compileDir%>/<%fileNamePrefix%>_init.xml"));
>>
%>

#endif
_reader = shared_ptr<IPropertyReader>(new XmlPropertyReader(_global_settings, "<%fileNamePrefix%>_init.xml"));
_reader->readInitialValues(*this, getSimVars());
#endif

Expand Down
Expand Up @@ -12,7 +12,7 @@
XmlPropertyReader::XmlPropertyReader(IGlobalSettings *globalSettings, std::string propertyFile)
: IPropertyReader()
,_globalSettings(globalSettings)
,_propertyFile(propertyFile)
,_propertyFile(globalSettings->getInputPath() + string("/") + propertyFile)
,_isInitialized(false)
{
}
Expand Down
3 changes: 3 additions & 0 deletions SimulationRuntime/cpp/Core/SimController/SimController.cpp
Expand Up @@ -161,6 +161,9 @@ void SimController::Start(SimSettings simsettings, string modelKey)
global_settings->setEmitResults(simsettings.emitResults);
global_settings->setNonLinearSolverContinueOnError(simsettings.nonLinearSolverContinueOnError);
global_settings->setSolverThreads(simsettings.solverThreads);
global_settings->setInputPath(simsettings.inputPath);
global_settings->setOutputPath(simsettings.outputPath);

/*shared_ptr<SimManager>*/ _simMgr = shared_ptr<SimManager>(new SimManager(mixedsystem, _config.get()));

ISolverSettings* solver_settings = _config->getSolverSettings();
Expand Down
10 changes: 10 additions & 0 deletions SimulationRuntime/cpp/Core/SimulationSettings/GlobalSettings.cpp
Expand Up @@ -135,6 +135,16 @@ void GlobalSettings::setOutputPath(string path)
_output_path = path;
}

string GlobalSettings::getInputPath()
{
return _input_path;
}

void GlobalSettings::setInputPath(string path)
{
_input_path = path;
}

string GlobalSettings::getSelectedSolver()
{
return _selected_solver;
Expand Down
Expand Up @@ -23,6 +23,8 @@ struct SimSettings
int solverThreads;
OutputFormat outputFormat;
EmitResults emitResults;
string inputPath;
string outputPath;
};

/**
Expand Down
Expand Up @@ -29,6 +29,9 @@ class GlobalSettings : public IGlobalSettings
virtual void setInfoOutput(bool);
virtual bool useEndlessSim();
virtual void useEndlessSim(bool);
///path for input files, like init xml
virtual string getInputPath();
virtual void setInputPath(string);
///path for simulation results in textfile
virtual string getOutputPath();
virtual void setOutputPath(string);
Expand Down Expand Up @@ -73,6 +76,7 @@ class GlobalSettings : public IGlobalSettings
_endless_sim,
_nonLinSolverContinueOnError;
string
_input_path,
_output_path,
_selected_solver,
_selected_lin_solver,
Expand Down
Expand Up @@ -72,7 +72,7 @@ class IGlobalSettings
virtual LogSettings getLogSettings() = 0;
virtual void setLogSettings(LogSettings) = 0;
virtual void setAlarmTime(unsigned int) = 0;
virtual unsigned int getAlarmTime() = 0;
virtual unsigned int getAlarmTime() = 0;

virtual OutputFormat getOutputFormat() = 0;
virtual void setOutputFormat(OutputFormat) = 0;
Expand All @@ -94,6 +94,9 @@ class IGlobalSettings
virtual string getResultsFileName() = 0;
virtual void setRuntimeLibrarypath(string) = 0;
virtual string getRuntimeLibrarypath() = 0;
///< Directory for input files, like init.xml
virtual string getInputPath() = 0;
virtual void setInputPath(string) = 0;

virtual void setNonLinearSolverContinueOnError(bool) = 0;
virtual bool getNonLinearSolverContinueOnError() = 0;
Expand Down
4 changes: 3 additions & 1 deletion SimulationRuntime/cpp/Include/FMU/FMUGlobalSettings.h
Expand Up @@ -32,12 +32,14 @@ class FMUGlobalSettings : public IGlobalSettings
///< Write out statistical simulation infos, e.g. number of steps (at the end of simulation); [false,true]; default: true)
virtual bool getInfoOutput() { return false; }
virtual void setInfoOutput(bool) {}
virtual string getOutputPath() { return "./"; }
virtual string getOutputPath() { return "."; }
virtual string getInputPath() { return "."; }
virtual LogSettings getLogSettings() {return LogSettings(LF_FMI);}
virtual void setLogSettings(LogSettings) {}
virtual OutputPointType getOutputPointType() { return OPT_ALL; };
virtual void setOutputPointType(OutputPointType) {};
virtual void setOutputPath(string) {}
virtual void setInputPath(string) {}
virtual string getSelectedSolver() { return "euler"; }
virtual void setSelectedSolver(string) {}
virtual string getSelectedLinSolver() { return "dgesvSolver"; }
Expand Down
4 changes: 3 additions & 1 deletion SimulationRuntime/cpp/Include/FMU2/FMU2GlobalSettings.h
Expand Up @@ -64,12 +64,14 @@ class FMU2GlobalSettings : public IGlobalSettings
///< Write out statistical simulation infos, e.g. number of steps (at the end of simulation); [false,true]; default: true)
virtual bool getInfoOutput() { return false; }
virtual void setInfoOutput(bool) {}
virtual string getOutputPath() { return "./"; }
virtual string getOutputPath() { return "."; }
virtual string getInputPath() { return "."; }
virtual LogSettings getLogSettings() { return LogSettings(LF_FMI2); }
virtual void setLogSettings(LogSettings) {}
virtual OutputPointType getOutputPointType() { return OPT_ALL; };
virtual void setOutputPointType(OutputPointType) {};
virtual void setOutputPath(string) {}
virtual void setInputPath(string) {}
virtual string getSelectedSolver() { return "euler"; }
virtual void setSelectedSolver(string) {}
virtual string getSelectedLinSolver() { return "dgesvSolver"; }
Expand Down
16 changes: 15 additions & 1 deletion SimulationRuntime/cpp/SimCoreFactory/OMCFactory/OMCFactory.cpp
Expand Up @@ -307,6 +307,8 @@ SimSettings OMCFactory::readSimulationParameter(int argc, const char* argv[])
("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")
("input-path", po::value< string >(), "directory with input files, like init xml (defaults to modelica-system-library)")
("output-path", po::value< string >(), "directory for output files, like results (defaults to modelica-system-library)")
("results-file,F", po::value<vector<string> >(),"name of results file")
("start-time,S", po::value< double >()->default_value(0.0), "simulation start time")
("stop-time,E", po::value< double >()->default_value(1.0), "simulation stop time")
Expand Down Expand Up @@ -401,6 +403,16 @@ SimSettings OMCFactory::readSimulationParameter(int argc, const char* argv[])
else
throw ModelicaSimulationError(MODEL_FACTORY,"Modelica library path is not set");

string inputPath, outputPath;
if (vm.count("input-path"))
inputPath = vm["input-path"].as<string>();
else
inputPath = modelica_lib_path;
if (vm.count("output-path"))
outputPath = vm["output-path"].as<string>();
else
outputPath = modelica_lib_path;

string resultsfilename;
if (vm.count("results-file"))
{
Expand Down Expand Up @@ -453,7 +465,7 @@ SimSettings OMCFactory::readSimulationParameter(int argc, const char* argv[])
libraries_path.make_preferred();
modelica_path.make_preferred();

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

_library_path = libraries_path.string();
_modelicasystem_path = modelica_path.string();
Expand Down Expand Up @@ -592,6 +604,8 @@ void OMCFactory::fillArgumentsToReplace()
_argumentsToReplace.insert(pair<string,string>("-port", "--log-port"));
_argumentsToReplace.insert(pair<string,string>("-alarm", "--alarm"));
_argumentsToReplace.insert(pair<string,string>("-emit_protected", "--emit-results all"));
_argumentsToReplace.insert(pair<string,string>("-inputPath", "--input-path"));
_argumentsToReplace.insert(pair<string,string>("-outputPath", "--output-path"));
}

pair<shared_ptr<ISimController>,SimSettings>
Expand Down

0 comments on commit 2661fa9

Please sign in to comment.