Opened 8 years ago
Closed 8 years ago
#4089 closed defect (fixed)
HideResult defaults to protected
Reported by: | Rüdiger Franke | Owned by: | Patrick Täuber |
---|---|---|---|
Priority: | high | Milestone: | 1.11.0 |
Component: | Backend | Version: | |
Keywords: | Cc: | Patrick Täuber |
Description
The treatment of parameters has significantly improved with d75f648c (see also #4027).
The treatment of the HideResult annotation is still unsatisfactory. According to Modelica Spec 3.3, section 18.3 this annotation overrides the protected status for the translated model. In particular a protected variable can be made available with HideResult=false
.
See the following example:
model HideResult parameter Real a = 1; parameter Real b = 2 annotation(HideResult = true); parameter Real e = d; protected parameter Real c = 3; parameter Real d = 4 annotation(HideResult = false); end HideResult;
It should be possible to change the value of d
after model translation. Re-simulate should calculate e
.
Change History (20)
comment:3 by , 8 years ago
dd59e54 adjusts the filtering of variables in the result file.
The problem remains that parameters are still written to the result file, even if they are protected or hidden -- check the above example with and without parameter qualifiers!?
follow-up: 6 comment:5 by , 8 years ago
I get the desired code generated when replacing in BackendVariable.mo
two calls to DAEUtil.getProtectedAttr
with the new funtion isHiddenVar
. This new function lets the optional HideResult
annotation override the result of DAEUtil.getProtectedAttr
.
Could this work out?
*** BackendVariable.head.mo 2016-10-24 21:22:46.364719794 +0200 --- BackendVariable.mo 2016-10-24 21:24:10.076716111 +0200 *************** public function isProtectedVar *** 1297,1308 **** "author: Frenkel TUD 2013-01 Returns the DAE.Protected attribute." input BackendDAE.Var v; ! output Boolean prot; ! protected ! Option<DAE.VariableAttributes> attr; ! algorithm ! BackendDAE.VAR(values = attr) := v; ! prot := DAEUtil.getProtectedAttr(attr); end isProtectedVar; public function hasVarEvaluateAnnotationOrFinal --- 1297,1303 ---- "author: Frenkel TUD 2013-01 Returns the DAE.Protected attribute." input BackendDAE.Var v; ! output Boolean prot = isHiddenVar(v); end isProtectedVar; public function hasVarEvaluateAnnotationOrFinal *************** algorithm *** 1340,1345 **** --- 1335,1359 ---- end match; end hasVarEvaluateAnnotation; + protected function isHiddenVar + input BackendDAE.Var inVar; + output Boolean hidden; + protected + SCode.Annotation anno; + Absyn.Exp val; + algorithm + try + BackendDAE.VAR(comment=SOME(SCode.COMMENT(annotation_ = SOME(anno)))) := inVar; + val := SCode.getNamedAnnotation(anno, "HideResult"); + hidden := match(val) + case Absyn.BOOL(true) then true; + else false; + end match; + else + hidden := DAEUtil.getProtectedAttr(inVar.values); // see Modelica Spec 3.3, section 18.3 + end try; + end isHiddenVar; + public function hasAnnotation"checks if the variable has an annotation" input BackendDAE.Var inVar; output Boolean hasAnnot; *************** end isFinalVar; *** 1690,1696 **** public function isFinalOrProtectedVar input BackendDAE.Var inVar; ! output Boolean b = DAEUtil.getFinalAttr(inVar.values) or DAEUtil.getProtectedAttr(inVar.values); end isFinalOrProtectedVar; public function getVariableAttributes "Returns the DAE.VariableAttributes of a variable." --- 1704,1710 ---- public function isFinalOrProtectedVar input BackendDAE.Var inVar; ! output Boolean b = DAEUtil.getFinalAttr(inVar.values) or isHiddenVar(inVar); end isFinalOrProtectedVar; public function getVariableAttributes "Returns the DAE.VariableAttributes of a variable."
comment:6 by , 8 years ago
Replying to rfranke:
I get the desired code generated when replacing in
BackendVariable.mo
two calls toDAEUtil.getProtectedAttr
with the new funtionisHiddenVar
. This new function lets the optionalHideResult
annotation override the result ofDAEUtil.getProtectedAttr
.
I think this is a good idea, because it would make it easier to handle the protected attribute consistently.
comment:7 by , 8 years ago
Commit 6345c52 adapts the function BackendVariable.isProtectedVar
accordingly.
comment:8 by , 8 years ago
Here is a new version of the example. The hiding of b
does not work anymore, i.e. evaluation of hide_b
does not work?!
model HideResult2 parameter Real a = 1; parameter Boolean hide_b = true annotation(Evaluate = true); parameter Real b = 2 annotation(HideResult = hide_b); parameter Real e = d; protected parameter Real c = 3; parameter Real d = 4 annotation(HideResult = false); end HideResult2;
follow-up: 12 comment:10 by , 8 years ago
hide_b
is evaluated but evaluated parameters are only replaced in the variable attributes not in annotations. I think we should add hideResult to BackendDAE.VAR in the lowering phase and access it from there (just like it is done for tearingSelect).
comment:11 by , 8 years ago
Hmm... vwaurich and myself just were fighting with all the hardly documented features to distinguish between an array and a scalar during code generation (#4093). Much too much effort for such a simple thing.
Wouldn't it be better to replace evaluated variables instead of introducing yet another special rule?
comment:12 by , 8 years ago
Replying to ptaeuber:
I think we should add hideResult to BackendDAE.VAR in the lowering phase and access it from there (just like it is done for tearingSelect).
I agree with that.
comment:13 by , 8 years ago
Evaluated parameters are now also replaced in the hideResult attribute (70c7422).
comment:15 by , 8 years ago
Resolution: | fixed |
---|---|
Status: | closed → reopened |
Unfortunately this slight modification of the example does not work:
model HideResult3 parameter Real a = 1; parameter Boolean show_b = false annotation(Evaluate = true); parameter Real b = 2 annotation(HideResult = not show_b); end HideResult3;
It gives:
Translation Warning The hideResult annotation could not be evaluated, probably due to missing annotation(Evaluate=true). It is set to false by default.
comment:17 by , 8 years ago
Thank you for the fix for not show_b
!
This seems to be a tricky issue :-( Evaluation of HideResult does not yet seem to work for composed models. See HideResult4.Test
:
package HideResult4 model Component parameter Real a = 1; parameter Boolean hide_b = false annotation(Evaluate = true); parameter Real b = 2 annotation(HideResult = hide_b); end Component; model Test Component c(hide_b = true); end Test; end HideResult4;
Gives:
Translation Warning The hideResult annotation could not be evaluated, probably due to missing annotation(Evaluate=true). It is set to isProtected (=false) by default.
comment:18 by , 8 years ago
Resolution: | fixed |
---|---|
Status: | closed → reopened |
comment:19 by , 8 years ago
Owner: | changed from | to
---|---|
Status: | reopened → accepted |
The issue of HideResult4
is fixed in 901d152. Please check the functionality again.
PR1153 attempts to fix
hideResult
for the generated code.