Modelica - A Unified Object-Oriented Language for Systems

Modelica Change Proposal MCP-0027
Units of Literal Constants
(In Development)
Proposed Changes to the Modelica Language Specification
Version 3.4
Table of Contents
Preface ................................................................................................................................................. 3
Chapter 1
Introduction ................................................................................................................ 3
Chapter 2
Lexical Structure ........................................................................................................ 3
Chapter 3
Operators and Expressions ....................................................................................... 5
Chapter 4
Classes, Predefined Types, and Declarations .......................................................... 5
Chapter 5
Scoping, Name Lookup, and Flattening ................................................................... 5
Chapter 6
Interface or Type Relationships................................................................................ 5
Chapter 7
Inheritance, Modification, and Redeclaration ........................................................ 5
Chapter 8
Equations .................................................................................................................... 6
Chapter 9
Connectors and Connections..................................................................................... 6
Chapter 10
Arrays .......................................................................................................................... 6
Chapter 11
Statements and Algorithm Sections.......................................................................... 6
Chapter 12
Functions ..................................................................................................................... 6
Chapter 13
Packages ...................................................................................................................... 7
Chapter 14
Overloaded Operators ............................................................................................... 7
Chapter 15
Stream Connectors ..................................................................................................... 7
Chapter 16
Synchronous Language Elements ............................................................................. 7
Chapter 17
State Machines............................................................................................................ 7
Chapter 18
Annotations ................................................................................................................. 8
Chapter 19
Unit Expressions......................................................................................................... 8
Chapter 20
The Modelica Standard Library ............................................................................... 8
Appendix A
Glossary................................................................................................................... 8
Appendix B
Modelica Concrete Syntax..................................................................................... 8
Appendix C
Modelica DAE Representation ............................................................................. 8
Appendix D
Derivation of Stream Equations ........................................................................... 9
3
Preface
Chapter 1
Introduction
Chapter 2
Lexical Structure
2.4.1 Floating Point Numbers
Add the following text at the end of the existing section
A literal floating point constant is implicitly assumed to have unit "1" in the following cases:



if it appears in an expression containing other variables, parameters, or constants that have a
non-empty unit attribute;
if it appears in the then or else branch of a conditional expression whereby the other branch
contains variables, parameters, or constants with non-empty unit attribute
if it appears in one side of an relation operator whereby the other side contains variables,
parameters, or constants with non-empty unit attribute
[Rationale: if a literal constant shows up in an expression which also contains terms with units,
then obviously its intended meaning is to represent a nondimensional factor, so unit checking
should be enforced by assuming that. For example:
Modelica.SIunits.Length h;
Modelica.SIunits.Acceleration g;
Modelica.SIunits.Velocity v = sqrt(2*g*h);
when unit checking the binding equation for v, the unit of the literal constant 2 should not be
inferred to match the left-hand-side unit, but rather set to "1" in order to check the dimensional
consistency of the equation. A dimensionally wrong equation such as
Modelica.SIunits.Velocity v = 2*g*h;
4 MCP <number> <short description>
should trigger a error when performing unit checking. If one wants to put a literal physical constant
in an expression containing other terms with units, the following pattern can be used
Modelica.SIunits.Voltage v;
Modelica.SIunits.Current i;
final constant Modelica.SIunits.Resistance ohm = 1;
equation
v = 4*ohm*i;
A literal constant is also assumed to have unit 1 in these cases
Modelica.SIunits.Voltage v;
Modelica.SIunits.Current i;
Modelica.SIunits.Resistance R;
Boolean condition;
final constant Modelica.SIunits.Resistance ohm = 1;
equation
i = if on then v / R else 1*ohm;
// I = if on then v / R else 1; generates a warning
Modelica.SIunits.Length l, L;
equation
final constant Modelica.SIunits.Length m = 1;
if l > 4 * m then ...
// if l > 4 then ...; generates a warning
Usual parameter declaration statements such as
Modelica.SIunits.Length l = 4;
Modelica.SIunits.Pressure p = 1e6;
remain valid with this rule, because in this case the literal constant has no unit attribute.
MCP <number> <short description> 5
Chapter 3
Operators and Expressions
Chapter 4
Classes, Predefined Types, and Declarations
Chapter 5
Scoping, Name Lookup, and Flattening
Chapter 6
Interface or Type Relationships
Chapter 7
Inheritance, Modification, and Redeclaration
6 MCP <number> <short description>
Chapter 8
Equations
Chapter 9
Connectors and Connections
Chapter 10
Arrays
Chapter 11
Statements and Algorithm Sections
Chapter 12
Functions
MCP <number> <short description> 7
Chapter 13
Packages
Chapter 14
Overloaded Operators
Chapter 15
Stream Connectors
Chapter 16
Synchronous Language Elements
Chapter 17
State Machines
8 MCP <number> <short description>
Chapter 18
Annotations
Chapter 19
Unit Expressions
Chapter 20
The Modelica Standard Library
Appendix A
Glossary
Appendix B
Modelica Concrete Syntax
Appendix C
Modelica DAE Representation
MCP <number> <short description> 9
Appendix D
Derivation of Stream Equations