ViennaSHE 1.3.0
Free open-source semiconductor device simulator using spherical harmonics expansions techniques.
bernoulli.hpp
Go to the documentation of this file.
1#ifndef VIENNASHE_MATH_BERNOULLI_HPP
2#define VIENNASHE_MATH_BERNOULLI_HPP
3
4/* ============================================================================
5 Copyright (c) 2011-2022, Institute for Microelectronics,
6 Institute for Analysis and Scientific Computing,
7 TU Wien.
8
9 -----------------
10 ViennaSHE - The Vienna Spherical Harmonics Expansion Boltzmann Solver
11 -----------------
12
13 http://viennashe.sourceforge.net/
14
15 License: MIT (X11), see file LICENSE in the base directory
16=============================================================================== */
17
18
19#include <math.h>
20
27namespace viennashe
28{
29 namespace math
30 {
31
33 template <typename NumericT>
34 NumericT Bernoulli(NumericT x)
35 {
36 /*if (fabs(x) > 0.001)
37 return x/(exp(x) - 1.0);
38 else //avoids round-off errors due to exp(x) - 1
39 return 1.0 / (1.0 + x / 2.0 + x*x / 6.0);*/
40 if (fabs(x) > 0.01)
41 return x/(exp(x) - 1.0);
42 else //avoids round-off errors due to exp(x) - 1
43 return 1.0 / (1.0 + x / 2.0 + x*x / 6.0 + x*x*x/24.0);
44 }
45
46
48 template <typename NumericT>
49 NumericT Bernoulli_dx(NumericT x)
50 {
51 if (fabs(x) > 1e-4)
52 {
53 double exp_x = exp(x);
54 return (exp_x - 1.0 - x * exp_x) / (exp_x - 1.0) / (exp_x - 1.0);
55 }
56 else // replace by first-order Taylor expansion at x = 0
57 return -0.5 + x / 6.0;
58 }
59
60
61 } //namespace math
62} //namespace viennashe
63#endif
NumericT Bernoulli_dx(NumericT x)
Derivative of the Bernoulli function. f'(x) = [exp(x) - 1 - x exp(x)] / (exp(x) - 1)^2....
Definition: bernoulli.hpp:49
NumericT Bernoulli(NumericT x)
The Bernoulli function f(x) = x / (exp(x) - 1). Avoids round-off errors near zero.
Definition: bernoulli.hpp:34
The main ViennaSHE namespace. All functionality resides inside this namespace.
Definition: accessors.hpp:40