Skip to content

Commit

Permalink
- tabs are not welcome here :)
Browse files Browse the repository at this point in the history
git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@15701 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
adrpo committed Mar 29, 2013
1 parent a1edc45 commit 10e9d84
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 90 deletions.
178 changes: 89 additions & 89 deletions SimulationRuntime/cpp/Include/FMU/FMUWrapper.cpp
Expand Up @@ -2,11 +2,11 @@
#include "FMU/FMUWrapper.h"

FMUWrapper::FMUWrapper(fmiString instanceName, fmiString GUID,
fmiCallbackFunctions functions, fmiBoolean loggingOn) :
IFMUInterface(instanceName, GUID, functions, loggingOn),
_global_settings()
fmiCallbackFunctions functions, fmiBoolean loggingOn) :
IFMUInterface(instanceName, GUID, functions, loggingOn),
_global_settings()
{
_model = boost::shared_ptr<MODEL_IDENTIFIER>(new MODEL_IDENTIFIER(_global_settings));
_model = boost::shared_ptr<MODEL_IDENTIFIER>(new MODEL_IDENTIFIER(_global_settings));
}

FMUWrapper::~FMUWrapper()
Expand All @@ -15,176 +15,176 @@ FMUWrapper::~FMUWrapper()

fmiStatus FMUWrapper::setDebugLogging(fmiBoolean loggingOn)
{
return fmiOK;
return fmiOK;
}

/* independent variables and re-initialization of caching */
fmiStatus FMUWrapper::setTime(fmiReal time)
{
_time = time;
_model->setTime(time);
_need_update = true;
return fmiOK;
_time = time;
_model->setTime(time);
_need_update = true;
return fmiOK;
}

fmiStatus FMUWrapper::setContinuousStates(const fmiReal states[], size_t nx)
{
// to set states do the folowing
_model->setVars(states);
_need_update = true;
return fmiOK;
// to set states do the folowing
_model->setVars(states);
_need_update = true;
return fmiOK;
}

fmiStatus FMUWrapper::getContinuousStates(fmiReal states[], size_t nx)
{
_model->giveVars(states);
return fmiOK;
_model->giveVars(states);
return fmiOK;
}

fmiStatus FMUWrapper::getDerivatives(fmiReal derivatives[], size_t nx)
{
updateModel();
_model->giveRHS(derivatives);
return fmiOK;
updateModel();
_model->giveRHS(derivatives);
return fmiOK;
}


void FMUWrapper::updateModel()
{
// only call update if, time, states or imputs changed
if(!_need_update)
return;
// only call update if, time, states or imputs changed
if(!_need_update)
return;

_model->update(); // This will calculate the values for derivate variables, algebraic variables
_need_update = false;
_model->update(); // This will calculate the values for derivate variables, algebraic variables
_need_update = false;
}

fmiStatus FMUWrapper::completedIntegratorStep(fmiBoolean* callEventUpdate)
{
return fmiOK;
return fmiOK;
}

// Functions for setting inputs and start values
fmiStatus FMUWrapper::setReal(const fmiValueReference vr[], size_t nvr,
const fmiReal value[])
const fmiReal value[])
{ _need_update = true; return fmiOK; }

fmiStatus FMUWrapper::setInteger(const fmiValueReference vr[], size_t nvr,
const fmiInteger value[])
const fmiInteger value[])
{ _need_update = true; return fmiOK; }

fmiStatus FMUWrapper::setBoolean(const fmiValueReference vr[], size_t nvr,
const fmiBoolean value[])
const fmiBoolean value[])
{ _need_update = true; return fmiOK; }

fmiStatus FMUWrapper::setString(const fmiValueReference vr[], size_t nvr,
const fmiString value[])
const fmiString value[])
{ _need_update = true; return fmiOK; }

/* of the model equations */
fmiStatus FMUWrapper::initialize(fmiBoolean toleranceControlled, fmiReal relativeTolerance, fmiEventInfo& eventInfo)
{
double start_time = _time; // TODO set to useful values
double end_time = _time; // TODO set to useful values
_model->init(start_time, end_time);
_need_update = true;
// TODO set options for algerbraic solver according to toleranceControlled and relativeTolerance
eventInfo.terminateSimulation = fmiFalse;
eventInfo.upcomingTimeEvent = fmiFalse;
//eventInfo.nextTimeEvent no need to set this for this model
return fmiOK;
double start_time = _time; // TODO set to useful values
double end_time = _time; // TODO set to useful values
_model->init(start_time, end_time);
_need_update = true;
// TODO set options for algerbraic solver according to toleranceControlled and relativeTolerance
eventInfo.terminateSimulation = fmiFalse;
eventInfo.upcomingTimeEvent = fmiFalse;
//eventInfo.nextTimeEvent no need to set this for this model
return fmiOK;
}

fmiStatus FMUWrapper::getEventIndicators(fmiReal eventIndicators[], size_t ni)
{
updateModel();
bool conditions[NUMBER_OF_EVENT_INDICATORS];
_model->giveConditions(conditions);
_model->giveZeroFunc(eventIndicators);
for(int i = 0; i < ni; i++)
if(!conditions[i]) eventIndicators[i] = -eventIndicators[i];
return fmiOK;
updateModel();
bool conditions[NUMBER_OF_EVENT_INDICATORS];
_model->giveConditions(conditions);
_model->giveZeroFunc(eventIndicators);
for(int i = 0; i < ni; i++)
if(!conditions[i]) eventIndicators[i] = -eventIndicators[i];
return fmiOK;
}

