PyNE C++
material.h
1 
8 #ifndef PYNE_MR34UE5INRGMZK2QYRDWICFHVM
9 #define PYNE_MR34UE5INRGMZK2QYRDWICFHVM
10 
11 #include <iostream>
12 #include <fstream>
13 #include <string>
14 #include <map>
15 #include <set>
16 #include <stdio.h>
17 #include <stdlib.h>
18 #include <sstream> // std::ostringstream
19 
20 #if !defined(JSON_IS_AMALGAMATION)
21  #define JSON_IS_AMALGAMATION
22 #endif
23 
24 #ifndef PYNE_IS_AMALGAMATED
25 #include "json-forwards.h"
26 #include "json.h"
27 #include "h5wrap.h"
28 #include "utils.h"
29 #include "nucname.h"
30 #include "data.h"
31 #include "decay.h"
32 #endif
33 
34 namespace pyne
35 {
36  // Set Type Definitions
37  typedef std::map<int, double> comp_map;
38  typedef comp_map::iterator comp_iter;
39 
40  #ifdef PYNE_IS_AMALGAMATED
41  namespace decayers {
42  extern comp_map decay(comp_map, double);
43  } // namespace decayers
44  #endif
45 
46 
47  // These 37 strings are predefined FLUKA materials.
48  // Materials not on this list requires a MATERIAL card.
49  static std::string fluka_mat_strings[] = {
50  "BLCKHOLE", "VACUUM", "HYDROGEN", "HELIUM", "BERYLLIU", "CARBON",
51  "NITROGEN", "OXYGEN", "MAGNESIU", "ALUMINUM", "IRON", "COPPER",
52  "SILVER", "SILICON", "GOLD", "MERCURY", "LEAD", "TANTALUM",
53  "SODIUM", "ARGON", "CALCIUM", "TIN", "TUNGSTEN", "TITANIUM",
54  "NICKEL", "WATER", "POLYSTYR", "PLASCINT", "PMMA", "BONECOMP",
55  "BONECORT", "MUSCLESK", "MUSCLEST", "ADTISSUE", "KAPTON", "POLYETHY", "AIR"
56  };
57 
58  static int FLUKA_MAT_NUM = 37;
59 
61  class Material
62  {
63  protected:
64 
66  double get_comp_sum ();
67 
68  public:
69 
70  // Material Constructors
71  Material ();
72  Material(comp_map cm, double m=-1.0, double d=-1.0, double apm=-1.0,
80  Json::Value attributes=Json::Value(Json::objectValue));
93  Material(char * filename, double m=-1.0, double d=-1.0, double apm=-1.0,
94  Json::Value attributes=Json::Value(Json::objectValue));
107  Material(std::string filename, double m=-1.0, double d=-1.0, double apm=-1.0,
108  Json::Value attributes=Json::Value(Json::objectValue));
109  ~Material ();
110 
112  void norm_comp ();
113 
114  // Persistence functions.
115 
121  void _load_comp_protocol0(hid_t db, std::string datapath, int row);
122 
128  void _load_comp_protocol1(hid_t db, std::string datapath, int row);
129 
135  void from_hdf5(char * filename, char * datapath, int row=-1, int protocol=1);
136 
142  void from_hdf5(std::string filename, std::string datapath="/material",
143  int row=-1, int protocol=1);
144 
154  void write_hdf5(char * filename, char * datapath, char * nucpath, float row=-0.0,
155  int chunksize=100);
165  void write_hdf5(std::string filename, std::string datapath="/material",
166  std::string nucpath="/nucid", float row=-0.0, int chunksize=100);
167 
169  std::string mcnp(std::string frac_type = "mass");
172  std::string fluka(int id, std::string frac_type = "mass");
174  bool not_fluka_builtin(std::string fluka_name);
176  std::string fluka_material_str(int id);
178  std::string fluka_material_component(int fid, int nucid,
179  std::string fluka_name);
181  std::string fluka_material_line(int znum, double atomic_mass,
182  int fid, std::string fluka_name);
184  std::string fluka_format_field(float field);
187  std::string fluka_compound_str(int id, std::string frac_type = "mass");
188 
190  void from_text(char * filename);
192  void from_text(std::string filename);
193 
195  void write_text(char * filename);
197  void write_text(std::string filename);
198 
200  void load_json(Json::Value);
202  Json::Value dump_json();
204  void from_json(char * filename);
206  void from_json(std::string filname);
208  void write_json(char * filename);
210  void write_json(std::string filename);
211 
212  // Fundemental mass stream data
214  comp_map comp;
215  double mass;
216  double density;
218  Json::Value metadata;
220 
221  // Material function definitions
222  void normalize ();
223  comp_map mult_by_mass();
231  double molecular_mass(double apm=-1.0);
234  comp_map activity();
238  comp_map decay_heat();
248  comp_map dose_per_g(std::string dose_type, int source=0);
251  Material expand_elements();
252  // Returns a copy of the current material where all the isotopes of the elements
253  // are added up, atomic-fraction-wise, unless they are in the exception set
254  Material collapse_elements(std::set<int> exception_znum);
255  // Wrapped version to facilitate calling from python
256  Material collapse_elements(int **int_ptr_arry);
257  // void print_material( pyne::Material test_mat);
262  double mass_density(double num_dens=-1.0, double apm=-1.0);
268  double number_density(double mass_dens=-1.0, double apm=-1.0);
269 
270  // Sub-Stream Computation
273  Material sub_mat(std::set<int> nucset);
276  Material sub_mat(std::set<std::string> nucset);
277 
281  Material set_mat(std::set<int> nucset, double value);
284  Material set_mat(std::set<std::string> nucset, double value);
285 
288  Material del_mat(std::set<int> nucset);
291  Material del_mat(std::set<std::string> nucset);
292 
294  Material sub_range(int lower=0, int upper=10000000);
297  Material set_range(int lower=0, int upper=10000000, double value=0.0);
299  Material del_range(int lower=0, int upper=10000000);
300 
303  Material sub_elem(int element);
305  Material sub_lan();
307  Material sub_act();
309  Material sub_tru();
311  Material sub_ma();
313  Material sub_fp();
314 
315  // Atom fraction functions
318  std::map<int, double> to_atom_frac();
321  void from_atom_frac(std::map<int, double> atom_fracs);
322 
325  std::map<int, double> to_atom_dens();
326 
327  // Radioactive Material functions
330  std::vector<std::pair<double, double> > gammas();
333  std::vector<std::pair<double, double> > xrays();
336  std::vector<std::pair<double, double> > photons(bool norm);
339  std::vector<std::pair<double, double> > normalize_radioactivity(
340  std::vector<std::pair<double, double> > unnormed);
341 
343  Material decay(double t);
344 
345  // Overloaded Operators
347  Material operator+ (double);
349  Material operator+ (Material);
351  Material operator* (double);
353  Material operator/ (double);
354  };
355 
358  std::ostream& operator<< (std::ostream& os, Material mat);
359 
362  typedef struct material_data {
363  double mass;
364  double density;
365  double atoms_per_mol;
366  double comp[1];
367  } material_data;
368 
370  class MaterialProtocolError: public std::exception
371  {
373  virtual const char* what() const throw()
374  {
375  return "Invalid loading protocol number; please use 0 or 1.";
376  }
377  };
378 
379 // End pyne namespace
380 }
381 
382 #endif // PYNE_MR34UE5INRGMZK2QYRDWICFHVM
comp_map::iterator comp_iter
Nuclide-mass composition iter type.
Definition: material.h:38
struct pyne::material_data material_data
comp_map comp
composition, maps nuclides in id form to normalized mass weights.
Definition: material.h:214
Material composed of nuclides.
Definition: material.h:61
double density
density (in arbitrary units) of the Material.
Definition: material.h:216
object value (collection of name/value pairs).
Definition: json.h:358
Implements basic nuclear data functions.
Definition: material.h:362
double density
material density
Definition: material.h:364
std::map< int, double > comp_map
Nuclide-mass composition map type.
Definition: material.h:37
double atoms_per_molecule
Definition: material.h:217
double mass
material mass
Definition: material.h:363
struct pyne::decay decay
a struct matching the &#39;/decay/decays&#39; table in nuc_data.h5.
Provides some HDF5 helper functionality in its own namespace.
double atoms_per_mol
material atoms per mole
Definition: material.h:365
std::ostream & operator<<(std::ostream &os, Material mat)
Definition: material.cpp:1053
std::vector< std::pair< double, double > > gammas(int parent_state_id)
Returns a list of energies and intensities normalized to branching ratios.
Definition: data.cpp:2358
Custom exception for invalid HDF5 protocol numbers.
Definition: material.h:370
A container representing enrichment cascades.
Definition: _atomic_data.h:7
double atomic_mass(int nuc)
Returns the atomic mass of a nuclide nuc.
Definition: data.cpp:95
double mass
mass (in arbitrary units) of the Material.
Definition: material.h:215