Flow123d  release_2.2.0-41-g0958a8d
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 <vector>
22 
25 
26 #include "armadillo"
27 
28 class Mesh;
29 class PadeApproximant;
30 
31 /** @brief Base class for linear reactions and decay chain.
32  *
33  * The class implements common interface for linear reactions and decay chains.
34  * One step of the linear reaction or the decay is represented as a product of a reaction matrix and
35  * a vector of concentrations of transported substances on a single element.
36  *
37  * It uses armadillo to compute the reaction matrix which then multiplies to concetration vector.
38  * This class also resolves the choice of the numerical method which is used to compute the reaction matrix.
39  */
41 {
42 public:
43  /// Constructor.
44  FirstOrderReactionBase(Mesh &init_mesh, Input::Record in_rec);
45 
46  /// Destructor.
48 
49  /// Prepares the object to usage.
50  /**
51  * Allocating memory, reading input, initialization of fields.
52  */
53  void initialize() override;
54 
55  /// Moves the model to zero time.
56  /** The assembly of the system matrix is called here.
57  */
58  void zero_time_step() override;
59 
60  /// Updates the solution.
61  /**
62  * Goes through local distribution of elements and calls @p compute_reaction.
63  */
64  void update_solution(void) override;
65 
66  bool evaluate_time_constraint(double &time_constraint) override;
67 
68 protected:
69  /// Assembles the matrix of the ODEs.
70  /**
71  * We solve the system of \f$N\f$ equations
72  * \f[
73  * \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
74  * \f]
75  * where \f$M_i, M_j\f$ are the molar masses of the parent substances and products, \f$\lambda_i\f$ are the
76  * reaction rate constants (in case of decays converted from half_lives) and \f$b_j\f$ are the branching ratios.
77  * The constant coefficients \f$\mathbf{A}_{ij}=\frac{M_i}{M_j} \lambda_{i} b_j\f$ are the elements of the system matrix.
78  *
79  * It is pure virtual and must be implemented in descendants.
80  */
81  virtual void assemble_ode_matrix(void) = 0;
82 
83  /// Computes the reaction on a specified element.
84  virtual double **compute_reaction(double **concentrations, int loc_el) override;
85 
86  /// Initializes private members of sorption from the input record.
87  virtual void initialize_from_input() = 0;
88 
89  /** Help function to create mapping of substance indices.
90  * Finds a position of a string in specified array.
91  */
92  unsigned int find_subst_name(const std::string &name);
93 
94  /**
95  * Sequence of integers describing an order of isotopes.
96  * substance_ids_[reactant][local_product_idx] = global_substance_idx
97  */
99 
100  /**
101  * Two dimensional array contains mass percentage of every single decay bifurcation on every single row.
102  */
104 
105  /// Number of all transported substances. It is the dimension of the reaction matrix.
106  unsigned int n_substances_;
107 
108  arma::mat reaction_matrix_; ///< Reaction matrix.
109  arma::vec prev_conc_; ///< Column vector storing previous concetrations on an element.
110 
111  arma::mat molar_matrix_; ///< Diagonal matrix with molar masses of substances.
112  arma::mat molar_mat_inverse_; ///< Inverse of @p molar_matrix_.
113 
114  std::shared_ptr<PadeApproximant> linear_ode_solver_;
115 };
116 
117 #endif // FIRST_ORDER_REACTION_BASE_H_
This class implements the Pade approximation of exponential function.
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:97
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.
Class ReactionTerm is an abstract class representing reaction term in transport.
void update_solution(void) override
Updates the solution.
arma::mat reaction_matrix_
Reaction matrix.
FirstOrderReactionBase(Mesh &init_mesh, Input::Record in_rec)
Constructor.
Accessor to the data with type Type::Record.
Definition: accessors.hh:292
arma::vec prev_conc_
Column vector storing previous concetrations on an element.
arma::mat molar_mat_inverse_
Inverse of molar_matrix_.
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::shared_ptr< PadeApproximant > linear_ode_solver_
bool evaluate_time_constraint(double &time_constraint) override
Computes a constraint for time step.
std::vector< std::vector< double > > bifurcation_