Flow123d  release_1.8.2-1603-g0109a2b
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;
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 protected:
67  /// Assembles the matrix of the ODEs.
68  /**
69  * We solve the system of \f$N\f$ equations
70  * \f[
71  * \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
72  * \f]
73  * where \f$M_i, M_j\f$ are the molar masses of the parent substances and products, \f$\lambda_i\f$ are the
74  * reaction rate constants (in case of decays converted from half_lives) and \f$b_j\f$ are the branching ratios.
75  * The constant coefficients \f$\mathbf{A}_{ij}=\frac{M_i}{M_j} \lambda_{i} b_j\f$ are the elements of the system matrix.
76  *
77  * It is pure virtual and must be implemented in descendants.
78  */
79  virtual void assemble_ode_matrix(void) = 0;
80 
81  /// Computes the reaction on a specified element.
82  virtual double **compute_reaction(double **concentrations, int loc_el) override;
83 
84  /// Initializes private members of sorption from the input record.
85  virtual void initialize_from_input() = 0;
86 
87  /** Help function to create mapping of substance indices.
88  * Finds a position of a string in specified array.
89  */
90  unsigned int find_subst_name(const std::string &name);
91 
92  /**
93  * Sequence of integers describing an order of isotopes.
94  * substance_ids_[reactant][local_product_idx] = global_substance_idx
95  */
97 
98  /**
99  * Two dimensional array contains mass percentage of every single decay bifurcation on every single row.
100  */
102 
103  /// Number of all transported substances. It is the dimension of the reaction matrix.
104  unsigned int n_substances_;
105 
106  arma::mat reaction_matrix_; ///< Reaction matrix.
107  arma::vec prev_conc_; ///< Column vector storing previous concetrations on an element.
108 
109  arma::mat molar_matrix_; ///< Diagonal matrix with molar masses of substances.
110  arma::mat molar_mat_inverse_; ///< Inverse of @p molar_matrix_.
111 
112  std::shared_ptr<LinearODESolverBase> linear_ode_solver_;
113 };
114 
115 #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:99
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.
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:277
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_
std::shared_ptr< LinearODESolverBase > linear_ode_solver_
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_