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::atom_frac(std::set<Nuc> nucs) {
45  CompMap v = m_->comp()->atom();
47 
48  double frac_tot = 0;
49  std::set<Nuc>::iterator it ;
50  for (it = nucs.begin(); it != nucs.end(); ++it) {
51  if (v.find(*it) != v.end()){
52  frac_tot += v[*it];
53  }
54  }
55  return frac_tot;
56 }
57 
59  return mass(pyne::nucname::id(nuc));
60 }
61 
63  return moles(pyne::nucname::id(nuc));
64 }
65 
67  return mass_frac(pyne::nucname::id(nuc));
68 }
69 
71  return atom_frac(pyne::nucname::id(nuc));
72 }
73 
74 bool MatQuery::AlmostEq(Material::Ptr other, double threshold) {
75  CompMap n1 = m_->comp()->mass();
76  CompMap n2 = other->comp()->mass();
79  return compmath::AlmostEq(n1, n2, threshold);
80 }
81 
83  CompMap m = m_->comp()->mass();
84  CompMap m_other = c->mass();
85 
87  compmath::Normalize(&m_other);
88 
89  Nuc limiter;
90  double min_ratio = 1e300;
91  CompMap::iterator it;
92  for (it = m_other.begin(); it != m_other.end(); ++it) {
93  Nuc nuc = it->first;
94  double qty_other = it->second;
95  if (m.count(nuc) == 0 && qty_other > 0) {
96  return 0;
97  }
98  double qty = m[nuc];
99 
100  double ratio = qty / qty_other;
101  if (ratio < min_ratio) {
102  min_ratio = ratio;
103  limiter = nuc;
104  }
105  }
106 
107  double mult = min_ratio * qty();
108  compmath::Normalize(&m_other, mult);
109  double sum = 0;
110  for (it = m_other.begin(); it != m_other.end(); ++it) {
111  sum += it->second;
112  }
113  return sum;
114 }
115 
116 } // namespace toolkit
117 } // 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:74
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:82
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