PyNE C++
material_library.h
1 #ifndef PYNE_MATERIAL_LIBRARY
2 #define PYNE_MATERIAL_LIBRARY
3 
4 #include <stdlib.h>
5 #include <iostream>
6 #include <memory>
7 #include <string>
8 #include <unordered_map>
9 #include <vector>
10 
11 #if !defined(JSON_IS_AMALGAMATION)
12 #define JSON_IS_AMALGAMATION
13 #endif
14 
15 #ifndef PYNE_IS_AMALGAMATED
16 #include "material.h"
17 #endif
18 
19 namespace pyne {
20 
21 typedef std::shared_ptr<pyne::Material> shr_mat_ptr;
22 typedef std::unordered_map<std::string, shr_mat_ptr> mat_map;
23 typedef std::set<std::string> matname_set;
24 typedef std::set<int> nuc_set;
25 
27  public:
28  // materialLibrary constructor
29  MaterialLibrary(); //< empty constryctor
30 
38  MaterialLibrary(const std::string& fname, const std::string& datapath);
39 
40  ~MaterialLibrary(){}; //< default destructor
41 
48  void from_hdf5(const std::string& filename, const std::string& datapath);
52 
53  void from_json(const std::string& filename);
54  void load_json(Json::Value json);
55  Json::Value dump_json();
56  void write_json(const std::string& filename);
69  void write_hdf5(const std::string& filename,
70  const std::string& datapath = "/materials",
71  bool h5_overwrite = false) const;
78  void write_hdf5_nucpath(hid_t db, std::string nucpath) const;
83  void merge(const pyne::MaterialLibrary& mat_lib);
88  void merge(pyne::MaterialLibrary* mat_lib);
93  void add_material(pyne::Material mat);
100  void add_material(const std::string& mat_name, const pyne::Material& mat);
105  void del_material(const std::string& mat_name);
110  pyne::Material get_material(const std::string& mat_name) const;
115  pyne::shr_mat_ptr get_material_ptr(const std::string& mat_name) const;
123  std::string ensure_material_name_and_number(pyne::Material& mat) const;
130  int ensure_material_number(pyne::Material& mat) const;
135  pyne::mat_map get_mat_library() const { return material_library; }
140  pyne::matname_set get_keylist() const { return keylist; }
145  pyne::nuc_set get_nuclist() const { return nuclist; }
146 
150  typedef mat_map::iterator iterator;
151  typedef mat_map::const_iterator const_iterator;
152  iterator begin() { return material_library.begin(); }
153  iterator end() { return material_library.end(); }
154 
155  const_iterator cbegin() const { return material_library.cbegin(); }
156  const_iterator cend() const { return material_library.cend(); }
157  std::size_t size() const { return material_library.size(); }
158  bool emtpy() const { return material_library.empty(); }
159  std::size_t count(std::string mat_name) const {
160  return material_library.count(mat_name);
161  }
162  std::shared_ptr<Material>& operator[](const std::string& k) {
163  return material_library[k];
164  }
165  std::shared_ptr<Material>& operator[](std::string&& k) {
166  return material_library[k];
167  }
168 
169  private:
174  void append_to_nuclist(const pyne::Material& mat);
181  int get_length_of_table(hid_t db, const std::string& datapath) const;
182 
183  std::set<int>
184  mat_number_set; // list of material number in the library (ordered)
185  matname_set keylist; // list of masterial keys
186  nuc_set nuclist; // list of nuclides in the library
187  // The actual library
188  mat_map material_library; // material library
189 
190 }; // end MaterialLibrary class header
191 } // namespace pyne
192 #endif // PYNE_MATERIAL_LIBRARY
int ensure_material_number(pyne::Material &mat) const
Return a material material number, ensure it exist as an int, if it exist as a string convert it into...
Definition: material_library.cpp:136
void add_material(pyne::Material mat)
Add a material to the library.
Definition: material_library.cpp:186
Material composed of nuclides.
Definition: material.h:71
pyne::mat_map get_mat_library() const
Get the material library itself.
Definition: material_library.h:135
void from_hdf5(const std::string &filename, const std::string &datapath)
loads the pyne materials in map of name vs Material
Definition: material_library.cpp:32
mat_map::iterator iterator
Definition: material_library.h:150
pyne::matname_set get_keylist() const
Get the list of materials in the Library.
Definition: material_library.h:140
pyne::shr_mat_ptr get_material_ptr(const std::string &mat_name) const
Get a material of the Library by name.
Definition: material_library.cpp:216
std::string ensure_material_name_and_number(pyne::Material &mat) const
Return a material material number, ensure it exist if it does not exist build it using the material n...
Definition: material_library.cpp:166
void del_material(const std::string &mat_name)
remove a material of the Library by name
Definition: material_library.cpp:206
pyne::nuc_set get_nuclist() const
Get the list of nuclides in the Library.
Definition: material_library.h:145
pyne::Material get_material(const std::string &mat_name) const
remove a material of the Library by name
Definition: material_library.cpp:211
void write_hdf5_nucpath(hid_t db, std::string nucpath) const
Writes this nucpath to an HDF5 file. This happens according to protocol 1.
Definition: material_library.cpp:300
void from_json(const std::string &filename)
loads the pyne materials in map of name vs Material /
Definition: material_library.cpp:112
void write_hdf5(const std::string &filename, const std::string &datapath="/materials", bool h5_overwrite=false) const
Writes MaterialLibrary out to an HDF5 file. This happens according to protocol 1. Writting in a file ...
Definition: material_library.cpp:226
void merge(const pyne::MaterialLibrary &mat_lib)
Merge a material library into the current one.
Definition: material_library.cpp:80
A container representing enrichment cascades.
Definition: _atomic_data.h:16
Definition: material_library.h:26