source: Sophya/trunk/SophyaLib/SkyT/radspecvector.cc@ 4035

Last change on this file since 4035 was 2615, checked in by cmv, 21 years ago

using namespace sophya enleve de machdefs.h, nouveau sopnamsp.h cmv 10/09/2004

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