Loading...
Searching...
No Matches
ITHACAsampling.C
Go to the documentation of this file.
1#include "ITHACAsampling.H"
2
3std::vector<std::string> ITHACAsampling::distributions = {"UNIFORM", "NORMAL", "POISSON", "EXPONENTIAL"};
4
5Eigen::VectorXd ITHACAsampling::samplingMC(std::string pdftype, double& lowerE,
6 double& upperE, double& distpara1, double& distpara2, label& Npoints)
7{
8 std::random_device rd;
9 std::mt19937 generator(rd());
10
11 //to make it non-case sensitive
12 for (label i = 0; i < pdftype.size(); i++)
13 {
14 pdftype[i] = toupper(pdftype[i]);
15 }
16
17 label pos = -1;
18 bool pdf_found = false;
19 Eigen::VectorXd samplingVector;
20 samplingVector.resize(Npoints);
21 std::uniform_real_distribution<> dist0(distpara1, distpara2);
22 std::normal_distribution<> dist1(distpara1, distpara2);
23 std::poisson_distribution<> dist2(distpara1);
24 std::exponential_distribution<> dist3(distpara1);
25
26 for (label j = 0; j < distributions.size(); j++)
27 {
28 if (pdftype == distributions[j])
29 {
30 pdf_found = true;
31 pos = j;
32 }
33 }
34
35 double random;
36 label p_counter = 0;
37
38 if (pdf_found == true)
39 {
40 while (p_counter < samplingVector.size())
41 {
42 switch (pos)
43 {
44 case 0:
45 random = dist0(generator);
46 break;
47
48 case 1:
49 random = dist1(generator);
50 break;
51
52 case 2:
53 random = dist2(generator);
54 break;
55
56 case 3:
57 random = dist3(generator);
58 break;
59 }
60
61 if (random >= lowerE && random <= upperE)
62 {
63 samplingVector(p_counter) = random;
64 p_counter++;
65 }
66 }
67 }
68 else
69 {
70 std::cout << "pdf '" << pdftype << "' not implemented, programm aborted" <<
71 std::endl;
72 exit(0);
73 }
74
75 return samplingVector;
76}
static Eigen::VectorXd samplingMC(std::string pdftype, double &lowerE, double &upperE, double &distpara1, double &distpara2, label &Npoints)
label i
Definition pEqn.H:46