1 | //--------------------------------------------------------------------------
|
---|
2 | // File and Version Information:
|
---|
3 | // $Id: radspecvector.cc,v 1.7 2000-04-14 07:28:13 ansari Exp $
|
---|
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 | //----------------
|
---|
28 |
|
---|
29 | /*!
|
---|
30 | * \class SOPHYA::RadSpectraVec
|
---|
31 | \ingroup SkyT
|
---|
32 | * One may define the radiation
|
---|
33 | * spectrum with two vectors: <BR> one for the frequencies and the second for the
|
---|
34 | * value of the flux function. <BR>
|
---|
35 | * In that case, the class to use is RadSpectraVec !
|
---|
36 | */
|
---|
37 |
|
---|
38 | RadSpectraVec::RadSpectraVec()
|
---|
39 | {
|
---|
40 | }
|
---|
41 | /*! Constructor:
|
---|
42 | \param nu is the frequency vector <BR>
|
---|
43 | \param fdenu is the corresponding flux values (stored in a vector as well)
|
---|
44 | */
|
---|
45 | RadSpectraVec::RadSpectraVec(Vector const & nu, Vector const & fdenu, double numin, double numax)
|
---|
46 | : RadSpectra(numin, numax)
|
---|
47 | {
|
---|
48 | if(nu.NElts() != fdenu.NElts())
|
---|
49 | throw SzMismatchError("RadSpectraVec::RadSpectraVec() - Non equal vector sizes");
|
---|
50 | _vecOfNu = nu;
|
---|
51 | _vecOfFDeNu = fdenu;
|
---|
52 | _numin = nu(0);
|
---|
53 | _numax = nu(nu.NElts()-1);
|
---|
54 | }
|
---|
55 |
|
---|
56 |
|
---|
57 | //--------------
|
---|
58 | // Destructor --
|
---|
59 | //--------------
|
---|
60 | RadSpectraVec::~RadSpectraVec()
|
---|
61 | {
|
---|
62 | }
|
---|
63 |
|
---|
64 | // ---------------------------
|
---|
65 | // -- Function Definitions --
|
---|
66 | // ---------------------------
|
---|
67 |
|
---|
68 |
|
---|
69 |
|
---|
70 | /*! The flux function extrapolates the flux values for the
|
---|
71 | frequencies that are not present in the nu vector <BR>
|
---|
72 | given at the instanciation of the class.
|
---|
73 | */
|
---|
74 | double
|
---|
75 | RadSpectraVec::flux(double nu) const
|
---|
76 | {
|
---|
77 | if ( (nu < _numin) || (nu > _numax) ) return(0.);
|
---|
78 | double value = 0.;
|
---|
79 | int sizeVecOfNu = _vecOfNu.NElts();
|
---|
80 | if(nu <= _vecOfNu(0)) return _vecOfFDeNu(0);
|
---|
81 | if(nu >= _vecOfNu(sizeVecOfNu-1)) return _vecOfFDeNu(sizeVecOfNu-1);
|
---|
82 |
|
---|
83 | for (int i=1; i<sizeVecOfNu; i++)
|
---|
84 | {
|
---|
85 | if(nu < _vecOfNu(i))
|
---|
86 | {
|
---|
87 | double up = _vecOfFDeNu(i) ;
|
---|
88 | double down = _vecOfFDeNu(i-1);
|
---|
89 | double xmin = _vecOfNu(i-1);
|
---|
90 | double xmax = _vecOfNu(i);
|
---|
91 | double a = ((up-down)/(xmax-xmin));
|
---|
92 | value = a*nu+(up-a*xmax);
|
---|
93 | return value;
|
---|
94 | }
|
---|
95 | }
|
---|
96 | return _vecOfFDeNu(sizeVecOfNu-1);
|
---|
97 | }
|
---|
98 |
|
---|
99 |
|
---|
100 |
|
---|
101 | void
|
---|
102 | RadSpectraVec::Print(ostream& os) const
|
---|
103 | {
|
---|
104 | // os << "RadSpectraVec::Print (" << typeid(*this).name()
|
---|
105 | // << ") - Fmin,Fmax= " << minFreq() << "," << maxFreq() << endl;
|
---|
106 | os << "RadSpectraVec::Print - Fmin,Fmax= " << minFreq() << "," << maxFreq() << endl;
|
---|
107 | os << "MeanFreq= " << meanFreq() << " Emission= " << flux(meanFreq()) << endl;
|
---|
108 | os << "PeakFreq= " << peakFreq() << " Emission= " << flux(peakFreq()) << endl;
|
---|
109 |
|
---|
110 | }
|
---|
111 |
|
---|
112 | /*
|
---|
113 | void
|
---|
114 | RadSpectraVec::WriteSelf(POutPersist& s)
|
---|
115 | {
|
---|
116 | s.PutI4(this->NbElts());
|
---|
117 | for (int i=0; i< this->NbElts(); i++)
|
---|
118 | {
|
---|
119 | s.PutR8(this->getNuVec(i));
|
---|
120 | s.PutR8(this->getFNuVec(i));
|
---|
121 | }
|
---|
122 | s.PutR8(this->minFreq());
|
---|
123 | s.PutR8(this->maxFreq());
|
---|
124 |
|
---|
125 | }
|
---|
126 |
|
---|
127 | void
|
---|
128 | RadSpectraVec::ReadSelf(PInPersist& s)
|
---|
129 | {
|
---|
130 | s.GetI4(_size);
|
---|
131 |
|
---|
132 | _vecOfNu.ReSize(_size);
|
---|
133 | _vecOfFDeNu.ReSize(_size);
|
---|
134 | for (int i=0; i< _size; i++)
|
---|
135 | {
|
---|
136 | s.GetR8(_vecOfNu(i));
|
---|
137 | s.GetR8(_vecOfFDeNu(i));
|
---|
138 | }
|
---|
139 | s.GetR8(_numin);
|
---|
140 | s.GetR8(_numax);
|
---|
141 | cout << "minFreq - maxFreq"<< endl;
|
---|
142 | cout << _numin<< "-" << _numax << endl;
|
---|
143 | }
|
---|
144 | */
|
---|
145 |
|
---|
146 |
|
---|