home *** CD-ROM | disk | FTP | other *** search
/ Programmer's ROM - The Computer Language Library / programmersrom.iso / ada / piwg / z000004.ada < prev    next >
Encoding:
Text File  |  1988-05-03  |  12.7 KB  |  289 lines

  1. with PHYSICAL_REAL ; use PHYSICAL_REAL ;
  2.  
  3. package PHYSICAL_UNITS_BASIC is
  4.  
  5. -- This package specification defines Ada types for physical
  6. -- quantities. A number of other packages use this package
  7. -- specification in order to provide a comprehensive dimension
  8. -- checking and units conversion system.
  9. --
  10. --              PHYSICAL QUANTITIES AND THEIR ASSOCIATED DIMENSIONS
  11. --
  12. --   Errors can occur in writing equations to solve problems in classical
  13. --physics. Many of these errors can be prevented by performing a dimensionality
  14. --check on the equations. All physical quantities have a fundamental dimension
  15. --that is independent of the units of measurement. The basic physical dimensions
  16. --are: length, mass, time, electrical charge, temperature and luminous intens-
  17. --ity.There are a number of systems of units for measuring physical quantities.
  18. --The MKS system is based on meter, kilogram, second  measurement.
  19. --The CGS system is based on centimeter, gram, second  measurement.
  20. --The English system is based on feet, pound, second  measurement.
  21. --A few physical dimensions and the associated measurement unit in 
  22. --these three systems are :
  23. --
  24. --
  25. --      Physical Quantity                           Unit System
  26. --        Dimension                         MKS         CGS          English
  27. --
  28. --        length                            meter       centimeter   feet
  29. --
  30. --        mass                              kilogram    gram         pound mass
  31. --
  32. --        time                              second      second       second
  33. --
  34. --        force                             newton      dyne         poundal
  35. --
  36. --        energy                            joule       erg          B.t.u.
  37. --
  38. --
  39. --   The checking of a physical equation has two aspects. The first is to check
  40. --the dimensionality. The dimensionality is independent of the unit system. The
  41. --second is to check that a consistent system of units is used in the equation.
  42. --   An example of a dimensionality check is using the basic equation F=ma to
  43. --determine that force has the dimension  mass x length / time squared, then
  44. --              2
  45. --check if  F=mv /r  is dimensionally correct. The check is performed by 
  46. --expanding the dimensions, e.g.  mass x (length/time) x (length/time) / length.
  47. --with the dimensions expected for force from the basic equation F=ma. As
  48. --expected, centripetal force has the same dimensionality as the force from
  49. --Newton's second law of motion.
  50. --
  51. --                    THE ALGEBRA OF DIMENSIONALITY
  52. --
  53. --   The dimension of any physical quantity can be written as
  54. --
  55. --                  a   b   c   d   e   f
  56. --                 L   M   T   Q   C   K
  57. --
  58. --where a,b,c,d,e and f are integers such as -4, -3, -2 , -1, 0, 1, 2, 3, 4
  59. --and L is length, M is mass, T is time, Q is charge, C is luminous intensity
  60. --and K is temperature. An exponent of zero means the dimension does not apply
  61. --to the physical quantity. The normal rules of algebra for exponents apply
  62. --for combining dimensions.
  63. --
  64. --   In order to add or subtract two physical quantities the quantities must
  65. --have the same dimension. The resulting physical quantity has the same
  66. --dimensions. Physical quantities with the same dimension in different
  67. --systems of units can be added or subtracted by multiplying one of
  68. --the quantities by a units conversion factor to obtain compatible units.
  69. --
  70. --   The multiplication of two physical quantities results in a new physical
  71. --quantity that has the sum of the exponents of the dimensions of the initial
  72. --two quantities.
  73. --
  74. --   The division of one physical quantity by another results in a new physical
  75. --quantity that has the dimension of the exponents of the first quantity minus
  76. --the exponents of the second quantity.
  77. --
  78. --   Taking the square root of a physical quantity results in a new physical
  79. --quantity having a dimension with exponents half of the initial dimension.
  80. --
  81. --   Raising a physical quantity to a power results in a new physical quantity
  82. --having a dimension with the exponents multiplied by the power.
  83. --
  84. --                                     2                2  2    2 -2
  85. --          e.g. v has dimension L/T, v  has dimension L /T or L T
  86. --
  87. --   The derivative of a physical quantity with respect to another physical
  88. --quantity results in a new physical quantity with the exponents of the
  89. --first dimension minus the exponents of the other dimension.
  90. --         e.g.  v has dimension L/T, t has dimension T,
  91. --
  92. --                                           2
  93. --               then dv/dt has dimension L/T
  94. --
  95. --   The integral of a physical quantity over the range of another physical
  96. --quantity results in a new physical quantity that has a dimension with the
  97. --sum of the exponents of the two quantities.
  98. --        
  99. --         e.g.  v has dimension L/T, t has dimension T,
  100. --               then  integral v dt  has dimension  L/T * T or L
  101. --
  102. --
  103. -- The initial thought was to have metric units and English units
  104. -- in separate package specifications. This proved inpractical
  105. -- because time in seconds is both metric and English. Many other
  106. -- units such as watt of power and Farad of capacitance are in
  107. -- both systems. A further impracticallity arose when considering
  108. -- the design of a units system conversion package. e.g. A package
  109. -- that would provide accurate conversion form meters to inches
  110. -- to micrometers to light years. The one package specification became
  111. -- so large that it was inefficient, so, in order to keep the size
  112. -- reasonable, three packages were created. The basic units, the
  113. -- mechanical units and the electrical units. Then a package
  114. -- called other units came into existance for pragmatic reasons.
  115. --
  116. -- Notice that there is not a type called LENGTH because
  117. -- adding length in meters to length in feet is not allowed.
  118. -- Even LENGTH_METRIC and LENGTH_ENGLISH are not acceptable
  119. -- because meters can not be added to centimeters and inches can
  120. -- not be added to feet. Further complication arises because of
  121. -- seconds of time and seconds of arc. There can be ounces of
  122. -- milk ( liquid measure ) and ounces of sugar ( weight measure ).
  123. -- There can be quarts of milk and quarts of strawberries ( dry
  124. -- measure ). Thus the decision was made that every Ada type
  125. -- would be a dimension name followed by a unit name.
  126. --
  127. -- Now, more choices had to be made. Unit names such as 
  128. --  DENSITY_KILOGRAM_PER_CUBIC_METER or DENSITY_TONS_PER_CUBIC_YARD
  129. -- start getting long and there are many combinations. The number
  130. -- of combinations for density are all the units of mass times all
  131. -- the units of volume. Thus a subset of all possible units was
  132. -- chosen with the additional short hand notation of _MKS for
  133. -- the meter, kilogram, second system of units and the _ENGLISH for
  134. -- the foot, pound, second system. Additional qualifiers are added
  135. -- to clarify such as VOLUME_QUART_LIQUID and VOLUME_QUART_DRY.
  136. --
  137. -- Some other compromises were made:
  138. --       Only a few units were entered as both singular and plural.
  139. --       The choice of names is the authors. A committee could expand
  140. --       the list. For example a meter can be a length or a distance,
  141. --       length is used as the type and distance is a subtype.
  142. --       A user may provide additional local subtype names for units 
  143. --       and thus has the full capability for alternate type names.
  144. --
  145. --   The comments below are organized to present the physical quantity name with
  146. --associated information. The second column is one of the typical symbols used
  147. --for the physical quantity. The third column is the dimension of the physical
  148. --quantity expressed in terms of the fundamental dimensions. The fourth column
  149. --is the name of the unit in the MKS measurement system. The fifth column
  150. --is the typical MKS unit equation. An independent table presents conversion
  151. --factors from the MKS measurement system to other measurement systems.
  152. --   Physics developed over a period of many years by many people from a variety
  153. --of disciplines. Thus, there is ambiguity and duplication of symbols.
  154. -- 
  155. --
  156. --PHYSICAL QUANTITY         SYMBOL  DIMENSION   MEASUREMENT UNIT  UNIT EQUATION
  157. --_________________         ______  _________   ________________  ______________
  158. --
  159. --
  160. --                                  BASIC UNITS
  161. --
  162. --length                     s       L           meter              m
  163. --wave length                lambda  "             "                "
  164. --
  165.   type LENGTH_MKS is new REAL ;
  166.   subtype LENGTH_METER is LENGTH_MKS ;
  167.   subtype LENGTH_METERS is LENGTH_MKS ;  -- This could be done for every type
  168.   subtype DISTANCE_METER is LENGTH_MKS ;  -- with plurals and alias and
  169.   subtype DISTANCE_METERS is LENGTH_MKS ;  -- plurals for the alias
  170.   subtype WAVE_LENGTH_MKS is LENGTH_MKS ;
  171.   subtype WAVE_LENGTH_METER is LENGTH_MKS ;
  172.   type LENGTH_ENGLISH is new REAL ;
  173.   subtype LENGTH_FOOT is LENGTH_ENGLISH ;
  174.   subtype LENGTH_FEET is LENGTH_ENGLISH ;
  175.   type LENGTH_PICOMETER is new REAL ;
  176.   type LENGTH_NANOMETER is new REAL ;
  177.   type LENGTH_MICROMETER is new REAL ;
  178.   type LENGTH_MILLIMETER is new REAL ;
  179.   type LENGTH_CENTIMETER is new REAL ;
  180.   type LENGTH_DECIMETER is new REAL ;
  181.   type LENGTH_DECAMETER is new REAL ;
  182.   type LENGTH_HECTOMETER is new REAL ;
  183.   type LENGTH_KILOMETER is new REAL ;
  184.   type LENGTH_MEGAMETER is new REAL ;
  185.   type LENGTH_GIGAMETER is new REAL ;
  186.   type LENGTH_ANGSTROM is new REAL ;
  187.   type LENGTH_MIL is new REAL ;
  188.   type LENGTH_INCH is new REAL ;
  189.   type LENGTH_YARD is new REAL ;
  190.   type LENGTH_FATHOM is new REAL ;
  191.   type LENGTH_ROD is new REAL ;
  192.   type LENGTH_CHAIN_SURVEYOR is new REAL ;
  193.   type LENGTH_CHAIN_ENGINEER is new REAL ;
  194.   type LENGTH_FURLONG is new REAL ;
  195.   type LENGTH_MILE is new REAL ;
  196.   subtype LENGTH_MILE_STATUTE is LENGTH_MILE ;
  197.   type LENGTH_MILE_NAUTICAL is new REAL ;
  198.   type LENGTH_LEAGUE_LAND is new REAL ;
  199.   type LENGTH_LEAGUE_MARINE is new REAL ;
  200.   type LENGTH_LIGHT_YEAR is new REAL ;
  201.  
  202. --
  203. --mass                       m       M           kilogram           Kg
  204. --
  205.   type MASS_MKS is new REAL ;
  206.   subtype MASS_KILOGRAM is MASS_MKS ;
  207.   type MASS_ENGLISH is new REAL ;
  208.   subtype MASS_POUND is MASS_ENGLISH ;
  209.   subtype MASS_POUND_AVDP is MASS_ENGLISH ;
  210.   type MASS_POUND_TROY is new REAL ;
  211.   subtype MASS_POUND_APOTHECARY is MASS_POUND_TROY ;
  212.   type MASS_MILLIGRAM is new REAL ;
  213.   type MASS_GRAM is new REAL ;
  214.   type MASS_GRAIN is new REAL ; -- same inall English systems
  215.   type MASS_PENNYWEIGHT_TROY is new REAL ;
  216.   type MASS_CARAT_TROY is new REAL ;
  217.   type MASS_SCRUPLE is new REAL ;
  218.   type MASS_DRAM_AVDP is new REAL ;
  219.   type MASS_OUNCE_AVDP is new REAL ;
  220.   type MASS_OUNCE_TROY is new REAL ;
  221.   type MASS_TON_SHORT is new REAL ;
  222.   type MASS_TON_LONG is new REAL ;
  223.   type MASS_TON_METRIC is new REAL ;
  224.  
  225. --
  226. --time                       t       T           second             sec
  227. --
  228.   type TIME_SECOND is new REAL ;
  229.   subtype TIME_SECONDS is TIME_SECOND ;
  230.   type TIME_PICOSECOND is new REAL ;
  231.   type TIME_NANOSECOND is new REAL ;
  232.   type TIME_MICROSECOND is new REAL ;
  233.   type TIME_MILLISECOND is new REAL ;
  234.   type TIME_CENTISECOND is new REAL ;
  235.   type TIME_KILOSECOND is new REAL ;
  236.   type TIME_MEGASECOND is new REAL ;
  237.   type TIME_GIGASECOND is new REAL ;
  238.   type TIME_MINUTE is new REAL ;
  239.   type TIME_HOUR is new REAL ;
  240.   type TIME_DAY is new REAL ;
  241.   type TIME_FORTNIGHT is new REAL ;
  242.   type TIME_MONTH is new REAL ;
  243.   type TIME_YEAR is new REAL ;
  244.   type TIME_DECADE is new REAL ;
  245.   type TIME_CENTURY is new REAL ;
  246.   type TIME_MILLENNIA is new REAL ;
  247.  
  248. --
  249. --electric charge            q       Q           coulomb            c
  250. --  electric flux
  251. --
  252.   type CHARGE_COULOMB is new REAL ;
  253.   subtype CHARGE_AMPERE_SECOND is CHARGE_COULOMB ;
  254.   type CHARGE_AMPERE_HOURS is new REAL ;
  255.   type CHARGE_ELECTRON is new REAL ;
  256.   type CHARGE_FARADAY is new REAL ;
  257.  
  258. --
  259. --luminous intensity         I       C           candle             cd
  260. --
  261.   type LUMINOUS_INTENSITY_CANDLE is new REAL ;
  262.  
  263. --                                                                  o
  264. --temperature                T       K           degree kelvin       K
  265. --
  266.   type TEMPERATURE_KELVIN is new real ;
  267.   type TEMPERATURE_CENTIGRADE is new REAL ;
  268.   subtype TEMPERATURE_CELSIUS is TEMPERATURE_CENTIGRADE ;
  269.   type TEMPERATURE_FARENHEIT is new REAL ;
  270.  
  271. --
  272. --angle                      theta   none        radian             none
  273. --
  274.   type ANGLE_RADIAN is new REAL ;
  275.   subtype ANGLE_RADIANS is ANGLE_RADIAN ;
  276.   subtype PLANE_ANGLE_RADIANS is ANGLE_RADIAN ;
  277.   type ANGLE_SECOND is new REAL ;
  278.   type ANGLE_MINUTE is new REAL ;
  279.   type ANGLE_DEGREE is new REAL ;
  280.   type ANGLE_REVOLUTION is new REAL ;
  281.   type ANGLE_BAM is new REAL ;
  282.  
  283. --
  284. --solid angle                phi     none        steradian          none
  285. --
  286.   type SOLID_ANGLE_STERADIAN is new REAL ;
  287. --
  288. end PHYSICAL_UNITS_BASIC ;
  289.