Message Boards Message Boards

0
|
5349 Views
|
4 Replies
|
0 Total Likes
View groups...
Share
Share this post:

Programmatically set rotationType from Mathematica?

Posted 3 years ago

Dear Colleagues,

I am trying to figure out how to programmatically set, with Mathematica, the rotationType parameter in a Modelica.Mechanics.MultiBody.Parts.FixedRotation.

This is a snippet of my code where topMdlName is the name of the model, tNames4Modelica is a list of names of FixedRotation transforms in the model, and tCnt is the number of transforms.

Map[
  SetSystemModel[topMdlName, <|"ParameterValues" -> {StringJoin[tNames4Modelica[[#]], 
         ".rotationType"] ->"Modelica.Mechanics.MultiBody.Types.RotationTypes.PlanarRotationSequence"}|>] &,Range[tCnt]];

The function, obviously, writes strings to the model and the Simulation Center stops on an error that asserts that the value of the parameter is a string and not the expected enumeration.

I know that the value of the rotationType parameter is a Modelica enumeration as explained in the documentation

type RotationTypes = enumeration(RotationAxis "Rotating frame\_a around an angle with a fixed axis", TwoAxesVectors "Resolve two vectors of frame\_b in frame\_a", PlanarRotationSequence "Planar rotation sequence") "Enumeration defining in which way the fixed orientation of frame\_b with respect to frame_a is specified" annotation(Documentation(Evaluate = true, info = "<html>

but I cannot find a way to set it in Mathematica.

I have read the SetSystemModel help pages and searched the interwebs to no avail. So I am writing to ask for help either for a pointer to documentation or a workaround.

Thank you.

Bogdan

POSTED BY: Bogdan Udrea
4 Replies

I see, this is something that certainly works in the more recent versions, now that we have given more attention to other types of value setting like in enumerations. There are a couple of options. We could first try something like this that may have worked in 12.1,

<|"ParameterValues" -> {"transf.rotationType" -> WSMLink`Reference`ToDotName["Modelica.Mechanics.MultiBody.Types.RotationTypes.PlanarRotationSequence"]}|>

Try this association in either SetSystemModel or possibly in the ConnectSystemModelComponents call, which may have already been supported at the the time.

POSTED BY: Sergio Vargas
Posted 3 years ago

Thank you Sergio. The new method gives the same error

SystemModel::irl: The list of rules is not on the form {"variable" -> numericValue, ...}.

I'll email you about the bugs.

B

POSTED BY: Bogdan Udrea

A wrapper that allows the value setting functions to see a string as a component identifier is QuantityVariable. QuantityVariable, when representing a variable, has two arguments. For the first, we use the identifier string. Conventionally, the second argument is a physical quantity, but in this case you can use a generic IndependentPhysicalQuantity[""]. So your parameter can be added as

QuantityVariable["Modelica.Mechanics.MultiBody.Types.RotationTypes.PlanarRotationSequence", IndependentPhysicalQuantity[""]]

Sergio

POSTED BY: Sergio Vargas
Posted 3 years ago

Thank you Sergio but I cannot get your solution to work. Please see the Minimal Working Example (MWE)

comp = {"world" \[Element] "Modelica.Mechanics.MultiBody.World", 
   "transf" \[Element] "Modelica.Mechanics.MultiBody.Parts.FixedRotation", 
   "box" \[Element] "Modelica.Mechanics.MultiBody.Parts.BodyShape"};
conn = {"world.frame_b" \[DirectedEdge] "transf.frame_a", 
   "transf.frame_b" \[DirectedEdge] "box.frame_a"};

mdlName = "TestIt";
ConnectSystemModelComponents[mdlName, comp, conn]

SetSystemModel[
  mdlName, <|
   "ParameterValues" -> {"transf.rotationType" -> 
      QuantityVariable[
       "Modelica.Mechanics.MultiBody.Types.RotationTypes.
PlanarRotationSequence", IndependentPhysicalQuantity[""]]}|>];

This MWE gives the following error:

SystemModel::irl: The list of rules is not on the form {"variable" -> numericValue, ...}.

If my syntax is correct then there might be some unexpected behavior from SetSystemModel for enumeration types. I wonder if it's a bug that I should report.

To make progress on my project I have worked around the problem like so: after all model parameters are set: 1) assign the "Modelica.Mechanics.MultiBody.Types.RotationTypes. PlanarRotationSequence" string to all rotationType parameters, 2) extract the ModelicaString of the model; 3) find the string position of all rotationType; 4) remove the enclosing double quotes " and 5) save the ModelicaString to a text file of extension type .mo. It ain't pretty but it gets the job done.

If it's of any help I am using Matematica 12.1.0.0 and SystemModeler 12.2.0, build 8. I cannot update to Mathematica 12.2 because it has other bugs that crash other notebooks.

B

POSTED BY: Bogdan Udrea
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