[601] | 1 | //--------------------------------------------------------------------------
|
---|
| 2 | // File and Version Information:
|
---|
[909] | 3 | // $Id: radspecvector.cc,v 1.6 2000-04-13 14:10:45 ansari Exp $
|
---|
[601] | 4 | //
|
---|
| 5 | // Description:
|
---|
| 6 | // Aim of the class: To give the energy density
|
---|
| 7 | // The unity used here is W/m^2/Hz/sr
|
---|
| 8 | //
|
---|
| 9 | // History (add to end):
|
---|
| 10 | // Sophie Oct, 1999 - creation
|
---|
| 11 | //
|
---|
| 12 | //------------------------------------------------------------------------
|
---|
| 13 |
|
---|
| 14 | //---------------
|
---|
| 15 | // C++ Headers --
|
---|
| 16 | //---------------
|
---|
| 17 | #include "machdefs.h"
|
---|
| 18 | #include <iostream.h>
|
---|
| 19 | #include <math.h>
|
---|
| 20 | // #include <typeinfo>
|
---|
| 21 |
|
---|
| 22 | #include "radspecvector.h"
|
---|
| 23 | #include "pexceptions.h"
|
---|
| 24 |
|
---|
| 25 | //----------------
|
---|
| 26 | // Constructor --
|
---|
| 27 | //----------------
|
---|
[909] | 28 |
|
---|
| 29 | /*!
|
---|
| 30 | * \class SOPHYA::RadSpectraVec
|
---|
| 31 | * One may define the radiation
|
---|
| 32 | * spectrum with two vectors: <BR> one for the frequencies and the second for the
|
---|
| 33 | * value of the flux function. <BR>
|
---|
| 34 | * In that case, the class to use is RadSpectraVec !
|
---|
| 35 | */
|
---|
| 36 |
|
---|
[668] | 37 | RadSpectraVec::RadSpectraVec()
|
---|
| 38 | {
|
---|
| 39 | }
|
---|
[909] | 40 | /*! Constructor:
|
---|
| 41 | \param nu is the frequency vector <BR>
|
---|
| 42 | \param fdenu is the corresponding flux values (stored in a vector as well)
|
---|
| 43 | */
|
---|
[601] | 44 | RadSpectraVec::RadSpectraVec(Vector const & nu, Vector const & fdenu, double numin, double numax)
|
---|
| 45 | : RadSpectra(numin, numax)
|
---|
| 46 | {
|
---|
| 47 | if(nu.NElts() != fdenu.NElts())
|
---|
| 48 | throw SzMismatchError("RadSpectraVec::RadSpectraVec() - Non equal vector sizes");
|
---|
| 49 | _vecOfNu = nu;
|
---|
| 50 | _vecOfFDeNu = fdenu;
|
---|
| 51 | _numin = nu(0);
|
---|
| 52 | _numax = nu(nu.NElts()-1);
|
---|
| 53 | }
|
---|
| 54 |
|
---|
| 55 |
|
---|
| 56 | //--------------
|
---|
| 57 | // Destructor --
|
---|
| 58 | //--------------
|
---|
| 59 | RadSpectraVec::~RadSpectraVec()
|
---|
| 60 | {
|
---|
| 61 | }
|
---|
| 62 |
|
---|
| 63 | // ---------------------------
|
---|
| 64 | // -- Function Definitions --
|
---|
| 65 | // ---------------------------
|
---|
| 66 |
|
---|
| 67 |
|
---|
| 68 |
|
---|
[909] | 69 | /*! The flux function extrapolates the flux values for the
|
---|
| 70 | frequencies that are not present in the nu vector <BR>
|
---|
| 71 | given at the instanciation of the class.
|
---|
| 72 | */
|
---|
[601] | 73 | double
|
---|
| 74 | RadSpectraVec::flux(double nu) const
|
---|
| 75 | {
|
---|
| 76 | if ( (nu < _numin) || (nu > _numax) ) return(0.);
|
---|
[610] | 77 | double value = 0.;
|
---|
[601] | 78 | int sizeVecOfNu = _vecOfNu.NElts();
|
---|
[610] | 79 | if(nu <= _vecOfNu(0)) return _vecOfFDeNu(0);
|
---|
[601] | 80 | if(nu >= _vecOfNu(sizeVecOfNu-1)) return _vecOfFDeNu(sizeVecOfNu-1);
|
---|
| 81 |
|
---|
| 82 | for (int i=1; i<sizeVecOfNu; i++)
|
---|
| 83 | {
|
---|
[610] | 84 | if(nu < _vecOfNu(i))
|
---|
[601] | 85 | {
|
---|
| 86 | double up = _vecOfFDeNu(i) ;
|
---|
| 87 | double down = _vecOfFDeNu(i-1);
|
---|
| 88 | double xmin = _vecOfNu(i-1);
|
---|
| 89 | double xmax = _vecOfNu(i);
|
---|
| 90 | double a = ((up-down)/(xmax-xmin));
|
---|
| 91 | value = a*nu+(up-a*xmax);
|
---|
| 92 | return value;
|
---|
| 93 | }
|
---|
| 94 | }
|
---|
[610] | 95 | return _vecOfFDeNu(sizeVecOfNu-1);
|
---|
[601] | 96 | }
|
---|
| 97 |
|
---|
[669] | 98 |
|
---|
| 99 |
|
---|
[668] | 100 | void
|
---|
[669] | 101 | RadSpectraVec::Print(ostream& os) const
|
---|
| 102 | {
|
---|
| 103 | // os << "RadSpectraVec::Print (" << typeid(*this).name()
|
---|
| 104 | // << ") - Fmin,Fmax= " << minFreq() << "," << maxFreq() << endl;
|
---|
| 105 | os << "RadSpectraVec::Print - Fmin,Fmax= " << minFreq() << "," << maxFreq() << endl;
|
---|
| 106 | os << "MeanFreq= " << meanFreq() << " Emission= " << flux(meanFreq()) << endl;
|
---|
| 107 | os << "PeakFreq= " << peakFreq() << " Emission= " << flux(peakFreq()) << endl;
|
---|
| 108 |
|
---|
| 109 | }
|
---|
| 110 |
|
---|
| 111 | /*
|
---|
| 112 | void
|
---|
[668] | 113 | RadSpectraVec::WriteSelf(POutPersist& s)
|
---|
| 114 | {
|
---|
| 115 | s.PutI4(this->NbElts());
|
---|
| 116 | for (int i=0; i< this->NbElts(); i++)
|
---|
| 117 | {
|
---|
| 118 | s.PutR8(this->getNuVec(i));
|
---|
| 119 | s.PutR8(this->getFNuVec(i));
|
---|
| 120 | }
|
---|
| 121 | s.PutR8(this->minFreq());
|
---|
| 122 | s.PutR8(this->maxFreq());
|
---|
| 123 |
|
---|
| 124 | }
|
---|
[601] | 125 |
|
---|
| 126 | void
|
---|
[668] | 127 | RadSpectraVec::ReadSelf(PInPersist& s)
|
---|
| 128 | {
|
---|
| 129 | s.GetI4(_size);
|
---|
| 130 |
|
---|
| 131 | _vecOfNu.ReSize(_size);
|
---|
| 132 | _vecOfFDeNu.ReSize(_size);
|
---|
| 133 | for (int i=0; i< _size; i++)
|
---|
| 134 | {
|
---|
| 135 | s.GetR8(_vecOfNu(i));
|
---|
| 136 | s.GetR8(_vecOfFDeNu(i));
|
---|
| 137 | }
|
---|
| 138 | s.GetR8(_numin);
|
---|
| 139 | s.GetR8(_numax);
|
---|
| 140 | cout << "minFreq - maxFreq"<< endl;
|
---|
| 141 | cout << _numin<< "-" << _numax << endl;
|
---|
| 142 | }
|
---|
[669] | 143 | */
|
---|
[668] | 144 |
|
---|
| 145 |
|
---|