// Funktions for reading the values of variables that have a reference by the modelDescription.xml
fmiStatus FMUWrapper::getReal(const fmiValueReference vr[], size_t nvr, fmiReal value[])
{
updateModel();
for(size_t i = 0; i < nvr; ++i)
_model->getReal(vr[i], value[i]);
return fmiOK;
updateModel();
for(size_t i = 0; i < nvr; ++i)
_model->getReal(vr[i], value[i]);
return fmiOK;
}

fmiStatus FMUWrapper::getInteger(const fmiValueReference vr[], size_t nvr, fmiInteger value[])
{
updateModel();
for(size_t i = 0; i < nvr; ++i)
_model->getInteger(vr[i], value[i]);
return fmiOK;
updateModel();
for(size_t i = 0; i < nvr; ++i)
_model->getInteger(vr[i], value[i]);
return fmiOK;
}

fmiStatus FMUWrapper::getBoolean(const fmiValueReference vr[], size_t nvr, fmiBoolean value[])
{
updateModel();
for(size_t i = 0; i < nvr; ++i)
_model->getBoolean(vr[i], (bool&) value[i]);
return fmiOK;
updateModel();
for(size_t i = 0; i < nvr; ++i)
_model->getBoolean(vr[i], (bool&) value[i]);
return fmiOK;
}

fmiStatus FMUWrapper::getString(const fmiValueReference vr[], size_t nvr, fmiString value[])
{
updateModel();
// for(size_t i = 0; i < nvr; ++i)
//TODO _model->getString(vr[i], value[i]);
return fmiOK;
updateModel();
// for(size_t i = 0; i < nvr; ++i)
//TODO _model->getString(vr[i], value[i]);
return fmiOK;
}


fmiStatus FMUWrapper::eventUpdate(fmiBoolean intermediateResults,
fmiEventInfo& eventInfo)
{
updateModel();
// Check if an Zero Crossings happend
double f[NUMBER_OF_EVENT_INDICATORS];
bool events[NUMBER_OF_EVENT_INDICATORS];
_model->giveZeroFunc(f);
for(int i=0; i<NUMBER_OF_EVENT_INDICATORS; i++)
events[i] = f[i] >= 0;
// Handle Zero Crossings if nessesary
_model->handleSystemEvents(events);
// everything is done
eventInfo.iterationConverged = fmiTrue;
eventInfo.stateValueReferencesChanged = fmiFalse; // will never change for open Modelica Models
eventInfo.stateValuesChanged = fmiTrue; // TODO
eventInfo.terminateSimulation = fmiFalse;
eventInfo.upcomingTimeEvent = fmiFalse;
//eventInfo.nextEventTime = _time;
return fmiOK;
fmiEventInfo& eventInfo)
{
updateModel();
// Check if an Zero Crossings happend
double f[NUMBER_OF_EVENT_INDICATORS];
bool events[NUMBER_OF_EVENT_INDICATORS];
_model->giveZeroFunc(f);
for(int i=0; i<NUMBER_OF_EVENT_INDICATORS; i++)
events[i] = f[i] >= 0;
// Handle Zero Crossings if nessesary
_model->handleSystemEvents(events);
// everything is done
eventInfo.iterationConverged = fmiTrue;
eventInfo.stateValueReferencesChanged = fmiFalse; // will never change for open Modelica Models
eventInfo.stateValuesChanged = fmiTrue; // TODO
eventInfo.terminateSimulation = fmiFalse;
eventInfo.upcomingTimeEvent = fmiFalse;
//eventInfo.nextEventTime = _time;
return fmiOK;
}

fmiStatus FMUWrapper::getNominalContinuousStates(fmiReal x_nominal[], size_t nx)
{
updateModel();
for(int i = 0; i < nx; ++i)
x_nominal[i] = 1.0;
return fmiOK;
updateModel();
for(int i = 0; i < nx; ++i)
x_nominal[i] = 1.0;
return fmiOK;
}

fmiStatus FMUWrapper::getStateValueReferences(fmiValueReference vrx[], size_t nx)
{
updateModel();
for(int i = 0; i < nx; i++)
vrx[i] = i;
return fmiOK;
updateModel();
for(int i = 0; i < nx; i++)
vrx[i] = i;
return fmiOK;
}

fmiStatus FMUWrapper::terminate()
{
return fmiOK;
return fmiOK;
}

fmiStatus FMUWrapper::setExternalFunction(fmiValueReference vr[], size_t nvr, const void* value[])
{
return fmiOK;
return fmiOK;
}

2 changes: 1 addition & 1 deletion SimulationRuntime/cpp/Include/FMU/IFMUInterface.h
Expand Up @@ -38,7 +38,7 @@ class IFMUInterface
{
public:
IFMUInterface(fmiString instanceName, fmiString GUID, fmiCallbackFunctions functions, fmiBoolean loggingOn) :
instanceName(instanceName), GUID(GUID), functions(functions) {};
instanceName(instanceName), GUID(GUID), functions(functions) {};
virtual ~IFMUInterface() {};
virtual fmiStatus setDebugLogging (fmiBoolean loggingOn) = 0;

Expand Down

0 comments on commit 10e9d84

Please sign in to comment.