Hi everybody,
The following minimal example does compile without any problems in WSM 4.3 and 5.1. But it will cause an error in WSM 12.0 all of a sudden:
model UnitErrorModel
MyComponent c( hasUnit = "myUnit" );
block MyComponent
parameter String hasUnit = "1";
output Real y( unit = hasUnit );
equation
y = 10;
end MyComponent;
end UnitErrorModel;
So the global model will have a component c that modifies a parameter hasUnit which is used by the component to set the unit-attribute of its output y.
In Mathematica [12.0.0 for Microsoft Windows (64-bit) (April 6, 2019)] I observe this:
model = Import[ "UnitErrorModel.mo" ];
SystemModelSimulate[ model, { 0, 10 } ]
SystemModelSimulate::bldl
Internal error: Codegen.getValueString: Non-constant expression:c.hasUnit
What has changed in WSM that this is causing an error? Why can't a parameter (note, that making the modification final will not resolve the issue) be used to set the unit-attribute - after all it is known at runtime when compiling the model?
Best regards, Guido
Note: I cross-posted an extended question on StackOverflow.
Background: I am developing a library for (acausal) System Dynamics modeling. Since SD is very low level (e.g. stocks and flows) working with hard-wired SI-units is not helpful for modeling managerial or economical problems. Yet, unit checking is very useful and widely embraced in the SD community. Thus, having a flexible way to use parameters to assign units to output (and input) connectors wouldmbe very helpful; this is also how most dedicated SD tools go about it.