Avoid error "Hold[Throw[$Failed]]" while using ConnectSystemModelComponents

I am just starting to experiment with the system modeling capability in Mathematica.

This very simple model gives this for the result “Hold[Throw[$Failed]]”

components = 
  {
   "S" \[Element] 
    "Modelica.Thermal.HeatTransfer.Sources.FixedHeatFlow",
   "R1" \[Element] 
    "Modelica.Thermal.HeatTransfer.Components.ThermalResistor",
   "T" \[Element] 
    "Modelica.Thermal.HeatTransfer.Sources.FixedTemperature"};
connections = {"S.b" \[UndirectedEdge] "R1.a", 
  "R1.b" \[UndirectedEdge] "R2.a", "R2.b" \[UndirectedEdge] "T.b"};
model = ConnectSystemModelComponents[components, connections]

What am I doing wrong?

Jeff,

Two things are wrong:

  1. you forgot a component (you use R2 but don’t specify it)

     components = {"S" \[Element] 
         "Modelica.Thermal.HeatTransfer.Sources.FixedHeatFlow", 
        "R1" \[Element] 
         "Modelica.Thermal.HeatTransfer.Components.ThermalResistor", 
        "R2" \[Element] 
         "Modelica.Thermal.HeatTransfer.Components.ThermalResistor", 
        "T" \[Element] 
         "Modelica.Thermal.HeatTransfer.Sources.FixedTemperature"};
    

and 2. You got the port names wrong for the heat components:

    connections = {"S.port" \[UndirectedEdge] "R1.port_a", 
       "R1.port_b" \[UndirectedEdge] "R2.port_a", 
       "R2.port_b" \[UndirectedEdge] "T.port"};

Now it works (although your model has 2 sources connected with resistors so it does not do anything interesting – I assume you were just trying to get a simple example to work)

The error message is not at all helpful so I will report it to Wolfram in Sweden so they can fix it.

I found the best way to get started is to go into SystemModeler (WSM) and view the components there – even create a basic model and then change/update/recreate it in MMA once you have the component names and ports correct. You can also build a simple model in WSM and do this in MMA to get the correct syntax (essentially reversing your process):

model = SystemModel["Model1"]
comp = foo["Components"]
conn = foo["Connections"]

This will give you the strings you need for the component names (or just hover your mouse over the output objects)

comp //InputForm

Regards,

Neil

@Ankit Naik

the error message makes no sense. Also, this post should be added to the SystemModeler group

Regards

Thanks! This helps.

Hi Neil and @Jeff Burns ,

Thanks for your feedback,

I have filed a bug to add more information to the error message.
The post has been added to the SystemModeler group.

Regards,
Ankit