4

I am trying to assign values to some model parameters using WSMSetValues function, however, it seems to be working only with values greater than 10^-4. Is this normal behavior or I am doing something wrong? Of course, I could manually type in these values in Model Center and it would work fine, but I wish to do this programmatically. Here is an example:

Needs["WSMLink`"];
param = {"TT1.C2" -> 1. 10^-7, "TT1.C1" -> 1. 10^-7, 
"TT1.R6" -> 10000., "TT1.R5" -> 10000., "TT1.R4" -> 10000., 
"TT1.R3" -> 5400., "TT1.R2" -> 10000., "TT1.R1" -> 10000.};
m = "filter";  
WSMSetValues[m, param];  
WSMModelData[m, "ParameterValues"]  

and this is an output showing that C1 and C2 did not take desired values:

 {TT1\[UpPointer]resistor1\[UpPointer]useHeatPort -> False, 
 TT1\[UpPointer]resistor1\[UpPointer]T -> 
 TT1\[UpPointer]resistor1\[UpPointer]T\[UnderBracket]ref, 
 TT1\[UpPointer]resistor1\[UpPointer]R -> TT1\[UpPointer]R1, 
 TT1\[UpPointer]resistor1\[UpPointer]T\[UnderBracket]ref -> 300.15, 
 TT1\[UpPointer]resistor1\[UpPointer]alpha -> 0, 
 TT1\[UpPointer]resistor2\[UpPointer]useHeatPort -> False, 
 TT1\[UpPointer]resistor2\[UpPointer]T -> 
 TT1\[UpPointer]resistor2\[UpPointer]T\[UnderBracket]ref, 
 TT1\[UpPointer]resistor2\[UpPointer]R -> TT1\[UpPointer]R2, 
 TT1\[UpPointer]resistor2\[UpPointer]T\[UnderBracket]ref -> 300.15, 
 TT1\[UpPointer]resistor2\[UpPointer]alpha -> 0, 
 TT1\[UpPointer]resistor3\[UpPointer]useHeatPort -> False, 
 TT1\[UpPointer]resistor3\[UpPointer]T -> 
 TT1\[UpPointer]resistor3\[UpPointer]T\[UnderBracket]ref, 
 TT1\[UpPointer]resistor3\[UpPointer]R -> TT1\[UpPointer]R3, 
 TT1\[UpPointer]resistor3\[UpPointer]T\[UnderBracket]ref -> 300.15, 
 TT1\[UpPointer]resistor3\[UpPointer]alpha -> 0, 
 TT1\[UpPointer]resistor4\[UpPointer]useHeatPort -> False, 
 TT1\[UpPointer]resistor4\[UpPointer]T -> 
 TT1\[UpPointer]resistor4\[UpPointer]T\[UnderBracket]ref, 
 TT1\[UpPointer]resistor4\[UpPointer]R -> TT1\[UpPointer]R4, 
 TT1\[UpPointer]resistor4\[UpPointer]T\[UnderBracket]ref -> 300.15, 
 TT1\[UpPointer]resistor4\[UpPointer]alpha -> 0, 
 TT1\[UpPointer]resistor5\[UpPointer]useHeatPort -> False, 
 TT1\[UpPointer]resistor5\[UpPointer]T -> 
 TT1\[UpPointer]resistor5\[UpPointer]T\[UnderBracket]ref, 
 TT1\[UpPointer]resistor5\[UpPointer]R -> TT1\[UpPointer]R5, 
 TT1\[UpPointer]resistor5\[UpPointer]T\[UnderBracket]ref -> 300.15, 
 TT1\[UpPointer]resistor5\[UpPointer]alpha -> 0, 
 TT1\[UpPointer]resistor6\[UpPointer]useHeatPort -> False, 
 TT1\[UpPointer]resistor6\[UpPointer]T -> 
 TT1\[UpPointer]resistor6\[UpPointer]T\[UnderBracket]ref, 
 TT1\[UpPointer]resistor6\[UpPointer]R -> TT1\[UpPointer]R6, 
 TT1\[UpPointer]resistor6\[UpPointer]T\[UnderBracket]ref -> 300.15, 
 TT1\[UpPointer]resistor6\[UpPointer]alpha -> 0, 
 TT1\[UpPointer]capacitor1\[UpPointer]C -> TT1\[UpPointer]C1, 
 TT1\[UpPointer]capacitor2\[UpPointer]C -> TT1\[UpPointer]C2, 
 TT1\[UpPointer]R1 -> 10000, TT1\[UpPointer]R2 -> 10000, 
 TT1\[UpPointer]R3 -> 5400, TT1\[UpPointer]R4 -> 10000, 
 TT1\[UpPointer]R5 -> 10000, TT1\[UpPointer]R6 -> 10000, 
 TT1\[UpPointer]C1 -> 0, TT1\[UpPointer]C2 -> 0}  

Since I could not attach the model here, I am providing a link for the same question I asked at Wolfram student forum where i was able to attach the model: http://forums.wolfram.com/student-support/topics/487059

Thank you, Tatjana

Tatjana
  • 85
  • 4

1 Answers1

4

I work with Wolfram SystemModeler development at Wolfram Research

As also answered on the student forum:

This is a bug in WSM 3.0, which will be fixed in a future version. As a workaround, you can evaluate this before you try to run WSMSetValues:

WSMLink`Utilities`iConvertValue[x_ /; NumberQ[x] && (x < 0.001 || x > 1000)] /; 
WSMLink`Utilities`validWSMSetValueQ[x, NumberQ] := ToString[x, CForm] 

After evaluating the snippet above, your calls to WSMSetValues should work again. Note that you have to evaluate this after every time you load the WSMLink with Needs["WSMLink`"].

Albert Retey
  • 23,585
  • 60
  • 104
Malte Lenz
  • 2,471
  • 19
  • 21
  • Can you explain in a sentence what exactly that does? I would interpret that you somehow circumvent a checking mechanism which otherwise would convert the value (or set it to a default?) by mistake. Is that roughly correct? – Albert Retey May 27 '13 at 08:18
  • Thank you for the answer - the workaround you offered solved my problem. Do you know if this bug was fixed in the latest SystemModeler version? – Tatjana May 31 '13 at 07:56
  • @AlbertRetey: It adds an additional DownValue to the iConvertValue symbol for small and big values, making it use a different kind of call to ToString that handles the given numbers in a better way. The created string is later used internally in the communication with the SystemModeler kernel. – Malte Lenz Jun 13 '13 at 07:36
  • @Tatjana: This bug was not fixed in the latest released SystemModeler (3.0.2). It will however be fixed in the next release. – Malte Lenz Jun 13 '13 at 07:37