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) BuildDecayMatrix();
39
40 pre_vect_ = Vector(parent_.size(), 1);
41 for (comp_iter = comp.begin(); comp_iter != comp.end(); ++comp_iter) {
42 nuc = comp_iter->first;
43 atom_count = comp_iter->second;
44 col = parent_[nuc].first;
45 pre_vect_(col, 1) = atom_count;
46 }
47}
48
50
51// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
52void Decayer::AddNucToMaps(int nuc) {
53 int i;
54 int col;
55 int daughter;
56 std::set<int> daughters;
57 std::set<int>::iterator d;
58
59 if (IsNucTracked(nuc)) return;
60
61 col = parent_.size() + 1;
62 parent_[nuc] = std::make_pair(col, pyne::decay_const(nuc));
63 AddNucToList(nuc);
64
65 i = 0;
66 daughters = pyne::decay_children(nuc);
67 std::vector<std::pair<int, double>> dvec(daughters.size());
68 for (d = daughters.begin(); d != daughters.end(); ++d) {
69 daughter = *d;
70 AddNucToMaps(daughter);
71 dvec[i] = std::make_pair(daughter, pyne::branch_ratio(nuc, daughter));
72 i++;
73 }
74 daughters_[col] = dvec;
75}
76
77// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
78bool Decayer::IsNucTracked(int nuc) {
79 return (find(nuclides_tracked_.begin(), nuclides_tracked_.end(), nuc) !=
80 nuclides_tracked_.end());
81}
82
83// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
84void Decayer::AddNucToList(int nuc) {
85 if (!IsNucTracked(nuc)) {
86 nuclides_tracked_.push_back(nuc);
87 }
88}
89
90// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
92 // loops through the ParentMap and populates the passed CompMap with
93 // the number density from the comp parameter for each nuclide
94 ParentMap::const_iterator parent_iter = parent_.begin(); // get first parent
95 while (parent_iter != parent_.end()) {
96 int nuc = parent_iter->first;
97 int col = parent_.find(nuc)->second.first; // get Vector position
98
99 // checks to see if the Vector position is valid
100 if (col <= post_vect_.NumRows()) {
101 double atom_count = post_vect_(col, 1);
102 // adds nuclide to the map if its number density is non-zero
103 if (atom_count > 0) {
104 comp[nuc] = atom_count;
105 }
106 } else {
107 LOG(LEV_ERROR, "none!") << "Decay Error - invalid Vector position";
108 }
109 ++parent_iter; // get next parent
110 }
111}
112
113// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
114void Decayer::BuildDecayMatrix() {
115 double decay_const = 0; // decay constant, in inverse secs
116 int jcol = 1;
117 int n = parent_.size();
118 decay_matrix_ = Matrix(n, n);
119
120 ParentMap::const_iterator parent_iter = parent_.begin(); // get first parent
121
122 // populates the decay matrix column by column
123 while (parent_iter != parent_.end()) {
124 jcol = parent_iter->second.first; // determines column index
125 decay_const = parent_iter->second.second;
126 // Gross heuristic for mostly stable nuclides 2903040000 sec / 100 years
127 if (static_cast<long double>(exp(-2903040000 * decay_const)) == 0.0)
128 decay_const = 0.0;
129 decay_matrix_(jcol, jcol) = -1 * decay_const; // sets A(i,i) value
130
131 // processes the vector in the daughters map if it is not empty
132 if (!daughters_.find(jcol)->second.empty()) {
133 // an iterator that points to 1st daughter in the vector
134 // pair<nuclide,branch_ratio>
135 std::vector<std::pair<int, double>>::const_iterator nuc_iter =
136 daughters_.find(jcol)->second.begin();
137
138 // processes all daughters of the parent
139 while (nuc_iter != daughters_.find(jcol)->second.end()) {
140 int nuc = nuc_iter->first;
141 int irow = parent_.find(nuc)->second.first; // determines row index
142 double branch_ratio = nuc_iter->second;
143 decay_matrix_(irow, jcol) =
144 branch_ratio * decay_const; // sets A(i,j) value
145
146 ++nuc_iter; // get next daughter
147 }
148 }
149 ++parent_iter; // get next parent
150 }
151}
152
153// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
154void Decayer::Decay(double secs) {
156 "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:91
Decayer(const CompMap &comp)
Definition decayer.cc:19
void Decay(double secs)
decay the material
Definition decayer.cc:154
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:34
taken directly from OsiSolverInterface.cpp on 2/17/14 from https://projects.coin-or....
Definition agent.cc:14
@ LEV_ERROR
Use for errors that require agent code or input file modification (use extremely sparingly)
Definition logger.h:56
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
std::map< int, std::pair< int, double > > ParentMap
A map type to represent all of the parent nuclides tracked.
Definition decayer.h:23
LMatrix Vector
void Warn(const std::string &msg)
Issue a warning with the approriate message, accoring to the current warning settings.
Definition error.h:108
std::vector< int > NucList
Definition decayer.h:32
double decay_const(int nuc)
Returns the decay constant for a nuclide nuc.
Definition pyne.cc:9528
std::set< int > decay_children(int nuc)
Returns a set of decay children of a nuc.
Definition pyne.cc:9466
double branch_ratio(std::pair< int, int > from_to)
Returns the branch ratio for a parent/child nuclide pair.
Definition pyne.cc:9572