Beispiel #1
0
pyne::Material::Material(pyne::comp_map cm, double m, std::string s, double apm)
{
  // Initializes the mass stream based on an isotopic component dictionary.
  comp = cm;
  mass = m;
  name = s;
  atoms_per_mol = apm;
  norm_comp();
};
Beispiel #2
0
void pyne::Material::from_atom_frac(std::map<int, double> atom_fracs)
{
  // atom frac must be of the form {nuc: af}, eg, water
  //  80160: 1.0
  //  10010: 2.0

  // clear existing components
  comp.clear();
  atoms_per_mol = 0.0;

  for (std::map<int, double>::iterator afi = atom_fracs.begin(); afi != atom_fracs.end(); afi++)
  {
    comp[afi->first] = (afi->second) * pyne::atomic_mass(afi->first);
    atoms_per_mol += (afi->second);
  };

  norm_comp();
};
Beispiel #3
0
void pyne::Material::from_hdf5(std::string filename, std::string datapath, int row, int protocol) {
  // Turn off annoying HDF5 errors
  herr_t status;
  H5Eset_auto2(H5E_DEFAULT, NULL, NULL);

  // Check that the file is there
  if (!pyne::file_exists(filename))
    throw pyne::FileNotFound(filename);

  // Check to see if the file is in HDF5 format.
  bool ish5 = H5Fis_hdf5(filename.c_str());
  if (!ish5)
    throw h5wrap::FileNotHDF5(filename);

  //Set file access properties so it closes cleanly
  hid_t fapl;
  fapl = H5Pcreate(H5P_FILE_ACCESS);
  H5Pset_fclose_degree(fapl,H5F_CLOSE_STRONG);
  // Open the database
  hid_t db = H5Fopen(filename.c_str(), H5F_ACC_RDONLY, fapl);

  bool datapath_exists = h5wrap::path_exists(db, datapath);
  if (!datapath_exists)
    throw h5wrap::PathNotFound(filename, datapath);

  // Clear current content
  comp.clear();

  // Load via various protocols
  if (protocol == 0)
    _load_comp_protocol0(db, datapath, row);
  else if (protocol == 1)
    _load_comp_protocol1(db, datapath, row);
  else
    throw pyne::MaterialProtocolError();

  // Close the database
  status = H5Fclose(db);

  // Renomalize the composition, just to be safe.
  norm_comp();
};
Beispiel #4
0
void pyne::Material::from_hdf5(std::string filename, std::string datapath, int row, int protocol)
{
  // Turn off annoying HDF5 errors
  H5::Exception::dontPrint();

  // Check that the file is there
  if (!pyne::file_exists(filename))
    throw pyne::FileNotFound(filename);

  // Check to see if the file is in HDF5 format.
  bool isH5 = H5::H5File::isHdf5(filename);
  if (!isH5)
    throw h5wrap::FileNotHDF5(filename);

  // Open the database
  H5::H5File db (filename, H5F_ACC_RDONLY);

  bool datapath_exists = h5wrap::path_exists(&db, datapath);
  if (!datapath_exists)
    throw h5wrap::PathNotFound(filename, datapath);

  // Clear current content
  comp.clear();

  // Load via various protocols
  if (protocol == 0)
    _load_comp_protocol0(&db, datapath, row);
  else if (protocol == 1)
    _load_comp_protocol1(&db, datapath, row);
  else
    throw pyne::MaterialProtocolError();

  // Close the database
  db.close();

  // Renomalize the composition, just to be safe.
  norm_comp();
};
Beispiel #5
0
void pyne::Material::from_text(std::string filename)
{
  // Check that the file is there
  if (!pyne::file_exists(filename))
    throw pyne::FileNotFound(filename);

  // New filestream
  std::ifstream f;
  f.open(filename.c_str());

  // Read in
  comp.clear();
  std::string keystr, valstr;

  while ( !f.eof() )
  {
    f >> keystr;

    if (0 == keystr.length())
      continue;
    else 
      f >> valstr;

    if (keystr == "Name")
      name = valstr;
    else if (keystr == "Mass")
      mass = pyne::to_dbl(valstr);
    else if (keystr == "APerM")
      atoms_per_mol = pyne::to_dbl(valstr);
    else
      comp[pyne::nucname::zzaaam(keystr)] = pyne::to_dbl(valstr);
  };

  f.close();
  norm_comp();
};