PyNE C++
source_sampling.h
Go to the documentation of this file.
1 
24 #ifndef PYNE_6OR6BJURKJHHTOFWXO2VMQM5EY
25 #define PYNE_6OR6BJURKJHHTOFWXO2VMQM5EY
26 
27 #include <assert.h>
28 #include <iostream>
29 #include <fstream>
30 #include <stdio.h>
31 #include <stdlib.h>
32 #include <vector>
33 #include <stdexcept>
34 #include <sstream>
35 #include <string>
36 
37 #include "moab/Range.hpp"
38 #include "moab/Core.hpp"
39 #include "measure.h"
40 #include "moab/CartVect.hpp"
41 
42 #ifdef __cplusplus
43 extern "C" {
44 #endif
45 
46 namespace pyne {
47 
50  void sampling_setup_(int* mode);
58  void particle_birth_(double* rands,
59  double* x,
60  double* y,
61  double* z,
62  double* e,
63  double* w);
66  std::vector<double> read_e_bounds(std::string e_bounds_file);
67 
69  struct edge_points {
70  moab::CartVect o_point;
71  moab::CartVect x_vec;
72  moab::CartVect y_vec;
73  moab::CartVect z_vec;
74  };
75 
77  class AliasTable {
78  public:
81  AliasTable(std::vector<double> p);
85  int sample_pdf(double rand1, double rand2);
86  ~AliasTable(){};
87  int n;
88  std::vector<double> prob;
89  std::vector<int> alias;
90  };
91 
93  enum Mode {USER, ANALOG, UNIFORM};
94 
96  class Sampler {
97  public:
106  Sampler(std::string filename,
107  std::string src_tag_name,
108  std::vector<double> e_bounds,
109  bool uniform);
121  Sampler(std::string filename,
122  std::string src_tag_name,
123  std::vector<double> e_bounds,
124  std::string bias_tag_name);
129  std::vector<double> particle_birth(std::vector<double> rands);
130  ~Sampler() {
131  delete mesh;
132  delete at;
133  };
134 
135  // member variables
136  private:
137  // problem parameters
138  std::string filename;
139  std::string src_tag_name;
140  std::string bias_tag_name;
141  std::vector<double> e_bounds;
142  int num_e_groups;
143  int num_bias_groups;
144  Mode mode;
145  // mesh
146  moab::Interface* mesh;
147  int num_ves;
148  moab::EntityType ve_type;
149  int verts_per_ve;
150  // sampling
151  std::vector<edge_points> all_edge_points;
152  std::vector<double> biased_weights;
153  AliasTable* at;
154 
155  // member functions
156  private:
157  // instantiation
158  void setup();
159  void mesh_geom_data(moab::Range ves, std::vector<double> &volumes);
160  void mesh_tag_data(moab::Range ves, const std::vector<double> volumes);
161  // select birth parameters
162  moab::CartVect sample_xyz(int ve_idx, std::vector<double> rands);
163  double sample_e(int e_idx, double rand);
164  double sample_w(int pdf_idx);
165  // helper functions
166  void normalize_pdf(std::vector<double> & pdf);
167  int num_groups(moab::Tag tag);
168  std::vector<double> read_bias_pdf(moab::Range ves, std::vector<double> volumes,
169  std::vector<double> pdf);
170  };
171 } //end namespace pyne
172 
173 #ifdef __cplusplus
174 } // extern "C"
175 #endif
176 
177 #endif // PYNE_6OR6BJURKJHHTOFWXO2VMQM5EY
Stores 4 connected points in a mesh volume element.
Definition: source_sampling.h:69
std::vector< int > alias
Probabilities.
Definition: source_sampling.h:89
Mesh based Monte Carlo source sampling.
Definition: source_sampling.h:96
void sampling_setup_(int *mode)
Definition: source_sampling.cpp:9
void particle_birth_(double *rands, double *x, double *y, double *z, double *e, double *w)
Definition: source_sampling.cpp:26
Mode
Problem modes.
Definition: source_sampling.h:93
std::vector< double > read_e_bounds(std::string e_bounds_file)
Definition: source_sampling.cpp:41
A container representing enrichment cascades.
Definition: _atomic_data.h:7
std::vector< double > prob
Number of bins in the PDF.
Definition: source_sampling.h:88
A data structure for O(1) source sampling.
Definition: source_sampling.h:77