Skip to content

Commit

Permalink
- fix Windows build by prefixing the enumerations in the CPP runtime …
Browse files Browse the repository at this point in the history
…settings with OM_ as otherwise the MSVC compiler complains madly
  • Loading branch information
adrpo committed Jul 2, 2015
1 parent 69e41fc commit c99eeed
Show file tree
Hide file tree
Showing 11 changed files with 109 additions and 79 deletions.
2 changes: 1 addition & 1 deletion SimulationRuntime/cpp/Core/SimController/SimController.cpp
Expand Up @@ -277,7 +277,7 @@ void SimController::Start(SimSettings simsettings, string modelKey)

boost::shared_ptr<IWriteOutput> writeoutput_system = boost::dynamic_pointer_cast<IWriteOutput>(mixedsystem);

if((global_settings->getOutputFormat()==BUFFER) && writeoutput_system)
if((global_settings->getOutputFormat()==OM_BUFFER) && writeoutput_system)
{
boost::shared_ptr<ISimData> simData = getSimData(modelKey).lock();
//get history object to query simulation results
Expand Down
24 changes: 14 additions & 10 deletions SimulationRuntime/cpp/Core/SimController/SimManager.cpp
Expand Up @@ -8,6 +8,10 @@

#include <sstream>

#if defined(_MSC_VER) && !defined(RUNTIME_STATIC_LINKING)
Logger* Logger::instance = NULL;
#endif

SimManager::SimManager(boost::shared_ptr<IMixedSystem> system, Configuration* config)
: _mixed_system (system)
, _config (config)
Expand Down Expand Up @@ -104,7 +108,7 @@ void SimManager::initialize()
return;
}

Logger::write("SimManager start init",INIT,DEBUG);
Logger::write("SimManager start init",OM_INIT,OM_DEBUG);
// Flag für Endlossimulaton (wird gesetzt wenn Solver zurückkommt)
_continueSimulation = true;

Expand Down Expand Up @@ -157,7 +161,7 @@ void SimManager::initialize()
memset(_events, false, _dimZeroFunc * sizeof(bool));
}

