Skip to content

Commit

Permalink
Read fmu kind properly (#979)
Browse files Browse the repository at this point in the history
  • Loading branch information
lochel authored Mar 8, 2021
1 parent 58368ea commit 8083559
Show file tree
Hide file tree
Showing 17 changed files with 261 additions and 274 deletions.
6 changes: 3 additions & 3 deletions src/OMSimulatorLib/Component.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,9 @@ oms::ComRef oms::Component::getFullCref() const
return parentSystem->getFullCref() + cref;
}

oms::Model* oms::Component::getModel() const
oms::Model& oms::Component::getModel() const
{
return parentSystem ? parentSystem->getModel() : NULL;
return parentSystem->getModel();
}

oms_status_enu_t oms::Component::addTLMBus(const oms::ComRef &cref, oms_tlm_domain_t domain, const int dimensions, const oms_tlm_interpolation_t interpolation)
Expand Down Expand Up @@ -206,7 +206,7 @@ oms_status_enu_t oms::Component::deleteConnector(const ComRef& cref)
if (connectors[i] && connectors[i]->getName() == cref)
{
// delete startValues associated with components connector
Component * component = parentSystem->getComponent(getCref());
Component* component = parentSystem->getComponent(getCref());
if (Flags::ExportParametersInline())
{
// delete startValues associated with the Connector
Expand Down
2 changes: 1 addition & 1 deletion src/OMSimulatorLib/Component.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ namespace oms
virtual const FMUInfo* getFMUInfo() const {return NULL;}
void fetchAllVars(bool enableOption) {fetchAllVars_ = enableOption;}
System* getParentSystem() const {return parentSystem;}
Model* getModel() const;
Model& getModel() const;
void setGeometry(const ssd::ElementGeometry& geometry) {element.setGeometry(&geometry);}
virtual oms_status_enu_t setFaultInjection(const ComRef& signal, oms_fault_type_enu_t faultType, double faultValue) {return oms_status_error;}

Expand Down
33 changes: 14 additions & 19 deletions src/OMSimulatorLib/ComponentFMUCS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
#include <RegEx.h>

oms::ComponentFMUCS::ComponentFMUCS(const ComRef& cref, System* parentSystem, const std::string& fmuPath)
: oms::Component(cref, oms_component_fmu, parentSystem, fmuPath), fmuInfo(fmuPath, oms_fmi_kind_cs)
: oms::Component(cref, oms_component_fmu, parentSystem, fmuPath), fmuInfo(fmuPath)
{
}

Expand All @@ -71,7 +71,7 @@ oms::Component* oms::ComponentFMUCS::NewComponent(const oms::ComRef& cref, oms::
return NULL;
}

filesystem::path temp_root(parentSystem->getModel()->getTempDirectory());
filesystem::path temp_root(parentSystem->getModel().getTempDirectory());
filesystem::path temp_temp = temp_root / "temp";
filesystem::path relFMUPath = parentSystem->copyResources() ? (filesystem::path("resources") / (parentSystem->getUniqueID() + "_" + std::string(cref) + ".fmu")) : filesystem::path(fmuPath);
filesystem::path absFMUPath = temp_root / relFMUPath;
Expand Down Expand Up @@ -129,12 +129,7 @@ oms::Component* oms::ComponentFMUCS::NewComponent(const oms::ComRef& cref, oms::
}

// update FMU info
if (oms_status_ok != component->fmuInfo.update(version, component->fmu))
{
logError("Error importing FMU attributes");
delete component;
return NULL;
}
component->fmuInfo.update(version, component->fmu);

component->callbackFunctions.logger = oms::fmi2logger;
component->callbackFunctions.allocateMemory = calloc;
Expand Down Expand Up @@ -296,7 +291,7 @@ oms::Component* oms::ComponentFMUCS::NewComponent(const pugi::xml_node& node, om
else if(name == oms::ssp::Version1_0::ssd::parameter_bindings)
{
// set parameter bindings associated with the component
std::string tempdir = parentSystem->getModel()->getTempDirectory();
std::string tempdir = parentSystem->getModel().getTempDirectory();
component->values.importFromSnapshot(*it, sspVersion, snapshot);
}
else
Expand Down Expand Up @@ -542,7 +537,7 @@ oms_status_enu_t oms::ComponentFMUCS::instantiate()
}

// enterInitialization
time = getModel()->getStartTime();
time = getModel().getStartTime();
double relativeTolerance = 0.0;
dynamic_cast<SystemWC*>(getParentSystem())->getTolerance(NULL, &relativeTolerance);
fmistatus = fmi2_import_setup_experiment(fmu, fmi2_true, relativeTolerance, time, fmi2_false, 1.0);
Expand Down Expand Up @@ -605,7 +600,7 @@ oms_status_enu_t oms::ComponentFMUCS::reset()
return logError_ResetFailed(getCref());

// enterInitialization
time = getModel()->getStartTime();
time = getModel().getStartTime();
double relativeTolerance = 0.0;
dynamic_cast<SystemWC*>(getParentSystem())->getTolerance(NULL, &relativeTolerance);
fmistatus = fmi2_import_setup_experiment(fmu, fmi2_true, relativeTolerance, time, fmi2_false, 1.0);
Expand All @@ -620,7 +615,7 @@ oms_status_enu_t oms::ComponentFMUCS::reset()
oms_status_enu_t oms::ComponentFMUCS::stepUntil(double stopTime)
{
CallClock callClock(clock);
System *topLevelSystem = getModel()->getTopLevelSystem();
System *topLevelSystem = getModel().getTopLevelSystem();

fmi2_status_t fmistatus;
double hdef = (stopTime-time) / 1.0;
Expand Down Expand Up @@ -676,7 +671,7 @@ oms_status_enu_t oms::ComponentFMUCS::getBoolean(const ComRef& cref, bool& value
{
CallClock callClock(clock);

if (oms_modelState_virgin == getModel()->getModelState())
if (oms_modelState_virgin == getModel().getModelState())
{
// check for start values exist, priority over modeldescription.xml start values
auto booleanValue = values.booleanStartValues.find(cref);
Expand Down Expand Up @@ -729,7 +724,7 @@ oms_status_enu_t oms::ComponentFMUCS::getInteger(const ComRef& cref, int& value)
{
CallClock callClock(clock);

if (oms_modelState_virgin == getModel()->getModelState())
if (oms_modelState_virgin == getModel().getModelState())
{
// check for start values exist, priority over modeldescription.xml start values
auto integerValue = values.integerStartValues.find(cref);
Expand Down Expand Up @@ -821,7 +816,7 @@ oms_status_enu_t oms::ComponentFMUCS::getReal(const ComRef& cref, double& value)
{
CallClock callClock(clock);

if (oms_modelState_virgin == getModel()->getModelState())
if (oms_modelState_virgin == getModel().getModelState())
{
// check for start values exist, priority over modeldescription.xml start values
auto realValue = values.realStartValues.find(cref);
Expand Down Expand Up @@ -926,7 +921,7 @@ oms_status_enu_t oms::ComponentFMUCS::setBoolean(const ComRef& cref, bool value)
if (!fmu || j < 0)
return logError_UnknownSignal(getFullCref() + cref);

if (oms_modelState_virgin == getModel()->getModelState())
if (oms_modelState_virgin == getModel().getModelState())
{
if (Flags::ExportParametersInline())
{
Expand Down Expand Up @@ -965,7 +960,7 @@ oms_status_enu_t oms::ComponentFMUCS::setInteger(const ComRef& cref, int value)
if (!fmu || j < 0)
return logError_UnknownSignal(getFullCref() + cref);

if (oms_modelState_virgin == getModel()->getModelState())
if (oms_modelState_virgin == getModel().getModelState())
{
if (Flags::ExportParametersInline())
{
Expand Down Expand Up @@ -1003,11 +998,11 @@ oms_status_enu_t oms::ComponentFMUCS::setReal(const ComRef& cref, double value)
if (!fmu || j < 0)
return logError_UnknownSignal(getFullCref() + cref);

if (getModel()->validState(oms_modelState_virgin|oms_modelState_enterInstantiation|oms_modelState_instantiated))
if (getModel().validState(oms_modelState_virgin|oms_modelState_enterInstantiation|oms_modelState_instantiated))
if (allVariables[j].isCalculated() || allVariables[j].isIndependent())
return logWarning("It is not allowed to provide a start value if initial=\"calculated\" or causality=\"independent\".");

if (oms_modelState_virgin == getModel()->getModelState())
if (oms_modelState_virgin == getModel().getModelState())
{
if (Flags::ExportParametersInline())
{
Expand Down
31 changes: 13 additions & 18 deletions src/OMSimulatorLib/ComponentFMUME.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
#include <RegEx.h>

oms::ComponentFMUME::ComponentFMUME(const ComRef& cref, System* parentSystem, const std::string& fmuPath)
: oms::Component(cref, oms_component_fmu, parentSystem, fmuPath), fmuInfo(fmuPath, oms_fmi_kind_me)
: oms::Component(cref, oms_component_fmu, parentSystem, fmuPath), fmuInfo(fmuPath)
{
}

Expand All @@ -70,7 +70,7 @@ oms::Component* oms::ComponentFMUME::NewComponent(const oms::ComRef& cref, oms::
return NULL;
}

filesystem::path temp_root(parentSystem->getModel()->getTempDirectory());
filesystem::path temp_root(parentSystem->getModel().getTempDirectory());
filesystem::path temp_temp = temp_root / "temp";
filesystem::path relFMUPath = parentSystem->copyResources() ? (filesystem::path("resources") / (parentSystem->getUniqueID() + "_" + std::string(cref) + ".fmu")) : filesystem::path(fmuPath);
filesystem::path absFMUPath = temp_root / relFMUPath;
Expand Down Expand Up @@ -128,12 +128,7 @@ oms::Component* oms::ComponentFMUME::NewComponent(const oms::ComRef& cref, oms::
}

// update FMU info
if (oms_status_ok != component->fmuInfo.update(version, component->fmu))
{
logError("Error importing FMU attributes");
delete component;
return NULL;
}
component->fmuInfo.update(version, component->fmu);

component->callbackFunctions.logger = oms::fmi2logger;
component->callbackFunctions.allocateMemory = calloc;
Expand Down Expand Up @@ -298,7 +293,7 @@ oms::Component* oms::ComponentFMUME::NewComponent(const pugi::xml_node& node, om
else if(name == oms::ssp::Version1_0::ssd::parameter_bindings)
{
// set parameter bindings associated with the component
std::string tempdir = parentSystem->getModel()->getTempDirectory();
std::string tempdir = parentSystem->getModel().getTempDirectory();
component->values.importFromSnapshot(*it, sspVersion, snapshot);
}
else
Expand Down Expand Up @@ -543,7 +538,7 @@ oms_status_enu_t oms::ComponentFMUME::instantiate()
}

// enterInitialization
const double& startTime = getParentSystem()->getModel()->getStartTime();
const double& startTime = getModel().getStartTime();
double relativeTolerance = 0.0;
dynamic_cast<SystemSC*>(getParentSystem())->getTolerance(NULL, &relativeTolerance);
fmistatus = fmi2_import_setup_experiment(fmu, fmi2_true, relativeTolerance, startTime, fmi2_false, 1.0);
Expand Down Expand Up @@ -637,7 +632,7 @@ oms_status_enu_t oms::ComponentFMUME::reset()
return logError_ResetFailed(getCref());

// enterInitialization
const double& startTime = getParentSystem()->getModel()->getStartTime();
const double& startTime = getModel().getStartTime();
double relativeTolerance = 0.0;
dynamic_cast<SystemSC*>(getParentSystem())->getTolerance(NULL, &relativeTolerance);
fmistatus = fmi2_import_setup_experiment(fmu, fmi2_true, relativeTolerance, startTime, fmi2_false, 1.0);
Expand Down Expand Up @@ -672,7 +667,7 @@ oms_status_enu_t oms::ComponentFMUME::getBoolean(const ComRef& cref, bool& value
{
CallClock callClock(clock);

if (oms_modelState_virgin == getModel()->getModelState())
if (oms_modelState_virgin == getModel().getModelState())
{
// check for start values exist, priority over modeldescription.xml start values
auto booleanValue = values.booleanStartValues.find(cref);
Expand Down Expand Up @@ -725,7 +720,7 @@ oms_status_enu_t oms::ComponentFMUME::getInteger(const ComRef& cref, int& value)
{
CallClock callClock(clock);

if (oms_modelState_virgin == getModel()->getModelState())
if (oms_modelState_virgin == getModel().getModelState())
{
// check for start values exist, priority over modeldescription.xml start values
auto integerValue = values.integerStartValues.find(cref);
Expand Down Expand Up @@ -817,7 +812,7 @@ oms_status_enu_t oms::ComponentFMUME::getReal(const ComRef& cref, double& value)
{
CallClock callClock(clock);

if (oms_modelState_virgin == getModel()->getModelState())
if (oms_modelState_virgin == getModel().getModelState())
{
// check for start values exist, priority over modeldescription.xml start values
auto realValue = values.realStartValues.find(cref);
Expand Down Expand Up @@ -872,7 +867,7 @@ oms_status_enu_t oms::ComponentFMUME::setBoolean(const ComRef& cref, bool value)
if (!fmu || j < 0)
return logError_UnknownSignal(getFullCref() + cref);

if (oms_modelState_virgin == getModel()->getModelState())
if (oms_modelState_virgin == getModel().getModelState())
{
if (Flags::ExportParametersInline())
{
Expand Down Expand Up @@ -911,7 +906,7 @@ oms_status_enu_t oms::ComponentFMUME::setInteger(const ComRef& cref, int value)
if (!fmu || j < 0)
return logError_UnknownSignal(getFullCref() + cref);

if (oms_modelState_virgin == getModel()->getModelState())
if (oms_modelState_virgin == getModel().getModelState())
{
if (Flags::ExportParametersInline())
{
Expand Down Expand Up @@ -954,11 +949,11 @@ oms_status_enu_t oms::ComponentFMUME::setReal(const ComRef& cref, double value)
if (!fmu || j < 0)
return logError_UnknownSignal(getFullCref() + cref);

if (getModel()->validState(oms_modelState_virgin|oms_modelState_enterInstantiation|oms_modelState_instantiated))
if (getModel().validState(oms_modelState_virgin|oms_modelState_enterInstantiation|oms_modelState_instantiated))
if (allVariables[j].isCalculated() || allVariables[j].isIndependent())
return logWarning("It is not allowed to provide a start value if initial=\"calculated\" or causality=\"independent\".");

if (oms_modelState_virgin == getModel()->getModelState())
if (oms_modelState_virgin == getModel().getModelState())
{
if (Flags::ExportParametersInline())
{
Expand Down
6 changes: 3 additions & 3 deletions src/OMSimulatorLib/ComponentTable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ oms::Component* oms::ComponentTable::NewComponent(const oms::ComRef& cref, oms::
if (path.length() > 4)
extension = path.substr(path.length() - 4);

filesystem::path temp_root(parentSystem->getModel()->getTempDirectory());
filesystem::path temp_root(parentSystem->getModel().getTempDirectory());
filesystem::path relPath = parentSystem->copyResources() ? (filesystem::path("resources") / (parentSystem->getUniqueID() + "_" + std::string(cref) + extension)) : filesystem::path(path);
filesystem::path absPath = temp_root / relPath;

Expand Down Expand Up @@ -180,13 +180,13 @@ oms_status_enu_t oms::ComponentTable::exportToSSD(pugi::xml_node& node, pugi::xm

oms_status_enu_t oms::ComponentTable::instantiate()
{
time = getModel()->getStartTime();
time = getModel().getStartTime();
return oms_status_ok;
}

oms_status_enu_t oms::ComponentTable::reset()
{
time = getModel()->getStartTime();
time = getModel().getStartTime();
return oms_status_ok;
}

Expand Down
Loading

0 comments on commit 8083559

Please sign in to comment.