| 1 | //--------------------------------------------------------------------------
 | 
|---|
| 2 | // File and Version Information:
 | 
|---|
| 3 | //      $Id: blackbody.cc,v 1.6 2000-04-14 07:28:11 ansari Exp $
 | 
|---|
| 4 | //
 | 
|---|
| 5 | // Description:
 | 
|---|
| 6 | //      Aim of the class: To give the energy density for a blackbody
 | 
|---|
| 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 "blackbody.h"
 | 
|---|
| 21 | 
 | 
|---|
| 22 | /*! 
 | 
|---|
| 23 |  * \class SOPHYA::BlackBody 
 | 
|---|
| 24 |  \ingroup SkyT
 | 
|---|
| 25 |  This class corresponds to the emission spectrum of a
 | 
|---|
| 26 |  blackbody radiation.
 | 
|---|
| 27 |  */
 | 
|---|
| 28 | //----------------
 | 
|---|
| 29 | // Constructor --
 | 
|---|
| 30 | //----------------
 | 
|---|
| 31 | /*! Constructor: needs a temperature. Otherwise set to ConvTools::tcmb */
 | 
|---|
| 32 | BlackBody::BlackBody(double temperature)
 | 
|---|
| 33 |   : RadSpectra(10., 10000.)
 | 
|---|
| 34 | {
 | 
|---|
| 35 |   _temperature = temperature;
 | 
|---|
| 36 | }
 | 
|---|
| 37 | 
 | 
|---|
| 38 | 
 | 
|---|
| 39 | BlackBody::~BlackBody()
 | 
|---|
| 40 | {
 | 
|---|
| 41 | }
 | 
|---|
| 42 | /*! Black Body Flux Function:
 | 
|---|
| 43 |   \f[
 | 
|---|
| 44 |   I_\nu = {2 h_{pl} (1.10^9*\nu)^3 \over c^2 (e^{{h_{pl}(1.10^9*\nu) \over kT}} -1)}
 | 
|---|
| 45 |   \f]
 | 
|---|
| 46 | */
 | 
|---|
| 47 | double
 | 
|---|
| 48 | BlackBody::flux(double nu) const
 | 
|---|
| 49 | {
 | 
|---|
| 50 |   if(nu < -1.e99) nu = -1.e99;
 | 
|---|
| 51 |   if(nu > 1.e99) nu = 1.e99;
 | 
|---|
| 52 |   double temperature = getTemperature();
 | 
|---|
| 53 |   if(nu==0.) return 0.;
 | 
|---|
| 54 |   double hpl = ConvTools::hpl;
 | 
|---|
| 55 |   double cel = ConvTools::cel;
 | 
|---|
| 56 |   double kb  = ConvTools::kb;
 | 
|---|
| 57 |   double puiss1 = nu*pow(10,9);
 | 
|---|
| 58 |   if(puiss1 >  1.e99)   puiss1=1.e99;
 | 
|---|
| 59 |   if(puiss1 < -1.e99)   puiss1=-1.e99;
 | 
|---|
| 60 |   double puiss2 = hpl*nu*pow(10,9)/(kb*temperature);
 | 
|---|
| 61 |   if(puiss2 >  1.e99)   puiss2=1.e99;
 | 
|---|
| 62 |   if(puiss2 < -1.e99)   puiss2=-1.e99;
 | 
|---|
| 63 |   
 | 
|---|
| 64 |   double result=
 | 
|---|
| 65 |    (2*hpl* pow( puiss1 ,3))/( pow(cel,2)*(exp(puiss2)-1));
 | 
|---|
| 66 |   return result;
 | 
|---|
| 67 | }
 | 
|---|
| 68 | 
 | 
|---|
| 69 | 
 | 
|---|
| 70 | void
 | 
|---|
| 71 | BlackBody::Print(ostream& os) const
 | 
|---|
| 72 | {
 | 
|---|
| 73 |   os << "BlackBody::Print Temp= " << getTemperature() 
 | 
|---|
| 74 |      << " - Fmin,Fmax= " << minFreq() << "," << maxFreq() << endl;
 | 
|---|
| 75 |   os << "MeanFreq= " << meanFreq() << "  Emission= " << flux(meanFreq()) << endl;
 | 
|---|
| 76 |   os << "PeakFreq= " << peakFreq() << "  Emission= " << flux(peakFreq()) << endl;
 | 
|---|
| 77 | 
 | 
|---|
| 78 | }
 | 
|---|
| 79 | 
 | 
|---|
| 80 | /*
 | 
|---|
| 81 | void 
 | 
|---|
| 82 | BlackBody::WriteSelf(POutPersist& s)  
 | 
|---|
| 83 | {
 | 
|---|
| 84 |   s.PutR8(this->getTemperature());
 | 
|---|
| 85 |   s.PutR8(this->minFreq());
 | 
|---|
| 86 |   s.PutR8(this->maxFreq());
 | 
|---|
| 87 | }
 | 
|---|
| 88 | 
 | 
|---|
| 89 | void
 | 
|---|
| 90 | BlackBody::ReadSelf(PInPersist& s)  
 | 
|---|
| 91 | {
 | 
|---|
| 92 |   s.GetR8(_temperature);
 | 
|---|
| 93 |   s.GetR8(_numin);
 | 
|---|
| 94 |   s.GetR8(_numax);
 | 
|---|
| 95 |   cout << " Temperature - minFreq - maxFreq " << endl; 
 | 
|---|
| 96 |   cout << _temperature << "-" << _numin << "-" << _numax << endl;
 | 
|---|
| 97 | }
 | 
|---|
| 98 | 
 | 
|---|
| 99 | */
 | 
|---|