Logger::write("SimManager assemble completed",INIT,DEBUG);
Logger::write("SimManager assemble completed",OM_INIT,OM_DEBUG);
//#if defined(__TRICORE__) || defined(__vxworks)
// Initialization for RT simulation
if (_config->getGlobalSettings()->useEndlessSim())
Expand Down Expand Up @@ -259,24 +263,24 @@ void SimManager::runSimulation()
#endif
try
{
Logger::write("SimManager: start simulation at t = " + boost::lexical_cast<std::string>(_tStart),SOLV,INFO);
Logger::write("SimManager: start simulation at t = " + boost::lexical_cast<std::string>(_tStart),OM_SOLV,OM_INFO);
runSingleProcess();
// Zeit messen, Ausgabe der SimInfos
ISolver::SOLVERSTATUS status = _solver->getSolverStatus();
if ((status & ISolver::DONE) || (status & ISolver::USER_STOP))
{
Logger::write("SimManager: simulation done at t = " + boost::lexical_cast<std::string>(_tEnd),SOLV,INFO);
Logger::write("SimManager: number of steps = " + boost::lexical_cast<std::string>(_totStps),SOLV,INFO);
Logger::write("SimManager: simulation done at t = " + boost::lexical_cast<std::string>(_tEnd),OM_SOLV,OM_INFO);
Logger::write("SimManager: number of steps = " + boost::lexical_cast<std::string>(_totStps),OM_SOLV,OM_INFO);
writeProperties();
}
}
catch (std::exception & ex)
{
Logger::write("SimManager: simulation finish with errors at t = " + boost::lexical_cast<std::string>(_tEnd),SOLV,ERROR);
Logger::write("SimManager: number of steps = " + boost::lexical_cast<std::string>(_totStps),SOLV,INFO);
Logger::write("SimManager: simulation finish with errors at t = " + boost::lexical_cast<std::string>(_tEnd),OM_SOLV,OM_ERROR);
Logger::write("SimManager: number of steps = " + boost::lexical_cast<std::string>(_totStps),OM_SOLV,OM_INFO);
writeProperties();

Logger::write("SimManager: error = " + boost::lexical_cast<std::string>(ex.what()),SOLV,ERROR);
Logger::write("SimManager: error = " + boost::lexical_cast<std::string>(ex.what()),OM_SOLV,OM_ERROR);
//ex << error_id(SIMMANAGER);
throw;
}
Expand All @@ -296,7 +300,7 @@ void SimManager::stopSimulation()
void SimManager::writeProperties()
{
// decl for Logging
std::pair<LogCategory, LogLevel> logM = Logger::getLogMode(SOLV, INFO);
std::pair<LogCategory, LogLevel> logM = Logger::getLogMode(OM_SOLV, OM_INFO);

Logger::write(boost::lexical_cast<std::string>("computationTime"),logM);
Logger::write(boost::lexical_cast<std::string>("Geforderte Simulationszeit: ") + boost::lexical_cast<std::string>(_tEnd),logM);
Expand Down Expand Up @@ -548,7 +552,7 @@ void SimManager::runSingleProcess()
_solverTask = ISolver::SOLVERCALL(_solverTask ^ ISolver::RECORDCALL);
/* Logs temporarily disabled
BOOST_LOG_SEV(simmgr_lg::get(), simmgr_normal) <<"Run single process." ; */
Logger::write("SimManager: run single process",SOLV,DEBUG);
Logger::write("SimManager: run single process",OM_SOLV,OM_DEBUG);

// Zeitinvervall speichern
//_H =_tEnd - _tStart;
Expand Down
Expand Up @@ -19,8 +19,8 @@ GlobalSettings::GlobalSettings()
, _selected_nonlin_solver("Newton")
, _resultsfile_name("results.csv")
, _endless_sim(false)
, _outputFormat(EMPTY)
, _outputPointType(ALL)
, _outputFormat(OM_EMPTY)
, _outputPointType(OM_ALL)
, _alarm_time(0)
{
}
Expand Down
Expand Up @@ -111,7 +111,7 @@ void SolverDefaultImplementation::initialize()
timeevent_system->setTime(_tCurrent);


if(_settings->getGlobalSettings()->getOutputPointType() != EMPTY2 && _settings->getGlobalSettings()->getOutputFormat() != EMPTY)
if(_settings->getGlobalSettings()->getOutputPointType() != OM_EMPTY2 && _settings->getGlobalSettings()->getOutputFormat() != OM_EMPTY)
writeoutput_system->writeOutput(IWriteOutput::HEAD_LINE);

// Allocate array with values of zero functions
Expand Down Expand Up @@ -192,7 +192,7 @@ void SolverDefaultImplementation::writeToFile(const int& stp, const double& t, c
}
#endif

if(_settings->getGlobalSettings()->getOutputFormat()!= EMPTY)
if(_settings->getGlobalSettings()->getOutputFormat()!= OM_EMPTY)
{
IWriteOutput* writeoutput_system = dynamic_cast<IWriteOutput*>(_system);

Expand Down
11 changes: 5 additions & 6 deletions SimulationRuntime/cpp/Core/Utils/extension/logger.cpp
Expand Up @@ -8,7 +8,7 @@
#include <Core/Modelica.h>
#include <Core/Utils/extension/logger.hpp>

Logger* Logger::instance = 0;
Logger* Logger::instance = NULL;

Logger::Logger(LogSettings settings, bool enabled) : _settings(settings), _isEnabled(enabled)
{
Expand Down Expand Up @@ -50,18 +50,17 @@ bool Logger::isOutput(std::pair<LogCategory,LogLevel> mode) const
return isOutput(mode.first, mode.second);
}


std::string Logger::getPrefix(LogCategory cat, LogLevel lvl) const
{
switch(lvl)
{
case(DEBUG):
case(OM_DEBUG):
return "DEBUG: ";
case(ERROR):
case(OM_ERROR):
return "ERROR: ";
case(INFO):
case(OM_INFO):
return "INFO: ";
case(WARNING):
case(OM_WARNING):
return "WARNING: ";
default:
return "";
Expand Down
8 changes: 4 additions & 4 deletions SimulationRuntime/cpp/FMU/FMULogger.cpp
Expand Up @@ -9,7 +9,7 @@
#include <FMU/FMULogger.h>

#if defined(_MSC_VER) && !defined(RUNTIME_STATIC_LINKING)
Logger* Logger::instance = 0;
Logger* Logger::instance = NULL;
#endif

FMULogger::FMULogger(fmiCallbackLogger callbackLogger, fmiComponent component, fmiString instanceName) : Logger(false),
Expand All @@ -28,11 +28,11 @@ void FMULogger::writeInternal(std::string errorMsg, LogCategory cat, LogLevel lv
case(ERROR):
callbackLogger(component, instanceName, fmiError, "?", errorMsg.c_str());
break;
case(WARNING):
case(OM_WARNING):
callbackLogger(component, instanceName, fmiWarning, "?", errorMsg.c_str());
break;
case(INFO):
case(DEBUG):
case(OM_INFO):
case(OM_DEBUG):
callbackLogger(component, instanceName, fmiOK, "?", errorMsg.c_str());
break;
default:
Expand Down
Expand Up @@ -25,18 +25,21 @@ using std::string;

#include <vector>

enum OutputFormat {CSV, MAT, BUFFER, EMPTY};
// adrpo: the MSVC compiler has issues with some of the enumerations (OUT, DEBUG, ERROR)
enum OutputFormat {OM_CSV, OM_MAT, OM_BUFFER, OM_EMPTY};

enum LogCategory {OM_INIT = 0, OM_NLS = 1, OM_LS = 2, OM_SOLV = 3, OM_OUT = 4, OM_EVT = 5, OM_OTHER = 6, OM_MOD = 7};
enum LogLevel {OM_ERROR = 0, OM_WARNING = 1, OM_INFO = 2, OM_DEBUG = 3};

enum OutputPointType {OM_ALL, OM_STEP, OM_EMPTY2};

enum LogCategory {INIT = 0, NLS = 1, LS = 2, SOLV = 3, OUT = 4, EVT = 5, OTHER = 6, MOD = 7};
enum LogLevel {ERROR = 0, WARNING = 1, INFO = 2, DEBUG = 3};
struct LogSettings
{
std::vector<LogLevel> modes;

LogSettings()
{
modes = std::vector<LogLevel>(8,ERROR);
modes = std::vector<LogLevel>(8,OM_ERROR);
}

void setAll(LogLevel l)
Expand All @@ -46,7 +49,6 @@ struct LogSettings
}
};

enum OutputPointType {ALL, STEP, EMPTY2};
class IGlobalSettings
{
public:
Expand Down
2 changes: 0 additions & 2 deletions SimulationRuntime/cpp/Include/Core/Utils/extension/logger.hpp
Expand Up @@ -79,6 +79,4 @@ class BOOST_EXTENSION_EXPORT_DECL Logger
bool _isEnabled;
};



#endif /* LOGGER_HPP_ */
69 changes: 44 additions & 25 deletions SimulationRuntime/cpp/SimCoreFactory/OMCFactory/OMCFactory.cpp
Expand Up @@ -55,10 +55,29 @@ SimSettings OMCFactory::readSimulationParameter(int argc, const char* argv[])
{
int opt;
int portnum;
std::map<std::string,OutputFormat> outputFormatMap = map_list_of("csv", CSV)("mat", MAT)("buffer", BUFFER)("empty", EMPTY);
std::map<std::string,LogCategory> logCatMap = map_list_of("init", INIT)("nls", NLS)("ls",LS)("solv", SOLV)("output", OUT)("event",EVT)("modell",MOD)("other",OTHER);
std::map<std::string,LogLevel> logLvlMap = map_list_of("error", ERROR)("warning", WARNING)("info", INFO)("debug", DEBUG);
std::map<std::string,OutputPointType> outputPointTypeMap = map_list_of("all", ALL)("step", STEP)("empty2",EMPTY2);
std::map<std::string,OutputFormat> outputFormatMap = map_list_of
("csv", OM_CSV)
("mat", OM_MAT)
("buffer", OM_BUFFER)
("empty", OM_EMPTY);
std::map<std::string,LogCategory> logCatMap = map_list_of
("init", OM_INIT)
("nls", OM_NLS)
("ls", OM_LS)
("solv", OM_SOLV)
("output", OM_OUT)
("event", OM_EVT)
("modell", OM_MOD)
("other", OM_OTHER);
std::map<std::string,LogLevel> logLvlMap = map_list_of
("error", OM_ERROR)
("warning", OM_WARNING)
("info", OM_INFO)
("debug", OM_DEBUG);
std::map<std::string,OutputPointType> outputPointTypeMap = map_list_of
("all", OM_ALL)
("step", OM_STEP)
("empty2", OM_EMPTY2);
po::options_description desc("Allowed options");
desc.add_options()
("help", "produce help message")
Expand Down Expand Up @@ -157,7 +176,7 @@ SimSettings OMCFactory::readSimulationParameter(int argc, const char* argv[])
//cout << "results file: " << vm["results-file"].as<string>() << std::endl;
outputFormat_str = vm["OutputFormat"].as<string>();
outputFomat = outputFormatMap[outputFormat_str];
if(!((outputFomat==CSV) || (outputFomat==EMPTY)||(outputFomat==BUFFER)||(outputFomat==MAT)))
if(!((outputFomat==OM_CSV) || (outputFomat==OM_EMPTY)||(outputFomat==OM_BUFFER)||(outputFomat==OM_MAT)))
{
std::string eception_msg = "The output format is not supported yet. Please use outputFormat=\"csv\" or outputFormat=\"empty\" or outputFormat=\"matlab\"in simulate command ";
throw ModelicaSimulationError(MODEL_FACTORY,eception_msg.c_str());
Expand All @@ -184,26 +203,26 @@ SimSettings OMCFactory::readSimulationParameter(int argc, const char* argv[])
LogSettings logSet;
if (vm.count("log-settings"))
{
std::vector<std::string> log_vec = vm["log-settings"].as<std::vector<string> >(),tmpvec;
for(unsigned i=0;i<log_vec.size();++i)
{
cout << i << ". " << log_vec[i] << std::endl;
tmpvec.clear();
boost::split(tmpvec,log_vec[i],boost::is_any_of("="));

if(tmpvec.size()>1 && logLvlMap.find(tmpvec[1]) != logLvlMap.end() && ( tmpvec[0] == "all" || logCatMap.find(tmpvec[0]) != logCatMap.end()))
{
if(tmpvec[0] == "all")
{
logSet.setAll(logLvlMap[tmpvec[1]]);
break;
}
else
logSet.modes[logCatMap[tmpvec[0]]] = logLvlMap[tmpvec[1]];
}
else
throw ModelicaSimulationError(MODEL_FACTORY,"log-settings flags not supported: " + boost::lexical_cast<std::string>(log_vec[i]) + "\n");
}
std::vector<std::string> log_vec = vm["log-settings"].as<std::vector<string> >(),tmpvec;
for(unsigned i=0;i<log_vec.size();++i)
{
cout << i << ". " << log_vec[i] << std::endl;
tmpvec.clear();
boost::split(tmpvec,log_vec[i],boost::is_any_of("="));

if(tmpvec.size()>1 && logLvlMap.find(tmpvec[1]) != logLvlMap.end() && ( tmpvec[0] == "all" || logCatMap.find(tmpvec[0]) != logCatMap.end()))
{
if(tmpvec[0] == "all")
{
logSet.setAll(logLvlMap[tmpvec[1]]);
break;
}
else
logSet.modes[logCatMap[tmpvec[0]]] = logLvlMap[tmpvec[1]];
}
else
throw ModelicaSimulationError(MODEL_FACTORY,"log-settings flags not supported: " + boost::lexical_cast<std::string>(log_vec[i]) + "\n");
}

}

Expand Down
28 changes: 16 additions & 12 deletions SimulationRuntime/cpp/Solver/CVode/CVode.cpp
Expand Up @@ -10,6 +10,10 @@
#include <Core/Utils/numeric/bindings/traits/ublas_vector.hpp>
#include <Core/Utils/numeric/bindings/traits/ublas_sparse.hpp>

#if defined(_MSC_VER) && !defined(RUNTIME_STATIC_LINKING)
Logger* Logger::instance = NULL;
#endif

Cvode::Cvode(IMixedSystem* system, ISolverSettings* settings)
: SolverDefaultImplementation(system, settings),
_cvodesettings(dynamic_cast<ISolverSettings*>(_settings)),
Expand Down Expand Up @@ -308,14 +312,14 @@ void Cvode::initialize()

_cvode_initialized = true;

Logger::write("Cvode: initialized",SOLV,DEBUG);
Logger::write("Cvode: initialized",OM_SOLV,OM_DEBUG);
}
}

void Cvode::solve(const SOLVERCALL action)
{
bool writeEventOutput = (_settings->getGlobalSettings()->getOutputPointType() == ALL);
bool writeOutput = !(_settings->getGlobalSettings()->getOutputFormat() == EMPTY) && !(_settings->getGlobalSettings()->getOutputPointType() == EMPTY2);
bool writeEventOutput = (_settings->getGlobalSettings()->getOutputPointType() == OM_ALL);
bool writeOutput = !(_settings->getGlobalSettings()->getOutputFormat() == OM_EMPTY) && !(_settings->getGlobalSettings()->getOutputPointType() == OM_EMPTY2);

#ifdef RUNTIME_PROFILING
MEASURETIME_REGION_DEFINE(cvodeSolveFunctionHandler, "solve");
Expand Down Expand Up @@ -454,8 +458,8 @@ void Cvode::CVodeCore()
if (_idid < 0)
throw ModelicaSimulationError(SOLVER,"CVode::ReInit");

bool writeEventOutput = (_settings->getGlobalSettings()->getOutputPointType() == ALL);
bool writeOutput = !(_settings->getGlobalSettings()->getOutputFormat() == EMPTY) && !(_settings->getGlobalSettings()->getOutputPointType() == EMPTY2);
bool writeEventOutput = (_settings->getGlobalSettings()->getOutputPointType() == OM_ALL);
bool writeOutput = !(_settings->getGlobalSettings()->getOutputFormat() == OM_EMPTY) && !(_settings->getGlobalSettings()->getOutputPointType() == OM_EMPTY2);

while (_solverStatus & ISolver::CONTINUE && !_interrupt )
{
Expand Down Expand Up @@ -939,13 +943,13 @@ void Cvode::writeSimulationInfo()

flag = CVodeGetNonlinSolvStats(_cvodeMem, &nni, &ncfn);

Logger::write("Cvode: number steps = " + boost::lexical_cast<std::string>(nst),SOLV,INFO);
Logger::write("Cvode: function evaluations 'f' = " + boost::lexical_cast<std::string>(nfe),SOLV,INFO);
Logger::write("Cvode: error test failures 'netf' = " + boost::lexical_cast<std::string>(netfS),SOLV,INFO);
Logger::write("Cvode: linear solver setups 'nsetups' = " + boost::lexical_cast<std::string>(nsetups),SOLV,INFO);
Logger::write("Cvode: nonlinear iterations 'nni' = " + boost::lexical_cast<std::string>(nni),SOLV,INFO);
Logger::write("Cvode: convergence failures 'ncfn' = " + boost::lexical_cast<std::string>(ncfn),SOLV,INFO);
Logger::write("Cvode: number of evaluateODE calls 'eODE' = " + boost::lexical_cast<std::string>(_numberOfOdeEvaluations),SOLV,INFO);
Logger::write("Cvode: number steps = " + boost::lexical_cast<std::string>(nst),OM_SOLV,OM_INFO);
Logger::write("Cvode: function evaluations 'f' = " + boost::lexical_cast<std::string>(nfe),OM_SOLV,OM_INFO);
Logger::write("Cvode: error test failures 'netf' = " + boost::lexical_cast<std::string>(netfS),OM_SOLV,OM_INFO);
Logger::write("Cvode: linear solver setups 'nsetups' = " + boost::lexical_cast<std::string>(nsetups),OM_SOLV,OM_INFO);
Logger::write("Cvode: nonlinear iterations 'nni' = " + boost::lexical_cast<std::string>(nni),OM_SOLV,OM_INFO);
Logger::write("Cvode: convergence failures 'ncfn' = " + boost::lexical_cast<std::string>(ncfn),OM_SOLV,OM_INFO);
Logger::write("Cvode: number of evaluateODE calls 'eODE' = " + boost::lexical_cast<std::string>(_numberOfOdeEvaluations),OM_SOLV,OM_INFO);

//// Solver
//outputStream << "\nSolver: " << getName()
Expand Down

0 comments on commit c99eeed

Please sign in to comment.