With more focus on good unit-checking we also need the possibility configure it, for the following reasons:
For enabling one can have a new annotation UnitChecking that can be placed on equations and possibly in classes
record UnitChecking
/*literal*/ constant enable=true;
/*literal*/ constant strictLiterals=true;
end UnitChecking;
Setting enable=false completely disable unit-checking, whereas strictLiterals=false disables the proposed 4-line idea.
Design issues:
- An alternative is to have slightly different names for the equation and class ones, so that single a misplaced semi-colon can be detected.
- An alternative is to have an enumeration with different options (Disable "completely disabled", IgnoreLiterals "Literals can have any unit", StrictMultiplication "The 4-line proposal"). That would work especially well if we can see them as ordered, but not if there are orthogonal concepts.
Tools should use the settings to limit the checking, and may also indicate that the checking was limited due to these settings.
The main reason to limit the check is to support legacy code (without having to make too many changes - the goal is to have long-term support for Modelica models is that they should continue to work) and for correlations in a few equations. This is needed:
And new units and unit-conversions in (top-level) packages. The first can use:
record BaseUnit
/*literal*/ String symbol;
/*literal*/ String quantity;
end BaseUnit;
The latter could use the same logic as for version conversions but with a different command.
So:
package P
annotation(BaseUnit(symbol="XXX", quantity="currency"), UnitConversion(script="test.mos"));
end P;
The goal would be to have some mild form of standardization of non-SI units; so that the same symbol and quantity are preferably used for the same things. (As in #3425 the "XXX" is used for currency, similarly as "USD" and "EUR").
Each BaseUnit should be orthogonal to ones that don't have the same symbol and quantity, and each symbol should only be matched with the same non-empty quantity. It might also be necessary to coordinate with the FMI-standard.
With conversion commands (no need for these specific ones, but to illustrate the concept):
// defineUnitConversion(<unit>, <derived unit>, <scale>, <opt. offset>);
// if scale is zero the offset gives the inverted scale.
defineUnitConversion("W", "mW", 1000);
defineUnitConversion("K", "degC", 1, -273.15);
defineUnitConversion("cl/km", "mpgUS", 0, 378.5411784/1.609344)
The exact syntax can be discussed, and obviously tools may have global settings for units in other ways.
If the derived unit looks like a valid unit the specified conversion should be the correct one (so you cannot introduce "mW" to mean "10 A", but "mpg" is fine as you may not stack prefixes like "m" and "p" on top of the unit "g").
In particular duplicate identical unit conversions should just work.
The existing rules and guidelines for units still apply - including base units, and would become even more important.
With more focus on good unit-checking we also need the possibility configure it, for the following reasons:
For enabling one can have a new annotation UnitChecking that can be placed on equations and possibly in classes
Setting
enable=falsecompletely disable unit-checking, whereasstrictLiterals=falsedisables the proposed 4-line idea.Design issues:
Tools should use the settings to limit the checking, and may also indicate that the checking was limited due to these settings.
The main reason to limit the check is to support legacy code (without having to make too many changes - the goal is to have long-term support for Modelica models is that they should continue to work) and for correlations in a few equations. This is needed:
And new units and unit-conversions in (top-level) packages. The first can use:
The latter could use the same logic as for version conversions but with a different command.
So:
The goal would be to have some mild form of standardization of non-SI units; so that the same symbol and quantity are preferably used for the same things. (As in #3425 the "XXX" is used for currency, similarly as "USD" and "EUR").
Each BaseUnit should be orthogonal to ones that don't have the same symbol and quantity, and each symbol should only be matched with the same non-empty quantity. It might also be necessary to coordinate with the FMI-standard.
With conversion commands (no need for these specific ones, but to illustrate the concept):
The exact syntax can be discussed, and obviously tools may have global settings for units in other ways.
If the derived unit looks like a valid unit the specified conversion should be the correct one (so you cannot introduce "mW" to mean "10 A", but "mpg" is fine as you may not stack prefixes like "m" and "p" on top of the unit "g").
In particular duplicate identical unit conversions should just work.
The existing rules and guidelines for units still apply - including base units, and would become even more important.