Skip to content

Commit 8c7c1b2

Browse files
authored
display warnings when replacing SubModel (#1176)
1 parent b0abae4 commit 8c7c1b2

23 files changed

+1217
-59
lines changed

src/OMSimulatorLib/Component.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ namespace oms
8181
virtual oms_status_enu_t deleteStartValue(const ComRef& cref) { return oms_status_ok; }
8282
virtual std::vector<Values> getValuesResources() { return{}; }
8383
virtual oms_status_enu_t setValuesResources(std::vector<Values>& allResources) { return oms_status_ok; }
84-
virtual oms_status_enu_t updateOrDeleteStartValueInReplacedComponent() { return oms_status_ok; }
84+
virtual oms_status_enu_t updateOrDeleteStartValueInReplacedComponent(std::vector<std::string>& warningList) { return oms_status_ok; }
8585
virtual oms_status_enu_t exportToSSMTemplate(pugi::xml_node& ssmNode) { return logError_NotImplemented; }
8686
virtual oms_status_enu_t exportToSSVTemplate(pugi::xml_node& ssvNode, Snapshot& snapshot) { return logError_NotImplemented; }
8787
virtual oms_status_enu_t freeState() { return logError_NotImplemented; }

src/OMSimulatorLib/ComponentFMUCS.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1794,22 +1794,22 @@ std::vector<oms::Values> oms::ComponentFMUCS::getValuesResources()
17941794
return this->values.parameterResources;
17951795
}
17961796

