Skip to content

Commit

Permalink
FMI2 Cpp: distinguish model identifier from model class
Browse files Browse the repository at this point in the history
git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@25310 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
rfranke committed Mar 30, 2015
1 parent 26bd258 commit 0f669b2
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 9 deletions.
4 changes: 2 additions & 2 deletions Compiler/Template/CodegenFMUCpp.tpl
Expand Up @@ -144,8 +144,8 @@ case SIMCODE(modelInfo=MODELINFO(__)) then
let modelShortName = lastIdentOfPath(modelInfo.name)
let modelIdentifier = System.stringReplace(modelName, ".", "_")
<<
// define class name and unique id
#define MODEL_IDENTIFIER <%modelShortName%>Extension
// define model identifier and unique id
#define MODEL_IDENTIFIER <%modelShortName%>
#define MODEL_GUID "{<%guid%>}"

#include <Core/Modelica.h>
Expand Down
4 changes: 2 additions & 2 deletions SimulationRuntime/cpp/Include/FMU/FMUWrapper.cpp
Expand Up @@ -19,8 +19,8 @@ FMUWrapper::FMUWrapper(fmiString instanceName, fmiString GUID,
{
boost::shared_ptr<IAlgLoopSolverFactory>
solver_factory(new AlgLoopSolverFactory(&_global_settings,PATH(""),PATH("")));
_model = boost::shared_ptr<MODEL_IDENTIFIER>
(new MODEL_IDENTIFIER(&_global_settings, solver_factory,boost::shared_ptr<ISimData>(new SimData())));
_model = boost::shared_ptr<MODEL_CLASS>
(new MODEL_CLASS(&_global_settings, solver_factory, boost::shared_ptr<ISimData>(new SimData())));
_model->setInitial(true);
_tmp_real_buffer.resize(_model->getDimReal());
_tmp_int_buffer.resize(_model->getDimInteger());
Expand Down
7 changes: 6 additions & 1 deletion SimulationRuntime/cpp/Include/FMU/FMUWrapper.h
Expand Up @@ -6,6 +6,11 @@
#include "FMU/IFMUInterface.h"
#include "FMU/FMUGlobalSettings.h"

// build MODEL_CLASS from MODEL_IDENTIFIER
#define FMU_PASTER(a, b) a ## b
#define FMU_CONCAT(a, b) FMU_PASTER(a, b)
#define MODEL_CLASS FMU_CONCAT(MODEL_IDENTIFIER, Extension)

class FMUWrapper : public IFMUInterface
{
public:
Expand Down Expand Up @@ -41,7 +46,7 @@ class FMUWrapper : public IFMUInterface
virtual fmiStatus setExternalFunction (fmiValueReference vr[], size_t nvr, const void* value[]);
private:
FMUGlobalSettings _global_settings;
boost::shared_ptr<MODEL_IDENTIFIER> _model;
boost::shared_ptr<MODEL_CLASS> _model;
std::vector<fmiReal> _tmp_real_buffer;
std::vector<fmiInteger> _tmp_int_buffer;
std::vector<fmiBoolean> _tmp_bool_buffer;
Expand Down
6 changes: 3 additions & 3 deletions SimulationRuntime/cpp/Include/FMU2/FMU2Wrapper.cpp
Expand Up @@ -74,9 +74,9 @@ FMU2Wrapper::FMU2Wrapper(fmi2String instanceName, fmi2String GUID,
boost::shared_ptr<IAlgLoopSolverFactory>
solver_factory(new AlgLoopSolverFactory(&_global_settings,
PATH(""), PATH("")));
_model = boost::shared_ptr<MODEL_IDENTIFIER>
(new MODEL_IDENTIFIER(&_global_settings, solver_factory,
boost::shared_ptr<ISimData>(new SimData())));
_model = boost::shared_ptr<MODEL_CLASS>
(new MODEL_CLASS(&_global_settings, solver_factory,
boost::shared_ptr<ISimData>(new SimData())));
_model->setInitial(true);
_model->initialize(); // set default start values
_tmp_real_buffer.resize(_model->getDimReal());
Expand Down
7 changes: 6 additions & 1 deletion SimulationRuntime/cpp/Include/FMU2/FMU2Wrapper.h
Expand Up @@ -40,6 +40,11 @@
#include "fmi2Functions.h"
#include "FMU2GlobalSettings.h"

// build MODEL_CLASS from MODEL_IDENTIFIER
#define FMU2_PASTER(a, b) a ## b
#define FMU2_CONCAT(a, b) FMU2_PASTER(a, b)
#define MODEL_CLASS FMU2_CONCAT(MODEL_IDENTIFIER, Extension)

// define logger as macro that passes through variadic args
#define FMU2_LOG(w, status, category, ...) \
if ((w)->logCategories & (1 << (category))) \
Expand Down Expand Up @@ -124,7 +129,7 @@ class FMU2Wrapper

private:
FMU2GlobalSettings _global_settings;
boost::shared_ptr<MODEL_IDENTIFIER> _model;
boost::shared_ptr<MODEL_CLASS> _model;
std::vector<fmi2Real> _tmp_real_buffer;
std::vector<fmi2Integer> _tmp_int_buffer;
std::vector<fmi2Boolean> _tmp_bool_buffer;
Expand Down

0 comments on commit 0f669b2

Please sign in to comment.