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  #define PYNE_DECAY
26 #include "json-forwards.h"
27 #include "json.h"
28 #include "h5wrap.h"
29 #include "utils.h"
30 #include "nucname.h"
31 #include "data.h"
32 #include "decay.h"
33 #endif
34 
35 #define DEFAULT_MAT_CHUNKSIZE 100
36 
37 namespace pyne
38 {
39  // Set Type Definitions
40  typedef std::map<int, double> comp_map;
41  typedef comp_map::iterator comp_iter;
42 
43  #ifdef PYNE_IS_AMALGAMATED
44  namespace decayers {
45  extern comp_map decay(comp_map, double);
46  } // namespace decayers
47  #endif
48 
55  bool detect_nuclidelist(hid_t dataset, std::string& nucpath);
56 
57  // These 37 strings are predefined FLUKA materials.
58  // Materials not on this list requires a MATERIAL card.
59  static std::string fluka_mat_strings[] = {
60  "BLCKHOLE", "VACUUM", "HYDROGEN", "HELIUM", "BERYLLIU", "CARBON",
61  "NITROGEN", "OXYGEN", "MAGNESIU", "ALUMINUM", "IRON", "COPPER",
62  "SILVER", "SILICON", "GOLD", "MERCURY", "LEAD", "TANTALUM",
63  "SODIUM", "ARGON", "CALCIUM", "TIN", "TUNGSTEN", "TITANIUM",
64  "NICKEL", "WATER", "POLYSTYR", "PLASCINT", "PMMA", "BONECOMP",
65  "BONECORT", "MUSCLESK", "MUSCLEST", "ADTISSUE", "KAPTON", "POLYETHY", "AIR"
66  };
67 
68  static int FLUKA_MAT_NUM = 37;
69 
71  class Material
72  {
73  protected:
74 
76  double get_comp_sum ();
77 
78  public:
79 
80  // Material Constructors
81  Material ();
82  Material(comp_map cm, double m=-1.0, double d=-1.0, double apm=-1.0,
90  Json::Value attributes=Json::Value(Json::objectValue));
103  Material(char * filename, double m=-1.0, double d=-1.0, double apm=-1.0,
104  Json::Value attributes=Json::Value(Json::objectValue));
117  Material(std::string filename, double m=-1.0, double d=-1.0, double apm=-1.0,
118  Json::Value attributes=Json::Value(Json::objectValue));
119  ~Material ();
120 
122  void norm_comp ();
123 
124  // Persistence functions.
125 
131  void _load_comp_protocol0(hid_t db, std::string datapath, int row);
132 
138  void _load_comp_protocol1(hid_t db, std::string datapath, int row);
139 
146  void _load_comp_protocol1(hid_t db, std::string datapath, std::string nucpath, int row);
147 
153  void from_hdf5(char * filename, char * datapath, int row=-1, int protocol=1);
154 
160  void from_hdf5(std::string filename, std::string datapath="/mat_name",
161  int row=-1, int protocol=1);
162 
163  private:
164 
173  int detect_hdf5_layout(hid_t db, std::string datapath);
174 
175  enum prot1_layout {path_donotexists=-1, unknown, old_layout, new_layout};
176 
177  public:
178 
188  void write_hdf5(std::string filename, std::string datapath="/mat_name",
189  float row=-0.0, int chunksize=DEFAULT_MAT_CHUNKSIZE);
190 
197  std::vector<int> write_hdf5_nucpath(hid_t db, std::string nucpath);
198 
210  void write_hdf5_datapath(hid_t db, std::string datapath, float row, int chunksize,
211  std::vector<int> nuclides);
225  void deprecated_write_hdf5(char * filename, char * datapath, char * nucpath, float row=-0.0,
226  int chunksize=DEFAULT_MAT_CHUNKSIZE);
240  void deprecated_write_hdf5(hid_t db, std::string datapath, std::string nucpath, float row=-0.0,
241  int chunksize=DEFAULT_MAT_CHUNKSIZE);
251  void deprecated_write_hdf5(std::string filename, std::string datapath,
252  std::string nucpath, float row=-0.0, int chunksize=DEFAULT_MAT_CHUNKSIZE);
254  std::string openmc(std::string fact_type = "mass");
255 
257  std::string mcnp(std::string frac_type = "mass", bool mult_den = true);
259  std::string phits(std::string frac_type = "mass", bool mult_den = true);
261  std::string mcnp_frac(std::map<int, double> fracs, std::string frac_type = "");
264  std::string get_uwuw_name();
267  std::string fluka(int id, std::string frac_type = "mass");
269  bool not_fluka_builtin(std::string fluka_name);
271  std::string fluka_material_str(int id);
273  std::string fluka_material_component(int fid, int nucid,
274  std::string fluka_name);
276  std::string fluka_material_line(int znum, double atomic_mass,
277  int fid, std::string fluka_name);
279  std::string fluka_format_field(float field);
282  std::string fluka_compound_str(int id, std::string frac_type = "mass");
283 
285  void from_text(char * filename);
287  void from_text(std::string filename);
288 
290  void write_text(char * filename);
292  void write_text(std::string filename);
293 
295  void load_json(Json::Value);
297  Json::Value dump_json();
299  void from_json(char * filename);
301  void from_json(std::string filname);
303  void write_json(char * filename);
305  void write_json(std::string filename);
306 
307  // Fundemental mass stream data
309  comp_map comp;
310  double mass;
311  double density;
313  Json::Value metadata;
315 
316  // Material function definitions
317  void normalize ();
318  comp_map mult_by_mass();
326  double molecular_mass(double apm=-1.0);
329  comp_map activity();
333  comp_map decay_heat();
343  comp_map dose_per_g(std::string dose_type, int source=0);
346  Material expand_elements(std::set<int> exception_ids);
347  // Wrapped version to facilitate calling from python
348  Material expand_elements(int **int_ptr_arry = NULL);
349  // Returns a copy of the current material where all the isotopes of the elements
350  // are added up, atomic-fraction-wise, unless they are in the exception set
351  Material collapse_elements(std::set<int> exception_znum);
352  // Wrapped version to facilitate calling from python
353  Material collapse_elements(int **int_ptr_arry);
354  // void print_material( pyne::Material test_mat);
359  double mass_density(double num_dens=-1.0, double apm=-1.0);
360  // void print_material( pyne::Material test_mat);
364  std::map<int, double> get_density_frac(std::string frac_type="atom", bool mult_den=true);
370  double number_density(double mass_dens=-1.0, double apm=-1.0);
371 
372  // Sub-Stream Computation
375  Material sub_mat(std::set<int> nucset);
378  Material sub_mat(std::set<std::string> nucset);
379 
383  Material set_mat(std::set<int> nucset, double value);
386  Material set_mat(std::set<std::string> nucset, double value);
387 
390  Material del_mat(std::set<int> nucset);
393  Material del_mat(std::set<std::string> nucset);
394 
396  Material sub_range(int lower=0, int upper=10000000);
399  Material set_range(int lower=0, int upper=10000000, double value=0.0);
401  Material del_range(int lower=0, int upper=10000000);
402 
405  Material sub_elem(int element);
407  Material sub_lan();
409  Material sub_act();
411  Material sub_tru();
413  Material sub_ma();
415  Material sub_fp();
416 
417  // Atom fraction functions
420  std::map<int, double> to_atom_frac();
423  void from_atom_frac(std::map<int, double> atom_fracs);
424 
427  std::map<int, double> to_atom_dens();
428 
429  // Radioactive Material functions
432  std::vector<std::pair<double, double> > gammas();
435  std::vector<std::pair<double, double> > xrays();
438  std::vector<std::pair<double, double> > photons(bool norm);
441  std::vector<std::pair<double, double> > normalize_radioactivity(
442  std::vector<std::pair<double, double> > unnormed);
445  void from_activity(std::map<int, double> activities);
446 
447 #ifdef PYNE_DECAY
448  Material decay(double t);
450 #endif // PYNE_DECAY
451 
456  Material cram(std::vector<double> A, const int order=14);
457 
458  // Overloaded Operators
460  Material operator+ (double);
462  Material operator+ (Material);
464  Material operator* (double);
466  Material operator/ (double);
467  };
468 
471  std::ostream& operator<< (std::ostream& os, Material mat);
472 
475  typedef struct material_data {
476  double mass;
477  double density;
478  double atoms_per_mol;
479  double comp[1];
480  } material_data;
481 
483  class MaterialProtocolError: public std::exception
484  {
486  virtual const char* what() const throw()
487  {
488  return "Invalid loading protocol number; please use 0 or 1.";
489  }
490  };
491 
492 // End pyne namespace
493 }
494 
495 #endif // PYNE_MR34UE5INRGMZK2QYRDWICFHVM
comp_map::iterator comp_iter
Nuclide-mass composition iter type.
Definition: material.h:41
struct pyne::material_data material_data
comp_map comp
composition, maps nuclides in id form to normalized mass weights.
Definition: material.h:309
Material composed of nuclides.
Definition: material.h:71
double density
density (in arbitrary units) of the Material.
Definition: material.h:311
object value (collection of name/value pairs).
Definition: json.h:358
Implements basic nuclear data functions.
Definition: material.h:475
double density
material density
Definition: material.h:477
std::map< int, double > comp_map
Nuclide-mass composition map type.
Definition: material.h:40
double atoms_per_molecule
Definition: material.h:312
double mass
material mass
Definition: material.h:476
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:478
bool detect_nuclidelist(hid_t dataset, std::string &nucpath)
Definition: material.cpp:2095
std::ostream & operator<<(std::ostream &os, Material mat)
Definition: material.cpp:1446
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:2362
Custom exception for invalid HDF5 protocol numbers.
Definition: material.h:483
A container representing enrichment cascades.
Definition: _atomic_data.h:16
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:310