m2m模型翻译
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

386 lines
13 KiB

7 months ago
  1. from sympy.physics.units.definitions.dimension_definitions import current, temperature, amount_of_substance, \
  2. luminous_intensity, angle, charge, voltage, impedance, conductance, capacitance, inductance, magnetic_density, \
  3. magnetic_flux, information
  4. from sympy.core.numbers import (Rational, pi)
  5. from sympy.core.singleton import S as S_singleton
  6. from sympy.physics.units.prefixes import kilo, milli, micro, deci, centi, nano, pico, kibi, mebi, gibi, tebi, pebi, exbi
  7. from sympy.physics.units.quantities import Quantity
  8. One = S_singleton.One
  9. #### UNITS ####
  10. # Dimensionless:
  11. percent = percents = Quantity("percent", latex_repr=r"\%")
  12. percent.set_global_relative_scale_factor(Rational(1, 100), One)
  13. permille = Quantity("permille")
  14. permille.set_global_relative_scale_factor(Rational(1, 1000), One)
  15. # Angular units (dimensionless)
  16. rad = radian = radians = Quantity("radian", abbrev="rad")
  17. radian.set_global_dimension(angle)
  18. deg = degree = degrees = Quantity("degree", abbrev="deg", latex_repr=r"^\circ")
  19. degree.set_global_relative_scale_factor(pi/180, radian)
  20. sr = steradian = steradians = Quantity("steradian", abbrev="sr")
  21. mil = angular_mil = angular_mils = Quantity("angular_mil", abbrev="mil")
  22. # Base units:
  23. m = meter = meters = Quantity("meter", abbrev="m")
  24. # gram; used to define its prefixed units
  25. g = gram = grams = Quantity("gram", abbrev="g")
  26. # NOTE: the `kilogram` has scale factor 1000. In SI, kg is a base unit, but
  27. # nonetheless we are trying to be compatible with the `kilo` prefix. In a
  28. # similar manner, people using CGS or gaussian units could argue that the
  29. # `centimeter` rather than `meter` is the fundamental unit for length, but the
  30. # scale factor of `centimeter` will be kept as 1/100 to be compatible with the
  31. # `centi` prefix. The current state of the code assumes SI unit dimensions, in
  32. # the future this module will be modified in order to be unit system-neutral
  33. # (that is, support all kinds of unit systems).
  34. kg = kilogram = kilograms = Quantity("kilogram", abbrev="kg")
  35. kg.set_global_relative_scale_factor(kilo, gram)
  36. s = second = seconds = Quantity("second", abbrev="s")
  37. A = ampere = amperes = Quantity("ampere", abbrev='A')
  38. ampere.set_global_dimension(current)
  39. K = kelvin = kelvins = Quantity("kelvin", abbrev='K')
  40. kelvin.set_global_dimension(temperature)
  41. mol = mole = moles = Quantity("mole", abbrev="mol")
  42. mole.set_global_dimension(amount_of_substance)
  43. cd = candela = candelas = Quantity("candela", abbrev="cd")
  44. candela.set_global_dimension(luminous_intensity)
  45. mg = milligram = milligrams = Quantity("milligram", abbrev="mg")
  46. mg.set_global_relative_scale_factor(milli, gram)
  47. ug = microgram = micrograms = Quantity("microgram", abbrev="ug", latex_repr=r"\mu\text{g}")
  48. ug.set_global_relative_scale_factor(micro, gram)
  49. # derived units
  50. newton = newtons = N = Quantity("newton", abbrev="N")
  51. joule = joules = J = Quantity("joule", abbrev="J")
  52. watt = watts = W = Quantity("watt", abbrev="W")
  53. pascal = pascals = Pa = pa = Quantity("pascal", abbrev="Pa")
  54. hertz = hz = Hz = Quantity("hertz", abbrev="Hz")
  55. # CGS derived units:
  56. dyne = Quantity("dyne")
  57. dyne.set_global_relative_scale_factor(One/10**5, newton)
  58. erg = Quantity("erg")
  59. erg.set_global_relative_scale_factor(One/10**7, joule)
  60. # MKSA extension to MKS: derived units
  61. coulomb = coulombs = C = Quantity("coulomb", abbrev='C')
  62. coulomb.set_global_dimension(charge)
  63. volt = volts = v = V = Quantity("volt", abbrev='V')
  64. volt.set_global_dimension(voltage)
  65. ohm = ohms = Quantity("ohm", abbrev='ohm', latex_repr=r"\Omega")
  66. ohm.set_global_dimension(impedance)
  67. siemens = S = mho = mhos = Quantity("siemens", abbrev='S')
  68. siemens.set_global_dimension(conductance)
  69. farad = farads = F = Quantity("farad", abbrev='F')
  70. farad.set_global_dimension(capacitance)
  71. henry = henrys = H = Quantity("henry", abbrev='H')
  72. henry.set_global_dimension(inductance)
  73. tesla = teslas = T = Quantity("tesla", abbrev='T')
  74. tesla.set_global_dimension(magnetic_density)
  75. weber = webers = Wb = wb = Quantity("weber", abbrev='Wb')
  76. weber.set_global_dimension(magnetic_flux)
  77. # CGS units for electromagnetic quantities:
  78. statampere = Quantity("statampere")
  79. statcoulomb = statC = franklin = Quantity("statcoulomb", abbrev="statC")
  80. statvolt = Quantity("statvolt")
  81. gauss = Quantity("gauss")
  82. maxwell = Quantity("maxwell")
  83. debye = Quantity("debye")
  84. oersted = Quantity("oersted")
  85. # Other derived units:
  86. optical_power = dioptre = diopter = D = Quantity("dioptre")
  87. lux = lx = Quantity("lux", abbrev="lx")
  88. # katal is the SI unit of catalytic activity
  89. katal = kat = Quantity("katal", abbrev="kat")
  90. # gray is the SI unit of absorbed dose
  91. gray = Gy = Quantity("gray")
  92. # becquerel is the SI unit of radioactivity
  93. becquerel = Bq = Quantity("becquerel", abbrev="Bq")
  94. # Common length units
  95. km = kilometer = kilometers = Quantity("kilometer", abbrev="km")
  96. km.set_global_relative_scale_factor(kilo, meter)
  97. dm = decimeter = decimeters = Quantity("decimeter", abbrev="dm")
  98. dm.set_global_relative_scale_factor(deci, meter)
  99. cm = centimeter = centimeters = Quantity("centimeter", abbrev="cm")
  100. cm.set_global_relative_scale_factor(centi, meter)
  101. mm = millimeter = millimeters = Quantity("millimeter", abbrev="mm")
  102. mm.set_global_relative_scale_factor(milli, meter)
  103. um = micrometer = micrometers = micron = microns = \
  104. Quantity("micrometer", abbrev="um", latex_repr=r'\mu\text{m}')
  105. um.set_global_relative_scale_factor(micro, meter)
  106. nm = nanometer = nanometers = Quantity("nanometer", abbrev="nm")
  107. nm.set_global_relative_scale_factor(nano, meter)
  108. pm = picometer = picometers = Quantity("picometer", abbrev="pm")
  109. pm.set_global_relative_scale_factor(pico, meter)
  110. ft = foot = feet = Quantity("foot", abbrev="ft")
  111. ft.set_global_relative_scale_factor(Rational(3048, 10000), meter)
  112. inch = inches = Quantity("inch")
  113. inch.set_global_relative_scale_factor(Rational(1, 12), foot)
  114. yd = yard = yards = Quantity("yard", abbrev="yd")
  115. yd.set_global_relative_scale_factor(3, feet)
  116. mi = mile = miles = Quantity("mile")
  117. mi.set_global_relative_scale_factor(5280, feet)
  118. nmi = nautical_mile = nautical_miles = Quantity("nautical_mile")
  119. nmi.set_global_relative_scale_factor(6076, feet)
  120. # Common volume and area units
  121. l = L = liter = liters = Quantity("liter")
  122. dl = dL = deciliter = deciliters = Quantity("deciliter")
  123. dl.set_global_relative_scale_factor(Rational(1, 10), liter)
  124. cl = cL = centiliter = centiliters = Quantity("centiliter")
  125. cl.set_global_relative_scale_factor(Rational(1, 100), liter)
  126. ml = mL = milliliter = milliliters = Quantity("milliliter")
  127. ml.set_global_relative_scale_factor(Rational(1, 1000), liter)
  128. # Common time units
  129. ms = millisecond = milliseconds = Quantity("millisecond", abbrev="ms")
  130. millisecond.set_global_relative_scale_factor(milli, second)
  131. us = microsecond = microseconds = Quantity("microsecond", abbrev="us", latex_repr=r'\mu\text{s}')
  132. microsecond.set_global_relative_scale_factor(micro, second)
  133. ns = nanosecond = nanoseconds = Quantity("nanosecond", abbrev="ns")
  134. nanosecond.set_global_relative_scale_factor(nano, second)
  135. ps = picosecond = picoseconds = Quantity("picosecond", abbrev="ps")
  136. picosecond.set_global_relative_scale_factor(pico, second)
  137. minute = minutes = Quantity("minute")
  138. minute.set_global_relative_scale_factor(60, second)
  139. h = hour = hours = Quantity("hour")
  140. hour.set_global_relative_scale_factor(60, minute)
  141. day = days = Quantity("day")
  142. day.set_global_relative_scale_factor(24, hour)
  143. anomalistic_year = anomalistic_years = Quantity("anomalistic_year")
  144. anomalistic_year.set_global_relative_scale_factor(365.259636, day)
  145. sidereal_year = sidereal_years = Quantity("sidereal_year")
  146. sidereal_year.set_global_relative_scale_factor(31558149.540, seconds)
  147. tropical_year = tropical_years = Quantity("tropical_year")
  148. tropical_year.set_global_relative_scale_factor(365.24219, day)
  149. common_year = common_years = Quantity("common_year")
  150. common_year.set_global_relative_scale_factor(365, day)
  151. julian_year = julian_years = Quantity("julian_year")
  152. julian_year.set_global_relative_scale_factor((365 + One/4), day)
  153. draconic_year = draconic_years = Quantity("draconic_year")
  154. draconic_year.set_global_relative_scale_factor(346.62, day)
  155. gaussian_year = gaussian_years = Quantity("gaussian_year")
  156. gaussian_year.set_global_relative_scale_factor(365.2568983, day)
  157. full_moon_cycle = full_moon_cycles = Quantity("full_moon_cycle")
  158. full_moon_cycle.set_global_relative_scale_factor(411.78443029, day)
  159. year = years = tropical_year
  160. #### CONSTANTS ####
  161. # Newton constant
  162. G = gravitational_constant = Quantity("gravitational_constant", abbrev="G")
  163. # speed of light
  164. c = speed_of_light = Quantity("speed_of_light", abbrev="c")
  165. # elementary charge
  166. elementary_charge = Quantity("elementary_charge", abbrev="e")
  167. # Planck constant
  168. planck = Quantity("planck", abbrev="h")
  169. # Reduced Planck constant
  170. hbar = Quantity("hbar", abbrev="hbar")
  171. # Electronvolt
  172. eV = electronvolt = electronvolts = Quantity("electronvolt", abbrev="eV")
  173. # Avogadro number
  174. avogadro_number = Quantity("avogadro_number")
  175. # Avogadro constant
  176. avogadro = avogadro_constant = Quantity("avogadro_constant")
  177. # Boltzmann constant
  178. boltzmann = boltzmann_constant = Quantity("boltzmann_constant")
  179. # Stefan-Boltzmann constant
  180. stefan = stefan_boltzmann_constant = Quantity("stefan_boltzmann_constant")
  181. # Atomic mass
  182. amu = amus = atomic_mass_unit = atomic_mass_constant = Quantity("atomic_mass_constant")
  183. # Molar gas constant
  184. R = molar_gas_constant = Quantity("molar_gas_constant", abbrev="R")
  185. # Faraday constant
  186. faraday_constant = Quantity("faraday_constant")
  187. # Josephson constant
  188. josephson_constant = Quantity("josephson_constant", abbrev="K_j")
  189. # Von Klitzing constant
  190. von_klitzing_constant = Quantity("von_klitzing_constant", abbrev="R_k")
  191. # Acceleration due to gravity (on the Earth surface)
  192. gee = gees = acceleration_due_to_gravity = Quantity("acceleration_due_to_gravity", abbrev="g")
  193. # magnetic constant:
  194. u0 = magnetic_constant = vacuum_permeability = Quantity("magnetic_constant")
  195. # electric constat:
  196. e0 = electric_constant = vacuum_permittivity = Quantity("vacuum_permittivity")
  197. # vacuum impedance:
  198. Z0 = vacuum_impedance = Quantity("vacuum_impedance", abbrev='Z_0', latex_repr=r'Z_{0}')
  199. # Coulomb's constant:
  200. coulomb_constant = coulombs_constant = electric_force_constant = \
  201. Quantity("coulomb_constant", abbrev="k_e")
  202. atmosphere = atmospheres = atm = Quantity("atmosphere", abbrev="atm")
  203. kPa = kilopascal = Quantity("kilopascal", abbrev="kPa")
  204. kilopascal.set_global_relative_scale_factor(kilo, Pa)
  205. bar = bars = Quantity("bar", abbrev="bar")
  206. pound = pounds = Quantity("pound") # exact
  207. psi = Quantity("psi")
  208. dHg0 = 13.5951 # approx value at 0 C
  209. mmHg = torr = Quantity("mmHg")
  210. atmosphere.set_global_relative_scale_factor(101325, pascal)
  211. bar.set_global_relative_scale_factor(100, kPa)
  212. pound.set_global_relative_scale_factor(Rational(45359237, 100000000), kg)
  213. mmu = mmus = milli_mass_unit = Quantity("milli_mass_unit")
  214. quart = quarts = Quantity("quart")
  215. # Other convenient units and magnitudes
  216. ly = lightyear = lightyears = Quantity("lightyear", abbrev="ly")
  217. au = astronomical_unit = astronomical_units = Quantity("astronomical_unit", abbrev="AU")
  218. # Fundamental Planck units:
  219. planck_mass = Quantity("planck_mass", abbrev="m_P", latex_repr=r'm_\text{P}')
  220. planck_time = Quantity("planck_time", abbrev="t_P", latex_repr=r't_\text{P}')
  221. planck_temperature = Quantity("planck_temperature", abbrev="T_P",
  222. latex_repr=r'T_\text{P}')
  223. planck_length = Quantity("planck_length", abbrev="l_P", latex_repr=r'l_\text{P}')
  224. planck_charge = Quantity("planck_charge", abbrev="q_P", latex_repr=r'q_\text{P}')
  225. # Derived Planck units:
  226. planck_area = Quantity("planck_area")
  227. planck_volume = Quantity("planck_volume")
  228. planck_momentum = Quantity("planck_momentum")
  229. planck_energy = Quantity("planck_energy", abbrev="E_P", latex_repr=r'E_\text{P}')
  230. planck_force = Quantity("planck_force", abbrev="F_P", latex_repr=r'F_\text{P}')
  231. planck_power = Quantity("planck_power", abbrev="P_P", latex_repr=r'P_\text{P}')
  232. planck_density = Quantity("planck_density", abbrev="rho_P", latex_repr=r'\rho_\text{P}')
  233. planck_energy_density = Quantity("planck_energy_density", abbrev="rho^E_P")
  234. planck_intensity = Quantity("planck_intensity", abbrev="I_P", latex_repr=r'I_\text{P}')
  235. planck_angular_frequency = Quantity("planck_angular_frequency", abbrev="omega_P",
  236. latex_repr=r'\omega_\text{P}')
  237. planck_pressure = Quantity("planck_pressure", abbrev="p_P", latex_repr=r'p_\text{P}')
  238. planck_current = Quantity("planck_current", abbrev="I_P", latex_repr=r'I_\text{P}')
  239. planck_voltage = Quantity("planck_voltage", abbrev="V_P", latex_repr=r'V_\text{P}')
  240. planck_impedance = Quantity("planck_impedance", abbrev="Z_P", latex_repr=r'Z_\text{P}')
  241. planck_acceleration = Quantity("planck_acceleration", abbrev="a_P",
  242. latex_repr=r'a_\text{P}')
  243. # Information theory units:
  244. bit = bits = Quantity("bit")
  245. bit.set_global_dimension(information)
  246. byte = bytes = Quantity("byte")
  247. kibibyte = kibibytes = Quantity("kibibyte")
  248. mebibyte = mebibytes = Quantity("mebibyte")
  249. gibibyte = gibibytes = Quantity("gibibyte")
  250. tebibyte = tebibytes = Quantity("tebibyte")
  251. pebibyte = pebibytes = Quantity("pebibyte")
  252. exbibyte = exbibytes = Quantity("exbibyte")
  253. byte.set_global_relative_scale_factor(8, bit)
  254. kibibyte.set_global_relative_scale_factor(kibi, byte)
  255. mebibyte.set_global_relative_scale_factor(mebi, byte)
  256. gibibyte.set_global_relative_scale_factor(gibi, byte)
  257. tebibyte.set_global_relative_scale_factor(tebi, byte)
  258. pebibyte.set_global_relative_scale_factor(pebi, byte)
  259. exbibyte.set_global_relative_scale_factor(exbi, byte)
  260. # Older units for radioactivity
  261. curie = Ci = Quantity("curie", abbrev="Ci")
  262. rutherford = Rd = Quantity("rutherford", abbrev="Rd")