Opened 12 years ago
Closed 12 years ago
#1955 closed defect (fixed)
Parameter values lost
Reported by: | Teemu Lempinen | Owned by: | Adrian Pop |
---|---|---|---|
Priority: | high | Milestone: | 1.9.0 |
Component: | Backend | Version: | trunk |
Keywords: | Cc: |
Description
There is a problem with the following model and OpenModelica-revision-14082:
model ParameterTestModel class Inside_class parameter Real A1 = 2.0; end Inside_class; Inside_class Inside; parameter Real Var2 = Inside.A1; Real Var1( start=0, fixed=true); equation der(Var1) = Var2; end ParameterTestModel;
The value of Var2 is lost. It is not in the result file and init.xml contains the following:
<ScalarVariable name = "Var2" valueReference = "1003" variability = "parameter" isDiscrete = "false" causality = "internal" alias = "noAlias" classIndex = "1" classType = "rPar" fileName = "ParameterTestModel.mo" startLine = "9" startColumn = "5" endLine = "9" endColumn = "36" fileWritable = "true"> <Real useStart="false" start="0.0" fixed="true" useNominal="false" nominal="1.0" min="-1.7976931348623157E+308" max="1.7976931348623157E+308" /> </ScalarVariable>
The simulation runs OK and the value of Var1 is correct, but the value of Var2 is not recorded anywhere. I would like to read all results and parameter values after simulation, previous versions (1.8.1) store the value to start="2.0" in init.xml.
Attachments (1)
Change History (11)
comment:1 by , 12 years ago
comment:2 by , 12 years ago
Inside.A1 in init.xml:
<ScalarVariable name = "Inside.A1" valueReference = "1002" variability = "parameter" isDiscrete = "false" causality = "internal" alias = "noAlias" classIndex = "0" classType = "rPar" fileName = "ParameterTestModel.mo" startLine = "4" startColumn = "3" endLine = "4" endColumn = "26" fileWritable = "true"> <Real useStart="true" start="2.0" fixed="true" useNominal="false" nominal="1.0" min="-1.7976931348623157E+308" max="1.7976931348623157E+308" /> </ScalarVariable>
comment:3 by , 12 years ago
To read the values after the simulation you don't use the XML file.
You either read the .mat file or choose outputFormat="csv" to output
the simulation results as comma separated values and read that.
Cheers,
Adrian Pop/
comment:4 by , 12 years ago
I understand that the xml file is not actually a result file, but the result file does not contain the values of parameter variables. So when I want to know the numerical value of all variables in the model, what should I do? Currently with 1.8.1 I collect time series for continuous variables from mat file and start values for parameters from xml file (which I use to draw a straight line on a chart).
Notice that I do not set the value for Var2 in mo file, so I cannot collect the value from there unless I code some alias functionality to my collector as well. That becomes tricky with array variables and in cases like this:
parameter Real a = 1.0; parameter Real b = 1.0; parameter Real c = a + b;
comment:5 by , 12 years ago
Ouch, it seems we don't write the parameters to the .csv or .plt files, only to .mat files.
Can you read the .mat file? What language do you use for collecting these?
Cheers,
Adrian Pop/
comment:6 by , 12 years ago
A colleague made a reader for mat files when OpenModelica switched to using them. I have only been reading continuous variables with it, and I thought they contain only continuous variables like csv and plt files. I'll have to look into that reader to see if I can use it to get parameters too.
by , 12 years ago
Attachment: | ParameterTestModel.png added |
---|
all parameters and variables are in the .mat file
comment:7 by , 12 years ago
comment:8 by , 12 years ago
Owner: | changed from | to
---|---|
Status: | new → accepted |
comment:9 by , 12 years ago
Yes, I found them already. Thank you very much!
This is much better this way. I understand that now I can make something like this:
parameter Real a = 1.0; parameter Real b = a; parameter Real c = b;
and just by changing the value of a in XML, the values of all variables will be changed. Previously the values were calculated when XML was created, and changing the value of a did not change b and c.
comment:10 by , 12 years ago
Resolution: | → fixed |
---|---|
Status: | accepted → closed |
I will close this bug as you found the workaround of using .mat files.
Cheers,
Adrian Pop/
I guess this comes from alias removal.
What is the XML info on Inside.A1?