Changeset 116 for trunk/test/src


Ignore:
Timestamp:
Oct 26, 2005, 11:32:52 PM (19 years ago)
Author:
dkearney
Message:
  1. rewrote RpUnits::define(...) and RpUnits::convert(...) fxns.
  2. added functionality so you no longer need to call add_presets(...)
  3. RpUnits can now handle conversions as follows 1cm2/Vs -> 1e-7m2/kVus
  4. Cannot handle conversions dealing with Temperature very well because

Temperature conversions have offsets (+/- 32...). you can still do
F->C and Fs->Cs, but Fms->Cs provides unreliable results. (not to
mention that i'm still unsure how to do a conversion like this.

  1. still need to add Fo (delta fahrenheit) and Co (delta celcius)

units and conversions. These should not be effected by the notorious
temperature

  1. adjusted RpUnits_test.cc for testing. python.fortran and matlab

bindings have not been tested yet.

Location:
trunk/test/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/src/RpUnitsF_test.f

    r115 r116  
    3030        print *,"72F = ",dblVal, " (no units)"
    3131        print *,"retVal = ",retVal
    32        
     32
    3333      end program units_test
    3434
  • trunk/test/src/RpUnits_test.cc

    r115 r116  
    4141    //
    4242    printf ("=============== TEST 1 ===============\n");
    43     const RpUnits * meters = RpUnits::define("m", NULL);
    44     // (meters) ? success() : fail();
    45     // RpUnits * centimeter = RpUnits::define("cm", NULL);
    46 
    47     RpUnits::makeMetric(meters);
    48     RpUnits::define("V", NULL);
    49     RpUnits::define("s", NULL);
    50 
    5143/*
    5244    std::string srch_str = std::string("cm");
     
    6153
    6254*/
    63    
     55
     56/*
    6457    const RpUnits* mobility = RpUnits::defineCmplx("cm2/Vs", NULL);
    6558    std::cout << "mobility = :" << mobility->getUnitsName() <<":"<< std::endl;
     
    7467        std::cout << "mobility2 dn exists" << std::endl;
    7568    }
    76 
     69*/
     70
     71    const RpUnits* meters = RpUnits::find("m");
    7772    const RpUnits* cmeters = RpUnits::find("cm");
    78     const RpUnits* angstrom = RpUnits::define("A", NULL);
    79     RpUnits::define(angstrom, meters, angstrom2meter, meter2angstrom);
     73    const RpUnits* angstrom = RpUnits::find("A");
    8074
    8175    value = angstrom->convert(meters,1.0,&result);
    8276    std::cout << "1 angstrom = " << value << " meters" << std::endl;
     77    std::cout << "result = " << result << std::endl;
    8378
    8479    result = 0;
     
    8782
    8883
    89     const RpUnits* fahrenheit  = RpUnits::define("F", NULL);
    90     const RpUnits* celcius  = RpUnits::define("C", NULL);
    91     const RpUnits* kelvin  = RpUnits::define("K", NULL);
    92    
    93     RpUnits::define(fahrenheit, celcius, fahrenheit2centigrade, centigrade2fahrenheit);
    94     RpUnits::define(celcius, kelvin, centigrade2kelvin, kelvin2centigrade);
    95    
     84    const RpUnits* fahrenheit  = RpUnits::find("F");
     85    const RpUnits* celcius  = RpUnits::find("C");
     86    const RpUnits* kelvin  = RpUnits::find("K");
     87
    9688    value = fahrenheit->convert(celcius,72,&result);
    9789    std::cout << "72 degrees fahrenheit = " << value << " degrees celcius" << std::endl;
    98    
     90
    9991    value = celcius->convert(fahrenheit,value,&result);
    10092    std::cout << "22.222 degrees celcius = " << value << " degrees fahrenheit" << std::endl;
    101    
     93
    10294    value = celcius->convert(kelvin,20,&result);
    10395    std::cout << "20 degrees celcius = " << value << " kelvin" << std::endl;
     
    264256
    265257
    266     const RpUnits* eV  = RpUnits::define("eV", NULL);
    267     const RpUnits* joules  = RpUnits::define("J", NULL);
    268 
    269     RpUnits::define(eV, joules, electronVolt2joule, joule2electronVolt);
     258    const RpUnits* eV  = RpUnits::find("eV");
     259    const RpUnits* joules  = RpUnits::find("J");
    270260
    271261    value = joules->convert(eV,1,&result);
     
    323313    delete testRpUnits;
    324314    std::cout << "copyRpUnits = " << copyRpUnits.getUnitsName() << std::endl;
     315
     316
     317    // test deleting a const object
     318
     319    const RpUnits* myobj = RpUnits::define("myunit",NULL);
     320    delete myobj;
     321
     322    // test /cm2
     323    // std::cout << "convert (3m3 -> cm3)     = " << RpUnits::convert("3m3","cm3",0) << std::endl;
     324    // std::cout << "convert (3/m3 -> /cm3)   = " << RpUnits::convert("3/m3","/cm3",0) << std::endl;
     325    // std::cout << "convert (300cm3 -> m3)   = " << RpUnits::convert("300cm3","m3",0) << std::endl;
     326    // std::cout << "convert (300/cm3 -> /m3) = " << RpUnits::convert("300/cm3","/m3",0) << std::endl;
     327
     328    std::cout << "convert (3m3 -> cm3)     = " << RpUnits::convert("3m3","cm3",0) << std::endl;
     329    std::cout << "convert (3/m3 -> /cm3)   = " << RpUnits::convert("3/m3","/cm3",0) << std::endl;
     330    std::cout << "convert (300cm3 -> m3)   = " << RpUnits::convert("300cm3","m3",0) << std::endl;
     331    std::cout << "convert (300/cm3 -> /m3) = " << RpUnits::convert("300/cm3","/m3",0) << std::endl;
     332    std::cout << "convert (72F -> 22.22C) = " << RpUnits::convert("72F","C",0) << std::endl;
     333    std::cout << "convert (5J -> 3.12075e+28neV) = " << RpUnits::convert("5J","neV",0) << std::endl;
     334    std::cout << "convert (5J2 -> 1.9478e+56neV2) = " << RpUnits::convert("5J2","neV2",0) << std::endl;
     335
     336    // testing complex units
     337    std::cout << "convert (1cm2/Vs -> 0.0001m2/Vs) = " << RpUnits::convert("1cm2/Vs","m2/Vs",0) << std::endl;
     338    std::cout << "convert (1cm2/Vs -> 0.1m2/kVs) = " << RpUnits::convert("1cm2/Vs","m2/kVs",0) << std::endl;
     339    std::cout << "convert (1cm2/Vs -> 1e-7m2/kVus) = " << RpUnits::convert("1cm2/Vs","m2/kVus",0) << std::endl;
     340
    325341    return 0;
     342
    326343}
Note: See TracChangeset for help on using the changeset viewer.