antioch-0.4.0
Functions
photochemical_rate_unit.C File Reference
#include <limits>
#include <string>
#include <iostream>
#include <iomanip>
#include <fstream>
#include "antioch/vector_utils_decl.h"
#include "antioch/particle_flux.h"
#include "antioch/photochemical_rate.h"
#include "antioch/physical_constants.h"
#include "antioch/kinetics_parsing.h"
#include "antioch/vector_utils.h"

Go to the source code of this file.

Functions

template<typename Scalar >
int check_rate (const Scalar &rate_exact, const Scalar &rate)
 
template<typename Scalar >
int tester (std::string path_to_files)
 
int main (int argc, char *argv[])
 

Function Documentation

template<typename Scalar >
int check_rate ( const Scalar &  rate_exact,
const Scalar &  rate 
)

Definition at line 50 of file photochemical_rate_unit.C.

Referenced by tester().

51 {
52  const Scalar tol = std::numeric_limits<Scalar>::epsilon() * 100;
53  int return_flag = (rate_exact > tol); // not zero
54  if(return_flag)std::cout << "Error: rate is null" << std::endl;
55  if( std::abs( (rate - rate_exact)/rate_exact ) > tol )
56  {
57  std::cout << std::scientific << std::setprecision(16)
58  << "Error: Mismatch in rate values." << std::endl
59  << "rate = " << rate << std::endl
60  << "rate_exact = " << rate_exact << std::endl
61  << "relative error = " << std::abs(rate_exact - rate)/rate_exact << std::endl
62  << "tolerance = " << tol << std::endl;
63 
64  return_flag = 1;
65  }
66 
67  return return_flag;
68 }
int main ( int  argc,
char *  argv[] 
)

Definition at line 164 of file photochemical_rate_unit.C.

References antioch_error.

165 {
166  if( argc < 2 )
167  {
168  // TODO: Need more consistent error handling.
169  std::cerr << "Error: Must specify input files location." << std::endl;
170  antioch_error();
171  }
172 
173  return (tester<float>(std::string(argv[1])) ||
174  tester<double>(std::string(argv[1])) ||
175  tester<long double>(std::string(argv[1]))
176  );
177 }
#define antioch_error()
template<typename Scalar >
int tester ( std::string  path_to_files)

Definition at line 71 of file photochemical_rate_unit.C.

References check_rate(), Antioch::reset_parameter_of_rate(), Antioch::PhotochemicalRate< CoeffType, VectorCoeffType >::set_parameter(), Antioch::set_zero(), Antioch::KineticsModel::SIGMA, and Antioch::SigmaBinConverter< VectorCoeffType >::y_on_custom_grid().

72 {
73  std::ifstream CH4(path_to_files + "/CH4_hv_cs.dat");
74  std::ifstream hv(path_to_files + "/solar_flux.dat");
75 
76  std::string first_line;
77 
78  getline(CH4,first_line);
79  getline(hv,first_line);
80 
81  std::vector<Scalar> CH4_cs;
82  std::vector<Scalar> CH4_lambda;
83  std::vector<Scalar> hv_irr;
84  std::vector<Scalar> hv_lambda;
85 
86  while(!CH4.eof())
87  {
88  Scalar cs,l(-1);
89  CH4 >> l >> cs;
90  if(!CH4.good())break;
91  CH4_lambda.push_back(l);
92  CH4_cs.push_back(cs);
93  }
94  CH4.close();
95 
96  while(!hv.eof())
97  {
98  Scalar w,l(-1),dw;
99  hv >> l >> w >> dw;
100  if(!hv.good())break;
101  hv_lambda.push_back(l * 10); //nm -> Angström
102  hv_irr.push_back(w * 1e-4L // * 1e-4: m-2 -> cm-2
103  / (Antioch::Constants::Planck_constant<Scalar>() * Antioch::Constants::light_celerity<Scalar>() / l)// /(h*c/lambda): energy -> number of photons
104  / 10); // by Angström
105  }
106  hv.close();
107 
108  Antioch::ParticleFlux<std::vector<Scalar> > part_flux(hv_lambda,hv_irr);
109 
110  Antioch::PhotochemicalRate<Scalar, std::vector<Scalar> > rate_hv(CH4_cs,CH4_lambda);
111 
113  std::vector<Scalar> sigma_rescaled(hv_lambda.size());
114  bin.y_on_custom_grid(CH4_lambda,CH4_cs,hv_lambda,sigma_rescaled);
115 
116  Scalar rate = rate_hv.rate(part_flux);
117 
118  Scalar rate_exact(0);
119 
120  for(unsigned int il = 0; il < hv_lambda.size() - 1; il++)
121  {
122  rate_exact += sigma_rescaled[il] * hv_irr[il] * (hv_lambda[il+1] - hv_lambda[il]);
123  }
124 
125  int return_flag = check_rate(rate_exact,rate);
126 
127  // multiplying by 2 the cross-section
128  int il = CH4_cs.size() * 2 / 3;
129  CH4_cs[il] *= 2;
130 
131  bin.y_on_custom_grid(CH4_lambda,CH4_cs,hv_lambda,sigma_rescaled);
132 
133  Antioch::set_zero(rate_exact);
134  for(unsigned int il = 0; il < hv_lambda.size() - 1; il++)
135  {
136  rate_exact += sigma_rescaled[il] * hv_irr[il] * (hv_lambda[il+1] - hv_lambda[il]);
137  }
138  rate_hv.set_parameter(Antioch::KineticsModel::Parameters::SIGMA, il, CH4_cs[il]);
139  rate = rate_hv.rate(part_flux);
140 
141  return_flag = check_rate(rate_exact,rate) || return_flag;
142 
143  // multiplying by 2 one value of the cross-section
144  il = CH4_cs.size()/2;
145  CH4_cs[il] *= 2;
146 
147  bin.y_on_custom_grid(CH4_lambda,CH4_cs,hv_lambda,sigma_rescaled);
148 
149  Antioch::set_zero(rate_exact);
150  for(unsigned int il = 0; il < hv_lambda.size() - 1; il++)
151  {
152  rate_exact += sigma_rescaled[il] * hv_irr[il] * (hv_lambda[il+1] - hv_lambda[il]);
153  }
154 
155 // the other way to reset
157  rate = rate_hv.rate(part_flux);
158 
159  return_flag = check_rate(rate_exact,rate) || return_flag;
160 
161  return return_flag;
162 }
Stores the incoming flux of particles.
Definition: particle_flux.h:38
void reset_parameter_of_rate(KineticsType< CoeffType, VectorCoeffType > &rate, KineticsModel::Parameters parameter, const CoeffType new_value, const std::string &unit="SI")
The rate constant models derived from the Arrhenius model have an activation energy which is stored a...
int check_rate(const Scalar &rate_exact, const Scalar &rate)
void set_zero(_Matrix< _Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols > &a)
Definition: eigen_utils.h:217
void y_on_custom_grid(const VectorCoeffType &x_old, const VectorCoeffType &y_old, const VectorStateType &x_new, VectorStateType &y_new) const
Photochemical rate.
Definition: kinetics_type.h:65

Generated on Thu Jul 7 2016 11:09:47 for antioch-0.4.0 by  doxygen 1.8.8