Added Integration Method and Bug fix, which lead to T5+ recombination rate being way too high.

This commit is contained in:
Christian
2019-11-14 12:28:31 +01:00
parent 7fca174042
commit aef20ad949
6 changed files with 110 additions and 65 deletions
+69
View File
@@ -0,0 +1,69 @@
//
// integrater.h
// mc_electron
//
// Created by Christian Reiling on 14.11.19.
// Copyright © 2019 Christian Reiling. All rights reserved.
//
#ifndef integrater_h
#define integrater_h
// Integrater from https://rosettacode.org/wiki/Numerical_integration#C.2B.2B
// the integration routine
template<typename Method, typename F, typename Float>
double integrate(F f, Float a, Float b, int steps, Method m)
{
double s = 0;
double h = (b-a)/steps;
for (int i = 0; i < steps; ++i)
s += m(f, a + h*i, h);
return h*s;
}
// methods
class rectangular
{
public:
enum position_type { left, middle, right };
rectangular(position_type pos): position(pos) {}
template<typename F, typename Float>
double operator()(F f, Float x, Float h) const
{
switch(position)
{
case left:
return f(x);
case middle:
return f(x+h/2);
case right:
return f(x+h);
}
}
private:
const position_type position;
};
class trapezium
{
public:
template<typename F, typename Float>
double operator()(F f, Float x, Float h) const
{
return (f(x) + f(x+h))/2;
}
};
class simpson
{
public:
template<typename F, typename Float>
double operator()(F f, Float x, Float h) const
{
return (f(x) + 4*f(x+h/2) + f(x+h))/6;
}
};
#endif /* integrater_h */