Skip to content

Commit

Permalink
- replaced boost_log with logger-class of cpp-runtime
Browse files Browse the repository at this point in the history
- moved the implementation of StaticNonLinSolver-, StaticLinSolver- and StaticSolverOMCFactory to code files (because otherwise we are not able to disable cvode and kinsol for FMU export, easily)
- FMU is now using Newton instead of Kinsol by default
- FMU has no dependencies to sundials anymore
  • Loading branch information
Marcus Walther authored and OpenModelica-Hudson committed Jun 29, 2015
1 parent 48def8b commit 3385317
Show file tree
Hide file tree
Showing 24 changed files with 254 additions and 347 deletions.
5 changes: 4 additions & 1 deletion Compiler/Template/CodegenCpp.tpl
Expand Up @@ -1859,6 +1859,7 @@ case SIMCODE(modelInfo=MODELINFO(__), makefileParams=MAKEFILE_PARAMS(__), simula
#include <Core/ModelicaDefine.h>
#include <Core/Modelica.h>
#include <Core/SimController/ISimController.h>
#include <Core/Utils/extension/logger.hpp>

<%
match(getConfigString(PROFILING_LEVEL))
Expand Down Expand Up @@ -1959,6 +1960,8 @@ case SIMCODE(modelInfo=MODELINFO(__), makefileParams=MAKEFILE_PARAMS(__), simula
%>
try
{
Logger::initialize();
Logger::setEnabled(false);
<%if boolNot(stringEq(getConfigString(PROFILING_LEVEL),"none")) then
<<
std::vector<MeasureTimeData> measureTimeArraySimulation = std::vector<MeasureTimeData>(2); //0 all, 1 setup
Expand Down Expand Up @@ -2584,7 +2587,7 @@ case "gcc" then
let libsStr = (makefileParams.libs |> lib => lib ;separator=" ")
let libsPos1 = if not dirExtra then libsStr //else ""
let libsPos2 = if dirExtra then libsStr // else ""
let staticLibs = '-lOMCppOMCFactory_static -lOMCppSimController_static -lOMCppSimulationSettings_static -lOMCppSystem_static -lOMCppNewton_static -lOMCppEuler_static -lOMCppKinsol_static -lOMCppCVode_static -lOMCppSolver_static -lOMCppMath_static -lOMCppModelicaUtilities_static -lOMCppExtensionUtilities_static -L$(SUNDIALS_LIBS) -L$(UMFPACK_LIBS) -L$(LAPACK_LIBS)'
let staticLibs = '-Wl,--start-group -lOMCppOMCFactory_static -lOMCppSystem_static -lOMCppSimController_static -Wl,--end-group -lOMCppSimulationSettings_static -lOMCppNewton_static -lOMCppEuler_static -lOMCppKinsol_static -lOMCppCVode_static -lOMCppSolver_static -lOMCppMath_static -lOMCppModelicaUtilities_static -lOMCppExtensionUtilities_static -L$(SUNDIALS_LIBS) -L$(UMFPACK_LIBS) -L$(LAPACK_LIBS)'
let staticIncludes = '-I"$(SUNDIALS_INCLUDE)" -I"$(SUNDIALS_INCLUDE)/kinsol" -I"$(SUNDIALS_INCLUDE)/nvector"'
let _extraCflags = match sopt case SOME(s as SIMULATION_SETTINGS(__)) then ""
let extraCflags = '<%_extraCflags%><% if Flags.isSet(Flags.GEN_DEBUG_SYMBOLS) then " -g"%>'
Expand Down
8 changes: 4 additions & 4 deletions Compiler/Template/CodegenFMUCpp.tpl
Expand Up @@ -731,7 +731,7 @@ case SIMCODE(modelInfo=MODELINFO(__), makefileParams=MAKEFILE_PARAMS(__), simula

#OMCPP_LIBS= -lOMCppSystem_static -lOMCppDataExchange_static -lOMCppOMCFactory_static -OMCppSimulationSettings_static -lOMCppMath_static -lOMCppFMU_static -lOMCppExtensionUtilities_static -lOMCppModelicaUtilities_static
# CVode can be used for Co-Simulation FMUs, Kinsol is available to handle non linear equation systems
OMCPP_LIBS=-lOMCppSystem_static -lOMCppDataExchange_static -lOMCppOMCFactory_static -lOMCppSimController_static -lOMCppSimulationSettings_static -lOMCppNewton_static -lOMCppKinsol_static -lOMCppCVode_static -lOMCppSolver_static -lOMCppMath_static -lOMCppModelicaUtilities_static -lOMCppExtensionUtilities_static -lOMCppFMU_static
OMCPP_LIBS=-Wl,--start-group -lOMCppOMCFactory_FMU_static -lOMCppSystem_static -lOMCppSimController_static -Wl,--end-group -lOMCppDataExchange_static -lOMCppSimulationSettings_static -lOMCppNewton_static -lOMCppSolver_static -lOMCppMath_static -lOMCppModelicaUtilities_static -lOMCppExtensionUtilities_static -lOMCppFMU_static
OMCPP_SOLVER_LIBS=$(SUNDIALS_LIBRARIES)
MODELICA_EXTERNAL_LIBS=-lModelicaExternalC -lModelicaStandardTables -L$(LAPACK_LIBS) $(LAPACK_LIBRARIES)
BOOST_LIBRARIES = -l$(BOOST_SYSTEM_LIB) -l$(BOOST_FILESYSTEM_LIB) -l$(BOOST_PROGRAM_OPTIONS_LIB)
Expand All @@ -746,10 +746,10 @@ case SIMCODE(modelInfo=MODELINFO(__), makefileParams=MAKEFILE_PARAMS(__), simula
<%\t%>$(CXX) -shared -o <%fileNamePrefix%>$(DLLEXT) $(OFILES) $(LDFLAGS) $(LIBS)
<%\t%>rm -rf binaries
<%\t%><%mkdir%> -p "binaries/$(PLATFORM)"
<%\t%><%mkdir%> -p "documentation"
#<%\t%><%mkdir%> -p "documentation"
<%\t%>cp <%fileNamePrefix%>$(DLLEXT) "binaries/$(PLATFORM)/"
<%\t%>cp $(SUNDIALS_LIBRARIES_KINSOL) "binaries/$(PLATFORM)/"
<%\t%>cp $(OMHOME)/share/omc/runtime/cpp/licenses/sundials.license "documentation/"
#<%\t%>cp $(SUNDIALS_LIBRARIES_KINSOL) "binaries/$(PLATFORM)/"
#<%\t%>cp $(OMHOME)/share/omc/runtime/cpp/licenses/sundials.license "documentation/"
<%\t%>rm -f <%modelName%>.fmu
<%\t%>zip -r "<%modelName%>.fmu" modelDescription.xml binaries
<%\t%>rm -rf binaries
Expand Down
59 changes: 11 additions & 48 deletions SimulationRuntime/cpp/Core/SimController/SimManager.cpp
Expand Up @@ -5,26 +5,6 @@
#include <Core/ModelicaDefine.h>
#include <Core/Modelica.h>
#include <Core/SimController/SimManager.h>
/*
#include <boost/log/common.hpp>
#include <boost/log/expressions.hpp>
#include <boost/log/utility/setup/file.hpp>
#include <boost/log/utility/setup/console.hpp>
#include <boost/log/utility/setup/common_attributes.hpp>
#include <boost/log/attributes/timer.hpp>
#include <boost/log/attributes/named_scope.hpp>
#include <boost/log/sources/logger.hpp>
#include <boost/log/support/date_time.hpp>
namespace logging = boost::log;
namespace attrs = boost::log::attributes;
namespace src = boost::log::sources;
namespace keywords = boost::log::keywords;
*/

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

/* Logs temporarily disabled
BOOST_LOG_SEV(simmgr_lg::get(), simmgr_info) << "start init";*/

Logger::writeDebug("SimManager start init");
// Flag für Endlossimulaton (wird gesetzt wenn Solver zurückkommt)
_continueSimulation = true;

Expand Down Expand Up @@ -176,16 +154,8 @@ void SimManager::initialize()
_events = new bool[_dimZeroFunc];
memset(_events, false, _dimZeroFunc * sizeof(bool));
}
/*
//Log initialisieren
logging::add_console_log(std::clog, keywords::format = "%TimeStamp%: %Message%");
// Also let's add some commonly used attributes, like timestamp and record counter.
logging::add_common_attributes();
logging::core::get()->add_thread_attribute("Scope", attrs::named_scope());
*/
/* Logs vorübergehend deaktiviert
BOOST_LOG_SEV(simmgr_lg::get(), simmgr_info) << "Assemble completed";*/

Logger::writeDebug("SimManager assemble completed");
//#if defined(__TRICORE__) || defined(__vxworks)
// Initialization for RT simulation
if (_config->getGlobalSettings()->useEndlessSim())
Expand Down Expand Up @@ -287,35 +257,26 @@ void SimManager::runSimulation()
#endif
try
{
/* Logs temporarily disabled
BOOST_LOG_SEV(simmgr_lg::get(), simmgr_normal) << "Start simulation at t= " << _tStart;
*/
Logger::writeInfo("SimManager: start simulation at t = " + boost::lexical_cast<std::string>(_tStart));
runSingleProcess();
// Zeit messen, Ausgabe der SimInfos
ISolver::SOLVERSTATUS status = _solver->getSolverStatus();
if ((status & ISolver::DONE) || (status & ISolver::USER_STOP))
{
/* Logs temporarily disabled
BOOST_LOG_SEV(simmgr_lg::get(), simmgr_normal) << "Simulation done at t= " << _tEnd;
BOOST_LOG_SEV(simmgr_lg::get(), simmgr_normal) << "Number of steps: " << _totStps.at(0);
BOOST_LOG_SEV(simmgr_lg::get(), simmgr_normal) << "Simulationsdauer: " << (_tClockEnd-_tClockStart)/1000.0;
*/
Logger::writeInfo("SimManager: simulation done at t = " + boost::lexical_cast<std::string>(_tEnd));
Logger::writeInfo("SimManager: number of steps = " + boost::lexical_cast<std::string>(_totStps));
writeProperties();
}
}
catch (std::exception & ex)
{
/* Logs temporarily disabled
BOOST_LOG_SEV(simmgr_lg::get(), simmgr_normal) << "Simulation finish with errors at t= " << _tEnd;
BOOST_LOG_SEV(simmgr_lg::get(), simmgr_normal) << "Number of steps: " << _totStps.at(0);
*/
Logger::writeError("SimManager: simulation finish with errors at t = " + boost::lexical_cast<std::string>(_tEnd));
Logger::writeInfo("SimManager: number of steps = " + boost::lexical_cast<std::string>(_totStps));
writeProperties();

/* Logs temporarily disabled
BOOST_LOG_SEV(simmgr_lg::get(), simmgr_critical) << "SimManger simmgr_error: " + simmgr_error_simmgr_info;
*/
Logger::writeError("SimManager: error = " + boost::lexical_cast<std::string>(ex.what()));
//ex << error_id(SIMMANAGER);
throw;
throw;
}
#ifdef RUNTIME_PROFILING
if (MeasureTime::getInstance() != NULL)
Expand Down Expand Up @@ -582,6 +543,8 @@ void SimManager::runSingleProcess()
_solverTask = ISolver::SOLVERCALL(_solverTask ^ ISolver::RECORDCALL);
/* Logs temporarily disabled
BOOST_LOG_SEV(simmgr_lg::get(), simmgr_normal) <<"Run single process." ; */
Logger::writeDebug("SimManager: run single process");

// Zeitinvervall speichern
//_H =_tEnd - _tStart;

Expand Down
2 changes: 1 addition & 1 deletion SimulationRuntime/cpp/Core/System/AlgLoopSolverFactory.cpp
Expand Up @@ -8,7 +8,7 @@
#include <Core/System/AlgLoopSolverFactory.h>

AlgLoopSolverFactory::AlgLoopSolverFactory(IGlobalSettings* global_settings,PATH library_path,PATH modelicasystem_path)
: ObjectFactory<BaseFactory>(library_path,modelicasystem_path,library_path)
: IAlgLoopSolverFactory(), ObjectFactory<BaseFactory>(library_path,modelicasystem_path,library_path)
, NonLinSolverPolicy(library_path,modelicasystem_path,library_path)
, LinSolverPolicy(library_path,modelicasystem_path,library_path)
, _global_settings(global_settings)
Expand Down
6 changes: 6 additions & 0 deletions SimulationRuntime/cpp/Core/Utils/extension/logger.cpp
Expand Up @@ -36,6 +36,12 @@ void Logger::writeInfoInternal(std::string infoMsg)
std::cout << "Info: " << infoMsg << std::endl;
}

void Logger::writeDebugInternal(std::string debugMsg)
{
if(_isEnabled)
std::cout << "Debug: " << debugMsg << std::endl;
}

void Logger::setEnabledInternal(bool enabled)
{
_isEnabled = enabled;
Expand Down
25 changes: 1 addition & 24 deletions SimulationRuntime/cpp/Include/Core/SimController/SimManager.h
Expand Up @@ -5,34 +5,11 @@
*/
#include "Configuration.h"
#include "Initialization.h"

#include <Core/Utils/extension/logger.hpp>

#ifdef RUNTIME_PROFILING
#include <Core/Utils/extension/measure_time.hpp>
#endif
/*Logging vorübergehend deaktiviert
namespace logging = boost::log;
namespace attrs = boost::log::attributes;
namespace src = boost::log::sources;
namespace keywords = boost::log::keywords;
using boost::shared_ptr;
enum simmgrseverity_level
{
simmgr_info,
simmgr_normal,
simmgr_notification,
simmgr_warning,
simmgr_error,
simmgr_critical
};
// Global logger declaration
BOOST_LOG_INLINE_GLOBAL_LOGGER_CTOR_ARGS(
simmgr_lg,
src::severity_channel_logger_mt< >,
(keywords::severity = simmgr_normal)(keywords::channel = "Core.SimManager"))
*/

class SimManager
{
Expand Down
Expand Up @@ -23,7 +23,7 @@ using std::string;
#endif
*/
enum OutputFormat {CSV, MAT, BUFFER, EMPTY};
enum LogType {OFF, STATS, NLS, ODE};
enum LogType {OFF, STATS, NLS, ODE, DEBUG};
enum OutputPointType {ALL, STEP, EMPTY2};
class IGlobalSettings
{
Expand Down Expand Up @@ -69,4 +69,4 @@ class IGlobalSettings
virtual void setRuntimeLibrarypath(string) = 0;
virtual string getRuntimeLibrarypath() = 0;
};
/** @} */ // end of coreSimulationSettings
/** @} */ // end of coreSimulationSettings
Expand Up @@ -34,4 +34,4 @@ class AlgLoopSolverFactory : public IAlgLoopSolverFactory, public NonLinSolverPo
std::vector<boost::shared_ptr<IAlgLoopSolver> > _algsolvers;
IGlobalSettings* _global_settings;
};
/** @} */ // end of coreSystem
/** @} */ // end of coreSystem
Expand Up @@ -21,7 +21,8 @@ Copyright (c) 2008, OSMC
class IAlgLoopSolverFactory
{
public:
IAlgLoopSolverFactory() {};
virtual ~IAlgLoopSolverFactory() {};
virtual boost::shared_ptr<IAlgLoopSolver> createAlgLoopSolver(IAlgLoop* algLoop) = 0;
};
/** @} */ // end of coreSystem
/** @} */ // end of coreSystem
6 changes: 6 additions & 0 deletions SimulationRuntime/cpp/Include/Core/Utils/extension/logger.hpp
Expand Up @@ -46,6 +46,11 @@ class BOOST_EXTENSION_EXPORT_DECL Logger
getInstance()->writeInfoInternal(infoMsg);
}

static void writeDebug(std::string debugMsg)
{
getInstance()->writeDebugInternal(debugMsg);
}

static void setEnabled(bool enabled)
{
getInstance()->setEnabledInternal(enabled);
Expand All @@ -62,6 +67,7 @@ class BOOST_EXTENSION_EXPORT_DECL Logger
virtual void writeErrorInternal(std::string errorMsg);
virtual void writeWarningInternal(std::string warningMsg);
virtual void writeInfoInternal(std::string infoMsg);
virtual void writeDebugInternal(std::string debugMsg);
virtual void setEnabledInternal(bool enabled);
virtual bool isEnabledInternal();

Expand Down
4 changes: 2 additions & 2 deletions SimulationRuntime/cpp/Include/FMU/FMUGlobalSettings.h
Expand Up @@ -36,9 +36,9 @@ class FMUGlobalSettings : public IGlobalSettings
virtual void setOutputPath(string) {}
virtual string getSelectedSolver() { return "euler"; }
virtual void setSelectedSolver(string) {}
virtual string getSelectedLinSolver() { return "kinsol"; }
virtual string getSelectedLinSolver() { return "newton"; }
virtual void setSelectedLinSolver(string) {}
virtual string getSelectedNonLinSolver() { return "kinsol"; }
virtual string getSelectedNonLinSolver() { return "newton"; }
virtual void setSelectedNonLinSolver(string) {}
virtual void load(string xml_file) {};
virtual void setResultsFileName(string) {}
Expand Down
Expand Up @@ -37,6 +37,8 @@ class OMCFactory

//boost::shared_ptr<ISimController> _simController;
std::map<string,shared_library> _modules;
std::string _defaultLinSolver;
std::string _defaultNonLinSolver;
PATH _library_path;
PATH _modelicasystem_path;
};
Expand Down
Expand Up @@ -3,48 +3,23 @@
*
* @{
*/
#include <Core/ModelicaDefine.h>
#include <Core/Modelica.h>
#include <SimCoreFactory/Policies/LinSolverOMCFactory.h>

template<class T>
struct ObjectFactory;

template<class CreationPolicy>
struct StaticLinSolverOMCFactory : public LinSolverOMCFactory<CreationPolicy> {

public:
StaticLinSolverOMCFactory(PATH library_path, PATH modelicasystem_path,PATH config_path)
:ObjectFactory<CreationPolicy>(library_path,modelicasystem_path,config_path)
,LinSolverOMCFactory<CreationPolicy>(library_path,modelicasystem_path,config_path)
,_last_selected_solver("empty")
{

}
virtual ~StaticLinSolverOMCFactory()
{

}
StaticLinSolverOMCFactory(PATH library_path, PATH modelicasystem_path,PATH config_path);
virtual ~StaticLinSolverOMCFactory();

virtual boost::shared_ptr<ILinSolverSettings> createLinSolverSettings(string lin_solver)
{
/*
if(lin_solver.compare("umfpack")==0)
{
boost::shared_ptr<ILinSolverSettings> settings = boost::shared_ptr<ILinSolverSettings>(new UmfPackSettings());
return settings;
}
else */
return LinSolverOMCFactory<CreationPolicy>::createLinSolverSettings(lin_solver);
}
virtual boost::shared_ptr<ILinSolverSettings> createLinSolverSettings(string lin_solver);
virtual boost::shared_ptr<IAlgLoopSolver> createLinSolver(IAlgLoop* algLoop, string solver_name, boost::shared_ptr<ILinSolverSettings> solver_settings);

virtual boost::shared_ptr<IAlgLoopSolver> createLinSolver(IAlgLoop* algLoop, string solver_name, boost::shared_ptr<ILinSolverSettings> solver_settings)
{
/*
if(solver_name.compare("umfpack")==0)
{
boost::shared_ptr<IAlgLoopSolver> solver = boost::shared_ptr<IAlgLoopSolver>(new UmfPack(algLoop,solver_settings.get()));
return solver;
}
else */
return LinSolverOMCFactory<CreationPolicy>::createLinSolver(algLoop, solver_name, solver_settings);
}
protected:
string _last_selected_solver;
private:
Expand Down

0 comments on commit 3385317

Please sign in to comment.