Flow123d  jenkins-Flow123d-windows-release-multijob-285
first_order_reaction_base.hh
Go to the documentation of this file.
1 #ifndef FIRST_ORDER_REACTION_BASE_H_
2 #define FIRST_ORDER_REACTION_BASE_H_
3 
4 #include <vector>
5 
7 #include "input/accessors.hh"
8 
9 #include "armadillo"
10 
11 class Mesh;
13 
14 /** @brief Base class for linear reactions and decay chain.
15  *
16  * The class implements common interface for linear reactions and decay chains.
17  * One step of the linear reaction or the decay is represented as a product of a reaction matrix and
18  * a vector of concentrations of transported substances on a single element.
19  *
20  * It uses armadillo to compute the reaction matrix which then multiplies to concetration vector.
21  * This class also resolves the choice of the numerical method which is used to compute the reaction matrix.
22  */
24 {
25 public:
26  /// Constructor.
27  FirstOrderReactionBase(Mesh &init_mesh, Input::Record in_rec);
28 
29  /// Destructor.
31 
32  /// Prepares the object to usage.
33  /**
34  * Allocating memory, reading input, initialization of fields.
35  */
36  void initialize() override;
37 
38  /// Moves the model to zero time.
39  /** The assembly of the system matrix is called here.
40  */
41  void zero_time_step() override;
42 
43  /// Updates the solution.
44  /**
45  * Goes through local distribution of elements and calls @p compute_reaction.
46  */
47  void update_solution(void) override;
48 
49 protected:
50  /// Assembles the matrix of the ODEs.
51  /**
52  * We solve the system of \f$N\f$ equations
53  * \f[
54  * \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
55  * \f]
56  * where \f$M_i, M_j\f$ are the molar masses of the parent substances and products, \f$\lambda_i\f$ are the
57  * reaction rate constants (in case of decays converted from half_lives) and \f$b_j\f$ are the branching ratios.
58  * The constant coefficients \f$\mathbf{A}_{ij}=\frac{M_i}{M_j} \lambda_{i} b_j\f$ are the elements of the system matrix.
59  *
60  * It is pure virtual and must be implemented in descendants.
61  */
62  virtual void assemble_ode_matrix(void) = 0;
63 
64  /// Computes the reaction on a specified element.
65  virtual double **compute_reaction(double **concentrations, int loc_el) override;
66 
67  /// Initializes private members of sorption from the input record.
68  virtual void initialize_from_input() = 0;
69 
70  /** Help function to create mapping of substance indices.
71  * Finds a position of a string in specified array.
72  */
73  unsigned int find_subst_name(const std::string &name);
74 
75  /**
76  * Sequence of integers describing an order of isotopes.
77  * substance_ids_[reactant][local_product_idx] = global_substance_idx
78  */
80 
81  /**
82  * Two dimensional array contains mass percentage of every single decay bifurcation on every single row.
83  */
85 
86  /// Number of all transported substances. It is the dimension of the reaction matrix.
87  unsigned int n_substances_;
88 
89  arma::mat reaction_matrix_; ///< Reaction matrix.
90  arma::vec prev_conc_; ///< Column vector storing previous concetrations on an element.
91 
92  arma::mat molar_matrix_; ///< Diagonal matrix with molar masses of substances.
93  arma::mat molar_mat_inverse_; ///< Inverse of @p molar_matrix_.
94 
96 };
97 
98 #endif // FIRST_ORDER_REACTION_BASE_H_
virtual void initialize_from_input()=0
Initializes private members of sorption from the input record.
arma::mat molar_matrix_
Diagonal matrix with molar masses of substances.
void initialize() override
Prepares the object to usage.
void zero_time_step() override
Moves the model to zero time.
Definition: mesh.h:109
unsigned int find_subst_name(const std::string &name)
Base class for linear reactions and decay chain.
virtual void assemble_ode_matrix(void)=0
Assembles the matrix of the ODEs.
void update_solution(void) override
Updates the solution.
arma::mat reaction_matrix_
Reaction matrix.
Base class for linear ODE solver.
FirstOrderReactionBase(Mesh &init_mesh, Input::Record in_rec)
Constructor.
Accessor to the data with type Type::Record.
Definition: accessors.hh:327
arma::vec prev_conc_
Column vector storing previous concetrations on an element.
arma::mat molar_mat_inverse_
Inverse of molar_matrix_.
LinearODESolverBase * linear_ode_solver_
std::vector< std::vector< unsigned int > > substance_ids_
unsigned int n_substances_
Number of all transported substances. It is the dimension of the reaction matrix. ...
virtual double ** compute_reaction(double **concentrations, int loc_el) override
Computes the reaction on a specified element.
~FirstOrderReactionBase(void)
Destructor.
std::vector< std::vector< double > > bifurcation_