Trellis Logo Software Framework for Geometry Based Numerical
			Mechanics       
 www.scorec.rpi.edu/Trellis  

Home
SCOREC
 
About Trellis
Documentation
Code Documentation
Projects/Papers
 
Downloads
Support
 
SCOREC Publications
AOMD

Unit System
When data from different sources (file, database, PDM system) is provided as input into a simulation program it becomes important that there is a system that allows to handle units. The Unit System is supposed to reduce the error that occurs from converting the different units incorrectly into a common unit needed in the simulation program.

The SCOREC Unit System provides an implementation capable of simplifying the conversion between units. It allows to enter any of the 7 SI base units (meter, kilogram, second, ampere, kelvin, mole, candela) combined with any of the 20 SI prefixes (yotta, zetta, exa, peta, tera, giga, mega, kilo, hecto, deka, deci, centi, milli, micro, nano, pico, femto, atto, zepto, yocto). A few common derived units are also available (Newton, etc.). You can add or multiply quantities with units and the system will take care of the correct conversion between the units.

Here is a simple code demonstrating the usage of the Unit System:

    int main(int argc, char* argv[])
    {
      // create 2.0 kg
      doubleUnitVariable a(2.0,SCOREC_UnitSystem::kg(1));
      // create 3.0 km
      doubleUnitVariable b(3.0,SCOREC_UnitSystem::km(1));
      // multiply should yield
      doubleUnitVariable c(6.0,SCOREC_UnitSystem::kg(1),SCOREC_UnitSystem::km(1));
      assert(a*b == c);

      // This will get the factor needed to convert c from kg*km to g*mm
      double conv =
        c.getConversionFactor(SCOREC_UnitSystem::g(1),SCOREC_UnitSystem::mm(1));

      // We can compose base units to more complex units
      // Let's create 24 kg*m^2/sec^2
      doubleUnitVariable d(2.0,SCOREC_UnitSystem::kg(1));
      doubleUnitVariable e(3.0,SCOREC_UnitSystem::m(2));
      doubleUnitVariable f(4.0,SCOREC_UnitSystem::s(-2));
      doubleUnitVariable g = d * e * f;
      doubleUnitVariable h(24.0,SCOREC_UnitSystem::J(1)); // this is 24. Joule
      assert(g == h); // They should be equal
    }
Please note that the doubleUnitVariable is simply a typedef for the template<typename T> class UnitVariable. That allows to add units to any user defined type. If the type is a pointer the dereference operator -> is overloaded so that the usual pointer operation, which are allowed on the original type, are available for the "unit-enhanced" type, too.
 

Andrew Bauer