Skip to content

Commit 6c2bc65

Browse files
authored
add numeric type to connectors (#1573)
* set numeric type to component connectors * map numeric type to connectors in python api
1 parent 4e8169b commit 6c2bc65

15 files changed

Lines changed: 217 additions & 4 deletions

File tree

include/OMSimulator/OMSimulator.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ OMSAPI oms_status_enu_t OMSCALL oms_setCommandLineOption(const char* cmd);
138138
OMSAPI oms_status_enu_t OMSCALL oms_setConnectionGeometry(const char* crefA, const char* crefB, const ssd_connection_geometry_t* geometry);
139139
OMSAPI oms_status_enu_t OMSCALL oms_setConnectionLinearTransformation(const char* crefA, const char* crefB, double factor, double offset);
140140
OMSAPI oms_status_enu_t OMSCALL oms_setConnectorGeometry(const char* cref, const ssd_connector_geometry_t* geometry);
141+
OMSAPI oms_status_enu_t OMSCALL oms_setConnectorNumericType(const char* cref, const oms_signal_numeric_type_enu_t numericType);
141142
OMSAPI oms_status_enu_t OMSCALL oms_setElementGeometry(const char* cref, const ssd_element_geometry_t* geometry);
142143
OMSAPI oms_status_enu_t OMSCALL oms_setFixedStepSize(const char* cref, double stepSize);
143144
OMSAPI oms_status_enu_t OMSCALL oms_setInteger(const char* cref, int value);

include/OMSimulator/Types.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,8 @@ typedef enum {
125125
oms_signal_numeric_type_INT32, // Represents fmi3Int32
126126
oms_signal_numeric_type_UINT32, // Represents fmi3UInt32
127127
oms_signal_numeric_type_INT64, // Represents fmi3Int64
128-
oms_signal_numeric_type_UINT64 // Represents fmi3UInt64
128+
oms_signal_numeric_type_UINT64, // Represents fmi3UInt64
129+
oms_signal_numeric_type_none // Represents no numeric type (e.g., for non-numeric signals)
129130
} oms_signal_numeric_type_enu_t;
130131

131132
/**

src/OMSimulatorLib/ComponentFMU3CS.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,15 +249,27 @@ oms::Component* oms::ComponentFMU3CS::NewComponent(const oms::ComRef& cref, oms:
249249
int j = 1;
250250
int size = 1 + component->inputs.size();
251251
for (const auto& i : component->inputs)
252+
{
252253
component->connectors.push_back(new Connector(oms_causality_input, component->allVariables[i].getType(), component->allVariables[i].getCref(), component->getFullCref(), j++/(double)size));
254+
component->connectors.back()->setNumericType(component->allVariables[i].getNumericType());
255+
}
253256
j = 1;
254257
size = 1 + component->outputs.size();
255258
for (const auto& i : component->outputs)
259+
{
256260
component->connectors.push_back(new Connector(oms_causality_output, component->allVariables[i].getType(), component->allVariables[i].getCref(), component->getFullCref(), j++/(double)size));
261+
component->connectors.back()->setNumericType(component->allVariables[i].getNumericType());
262+
}
257263
for (const auto& i : component->parameters)
264+
{
258265
component->connectors.push_back(new Connector(oms_causality_parameter, component->allVariables[i].getType(), component->allVariables[i].getCref(), component->getFullCref()));
266+
component->connectors.back()->setNumericType(component->allVariables[i].getNumericType());
267+
}
259268
for (const auto& i : component->calculatedParameters)
269+
{
260270
component->connectors.push_back(new Connector(oms_causality_calculatedParameter, component->allVariables[i].getType(), component->allVariables[i].getCref(), component->getFullCref()));
271+
component->connectors.back()->setNumericType(component->allVariables[i].getNumericType());
272+
}
261273
component->connectors.push_back(NULL);
262274
component->element.setConnectors(&component->connectors[0]);
263275

src/OMSimulatorLib/ComponentFMU3ME.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,15 +247,27 @@ oms::Component* oms::ComponentFMU3ME::NewComponent(const oms::ComRef& cref, oms:
247247
int j = 1;
248248
int size = 1 + component->inputs.size();
249249
for (const auto& i : component->inputs)
250+
{
250251
component->connectors.push_back(new Connector(oms_causality_input, component->allVariables[i].getType(), component->allVariables[i].getCref(), component->getFullCref(), j++/(double)size));
252+
component->connectors.back()->setNumericType(component->allVariables[i].getNumericType());
253+
}
251254
j = 1;
252255
size = 1 + component->outputs.size();
253256
for (const auto& i : component->outputs)
257+
{
254258
component->connectors.push_back(new Connector(oms_causality_output, component->allVariables[i].getType(), component->allVariables[i].getCref(), component->getFullCref(), j++/(double)size));
259+
component->connectors.back()->setNumericType(component->allVariables[i].getNumericType());
260+
}
255261
for (const auto& i : component->parameters)
262+
{
256263
component->connectors.push_back(new Connector(oms_causality_parameter, component->allVariables[i].getType(), component->allVariables[i].getCref(), component->getFullCref()));
264+
component->connectors.back()->setNumericType(component->allVariables[i].getNumericType());
265+
}
257266
for (const auto& i : component->calculatedParameters)
267+
{
258268
component->connectors.push_back(new Connector(oms_causality_calculatedParameter, component->allVariables[i].getType(), component->allVariables[i].getCref(), component->getFullCref()));
269+
component->connectors.back()->setNumericType(component->allVariables[i].getNumericType());
270+
}
259271
component->connectors.push_back(NULL);
260272
component->element.setConnectors(&component->connectors[0]);
261273

src/OMSimulatorLib/Connector.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ namespace oms
7171
void setOwner(const oms::ComRef& owner);
7272
void setGeometry(const oms::ssd::ConnectorGeometry* newGeometry);
7373
oms_status_enu_t setExportName(const std::string & exportName) { this->exportName = exportName; return oms_status_ok;};
74+
oms_status_enu_t setNumericType(oms_signal_numeric_type_enu_t numericType) { this->numericType = numericType; return oms_status_ok; }
75+
oms_signal_numeric_type_enu_t getNumericType() const { return this->numericType; }
7476
std::string getExportName() const { return this->exportName; }
7577

7678
std::map<std::string, std::map<std::string, std::string>> connectorUnits; ///< single entry map which contains unit as key and BaseUnits as value for a connector
@@ -98,6 +100,7 @@ namespace oms
98100
friend bool operator==(const Connector& v1, const Connector& v2);
99101
friend bool operator!=(const Connector& v1, const Connector& v2);
100102
std::string exportName; ///< name to be used in result file
103+
oms_signal_numeric_type_enu_t numericType = oms_signal_numeric_type_none; ///< numeric type for the connector for FMI 3.0
101104
};
102105

103106
bool operator==(const Connector& v1, const Connector& v2);

src/OMSimulatorLib/OMSimulator.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -583,6 +583,23 @@ oms_status_enu_t oms_setConnectorGeometry(const char *cref, const ssd_connector_
583583
return system->setConnectorGeometry(tail, reinterpret_cast<const oms::ssd::ConnectorGeometry*>(geometry));
584584
}
585585

586+
oms_status_enu_t oms_setConnectorNumericType(const char *cref, const oms_signal_numeric_type_enu_t numericType)
587+
{
588+
oms::ComRef tail(cref);
589+
oms::ComRef modelCref = tail.pop_front();
590+
oms::ComRef systemCref = tail.pop_front();
591+
592+
oms::Model* model = oms::Scope::GetInstance().getModel(modelCref);
593+
if (!model)
594+
return logError_ModelNotInScope(modelCref);
595+
596+
oms::System* system = model->getSystem(systemCref);
597+
if (!system)
598+
return logError_SystemNotInModel(modelCref, systemCref);
599+
600+
return system->setConnectorNumericType(tail, numericType);
601+
}
602+
586603
oms_status_enu_t oms_setConnectionGeometry(const char *crefA, const char *crefB, const ssd_connection_geometry_t *geometry)
587604
{
588605
oms::ComRef tailA(crefA);

src/OMSimulatorLib/System.cpp

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1355,6 +1355,37 @@ oms_status_enu_t oms::System::setConnectorGeometry(const oms::ComRef& cref, cons
13551355
return logError("Connector " + std::string(cref) + " not found in system " + std::string(getCref()));
13561356
}
13571357

1358+
oms_status_enu_t oms::System::setConnectorNumericType(const oms::ComRef& cref, const oms_signal_numeric_type_enu_t numericType)
1359+
{
1360+
oms::ComRef tail(cref);
1361+
oms::ComRef head = tail.pop_front();
1362+
auto subsystem = subsystems.find(head);
1363+
if (subsystem != subsystems.end())
1364+
return subsystem->second->setConnectorNumericType(tail, numericType);
1365+
1366+
auto component = components.find(head);
1367+
if (component != components.end())
1368+
{
1369+
oms::Connector *connector = component->second->getConnector(tail);
1370+
if (connector)
1371+
{
1372+
connector->setNumericType(numericType);
1373+
return oms_status_ok;
1374+
}
1375+
else {
1376+
return logError("Connector " + std::string(tail) + " not found in component " + std::string(head));
1377+
}
1378+
}
1379+
1380+
oms::Connector* connector = this->getConnector(cref);
1381+
if (connector)
1382+
{
1383+
connector->setNumericType(numericType);
1384+
return oms_status_ok;
1385+
}
1386+
return logError("Connector " + std::string(cref) + " not found in system " + std::string(getCref()));
1387+
}
1388+
13581389
oms_status_enu_t oms::System::setConnectionGeometry(const oms::ComRef& crefA, const oms::ComRef& crefB, const oms::ssd::ConnectionGeometry *geometry)
13591390
{
13601391
oms::ComRef tailA(crefA);

src/OMSimulatorLib/System.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ namespace oms
106106
oms_status_enu_t deleteConnection(const ComRef& crefA, const ComRef& crefB);
107107
oms_status_enu_t setConnectorGeometry(const ComRef& cref, const oms::ssd::ConnectorGeometry* geometry);
108108
oms_status_enu_t setConnectionGeometry(const ComRef &crefA, const ComRef &crefB, const oms::ssd::ConnectionGeometry* geometry);
109+
oms_status_enu_t setConnectorNumericType(const ComRef& cref, const oms_signal_numeric_type_enu_t numericType);
109110
oms_status_enu_t setConnectionLinearTransformation(const oms::ComRef& crefA, const oms::ComRef& crefB, double factor, double offset);
110111
oms_status_enu_t addBus(const ComRef& cref);
111112
oms_status_enu_t newResources(const ComRef& cref, const std::string& ssvFilename, const std::string& ssmFilename = "", bool externalresources = false);

src/OMSimulatorLib/Variable.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,9 +167,11 @@ void oms::Variable::configureFMI3Variable(fmiHandle* fmi4c, int index_)
167167
break;
168168
case fmi3DataTypeBoolean:
169169
type = oms_signal_type_boolean;
170+
numericType = oms_signal_numeric_type_none;
170171
break;
171172
case fmi3DataTypeString:
172173
type = oms_signal_type_string;
174+
numericType = oms_signal_numeric_type_none;
173175
break;
174176
case fmi3DataTypeEnumeration:
175177
type = oms_signal_type_enum;

src/OMSimulatorPython/capi.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ class ssd_element_geometry_t(ctypes.Structure):
3838
("iconFlip", ctypes.c_bool),
3939
("iconFixedAspectRatio", ctypes.c_bool),
4040
]
41+
4142
class capi:
4243
def __init__(self):
4344
dirname = os.path.dirname(__file__)
@@ -105,6 +106,8 @@ def __init__(self):
105106
self.obj.oms_setConnectionGeometry.restype = ctypes.c_int
106107
self.obj.oms_setConnectorGeometry.argtypes = [ctypes.c_char_p, ctypes.POINTER(ssd_connector_geometry_t)]
107108
self.obj.oms_setConnectorGeometry.restype = ctypes.c_int
109+
self.obj.oms_setConnectorNumericType.argtypes = [ctypes.c_char_p, ctypes.c_int]
110+
self.obj.oms_setConnectorNumericType.restype = ctypes.c_int
108111
self.obj.oms_setElementGeometry.argtypes = [ctypes.c_char_p, ctypes.POINTER(ssd_element_geometry_t)]
109112
self.obj.oms_setElementGeometry.restype = ctypes.c_int
110113
self.obj.oms_setTempDirectory.argtypes = [ctypes.c_char_p]
@@ -259,6 +262,12 @@ def setConnectorGeometry(self, cref, x, y):
259262
status = self.obj.oms_setConnectorGeometry(cref.encode(), ctypes.byref(geometry))
260263
return Status(status)
261264

265+
def setConnectorNumericType(self, cref, numericType):
266+
'''Set the numeric type for a connector.
267+
This is used to specify the numeric type of the connector, which is important for FMI3 connectors that can have different numeric types (e.g., float32, float64, int32, int64).'''
268+
status = self.obj.oms_setConnectorNumericType(cref.encode(), numericType)
269+
return Status(status)
270+
262271
def setElementGeometry(self, cref, x1, y1, x2, y2, rotation=0.0, iconSource=b"", iconRotation=0.0, iconFlip=False, iconFixedAspectRatio=False):
263272
'''Set the element geometry for a model or system.
264273
The element geometry is defined by a bounding box (x1, y1, x2, y2) that defines the position and size of the element in the diagram, as well as optional rotation and icon information.'''

0 commit comments

Comments
 (0)