1
$\begingroup$

I am trying to connect a set of SystemModels that I generated programmatically in Mathematica. I am interested in MultiBody models and I haven't tried other types of models. I am failing gloriously and I have spent a good part of the day reading the online help pages and performing a lot of trial and error. Here's a simplified example

First model called "model1"

comp1 = {"c11" \[Element] "Modelica.Mechanics.MultiBody.Parts.BodyShape", 
         "c12" \[Element] "Modelica.Mechanics.MultiBody.Parts.BodyShape"}
conn1 = {"c11.frame_b" \[DirectedEdge] "c12.frame_a"}
ConnectSystemModelComponents["model1", comp1, conn1, GraphLayout -> None]

Second model called "model2"

comp2 = {"c21" \[Element] "Modelica.Mechanics.MultiBody.Parts.BodyShape", 
         "c22" \[Element] "Modelica.Mechanics.MultiBody.Parts.BodyShape"}
conn2 = {"c21.frame_b" \[DirectedEdge] "c22.frame_a"}
ConnectSystemModelComponents["model2", comp2, conn2, GraphLayout -> None]

Model'o'models - failure

(*"Model" found by trial error. Is it needed, is it correct? At least Mathematica don't complain about it*)
compM = {"model1" \[Element] "Model", "model2" \[Element] "Model"}
connM = {"model1.c11.frame_a" \[DirectedEdge] "model2.c21.frame_a"}
ConnectSystemModelComponents["mdlOfMdls", compM, connM]

The error message is

ConnectSystemModelComponents::cnf: Connectors {model1.c11.frame_a,model2.c21.frame_a} are not 
one of the expected ones: {}.

I have also tried

connM = {"c11.frame_a" \[DirectedEdge] "c21.frame_a"}
ConnectSystemModelComponents["mdlOfMdls", compM, connM]

that gives a similar error message:

ConnectSystemModelComponents::cnf: Connectors {c11.frame_a,c21.frame_a} are not one of the expected ones: {}.

According to the Mathematica help page for ConnectSystemModelComponents[] at https://reference.wolfram.com/language/ref/ConnectSystemModelComponents.html

The compi can be a SystemModel object, a full model name string or a shortened model name accepted by SystemModel.

The error seems to come from the connectors of each model so the question is What type of connectors should I use?

Last but not least, I have also tried something a bit more sophisticated by introducing a MultoBody Interface component

comp1 = {"c11" \[Element] "Modelica.Mechanics.MultiBody.Parts.BodyShape", 
         "c12" \[Element] "Modelica.Mechanics.MultiBody.Parts.BodyShape", 
         "if1" \[Element] "Modelica.Mechanics.MultiBody.Interfaces.Frame_a"}
conn1 = {"c11.frame_a" \[DirectedEdge] "if1", 
  "c11.frame_b" \[DirectedEdge] "c12.frame_a"}
ConnectSystemModelComponents["model1", comp1, conn1]

comp2 = {"c21" \[Element] "Modelica.Mechanics.MultiBody.Parts.BodyShape", 
  "c22" \[Element] "Modelica.Mechanics.MultiBody.Parts.BodyShape", 
  "if2" \[Element] "Modelica.Mechanics.MultiBody.Interfaces.Frame_a"}
conn2 = {"c21.frame_a" \[DirectedEdge] "if2", 
  "c21.frame_b" \[DirectedEdge] "c22.frame_a"}
ConnectSystemModelComponents["model2", comp2, conn2]

compM = {"model1" \[Element] "Model", "model2" \[Element] "Model"}
connM = {"model1.if1" \[DirectedEdge] "model2.if2"}
ConnectSystemModelComponents["mdlOfMdls", compM, connM]

That gives the same type of error.

Thank you.

B

$\endgroup$

2 Answers 2

3
$\begingroup$

I posted the same question on the Wolfram forum. Neil Singer set me on the straight and narrow as seen in the link posted above by NCSNY. My mistake was improper instantiation of the models. This is how I solved it, following Neil's advice.

First model

comp1 = {"c11" \[Element] 
   "Modelica.Mechanics.MultiBody.Parts.BodyShape", 
  "c12" \[Element] "Modelica.Mechanics.MultiBody.Parts.BodyShape", 
  "if1" \[Element] "Modelica.Mechanics.MultiBody.Interfaces.Frame_a"}
conn1 = {"c11.frame_a" \[DirectedEdge] "if1", 
  "c11.frame_b" \[DirectedEdge] "c12.frame_a"}
ConnectSystemModelComponents["TestPack1.Model1", comp1, conn1]

Second model

comp2 = {"c21" \[Element] 
   "Modelica.Mechanics.MultiBody.Parts.BodyShape", 
  "c22" \[Element] "Modelica.Mechanics.MultiBody.Parts.BodyShape", 
  "if2" \[Element] "Modelica.Mechanics.MultiBody.Interfaces.Frame_a"}
conn2 = {"c21.frame_a" \[DirectedEdge] "if2", 
  "c21.frame_b" \[DirectedEdge] "c22.frame_a"}
ConnectSystemModelComponents["TestPack1.Model2", comp2, conn2]

And the model'o'models

compM = {"m1" \[Element] "TestPack1.Model1", 
         "m2" \[Element] "TestPack1.Model2"}
connM = {"m1.if1" \[DirectedEdge] "m2.if2"}
ConnectSystemModelComponents["TestPack1.mdlOfMdls", compM, connM]

Notice that the models are part of a package called TestPack1. Saving to file

Export[FileNameJoin[{NotebookDirectory[], "TestPack1.mo"}], "TestPack1", "MO"]

and opening with SystemModeler shows that the model and class structure are indeed the desired ones.

B

$\endgroup$
2
$\begingroup$

Resolution is with cross post here: https://community.wolfram.com/groups/-/m/t/2259002

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.