Flow123d  JS_before_hm-1822-gbb48b12e9
first_order_reaction_base.hh
Go to the documentation of this file.
1 /*!
2  *
3  * Copyright (C) 2015 Technical University of Liberec. All rights reserved.
4  *
5  * This program is free software; you can redistribute it and/or modify it under
6  * the terms of the GNU General Public License version 3 as published by the
7  * Free Software Foundation. (http://www.gnu.org/licenses/gpl-3.0.en.html)
8  *
9  * This program is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
12  *
13  *
14  * @file first_order_reaction_base.hh
15  * @brief
16  */
17 
18 #ifndef FIRST_ORDER_REACTION_BASE_H_
19 #define FIRST_ORDER_REACTION_BASE_H_
20 
21 #include <memory> // for shared_ptr
22 #include <string> // for string
23 #include <vector>
25 
26 #include "armadillo"
27 
28 class Mesh;
29 class LinearODESolver;
30 namespace Input { class Record; }
31 
32 /** @brief Base class for linear reactions and decay chain.
33  *
34  * The class implements common interface for linear reactions and decay chains.
35  * One step of the linear reaction or the decay is represented as a product of a reaction matrix and
36  * a vector of concentrations of transported substances on a single element.
37  *
38  * It uses armadillo to compute the reaction matrix which then multiplies to concetration vector.
39  * This class also resolves the choice of the numerical method which is used to compute the reaction matrix.
40  */
42 {
43 public:
44  /// Constructor.
45  FirstOrderReactionBase(Mesh &init_mesh, Input::Record in_rec);
46 
47  /// Destructor.
49 
50  /// Prepares the object to usage.
51  /**
52  * Allocating memory, reading input, initialization of fields.
53  */
54  void initialize() override;
55 
56  /// Moves the model to zero time.
57  /** The assembly of the system matrix is called here.
58  */
59  void zero_time_step() override;
60 
61  /// Updates the solution.
62  /**
63  * Goes through local distribution of elements and calls @p compute_reaction.
64  */
65  void update_solution(void) override;
66 
67 protected:
68  /// Assembles the matrix of the ODEs.
69  /**
70  * We solve the system of \f$N\f$ equations
71  * \f[
72  * \frac{\textrm{d} c_i}{\textrm{d}t}=-\sum\limits_{j=1}^N \frac{M_i}{M_j} \lambda_{i} b_j c_j, \qquad \textrm i=1,\ldots,N
73  * \f]
74  * where \f$M_i, M_j\f$ are the molar masses of the parent substances and products, \f$\lambda_i\f$ are the
75  * reaction rate constants (in case of decays converted from half_lives) and \f$b_j\f$ are the branching ratios.
76  * The constant coefficients \f$\mathbf{A}_{ij}=\frac{M_i}{M_j} \lambda_{i} b_j\f$ are the elements of the system matrix.
77  *
78  * It is pure virtual and must be implemented in descendants.
79  */
80  virtual void assemble_ode_matrix(void) = 0;
81 
82  /// Computes the reaction on a specified element.
83  virtual void compute_reaction(const DHCellAccessor& dh_cell) override;
84 
85  /// Initializes private members of sorption from the input record.
86  virtual void initialize_from_input() = 0;
87 
88  /** Help function to create mapping of substance indices.
89  * Finds a position of a string in specified array.
90  */
91  unsigned int find_subst_name(const std::string &name);
92 
93  /**
94  * Sequence of integers describing an order of isotopes.
95  * substance_ids_[reactant][local_product_idx] = global_substance_idx
96  */
98 
99  /**
100  * Two dimensional array contains mass percentage of every single decay bifurcation on every single row.
101  */
103 
104  /// Number of all transported substances. It is the dimension of the reaction matrix.
105  unsigned int n_substances_;
106 
107  arma::mat reaction_matrix_; ///< Reaction matrix.
108  arma::vec prev_conc_; ///< Column vector storing previous concetrations on an element.
109 
110  arma::mat molar_matrix_; ///< Diagonal matrix with molar masses of substances.
111  arma::mat molar_mat_inverse_; ///< Inverse of @p molar_matrix_.
112 
113  std::shared_ptr<LinearODESolver> linear_ode_solver_;
114 };
115 
116 #endif // FIRST_ORDER_REACTION_BASE_H_
FirstOrderReactionBase::find_subst_name
unsigned int find_subst_name(const std::string &name)
Definition: first_order_reaction_base.cc:121
FirstOrderReactionBase::molar_mat_inverse_
arma::mat molar_mat_inverse_
Inverse of molar_matrix_.
Definition: first_order_reaction_base.hh:111
Armor::vec
ArmaVec< double, N > vec
Definition: armor.hh:885
FirstOrderReactionBase::update_solution
void update_solution(void) override
Updates the solution.
Definition: first_order_reaction_base.cc:103
FirstOrderReactionBase::prev_conc_
arma::vec prev_conc_
Column vector storing previous concetrations on an element.
Definition: first_order_reaction_base.hh:108
FirstOrderReactionBase::FirstOrderReactionBase
FirstOrderReactionBase(Mesh &init_mesh, Input::Record in_rec)
Constructor.
Definition: first_order_reaction_base.cc:36
Input
Abstract linear system class.
Definition: balance.hh:40
FirstOrderReactionBase::n_substances_
unsigned int n_substances_
Number of all transported substances. It is the dimension of the reaction matrix.
Definition: first_order_reaction_base.hh:105
FirstOrderReactionBase::~FirstOrderReactionBase
~FirstOrderReactionBase(void)
Destructor.
Definition: first_order_reaction_base.cc:42
FirstOrderReactionBase::substance_ids_
std::vector< std::vector< unsigned int > > substance_ids_
Definition: first_order_reaction_base.hh:97
FirstOrderReactionBase::compute_reaction
virtual void compute_reaction(const DHCellAccessor &dh_cell) override
Computes the reaction on a specified element.
Definition: first_order_reaction_base.cc:84
std::vector
Definition: doxy_dummy_defs.hh:7
FirstOrderReactionBase::molar_matrix_
arma::mat molar_matrix_
Diagonal matrix with molar masses of substances.
Definition: first_order_reaction_base.hh:110
LinearODESolver
Class for linear ODE solver.
Definition: linear_ode_solver.hh:38
Armor::mat
ArmaMat< double, N, M > mat
Definition: armor.hh:888
Input::Record
Accessor to the data with type Type::Record.
Definition: accessors.hh:291
FirstOrderReactionBase::initialize
void initialize() override
Prepares the object to usage.
Definition: first_order_reaction_base.cc:46
FirstOrderReactionBase::zero_time_step
void zero_time_step() override
Moves the model to zero time.
Definition: first_order_reaction_base.cc:71
FirstOrderReactionBase::assemble_ode_matrix
virtual void assemble_ode_matrix(void)=0
Assembles the matrix of the ODEs.
FirstOrderReactionBase::initialize_from_input
virtual void initialize_from_input()=0
Initializes private members of sorption from the input record.
Mesh
Definition: mesh.h:98
DHCellAccessor
Cell accessor allow iterate over DOF handler cells.
Definition: dh_cell_accessor.hh:43
FirstOrderReactionBase
Base class for linear reactions and decay chain.
Definition: first_order_reaction_base.hh:41
FirstOrderReactionBase::bifurcation_
std::vector< std::vector< double > > bifurcation_
Definition: first_order_reaction_base.hh:102
FirstOrderReactionBase::reaction_matrix_
arma::mat reaction_matrix_
Reaction matrix.
Definition: first_order_reaction_base.hh:107
reaction_term.hh
Class ReactionTerm is an abstract class representing reaction term in transport.
ReactionTerm
Definition: reaction_term.hh:45
FirstOrderReactionBase::linear_ode_solver_
std::shared_ptr< LinearODESolver > linear_ode_solver_
Definition: first_order_reaction_base.hh:113