CYCLUS
Loading...
Searching...
No Matches
decayer.cc
Go to the documentation of this file.
1#include "decayer.h"
2
3#include <fstream>
4#include <string>
5
6#include "env.h"
7#include "error.h"
8#include "logger.h"
9#include "uniform_taylor.h"
10
11namespace cyclus {
12
13ParentMap Decayer::parent_ = ParentMap();
14DaughtersMap Decayer::daughters_ = DaughtersMap();
15Matrix Decayer::decay_matrix_ = Matrix();
16NucList Decayer::nuclides_tracked_ = NucList();
17
18// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
21 "Decayer is deprecated in favor of pyne::decayers::decay");
22
23 int nuc;
24 int col;
25 long double atom_count;
26 bool needs_build = false;
27
28 std::map<int, double>::const_iterator comp_iter = comp.begin();
29 for (comp_iter = comp.begin(); comp_iter != comp.end(); ++comp_iter) {
30 nuc = comp_iter->first;
31 atom_count = comp_iter->second;
32 if (!IsNucTracked(nuc)) {
33 needs_build = true;
34 AddNucToMaps(nuc);
35 }
36 }
37
38 if (needs_build)
39 BuildDecayMatrix();
40
41 pre_vect_ = Vector(parent_.size(), 1);
42 for (comp_iter = comp.begin(); comp_iter != comp.end(); ++comp_iter) {
43 nuc = comp_iter->first;
44 atom_count = comp_iter->second;
45 col = parent_[nuc].first;
46 pre_vect_(col, 1) = atom_count;
47 }
48}
49
51
52// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
53void Decayer::AddNucToMaps(int nuc) {
54 int i;
55 int col;
56 int daughter;
57 std::set<int> daughters;
58 std::set<int>::iterator d;
59
60 if (IsNucTracked(nuc))
61 return;
62
63 col = parent_.size() + 1;
64 parent_[nuc] = std::make_pair(col, pyne::decay_const(nuc));
65 AddNucToList(nuc);
66
67 i = 0;
69 std::vector< std::pair<int, double> > dvec(daughters.size());
70 for (d = daughters.begin(); d != daughters.end(); ++d) {
71 daughter = *d;
72 AddNucToMaps(daughter);
73 dvec[i] = std::make_pair(daughter, pyne::branch_ratio(nuc, daughter));
74 i++;
75 }
76 daughters_[col] = dvec;
77}
78
79// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
80bool Decayer::IsNucTracked(int nuc) {
81 return (find(nuclides_tracked_.begin(), nuclides_tracked_.end(), nuc)
82 != nuclides_tracked_.end());
83}
84
85// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
86void Decayer::AddNucToList(int nuc) {
87 if (!IsNucTracked(nuc)) {
88 nuclides_tracked_.push_back(nuc);
89 }
90}
91
92// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
94 // loops through the ParentMap and populates the passed CompMap with
95 // the number density from the comp parameter for each nuclide
96 ParentMap::const_iterator parent_iter = parent_.begin(); // get first parent
97 while (parent_iter != parent_.end()) {
98 int nuc = parent_iter->first;
99 int col = parent_.find(nuc)->second.first; // get Vector position
100
101 // checks to see if the Vector position is valid
102 if (col <= post_vect_.NumRows()) {
103 double atom_count = post_vect_(col, 1);
104 // adds nuclide to the map if its number density is non-zero
105 if (atom_count > 0) {
106 comp[nuc] = atom_count;
107 }
108 } else {
109 LOG(LEV_ERROR, "none!") << "Decay Error - invalid Vector position";
110 }
111 ++parent_iter; // get next parent
112 }
113}
114
115// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
116void Decayer::BuildDecayMatrix() {
117 double decay_const = 0; // decay constant, in inverse secs
118 int jcol = 1;
119 int n = parent_.size();
120 decay_matrix_ = Matrix(n, n);
121
122 ParentMap::const_iterator parent_iter = parent_.begin(); // get first parent
123
124 // populates the decay matrix column by column
125 while (parent_iter != parent_.end()) {
126 jcol = parent_iter->second.first; // determines column index
127 decay_const = parent_iter->second.second;
128 // Gross heuristic for mostly stable nuclides 2903040000 sec / 100 years
129 if (static_cast<long double>(exp(-2903040000 * decay_const)) == 0.0)
130 decay_const = 0.0;
131 decay_matrix_(jcol, jcol) = -1 * decay_const; // sets A(i,i) value
132
133 // processes the vector in the daughters map if it is not empty
134 if (!daughters_.find(jcol)->second.empty()) {
135 // an iterator that points to 1st daughter in the vector
136 // pair<nuclide,branch_ratio>
137 std::vector< std::pair<int, double> >::const_iterator
138 nuc_iter = daughters_.find(jcol)->second.begin();
139
140 // processes all daughters of the parent
141 while (nuc_iter != daughters_.find(jcol)->second.end()) {
142 int nuc = nuc_iter->first;
143 int irow = parent_.find(nuc)->second.first; // determines row index
144 double branch_ratio = nuc_iter->second;
145 decay_matrix_(irow, jcol) = branch_ratio * decay_const; // sets A(i,j) value
146
147 ++nuc_iter; // get next daughter
148 }
149 }
150 ++parent_iter; // get next parent
151 }
152}
153
154// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
155void Decayer::Decay(double secs) {
156 Warn<VALIDATION_WARNING>("the cyclus decayer has not yet been benchmarked and "
157 "should be considered experimental.");
158 // solves the decay equation for the final composition
159 post_vect_ = UniformTaylor::MatrixExpSolver(decay_matrix_, pre_vect_, secs);
160}
161
162} // namespace cyclus
void GetResult(CompMap &comp)
set the composition from a CompMap
Definition decayer.cc:93
Decayer(const CompMap &comp)
Definition decayer.cc:19
void Decay(double secs)
decay the material
Definition decayer.cc:155
int NumRows() const
Definition l_matrix.cc:58
static Vector MatrixExpSolver(const Matrix &A, const Vector &x_o, const double t)
Solves the matrix exponential problem:
Code providing rudimentary logging capability for the Cyclus core.
#define LOG(level, prefix)
allows easy logging via the streaming operator similar to std::cout; this is the primary way to use t...
Definition logger.h:35
taken directly from OsiSolverInterface.cpp on 2/17/14 from https://projects.coin-or....
Definition agent.cc:14
std::map< int, std::pair< int, double > > ParentMap
A map type to represent all of the parent nuclides tracked.
Definition decayer.h:23
@ LEV_ERROR
Use for errors that require agent code or input file modification (use extremely sparingly)
Definition logger.h:51
std::map< Nuc, double > CompMap
a raw definition of nuclides and corresponding (dimensionless quantities).
Definition composition.h:17
std::map< int, std::vector< std::pair< int, double > > > DaughtersMap
A map type to represent all of the daughter nuclides tracked.
Definition decayer.h:30
LMatrix Matrix
T OptionalQuery(InfileTree *tree, std::string query, T default_val)
a query method for optional parameters
LMatrix Vector
std::vector< int > NucList
Definition decayer.h:32
double decay_const(int nuc)
Returns the decay constant for a nuclide nuc.
Definition pyne.cc:11914
std::set< int > decay_children(int nuc)
Returns a set of decay children of a nuc.
Definition pyne.cc:11843
double branch_ratio(std::pair< int, int > from_to)
Returns the branch ratio for a parent/child nuclide pair.
Definition pyne.cc:11964