Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
edf094d
FMI2: Read unit of local values
Vaan5 Sep 21, 2022
0d36722
Add error log messages
Vaan5 Nov 7, 2022
6cf3233
Check the reference only once at the beginning
Vaan5 Nov 7, 2022
0f7fcf1
Define a typedef for the dimension type
Vaan5 Nov 9, 2022
c260ddc
Use McxStatus as return type of channel functions
Vaan5 Nov 9, 2022
d13a9a0
Remove obsolete return
Vaan5 Nov 16, 2022
fb7b2cd
Calculate for loop bounds outside
Vaan5 Nov 16, 2022
5f6ddf0
Indentation
Vaan5 Nov 16, 2022
aaae41d
Add log message
Vaan5 Nov 16, 2022
accab58
Remove rebase artifacts
Vaan5 Nov 16, 2022
5b8f138
Fix indexing formula
Vaan5 Nov 16, 2022
344f53f
channel: Inline ChannelInData (Performance!)
Nov 10, 2022
856f2b5
channel: Inline ChannelOutData (Performance!)
Oct 25, 2022
5085248
channel: Reduce redirections on in connections (Performance!)
Oct 25, 2022
4860551
channel: Reduce redirections of ValueReferences (Performance!)
Nov 10, 2022
192ebb1
channel: Reduce redirections of conversions (Performance!)
Oct 25, 2022
1f65e6c
channel: Reduce redirections of out connections (Performance!)
Oct 25, 2022
605e667
channel: Fix datatype of function argument
Oct 25, 2022
ef92ee2
connection: Inline FilteredConnectionData (Performance!)
Oct 25, 2022
fb198e0
FilteredConnection: Store single filter pointer directly (Performance!)
Oct 27, 2022
189ca7d
channel: Write message only in debug (Performance!)
Oct 28, 2022
5bc0728
Fmu2: Create separate SetVariable for Init (Performance!)
Nov 2, 2022
42d3a1a
channel: Skip unnecessary type checks (Performance!)
Oct 31, 2022
0619675
fmu2: Remove variable only needed for warnings/errors (Performance!)
Oct 31, 2022
4533d79
channel: Call IsFullyConnected only once (Performance!)
Oct 31, 2022
d4f8915
channel: Only calculate isFullyConnected on demand (Performance!)
Nov 2, 2022
3858ee9
channel: Fix Channel dimension index in calculation
Vaan5 Nov 18, 2022
abe6e21
Use %zu for size_t
klausschuch Mar 5, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/components/comp_fmu.c
Original file line number Diff line number Diff line change
Expand Up @@ -871,19 +871,19 @@ static McxStatus Fmu2Initialize(Component * comp, size_t group, double startTime
McxStatus retVal = RETURN_OK;

// Set variables
retVal = Fmu2SetVariableArray(fmu2, fmu2->params);
retVal = Fmu2SetVariableArrayInitialize(fmu2, fmu2->params);
if (RETURN_OK != retVal) {
ComponentLog(comp, LOG_ERROR, "Setting params failed");
return RETURN_ERROR;
}

retVal = Fmu2SetVariableArray(fmu2, fmu2->initialValues);
retVal = Fmu2SetVariableArrayInitialize(fmu2, fmu2->initialValues);
if (RETURN_OK != retVal) {
ComponentLog(comp, LOG_ERROR, "Setting initialValues failed");
return RETURN_ERROR;
}

retVal = Fmu2SetVariableArray(fmu2, fmu2->in);
retVal = Fmu2SetVariableArrayInitialize(fmu2, fmu2->in);
if (RETURN_OK != retVal) {
ComponentLog(comp, LOG_ERROR, "Setting inChannels failed");
return RETURN_ERROR;
Expand Down Expand Up @@ -916,13 +916,13 @@ static McxStatus Fmu2Initialize(Component * comp, size_t group, double startTime
}

// Set variables
retVal = Fmu2SetVariableArray(fmu2, fmu2->initialValues);
retVal = Fmu2SetVariableArrayInitialize(fmu2, fmu2->initialValues);
if (RETURN_OK != retVal) {
ComponentLog(comp, LOG_ERROR, "Setting initialValues failed");
return RETURN_ERROR;
}

retVal = Fmu2SetVariableArray(fmu2, fmu2->in);
retVal = Fmu2SetVariableArrayInitialize(fmu2, fmu2->in);
if (RETURN_OK != retVal) {
ComponentLog(comp, LOG_ERROR, "Setting inChannels failed");
return RETURN_ERROR;
Expand Down
30 changes: 13 additions & 17 deletions src/core/Component.c
Original file line number Diff line number Diff line change
Expand Up @@ -851,7 +851,7 @@ Vector * GetInConnectionInfos(const Component * comp, size_t channelID) {
return NULL;
}

ObjectContainer * GetInConnections(const Component * comp, size_t channelID) {
ConnectionList * GetInConnections(const Component * comp, size_t channelID) {
size_t channelNum = DatabusInfoGetChannelNum(DatabusGetInInfo(comp->data->databus));
if (channelID < channelNum) {
ChannelIn * in = DatabusGetInChannel(comp->data->databus, channelID);
Expand Down Expand Up @@ -972,11 +972,10 @@ static ObjectList * ComponentGetConnections(Component * fromComp, Component * to

for (i = 0; i < DatabusGetOutChannelsNum(db); i++) {
ChannelOut * out = DatabusGetOutChannel(db, i);
ObjectList * conns = out->GetConnections(out);
size_t connSize = conns->Size(conns);
ConnectionList * conns = out->GetConnections(out);

for (j = 0; j < connSize; j++) {
Connection * conn = (Connection *) conns->At(conns, j);
for (j = 0; j < conns->numConnections; j++) {
Connection * conn = conns->connections[j];
ConnectionInfo * info = conn->GetInfo(conn);

if (info->targetComponent == toComp) {
Expand Down Expand Up @@ -1014,11 +1013,10 @@ McxStatus ComponentOutConnectionsEnterInitMode(Component * comp) {

for (i = 0; i < numOutChannels; i++) {
ChannelOut * out = DatabusGetOutChannel(db, i);
ObjectList * conns = out->GetConnections(out);
size_t connSize = conns->Size(conns);
ConnectionList * conns = out->GetConnections(out);

for (j = 0; j < connSize; j++) {
Connection * connection = (Connection *) conns->At(conns, j);
for (j = 0; j < conns->numConnections; j++) {
Connection * connection = conns->connections[j];
retVal = connection->EnterInitializationMode(connection);
if (RETURN_OK != retVal) { // error message in calling function
return RETURN_ERROR;
Expand All @@ -1035,11 +1033,10 @@ McxStatus ComponentDoOutConnectionsInitialization(Component * comp, int onlyIfDe

for (i = 0; i < numOutChannels; i++) {
ChannelOut * out = DatabusGetOutChannel(db, i);
ObjectList * conns = out->GetConnections(out);
size_t connSize = conns->Size(conns);
ConnectionList * conns = out->GetConnections(out);

for (j = 0; j < connSize; j++) {
Connection * connection = (Connection *) conns->At(conns, j);
for (j = 0; j < conns->numConnections; j++) {
Connection * connection = conns->connections[j];

if (!onlyIfDecoupled || connection->IsDecoupled(connection)) {
McxStatus retVal = connection->UpdateInitialValue(connection);
Expand All @@ -1063,11 +1060,10 @@ McxStatus ComponentOutConnectionsExitInitMode(Component * comp, double time) {

for (i = 0; i < numOutChannels; i++) {
ChannelOut * out = DatabusGetOutChannel(db, i);
ObjectList * conns = out->GetConnections(out);
size_t connSize = conns->Size(conns);
ConnectionList * conns = out->GetConnections(out);

for (j = 0; j < connSize; j++) {
Connection * connection = (Connection *) conns->At(conns, j);
for (j = 0; j < conns->numConnections; j++) {
Connection * connection = conns->connections[j];
retVal = connection->ExitInitializationMode(connection, time);
if (RETURN_OK != retVal) { // error message in calling function
return RETURN_ERROR;
Expand Down
2 changes: 1 addition & 1 deletion src/core/Component.h
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ McxStatus ComponentEnterCommunicationPoint(Component * comp, TimeInterval * time
McxStatus ComponentEnterCommunicationPointForConnections(Component * comp, ObjectList * connections, TimeInterval * time);

Vector * GetInConnectionInfos(const Component * comp, size_t channelID);
struct ObjectContainer * GetInConnections(const Component * comp, size_t channelID);
struct ConnectionList * GetInConnections(const Component * comp, size_t channelID);

size_t ComponentGetNumOutGroups(const Component * comp);
size_t ComponentGetNumInitialOutGroups(const Component * comp);
Expand Down
15 changes: 7 additions & 8 deletions src/core/Conversion.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,23 +99,22 @@ McxStatus RangeConversionMinValueRefConversion(void * element, size_t idx, Chann
ChannelValue * min = (ChannelValue *) ctx;
void * minElem = mcx_array_get_elem_reference(&min->value.a, idx);
if (RangeConversionElemwiseLeq(element, minElem, type)) {
switch (type->con)
{
switch (type->con) {
case CHANNEL_DOUBLE:
{
double * elem = (double *) element;
*elem = *((double *)minElem);
*elem = *((double *) minElem);
break;
}
case CHANNEL_INTEGER:
case CHANNEL_INTEGER:
{
int * elem = (int *) element;
*elem = *((int *)minElem);
*elem = *((int *) minElem);
break;
}
default:
mcx_log(LOG_ERROR, "RangeConversion: Unsupported type");
return RETURN_ERROR;
default:
mcx_log(LOG_ERROR, "RangeConversion: Unsupported type");
return RETURN_ERROR;
}
}

Expand Down
10 changes: 5 additions & 5 deletions src/core/Databus.c
Original file line number Diff line number Diff line change
Expand Up @@ -1303,8 +1303,8 @@ McxStatus DatabusCollectModeSwitchData(Databus * db) {
// determine cache size
for (i = 0; i < size; i++) {
ChannelOut * out = db->data->out[i];
ObjectList * conns = out->GetConnections(out);
db->modeSwitchDataSize += conns->Size(conns);
ConnectionList * conns = out->GetConnections(out);
db->modeSwitchDataSize += conns->numConnections;
}

// allocate cache
Expand All @@ -1316,11 +1316,11 @@ McxStatus DatabusCollectModeSwitchData(Databus * db) {
// fill up the cache
for (i = 0, idx = 0; i < size; i++) {
ChannelOut * out = db->data->out[i];
ObjectList * conns = out->GetConnections(out);
size_t connSize = conns->Size(conns);
ConnectionList * conns = out->GetConnections(out);
size_t connSize = conns->numConnections;

for (j = 0; j < connSize; j++, idx++) {
Connection * connection = (Connection*)conns->At(conns, j);
Connection * connection = conns->connections[j];
ConnectionInfo * info = connection->GetInfo(connection);
Component * target = info->targetComponent;
Component * source = info->sourceComponent;
Expand Down
44 changes: 38 additions & 6 deletions src/core/Model.c
Original file line number Diff line number Diff line change
Expand Up @@ -447,10 +447,10 @@ static McxStatus ModelInsertAllFilters(Model * model) {

for (j = 0; j < numOutChannels; j++) {
ChannelOut * out = DatabusGetOutChannel(db, j);
ObjectList * conns = out->GetConnections(out);
ConnectionList * conns = out->GetConnections(out);

for (k = 0; k < conns->Size(conns); k++) {
Connection * connection = (Connection *) conns->At(conns, k);
for (k = 0; k < conns->numConnections; k++) {
Connection * connection = conns->connections[k];
ConnectionInfo * info = connection->GetInfo(connection);
if (connection->AddFilter) {
char * connStr = ConnectionInfoConnectionString(info);
Expand Down Expand Up @@ -700,10 +700,10 @@ static Connection * ModelGetConnectionFromInfo(Model * model, ConnectionInfo * i

for (j = 0; j < numOutChannels; j++) {
ChannelOut * out = DatabusGetOutChannel(db, j);
ObjectList * conns = out->GetConnections(out);
ConnectionList * conns = out->GetConnections(out);

for (k = 0; k < conns->Size(conns); k++) {
Connection * connection = (Connection *) conns->At(conns, k);
for (k = 0; k < conns->numConnections; k++) {
Connection * connection = conns->connections[k];
if (connection->GetInfo(connection) == info) {
return connection;
}
Expand Down Expand Up @@ -1263,6 +1263,38 @@ static McxStatus ModelSetup(void * self) {
}
mcx_log(LOG_DEBUG, " ");

// Set isFullyConnected status on all channels
size_t i = 0;
size_t j = 0;
Component * comp = NULL;
Databus * db = NULL;
size_t inNum = 0;
size_t outNum = 0;
Channel * channel = NULL;
ObjectContainer * comps = model->components;
for (i = 0; i < comps->Size(comps); i++) {
comp = (Component *)comps->At(comps, i);
db = comp->GetDatabus(comp);
inNum = DatabusGetInChannelsNum(db);
for (j = 0; j < inNum; j++) {
channel = (Channel *) DatabusGetInChannel(db, j);
retVal = channel->SetIsFullyConnected(channel);
if (RETURN_OK != retVal) {
mcx_log(LOG_ERROR, "Model: Setting IsFullyConnected state for input %s failed", channel->info.name);
return RETURN_ERROR;
}
}
outNum = DatabusGetOutChannelsNum(db);
for (j = 0; j < outNum; j++) {
channel = (Channel *) DatabusGetOutChannel(db, j);
retVal = channel->SetIsFullyConnected(channel);
if (RETURN_OK != retVal) {
mcx_log(LOG_ERROR, "Model: Setting IsFullyConnected state for output %s failed", channel->info.name);
return RETURN_ERROR;
}
}
}

if (model->config->outputModel) {
retVal = ModelPrint(model);
if (RETURN_OK != retVal) {
Expand Down
4 changes: 2 additions & 2 deletions src/core/SubModel.c
Original file line number Diff line number Diff line change
Expand Up @@ -716,12 +716,12 @@ static struct Dependencies * SubModelGeneratorCreateDependencyMatrix(SubModelGen

if (DEP_INDEPENDENT != dependency) {
Vector * infos = GetInConnectionInfos(targetComp, targetInChannelID);
ObjectContainer * conns = GetInConnections(targetComp, targetInChannelID);
ConnectionList * conns = GetInConnections(targetComp, targetInChannelID);
size_t i = 0;

for (i = 0; i < infos->Size(infos); i++) {
ConnectionInfo * info = *(ConnectionInfo**) infos->At(infos, i);
Connection * conn = conns->At(conns, i);
Connection * conn = conns->connections[i];

if (info && (info->decoupleType & (DECOUPLE_NEVER | DECOUPLE_IFNEEDED)) && (!ConnectionInfoIsDecoupled(info)) &&
conn && conn->IsActiveDependency(conn))
Expand Down
Loading
Loading