Opened 7 years ago
Closed 7 years ago
#4621 closed defect (fixed)
[NF] Parameters and constants not in format expected by the backend
Reported by: | Martin Sjölund | Owned by: | Per Östlund |
---|---|---|---|
Priority: | high | Milestone: | Future |
Component: | New Instantiation | Version: | |
Keywords: | Cc: | Lennart Ochel |
Description
The new frontend is a little bit weird when it comes to evaluation of constants, for example in the flattened code for the following model only the array dimension is replaced:
model M constant Integer i = 2; Real x[i] = {i,i}; end M;
class M constant Integer i = 2; Real x[1]; Real x[2]; equation x = {/*Real*/(i), /*Real*/(i)}; end M;
Modelica_3.2.1_Modelica.Thermal.HeatTransfer.Examples.TwoMasses.c:85:132: error: use of undeclared identifier '$PModelica$PConstants$PT_zero' data->localData[0]->realVars[4] /* Tsensor1.T variable */ = data->localData[0]->realVars[0] /* mass1.T STATE(1,mass1.der_T) */ + $PModelica$PConstants$PT_zero;
If i
is changed to a parameter then the backend marks the parameter as changeable. I believe all constants as well as evaluated parameters need to be replaced in a stage before flattening to the DAE structure (but after unit checking) which is a bit hard since the unit checking is currently done on the DAE structure. Perhaps one work-around for that would simply be to mark all constants as "structural parameters" to make the (pre-?)backend perform the replacements.
Change History (3)
follow-up: 2 comment:1 by , 7 years ago
comment:2 by , 7 years ago
Replying to perost:
Replacing constants/structural parameters would currently be far more efficient to do in the frontend, since each cref has direct access to the binding of the component it refers to. But as you say that's not so easy right now. And currently we don't even cache the evaluated values, so we reevaluate constants/parameters every time we need their values.
Doing so is crucial for the efficiency of some Media libraries
comment:3 by , 7 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
Constants and structural parameters are now replaced in the NF since a while back, so I'd say this is fixed.
Yes, we need to improve the handling of constants/parameters. I added a phase that collects all package constants used by the model, and adds them as constants in the model. It seems to work fine, but I added that mostly because it was an easy way of getting more models to work. The reason TwoMasses fails is simply because I forgot to collect constants in functions, so that particular issue should be easy to fix.
Replacing constants/structural parameters would currently be far more efficient to do in the frontend, since each cref has direct access to the binding of the component it refers to. But as you say that's not so easy right now. And currently we don't even cache the evaluated values, so we reevaluate constants/parameters every time we need their values.