Message Boards Message Boards

0
|
2425 Views
|
2 Replies
|
3 Total Likes
View groups...
Share
Share this post:

Extracting information from a Modelica model with Mathematica.

Posted 1 year ago

Hello all,

I have a Modelica model that I have imported into Mathematica from SystemModeler, and I was able to get the list of its components and their types using

SystemModel[mdl]["Components"]

where mdl is the name of the model. The output is shown in this screenshot:

enter image description here

Is there a way to find out the names of the components of a particular type, and then be able to access the names and values of their variables? For example, I'd like to know the name of all the components of the type Modelica.Mechanics.MultiBody.Forces.Spring (e. g. spring1), and then access the value of its variables, like spring1.c for example.

I assume the Select command would do this, but more information on how use it would be highly appreciated.

Cheers,

Fabián

POSTED BY: Fabián Peña
2 Replies
Posted 1 year ago

Dear Sergio,

Thank you very much for your answer. Your advice is very useful.

Following your suggestions, I came up with the code below, which seems suitable for my application:

First, the components of a particular type are selected as you suggested:

(* Selects the components that are springs *)
type = "Modelica.Mechanics.MultiBody.Forces.Spring" ;
selectComps =  Select[SystemModel[mdl, "Components"], #[[-1, 1]] === type &] 

Then, the component's names of interest are appended with the variable names, (e. g. from spring1 to spring1.c):

springConstantNames = selectComps[[All, 1]]  (* For all elements, get the first sub-element *) 
springConstantNames = Map[StringJoin[#, ".c"] &,  springConstantNames] (* Append ".c" to each name *)

Finally, the simulation is carried out for zero seconds, and the numeric values of such variables are extracted:

(* Executes the simulation for zero seconds to retrieve the values of  the spring constants *)
springConstantValues =  SystemModelSimulate[mdl, All, 0][springConstantNames]

Thank you very much again.

Cheers,

Fabián

POSTED BY: Fabián Peña

POSTED BY: Sergio Vargas
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract