cantera/test_problems/spectroscopy/spectratest.cpp
2012-02-07 17:45:05 +00:00

87 lines
1.9 KiB
C++

/**
* @file spectratest.cpp
*
* $Author: $
* $Date: 2007/05/04 15:18:45 $
* $Revision: 1.3 $
*
* nick adding more useful on 2/7/12
*/
#include "Cantera.h"
#include "spectra.h"
#include "Nuclei.h"
#include <iostream>
using namespace std;
using namespace CanteraSpectra;
int main() {
Nucleus* a = CanteraSpectra::HydrogenNucleus();
Nucleus* b = HydrogenNucleus();
if (*a == *b) {
cout << "a and b and indistinguishable" << endl;
}
else
{
cout << "\nwhy are a and b not indistinguishable?\n";
return 1;
}
// test line broading classes
double gam = 2.0e0;
double sigma = 5.0;
LineBroadener* lor = new Lorentzian(gam);
LineBroadener* gaus = new Gaussian(sigma);
Voigt* voig = new Voigt(sigma, gam);
//voig->testv();
double dnu = 0.1;
double nu;
double sum = 0.0, sumg = 0.0, sumlor = 0.0;
for (int n = -2000; n < 2000; n++) {
//cout << n << endl;
nu = n*dnu;
sumg += gaus->profile(nu)*dnu;
sum += voig->profile(nu)*dnu;
sumlor += lor->profile(nu)*dnu;
//cout << nu << ", " << (*lor)(nu) << ", " << (*gaus)(nu)
// << ", " << (*voig)(nu) << endl;
}
/* old output
cout << "Voigt area = " << sum << endl;
cout << "Gaussian area = " << sumg << endl;
cout << "Lorentzian area = " << sumlor << endl;
*/
// 'blessed' output:
// Voigt area = 0.99363
// Gaussian area = 1
// Lorentzian area = 0.993634
// guessing a sane tolerance
double TOL = .0001;
if(abs(sum-.99363) > TOL)
{
cout << "\nVOIGT AREA REGRESSION TEST FAILURE\n";
return 1;
}
if(abs(sumg-1.0) > TOL)
{
cout << "\nGAUSSIAN AREA REGRESSION TEST FAILURE\n";
return 1;
}
if(abs(sumlor-.993634) > TOL)
{
cout << "\nLORENTZIAN AREA REGRESSION TEST FAILURE\n";
return 1;
}
// steady as she goes
return 0;
}