CYCLUS
mat_query.cc
Go to the documentation of this file.
1 #include "mat_query.h"
2 #include "pyne.h"
3 
4 #include <cmath>
5 
6 namespace cyclus {
7 namespace toolkit {
8 
10 
11 double MatQuery::qty() {
12  return m_->quantity();
13 }
14 
15 double MatQuery::mass(Nuc nuc) {
16  return mass_frac(nuc) * qty();
17 }
18 
19 double MatQuery::moles(Nuc nuc) {
20  return mass(nuc) / (pyne::atomic_mass(nuc) * units::g);
21 }
22 
23 double MatQuery::mass_frac(Nuc nuc) {
24  CompMap v = m_->comp()->mass();
26  return v[nuc];
27 }
28 
29 double MatQuery::mass_frac(std::set<Nuc> nucs) {
30  double m_tot = 0;
31  std::set<Nuc>::iterator it ;
32  for (it = nucs.begin(); it != nucs.end(); ++it) {
33  m_tot += mass(*it);
34  }
35  return m_tot/qty();
36 }
37 
38 double MatQuery::atom_frac(Nuc nuc) {
39  CompMap v = m_->comp()->atom();
41  return v[nuc];
42 }
43 
44 double MatQuery::mass(std::string nuc) {
45  return mass(pyne::nucname::id(nuc));
46 }
47 
48 double MatQuery::moles(std::string nuc) {
49  return moles(pyne::nucname::id(nuc));
50 }
51 
52 double MatQuery::mass_frac(std::string nuc) {
53  return mass_frac(pyne::nucname::id(nuc));
54 }
55 
56 double MatQuery::atom_frac(std::string nuc) {
57  return atom_frac(pyne::nucname::id(nuc));
58 }
59 
60 bool MatQuery::AlmostEq(Material::Ptr other, double threshold) {
61  CompMap n1 = m_->comp()->mass();
62  CompMap n2 = other->comp()->mass();
65  return compmath::AlmostEq(n1, n2, threshold);
66 }
67 
69  CompMap m = m_->comp()->mass();
70  CompMap m_other = c->mass();
71 
73  compmath::Normalize(&m_other);
74 
75  Nuc limiter;
76  double min_ratio = 1e300;
77  CompMap::iterator it;
78  for (it = m_other.begin(); it != m_other.end(); ++it) {
79  Nuc nuc = it->first;
80  double qty_other = it->second;
81  if (m.count(nuc) == 0 && qty_other > 0) {
82  return 0;
83  }
84  double qty = m[nuc];
85 
86  double ratio = qty / qty_other;
87  if (ratio < min_ratio) {
88  min_ratio = ratio;
89  limiter = nuc;
90  }
91  }
92 
93  double mult = min_ratio * qty();
94  compmath::Normalize(&m_other, mult);
95  double sum = 0;
96  for (it = m_other.begin(); it != m_other.end(); ++it) {
97  sum += it->second;
98  }
99  return sum;
100 }
101 
102 } // namespace toolkit
103 } // namespace cyclus
double moles(Nuc nuc)
Returns the number of moles of nuclide nuc in the material.
Definition: mat_query.cc:19
boost::shared_ptr< Composition > Ptr
Definition: composition.h:43
MatQuery(Material::Ptr m)
Creates a new query object inspecting m.
Definition: mat_query.cc:9
boost::shared_ptr< Material > Ptr
Definition: material.h:75
double qty()
Returns the mass in kg of the material.
Definition: mat_query.cc:11
bool AlmostEq(const CompMap &v1, const CompMap &v2, double threshold)
Returns true if all nuclides of v1 and v2 are the same within threshold.
Definition: comp_math.cc:93
double mass_frac(Nuc nuc)
Returns the mass fraction of nuclide nuc in the material.
Definition: mat_query.cc:23
std::map< Nuc, double > CompMap
a raw definition of nuclides and corresponding (dimensionless quantities).
Definition: composition.h:17
double atom_frac(Nuc nuc)
returns the atom/mole fraction of nuclide nuc in the material.
Definition: mat_query.cc:38
bool AlmostEq(Material::Ptr other, double threshold=eps_rsrc())
Returns true if all nuclide fractions of the material and other are the same within threshold...
Definition: mat_query.cc:60
const double g
Definition: material.h:18
taken directly from OsiSolverInterface.cpp on 2/17/14 from https://projects.coin-or.org/Osi/browser/trunk.
Definition: agent.cc:14
double mass(Nuc nuc)
Returns the mass in kg of nuclide nuc in the material.
Definition: mat_query.cc:15
int id(int nuc)
Definition: pyne.cc:2716
double Amount(Composition::Ptr c)
Returns the maximum mass quantity of composition c that can be extracted from the material...
Definition: mat_query.cc:68
double atomic_mass(int nuc)
Returns the atomic mass of a nuclide nuc.
Definition: pyne.cc:10440
void Normalize(CompMap *v, double val)
The sum of quantities of all nuclides of v is normalized to val.
Definition: comp_math.cc:63
int Nuc
Definition: composition.h:12