Changeset 1427


Ignore:
Timestamp:
Apr 29, 2009 10:02:27 AM (12 years ago)
Author:
dkearney
Message:

adding tesla, gauss, weber and maxwell magnetic field units.
noticed python bindings do not validate the to_units before converting,
o stuff like mM-3 is not converted to /mm3 when given back to the user.
this is a minor bug right now.

Location:
trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/lang/python/Rappture/PyRpUnits.cc

    r1368 r1427  
    423423
    424424    static char *kwlist[] = {
    425         (char *)"fromVal",
    426         (char *)"to",
    427         (char *)"units",
    428         NULL
     425        (char *)"fromVal",
     426        (char *)"to",
     427        (char *)"units",
     428        NULL
    429429    };
    430430
     
    433433        if (!PyArg_ParseTupleAndKeywords(args, keywds, "ss|s",
    434434                    kwlist, &fromVal, &to, &units)) {
    435             return NULL; 
     435            return NULL;
    436436        }
    437437    }
  • trunk/lang/tcl/tests/units.test

    r1157 r1427  
    884884
    885885#--------------------------------------------------------------------
     886# Magnetic Field Conversions
     887#--------------------------------------------------------------------
     888
     889test convert_units-5.4.11.0 {Rappture::Units::convert, T->G} {
     890    list [catch {Rappture::Units::convert 5T -to G} msg] $msg
     891} {0 50000G}
     892
     893test convert_units-5.4.11.1 {Rappture::Units::convert, G->T} {
     894    list [catch {Rappture::Units::convert 5G -to T} msg] $msg
     895} {0 0.0005T}
     896
     897test convert_units-5.4.11.2 {Rappture::Units::convert, G->mT} {
     898    list [catch {Rappture::Units::convert 50G -to mT} msg] $msg
     899} {0 5mT}
     900
     901test convert_units-5.4.11.3 {Rappture::Units::convert, Mx->Wb} {
     902    list [catch {Rappture::Units::convert 5Mx -to Wb} msg] $msg
     903} {0 5e-08Wb}
     904
     905test convert_units-5.4.11.4 {Rappture::Units::convert, Wb->Mx} {
     906    list [catch {Rappture::Units::convert 5e-8Wb -to Mx} msg] $msg
     907} {0 5Mx}
     908
     909test convert_units-5.4.11.5 {Rappture::Units::convert, wB->mX} {
     910    list [catch {Rappture::Units::convert 5e-8wB -to mX} msg] $msg
     911} {0 5Mx}
     912
     913#--------------------------------------------------------------------
    886914# Rappture::Units::Search::for <units>
    887915#--------------------------------------------------------------------
  • trunk/src/core/RpUnits.cc

    r1006 r1427  
    23892389        retVal = RpUnitsPreset::addPresetForce();
    23902390    }
     2391    else if (group.compare(RP_TYPE_MAGNETIC) == 0) {
     2392        retVal = RpUnitsPreset::addPresetMagnetic();
     2393    }
    23912394    else if (group.compare(RP_TYPE_MISC) == 0) {
    23922395        retVal = RpUnitsPreset::addPresetMisc();
     
    24212424    result += addPresetConcentration();
    24222425    result += addPresetForce();
     2426    result += addPresetMagnetic();
    24232427    result += addPresetMisc();
    24242428
     
    28802884
    28812885/**********************************************************************/
     2886// METHOD: addPresetMagnetic()
     2887/// Add concentration related units to the dictionary
     2888/**
     2889 *
     2890 * http://en.wikipedia.org/wiki/Tesla_(unit)
     2891 * http://en.wikipedia.org/wiki/Gauss_(unit)
     2892 * http://en.wikipedia.org/wiki/Maxwell_(unit)
     2893 * http://en.wikipedia.org/wiki/Weber_(unit)
     2894 *
     2895 * Defines the following units:
     2896 *   tesla    (T)
     2897 *   gauss    (G)
     2898 *   maxwell  (Mx)
     2899 *   weber    (Wb)
     2900 *
     2901 * Return codes: 0 success, anything else is error
     2902 */
     2903
     2904int
     2905RpUnitsPreset::addPresetMagnetic () {
     2906
     2907    RpUnits* tesla = NULL;
     2908    RpUnits* gauss = NULL;
     2909    RpUnits* maxwell = NULL;
     2910    RpUnits* weber = NULL;
     2911
     2912    tesla = RpUnits::define("T",  NULL, RP_TYPE_MAGNETIC, RPUNITS_METRIC);
     2913    gauss = RpUnits::define("G",  NULL, RP_TYPE_MAGNETIC);
     2914    maxwell = RpUnits::define("Mx",  NULL, RP_TYPE_MAGNETIC);
     2915    weber = RpUnits::define("Wb", NULL, RP_TYPE_MAGNETIC, RPUNITS_METRIC);
     2916
     2917    RpUnits::define(tesla,gauss,tesla2gauss,gauss2tesla);
     2918    RpUnits::define(maxwell,weber,maxwell2weber,weber2maxwell);
     2919
     2920    return 0;
     2921}
     2922
     2923/**********************************************************************/
    28822924// METHOD: addPresetMisc()
    28832925/// Add Misc related units to the dictionary
     
    29472989        return &RpUnitsTypes::hintTypeConc;
    29482990    }
    2949     else if (type.compare(RP_TYPE_CONC) == 0) {
     2991    else if (type.compare(RP_TYPE_FORCE) == 0) {
    29502992        return &RpUnitsTypes::hintTypeForce;
     2993    }
     2994    else if (type.compare(RP_TYPE_MAGNETIC) == 0) {
     2995        return &RpUnitsTypes::hintTypeMagnetic;
    29512996    }
    29522997    else if (type.compare(RP_TYPE_MISC) == 0) {
     
    31083153
    31093154    if ( (unitObj->getType()).compare(RP_TYPE_FORCE) == 0 ) {
     3155        retVal = true;
     3156    }
     3157
     3158    return retVal;
     3159}
     3160
     3161bool
     3162RpUnitsTypes::hintTypeMagnetic   (   RpUnits* unitObj    ) {
     3163
     3164    bool retVal = false;
     3165
     3166    if ( (unitObj->getType()).compare(RP_TYPE_MAGNETIC) == 0 ) {
    31103167        retVal = true;
    31113168    }
  • trunk/src/core/RpUnits.h

    r709 r1427  
    4646#define RP_TYPE_CONC        "concentration"
    4747#define RP_TYPE_FORCE       "force"
     48#define RP_TYPE_MAGNETIC    "magnetic"
    4849#define RP_TYPE_MISC        "misc"
    4950
     
    8485        static int  addPresetConcentration();
    8586        static int  addPresetForce();
     87        static int  addPresetMagnetic();
    8688        static int  addPresetMisc();
    8789};
     
    106108        static bool hintTypeConc      ( RpUnits* unitObj );
    107109        static bool hintTypeForce     ( RpUnits* unitObj );
     110        static bool hintTypeMagnetic  ( RpUnits* unitObj );
    108111        static bool hintTypeMisc      ( RpUnits* unitObj );
    109112
     
    515518        //  RP_TYPE_CONC      "concentration" load units related to concentration
    516519        //  RP_TYPE_FORCE     "force"         load units related to force
     520        //  RP_TYPE_MAGNETIC  "magnetic"      load units related to magnetics
    517521        //  RP_TYPE_MISC      "misc"          load units related to everything else
    518522        //  (no other groups have been created)
  • trunk/src/core/RpUnitsStd.cc

    r1018 r1427  
    567567}
    568568
     569/****************************************
     570 * MAGNETIC CONVERSIONS
     571 * http://en.wikipedia.org/wiki/Tesla_(unit)
     572 * http://en.wikipedia.org/wiki/Gauss_(unit)
     573 * http://en.wikipedia.org/wiki/Maxwell_(unit)
     574 * http://en.wikipedia.org/wiki/Weber_(unit)
     575 ****************************************/
     576
     577double tesla2gauss (double tesla)
     578{
     579    return (tesla*1e4);
     580}
     581
     582double gauss2tesla (double gauss)
     583{
     584    return (gauss*1e-4);
     585}
     586
     587double maxwell2weber (double maxwell)
     588{
     589    return (maxwell*1e-8);
     590}
     591
     592double weber2maxwell (double weber)
     593{
     594    return (weber*1e8);
     595}
     596
  • trunk/src/core/RpUnitsStd.h

    r999 r1427  
    146146double pOH2pH (double pOH);
    147147
     148
     149
     150double tesla2gauss (double tesla);
     151double gauss2tesla (double gauss);
     152double maxwell2weber (double maxwell);
     153double weber2maxwell (double weber);
     154
    148155#ifdef __cplusplus
    149156}
Note: See TracChangeset for help on using the changeset viewer.