Changeset 4062 in Sophya


Ignore:
Timestamp:
Apr 27, 2012, 12:26:07 AM (12 years ago)
Author:
ansari
Message:

Petites ameliorations classes Units et PhysQty, documentation doxygen, ajout fichiers pqnumber.h et sunitpcst.h ds basetools.h, passage numero de version a 2.30, Reza 27/04/2012

Location:
trunk/SophyaLib/BaseTools
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/SophyaLib/BaseTools/basetools.h

    r4051 r4062  
    2727#include "randtmt32.h"
    2828#include "randtmt64.h"
    29 
     29#include "pqnumber.h"
     30#include "pqnumber.h"
     31#include "sunitpcst.h"
    3032#endif
  • trunk/SophyaLib/BaseTools/pqnumber.cc

    r4056 r4062  
    1515   \code
    1616   // Create a PrimeNumbers object
     17   // Create a PrimeNumbers object
    1718   PrimeNumbers primes;
    18    // Print the first 15 primes ...
    19    for(size_t k=0; k<15; k++)
    20      cout << primes(k) << endl;
     19   // Print the prime numbers from rank 20 to 25 ...
     20   cout << " Primes[20...30]: " ;
     21   for(size_t k=19; k<30; k++) cout << primes(k) << "  ";
    2122   // Print all prime numbers less than some max values
    22    uint_8 pmax = 223;
    23    uint_8 p = primes.Next();
     23   uint_8 p = primes.Next();  uint_8 pmax = 223;
     24   cout << endl << " Primes < " << pmax << " : " << endl;
    2425   while (p<pmax) {
    25      cout << p << endl;
    26      p = primes.Next();
     26    cout << p << "  ";
     27    p = primes.Next();
    2728   }
     29   cout << endl;
     30   // Compute and print prime factor decomposition:
     31   uint_8 nombre=247890;
     32   vector<uint_8> pfac=primes.PrimeFactors(nombre, true);
     33   cout << " PrimeFactors[" << nombre << "]: ";
     34   for(size_t i=0; i<pfac.size(); i++) cout << pfac[i] << "   ";   
     35   cout << endl;
    2836   \endcode
    2937*/
     
    266274   
    267275   \code
    268    // Create rational numbers from integers
     276   // Create rational numbers from pairs of integers
    269277   QNumber q1(3,4), q2(5,6), q3(6,8);
    270278   // Operations and comparsion
     
    272280   cout << q1 << " + " << q2 << " = " << q4 << endl;
    273281   QNumber qa(q1), qb(q2);
    274    cout " Test qa==qb : -> " << qa << " ?== " << qb;
     282   cout << " Test qa==qb : -> " << qa << " ?== " << qb;
    275283   if (qa == qb)  cout << " -> true " << endl;
    276284   else cout << " -> false " << endl;
    277285   qb = q3;
    278    cout " Test qa==qb : -> " << qa << " ?== " << qb;
     286   cout << " Test qa==qb : -> " << qa << " ?== " << qb;
    279287   if (qa == qb)  cout << " -> true " << endl;
    280288   else cout << " -> false " << endl;
  • trunk/SophyaLib/BaseTools/sunitpcst.cc

    r4056 r4062  
    77   \class Units
    88   \ingroup BaseTools
    9    Class for representing physical units
     9   This class represents physical dimension and units. Static methods return Units
     10   objects corresponding to the usual units, such as meter or watt
    1011   
    1112   \code
    12    // Create ....
     13   Units w=Units::watt();
     14   cout << " Power unit (watt) : " << w.Name() << " (" << w << ")" << endl;
     15   // define the speed SI unit (m/s) :
     16   Units mos = Units::meter()/Units::second() ;
     17   cout << " SI speed unit : " << mos << "  -> "; mos.Print() ; 
     18   // mutiple of an existing unit :
     19   Units mw=Units::watt().mega();
     20   cout << " Megawatt: " << mw.Name() << " (" << mw << ")  -> "; mw.Print() ;
    1321   \endcode
    1422*/
     
    2634
    2735/* --Methode-- */
     36/*!
     37  The Units object is created by specifying its name and short name, and the integer powers
     38  for the seven SI base physical quantities (length, mass, time \ldots), and the value of the
     39  unit in term of the SI unit.
     40*/
    2841Units::Units(const char* nom, const char* snom, int m, int kg, int s, r_8 val, int A, int K, int mol, int cd)
    2942  : mLength_(m), mMass_(kg), mTime_(s), mCurr_(A),
     
    3851{
    3952  Set(un);
     53}
     54
     55/* --Methode-- */
     56Units::Units(Units const& un, r_8 scale, const char* nom, const char* snom)
     57{
     58  Set(un);
     59  mSI_Value_*=scale;
     60  mName_=nom;
     61  mShortName_=snom;
    4062}
    4163
     
    179201   \class PhysQty
    180202   \ingroup BaseTools
    181    Class for representing physical quantities and constants
     203   Class for representing physical quantities and constants. A physical quantity
     204   has a unit and a value, and optionally a precision and/or a name. A number of
     205   physical constants and standard quantities can be obtained as PhysQty objects
     206   through static methods.
    182207   
     208   \sa SOPHYA::Units
     209
    183210   \code
    184    // Create ....
     211   cout <<  " k_Boltzmann: " << PhysQty::k() << endl;
     212   cout <<  " m_e: " << PhysQty::electron_mass() << endl;
     213   // Conversion of a quantity to a different unit
     214   PhysQty aj(Units::joule(), 25.);
     215   PhysQty aev=aj.ConvertTo(Units::electronvolt().giga());
     216   cout <<  " A : " << aj << " -> " << aev << endl;
    185217   \endcode
    186218*/
     
    191223
    192224/* --Methode-- */
     225//! Default constructor: zero valued dimensionless quantity
    193226PhysQty::PhysQty()
    194227  : unit_(), val_(0.), prec_(0.)
     
    197230
    198231/* --Methode-- */
     232/*!
     233  \brief standard constructor
     234  The object is constructed through the specification of the unit \b u, the value \b val,
     235  and optional relative precision \b prec (=delta val/val) and an optional name.
     236*/
    199237PhysQty::PhysQty(Units const & u, r_8 val, r_8 prec, const char* nom)
    200238  : unit_(u), val_(val), prec_(prec), name_((nom==NULL)?"":nom)
     
    203241
    204242/* --Methode-- */
     243//! Copy constructor
    205244PhysQty::PhysQty(PhysQty const & qty)
    206245  : unit_(qty.unit_), val_(qty.val_), prec_(qty.prec_), name_(qty.name_)
  • trunk/SophyaLib/BaseTools/sunitpcst.h

    r4056 r4062  
    3232
    3333public:
     34  //! Default constructor - creates a dimensionless object = 1
    3435  Units();
     36  //! Copy constructor
    3537  Units(Units const& un);
     38  //! Base constructor 
    3639  Units(const char* nom, const char* snom, int m, int kg, int s, r_8 val=1., int A=0, int K=0, int mol=0, int cd=0);
     40  //! Constructor from an existing unit, but with a scaling factor and new name   
     41  Units(Units const& un, r_8 scale, const char* nom, const char* snom);
     42
    3743  virtual ~Units();
    3844
     
    8894
    8995  // Les unites usuelles - Voir definition et convention sur
     96  //  http://www.bipm.org/fr/si/   et  http://physics.nist.gov/cuu/Units/
    9097  inline static Units meter()
    9198  { return Units("meter","m",1,0,0); }
     
    153160  inline static Units radian()
    154161  { return Units("radian","rad",0,0,0,1);  }
     162  inline static Units degree()
     163  { return Units("degree","deg",0,0,0,M_PI/180.);  }
    155164  inline static Units steradian()
    156165  { return Units("steradian","sr",0,0,0,1);  }
     
    219228  //! Return the physical quantity value in SI units
    220229  inline r_8 SIValue()  const { return val_*unit_.SIValue(); }
     230  //! Return the associated unit
    221231  inline Units getUnit()  {return unit_; }
     232  //! Return the associated value
    222233  inline r_8 Value()  const { return val_; }
     234  //! Change the value of the physical quantity
    223235  inline void setValue(r_8 val)  { val_=val; }
     236  //! Return the relative precision
    224237  inline r_8 RelativePrecision()  const { return prec_; }
     238  //! Change the relative precision
    225239  inline void setRelativePrecision(r_8 prec) { prec_=prec; }
     240  //! Return the absolute precision
    226241  inline r_8 AbsolutePrecision() const { return prec_*val_; }
    227   //! return the unit name
     242  //! Return the associoated name
    228243  inline string const& Name() const { return name_; }
    229244
  • trunk/SophyaLib/BaseTools/sversion.h

    r4056 r4062  
    33
    44#define SOPHYA_VERSION   2.2
    5 #define SOPHYA_REVISION  22
     5#define SOPHYA_REVISION  30
    66#define SOPHYA_TAG       "V_Avr2012"
    77
Note: See TracChangeset for help on using the changeset viewer.