Exclude unwanted units - mkraska/meclib GitHub Wiki

Sometimes sans simplifies to the same base unit as tans but the unit may still be inappropriate. Examples are

  • Hz for angular velocities or angular frequencies. 1/s or rad/s is correct, Hz is not.
  • J for mechanical moments. They must be given in force unit times length unit, e.g. N*m.
  • Hz for time constants which aren't frequencies.
  • m Pa for spring constants, which are force by length.

So how can we refuse these cases without spoiling the freedom to use the pre-defined units and unit tests?

Tools:

  • extract unit with stack functions. Check if the unit isn't oversimplified.
  • check against a blacklist either using member(value, list) or string comparison
    • [Hz, kHz, MHz]
    • [mJ, J, kJ, MJ, GJ]
  • For moments: check that the answer consists of value, force unit and length unit.
    • args(10*N*m) simplifies to [10, N, m]
  • However, it is not as trivial as it seems:
    • args(10*N/m) simplifies to [10*N, m]

Possible feedback:

  • Winkelgeschwindigkeiten und Kreisfrequenzen werden nicht in Hz gemessen. Benutzen Sie rad/s oder 1/s.
  • Momente werden nicht in J gemessen. Nutzen Sie Produkte aus Kraft- und Längeneinheiten (in dieser Reihenfolge)