Flow123d  jenkins-Flow123d-windows-release-multijob-285
radioactive_decay.cc
Go to the documentation of this file.
5 
6 #include "system/global_defs.h"
7 #include "mesh/mesh.h"
8 
9 #include "armadillo"
10 
11 using namespace Input::Type;
12 
14  = Record("RadioactiveDecayProduct", "A record describing a product of a radioactive decay.")
15  .allow_auto_conversion("name")
16  .declare_key("name", String(), Default::obligatory(),
17  "The name of the product.")
18  .declare_key("energy", Double(0.0), Default("0.0"),
19  "Not used at the moment! The released energy in MeV from the decay of the radionuclide into the product.")
20  .declare_key("branching_ratio", Double(0.0), Default("1.0"),
21  "The branching ratio of the product when there is more than one."
22  "Considering only one product, the default ratio 1.0 is used."
23  "Its value must be positive. Further, the branching ratios of all products are normalized"
24  "by their sum, so the sum then gives 1.0 (this also resolves possible rounding errors).");
25 
27  = Record("Decay", "A model of a radioactive decay.")
28  .declare_key("radionuclide", String(), Default::obligatory(),
29  "The name of the parent radionuclide.")
30  .declare_key("half_life", Double(0.0), Default::obligatory(),
31  "The half life of the parent radionuclide in seconds.")
32  .declare_key("products", Array(RadioactiveDecay::input_type_product,1), Default::obligatory(),
33  "An array of the decay products (daughters).");
34 
36  = Record("RadioactiveDecay", "A model of a radioactive decay and possibly of a decay chain.")
38  .declare_key("decays", Array( RadioactiveDecay::input_type_single_decay, 1), Default::obligatory(),
39  "An array of radioactive decays.")
41  "Numerical solver for the system of first order ordinary differential equations coming from the model.");
42 
43 
44 
46  : FirstOrderReactionBase(init_mesh, in_rec)
47 {
48 }
49 
51 {
52 }
53 
54 
56 {
57  Input::Array decay_array = input_record_.val<Input::Array>("decays");
58 
59  substance_ids_.resize( decay_array.size() );
60  half_lives_.resize( decay_array.size() );
61  bifurcation_.resize( decay_array.size() );
62 
63  unsigned int idx;
64  int i_decay = 0;
65  for (Input::Iterator<Input::Record> dec_it = decay_array.begin<Input::Record>();
66  dec_it != decay_array.end(); ++dec_it, ++i_decay)
67  {
68  //read half-life
69  half_lives_[i_decay] = dec_it->val<double>("half_life");
70 
71  //read radionuclide name and products array
72  string radionuclide = dec_it->val<string>("radionuclide");
73  Input::Array product_array = dec_it->val<Input::Array>("products");
74 
75  //resizing according to product count
76  substance_ids_[i_decay].resize(product_array.size()+1);
77  bifurcation_[i_decay].resize(product_array.size());
78 
79  //Reading products - setting substance ids, branching ratios.
80  //iterating over products
81  unsigned int i_product = 0;
82  for (Input::Iterator<Input::Record> prod_it = product_array.begin<Input::Record>();
83  prod_it != product_array.end(); ++prod_it, ++i_product)
84  {
85  string product_name = prod_it->val<string>("name");
86  idx = find_subst_name(product_name);
87  if (idx < substances_.size())
88  substance_ids_[i_decay][i_product+1] = idx;
89  else THROW(ReactionTerm::ExcUnknownSubstance()
90  << ReactionTerm::EI_Substance(product_name)
91  << (*prod_it).ei_address());
92 
93  bifurcation_[i_decay][i_product] = prod_it->val<double>("branching_ratio");
94  }
95 
96  // set radionuclide substance index
97  idx = find_subst_name(radionuclide);
98  if (idx < substances_.size())
99  substance_ids_[i_decay][0] = idx;
100  else THROW(ReactionTerm::ExcUnknownSubstance()
101  << ReactionTerm::EI_Substance(radionuclide)
102  << (*dec_it).ei_address());
103 
104  //Normalization of branching ratios in bifurcation vector by its norm.
105  //sum:
106  double sum=0;
107  for(auto &b : bifurcation_[i_decay])
108  sum += b;
109  //Normalization:
110  for(auto &b : bifurcation_[i_decay])
111  b = b / sum;
112  }
113 }
114 
115 
117 {
118  // create decay matrix
120  unsigned int reactant_index, product_index; //global indices of the substances
121  double exponent; //temporary variable k = ln(2)/t_half
122  for (unsigned int i_decay = 0; i_decay < half_lives_.size(); i_decay++) {
123  reactant_index = substance_ids_[i_decay][0];
124  exponent = log(2) / half_lives_[i_decay];
125  reaction_matrix_(reactant_index, reactant_index) = -exponent;
126 
127  for (unsigned int i_product = 1; i_product < substance_ids_[i_decay].size(); ++i_product){
128  product_index = substance_ids_[i_decay][i_product];
129  reaction_matrix_(product_index, reactant_index) = exponent * bifurcation_[i_decay][i_product-1];
130  }
131  }
132 }
Iterator< ValueType > begin() const
Accessor to input data conforming to declared Array.
Definition: accessors.hh:558
void assemble_ode_matrix(void) override
Implements the assembly of the system matrix of the ODEs.
Class Input::Type::Default specifies default value of keys of a Input::Type::Record.
Definition: type_record.hh:39
static Default obligatory()
Definition: type_record.hh:89
???
SubstanceList substances_
Names belonging to substances.
static Input::Type::AbstractRecord input_type
~RadioactiveDecay(void)
Destructor.
Definition: mesh.h:109
Record & derive_from(AbstractRecord &parent)
Definition: type_record.cc:197
unsigned int find_subst_name(const std::string &name)
Base class for linear reactions and decay chain.
unsigned int size() const
Definition: substance.hh:99
Class for declaration of inputs sequences.
Definition: type_base.hh:239
void initialize_from_input() override
Initializes private members of sorption from the input record.
IteratorBase end() const
static Input::Type::AbstractRecord input_type
static Default optional()
Definition: type_record.hh:102
Global macros to enhance readability and debugging, general constants.
Record & allow_auto_conversion(const string &from_key)
Definition: type_record.cc:111
arma::mat reaction_matrix_
Reaction matrix.
Class for declaration of the input data that are floating point numbers.
Definition: type_base.hh:392
static Input::Type::Record input_type_single_decay
Input record which defines particular decay step.
Accessor to the data with type Type::Record.
Definition: accessors.hh:327
const Ret val(const string &key) const
static Input::Type::Record input_type_product
Input record for a product of a radioactive decay.
Input::Record input_record_
Definition: equation.hh:220
std::vector< double > half_lives_
Half-lives of the substances.
static Input::Type::Record input_type
Input record for class RadioactiveDecay.
std::vector< std::vector< unsigned int > > substance_ids_
unsigned int size() const
Record type proxy class.
Definition: type_record.hh:169
RadioactiveDecay(Mesh &mesh, Input::Record in_rec)
Constructor.
unsigned int n_substances_
Number of all transported substances. It is the dimension of the reaction matrix. ...
#define THROW(whole_exception_expr)
Wrapper for throw. Saves the throwing point.
Definition: exceptions.hh:34
std::vector< std::vector< double > > bifurcation_
Record & declare_key(const string &key, const KeyType &type, const Default &default_value, const string &description)
Definition: type_record.cc:430