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 #include <map>
37 
38 #include "moab/Range.hpp"
39 #include "moab/Core.hpp"
40 #ifndef PYNE_IS_AMALGAMATED
41 #include "measure.h"
42 #endif
43 #include "moab/CartVect.hpp"
44 
45 #ifdef __cplusplus
46 extern "C" {
47 #endif
48 
49 namespace pyne {
50 
60  void sampling_setup_(int* mode, int* cell_list_size);
69  void particle_birth_(double* rands,
70  double* x,
71  double* y,
72  double* z,
73  double* e,
74  double* w,
75  int* cell_list);
78  std::vector<double> read_e_bounds(std::string e_bounds_file);
79 
81  struct edge_points {
82  moab::CartVect o_point;
83  moab::CartVect x_vec;
84  moab::CartVect y_vec;
85  moab::CartVect z_vec;
86  };
87 
89  class AliasTable {
90  public:
93  AliasTable(std::vector<double> p);
97  int sample_pdf(double rand1, double rand2);
98  ~AliasTable(){};
99  int n;
100  std::vector<double> prob;
101  std::vector<int> alias;
102  };
103 
104  // class Source particle
106  public:
107  SourceParticle();
115  SourceParticle(double x,
116  double y,
117  double z,
118  double e,
119  double w,
120  std::vector<int> cell_list);
121  ~SourceParticle();
122 
123  double get_x() {return x;};
124  double get_y() {return y;};
125  double get_z() {return z;};
126  double get_e() {return e;};
127  double get_w() {return w;};
128  std::vector<int> get_cell_list() {return cell_list;};
129  private:
130  double x; // x coordinate
131  double y; // y coordinate
132  double z; // z coordinate
133  double e; // energy
134  double w; // weight
136  std::vector<int> cell_list;
137  };
138 
140  enum BiasMode {USER, ANALOG, UNIFORM};
141  enum MeshMode {VOXEL, SUBVOXEL, TET};
142 
144  class Sampler {
145  public:
154  Sampler(std::string filename,
155  std::string src_tag_name,
156  std::vector<double> e_bounds,
157  bool uniform);
169  Sampler(std::string filename,
170  std::string src_tag_name,
171  std::vector<double> e_bounds,
172  std::string bias_tag_name);
179  Sampler(std::string filename,
180  std::map<std::string, std::string> tag_names,
181  std::vector<double> e_bounds,
182  int mode);
183 
188  pyne::SourceParticle particle_birth(std::vector<double> rands);
189 
191  int get_cell_list_size();
192 
193  ~Sampler() {
194  delete mesh;
195  delete at;
196  };
197 
198  // member variables
199  private:
200  // problem parameters
201  std::string filename;
202  std::string src_tag_name;
203  std::string bias_tag_name;
204  std::string cell_number_tag_name;
205  std::string cell_fracs_tag_name;
206  std::map<std::string, std::string> tag_names;
207  std::vector<double> e_bounds;
208  int num_e_groups;
209  int num_bias_groups;
210  int max_num_cells;
211  // Equivalent cell number in photon source.
212  // For voxel R2S, p_src_num_cells = 1
213  // For sub-voxel R2S, p_src_num_cells = max_num_cells
214  // For unstructured R2S, p_src_num_cells = 1.
215  int p_src_num_cells;
216  int cell_list_size;
217  bool has_cell_fracs;
218  BiasMode bias_mode;
219  MeshMode mesh_mode;
220  int mode;
221  // mesh
222  moab::Interface* mesh;
223  int num_ves;
224  moab::EntityType ve_type;
225  int verts_per_ve;
226  // sampling
227  std::vector<edge_points> all_edge_points;
228  std::vector<double> biased_weights;
229  std::vector<int> cell_number;
230  std::vector<int> cell_list;
231  std::vector<double> cell_fracs;
232  AliasTable* at;
233 
234  // member functions
235  private:
236  // instantiation
237  void setup();
238  void mesh_geom_data(moab::Range ves, std::vector<double> &volumes);
239  void mesh_tag_data(moab::Range ves, const std::vector<double> volumes);
240  // select birth parameters
241  moab::CartVect sample_xyz(int ve_idx, std::vector<double> rands);
242  double sample_e(int e_idx, double rand);
243  double sample_w(int pdf_idx);
244  // helper functions
245  void normalize_pdf(std::vector<double> & pdf);
246  int num_groups(moab::Tag tag);
247  std::vector<double> read_bias_pdf(moab::Range ves, std::vector<double> volumes,
248  std::vector<double> pdf);
249  // Get max_num_cells
250  int get_max_num_cells(moab::Tag cell_fracs_tag);
251  // get has_cell_fracs
252  bool check_cell_fracs(moab::Tag cell_fracs_tag);
253  };
254 } //end namespace pyne
255 
256 #ifdef __cplusplus
257 } // extern "C"
258 #endif
259 
260 #endif // PYNE_6OR6BJURKJHHTOFWXO2VMQM5EY
void particle_birth_(double *rands, double *x, double *y, double *z, double *e, double *w, int *cell_list)
Definition: source_sampling.cpp:31
Stores 4 connected points in a mesh volume element.
Definition: source_sampling.h:81
Definition: source_sampling.h:105
std::vector< int > alias
Probabilities.
Definition: source_sampling.h:101
Mesh based Monte Carlo source sampling.
Definition: source_sampling.h:144
std::vector< double > read_e_bounds(std::string e_bounds_file)
Definition: source_sampling.cpp:50
BiasMode
Problem modes.
Definition: source_sampling.h:140
A container representing enrichment cascades.
Definition: _atomic_data.h:16
void sampling_setup_(int *mode, int *cell_list_size)
Definition: source_sampling.cpp:11
std::vector< double > prob
Number of bins in the PDF.
Definition: source_sampling.h:100
A data structure for O(1) source sampling.
Definition: source_sampling.h:89