Natural Unit Representation in Modelica
Total Page:16
File Type:pdf, Size:1020Kb
Natural Unit Representation in Modelica Kevin L. Davies Christiann J.J. Paredis Georgia Institute of Technology Atlanta, Georgia USA Abstract In general, a unit may be the product of powers of other units, whether they are base units or units de- A method is presented by which alternative systems rived from the base units in the same manner. of physical units may be represented and utilized in In the Modelica language, physical quantities are Modelica. The method may be useful in simulating typically expressed as instances of the Real type [12, models of physical systems where the base units of the p. 46]. The value attribute of the instance is the num- International System of Units (Système international ber associated with the value of the quantity (not the d’unités, SI)—the standard unit system in Modelica— value of the quantity, as will be seen). The unit at- are poorly scaled. It also provides a convenient means tribute is a string that describes the unit by which the to express the values of physical quantities in fields of value of the quantity is divided to arrive at the num- science and engineering where data is typically rep- ber.i The displayUnit attribute (also a string) de- resented in other systems of units or where the rank scribes the unit by which the value should be divided of the system of units is less than that of SI (i.e., to arrive at the number as it is entered by or pre- natural units). By explicitly expressing the value of sented to the user. Based on the information provided a physical quantity as the product of a number and by the unit and displayUnit attributes, simulation a unit (where the unit is an algebraic variable), the tools may perform unit checking and conversion. The method uses variables that are unit-neutral. Unfortu- Real type contains other attributes as well, including nately, workarounds are necessary in order to imple- quantity, which is another string [8, p. 375]. ment the method in the current version of the Model- The SIunits subpackage of the Modelica Standard ica language. Nonetheless, it may be useful in special Library contains types that inherent from the Real applications, and the related discussion may provide type. The type definitions appropriately modify the valuable insight. In particular, it is shown that there unit, displayUnit, and quantity attributes (among is an apparent conflict in the interpretation of “num- others) to represent various physical quantities. The ber” and “value” between Modelica and the Interna- unit and displayUnit attributes are based on the tional Bureau of Weights and Measures (Bureau Inter- SI. The quantity string is generally used to describe national des Poids et Mesures, BIPM). the name of the physical quantity. For example, the Keywords: natural units; physical quantities; Model- Velocity type has a unit of "m/s" and a quantity ica; SI of "Velocity". If an instance of the Velocity type has a value of 1 Introduction one (v = 1), then it is meant that “the value of velocity is equal to one meter per second.” Again, the value In the mathematical representation of physical sys- attribute represents the number, or the value divided tems, the values of quantities are interrelated through by the unit, not the value itself. This apparent con- equations that express the behavior of the system over flict could be solved in one of several ways. First, the time and space. As stated by the BIPM [5, p. 103]: unit could be strictly set equal to be one (1), regardless of what the unit is. This is the essence of the current “The value of a quantity is generally ex- implementation in Modelica. It is also the interpreta- pressed as the product of a number and a tion we use when we are working a problem by hand unit. The unit is simply a particular exam- i ple of the quantity concerned which is used Hereafter, the value of the quantity is referred to as simply the value, but it should not be confused with the value attribute as a reference, and the number is the ratio of (which, in the current version of the Modelica language, is the the value of the quantity to the unit.” number). DOI Proceedings of the 9th International Modelica Conference 801 10.3384/ecp12076801 September 3-5, 2012, Munich, Germany Natural Unit Representation in Modelica and drop the units because we are exclusively using a algebraic variable (albeit constant). For each unit in- particular system of units. However, in this case, the troduced, it is necessary to add an equation that allows statement that “the value of a quantity is generally ex- the unit’s value to be determined. If a unit is consid- pressed as the product of a number and a unit” [5] loses ered to be a derived unit, then the equation simply re- its meaning; it may as well be “the value of a quan- lates the unit to other units (e.g., 1 · cycle = 2p · rad). tity is generally expressed as the number.” Second, However, there are several units (in SI, 7) that may not the value attribute could be renamed as the number be simply defined via other units. These base units attribute. Since the name of a variable is an implicit must be related to something outside of the algebraic reference to this attribute (whatever it is called), the system of equations representing the immediate phys- variable would then represent the number. The third ical system. This something is the “particular example method of resolution is to let the units (the meter and of the quantity concerned which is used as a reference” the second in this case) be mathematical entities and quoted previously [5]. The designation of “base” or let v0 = 1 · m=s. Here, the variable v0 directly repre- “derived” is somewhat arbitrary [8, p. 375], but regard- sents the value. Its value attribute is the value in the less, there are a number of units that must be defined context of the statement by the BIPM. by example. Considering only the immediate physical system, these units are linearly independent. 2 Method If only the SI will be used, then it is easiest to strictly set each of the base units of SI equal to one (1)— The approach is to follow the third method to resolve the meter (m), kilogram (kg), second (s), ampere (A), the apparent misnomer of the value attribute—to fac- kelvin (K), mole (mol), and candela (cd). This is im- Modelica.SIunits tor the units out of the unit attribute and into the plicitly the case in , but again, it value attribute. This offers the advantage that unit hardly captures the idea that a value is the product of a conversion is handled naturally. The essence of unit number and a unit. conversion is that the phrase “x (value) in u (unit)” is There are systems where typical values are many interpreted mathematically as “x divided by u.” Con- orders of magnitude larger or smaller than the re- tinuing with the previous example, v0 is divided by lated product of powers of base SI units (e.g., the do- m=s in order to display v0 in meters per second (as mains of astrophysics and atomic physics). In mod- a number). The result is simply one (1). If the unit eling and simulating those systems, it may be advan- foot is established through the appropriate relation tageous to choose appropriately small or large values (ft ≈ 0:3048 · m) and v0 is divided by ft=s, the result (respectively) for the corresponding base units such is v0 in feet per second (∼ 3:2894). that the product of the number (large or small in mag- As another example, systems involving angle are nitude) and the unit (small or large, respectively) is sometimes evaluated by working with variables in cy- well-scaled. Products of this type are often involved in cles and other times with variables in radians. If the initial conditions or parameter expressions, which are variable is the value, then “variable in unit” means not time-varying. Therefore, the number and the unit “value divided by unit.” If we work with the value can be multiplied before the dynamic simulation. Dur- directly, then there is no need to specify which unit we ing the simulation, only the value is important. After are working “in.” The unit is included; it has not been the simulation, the trajectory of the value may be di- factored out by division. As long as the dimensionality vided by the unit for display. This scaling is usually is correct, the math is equivalent due to the relation- unnecessary due to the wide range and appropriate dis- ships among units (or combinations of units). In this tribution of the real numbers that are representable in case, the relevant unit relation is 1 · cycle = 2p · rad.ii floating point space. The Modelica language specifi- This example extends directly to frequency (angle per cation recommends that floating point numbers be rep- time). Often, different symbols are used for frequency resented in at least IEEE double precision, which cov- in Hz (n) and frequency in rad=s (w). If the units are ers magnitudes from ∼2:225×10−308 to ∼1:798×10308 included in the variable f , then f = n ·Hz = w ·rad=s. [12, p. 13]. However, in some cases it may be prefer- In this method, each unit must be represented by an able to carefully scale the units and use single pre- cision instead for the sake of computational perfor- ii Furthermore, a cycle is typically equated to the number one mance.