1797-
oms_status_enu_t oms::ComponentFMUCS::updateOrDeleteStartValueInReplacedComponent()
1797+
oms_status_enu_t oms::ComponentFMUCS::updateOrDeleteStartValueInReplacedComponent(std::vector<std::string>& warningList)
17981798
{
17991799
// check for local resources available
18001800
if (values.hasResources())
18011801
{
1802-
return values.updateOrDeleteStartValueInReplacedComponent(values, this->getCref());
1802+
return values.updateOrDeleteStartValueInReplacedComponent(values, this->getCref(), warningList);
18031803
}
18041804
// check for resources in root
18051805
else if (getParentSystem() && getParentSystem()->getValues().hasResources())
18061806
{
1807-
return getParentSystem()->getValues().updateOrDeleteStartValueInReplacedComponent(values, this->getCref());
1807+
return getParentSystem()->getValues().updateOrDeleteStartValueInReplacedComponent(values, this->getCref(), warningList);
18081808
}
18091809
// check for resources in top level root
18101810
else if (getParentSystem()->getParentSystem() && getParentSystem()->getParentSystem()->getValues().hasResources())
18111811
{
1812-
return getParentSystem()->getParentSystem()->getValues().updateOrDeleteStartValueInReplacedComponent(values, this->getCref());
1812+
return getParentSystem()->getParentSystem()->getValues().updateOrDeleteStartValueInReplacedComponent(values, this->getCref(), warningList);
18131813
}
18141814
else
18151815
{

src/OMSimulatorLib/ComponentFMUCS.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ namespace oms
9595
oms_status_enu_t getDirectionalDerivativeHeper(const int unknownIndex, const int knownindex, const std::vector<int>& dependencyList, double& value);
9696

9797
oms_status_enu_t deleteStartValue(const ComRef& cref);
98-
oms_status_enu_t updateOrDeleteStartValueInReplacedComponent();
98+
oms_status_enu_t updateOrDeleteStartValueInReplacedComponent(std::vector<std::string>& warningList);
9999
oms_status_enu_t setValuesResources(std::vector<Values>& allValuesResources);
100100
std::vector<Values> getValuesResources();
101101

src/OMSimulatorLib/ComponentFMUME.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1576,22 +1576,22 @@ std::vector<oms::Values> oms::ComponentFMUME::getValuesResources()
15761576
return this->values.parameterResources;
15771577
}
15781578

1579-
oms_status_enu_t oms::ComponentFMUME::updateOrDeleteStartValueInReplacedComponent()
1579+
oms_status_enu_t oms::ComponentFMUME::updateOrDeleteStartValueInReplacedComponent(std::vector<std::string>& warningList)
15801580
{
15811581
// check for local resources available
15821582
if (values.hasResources())
15831583
{
1584-
return values.updateOrDeleteStartValueInReplacedComponent(values, this->getCref());
1584+
return values.updateOrDeleteStartValueInReplacedComponent(values, this->getCref(), warningList);
15851585
}
15861586
// check for resources in root
15871587
else if (getParentSystem() && getParentSystem()->getValues().hasResources())
15881588
{
1589-
return getParentSystem()->getValues().updateOrDeleteStartValueInReplacedComponent(values, this->getCref());
1589+
return getParentSystem()->getValues().updateOrDeleteStartValueInReplacedComponent(values, this->getCref(), warningList);
15901590
}
15911591
// check for resources in top level root
15921592
else if (getParentSystem()->getParentSystem() && getParentSystem()->getParentSystem()->getValues().hasResources())
15931593
{
1594-
return getParentSystem()->getParentSystem()->getValues().updateOrDeleteStartValueInReplacedComponent(values, this->getCref());
1594+
return getParentSystem()->getParentSystem()->getValues().updateOrDeleteStartValueInReplacedComponent(values, this->getCref(), warningList);
15951595
}
15961596
else
15971597
{

src/OMSimulatorLib/ComponentFMUME.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ namespace oms
9090
oms_status_enu_t getDirectionalDerivativeHeper(const int unknownIndex, const int knownIndex, const std::vector<int>& dependencyList, double& value);
9191

9292
oms_status_enu_t deleteStartValue(const ComRef& cref);
93-
oms_status_enu_t updateOrDeleteStartValueInReplacedComponent();
93+
oms_status_enu_t updateOrDeleteStartValueInReplacedComponent(std::vector<std::string>& warningList);
9494
oms_status_enu_t setValuesResources(std::vector<Values>& allValuesResources);
9595
std::vector<Values> getValuesResources();
9696

src/OMSimulatorLib/OMSimulator.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -916,7 +916,7 @@ oms_status_enu_t oms_addSubModel(const char* cref, const char* fmuPath)
916916
return system->addSubModel(tail, fmuPath);
917917
}
918918

919-
oms_status_enu_t oms_replaceSubModel(const char* cref, const char* fmuPath)
919+
oms_status_enu_t oms_replaceSubModel(const char* cref, const char* fmuPath, bool dryRun, int* warningCount)
920920
{
921921
oms::ComRef tail(cref);
922922
oms::ComRef front = tail.pop_front();
@@ -929,7 +929,7 @@ oms_status_enu_t oms_replaceSubModel(const char* cref, const char* fmuPath)
929929
if (!system)
930930
return logError_SystemNotInModel(model->getCref(), front);
931931

932-
return system->replaceSubModel(tail, fmuPath);
932+
return system->replaceSubModel(tail, fmuPath, dryRun, *warningCount);
933933
}
934934

935935
oms_status_enu_t oms_getComponentType(const char* cref, oms_component_enu_t* type)

src/OMSimulatorLib/OMSimulator.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ OMSAPI oms_status_enu_t OMSCALL oms_newResources(const char* cref);
130130
OMSAPI oms_status_enu_t OMSCALL oms_reduceSSV(const char* cref, const char* ssvfile, const char* ssmfile, const char* filepath);
131131
OMSAPI oms_status_enu_t OMSCALL oms_removeSignalsFromResults(const char* cref, const char* regex);
132132
OMSAPI oms_status_enu_t OMSCALL oms_rename(const char* cref, const char* newCref);
133-
OMSAPI oms_status_enu_t OMSCALL oms_replaceSubModel(const char* cref, const char* fmuPath);
133+
OMSAPI oms_status_enu_t OMSCALL oms_replaceSubModel(const char* cref, const char* fmuPath, bool dryRun, int* warningCount);
134134
OMSAPI oms_status_enu_t OMSCALL oms_reset(const char* cref);
135135
OMSAPI oms_status_enu_t OMSCALL oms_referenceResources(const char* cref, const char* ssmFile);
136136
OMSAPI oms_status_enu_t OMSCALL oms_RunFile(const char* filename);

src/OMSimulatorLib/System.cpp

Lines changed: 40 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -325,8 +325,20 @@ oms_status_enu_t oms::System::addSubModel(const oms::ComRef& cref, const std::st
325325
return system->addSubModel(tail, path);
326326
}
327327

328-
oms_status_enu_t oms::System::replaceSubModel(const oms::ComRef& cref, const std::string& path)
328+
oms_status_enu_t oms::System::replaceSubModel(const oms::ComRef& cref, const std::string& path, bool dryRun, int& warningCount)
329329
{
330+
/*
331+
take the snapshot of entire ssd before replacing,
332+
if (dryRun==true)
333+
showwarnings, reimport the snapshot and replacing is not done
334+
else
335+
show warnings and replace is done
336+
*/
337+
338+
// get full snapshot
339+
char* fullsnapshot = NULL;
340+
getModel().exportSnapshot("", &fullsnapshot);
341+
330342
if (cref.isValidIdent())
331343
{
332344
if (validCref(cref))
@@ -352,6 +364,8 @@ oms_status_enu_t oms::System::replaceSubModel(const oms::ComRef& cref, const std
352364
if (!replaceComponent)
353365
return oms_status_error;
354366

367+
std::vector<std::string> warningList;
368+
355369
auto component = components.find(cref);
356370
if (component != components.end())
357371
{
@@ -365,8 +379,8 @@ oms_status_enu_t oms::System::replaceSubModel(const oms::ComRef& cref, const std
365379
oms::ComRef headB(connection->getSignalA());
366380
oms::ComRef tailB = headB.pop_front();
367381
// check the replacing variable is a valid ScalarVariable
368-
bool signalA = isValidScalarVariable(component->second, replaceComponent, connection, cref, connection->getSignalA().front(), headA, path);
369-
bool signalB = isValidScalarVariable(component->second, replaceComponent, connection, cref, connection->getSignalB().front(), headB, path);
382+
bool signalA = isValidScalarVariable(component->second, replaceComponent, connection, cref, connection->getSignalA().front(), headA, path, warningList);
383+
bool signalB = isValidScalarVariable(component->second, replaceComponent, connection, cref, connection->getSignalB().front(), headB, path, warningList);
370384

371385
// delete the connection, due to scalarVariable mismatch in the replaced submodel
372386
if (signalA || signalB)
@@ -378,12 +392,23 @@ oms_status_enu_t oms::System::replaceSubModel(const oms::ComRef& cref, const std
378392
}
379393
}
380394
}
395+
381396
// copy all the resources from old component to replacing component
382397
std::vector<Values> allResources = component->second->getValuesResources();
383398
replaceComponent->setValuesResources(allResources);
384399

385400
// update or delete the start value in ssv of with the replaced component
386-
replaceComponent->updateOrDeleteStartValueInReplacedComponent();
401+
replaceComponent->updateOrDeleteStartValueInReplacedComponent(warningList);
402+
403+
// update the warning count
404+
warningCount = warningList.size();
405+
406+
if (dryRun)
407+
{
408+
char * newCref = NULL;
409+
getModel().importSnapshot(fullsnapshot, &newCref);
410+
return oms_status_ok;
411+
}
387412

388413
//delete component
389414
delete component->second;
@@ -405,25 +430,32 @@ oms_status_enu_t oms::System::replaceSubModel(const oms::ComRef& cref, const std
405430
* (e.g) ScalarVariable_A.type = ScalarVariable_B.type
406431
* ScalarVariable_A.causality = ScalarVariable_B.causality
407432
*/
408-
bool oms::System::isValidScalarVariable(Component* referenceComponent, Component* replacingComponent, Connection* connection, const ComRef& crefA, const ComRef& crefB, const ComRef& signalName, const std::string& path)
433+
bool oms::System::isValidScalarVariable(Component* referenceComponent, Component* replacingComponent, Connection* connection, const ComRef& crefA, const ComRef& crefB, const ComRef& signalName, const std::string& path, std::vector<std::string>& warningList)
409434
{
410435
if (crefA == crefB)
411436
{
412437
Variable *oldVar = referenceComponent->getVariable(signalName);
413438
Variable *replaceVar = replacingComponent->getVariable(signalName);
439+
std::string errorMsg="";
414440
if (!oldVar || !replaceVar)
415441
{
416-
logWarning("deleting connection \"" + std::string(connection->getSignalA()) + " ==> " + std::string(connection->getSignalB()) + "\"" + ", as signal \"" + std::string(signalName) + "\"" + " couldn't be resolved to any signal in the replaced submodel \"" + path + "\"");
442+
errorMsg = "deleting connection \"" + std::string(connection->getSignalA()) + " ==> " + std::string(connection->getSignalB()) + "\"" + ", as signal \"" + std::string(signalName) + "\"" + " couldn't be resolved to any signal in the replaced submodel \"" + path + "\"";
443+
logWarning(errorMsg);
444+
warningList.push_back(errorMsg);
417445
return true;
418446
}
419447
if (oldVar->getCausality() != replaceVar->getCausality())
420448
{
421-
logWarning("deleting connection \"" + std::string(connection->getSignalA()) + " ==> " + std::string(connection->getSignalB()) + "\"" + ", as signal \"" + std::string(signalName) + "\"" + " has causality mismatch in the replaced submodel \"" + path + "\"");
449+
errorMsg = "deleting connection \"" + std::string(connection->getSignalA()) + " ==> " + std::string(connection->getSignalB()) + "\"" + ", as signal \"" + std::string(signalName) + "\"" + " has causality mismatch in the replaced submodel \"" + path + "\"";
450+
logWarning(errorMsg);
451+
warningList.push_back(errorMsg);
422452
return true;
423453
}
424454
if (oldVar->getType() != replaceVar->getType())
425455
{
426-
logWarning("deleting connection \"" + std::string(connection->getSignalA()) + " ==> " + std::string(connection->getSignalB()) + "\"" + ", as signal \"" + std::string(signalName) + "\"" + " has type mismatch in the replaced submodel \"" + path + "\"");
456+
errorMsg = "deleting connection \"" + std::string(connection->getSignalA()) + " ==> " + std::string(connection->getSignalB()) + "\"" + ", as signal \"" + std::string(signalName) + "\"" + " has type mismatch in the replaced submodel \"" + path + "\"";
457+
logWarning(errorMsg);
458+
warningList.push_back(errorMsg);
427459
return true;
428460
}
429461
}

src/OMSimulatorLib/System.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,8 @@ namespace oms
9595
oms_system_enu_t getType() const {return type;}
9696
oms_status_enu_t addSubSystem(const ComRef& cref, oms_system_enu_t type);
9797
oms_status_enu_t addSubModel(const ComRef& cref, const std::string& fmuPath);
98-
oms_status_enu_t replaceSubModel(const ComRef& cref, const std::string& fmuPath);
99-
bool isValidScalarVariable(Component* referenceComponent, Component* replacingComponent, Connection* connection, const ComRef& crefA, const ComRef& crefB, const ComRef& signalName, const std::string& path);
98+
oms_status_enu_t replaceSubModel(const ComRef& cref, const std::string& fmuPath, bool dryRun, int& warningCount);
99+
bool isValidScalarVariable(Component* referenceComponent, Component* replacingComponent, Connection* connection, const ComRef& crefA, const ComRef& crefB, const ComRef& signalName, const std::string& path, std::vector<std::string>& warningList);
100100
bool validCref(const ComRef& cref);
101101
oms_status_enu_t exportToSSD(pugi::xml_node& node, Snapshot& snapshot) const;
102102
oms_status_enu_t exportToSSV(Snapshot& snapshot) const;

src/OMSimulatorLib/Values.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -632,7 +632,7 @@ oms_status_enu_t oms::Values::deleteStartValue(const ComRef& cref)
632632
return oms_status_error;
633633
}
634634

635-
oms_status_enu_t oms::Values::updateOrDeleteStartValueInReplacedComponent(Values& value, const ComRef& owner)
635+
oms_status_enu_t oms::Values::updateOrDeleteStartValueInReplacedComponent(Values& value, const ComRef& owner, std::vector<std::string>& warningList)
636636
{
637637
for (auto &it : parameterResources)
638638
{
@@ -656,6 +656,9 @@ oms_status_enu_t oms::Values::updateOrDeleteStartValueInReplacedComponent(Values
656656
{
657657
//res.second.realStartValues.erase(mappedCref->second); // NOTE: should we keep unreferenced signals in ssm and ssv when importing ?
658658
mappedCref = res.second.mappedEntry.erase(mappedCref);
659+
std::string errorMsg = "deleting start value \"" + std::string(owner + front) + "\"" + " in \"" + std::string(res.second.ssmFile) + "\"" + " resources, because the identifier couldn't be resolved to any system signal in the replacing model";
660+
logWarning(errorMsg);
661+
warningList.push_back(errorMsg);
659662
}
660663
}
661664
++ mappedCref;
@@ -695,6 +698,9 @@ oms_status_enu_t oms::Values::updateOrDeleteStartValueInReplacedComponent(Values
695698
{
696699
// if (res.second.ssmFile.empty()) should we keep the unreferenced signals in ssv which does not have any reference in ssm when importing?
697700
res.second.realStartValues.erase(name.first); // delete the start value as signal does not exist in replaced component
701+
std::string errorMsg = "deleting start value \"" + std::string(owner + front) + "\"" + " in \"" + std::string(res.first) + "\"" + " resources, because the identifier couldn't be resolved to any system signal in the replacing model";
702+
logWarning(errorMsg);
703+
warningList.push_back(errorMsg);
698704
}
699705
}
700706
}

0 commit comments

Comments
 (0)